`

JMX with Spring

    博客分类:
  • JMX
 
阅读更多

import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.transaction.annotation.Transactional;

public class JmxDemo implements JmxDemoMBean, ApplicationContextAware {

    private final static Logger LOG = LoggerFactory.getLogger(JmxDemo.class);


    private JobControlDao jobControlDao;

    public void startJob(String jobID) {

        if (jobControlDao == null) {
            LOG.error("Configuration has some errors.");
            throw new RuntimeException("Configuration Error.");
        }

        if (StringUtils.isBlank(jobID)) {
            LOG.error("Job ID can't be empty.");
            throw new IllegalArgumentException("Job ID can't be empty.");
        }


    }

  

    @Transactional
    private void update(String updateBy, String jobID, String status) {

        JobControl job = jobControlDao.findOne(jobID);

        if (job == null) {
            LOG.error("Job ID doesn't exist.");
            throw new RuntimeException("Job ID doesn't exist.");
        }

        job.setStatus(status);
        job.setUpdateOn(new Date());
        job.setUpdateBy(updateBy);
        jobControlDao.save(job);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    jobControlDao = applicationContext.getBean(JobControlDao.class);
    }

}





<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">

	<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
		<property name="autodetectModeName">
			<value>AUTODETECT_ALL</value>
		</property>
	</bean>

	<bean name="com.xx.jmx:JmxDemo=JmxDemoMBean" class="com.xx.jmx.JmxDemo" />

</beans>

  


  
分享到:
评论

相关推荐

    Spring Recipes: A Problem-Solution Approach, Second Edition

    * Spring enterprise: Spring Java EE integration, Spring Integration, Spring Batch, jBPM with Spring, Spring Remoting, messaging, transactions, scaling using Terracotta and GridGrain, and more. ...

    pro Spring

    Effectively manage your Spring components and applications using Spring's built-in JMX engine. Learn how to add scheduling to your Spring application with Quartz. Learn how to simplify mail sending ...

    spring-boot-reference.pdf

    4. Working with Spring Boot 5. Learning about Spring Boot Features 6. Moving to Production 7. Advanced Topics II. Getting Started 8. Introducing Spring Boot 9. System Requirements 9.1. Servlet ...

    Agile.Java.Development.with.Spring.Hibernate.and.Eclipse

    Agile Java™ Development With Spring, Hibernate and Eclipse is a book about robust technologies and effective methods which help bring simplicity back into the world of enterprise Java development....

    Agile.Java.Development.with.Spring.Hibernate.and.Eclipse-part3

    Agile Java™ Development With Spring, Hibernate and Eclipse is a book about robust technologies and effective methods which help bring simplicity back into the world of enterprise Java development....

    Spring.Boot.Cookbook.1785284150

    The book starts with an overview of the important and useful Spring Boot starters that are included in the framework, and teaches you to create and add custom Servlet Filters, Interceptors, Converters...

    Spring-Reference_zh_CN(Spring中文参考手册)

    2.6.2. JMX 2.6 .3. 任务规划 2.6.4. 对Java 5(Tiger)的支持 2.7. 移植到Spring 2.0 2.7.1. 一些变化 2.7.1.1. Jar包 2.7.1.2. XML配置 2.7.1.3. Deprecated的类和方法 2.7.1.4. Apache OJB 2.7.1.5. iBatis 2.8....

    Spring.Boot.in.Action.2015.12.pdf

    7. 3 Monitoring your application with JMX 146 7.4 Customizing the Actuator 148 Changing endpoint Ds 148 Enabling and disabling endpoints 149 Adding custom metrics and gauges 149- Creating a custom ...

    learning rabbitmq

    His areas of interest include a wide range of Java-related technologies (Servlets, JSP, JAXB, JAXP, JMS, JMX, JAX-RS, JAX-WS, Hibernate, Spring Framework, Liferay Portal, and Eclipse RCP), cloud ...

    xmljava系统源码-mountain:山

    xml java系统源码 mountain 工程 ...因为JMX:Java Management Extension(Java管理应用扩展),默认是true,导致冲突 解决方法,在application-xxxx.properties文件中配置下边属性,进行区分: spring.

    金蝶BOSV6.1_业务组件API参考手册

    com.kingdee.bos.rpc.jmx com.kingdee.bos.rpc.performance com.kingdee.bos.rpc.performance.ui com.kingdee.bos.rpc.ssl com.kingdee.bos.rpc.trace com.kingdee.bos.rpcwrapper ...

    《activmq in action 》

    1.2. Getting Started With ActiveMQ ............................................... 10 1.2.1. Download and Install the Java SE ................................... 10 1.2.2. Download ActiveMQ .............

Global site tag (gtag.js) - Google Analytics