KickJava   Java API By Example, From Geeks To Geeks.

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


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

45 public class ProxyPushSupplierImpl
46     extends org.omg.CosEventChannelAdmin.ProxyPushSupplierPOA
47 {
48   private EventChannelImpl myEventChannel;
49   private PushConsumer myPushConsumer;
50   private org.omg.PortableServer.POA JavaDoc myPoa;
51   private boolean connected;
52
53   /**
54    * Constructor - to be called by EventChannel
55    */

56   protected ProxyPushSupplierImpl ( EventChannelImpl ec,
57                                     org.omg.CORBA.ORB JavaDoc orb,
58                                     org.omg.PortableServer.POA JavaDoc poa )
59   {
60     myEventChannel = ec;
61     myPoa = poa;
62     connected = false;
63     _this_object( orb );
64   }
65
66   /**
67    * fuers ProxyPushSupplier Interface.
68    * As stated by the EventService specification 1.1 section 2.3.7:
69    * "If a ProxyPushSupplier is already connected to a PushConsumer, then the
70    * AlreadyConnected exception is raised."
71    * and
72    * "Implementations shall raise the CORBA standard BAD_PARAM exception if
73    * a nil object reference is passed to the connect_push_consumer."
74    */

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

99   public void disconnect_push_supplier()
100   {
101     if ( connected )
102     {
103       if ( myPushConsumer != null )
104       {
105         myPushConsumer.disconnect_push_consumer();
106         myPushConsumer = null;
107       }
108       connected = false;
109     }
110     else
111     {
112       throw new OBJECT_NOT_EXIST();
113     }
114   }
115
116
117   /**
118    * Methoden, die von unserem EventChannel aufgerufen werden
119    */

120   protected void push_to_consumer(org.omg.CORBA.Any JavaDoc event )
121   {
122     if ( connected )
123     {
124       try
125       {
126         myPushConsumer.push ( event );
127       }
128       catch( Disconnected e )
129       {
130         connected = false;
131       }
132     }
133   }
134
135   /**
136    * Override this method from the Servant baseclass. Fintan Bolton
137    * in his book "Pure CORBA" suggests that you override this method to
138    * avoid the risk that a servant object (like this one) could be
139    * activated by the <b>wrong</b> POA object.
140    */

141   public org.omg.PortableServer.POA JavaDoc _default_POA()
142   {
143     return myPoa;
144   }
145 }
Popular Tags