KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > component > common > su > BindingComponentServiceUnitManager


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id$
20  * -------------------------------------------------------------------------
21  */

22
23 package org.objectweb.petals.component.common.su;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28
29 import javax.jbi.component.ComponentContext;
30 import javax.jbi.management.DeploymentException;
31
32 import org.objectweb.petals.component.common.PEtALSComponentSDKException;
33 import org.objectweb.petals.component.common.bc.AbstractBindingComponent;
34 import org.objectweb.petals.component.common.bc.ExternalListenerManager;
35 import org.objectweb.petals.tools.jbicommon.descriptor.Consumes;
36
37 /**
38  * Like SimpleServiceUnitManager but start and stop listeners for external
39  * addresses.
40  *
41  * @author ofabre
42  *
43  */

44 public class BindingComponentServiceUnitManager extends
45     SimpleServiceUnitManager {
46
47     private AbstractBindingComponent bindingComponent;
48
49     public BindingComponentServiceUnitManager(ComponentContext context,
50         Logger JavaDoc logger, AbstractBindingComponent bindingComponent) {
51         super(bindingComponent, context, logger);
52         this.bindingComponent = bindingComponent;
53     }
54
55     private List JavaDoc<String JavaDoc> getServiceUnitAddresses(final String JavaDoc serviceUnitName) {
56         return new ArrayList JavaDoc<String JavaDoc>(getServiceUnitDatas().get(serviceUnitName)
57             .getAddressToConsumes().keySet());
58     }
59
60     @Override JavaDoc
61     public void start(final String JavaDoc serviceUnitName) throws DeploymentException {
62         super.start(serviceUnitName);
63         for (String JavaDoc address : getServiceUnitAddresses(serviceUnitName)) {
64             try {
65                 Consumes consumes = getConsumesFromAddress(address);
66                 if (consumes == null) {
67                     throw new DeploymentException(
68                         "The Consumes node of the JBI.XML descriptor file is null.");
69                 }
70                 getExternalListenerManager().startListening(address,
71                     consumes.getExtensions());
72             } catch (PEtALSComponentSDKException e) {
73                 String JavaDoc msg = "Failed to start listening to address : "
74                     + address;
75                 getLogger().severe(msg);
76                 throw new DeploymentException(msg, e);
77             }
78         }
79     }
80
81     private ExternalListenerManager getExternalListenerManager()
82         throws DeploymentException {
83         ExternalListenerManager externalListenerManager = bindingComponent
84             .getInitializer().getExternalListenerManager();
85         if (externalListenerManager == null) {
86             throw new DeploymentException(
87                 "No external Listener manager provided. "
88                     + "So consumes node not allowed");
89         }
90         return externalListenerManager;
91     }
92
93     @Override JavaDoc
94     public void stop(final String JavaDoc serviceUnitName) throws DeploymentException {
95         for (String JavaDoc address : getServiceUnitAddresses(serviceUnitName)) {
96             try {
97                 getExternalListenerManager().stopListening(address);
98             } catch (PEtALSComponentSDKException e) {
99                 String JavaDoc msg = "Failed to start listening to address : "
100                     + address;
101                 getLogger().severe(msg);
102                 throw new DeploymentException(msg, e);
103             }
104         }
105         super.stop(serviceUnitName);
106     }
107
108 }
109
Popular Tags