KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jacorb.notification.servant;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2003 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.jacorb.notification.MessageFactory;
28 import org.jacorb.notification.OfferManager;
29 import org.jacorb.notification.SubscriptionManager;
30 import org.jacorb.notification.container.CORBAObjectComponentAdapter;
31 import org.jacorb.notification.interfaces.Disposable;
32 import org.jacorb.notification.interfaces.FilterStageSource;
33 import org.jacorb.notification.interfaces.MessageConsumer;
34 import org.jacorb.notification.util.CollectionsWrapper;
35 import org.omg.CORBA.BAD_PARAM JavaDoc;
36 import org.omg.CORBA.IntHolder JavaDoc;
37 import org.omg.CORBA.ORB JavaDoc;
38 import org.omg.CORBA.UNKNOWN JavaDoc;
39 import org.omg.CosEventChannelAdmin.ProxyPullConsumer;
40 import org.omg.CosEventChannelAdmin.ProxyPushConsumer;
41 import org.omg.CosNotification.EventType;
42 import org.omg.CosNotifyChannelAdmin.AdminLimitExceeded;
43 import org.omg.CosNotifyChannelAdmin.ClientType;
44 import org.omg.CosNotifyChannelAdmin.ProxyConsumer;
45 import org.omg.CosNotifyChannelAdmin.ProxyConsumerHelper;
46 import org.omg.CosNotifyChannelAdmin.ProxyNotFound;
47 import org.omg.CosNotifyChannelAdmin.SupplierAdmin;
48 import org.omg.CosNotifyChannelAdmin.SupplierAdminHelper;
49 import org.omg.CosNotifyChannelAdmin.SupplierAdminOperations;
50 import org.omg.CosNotifyChannelAdmin.SupplierAdminPOATie;
51 import org.omg.CosNotifyComm.InvalidEventType;
52 import org.omg.PortableServer.POA JavaDoc;
53 import org.omg.PortableServer.Servant JavaDoc;
54 import org.picocontainer.MutablePicoContainer;
55 import org.picocontainer.defaults.CachingComponentAdapter;
56
57 /**
58  * @author Alphonse Bendt
59  * @version $Id: SupplierAdminImpl.java,v 1.6 2005/04/10 14:28:58 alphonse.bendt Exp $
60  */

61
62 public class SupplierAdminImpl extends AbstractSupplierAdmin implements SupplierAdminOperations,
63         Disposable
64 {
65     private FilterStageSource subsequentFilterStagesSource_;
66
67     private final Servant JavaDoc thisServant_;
68
69     private final SupplierAdmin thisCorbaRef_;
70
71     ////////////////////////////////////////
72

73     public SupplierAdminImpl(IEventChannel channelServant, ORB JavaDoc orb, POA JavaDoc poa, Configuration config,
74             MessageFactory messageFactory, OfferManager offerManager,
75             SubscriptionManager subscriptionManager)
76     {
77         super(channelServant, orb, poa, config, messageFactory, offerManager, subscriptionManager);
78
79         thisServant_ = createServant();
80
81         thisCorbaRef_ = SupplierAdminHelper.narrow(getServant()._this_object(getORB()));
82
83         container_.registerComponent(new CachingComponentAdapter(new CORBAObjectComponentAdapter(
84                 SupplierAdmin.class, thisCorbaRef_)));
85
86         addDisposeHook(new Disposable()
87         {
88             public void dispose()
89             {
90                 container_.unregisterComponent(SupplierAdmin.class);
91             }
92         });
93     }
94
95     protected Servant JavaDoc createServant()
96     {
97         return new SupplierAdminPOATie(this);
98     }
99
100     public Servant JavaDoc getServant()
101     {
102         return thisServant_;
103     }
104
105     public org.omg.CORBA.Object JavaDoc activate()
106     {
107         return thisCorbaRef_;
108     }
109
110     public void offer_change(EventType[] added, EventType[] removed) throws InvalidEventType
111     {
112         offerManager_.offer_change(added, removed);
113     }
114
115     /**
116      * access the ids of all PullConsumers (NotifyStyle)
117      */

118     public int[] pull_consumers()
119     {
120         return get_all_notify_proxies(pullServants_, modifyProxiesLock_);
121     }
122
123     /**
124      * access the ids of all PushConsumers (NotifyStyle)
125      */

126     public int[] push_consumers()
127     {
128         return get_all_notify_proxies(pushServants_, modifyProxiesLock_);
129     }
130
131     public ProxyConsumer obtain_notification_pull_consumer(ClientType clientType,
132             IntHolder JavaDoc intHolder) throws AdminLimitExceeded
133     {
134         fireCreateProxyRequestEvent();
135
136         try
137         {
138             AbstractProxy _servant = obtain_notification_pull_consumer_servant(clientType);
139
140             intHolder.value = _servant.getID().intValue();
141
142             return ProxyConsumerHelper.narrow(_servant.activate());
143         } catch (Exception JavaDoc e)
144         {
145             logger_.fatalError("obtain_notification_pull_consumer: unexpected error", e);
146
147             throw new UNKNOWN JavaDoc();
148         }
149     }
150
151     private AbstractProxy obtain_notification_pull_consumer_servant(ClientType clientType)
152             throws Exception JavaDoc
153     {
154         AbstractProxy _servant = newProxyPullConsumer(clientType);
155
156         configureInterFilterGroupOperator(_servant);
157
158         configureQoS(_servant);
159
160         addProxyToMap(_servant, pullServants_, modifyProxiesLock_);
161
162         return _servant;
163     }
164
165     public ProxyConsumer get_proxy_consumer(int id) throws ProxyNotFound
166     {
167         return ProxyConsumerHelper.narrow(getProxy(id).activate());
168     }
169
170     public ProxyConsumer obtain_notification_push_consumer(ClientType clienttype,
171             IntHolder JavaDoc intHolder) throws AdminLimitExceeded
172     {
173         // may throws AdminLimitExceeded
174
fireCreateProxyRequestEvent();
175
176         try
177         {
178             AbstractProxy _servant = obtain_notification_push_consumer_servant(clienttype);
179
180             intHolder.value = _servant.getID().intValue();
181
182             return ProxyConsumerHelper.narrow(_servant.activate());
183         } catch (Exception JavaDoc e)
184         {
185             logger_.fatalError("obtain_notification_push_consumer: unexpected error", e);
186
187             throw new UNKNOWN JavaDoc();
188         }
189     }
190
191     private AbstractProxy obtain_notification_push_consumer_servant(ClientType clientType)
192             throws Exception JavaDoc
193     {
194         AbstractProxy _servant = newProxyPushConsumer(clientType);
195
196         configureInterFilterGroupOperator(_servant);
197
198         configureQoS(_servant);
199
200         addProxyToMap(_servant, pushServants_, modifyProxiesLock_);
201
202         return _servant;
203     }
204
205     /**
206      * get a ProxyPushConsumer (EventService Style)
207      */

208     public ProxyPushConsumer obtain_push_consumer()
209     {
210         try
211         {
212             MutablePicoContainer _container = newContainerForEventStyleProxy();
213
214             _container.registerComponent(newComponentAdapter(ECProxyPushConsumerImpl.class,
215                     ECProxyPushConsumerImpl.class));
216
217             AbstractProxyConsumer _servant = (AbstractProxyConsumer) _container
218                     .getComponentInstance(ECProxyPushConsumerImpl.class);
219
220             _servant.setSubsequentDestinations(CollectionsWrapper.singletonList(this));
221
222             addProxyToMap(_servant, pushServants_, modifyProxiesLock_);
223
224             return org.omg.CosEventChannelAdmin.ProxyPushConsumerHelper.narrow(_servant.activate());
225         } catch (Exception JavaDoc e)
226         {
227             logger_.fatalError("obtain_push_consumer: unexpected error", e);
228
229             throw new UNKNOWN JavaDoc();
230         }
231     }
232
233     /**
234      * get a ProxyPullConsumer (EventService Style)
235      */

236     public ProxyPullConsumer obtain_pull_consumer()
237     {
238         try
239         {
240             MutablePicoContainer _container = newContainerForEventStyleProxy();
241
242             _container.registerComponent(newComponentAdapter(ECProxyPullConsumerImpl.class,
243                     ECProxyPullConsumerImpl.class));
244
245             AbstractProxyConsumer _servant = (AbstractProxyConsumer) _container
246                     .getComponentInstance(ECProxyPullConsumerImpl.class);
247
248             _servant.setSubsequentDestinations(CollectionsWrapper.singletonList(this));
249
250             addProxyToMap(_servant, pushServants_, modifyProxiesLock_);
251
252             _servant.set_qos(get_qos());
253
254             return org.omg.CosEventChannelAdmin.ProxyPullConsumerHelper.narrow(_servant.activate());
255         } catch (Exception JavaDoc e)
256         {
257             logger_.fatalError("obtain_pull_consumer: unexpected error", e);
258
259             throw new UNKNOWN JavaDoc();
260         }
261     }
262
263     ////////////////////////////////////////
264

265     public List JavaDoc getSubsequentFilterStages()
266     {
267         return subsequentFilterStagesSource_.getSubsequentFilterStages();
268     }
269
270     public void setSubsequentFilterStageSource(FilterStageSource source)
271     {
272         subsequentFilterStagesSource_ = source;
273     }
274
275     /**
276      * SupplierAdmin does not ever have a MessageConsumer.
277      */

278     public MessageConsumer getMessageConsumer()
279     {
280         throw new UnsupportedOperationException JavaDoc();
281     }
282
283     /**
284      * SupplierAdmin does not ever have a MessageConsumer.
285      */

286     public boolean hasMessageConsumer()
287     {
288         return false;
289     }
290
291     public boolean hasInterFilterGroupOperatorOR()
292     {
293         return false;
294     }
295
296     /**
297      * factory method to create new ProxyPullConsumerServants.
298      */

299     AbstractProxy newProxyPullConsumer(ClientType clientType)
300     {
301         final AbstractProxyConsumer _servant;
302
303         final Class JavaDoc _clazz;
304
305         switch (clientType.value()) {
306         case ClientType._ANY_EVENT:
307             _clazz = ProxyPullConsumerImpl.class;
308             break;
309         case ClientType._STRUCTURED_EVENT:
310             _clazz = StructuredProxyPullConsumerImpl.class;
311             break;
312         case ClientType._SEQUENCE_EVENT:
313             _clazz = SequenceProxyPullConsumerImpl.class;
314             break;
315         default:
316             throw new BAD_PARAM JavaDoc("Invalid ClientType: ClientType." + clientType.value());
317         }
318
319         final MutablePicoContainer _containerForProxy = newContainerForNotifyStyleProxy();
320
321         _containerForProxy.registerComponent(newComponentAdapter(AbstractProxyConsumer.class,
322                 _clazz));
323
324         _servant = (AbstractProxyConsumer) _containerForProxy
325                 .getComponentInstance(AbstractProxyConsumer.class);
326
327         _servant.setSubsequentDestinations(CollectionsWrapper.singletonList(this));
328
329         return _servant;
330     }
331
332     /**
333      * factory method to create new ProxyPushConsumerServants.
334      */

335     AbstractProxy newProxyPushConsumer(ClientType clientType)
336     {
337         final AbstractProxyConsumer _servant;
338
339         final Class JavaDoc _proxyClazz;
340
341         switch (clientType.value()) {
342         case ClientType._ANY_EVENT:
343             _proxyClazz = ProxyPushConsumerImpl.class;
344             break;
345         case ClientType._STRUCTURED_EVENT:
346             _proxyClazz = StructuredProxyPushConsumerImpl.class;
347             break;
348         case ClientType._SEQUENCE_EVENT:
349             _proxyClazz = SequenceProxyPushConsumerImpl.class;
350             break;
351         default:
352             throw new BAD_PARAM JavaDoc("Invalid ClientType: ClientType." + clientType.value());
353         }
354
355         final MutablePicoContainer _containerForProxy = newContainerForNotifyStyleProxy();
356
357         _containerForProxy.registerComponent(newComponentAdapter(AbstractProxyConsumer.class,
358                 _proxyClazz));
359
360         _servant = (AbstractProxyConsumer) _containerForProxy
361                 .getComponentInstance(AbstractProxyConsumer.class);
362
363         _servant.setSubsequentDestinations(CollectionsWrapper.singletonList(this));
364
365         return _servant;
366     }
367 }
Popular Tags