001: package org.jacorb.notification;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1997-2004 Gerald Brose.
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Library General Public License for more details.
017: *
018: * You should have received a copy of the GNU Library General Public
019: * License along with this library; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: */
022:
023: import org.apache.avalon.framework.configuration.Configuration;
024: import org.jacorb.notification.container.PicoContainerFactory;
025: import org.jacorb.notification.servant.AbstractAdmin;
026: import org.jacorb.notification.servant.AbstractSupplierAdmin;
027: import org.jacorb.notification.servant.ConsumerAdminImpl;
028: import org.jacorb.notification.servant.IEventChannel;
029: import org.jacorb.notification.servant.SupplierAdminImpl;
030: import org.omg.CORBA.IntHolder;
031: import org.omg.CORBA.ORB;
032: import org.omg.CosNotifyChannelAdmin.AdminNotFound;
033: import org.omg.CosNotifyChannelAdmin.ConsumerAdmin;
034: import org.omg.CosNotifyChannelAdmin.ConsumerAdminHelper;
035: import org.omg.CosNotifyChannelAdmin.EventChannel;
036: import org.omg.CosNotifyChannelAdmin.EventChannelFactory;
037: import org.omg.CosNotifyChannelAdmin.EventChannelHelper;
038: import org.omg.CosNotifyChannelAdmin.EventChannelOperations;
039: import org.omg.CosNotifyChannelAdmin.EventChannelPOATie;
040: import org.omg.CosNotifyChannelAdmin.InterFilterGroupOperator;
041: import org.omg.CosNotifyChannelAdmin.SupplierAdmin;
042: import org.omg.CosNotifyChannelAdmin.SupplierAdminHelper;
043: import org.omg.CosNotifyFilter.FilterFactory;
044: import org.omg.PortableServer.POA;
045: import org.omg.PortableServer.Servant;
046: import org.picocontainer.MutablePicoContainer;
047:
048: /**
049: * @jmx.mbean name="EventChannelMBean" description="Control an EventChannel"
050: * extends = "AbstractEventChannelMBean"
051: *
052: * @jboss.xmbean
053: *
054: * @author Alphonse Bendt
055: * @version $Id: EventChannelImpl.java,v 1.35 2006/05/23 10:40:35 alphonse.bendt Exp $
056: */
057:
058: public class EventChannelImpl extends AbstractEventChannel implements
059: EventChannelOperations, EventChannelImplMBean {
060: private final EventChannelFactory eventChannelFactory_;
061:
062: private final EventChannel this Ref_;
063:
064: ////////////////////////////////////////
065:
066: public EventChannelImpl(IFactory factory, ORB orb, POA poa,
067: Configuration config, FilterFactory filterFactory,
068: EventChannelFactory factoryRef) {
069: super (factory, orb, poa, config, filterFactory);
070:
071: eventChannelFactory_ = factoryRef;
072:
073: this Ref_ = EventChannelHelper.narrow(activate());
074: }
075:
076: public Servant newServant() {
077: return new EventChannelPOATie(this );
078: }
079:
080: protected AbstractAdmin newConsumerAdmin(final int id) {
081: final MutablePicoContainer _adminContainer = newContainerForAdmin(id);
082:
083: _adminContainer.registerComponentImplementation(
084: AbstractAdmin.class, ConsumerAdminImpl.class);
085:
086: return (AbstractAdmin) _adminContainer
087: .getComponentInstanceOfType(AbstractAdmin.class);
088: }
089:
090: protected AbstractSupplierAdmin newSupplierAdmin(final int id) {
091: final MutablePicoContainer _adminContainer = newContainerForAdmin(id);
092:
093: _adminContainer.registerComponentImplementation(
094: AbstractSupplierAdmin.class, SupplierAdminImpl.class);
095:
096: return (AbstractSupplierAdmin) _adminContainer
097: .getComponentInstanceOfType(AbstractSupplierAdmin.class);
098: }
099:
100: private MutablePicoContainer newContainerForAdmin(final int id) {
101: final MutablePicoContainer _adminContainer = PicoContainerFactory
102: .createChildContainer(container_);
103:
104: final IEventChannel _channelAdapter = new IEventChannel() {
105: public int getAdminID() {
106: return id;
107: }
108:
109: public EventChannel getEventChannel() {
110: return this Ref_;
111: }
112:
113: public int getChannelID() {
114: return EventChannelImpl.this .getID();
115: }
116:
117: public MutablePicoContainer getContainer() {
118: return _adminContainer;
119: }
120:
121: public String getChannelMBean() {
122: return getJMXObjectName();
123: }
124:
125: public void destroy() {
126: _adminContainer
127: .unregisterComponent(IEventChannel.class);
128:
129: container_.removeChildContainer(_adminContainer);
130: }
131: };
132:
133: _adminContainer.registerComponentInstance(IEventChannel.class,
134: _channelAdapter);
135: return _adminContainer;
136: }
137:
138: /**
139: * The MyFactory attribute is a readonly attribute that maintains the object reference of the
140: * event channel factory, which created a given Notification Service EventChannel instance.
141: */
142: public EventChannelFactory MyFactory() {
143: return eventChannelFactory_;
144: }
145:
146: /**
147: * The default_consumer_admin attribute is a readonly attribute that maintains a reference to
148: * the default ConsumerAdmin instance associated with the target EventChannel instance. Each
149: * EventChannel instance has an associated default ConsumerAdmin instance, which exists upon
150: * creation of the channel and is assigned the unique identifier of zero. Subsequently, clients
151: * can create additional Event Service style ConsumerAdmin instances by invoking the inherited
152: * operation, and additional Notification Service style ConsumerAdmin instances by invoking the
153: * new_for_consumers operation defined by the EventChannel interface.
154: */
155: public ConsumerAdmin default_consumer_admin() {
156: return ConsumerAdminHelper
157: .narrow(getDefaultConsumerAdminServant().activate());
158: }
159:
160: /**
161: * The default_supplier_admin attribute is a readonly attribute that maintains a reference to
162: * the default SupplierAdmin instance associated with the target EventChannel instance. Each
163: * EventChannel instance has an associated default SupplierAdmin instance, which exists upon
164: * creation of the channel and is assigned the unique identifier of zero. Subsequently, clients
165: * can create additional Event Service style SupplierAdmin instances by invoking the inherited
166: * for_suppliers operation, and additional Notification Service style SupplierAdmin instances by
167: * invoking the new_for_suppliers operation defined by the EventChannel interface.
168: */
169: public SupplierAdmin default_supplier_admin() {
170: return SupplierAdminHelper
171: .narrow(getDefaultSupplierAdminServant().activate());
172: }
173:
174: /**
175: * The new_for_consumers operation is invoked to create a new Notification Service style
176: * ConsumerAdmin instance. The operation accepts as an input parameter a boolean flag, which
177: * indicates whether AND or OR semantics will be used when combining the filter objects
178: * associated with the newly created ConsumerAdmin instance with those associated with a
179: * supplier proxy, which was created by the ConsumerAdmin during the evaluation of each event
180: * against a set of filter objects. The new instance is assigned a unique identifier by the
181: * target EventChannel instance that is unique among all ConsumerAdmin instances currently
182: * associated with the channel. Upon completion, the operation returns the reference to the new
183: * ConsumerAdmin instance as the result of the operation, and the unique identifier assigned to
184: * the new ConsumerAdmin instance as the output parameter.
185: */
186: public ConsumerAdmin new_for_consumers(
187: InterFilterGroupOperator filterGroupOperator,
188: IntHolder intHolder) {
189: final AbstractAdmin _adminServant = new_for_consumers_servant(
190: filterGroupOperator, intHolder);
191:
192: return ConsumerAdminHelper.narrow(_adminServant.activate());
193: }
194:
195: public SupplierAdmin new_for_suppliers(
196: InterFilterGroupOperator filterGroupOperator,
197: IntHolder intHolder) {
198: final AbstractAdmin _adminServant = new_for_suppliers_servant(
199: filterGroupOperator, intHolder);
200:
201: return SupplierAdminHelper.narrow(_adminServant.activate());
202: }
203:
204: public ConsumerAdmin get_consumeradmin(int identifier)
205: throws AdminNotFound {
206: return ConsumerAdminHelper.narrow(get_consumeradmin_internal(
207: identifier).activate());
208: }
209:
210: public SupplierAdmin get_supplieradmin(int identifier)
211: throws AdminNotFound {
212: return SupplierAdminHelper.narrow(get_supplieradmin_internal(
213: identifier).activate());
214: }
215:
216: /**
217: * Return the consumerAdmin interface (event style)
218: */
219: public org.omg.CosEventChannelAdmin.ConsumerAdmin for_consumers() {
220: final AbstractAdmin _admin = getDefaultConsumerAdminServant();
221:
222: return org.omg.CosEventChannelAdmin.ConsumerAdminHelper
223: .narrow(_admin.activate());
224: }
225:
226: /**
227: * Return the supplierAdmin interface (event style)
228: */
229: public org.omg.CosEventChannelAdmin.SupplierAdmin for_suppliers() {
230: final AbstractAdmin _admin = getDefaultSupplierAdminServant();
231:
232: return org.omg.CosEventChannelAdmin.SupplierAdminHelper
233: .narrow(_admin.activate());
234: }
235:
236: public String getMBeanType() {
237: return "EventChannel";
238: }
239:
240: /**
241: * @jmx.managed-attribute access = "read-only"
242: * currencyTimeLimit = "2147483647"
243: */
244: public String getIOR() {
245: return orb_.object_to_string(thisRef_);
246: }
247: }
|