KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > compliance > core > notification > InvokerTest


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package test.compliance.core.notification;
8
9 import java.util.Timer JavaDoc;
10 import java.util.TimerTask JavaDoc;
11 import javax.management.ListenerNotFoundException JavaDoc;
12 import javax.management.Notification JavaDoc;
13 import javax.management.NotificationFilter JavaDoc;
14 import javax.management.NotificationListener JavaDoc;
15 import org.jboss.logging.Logger;
16 import org.jboss.mx.notification.AsynchNotificationBroadcasterSupport;
17 import org.jboss.mx.notification.NotificationFilterProxy;
18 import org.jboss.util.threadpool.BasicThreadPool;
19 import org.jboss.util.threadpool.BlockingMode;
20 import org.w3c.dom.Element JavaDoc;
21
22 /**
23  * Used in JMX invoker adaptor test.
24  *
25  * @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>
26  * @version $Revision: 33149 $
27  * @jmx:mbean name="jboss.test:service=InvokerTest"
28  */

29 public class InvokerTest
30       extends AsynchNotificationBroadcasterSupport
31       implements InvokerTestMBean
32 {
33    static Logger log = Logger.getLogger(InvokerTest.class);
34
35    private CustomClass custom = new CustomClass("InitialValue");
36    private NonserializableClass custom2 = new NonserializableClass();
37    private Element JavaDoc xml;
38
39    public InvokerTest()
40    {
41       BasicThreadPool pool = new BasicThreadPool();
42       pool.setBlockingMode(BlockingMode.RUN);
43       pool.setMaximumQueueSize(20);
44       pool.setMaximumPoolSize(1);
45       super.setThreadPool(pool);
46       /* With this set to 0, the testNotificationWithBadListener in
47       JMXInvokerUnitTestCase should fail due to the BadListener blocking the
48       server notification thread pool. With a value of
49       */

50       super.setNotificationTimeout(1000);
51    }
52
53    /**
54     * @jmx:managed-attribute
55     */

56    public String JavaDoc getSomething()
57    {
58       return "something";
59    }
60
61    public void addNotificationListener(NotificationListener JavaDoc listener,
62                                        NotificationFilter JavaDoc filter, Object JavaDoc handback)
63    {
64       log.info("addNotificationListener, listener: " + listener + ", handback: " + handback);
65       super.addNotificationListener(listener, filter, handback);
66       if(filter instanceof NotificationFilterProxy)
67       {
68          NotificationFilter JavaDoc delegateFilter = ((NotificationFilterProxy)filter).getFilter();
69          if(delegateFilter instanceof RunTimerFilter)
70          {
71             Timer JavaDoc t = new Timer JavaDoc();
72             Send10Notifies task = new Send10Notifies();
73             t.scheduleAtFixedRate(task, 0, 1000);
74          }
75       }
76    }
77
78    public void removeNotificationListener(NotificationListener JavaDoc listener)
79          throws ListenerNotFoundException JavaDoc
80    {
81       log.info("removeNotificationListener, listener: " + listener);
82       super.removeNotificationListener(listener);
83    }
84
85    /**
86     * @jmx:managed-attribute
87     */

88    public CustomClass getCustom()
89    {
90       return custom;
91    }
92
93    /**
94     * @jmx:managed-attribute
95     */

96    public void setCustom(CustomClass custom)
97    {
98       this.custom = custom;
99    }
100
101    /**
102     * @jmx:managed-attribute
103     */

104    public NonserializableClass getNonserializableClass()
105    {
106       return custom2;
107    }
108
109    /**
110     * @jmx:managed-attribute
111     */

112    public void setNonserializableClass(NonserializableClass custom)
113    {
114       this.custom2 = custom;
115    }
116
117    /**
118     * @jmx:managed-attribute
119     */

120    public Element JavaDoc getXml()
121    {
122       return xml;
123    }
124
125    /**
126     * @jmx:managed-attribute
127     */

128    public void setXml(Element JavaDoc xml)
129    {
130       this.xml = xml;
131    }
132
133    /**
134     * @jmx:managed-operation
135     */

136    public CustomClass doSomething(CustomClass custom)
137    {
138       return new CustomClass(custom.getValue());
139    }
140
141    /**
142     * @jmx:managed-operation
143     */

144    public CustomClass doSomething()
145    {
146       return new CustomClass(custom.getValue());
147    }
148
149    /**
150     * @jmx:managed-operation
151     */

152    public void stop()
153    {
154       stopThreadPool(true);
155    }
156
157    private class Send10Notifies extends TimerTask JavaDoc
158    {
159       int count;
160
161       /**
162        * The action to be performed by this timer task.
163        */

164       public void run()
165       {
166          log.info("Sending notification on timer, count=" + count);
167          System.out.println("Sending notification on timer, count = " + count);
168          Notification JavaDoc notify = new Notification JavaDoc("InvokerTest.timer",
169                                                 InvokerTest.this, count);
170          InvokerTest.super.sendNotification(notify);
171          count++;
172          if(count == 10)
173          {
174             super.cancel();
175             log.info("Cancelled timer");
176          }
177       }
178    }
179 }
180
Popular Tags