KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > events > ProxyPushConsumerImpl


1 package org.jacorb.events;
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.omg.CosEventComm.*;
24 import org.omg.CosEventChannelAdmin.*;
25 import org.omg.PortableServer.*;
26 import org.omg.CORBA.*;
27 import org.jacorb.orb.*;
28
29 /**
30  * Implementation of COSEventChannelAdmin interface; ProxyPushConsumer.
31  * This defines connect_push_supplier(), disconnect_push_consumer() and the all
32  * important push() method that the Supplier can call to actuall deliver a
33  * message.
34  *
35  * 2002/23/08 JFC OMG EventService Specification 1.1 page 2-7 states:
36  * "Registration is a two step process. An event-generating application
37  * first obtains a proxy consumer from a channel, then 'connects' to the
38  * proxy consumer by providing it with a supplier. ... The reason for
39  * the two step registration process..."
40  * Modifications to support the above have been made as well as to support
41  * section 2.1.5 "Disconnection Behavior" on page 2-4.
42  *
43  * @author Jeff Carlson, Joerg v. Frantzius, Rainer Lischetzki, Gerald Brose
44  * @version $Id: ProxyPushConsumerImpl.java,v 1.8 2004/05/06 12:39:58 nicolas Exp $
45  */

46 public class ProxyPushConsumerImpl
47     extends org.omg.CosEventChannelAdmin.ProxyPushConsumerPOA
48 {
49   private EventChannelImpl myEventChannel;
50   private PushSupplier myPushSupplier;
51   private org.omg.PortableServer.POA JavaDoc myPoa;
52   private boolean connected;
53
54   /**
55    * Konstruktor - wird von EventChannel aufgerufen
56    */

57   protected ProxyPushConsumerImpl ( EventChannelImpl ec,
58                                     org.omg.CORBA.ORB JavaDoc orb,
59                                     org.omg.PortableServer.POA JavaDoc poa )
60   {
61     myEventChannel = ec;
62     myPoa = poa;
63     connected = false;
64     _this_object( orb );
65   }
66
67   /**
68    * fuers ProxyPushConsumer Interface:
69    * As stated by the EventService specification 1.1 section 2.3.4:
70    * "If a ProxyPushConsumer is already connected to a PushSupplier, then the
71    * AlreadyConnected exception is raised."
72    * and
73    * "If a non-nil reference is passed to connect_push_supplier..." implying
74    * that a null reference is acceptable.
75    */

76   public void connect_push_supplier ( PushSupplier pushSupplier )
77       throws org.omg.CosEventChannelAdmin.AlreadyConnected
78   {
79     if ( connected ) { throw new org.omg.CosEventChannelAdmin.AlreadyConnected(); }
80     myPushSupplier = pushSupplier;
81     connected = true;
82   }
83
84   /**
85    * fuers PushConsumer Interface:
86    * See EventService v 1.1 specification section 2.1.1.
87    * 'disconnect_push_consumer terminates the event communication; it releases
88    * resources used at the consumer to support event communication. Calling
89    * this causes the implementation to call disconnect_push_supplier operation
90    * on the corresponding PushSupplier interface (if that iterface is known).'
91    * See EventService v 1.1 specification section 2.1.5. This method should
92    * adhere to the spec as it a) causes a call to the corresponding disconnect
93    * on the connected supplier, b) 'If a consumer or supplier has received a
94    * disconnect call and subsequently receives another disconnect call, it
95    * shall raise a CORBA::OBJECT_NOT_EXIST exception.
96    */

97   public void disconnect_push_consumer()
98   {
99     if ( connected )
100     {
101       if ( myPushSupplier != null )
102       {
103         myPushSupplier.disconnect_push_supplier();
104         myPushSupplier = null;
105       }
106       connected = false;
107     }
108     else
109     {
110       throw new org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc();
111     }
112   }
113
114   /**
115    * Supplier sends data to the consumer (this object) using this call.
116    */

117   public void push (org.omg.CORBA.Any JavaDoc event )
118       throws org.omg.CosEventComm.Disconnected
119   {
120     if ( !connected ) { throw new org.omg.CosEventComm.Disconnected(); }
121     myEventChannel.push_event( event );
122   }
123
124   /**
125    * Override this method from the Servant baseclass. Fintan Bolton
126    * in his book "Pure CORBA" suggests that you override this method to
127    * avoid the risk that a servant object (like this one) could be
128    * activated by the <b>wrong</b> POA object.
129    */

130   public org.omg.PortableServer.POA JavaDoc _default_POA()
131   {
132     return myPoa;
133   }
134 }
135
Popular Tags