Author: dgolovin
Date: 2009-11-02 15:04:59 -0500 (Mon, 02 Nov 2009)
New Revision: 18391
Added:
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/mbeans/
Removed:
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/Client.java
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/Hello.java
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/HelloMBean.java
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/Main.java
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/QueueSample.java
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/QueueSampler.java
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/QueueSamplerMBean.java
Log:
JMX core test error was fixed
Deleted:
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/Client.java
===================================================================
---
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/Client.java 2009-11-02
15:50:34 UTC (rev 18390)
+++
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/Client.java 2009-11-02
20:04:59 UTC (rev 18391)
@@ -1,217 +0,0 @@
-/*
- * Client.java - JMX client that interacts with the JMX agent. It gets
- * attributes and performs operations on the Hello MBean and the QueueSampler
- * MXBean example. It also listens for Hello MBean notifications.
- */
-
-package com.example;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.TreeSet;
-import javax.management.AttributeChangeNotification;
-import javax.management.JMX;
-import javax.management.MBeanServerConnection;
-import javax.management.Notification;
-import javax.management.NotificationEmitter;
-import javax.management.NotificationListener;
-import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-
-public class Client {
-
- /**
- * Inner class that will handle the notifications.
- */
- public static class ClientListener implements NotificationListener {
- public void handleNotification(Notification notification,
- Object handback) {
- echo("\nReceived notification:");
- echo("\tClassName: " + notification.getClass().getName());
- echo("\tSource: " + notification.getSource());
- echo("\tType: " + notification.getType());
- echo("\tMessage: " + notification.getMessage());
- if (notification instanceof AttributeChangeNotification) {
- AttributeChangeNotification acn =
- (AttributeChangeNotification) notification;
- echo("\tAttributeName: " + acn.getAttributeName());
- echo("\tAttributeType: " + acn.getAttributeType());
- echo("\tNewValue: " + acn.getNewValue());
- echo("\tOldValue: " + acn.getOldValue());
- }
- }
- }
-
- /* For simplicity, we declare "throws Exception".
- Real programs will usually want finer-grained exception handling. */
- public static void main(String[] args) throws Exception {
- // Create an RMI connector client and
- // connect it to the RMI connector server
- //
- echo("\nCreate an RMI connector client and " +
- "connect it to the RMI connector server");
- JMXServiceURL url =
- new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:9999/jmxrmi");
- JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
-
- // Create listener
- //
- ClientListener listener = new ClientListener();
-
- // Get an MBeanServerConnection
- //
- echo("\nGet an MBeanServerConnection");
- MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
- waitForEnterPressed();
-
- // Get domains from MBeanServer
- //
- echo("\nDomains:");
- String domains[] = mbsc.getDomains();
- Arrays.sort(domains);
- for (String domain : domains) {
- echo("\tDomain = " + domain);
- }
- waitForEnterPressed();
-
- // Get MBeanServer's default domain
- //
- echo("\nMBeanServer default domain = " + mbsc.getDefaultDomain());
-
- // Get MBean count
- //
- echo("\nMBean count = " + mbsc.getMBeanCount());
-
- // Query MBean names
- //
- echo("\nQuery MBeanServer MBeans:");
- Set<ObjectName> names =
- new TreeSet<ObjectName>(mbsc.queryNames(null, null));
- for (ObjectName name : names) {
- echo("\tObjectName = " + name);
- }
- waitForEnterPressed();
-
- // ----------------------
- // Manage the Hello MBean
- // ----------------------
-
- echo("\n>>> Perform operations on Hello MBean <<<");
-
- // Construct the ObjectName for the Hello MBean
- //
- ObjectName mbeanName = new ObjectName("com.example:type=Hello");
-
- // Create a dedicated proxy for the MBean instead of
- // going directly through the MBean server connection
- //
- HelloMBean mbeanProxy =
- JMX.newMBeanProxy(mbsc, mbeanName, HelloMBean.class, true);
-
- // Add notification listener on Hello MBean
- //
- echo("\nAdd notification listener...");
- mbsc.addNotificationListener(mbeanName, listener, null, null);
-
- // Get CacheSize attribute in Hello MBean
- //
- echo("\nCacheSize = " + mbeanProxy.getCacheSize());
-
- // Set CacheSize attribute in Hello MBean
- // Calling "reset" makes the Hello MBean emit a
- // notification that will be received by the registered
- // ClientListener.
- //
- mbeanProxy.setCacheSize(150);
-
- // Sleep for 2 seconds to have time to receive the notification
- //
- echo("\nWaiting for notification...");
- sleep(2000);
-
- // Get CacheSize attribute in Hello MBean
- //
- echo("\nCacheSize = " + mbeanProxy.getCacheSize());
-
- // Invoke "sayHello" in Hello MBean
- //
- echo("\nInvoke sayHello() in Hello MBean...");
- mbeanProxy.sayHello();
-
- // Invoke "add" in Hello MBean
- //
- echo("\nInvoke add(2, 3) in Hello MBean...");
- echo("\nadd(2, 3) = " + mbeanProxy.add(2, 3));
-
- waitForEnterPressed();
-
- // ------------------------------
- // Manage the QueueSampler MXBean
- // ------------------------------
-
- echo("\n>>> Perform operations on QueueSampler MXBean
<<<");
-
- // Construct the ObjectName for the QueueSampler MXBean
- //
- ObjectName mxbeanName =
- new ObjectName("com.example:type=QueueSampler");
-
- // Create a dedicated proxy for the MXBean instead of
- // going directly through the MBean server connection
- //
- QueueSamplerMXBean mxbeanProxy =
- JMX.newMXBeanProxy(mbsc, mxbeanName, QueueSamplerMXBean.class);
-
- // Get QueueSample attribute in QueueSampler MXBean
- //
- QueueSample queue1 = mxbeanProxy.getQueueSample();
- echo("\nQueueSample.Date = " + queue1.getDate());
- echo("QueueSample.Head = " + queue1.getHead());
- echo("QueueSample.Size = " + queue1.getSize());
-
- // Invoke "clearQueue" in QueueSampler MXBean
- //
- echo("\nInvoke clearQueue() in QueueSampler MXBean...");
- mxbeanProxy.clearQueue();
-
- // Get QueueSample attribute in QueueSampler MXBean
- //
- QueueSample queue2 = mxbeanProxy.getQueueSample();
- echo("\nQueueSample.Date = " + queue2.getDate());
- echo("QueueSample.Head = " + queue2.getHead());
- echo("QueueSample.Size = " + queue2.getSize());
-
- waitForEnterPressed();
-
- // Close MBeanServer connection
- //
- echo("\nClose the connection to the server");
- jmxc.close();
- echo("\nBye! Bye!");
- }
-
- static void echo(String msg) {
- System.out.println(msg);
- }
-
- private static void sleep(int millis) {
- try {
- Thread.sleep(millis);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- private static void waitForEnterPressed() {
- try {
- echo("\nPress <Enter> to continue...");
- System.in.read();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-}
Deleted:
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/Hello.java
===================================================================
---
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/Hello.java 2009-11-02
15:50:34 UTC (rev 18390)
+++
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/Hello.java 2009-11-02
20:04:59 UTC (rev 18391)
@@ -1,98 +0,0 @@
-/*
- * Hello.java - MBean implementation for the Hello MBean. This class must
- * implement all the Java methods declared in the HelloMBean interface,
- * with the appropriate behavior for each one.
- */
-
-package com.example;
-
-import javax.management.*;
-
-public class Hello
- extends NotificationBroadcasterSupport 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) {
- int oldSize = this.cacheSize;
- 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);
-
- /* Construct a notification that describes the change. The
- "source" of a notification is the ObjectName of the MBean
- that emitted it. But an MBean can put a reference to
- itself ("this") in the source, and the MBean server will
- replace this with the ObjectName before sending the
- notification on to its clients.
-
- For good measure, we maintain a sequence number for each
- notification emitted by this MBean.
-
- The oldValue and newValue parameters to the constructor are
- of type Object, so we are relying on Tiger's autoboxing
- here. */
- Notification n =
- new AttributeChangeNotification(this,
- sequenceNumber++,
- System.currentTimeMillis(),
- "CacheSize changed",
- "CacheSize",
- "int",
- oldSize,
- this.cacheSize);
-
- /* Now send the notification using the sendNotification method
- inherited from the parent class NotificationBroadcasterSupport. */
- sendNotification(n);
- }
-
- @Override
- public MBeanNotificationInfo[] getNotificationInfo() {
- String[] types = new String[] {
- AttributeChangeNotification.ATTRIBUTE_CHANGE
- };
- String name = AttributeChangeNotification.class.getName();
- String description = "An attribute of this MBean has changed";
- MBeanNotificationInfo info =
- new MBeanNotificationInfo(types, name, description);
- return new MBeanNotificationInfo[] {info};
- }
-
- private final String name = "Reginald";
- private int cacheSize = DEFAULT_CACHE_SIZE;
- private static final int DEFAULT_CACHE_SIZE = 200;
-
- private long sequenceNumber = 1;
-}
Deleted:
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/HelloMBean.java
===================================================================
---
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/HelloMBean.java 2009-11-02
15:50:34 UTC (rev 18390)
+++
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/HelloMBean.java 2009-11-02
20:04:59 UTC (rev 18391)
@@ -1,27 +0,0 @@
-/*
- * 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;
-
-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);
-}
Deleted:
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/Main.java
===================================================================
---
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/Main.java 2009-11-02
15:50:34 UTC (rev 18390)
+++
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/Main.java 2009-11-02
20:04:59 UTC (rev 18391)
@@ -1,50 +0,0 @@
-/*
- * Main.java - main class for the Hello MBean and QueueSampler MXBean example.
- * Create the Hello MBean and QueueSampler MXBean, register them in the platform
- * MBean server, then wait forever (or until the program is interrupted).
- *
- *
http://java.sun.com/docs/books/tutorial/jmx/remote/jconsole.html
- */
-
-package com.example;
-
-import java.lang.management.ManagementFactory;
-import java.util.Queue;
-import java.util.concurrent.ArrayBlockingQueue;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
-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 Hello MBean we will register
- ObjectName mbeanName = new ObjectName("com.example:type=Hello");
-
- // Create the Hello World MBean
- Hello mbean = new Hello();
-
- // Register the Hello World MBean
- mbs.registerMBean(mbean, mbeanName);
-
- // Construct the ObjectName for the QueueSampler MXBean we will register
- ObjectName mxbeanName = new
ObjectName("com.example:type=QueueSampler");
-
- // Create the Queue Sampler MXBean
- Queue<String> queue = new ArrayBlockingQueue<String>(10);
- queue.add("Request-1");
- queue.add("Request-2");
- queue.add("Request-3");
- QueueSampler mxbean = new QueueSampler(queue);
-
- // Register the Queue Sampler MXBean
- mbs.registerMBean(mxbean, mxbeanName);
-
- // Wait forever
- System.out.println("Waiting for incoming requests...");
- Thread.sleep(Long.MAX_VALUE);
- }
-}
Deleted:
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/QueueSample.java
===================================================================
---
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/QueueSample.java 2009-11-02
15:50:34 UTC (rev 18390)
+++
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/QueueSample.java 2009-11-02
20:04:59 UTC (rev 18391)
@@ -1,36 +0,0 @@
-/*
- * QueueSample.java - Java type representing a snapshot of a given queue.
- * It bundles together the instant time the snapshot was taken, the queue
- * size and the queue head.
- */
-
-package com.example;
-
-import java.beans.ConstructorProperties;
-import java.util.Date;
-
-public class QueueSample {
-
- private final Date date;
- private final int size;
- private final String head;
-
- @ConstructorProperties({"date", "size", "head"})
- public QueueSample(Date date, int size, String head) {
- this.date = date;
- this.size = size;
- this.head = head;
- }
-
- public Date getDate() {
- return date;
- }
-
- public int getSize() {
- return size;
- }
-
- public String getHead() {
- return head;
- }
-}
Deleted:
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/QueueSampler.java
===================================================================
---
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/QueueSampler.java 2009-11-02
15:50:34 UTC (rev 18390)
+++
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/QueueSampler.java 2009-11-02
20:04:59 UTC (rev 18391)
@@ -1,31 +0,0 @@
-/*
- * QueueSampler.java - MXBean implementation for the QueueSampler MXBean.
- * This class must implement all the Java methods declared in the
- * QueueSamplerMXBean interface, with the appropriate behavior for each one.
- */
-
-package com.example;
-
-import java.util.Date;
-import java.util.Queue;
-
-public class QueueSampler implements QueueSamplerMBean {
-
- private Queue<String> queue;
-
- public QueueSampler(Queue<String> queue) {
- this.queue = queue;
- }
-
- public QueueSample getQueueSample() {
- synchronized (queue) {
- return new QueueSample(new Date(), queue.size(), queue.peek());
- }
- }
-
- public void clearQueue() {
- synchronized (queue) {
- queue.clear();
- }
- }
-}
Deleted:
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/QueueSamplerMBean.java
===================================================================
---
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/QueueSamplerMBean.java 2009-11-02
15:50:34 UTC (rev 18390)
+++
trunk/jmx/tests/org.jboss.tools.jmx.core.test/projects/JMX_EXAMPLE/src/com/example/QueueSamplerMBean.java 2009-11-02
20:04:59 UTC (rev 18391)
@@ -1,12 +0,0 @@
-/*
- * QueueSamplerMXBean.java - MXBean interface describing the management
- * operations and attributes for the QueueSampler MXBean. In this case
- * there is a read-only attribute "QueueSample" and an operation
"clearQueue".
- */
-
-package com.example;
-
-public interface QueueSamplerMBean {
- public QueueSample getQueueSample();
- public void clearQueue();
-}