KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > EventChannelImpl


1 package org.jacorb.notification;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-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 import org.apache.avalon.framework.configuration.Configuration;
24 import org.jacorb.notification.container.PicoContainerFactory;
25 import org.jacorb.notification.container.CORBAObjectComponentAdapter;
26 import org.jacorb.notification.interfaces.Disposable;
27 import org.jacorb.notification.servant.AbstractAdmin;
28 import org.jacorb.notification.servant.AbstractSupplierAdmin;
29 import org.jacorb.notification.servant.ConsumerAdminImpl;
30 import org.jacorb.notification.servant.IEventChannel;
31 import org.jacorb.notification.servant.SupplierAdminImpl;
32 import org.omg.CORBA.IntHolder JavaDoc;
33 import org.omg.CORBA.ORB JavaDoc;
34 import org.omg.CosNotifyChannelAdmin.AdminNotFound;
35 import org.omg.CosNotifyChannelAdmin.ConsumerAdmin;
36 import org.omg.CosNotifyChannelAdmin.ConsumerAdminHelper;
37 import org.omg.CosNotifyChannelAdmin.EventChannel;
38 import org.omg.CosNotifyChannelAdmin.EventChannelFactory;
39 import org.omg.CosNotifyChannelAdmin.EventChannelHelper;
40 import org.omg.CosNotifyChannelAdmin.EventChannelOperations;
41 import org.omg.CosNotifyChannelAdmin.EventChannelPOATie;
42 import org.omg.CosNotifyChannelAdmin.InterFilterGroupOperator;
43 import org.omg.CosNotifyChannelAdmin.SupplierAdmin;
44 import org.omg.CosNotifyChannelAdmin.SupplierAdminHelper;
45 import org.omg.CosNotifyFilter.FilterFactory;
46 import org.omg.PortableServer.POA JavaDoc;
47 import org.omg.PortableServer.Servant JavaDoc;
48 import org.picocontainer.ComponentAdapter;
49 import org.picocontainer.MutablePicoContainer;
50 import org.picocontainer.defaults.CachingComponentAdapter;
51 import org.picocontainer.defaults.ComponentAdapterFactory;
52
53 /**
54  * @author Alphonse Bendt
55  * @version $Id: EventChannelImpl.java,v 1.28 2005/05/04 13:59:48 alphonse.bendt Exp $
56  */

57
58 public class EventChannelImpl extends AbstractEventChannel implements EventChannelOperations
59 {
60     private final EventChannelFactory eventChannelFactory_;
61
62     private final EventChannel thisRef_;
63
64     private final Servant JavaDoc thisServant_;
65
66     private final ComponentAdapterFactory adapterFactory_;
67
68     ////////////////////////////////////////
69

70     public EventChannelImpl(IFactory factory, ORB JavaDoc orb, POA JavaDoc poa, Configuration config,
71             FilterFactory filterFactory, EventChannelFactory factoryRef)
72     {
73         super(factory, orb, poa, config, filterFactory);
74
75         eventChannelFactory_ = factoryRef;
76
77         thisServant_ = new EventChannelPOATie(this);
78
79         thisRef_ = EventChannelHelper.narrow(thisServant_._this_object(orb_));
80
81         container_.registerComponent(new CORBAObjectComponentAdapter(EventChannel.class,
82                 EventChannelHelper.narrow(thisRef_)));
83
84         adapterFactory_ = (ComponentAdapterFactory) container_
85                 .getComponentInstance(ComponentAdapterFactory.class);
86
87         logger_.info("Creating Default Admins");
88         default_consumer_admin();
89         default_supplier_admin();
90
91         duringConstruction_ = false;
92
93         addDisposeHook(new Disposable()
94         {
95             public void dispose()
96             {
97                 container_.unregisterComponent(EventChannel.class);
98             }
99         });
100     }
101
102     protected Servant JavaDoc getServant()
103     {
104         return thisServant_;
105     }
106
107     public synchronized org.omg.CORBA.Object JavaDoc activate()
108     {
109         return thisRef_;
110     }
111
112     protected AbstractAdmin newConsumerAdmin(final int id)
113     {
114         final MutablePicoContainer _adminContainer = newContainerForAdmin(id);
115
116         ComponentAdapter _consumerAdminAdapter = adapterFactory_.createComponentAdapter(
117                 ConsumerAdminImpl.class, ConsumerAdminImpl.class, null);
118
119         _adminContainer.registerComponent(new CachingComponentAdapter(_consumerAdminAdapter));
120
121         AbstractAdmin _admin = (AbstractAdmin) _adminContainer
122                 .getComponentInstance(ConsumerAdminImpl.class);
123
124         return _admin;
125     }
126
127     protected AbstractSupplierAdmin newSupplierAdmin(final int id)
128     {
129         final MutablePicoContainer _adminContainer = newContainerForAdmin(id);
130
131         ComponentAdapter _supplierAdminAdapter = adapterFactory_.createComponentAdapter(
132                 SupplierAdminImpl.class, SupplierAdminImpl.class, null);
133
134         _adminContainer.registerComponent(new CachingComponentAdapter(_supplierAdminAdapter));
135
136         SupplierAdminImpl _admin = (SupplierAdminImpl) _adminContainer
137                 .getComponentInstance(SupplierAdminImpl.class);
138
139         return _admin;
140     }
141
142     private MutablePicoContainer newContainerForAdmin(final int id)
143     {
144         final MutablePicoContainer _adminContainer = PicoContainerFactory
145                 .createChildContainer(container_);
146         
147         IEventChannel _channelAdapter = new IEventChannel()
148         {
149             public int getAdminID()
150             {
151                 return id;
152             }
153
154             public EventChannel getEventChannel()
155             {
156                 return (EventChannel) _adminContainer.getComponentInstanceOfType(EventChannel.class);
157             }
158
159             public int getChannelID()
160             {
161                 return EventChannelImpl.this.getID();
162             }
163
164             public MutablePicoContainer getContainer()
165             {
166                 return _adminContainer;
167             }
168
169             public void destroy()
170             {
171                 _adminContainer.unregisterComponent(IEventChannel.class);
172
173                 container_.removeChildContainer(_adminContainer);
174             }
175         };
176         
177         _adminContainer.registerComponentInstance(IEventChannel.class, _channelAdapter);
178         return _adminContainer;
179     }
180     
181     /**
182      * The MyFactory attribute is a readonly attribute that maintains the object reference of the
183      * event channel factory, which created a given Notification Service EventChannel instance.
184      */

185     public EventChannelFactory MyFactory()
186     {
187         return eventChannelFactory_;
188     }
189
190     /**
191      * The default_consumer_admin attribute is a readonly attribute that maintains a reference to
192      * the default ConsumerAdmin instance associated with the target EventChannel instance. Each
193      * EventChannel instance has an associated default ConsumerAdmin instance, which exists upon
194      * creation of the channel and is assigned the unique identifier of zero. Subsequently, clients
195      * can create additional Event Service style ConsumerAdmin instances by invoking the inherited
196      * operation, and additional Notification Service style ConsumerAdmin instances by invoking the
197      * new_for_consumers operation defined by the EventChannel interface.
198      */

199     public ConsumerAdmin default_consumer_admin()
200     {
201         return ConsumerAdminHelper.narrow(getDefaultConsumerAdminServant().activate());
202     }
203
204     /**
205      * The default_supplier_admin attribute is a readonly attribute that maintains a reference to
206      * the default SupplierAdmin instance associated with the target EventChannel instance. Each
207      * EventChannel instance has an associated default SupplierAdmin instance, which exists upon
208      * creation of the channel and is assigned the unique identifier of zero. Subsequently, clients
209      * can create additional Event Service style SupplierAdmin instances by invoking the inherited
210      * for_suppliers operation, and additional Notification Service style SupplierAdmin instances by
211      * invoking the new_for_suppliers operation defined by the EventChannel interface.
212      */

213     public SupplierAdmin default_supplier_admin()
214     {
215         return SupplierAdminHelper.narrow(getDefaultSupplierAdminServant().activate());
216     }
217
218     /**
219      * The new_for_consumers operation is invoked to create a new Notification Service style
220      * ConsumerAdmin instance. The operation accepts as an input parameter a boolean flag, which
221      * indicates whether AND or OR semantics will be used when combining the filter objects
222      * associated with the newly created ConsumerAdmin instance with those associated with a
223      * supplier proxy, which was created by the ConsumerAdmin during the evaluation of each event
224      * against a set of filter objects. The new instance is assigned a unique identifier by the
225      * target EventChannel instance that is unique among all ConsumerAdmin instances currently
226      * associated with the channel. Upon completion, the operation returns the reference to the new
227      * ConsumerAdmin instance as the result of the operation, and the unique identifier assigned to
228      * the new ConsumerAdmin instance as the output parameter.
229      */

230     public ConsumerAdmin new_for_consumers(InterFilterGroupOperator filterGroupOperator,
231             IntHolder JavaDoc intHolder)
232     {
233         AbstractAdmin _consumerAdminTieImpl = new_for_consumers_servant(filterGroupOperator,
234                 intHolder);
235
236         return ConsumerAdminHelper.narrow(_consumerAdminTieImpl.activate());
237     }
238
239     public SupplierAdmin new_for_suppliers(InterFilterGroupOperator filterGroupOperator,
240             IntHolder JavaDoc intHolder)
241     {
242         AbstractAdmin _supplierAdmin = new_for_suppliers_servant(filterGroupOperator, intHolder);
243
244         return SupplierAdminHelper.narrow(_supplierAdmin.activate());
245     }
246
247     public ConsumerAdmin get_consumeradmin(int identifier) throws AdminNotFound
248     {
249         return ConsumerAdminHelper.narrow(get_consumeradmin_internal(identifier).activate());
250     }
251
252     public SupplierAdmin get_supplieradmin(int identifier) throws AdminNotFound
253     {
254         return SupplierAdminHelper.narrow(get_supplieradmin_internal(identifier).activate());
255     }
256
257     /**
258      * Return the consumerAdmin interface (event style)
259      */

260     public org.omg.CosEventChannelAdmin.ConsumerAdmin for_consumers()
261     {
262         AbstractAdmin _admin = getDefaultConsumerAdminServant();
263
264         return org.omg.CosEventChannelAdmin.ConsumerAdminHelper.narrow(_admin.activate());
265     }
266
267     /**
268      * Return the supplierAdmin interface (event style)
269      */

270     public org.omg.CosEventChannelAdmin.SupplierAdmin for_suppliers()
271     {
272         AbstractAdmin _admin = getDefaultSupplierAdminServant();
273
274         return org.omg.CosEventChannelAdmin.SupplierAdminHelper.narrow(_admin.activate());
275     }
276 }
277
278
Popular Tags