Announcement Announcement Module
Collapse
No announcement yet.
Spring JMX Integration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring JMX Integration

    I am using File Polling Application and two servlets to start and stop the file polling. I have initialized file polling beans in config files and it gets started during deployment itself. Now I want that control on me to start/Stop Polling rather polling during application start. File Polling works fine with my configuration.
    Code:
    <int:poller id="AppPoller" task-executor="AppTaskExecutor"
    		fixed-rate="1000">
    		<int:transactional isolation="DEFAULT" propagation="REQUIRED"
    			timeout="120" transaction-manager="transactionManager" />
    	</int:poller>
    	<int:poller id="wfPoller" fixed-rate="5000">
    		<int:advice-chain>
    			<bean class="com.spring.test.FilePollerMonitorAdvice">
    				<constructor-arg value="${inputDirectoryWF}/monitor" />
    				<constructor-arg value="5" />
    			</bean>
    		</int:advice-chain>
    	</int:poller>
    	<int:poller id="mainPoller" fixed-rate="5000">
    		<int:advice-chain>
    			<bean class="com.spring.test.FilePollerMonitorAdvice">
    				<constructor-arg value="${inputDirectory}/monitor" />
    				<constructor-arg value="5" />
    			</bean>
    		</int:advice-chain>
    	</int:poller>

    My JMX Configurations as follows

    Code:
    <context:mbean-export default-domain="myDomain" />
    	<context:mbean-server />
    	<bean id="serverConnector"
    		class="org.springframework.jmx.support.ConnectorServerFactoryBean"
    		depends-on="rmiRegistry">
    		<property name="objectName" value="connector:name=rmi" />
    		<property name="serviceUrl"
    			value="service:jmx:rmi:///jndi/rmi://10.83.6.45:1098/server" />
    	</bean>
    
    	<bean id="rmiRegistry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean"
    		depends-on="">
    		<property name="port" value="1098" />
    	</bean>
    
    	<bean id="clientConnector"
    		class="org.springframework.jmx.support.MBeanServerConnectionFactoryBean">
    		<property name="serviceUrl"
    			value="service:jmx:rmi:///jndi/rmi://10.83.6.45:1098/server" />
    	</bean>
    Now I want to use the above JMX Configurations in Spring Way to start/stop polling.

    Please advise on the same.

    My Sample Servlet to start/stop as follows
    Code:
    JMXServiceURL url = new JMXServiceURL(AppConstants.JMX_SERVICE_URL);
    		JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
    		MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
    		ObjectName mbeanName;
    		try {
    			mbeanName = new ObjectName(AppConstants.JMX_OBJ_NAME);
    			try {
    				mbsc.invoke(mbeanName, "stopPoll", null, null);
    			} catch (InstanceNotFoundException e) {
    				e.printStackTrace();
    			} catch (MBeanException e) {
    				e.printStackTrace();
    			} catch (ReflectionException e) {
    				e.printStackTrace();
    			}
    		} catch (MalformedObjectNameException e) {
    			e.printStackTrace();
    		}
    		MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    		JMXConnectorServer cs = JMXConnectorServerFactory
    				.newJMXConnectorServer(url, null, mbs);
    		cs.stop();
Working...
X