KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > servant > StructuredProxyPullSupplierImpl


1 package org.jacorb.notification.servant;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2004 Gerald Brose
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */

23
24 import java.util.List JavaDoc;
25
26 import org.apache.avalon.framework.configuration.Configuration;
27 import org.apache.avalon.framework.configuration.ConfigurationException;
28 import org.jacorb.notification.OfferManager;
29 import org.jacorb.notification.SubscriptionManager;
30 import org.jacorb.notification.engine.TaskProcessor;
31 import org.jacorb.notification.interfaces.Message;
32 import org.jacorb.notification.interfaces.MessageConsumer;
33 import org.jacorb.notification.util.CollectionsWrapper;
34 import org.omg.CORBA.BooleanHolder JavaDoc;
35 import org.omg.CORBA.ORB JavaDoc;
36 import org.omg.CosEventChannelAdmin.AlreadyConnected;
37 import org.omg.CosEventComm.Disconnected;
38 import org.omg.CosNotification.EventHeader;
39 import org.omg.CosNotification.EventType;
40 import org.omg.CosNotification.FixedEventHeader;
41 import org.omg.CosNotification.Property;
42 import org.omg.CosNotification.StructuredEvent;
43 import org.omg.CosNotifyChannelAdmin.ConsumerAdmin;
44 import org.omg.CosNotifyChannelAdmin.ProxySupplierHelper;
45 import org.omg.CosNotifyChannelAdmin.ProxyType;
46 import org.omg.CosNotifyChannelAdmin.StructuredProxyPullSupplierOperations;
47 import org.omg.CosNotifyChannelAdmin.StructuredProxyPullSupplierPOATie;
48 import org.omg.CosNotifyComm.StructuredPullConsumer;
49 import org.omg.PortableServer.POA JavaDoc;
50 import org.omg.PortableServer.Servant JavaDoc;
51
52 /**
53  * @author Alphonse Bendt
54  * @version $Id: StructuredProxyPullSupplierImpl.java,v 1.13 2005/04/27 10:45:46 alphonse.bendt Exp $
55  */

56
57 public class StructuredProxyPullSupplierImpl extends AbstractProxySupplier implements
58         StructuredProxyPullSupplierOperations
59 {
60     /**
61      * undefined StructuredEvent that is returned on unsuccessful pull operations.
62      */

63     protected static final StructuredEvent UNDEFINED_STRUCTURED_EVENT;
64
65     // initialize undefinedStructuredEvent_
66
static
67     {
68         ORB JavaDoc _orb = ORB.init();
69
70         UNDEFINED_STRUCTURED_EVENT = new StructuredEvent();
71         EventType _type = new EventType();
72         FixedEventHeader _fixed = new FixedEventHeader(_type, "");
73         Property[] _variable = new Property[0];
74         UNDEFINED_STRUCTURED_EVENT.header = new EventHeader(_fixed, _variable);
75         UNDEFINED_STRUCTURED_EVENT.filterable_data = new Property[0];
76         UNDEFINED_STRUCTURED_EVENT.remainder_of_body = _orb.create_any();
77     }
78
79     /**
80      * the associated Consumer.
81      */

82     private StructuredPullConsumer structuredPullConsumer_;
83
84     // //////////////////////////////////////
85

86     public StructuredProxyPullSupplierImpl(IAdmin admin, ORB JavaDoc orb, POA JavaDoc poa, Configuration conf,
87             TaskProcessor taskProcessor, OfferManager offerManager,
88             SubscriptionManager subscriptionManager, ConsumerAdmin consumerAdmin) throws ConfigurationException
89     {
90         super(admin, orb, poa, conf, taskProcessor, offerManager,
91                 subscriptionManager, consumerAdmin);
92     }
93
94     public ProxyType MyType()
95     {
96         return ProxyType.PULL_STRUCTURED;
97     }
98
99     public void connect_structured_pull_consumer(StructuredPullConsumer consumer)
100             throws AlreadyConnected
101     {
102         checkIsNotConnected();
103
104         connectClient(consumer);
105
106         structuredPullConsumer_ = consumer;
107
108         logger_.info("connect structured_pull_consumer");
109     }
110
111     public StructuredEvent pull_structured_event() throws Disconnected
112     {
113         checkStillConnected();
114
115         try
116         {
117             Message _message = getMessageBlocking();
118
119             try
120             {
121                 return _message.toStructuredEvent();
122             } finally
123             {
124                 _message.dispose();
125             }
126         } catch (InterruptedException JavaDoc e)
127         {
128             return UNDEFINED_STRUCTURED_EVENT;
129         }
130     }
131
132     public StructuredEvent try_pull_structured_event(BooleanHolder JavaDoc hasEvent) throws Disconnected
133     {
134         checkStillConnected();
135
136         Message _message = getMessageNoBlock();
137
138         if (_message != null)
139         {
140             try
141             {
142                 hasEvent.value = true;
143
144                 return _message.toStructuredEvent();
145             } finally
146             {
147                 _message.dispose();
148             }
149         }
150
151         hasEvent.value = false;
152
153         return UNDEFINED_STRUCTURED_EVENT;
154     }
155
156     public void disconnect_structured_pull_supplier()
157     {
158         destroy();
159     }
160
161     protected void disconnectClient()
162     {
163         logger_.info("disconnect structured_pull_consumer");
164
165         structuredPullConsumer_.disconnect_structured_pull_consumer();
166
167         structuredPullConsumer_ = null;
168     }
169
170     public List JavaDoc getSubsequentFilterStages()
171     {
172         return CollectionsWrapper.singletonList(this);
173     }
174
175     public MessageConsumer getMessageConsumer()
176     {
177         return this;
178     }
179
180     public void disableDelivery()
181     {
182         // as no active deliveries are made this can be ignored
183
}
184
185     public void enableDelivery()
186     {
187         // as no active deliveries are made this can be ignored
188
}
189
190     public void deliverPendingData()
191     {
192         // as no active deliveries are made this can be ignored
193
}
194
195     public synchronized Servant JavaDoc getServant()
196     {
197         if (thisServant_ == null)
198         {
199             thisServant_ = new StructuredProxyPullSupplierPOATie(this);
200         }
201
202         return thisServant_;
203     }
204
205     public org.omg.CORBA.Object JavaDoc activate()
206     {
207         return ProxySupplierHelper.narrow(getServant()._this_object(getORB()));
208     }
209    
210     protected long getCost()
211     {
212         return 0;
213     }
214 }
Popular Tags