KickJava   Java API By Example, From Geeks To Geeks.

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


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.IntHolder JavaDoc;
7 import org.omg.CORBA.ORB JavaDoc;
8 import org.omg.CosEventChannelAdmin.AlreadyConnected;
9 import org.omg.CosEventComm.Disconnected;
10 import org.omg.CosNotification.EventType;
11 import org.omg.CosNotifyChannelAdmin.AdminLimitExceeded;
12 import org.omg.CosNotifyChannelAdmin.AdminNotFound;
13 import org.omg.CosNotifyChannelAdmin.ClientType;
14 import org.omg.CosNotifyChannelAdmin.EventChannel;
15 import org.omg.CosNotifyChannelAdmin.InterFilterGroupOperator;
16 import org.omg.CosNotifyChannelAdmin.ProxyPushConsumer;
17 import org.omg.CosNotifyChannelAdmin.ProxyPushConsumerHelper;
18 import org.omg.CosNotifyChannelAdmin.ProxyType;
19 import org.omg.CosNotifyChannelAdmin.SupplierAdmin;
20 import org.omg.CosNotifyComm.PushSupplierPOA;
21 import org.omg.CosNotifyFilter.Filter;
22
23 public class AnyPushSender extends PushSupplierPOA implements TestClientOperations, Runnable JavaDoc
24 {
25     ORB JavaDoc orb_;
26
27     ProxyPushConsumer myConsumer_;
28
29     boolean connected_;
30
31     Any JavaDoc event_;
32
33     boolean error_;
34
35     long sendTime_;
36
37
38     int runs_;
39
40     long interval_;
41
42     SupplierAdmin myAdmin_;
43
44     NotificationTestCase testCase_;
45
46     public AnyPushSender(ORB JavaDoc orb, Any JavaDoc event)
47     {
48         orb_ = orb;
49         event_ = event;
50     }
51
52     void setInterval(int i)
53     {
54         interval_ = i;
55     }
56
57     void setEventsToSend(int i)
58     {
59         runs_ = i;
60     }
61
62     AnyPushSender(NotificationTestCase testCase, Any JavaDoc event)
63     {
64         event_ = event;
65         testCase_ = testCase;
66     }
67
68     public void addAdminFilter(Filter filter)
69     {
70         Assert.assertNotNull(myAdmin_);
71         myAdmin_.add_filter(filter);
72     }
73
74     public void addProxyFilter(Filter filter)
75     {
76         Assert.assertNotNull(myConsumer_);
77         myConsumer_.add_filter(filter);
78     }
79
80     public void disconnect_push_supplier()
81     {
82         connected_ = false;
83     }
84
85     public boolean isConnected()
86     {
87         return connected_;
88     }
89
90     public boolean isError()
91     {
92         return false;
93     }
94
95     public boolean isEventHandled()
96     {
97         return true;
98     }
99
100     public void subscription_change(EventType[] e1, EventType[] e2)
101     {
102         // ignored
103
}
104
105     public void run()
106     {
107         singleSend();
108     }
109
110     public void singleSend()
111     {
112         try
113         {
114             myConsumer_.push(event_);
115             sendTime_ = System.currentTimeMillis();
116         } catch (Disconnected d)
117         {
118             error_ = true;
119         }
120     }
121
122     public void connect(EventChannel channel, boolean useOrSemantic)
123
124     throws AdminLimitExceeded, AlreadyConnected, AdminNotFound
125     {
126
127         IntHolder JavaDoc _proxyId = new IntHolder JavaDoc();
128         IntHolder JavaDoc _adminId = new IntHolder JavaDoc();
129
130         if (useOrSemantic)
131         {
132             myAdmin_ = channel.new_for_suppliers(InterFilterGroupOperator.OR_OP, _adminId);
133             Assert.assertEquals(InterFilterGroupOperator.OR_OP, myAdmin_.MyOperator());
134         }
135         else
136         {
137             myAdmin_ = channel.new_for_suppliers(InterFilterGroupOperator.AND_OP, _adminId);
138         }
139
140         Assert.assertEquals(myAdmin_, channel.get_supplieradmin(_adminId.value));
141
142         myConsumer_ = ProxyPushConsumerHelper.narrow(myAdmin_.obtain_notification_push_consumer(
143                 ClientType.ANY_EVENT, _proxyId));
144
145         Assert.assertEquals(ProxyType._PUSH_ANY, myConsumer_.MyType().value());
146
147         myConsumer_.connect_any_push_supplier(_this(orb_));
148
149         connected_ = true;
150     }
151
152     public void shutdown()
153     {
154         myConsumer_.disconnect_push_consumer();
155
156         if (myAdmin_ != null)
157         {
158             myAdmin_.destroy();
159         }
160     }
161
162 }
163
Popular Tags