KickJava   Java API By Example, From Geeks To Geeks.

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


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.CosNotification.EventType;
9 import org.omg.CosNotification.StructuredEvent;
10 import org.omg.CosNotifyChannelAdmin.AdminLimitExceeded;
11 import org.omg.CosNotifyChannelAdmin.ClientType;
12 import org.omg.CosNotifyChannelAdmin.EventChannel;
13 import org.omg.CosNotifyChannelAdmin.ProxyType;
14 import org.omg.CosNotifyChannelAdmin.SequenceProxyPushConsumer;
15 import org.omg.CosNotifyChannelAdmin.SequenceProxyPushConsumerHelper;
16 import org.omg.CosNotifyChannelAdmin.SupplierAdmin;
17 import org.omg.CosNotifyComm.InvalidEventType;
18 import org.omg.CosNotifyComm.SequencePushSupplierHelper;
19 import org.omg.CosNotifyComm.SequencePushSupplierOperations;
20 import org.omg.CosNotifyComm.SequencePushSupplierPOATie;
21
22 class SequencePushSender extends Thread JavaDoc implements SequencePushSupplierOperations,
23         TestClientOperations
24 {
25     SequenceProxyPushConsumer pushConsumer_;
26
27     StructuredEvent[] event_;
28
29     int times_ = 1;
30
31     boolean error_ = false;
32
33     boolean connected_;
34
35     boolean eventSent_;
36
37     ORB JavaDoc orb_;
38
39     public SequencePushSender(ORB JavaDoc orb, StructuredEvent[] event)
40     {
41         orb_ = orb;
42         event_ = event;
43     }
44
45     public boolean isConnected()
46     {
47         return connected_;
48     }
49
50     public boolean isEventHandled()
51     {
52         return eventSent_;
53     }
54
55     public boolean isError()
56     {
57         return error_;
58     }
59
60     public void run()
61     {
62         for (int x = 0; x < times_; ++x)
63         {
64             try
65             {
66                 pushConsumer_.push_structured_events(event_);
67             } catch (Exception JavaDoc e)
68             {
69                 error_ = true;
70             }
71         }
72         eventSent_ = true;
73     }
74
75     public void disconnect_sequence_push_supplier()
76     {
77         connected_ = false;
78     }
79
80     public void subscription_change(EventType[] eventType, EventType[] eventType2)
81             throws InvalidEventType
82     {
83         // ignored
84
}
85
86     public void connect(EventChannel channel, boolean useOrSemantic) throws AdminLimitExceeded,
87             AlreadyConnected
88     {
89         SequencePushSupplierPOATie senderTie = new SequencePushSupplierPOATie(this);
90         SupplierAdmin supplierAdmin = channel.default_supplier_admin();
91         IntHolder JavaDoc _proxyIdHolder = new IntHolder JavaDoc();
92
93         pushConsumer_ = SequenceProxyPushConsumerHelper.narrow(supplierAdmin
94                 .obtain_notification_push_consumer(ClientType.SEQUENCE_EVENT, _proxyIdHolder));
95
96         Assert.assertEquals(ProxyType._PUSH_SEQUENCE, pushConsumer_.MyType().value());
97
98         pushConsumer_.connect_sequence_push_supplier(SequencePushSupplierHelper.narrow(senderTie
99                 ._this(orb_)));
100
101         connected_ = true;
102     }
103
104     public void shutdown()
105     {
106         pushConsumer_.disconnect_sequence_push_consumer();
107     }
108 }
109
Popular Tags