KickJava   Java API By Example, From Geeks To Geeks.

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


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.EventChannel;
9 import org.omg.CosEventChannelAdmin.EventChannelHelper;
10 import org.omg.CosEventChannelAdmin.ProxyPushConsumer;
11 import org.omg.CosEventChannelAdmin.SupplierAdmin;
12 import org.omg.CosEventComm.PushSupplierPOA;
13
14 /**
15  * @author Alphonse Bendt
16  */

17
18 public class CosEventPushSender extends PushSupplierPOA implements TestClientOperations, Runnable JavaDoc
19 {
20     boolean connected_;
21
22     boolean sent_;
23
24     boolean error_;
25
26     ProxyPushConsumer myConsumer_;
27
28     Any JavaDoc event_;
29
30     ORB JavaDoc orb_;
31
32     public CosEventPushSender(ORB JavaDoc orb, Any JavaDoc event)
33     {
34         event_ = event;
35         orb_ = orb;
36     }
37
38     public void disconnect_push_supplier()
39     {
40         connected_ = false;
41     }
42
43     public boolean isConnected()
44     {
45         return connected_;
46     }
47
48     public boolean isEventHandled()
49     {
50         return sent_;
51     }
52
53     public boolean isError()
54     {
55         return error_;
56     }
57
58     public void connect(org.omg.CosNotifyChannelAdmin.EventChannel channel, boolean useOrSemantic)
59             throws AlreadyConnected
60     {
61         Assert.assertNotNull(channel);
62         EventChannel _channel = EventChannelHelper.narrow(channel);
63         Assert.assertNotNull(_channel);
64
65         SupplierAdmin _admin = _channel.for_suppliers();
66         Assert.assertNotNull(_admin);
67
68         myConsumer_ = _admin.obtain_push_consumer();
69         Assert.assertNotNull(myConsumer_);
70
71         myConsumer_.connect_push_supplier(_this(orb_));
72
73         connected_ = true;
74     }
75
76     public void shutdown()
77     {
78         myConsumer_.disconnect_push_consumer();
79     }
80
81     // Implementation of java.lang.Runnable
82

83     /**
84      * Describe <code>run</code> method here.
85      *
86      */

87     public void run()
88     {
89         try
90         {
91             myConsumer_.push(event_);
92
93             event_ = null;
94             sent_ = true;
95         } catch (Throwable JavaDoc t)
96         {
97             error_ = true;
98         }
99     }
100
101 }
102
Popular Tags