KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jacorb.test.notification;
2
3 import junit.framework.Assert;
4
5 import org.omg.CORBA.IntHolder JavaDoc;
6 import org.omg.CORBA.ORB JavaDoc;
7 import org.omg.CosEventChannelAdmin.AlreadyConnected;
8 import org.omg.CosEventChannelAdmin.TypeError;
9 import org.omg.CosEventComm.Disconnected;
10 import org.omg.CosNotification.EventType;
11 import org.omg.CosNotification.StructuredEvent;
12 import org.omg.CosNotifyChannelAdmin.AdminLimitExceeded;
13 import org.omg.CosNotifyChannelAdmin.ClientType;
14 import org.omg.CosNotifyChannelAdmin.ConsumerAdmin;
15 import org.omg.CosNotifyChannelAdmin.EventChannel;
16 import org.omg.CosNotifyChannelAdmin.ProxyType;
17 import org.omg.CosNotifyChannelAdmin.SequenceProxyPushSupplier;
18 import org.omg.CosNotifyChannelAdmin.SequenceProxyPushSupplierHelper;
19 import org.omg.CosNotifyComm.InvalidEventType;
20 import org.omg.CosNotifyComm.SequencePushConsumerHelper;
21 import org.omg.CosNotifyComm.SequencePushConsumerOperations;
22 import org.omg.CosNotifyComm.SequencePushConsumerPOATie;
23
24 class SequencePushReceiver extends Thread JavaDoc implements SequencePushConsumerOperations,
25         TestClientOperations
26 {
27     SequenceProxyPushSupplier pushSupplier_;
28
29     boolean received_ = false;
30
31     boolean connected_ = false;
32
33     long timeout_ = 2000;
34
35     final ORB JavaDoc orb_;
36
37     public SequencePushReceiver(ORB JavaDoc orb)
38     {
39         orb_ = orb;
40     }
41
42     public void run()
43     {
44         synchronized (this)
45         {
46             if (!received_)
47             {
48                 try
49                 {
50                     wait(timeout_);
51                 } catch (InterruptedException JavaDoc e)
52                 {
53                     // ignored
54
}
55             }
56         }
57     }
58
59     public void push_structured_events(StructuredEvent[] event) throws Disconnected
60     {
61         synchronized (this)
62         {
63             received_ = true;
64             notifyAll();
65         }
66     }
67
68     public void disconnect_sequence_push_consumer()
69     {
70         connected_ = false;
71     }
72
73     public void offer_change(EventType[] type1, EventType[] type2) throws InvalidEventType
74     {
75         // ignored
76
}
77
78     public void connect(EventChannel channel, boolean useOrSemantic) throws AdminLimitExceeded,
79             AlreadyConnected, TypeError
80     {
81         SequencePushConsumerPOATie receiverTie = new SequencePushConsumerPOATie(this);
82         ConsumerAdmin _consumerAdmin = channel.default_consumer_admin();
83         IntHolder JavaDoc _proxyIdHolder = new IntHolder JavaDoc();
84
85         pushSupplier_ = SequenceProxyPushSupplierHelper.narrow(_consumerAdmin
86                 .obtain_notification_push_supplier(ClientType.SEQUENCE_EVENT, _proxyIdHolder));
87
88         Assert.assertEquals(ProxyType._PUSH_SEQUENCE, pushSupplier_.MyType().value());
89
90         pushSupplier_.connect_sequence_push_consumer(SequencePushConsumerHelper.narrow(receiverTie
91                 ._this(orb_)));
92
93         connected_ = true;
94     }
95
96     public boolean isEventHandled()
97     {
98         return received_;
99     }
100
101     public boolean isConnected()
102     {
103         return connected_;
104     }
105
106     public boolean isError()
107     {
108         return false;
109     }
110
111     public void shutdown()
112     {
113         pushSupplier_.disconnect_sequence_push_supplier();
114     }
115 }
116
Popular Tags