User: ejort   
  Date: 01/12/16 11:38:39

  Modified:    src/main/test TestMX.java
  Log:
  Initial release of javax.management.timer
  Basic functionality works, not tested everything yet
  Added a test to TestMX
  Added a target to build.xml to run TestMX
  
  Revision  Changes    Path
  1.5       +66 -5     jmx/src/main/test/TestMX.java
  
  Index: TestMX.java
  ===================================================================
  RCS file: /cvsroot/jboss/jmx/src/main/test/TestMX.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestMX.java       2001/12/13 00:12:58     1.4
  +++ TestMX.java       2001/12/16 19:38:39     1.5
  @@ -2,19 +2,27 @@
   
   import javax.management.*;
   import javax.management.loading.*;
  +import javax.management.timer.*;
   import java.util.*;
   
   import org.jboss.mx.modelmbean.*;
   
   public class TestMX
   {
  +   // useful class names
  +   private static String STRING = "java.lang.String";
  +   private static String OBJECT = "java.lang.Object";
  +   private static String DATE = "java.util.Date";
   
  +   private static MBeanServer server;
  +   private static ObjectName oname;
  +
      public static void main(String[] args)
      {
         try
         {
   
  -         MBeanServer server = MBeanServerFactory.createMBeanServer();
  +         server = MBeanServerFactory.createMBeanServer();
   
            NotificationListener regListener = new NotificationListener()
                                               {
  @@ -41,9 +49,8 @@
   
   
   
  -
            // simple speed test, invoke empty methodInvocation 1 million times
  -         ObjectName oname = new ObjectName("Speed:name=mymbean,class=Dynamic");
  +         oname = new ObjectName("Speed:name=mymbean,class=Dynamic");
            System.out.println(oname.getCanonicalName());
            System.out.println(oname.getDomain());
            System.out.println(oname.getKeyPropertyListString());
  @@ -145,7 +152,9 @@
            end = System.currentTimeMillis();
   
            System.out.println("1M invocations, MMB (INTROSPECTION), no args, return 
printInfo string: " + (end - time));
  -         
  +
  +         // simple timer test
  +         timerTest();
         }
         catch (Throwable t)
         {
  @@ -159,7 +168,6 @@
         }
      }
   
  -
      public static interface MyRealInterface extends DynamicMBean
      {}
   
  @@ -595,5 +603,58 @@
   
      }
   
  +   // Timer test stuff
  +
  +   public static void timerTest()
  +     throws Exception
  +   {
  +     System.out.println("Registering timer service...");
  +     oname = new ObjectName("standard:name=timer");
  +     server.createMBean("javax.management.timer.Timer", oname);
  +     System.out.println("Registered: " + oname);
  +
  +     System.out.println("Adding timer listener...");
  +     TestTimerListener ttl = new TestTimerListener();
  +     server.addNotificationListener(oname, ttl, null, null);
  +     System.out.println("Listening.");
  +
  +     System.out.println("Staring timer service...");
  +     server.invoke(oname, "start", new Object[0], new String[0]);
  +     System.out.println("Timer start time: " + curTimePlus(0));
  +
  +     System.out.println("Adding notifications...");
  +     Integer timerId = (Integer) server.invoke(oname, "addNotification", 
  +       new Object[] { "a", "b", "c", curTimePlus(2000) }, 
  +       new String[] { STRING, STRING, OBJECT, DATE });
  +     System.out.println("Registered for 2 second id: " + timerId);
  +     timerId = (Integer) server.invoke(oname, "addNotification", 
  +       new Object[] { "d", "e", "f", curTimePlus(5000) }, 
  +        new String[] { STRING, STRING, OBJECT, DATE });
  +     System.out.println("Registered for 5 seconds id: " + timerId);
  +
  +     System.out.println("Sleeping for 10 seconds...");
  +     Thread.currentThread().sleep(10000);
  +
  +     System.out.println("Stopping timer service...");
  +     server.invoke(oname, "stop", new Object[0], new String[0]);
  +     System.out.println("Timer test complete. :-)");
  +   }
  +
  +   public static Date curTimePlus(long add)
  +   {
  +     return new Date(System.currentTimeMillis() + add);
  +   }
   
  +   public static class TestTimerListener
  +     implements NotificationListener
  +   {
  +     public void handleNotification(Notification n, Object h)
  +     {
  +       if (!(n instanceof TimerNotification))
  +         return;
  +       TimerNotification tn = (TimerNotification) n;
  +       System.out.println("Got notification Id: " + tn.getNotificationID() + 
  +                          " time: "+ new Date(tn.getTimeStamp()));
  +     }
  +   }
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to