001: package org.jacorb.events;
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.omg.CosEventComm.*;
024: import org.omg.CosEventChannelAdmin.*;
025: import org.omg.PortableServer.*;
026: import org.omg.CORBA.*;
027: import org.jacorb.orb.*;
028:
029: /**
030: * Implementation of COSEventChannelAdmin interface; ProxyPushConsumer.
031: * This defines connect_push_supplier(), disconnect_push_consumer() and the all
032: * important push() method that the Supplier can call to actuall deliver a
033: * message.
034: *
035: * 2002/23/08 JFC OMG EventService Specification 1.1 page 2-7 states:
036: * "Registration is a two step process. An event-generating application
037: * first obtains a proxy consumer from a channel, then 'connects' to the
038: * proxy consumer by providing it with a supplier. ... The reason for
039: * the two step registration process..."
040: * Modifications to support the above have been made as well as to support
041: * section 2.1.5 "Disconnection Behavior" on page 2-4.
042: *
043: * @author Jeff Carlson, Joerg v. Frantzius, Rainer Lischetzki, Gerald Brose
044: * @version $Id: ProxyPushConsumerImpl.java,v 1.8 2004/05/06 12:39:58 nicolas Exp $
045: */
046: public class ProxyPushConsumerImpl extends
047: org.omg.CosEventChannelAdmin.ProxyPushConsumerPOA {
048: private EventChannelImpl myEventChannel;
049: private PushSupplier myPushSupplier;
050: private org.omg.PortableServer.POA myPoa;
051: private boolean connected;
052:
053: /**
054: * Konstruktor - wird von EventChannel aufgerufen
055: */
056: protected ProxyPushConsumerImpl(EventChannelImpl ec,
057: org.omg.CORBA.ORB orb, org.omg.PortableServer.POA poa) {
058: myEventChannel = ec;
059: myPoa = poa;
060: connected = false;
061: _this _object(orb);
062: }
063:
064: /**
065: * fuers ProxyPushConsumer Interface:
066: * As stated by the EventService specification 1.1 section 2.3.4:
067: * "If a ProxyPushConsumer is already connected to a PushSupplier, then the
068: * AlreadyConnected exception is raised."
069: * and
070: * "If a non-nil reference is passed to connect_push_supplier..." implying
071: * that a null reference is acceptable.
072: */
073: public void connect_push_supplier(PushSupplier pushSupplier)
074: throws org.omg.CosEventChannelAdmin.AlreadyConnected {
075: if (connected) {
076: throw new org.omg.CosEventChannelAdmin.AlreadyConnected();
077: }
078: myPushSupplier = pushSupplier;
079: connected = true;
080: }
081:
082: /**
083: * fuers PushConsumer Interface:
084: * See EventService v 1.1 specification section 2.1.1.
085: * 'disconnect_push_consumer terminates the event communication; it releases
086: * resources used at the consumer to support event communication. Calling
087: * this causes the implementation to call disconnect_push_supplier operation
088: * on the corresponding PushSupplier interface (if that iterface is known).'
089: * See EventService v 1.1 specification section 2.1.5. This method should
090: * adhere to the spec as it a) causes a call to the corresponding disconnect
091: * on the connected supplier, b) 'If a consumer or supplier has received a
092: * disconnect call and subsequently receives another disconnect call, it
093: * shall raise a CORBA::OBJECT_NOT_EXIST exception.
094: */
095: public void disconnect_push_consumer() {
096: if (connected) {
097: if (myPushSupplier != null) {
098: myPushSupplier.disconnect_push_supplier();
099: myPushSupplier = null;
100: }
101: connected = false;
102: } else {
103: throw new org.omg.CORBA.OBJECT_NOT_EXIST();
104: }
105: }
106:
107: /**
108: * Supplier sends data to the consumer (this object) using this call.
109: */
110: public void push(org.omg.CORBA.Any event)
111: throws org.omg.CosEventComm.Disconnected {
112: if (!connected) {
113: throw new org.omg.CosEventComm.Disconnected();
114: }
115: myEventChannel.push_event(event);
116: }
117:
118: /**
119: * Override this method from the Servant baseclass. Fintan Bolton
120: * in his book "Pure CORBA" suggests that you override this method to
121: * avoid the risk that a servant object (like this one) could be
122: * activated by the <b>wrong</b> POA object.
123: */
124: public org.omg.PortableServer.POA _default_POA() {
125: return myPoa;
126: }
127: }
|