KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > CosEventPushReceiver


1 package org.jacorb.test.notification;
2
3 import junit.framework.Assert;
4
5 import org.omg.CORBA.Any JavaDoc;
6 import org.omg.CORBA.ORB JavaDoc;
7 import org.omg.CosEventChannelAdmin.AlreadyConnected;
8 import org.omg.CosEventChannelAdmin.ConsumerAdmin;
9 import org.omg.CosEventChannelAdmin.EventChannel;
10 import org.omg.CosEventChannelAdmin.EventChannelHelper;
11 import org.omg.CosEventChannelAdmin.ProxyPushSupplier;
12 import org.omg.CosEventChannelAdmin.TypeError;
13 import org.omg.CosEventComm.Disconnected;
14 import org.omg.CosEventComm.PushConsumerPOA;
15
16 /**
17  * @author Alphonse Bendt
18  */

19
20 public class CosEventPushReceiver extends PushConsumerPOA implements Runnable JavaDoc, TestClientOperations
21 {
22     Any JavaDoc event_;
23
24     long timeout_ = 2000;
25
26     boolean received_ = false;
27
28     boolean connected_;
29
30     ProxyPushSupplier mySupplier_;
31
32     final ORB JavaDoc orb_;
33
34     public CosEventPushReceiver(ORB JavaDoc orb)
35     {
36         orb_ = orb;
37     }
38
39     public void setTimeOut(long t)
40     {
41         timeout_ = t;
42     }
43
44     public void push(Any JavaDoc event) throws Disconnected
45     {
46         synchronized (this)
47         {
48             event_ = event;
49             notifyAll();
50         }
51     }
52
53     public void disconnect_push_consumer()
54     {
55         connected_ = false;
56     }
57
58     public void run()
59     {
60         if (event_ == null)
61         {
62             synchronized (this)
63             {
64                 try
65                 {
66                     wait(timeout_);
67                 } catch (InterruptedException JavaDoc e)
68                 {
69                     // ignored
70
}
71             }
72         }
73
74         if (event_ != null)
75         {
76             received_ = true;
77         }
78     }
79
80     public boolean isEventHandled()
81     {
82         return received_;
83     }
84
85     public boolean isConnected()
86     {
87         return connected_;
88     }
89
90     public boolean isError()
91     {
92         return false;
93     }
94
95     public void connect(org.omg.CosNotifyChannelAdmin.EventChannel channel, boolean useOrSemantic)
96             throws AlreadyConnected, TypeError
97     {
98
99         EventChannel _channel = EventChannelHelper.narrow(channel);
100         Assert.assertNotNull(_channel);
101
102         ConsumerAdmin _admin = _channel.for_consumers();
103         Assert.assertNotNull(_admin);
104
105         mySupplier_ = _admin.obtain_push_supplier();
106         Assert.assertNotNull(mySupplier_);
107
108         mySupplier_.connect_push_consumer(_this(orb_));
109         connected_ = true;
110     }
111
112     public void shutdown()
113     {
114         mySupplier_.disconnect_push_supplier();
115     }
116 }
117
Popular Tags