Author: dgolovin
Date: 2009-11-10 15:03:21 -0500 (Tue, 10 Nov 2009)
New Revision: 18579
Added:
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/mbeans/Hello.java
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/mbeans/HelloMBean.java
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/mbeans/Main.java
Log:
another attempt to fix JMXCOnnection test errors
Added:
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/mbeans/Hello.java
===================================================================
---
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/mbeans/Hello.java
(rev 0)
+++
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/mbeans/Hello.java 2009-11-10
20:03:21 UTC (rev 18579)
@@ -0,0 +1,52 @@
+/* Hello.java - MBean implementation for the Hello World MBean.
+ This class must implement all the Java methods declared in the
+ HelloMBean interface, with the appropriate behavior for each one. */
+
+package com.example.mbeans;
+
+public class Hello implements HelloMBean {
+ public void sayHello() {
+ System.out.println("hello, world");
+ }
+
+ public int add(int x, int y) {
+ return x + y;
+ }
+
+ /* Getter for the Name attribute. The pattern shown here is
+ frequent: the getter returns a private field representing the
+ attribute value. In our case, the attribute value never
+ changes, but for other attributes it might change as the
+ application runs. Consider an attribute representing
+ statistics such as uptime or memory usage, for example. Being
+ read-only just means that it can't be changed through the
+ management interface. */
+ public String getName() {
+ return this.name;
+ }
+
+ /* Getter for the CacheSize attribute. The pattern shown here is
+ frequent: the getter returns a private field representing the
+ attribute value, and the setter changes that field. */
+ public int getCacheSize() {
+ return this.cacheSize;
+ }
+
+ /* Setter for the CacheSize attribute. To avoid problems with
+ stale values in multithreaded situations, it is a good idea
+ for setters to be synchronized. */
+ public synchronized void setCacheSize(int size) {
+ this.cacheSize = size;
+
+ /* In a real application, changing the attribute would
+ typically have effects beyond just modifying the cacheSize
+ field. For example, resizing the cache might mean
+ discarding entries or allocating new ones. The logic for
+ these effects would be here. */
+ System.out.println("Cache size now " + this.cacheSize);
+ }
+
+ private final String name = "Reginald";
+ private int cacheSize = DEFAULT_CACHE_SIZE;
+ private static final int DEFAULT_CACHE_SIZE = 200;
+}
Property changes on:
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/mbeans/Hello.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/mbeans/HelloMBean.java
===================================================================
---
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/mbeans/HelloMBean.java
(rev 0)
+++
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/mbeans/HelloMBean.java 2009-11-10
20:03:21 UTC (rev 18579)
@@ -0,0 +1,22 @@
+/* HelloMBean.java - MBean interface describing the management
+ operations and attributes for the Hello World MBean. In this case
+ there are two operations, "sayHello" and "add", and two
attributes,
+ "Name" and "CacheSize". */
+
+package com.example.mbeans;
+
+public interface HelloMBean {
+ // operations
+
+ public void sayHello();
+ public int add(int x, int y);
+
+ // attributes
+
+ // a read-only attribute called Name of type String
+ public String getName();
+
+ // a read-write attribute called CacheSize of type int
+ public int getCacheSize();
+ public void setCacheSize(int size);
+}
Property changes on:
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/mbeans/HelloMBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/mbeans/Main.java
===================================================================
---
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/mbeans/Main.java
(rev 0)
+++
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/mbeans/Main.java 2009-11-10
20:03:21 UTC (rev 18579)
@@ -0,0 +1,31 @@
+/* Main.java - main class for Hello World example. Create the
+ HelloWorld MBean, register it, then wait forever (or until the
+ program is interrupted). */
+
+package com.example.mbeans;
+
+import java.lang.management.*;
+import javax.management.*;
+
+public class Main {
+ /* For simplicity, we declare "throws Exception". Real programs
+ will usually want finer-grained exception handling. */
+ public static void main(String[] args) throws Exception {
+ // Get the Platform MBean Server
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+
+ // Construct the ObjectName for the MBean we will register
+ ObjectName name = new ObjectName("com.example.mbeans:type=Hello");
+
+ // Create the Hello World MBean
+ Hello mbean = new Hello();
+
+ // Register the Hello World MBean
+ mbs.registerMBean(mbean, name);
+
+ // Wait forever
+ System.out.println("Waiting forever...");
+ Thread.sleep(Long.MAX_VALUE);
+ }
+}
+
\ No newline at end of file
Property changes on:
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/mbeans/Main.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Show replies by date