KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jacorb.test.notification;
2
3 import junit.framework.Assert;
4
5 import org.omg.CORBA.BooleanHolder 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.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.SequenceProxyPullSupplier;
18 import org.omg.CosNotifyChannelAdmin.SequenceProxyPullSupplierHelper;
19 import org.omg.CosNotifyComm.SequencePullConsumerHelper;
20 import org.omg.CosNotifyComm.SequencePullConsumerOperations;
21 import org.omg.CosNotifyComm.SequencePullConsumerPOATie;
22
23 class SequencePullReceiver extends Thread JavaDoc implements SequencePullConsumerOperations,
24         TestClientOperations
25 {
26     StructuredEvent[] event_ = null;
27
28     boolean connected_;
29
30     SequenceProxyPullSupplier pullSupplier_;
31
32     boolean received_;
33
34     long TIMEOUT = 1000;
35
36     boolean error_;
37
38     ORB JavaDoc orb_;
39
40     public SequencePullReceiver(ORB JavaDoc orb)
41     {
42         super();
43         orb_ = orb;
44     }
45
46     public boolean isConnected()
47     {
48         return connected_;
49     }
50
51     public void connect(EventChannel channel, boolean useOrSemantic) throws AdminLimitExceeded,
52             AlreadyConnected
53     {
54         SequencePullConsumerPOATie _receiverTie = new SequencePullConsumerPOATie(this);
55         ConsumerAdmin _consumerAdmin = channel.default_consumer_admin();
56         IntHolder JavaDoc _proxyId = new IntHolder JavaDoc();
57
58         pullSupplier_ = SequenceProxyPullSupplierHelper.narrow(_consumerAdmin
59                 .obtain_notification_pull_supplier(ClientType.SEQUENCE_EVENT, _proxyId));
60
61         Assert.assertEquals(ProxyType._PULL_SEQUENCE, pullSupplier_.MyType().value());
62
63         pullSupplier_.connect_sequence_pull_consumer(SequencePullConsumerHelper.narrow(_receiverTie
64                 ._this(orb_)));
65
66         connected_ = true;
67     }
68
69     public boolean isEventHandled()
70     {
71         return event_ != null;
72     }
73
74     public boolean isError()
75     {
76         return false;
77     }
78
79     public void run()
80     {
81         BooleanHolder JavaDoc _success = new BooleanHolder JavaDoc();
82         _success.value = false;
83
84         try
85         {
86             event_ = pullSupplier_.pull_structured_events(1);
87         } catch (Disconnected d)
88         {
89             d.printStackTrace();
90             error_ = true;
91         }
92     }
93
94     public void push_structured_events(StructuredEvent[] event)
95     {
96         event_ = event;
97         synchronized (this)
98         {
99             notifyAll();
100         }
101     }
102
103     public void disconnect_sequence_pull_consumer()
104     {
105         connected_ = false;
106     }
107
108     public void offer_change(EventType[] e1, EventType[] e2)
109     {
110         // ignored
111
}
112
113     public void shutdown()
114     {
115         // mySupplier_.d
116
}
117 }
118
Popular Tags