KickJava   Java API By Example, From Geeks To Geeks.

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


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.CosEventChannelAdmin.TypeError;
10 import org.omg.CosEventComm.Disconnected;
11 import org.omg.CosNotification.EventType;
12 import org.omg.CosNotification.StructuredEvent;
13 import org.omg.CosNotifyChannelAdmin.AdminLimitExceeded;
14 import org.omg.CosNotifyChannelAdmin.AdminNotFound;
15 import org.omg.CosNotifyChannelAdmin.ClientType;
16 import org.omg.CosNotifyChannelAdmin.EventChannel;
17 import org.omg.CosNotifyChannelAdmin.ProxyType;
18 import org.omg.CosNotifyChannelAdmin.StructuredProxyPullConsumer;
19 import org.omg.CosNotifyChannelAdmin.StructuredProxyPullConsumerHelper;
20 import org.omg.CosNotifyChannelAdmin.SupplierAdmin;
21 import org.omg.CosNotifyComm.InvalidEventType;
22 import org.omg.CosNotifyComm.StructuredPullSupplierHelper;
23 import org.omg.CosNotifyComm.StructuredPullSupplierOperations;
24 import org.omg.CosNotifyComm.StructuredPullSupplierPOATie;
25
26 /**
27  * @author Alphonse Bendt
28  * @version $Id: StructuredPullSender.java,v 1.7 2005/05/01 21:14:29 alphonse.bendt Exp $
29  */

30
31 public class StructuredPullSender extends Thread JavaDoc implements StructuredPullSupplierOperations,
32         TestClientOperations
33 {
34     ORB JavaDoc orb_;
35
36     StructuredEvent event_;
37
38     StructuredProxyPullConsumer pullConsumer_;
39
40     private boolean error_;
41
42     boolean connected_;
43
44     boolean eventHandled_;
45
46     boolean available_;
47
48     public boolean isError()
49     {
50         return error_;
51     }
52
53     public boolean isEventHandled()
54     {
55         return eventHandled_;
56     }
57
58     public StructuredPullSender(ORB JavaDoc orb, StructuredEvent event)
59     {
60         event_ = event;
61         orb_ = orb;
62     }
63
64     public void run()
65     {
66         synchronized (this)
67         {
68             available_ = true;
69         }
70     }
71
72     // Implementation of org.omg.CosNotifyComm.NotifySubscribeOperations
73

74     public void subscription_change(EventType[] eventType1, EventType[] eventType2)
75             throws InvalidEventType
76     {
77         // ignored
78
}
79
80     // Implementation of org.omg.CosNotifyComm.StructuredPullSupplierOperations
81

82     /**
83      * Describe <code>pull_structured_event</code> method here.
84      *
85      * @return a <code>StructuredEvent</code> value
86      * @exception Disconnected
87      * if an error occurs
88      */

89     public StructuredEvent pull_structured_event() throws Disconnected
90     {
91         BooleanHolder JavaDoc _success = new BooleanHolder JavaDoc();
92         StructuredEvent _event;
93         while (true)
94         {
95             _event = try_pull_structured_event(_success);
96             if (_success.value)
97             {
98                 return _event;
99             }
100             Thread.yield();
101         }
102     }
103
104     /**
105      * Describe <code>try_pull_structured_event</code> method here.
106      *
107      * @param booleanHolder
108      * a <code>BooleanHolder</code> value
109      * @return a <code>StructuredEvent</code> value
110      * @exception Disconnected
111      * if an error occurs
112      */

113     public StructuredEvent try_pull_structured_event(BooleanHolder JavaDoc booleanHolder)
114             throws Disconnected
115     {
116         booleanHolder.value = false;
117         StructuredEvent _result = NotificationTestUtils.getInvalidStructuredEvent(orb_);
118         if (event_ != null)
119         {
120             synchronized (this)
121             {
122                 if (event_ != null && available_)
123                 {
124                     _result = event_;
125                     event_ = null;
126                     booleanHolder.value = true;
127                     eventHandled_ = true;
128                 }
129             }
130         }
131         return _result;
132     }
133
134     /**
135      * Describe <code>disconnect_structured_pull_supplier</code> method here.
136      *
137      */

138     public void disconnect_structured_pull_supplier()
139     {
140         connected_ = false;
141     }
142
143     public void connect(EventChannel channel, boolean useOrSemantic) throws AdminLimitExceeded,
144             AlreadyConnected, TypeError, AdminNotFound
145     {
146         StructuredPullSupplierPOATie _senderTie = new StructuredPullSupplierPOATie(this);
147         SupplierAdmin _supplierAdmin = channel.default_supplier_admin();
148         IntHolder JavaDoc _proxyId = new IntHolder JavaDoc();
149         pullConsumer_ = StructuredProxyPullConsumerHelper.narrow(_supplierAdmin
150                 .obtain_notification_pull_consumer(ClientType.STRUCTURED_EVENT, _proxyId));
151
152         Assert.assertEquals(_supplierAdmin, channel.get_supplieradmin(_supplierAdmin.MyID()));
153
154         Assert.assertEquals(pullConsumer_.MyType(), ProxyType.PULL_STRUCTURED);
155
156         pullConsumer_.connect_structured_pull_supplier(StructuredPullSupplierHelper
157                 .narrow(_senderTie._this(orb_)));
158         connected_ = true;
159     }
160
161     public void shutdown()
162     {
163         pullConsumer_.disconnect_structured_pull_consumer();
164         Assert.assertTrue(pullConsumer_._non_existent());
165     }
166
167     public boolean isConnected()
168     {
169         return connected_;
170     }
171
172 }
173
Popular Tags