KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > descriptor > componentassembly > ccm > deployer > binder > PublishesportDeployer


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Briclet Frédéric.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.binder;
27
28 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.util.CannotResolveReferenceException;
29 import org.omg.CORBA.Object JavaDoc;
30 import org.omg.Components.CCMObject;
31 import org.omg.Components.Cookie;
32 import org.omg.Components.EventConsumerBase;
33 import org.omg.Components.ExceededConnectionLimit;
34 import org.omg.Components.InvalidConnection;
35 import org.omg.Components.InvalidName;
36
37 /**
38  * The Publishesport deployer is used to resolve a publishesport and
39  * connect the consumer to it.
40  *
41  * @author <a HREF="mailto:briclet@lifl.fr">Briclet Frédéric</a>
42  *
43  * @version 0.1
44  */

45 public class PublishesportDeployer
46        extends PublishesportDeployerContext
47     {
48     // ==================================================================
49
//
50
// Internal state.
51
//
52
// ==================================================================
53

54     private CCMObject publisher;
55     private Cookie cookie;
56     // ==================================================================
57
//
58
// Constructors.
59
//
60
// ==================================================================
61
// ==================================================================
62
//
63
// Internal methods.
64
//
65
// ==================================================================
66

67     /**
68      * Internal method to resolve the CCMObject which supports the
69      * publishesport
70      * @return the CCMObject supporting the publishesport
71      * @throws CannotResolveException if the CCMObject cannot be found
72      */

73     private org.omg.Components.CCMObject
74     getCCMObjectPublisher()
75     throws CannotResolveReferenceException
76     {
77         Object JavaDoc ccm;
78         
79         if(getComponentinstantiationDeployer()!=null)
80             ccm=getComponentinstantiationDeployer().getComponent();
81         else ccm=getFindbyDeployer().resolveReference();
82         
83         return org.omg.Components.
84               CCMObjectHelper.narrow(ccm);
85     }
86     
87     // ==================================================================
88
//
89
// Public methods.
90
//
91
// ==================================================================
92

93     /**
94      * Connect the given @param consumedObject consumer to the current
95      * publishesport
96      * @param consumedObject the consumer to connect
97      * @throws InvalidName if the connection name is invalid
98      * @throws InvalidConnection if the given consumer is invalid
99      * @throws ExceededConnectionLimit if too many consumer are already connect
100      * @throws CannotResolveReferenceException if the precised CCMobject cannot be founded
101      */

102     public Cookie
103     connectPublisherToConsumer(EventConsumerBase consumedObject )
104     throws InvalidName,
105            InvalidConnection,
106            ExceededConnectionLimit,
107            CannotResolveReferenceException
108     {
109         
110         getLogger().log(">> Attempt to establish an event connection on port :"
111                                                             +getPublishesport()
112                                                             .getPublishesidentifier()
113                                                             .getValue());
114         
115         publisher=getCCMObjectPublisher();
116
117         cookie=publisher.subscribe(getPublishesport()
118                                     .getPublishesidentifier()
119                                     .getValue()
120                                      ,consumedObject);
121         getLifeCycleManager().stepEndedSuccessFully();
122         return cookie;
123     }
124     
125     /**
126      * DisconnectConsumer is used to disconnect the previous connnected consumer
127      * from the current publisher.
128      *
129      * @throws InvalidName if the port name is invalid
130      * @throws InvalidConnection if current cookie is invalid
131      */

132     public void
133     disconnectConsumer()
134     throws InvalidName,
135            InvalidConnection
136     
137     {
138         publisher.unsubscribe(getPublishesport()
139                             .getPublishesidentifier()
140                             .getValue(),cookie);
141         getLifeCycleManager().stepEndedSuccessFully();
142     }
143 }
144
Popular Tags