diff --git a/spring-integration-samples/jmx/.classpath b/spring-integration-samples/jmx/.classpath new file mode 100644 index 0000000000..a7ac8abdba --- /dev/null +++ b/spring-integration-samples/jmx/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/spring-integration-samples/jmx/.project b/spring-integration-samples/jmx/.project new file mode 100644 index 0000000000..2b917559c3 --- /dev/null +++ b/spring-integration-samples/jmx/.project @@ -0,0 +1,29 @@ + + + jmx + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.springframework.ide.eclipse.core.springbuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.springframework.ide.eclipse.core.springnature + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/spring-integration-samples/jmx/pom.xml b/spring-integration-samples/jmx/pom.xml new file mode 100644 index 0000000000..e1b8781282 --- /dev/null +++ b/spring-integration-samples/jmx/pom.xml @@ -0,0 +1,19 @@ + + + spring-integration-samples + org.springframework.integration + 2.0.0.BUILD-SNAPSHOT + + 4.0.0 + jmx + jmx + 2.0.0.BUILD-SNAPSHOT + + + org.springframework.integration + org.springframework.integration.jmx + 2.0.0.BUILD-SNAPSHOT + + + \ No newline at end of file diff --git a/spring-integration-samples/jmx/src/main/java/org/springframework/integration/samples/jmx/JmxAdapterDemo-context.xml b/spring-integration-samples/jmx/src/main/java/org/springframework/integration/samples/jmx/JmxAdapterDemo-context.xml new file mode 100644 index 0000000000..cc8b33b8ed --- /dev/null +++ b/spring-integration-samples/jmx/src/main/java/org/springframework/integration/samples/jmx/JmxAdapterDemo-context.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-integration-samples/jmx/src/main/java/org/springframework/integration/samples/jmx/JmxAdapterDemo.java b/spring-integration-samples/jmx/src/main/java/org/springframework/integration/samples/jmx/JmxAdapterDemo.java new file mode 100644 index 0000000000..74ad3ff4ba --- /dev/null +++ b/spring-integration-samples/jmx/src/main/java/org/springframework/integration/samples/jmx/JmxAdapterDemo.java @@ -0,0 +1,32 @@ +/* + * Copyright 2002-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.samples.jmx; + +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @author Mark Fisher + * @since 2.0 + */ +public class JmxAdapterDemo { + + public static void main(String[] args) { + new ClassPathXmlApplicationContext( + "JmxAdapterDemo-context.xml", JmxAdapterDemo.class); + } + +} diff --git a/spring-integration-samples/jmx/src/main/java/org/springframework/integration/samples/jmx/StopWatch.java b/spring-integration-samples/jmx/src/main/java/org/springframework/integration/samples/jmx/StopWatch.java new file mode 100644 index 0000000000..a431a579ac --- /dev/null +++ b/spring-integration-samples/jmx/src/main/java/org/springframework/integration/samples/jmx/StopWatch.java @@ -0,0 +1,72 @@ +/* + * Copyright 2002-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.samples.jmx; + +import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicInteger; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.jmx.export.annotation.ManagedAttribute; +import org.springframework.jmx.export.annotation.ManagedOperation; +import org.springframework.jmx.export.annotation.ManagedResource; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import org.springframework.stereotype.Component; + +/** + * @author Mark Fisher + * @since 2.0 + */ +@Component +@ManagedResource +public class StopWatch implements InitializingBean { + + private final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); + + private volatile Future future; + + private final AtomicInteger seconds = new AtomicInteger(); + + @ManagedAttribute + public int getSeconds() { + return this.seconds.get(); + } + + public void afterPropertiesSet() { + this.start(); + } + + @ManagedOperation + public void start() { + this.scheduler.initialize(); + this.future = this.scheduler.scheduleAtFixedRate(new Runnable() { + public void run() { + seconds.incrementAndGet(); + } + }, 1000); + } + + @ManagedOperation + public void stop() { + this.future.cancel(true); + } + + @ManagedOperation + public void reset() { + this.seconds.set(0); + } + +}