You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/03/04 01:31:55 UTC
svn commit: r382984 [3/4] - in
/incubator/servicemix/trunk/servicemix-core/src:
main/java/org/apache/servicemix/jbi/container/
main/java/org/apache/servicemix/jbi/framework/
main/java/org/apache/servicemix/jbi/loaders/
main/java/org/apache/servicemix/j...
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java?rev=382984&r1=382983&r2=382984&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java Fri Mar 3 16:31:49 2006
@@ -19,6 +19,7 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.jbi.JBIException;
@@ -26,21 +27,25 @@
import javax.jbi.component.ComponentContext;
import javax.jbi.management.DeploymentException;
import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.management.JMException;
import javax.management.ObjectName;
import javax.xml.namespace.QName;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.jbi.container.ActivationSpec;
import org.apache.servicemix.jbi.container.EnvironmentContext;
import org.apache.servicemix.jbi.container.JBIContainer;
import org.apache.servicemix.jbi.container.SubscriptionSpec;
import org.apache.servicemix.jbi.deployment.ServiceAssembly;
+import org.apache.servicemix.jbi.deployment.ServiceUnit;
import org.apache.servicemix.jbi.management.BaseSystemService;
-import org.apache.servicemix.jbi.messaging.DeliveryChannelImpl;
import org.apache.servicemix.jbi.messaging.MessageExchangeImpl;
import org.apache.servicemix.jbi.servicedesc.InternalEndpoint;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList;
/**
@@ -50,21 +55,24 @@
*/
public class Registry extends BaseSystemService implements RegistryMBean {
+ private static final Log log = LogFactory.getLog(Registry.class);
private ComponentRegistry componentRegistry;
private EndpointRegistry endpointRegistry;
private SubscriptionRegistry subscriptionRegistry;
private ServiceAssemblyRegistry serviceAssemblyRegistry;
private List componentPacketListeners;
+ private Map serviceUnits;
/**
* Constructor
*/
public Registry() {
this.componentRegistry = new ComponentRegistry(this);
- this.endpointRegistry = new EndpointRegistry(componentRegistry);
+ this.endpointRegistry = new EndpointRegistry(this);
this.subscriptionRegistry = new SubscriptionRegistry();
this.serviceAssemblyRegistry = new ServiceAssemblyRegistry(this);
this.componentPacketListeners = new CopyOnWriteArrayList();
+ this.serviceUnits = new ConcurrentHashMap();
}
/**
@@ -273,16 +281,6 @@
}
/**
- * Utility method to get a ComponentConnector from an InterfaceName
- *
- * @param interfaceName
- * @return the ComponentConnector
- */
- public ComponentConnector getComponentConnector(QName interfaceName) {
- return endpointRegistry.getComponentConnector(interfaceName);
- }
-
- /**
* REgister a local Component
*
* @param name
@@ -295,8 +293,8 @@
* @throws JBIException
*/
public LocalComponentConnector registerComponent(ComponentNameSpace name, String description,Component component,
- DeliveryChannelImpl dc, boolean binding, boolean service) throws JBIException {
- LocalComponentConnector result = componentRegistry.registerComponent(name,description, component, dc, binding, service);
+ boolean binding, boolean service) throws JBIException {
+ LocalComponentConnector result = componentRegistry.registerComponent(name,description, component, binding, service);
if (result != null) {
fireComponentPacketEvent(result, ComponentPacketEvent.ACTIVATED);
}
@@ -399,6 +397,17 @@
}
/**
+ * Get a locally create ComponentConnector
+ *
+ * @param id - id of the ComponentConnector
+ * @return ComponentConnector or null if not found
+ */
+ public LocalComponentConnector getLocalComponentConnector(String componentName) {
+ ComponentNameSpace cns = new ComponentNameSpace(container.getName(), componentName, componentName);
+ return componentRegistry.getLocalComponentConnector(cns);
+ }
+
+ /**
* Find existence of a Component locally registered to this Container
* @param componentName
* @return true if the Component exists
@@ -418,6 +427,14 @@
}
/**
+ *
+ * @return Collection of ComponentConnectors held by the registry
+ */
+ public Collection getComponentConnectors() {
+ return componentRegistry.getComponentConnectors();
+ }
+
+ /**
* Get a Component
* @param cns
* @return the Component
@@ -446,7 +463,7 @@
ComponentNameSpace cns = new ComponentNameSpace(container.getName(), name, name);
LocalComponentConnector lcc = getLocalComponentConnector(cns);
if (lcc != null){
- result = lcc.getMbeanName();
+ result = lcc.getMBeanName();
}
return result;
@@ -491,8 +508,8 @@
List tmpList = new ArrayList();
for (Iterator i = getLocalComponentConnectors().iterator(); i.hasNext();){
LocalComponentConnector lcc = (LocalComponentConnector) i.next();
- if (!lcc.isPojo() && lcc.isService() && lcc.getMbeanName() != null){
- tmpList.add(lcc.getMbeanName());
+ if (!lcc.isPojo() && lcc.isService() && lcc.getMBeanName() != null){
+ tmpList.add(lcc.getMBeanName());
}
}
result = new ObjectName[tmpList.size()];
@@ -510,8 +527,8 @@
List tmpList = new ArrayList();
for (Iterator i = getLocalComponentConnectors().iterator(); i.hasNext();){
LocalComponentConnector lcc = (LocalComponentConnector) i.next();
- if (lcc.isPojo() && lcc.getMbeanName() != null){
- tmpList.add(lcc.getMbeanName());
+ if (lcc.isPojo() && lcc.getMBeanName() != null){
+ tmpList.add(lcc.getMBeanName());
}
}
result = new ObjectName[tmpList.size()];
@@ -529,8 +546,8 @@
List tmpList = new ArrayList();
for (Iterator i = getLocalComponentConnectors().iterator(); i.hasNext();){
LocalComponentConnector lcc = (LocalComponentConnector) i.next();
- if (!lcc.isPojo() && lcc.isBinding() && lcc.getMbeanName() != null){
- tmpList.add(lcc.getMbeanName());
+ if (!lcc.isPojo() && lcc.isBinding() && lcc.getMBeanName() != null){
+ tmpList.add(lcc.getMBeanName());
}
}
result = new ObjectName[tmpList.size()];
@@ -623,80 +640,25 @@
}
/**
- * Start a ServiceAssembly
- * @param serviceAssemblyName
- * @return status
- * @throws DeploymentException
- */
- public String startServiceAssembly(String serviceAssemblyName) throws DeploymentException{
- return serviceAssemblyRegistry.start(serviceAssemblyName);
- }
-
- /**
- * Restore a service assembly to its previous state
- * @param serviceAssemblyName
- * @return status
- * @throws DeploymentException
- */
- public String restoreServiceAssembly(String serviceAssemblyName) throws DeploymentException {
- return serviceAssemblyRegistry.restore(serviceAssemblyName);
- }
-
- /**
- * Stop a ServiceAssembly
- * @param serviceAssemblyName
- * @return status
- * @throws DeploymentException
- */
- public String stopServiceAssembly(String serviceAssemblyName) throws DeploymentException{
- return serviceAssemblyRegistry.stop(serviceAssemblyName);
- }
-
- /**
- * Shutdown a ServiceAssembly
- * @param serviceAssemblyName
- * @return status
- * @throws DeploymentException
- */
- public String shutDownServiceAssembly(String serviceAssemblyName) throws DeploymentException{
- return serviceAssemblyRegistry.shutDown(serviceAssemblyName);
- }
-
- /**
- * Get the lifecycle state of a service assembly
- * @param serviceAssemblyName
- * @return status
- */
- public String getServiceAssemblyState(String serviceAssemblyName){
- return serviceAssemblyRegistry.getState(serviceAssemblyName);
- }
-
- /**
- * Get the lifecycle description of a service assembly
- * @param serviceAssemblyName
- * @return
- */
- public String getServiceAssemblyDesc(String serviceAssemblyName) {
- return serviceAssemblyRegistry.getDescription(serviceAssemblyName);
- }
-
- /**
* Register a service assembly
* @param sa
* @return true if not already registered
* @throws DeploymentException
+ * @deprecated
*/
public boolean registerServiceAssembly(ServiceAssembly sa) throws DeploymentException{
return serviceAssemblyRegistry.register(sa);
}
/**
- * Un-register a service assembly
+ * Register a service assembly
* @param sa
- * @return true if successfully unregistered
+ * @param sus list of deployed service units
+ * @return true if not already registered
+ * @throws DeploymentException
*/
- public boolean unregisterServiceAssembly(ServiceAssembly sa) {
- return serviceAssemblyRegistry.unregister(sa);
+ public boolean registerServiceAssembly(ServiceAssembly sa, String[] deployedSUs) throws DeploymentException{
+ return serviceAssemblyRegistry.register(sa, deployedSUs);
}
/**
@@ -713,29 +675,18 @@
* @param name
* @return the ServiceAssembly or null if it doesn't exist
*/
- public ServiceAssembly getServiceAssembly(String name){
- return serviceAssemblyRegistry.get(name);
+ public ServiceAssemblyLifeCycle getServiceAssembly(String saName){
+ return serviceAssemblyRegistry.getServiceAssembly(saName);
}
-
+
/**
* Returns a list of Service Units that are currently deployed to the given component.
*
* @param componentName name of the component.
- * @return List of deployed ASA Ids.
- */
- public String[] getSADeployedServiceUnitList(String componentName) {
- return serviceAssemblyRegistry.getDeployedServiceUnitList(componentName);
- }
-
- /**
- * Returns the service unit description.
- *
- * @param componentName
- * @param deployedServiceUnit
- * @return SA deployed service unit description.
+ * @return List of deployed service units
*/
- public String getSADeployedServiceUnitDesc(String componentName, String deployedServiceUnit) {
- return serviceAssemblyRegistry.getSADeployedServiceUnitDesc(componentName, deployedServiceUnit);
+ public ServiceUnitLifeCycle[] getDeployedServiceUnits(String componentName) {
+ return serviceAssemblyRegistry.getDeployedServiceUnits(componentName);
}
/**
@@ -789,4 +740,50 @@
}
}
}
+
+ /**
+ * Get a ServiceUnit by its key.
+ *
+ * @param suKey the key of the service unit
+ * @return the ServiceUnit or null of it doesn't exist
+ */
+ public ServiceUnitLifeCycle getServiceUnit(String suKey) {
+ return (ServiceUnitLifeCycle) serviceUnits.get(suKey);
+ }
+
+ /**
+ * Register a ServiceUnit.
+ *
+ * @param su the service unit to register
+ * @param serviceAssembly the service assembly the service unit belongs to
+ * @return the service unit key
+ */
+ public String registerServiceUnit(ServiceUnit su, String serviceAssembly) {
+ ServiceUnitLifeCycle sulc = new ServiceUnitLifeCycle(su, serviceAssembly, this);
+ this.serviceUnits.put(sulc.getKey(), sulc);
+ try {
+ ObjectName objectName = getContainer().getManagementContext().createObjectName(sulc);
+ getContainer().getManagementContext().registerMBean(objectName, sulc, ServiceUnitMBean.class);
+ } catch (JMException e) {
+ log.error("Could not register MBean for service unit", e);
+ }
+ return sulc.getKey();
+ }
+
+ /**
+ * Unregister a ServiceUnit by its key.
+ *
+ * @param suKey the key of the service unit
+ */
+ public void unregisterServiceUnit(String suKey) {
+ ServiceUnitLifeCycle sulc = (ServiceUnitLifeCycle) this.serviceUnits.remove(suKey);
+ if (sulc != null) {
+ try {
+ getContainer().getManagementContext().unregisterMBean(sulc);
+ } catch (JBIException e) {
+ log.error("Could not unregister MBean for service unit", e);
+ }
+ }
+ }
+
}
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyLifeCycle.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyLifeCycle.java?rev=382984&r1=382983&r2=382984&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyLifeCycle.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyLifeCycle.java Fri Mar 3 16:31:49 2006
@@ -15,123 +15,273 @@
*/
package org.apache.servicemix.jbi.framework;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Properties;
-import javax.jbi.management.DeploymentServiceMBean;
+import javax.jbi.management.DeploymentException;
+import javax.management.JMException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.ObjectName;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.deployment.Connection;
+import org.apache.servicemix.jbi.deployment.Consumes;
+import org.apache.servicemix.jbi.deployment.Descriptor;
import org.apache.servicemix.jbi.deployment.ServiceAssembly;
+import org.apache.servicemix.jbi.management.AttributeInfoHelper;
+import org.apache.servicemix.jbi.management.MBeanInfoProvider;
+import org.apache.servicemix.jbi.management.OperationInfoHelper;
+import org.apache.servicemix.jbi.nmr.Broker;
import org.apache.servicemix.jbi.util.XmlPersistenceSupport;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
/**
* ComponentConnector is used internally for message routing
*
* @version $Revision$
*/
-class ServiceAssemblyLifeCycle {
-
+public class ServiceAssemblyLifeCycle implements ServiceAssemblyMBean, MBeanInfoProvider {
+
private static final Log log = LogFactory.getLog(ServiceAssemblyLifeCycle.class);
- static final String UNKNOWN = "Unknown";
- static final String STARTED = DeploymentServiceMBean.STARTED;
- static final String SHUTDOWN = DeploymentServiceMBean.SHUTDOWN;
- static final String STOPPED = DeploymentServiceMBean.STOPPED;
+
private ServiceAssembly serviceAssembly;
+
private String currentState = SHUTDOWN;
+
private File stateFile;
+ private ServiceUnitLifeCycle[] sus;
+
+ private Registry registry;
+
+ private PropertyChangeListener listener;
+
/**
* Construct a LifeCycle
*
* @param sa
* @param stateFile
*/
- ServiceAssemblyLifeCycle(ServiceAssembly sa,File stateFile){
- this.serviceAssembly=sa;
- this.stateFile=stateFile;
+ ServiceAssemblyLifeCycle(ServiceAssembly sa,
+ String[] suKeys,
+ File stateFile,
+ Registry registry) {
+ this.serviceAssembly = sa;
+ this.stateFile = stateFile;
+ this.registry = registry;
+ this.sus = new ServiceUnitLifeCycle[suKeys.length];
+ for (int i = 0; i < suKeys.length; i++) {
+ this.sus[i] = registry.getServiceUnit(suKeys[i]);
+ }
+
}
/**
- * Start the item.
+ * Start a Service Assembly and put it in the STARTED state.
+ *
+ * @return Result/Status of this operation.
+ * @throws Exception
*/
- void start(){
- currentState=STARTED;
+ public String start() throws Exception {
+ return start(true);
+ }
+
+ public String start(boolean writeState) throws Exception {
+ log.info("Starting service assembly: " + getName());
+ // Start connections
+ startConnections();
+ // Start service units
+ List componentFailures = new ArrayList();
+ for (int i = 0; i < sus.length; i++) {
+ if (sus[i].isShutDown()) {
+ try {
+ sus[i].init();
+ } catch (DeploymentException e) {
+ componentFailures.add(getComponentFailure(e, "start", sus[i].getComponentName()));
+ }
+ }
+ }
+ for (int i = 0; i < sus.length; i++) {
+ if (sus[i].isStopped()) {
+ try {
+ sus[i].start();
+ } catch (DeploymentException e) {
+ componentFailures.add(getComponentFailure(e, "start", sus[i].getComponentName()));
+ }
+ }
+ }
+ if (componentFailures.size() == 0) {
+ log.info("Started Service Assembly: " + getName());
+ currentState = STARTED;
+ if (writeState) {
+ writeRunningState();
+ }
+ return ManagementSupport.createSuccessMessage("start");
+ } else {
+ throw ManagementSupport.failure("start", componentFailures);
+ }
}
/**
- * Stop the item. This suspends current messaging activities.
+ * Stops the service assembly and puts it in STOPPED state.
+ *
+ * @return Result/Status of this operation.
+ * @throws Exception
*/
- void stop(){
- currentState=STOPPED;
+ public String stop() throws Exception {
+ return stop(true);
+ }
+
+ public String stop(boolean writeState) throws Exception {
+ log.info("Stopping service assembly: " + getName());
+ // Stop connections
+ stopConnections();
+ // Stop service units
+ List componentFailures = new ArrayList();
+ for (int i = 0; i < sus.length; i++) {
+ if (sus[i].isStarted()) {
+ try {
+ sus[i].stop();
+ } catch (DeploymentException e) {
+ componentFailures.add(getComponentFailure(e, "stop", sus[i].getComponentName()));
+ }
+ }
+ }
+ if (componentFailures.size() == 0) {
+ log.info("Stopped Service Assembly: " + getName());
+ currentState = STOPPED;
+ if (writeState) {
+ writeRunningState();
+ }
+ return ManagementSupport.createSuccessMessage("stop");
+ } else {
+ throw ManagementSupport.failure("stop", componentFailures);
+ }
}
/**
- * Shut down the item. The releases resources, preparatory to uninstallation.
+ * Shutdown the service assembly and puts it in SHUTDOWN state.
+ *
+ * @return Result/Status of this operation.
+ * @throws Exception
*/
- void shutDown(){
- currentState=SHUTDOWN;
+ public String shutDown() throws Exception {
+ return shutDown(true);
+ }
+
+ public String shutDown(boolean writeState) throws Exception {
+ log.info("Shutting down service assembly: " + getName());
+ List componentFailures = new ArrayList();
+ for (int i = 0; i < sus.length; i++) {
+ if (sus[i].isStarted()) {
+ try {
+ sus[i].stop();
+ } catch (DeploymentException e) {
+ componentFailures.add(getComponentFailure(e, "shutDown", sus[i].getComponentName()));
+ }
+ }
+ }
+ for (int i = 0; i < sus.length; i++) {
+ if (sus[i].isStopped()) {
+ try {
+ sus[i].shutDown();
+ } catch (DeploymentException e) {
+ componentFailures.add(getComponentFailure(e, "shutDown", sus[i].getComponentName()));
+ }
+ }
+ }
+ if (componentFailures.size() == 0) {
+ log.info("Shutdown Service Assembly: " + getName());
+ currentState = SHUTDOWN;
+ if (writeState) {
+ writeRunningState();
+ }
+ return ManagementSupport.createSuccessMessage("shutDown");
+ } else {
+ throw ManagementSupport.failure("shutDown", componentFailures);
+ }
}
/**
* @return the currentState as a String
*/
- public String getCurrentState(){
+ public String getCurrentState() {
return currentState;
}
- boolean isShutDown(){
- return currentState==null||currentState.equals(UNKNOWN)||currentState.equals(SHUTDOWN);
+ boolean isShutDown() {
+ return currentState.equals(SHUTDOWN);
}
- boolean isStopped(){
- return currentState!=null&¤tState.equals(STOPPED);
+ boolean isStopped() {
+ return currentState.equals(STOPPED);
}
- boolean isStarted(){
- return currentState!=null&¤tState.equals(STARTED);
+ boolean isStarted() {
+ return currentState.equals(STARTED);
}
/**
* @return the name of the ServiceAssembly
*/
- String getName(){
+ public String getName() {
return serviceAssembly.getIdentification().getName();
}
/**
- *
+ *
* @return the description of the ServiceAssembly
*/
- String getDescription() {
+ public String getDescription() {
return serviceAssembly.getIdentification().getDescription();
}
/**
* @return the ServiceAssembly
*/
- ServiceAssembly getServiceAssembly(){
+ public ServiceAssembly getServiceAssembly() {
return serviceAssembly;
}
+
+ public String getDescriptor() {
+ File saDir = registry.getEnvironmentContext().getSARootDirectory(getName());
+ return AutoDeploymentService.getDescriptorAsText(saDir);
+ }
/**
* @return string representation of this
*/
- public String toString(){
- return getName()+" ServiceAssembly lifecycle: "+getCurrentState();
+ public String toString() {
+ return "ServiceAssemblyLifeCycle[name=" + getName() + ",state=" + getCurrentState() + "]";
}
/**
* write the current running state of the Component to disk
*/
- void writeRunningState(){
- try{
+ void writeRunningState() {
+ try {
String currentState = getCurrentState();
Properties props = new Properties();
props.setProperty("state", currentState);
XmlPersistenceSupport.write(stateFile, props);
- }catch(IOException e){
- log.error("Failed to write current running state for ServiceAssembly: "+getName(),e);
+ } catch (IOException e) {
+ log.error("Failed to write current running state for ServiceAssembly: " + getName(), e);
}
}
@@ -140,13 +290,175 @@
*/
String getRunningStateFromStore() {
try {
- if(stateFile.exists()){
+ if (stateFile.exists()) {
Properties props = (Properties) XmlPersistenceSupport.read(stateFile);
return props.getProperty("state", SHUTDOWN);
}
} catch (Exception e) {
- log.error("Failed to read current running state for ServiceAssembly: "+getName(),e);
+ log.error("Failed to read current running state for ServiceAssembly: " + getName(), e);
+ }
+ return null;
+ }
+
+ /**
+ * Restore this service assembly to its state at shutdown.
+ * @throws Exception
+ */
+ void restore() throws Exception {
+ String state = getRunningStateFromStore();
+ if (STARTED.equals(state)) {
+ start();
+ } else {
+ stop();
+ if (SHUTDOWN.equals(state)) {
+ shutDown();
+ }
}
+ }
+
+ public ServiceUnitLifeCycle[] getDeployedSUs() {
+ return sus;
+ }
+
+ protected void startConnections() {
+ if (serviceAssembly.getConnections() == null ||
+ serviceAssembly.getConnections().getConnections() == null) {
+ return;
+ }
+ Connection[] connections = serviceAssembly.getConnections().getConnections();
+ Broker broker = registry.getContainer().getBroker();
+ for (int i = 0; i < connections.length; i++) {
+ if (connections[i].getConsumer().getInterfaceName() != null) {
+ QName fromItf = connections[i].getConsumer().getInterfaceName();
+ QName toSvc = connections[i].getProvider().getServiceName();
+ String toEp = connections[i].getProvider().getEndpointName();
+ broker.registerInterfaceConnection(fromItf, toSvc, toEp);
+ } else {
+ QName fromSvc = connections[i].getConsumer().getServiceName();
+ String fromEp = connections[i].getConsumer().getEndpointName();
+ QName toSvc = connections[i].getProvider().getServiceName();
+ String toEp = connections[i].getProvider().getEndpointName();
+ String link = getLinkType(fromSvc, fromEp);
+ broker.registerEndpointConnection(fromSvc, fromEp, toSvc, toEp, link);
+ }
+ }
+ }
+
+ protected String getLinkType(QName svc, String ep) {
+ for (int i = 0; i < sus.length; i++) {
+ Descriptor d = AutoDeploymentService.buildDescriptor(sus[i].getServiceUnitRootPath());
+ if (d != null && d.getServices() != null && d.getServices().getConsumes() != null) {
+ Consumes[] consumes = d.getServices().getConsumes();
+ for (int j = 0; j < consumes.length; j++) {
+ if (svc.equals(consumes[j].getServiceName()) &&
+ ep.equals(consumes[j].getEndpointName())) {
+ return consumes[j].getLinkType();
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ protected void stopConnections() {
+ if (serviceAssembly.getConnections() == null ||
+ serviceAssembly.getConnections().getConnections() == null) {
+ return;
+ }
+ Connection[] connections = serviceAssembly.getConnections().getConnections();
+ Broker broker = registry.getContainer().getBroker();
+ for (int i = 0; i < connections.length; i++) {
+ if (connections[i].getConsumer().getInterfaceName() != null) {
+ QName fromItf = connections[i].getConsumer().getInterfaceName();
+ QName toSvc = connections[i].getProvider().getServiceName();
+ String toEp = connections[i].getProvider().getEndpointName();
+ broker.unregisterInterfaceConnection(fromItf, toSvc, toEp);
+ } else {
+ QName fromSvc = connections[i].getConsumer().getServiceName();
+ String fromEp = connections[i].getConsumer().getEndpointName();
+ QName toSvc = connections[i].getProvider().getServiceName();
+ String toEp = connections[i].getProvider().getEndpointName();
+ broker.unregisterEndpointConnection(fromSvc, fromEp, toSvc, toEp);
+ }
+ }
+ }
+
+ protected Element getComponentFailure(Exception exception, String task, String component) {
+ Element result = null;
+ String resultMsg = exception.getMessage();
+ try {
+ Document doc = parse(resultMsg);
+ result = getElement(doc, "component-task-result");
+ } catch (Exception e) {
+ log.warn("Could not parse result exception", e);
+ }
+ if (result == null) {
+ result = ManagementSupport.createComponentFailure(
+ task, component,
+ "Unable to parse result string", exception);
+ }
+ return result;
+ }
+
+ protected Document parse(String result) throws ParserConfigurationException, SAXException, IOException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ factory.setIgnoringElementContentWhitespace(true);
+ factory.setIgnoringComments(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder.parse(new InputSource(new StringReader(result)));
+ }
+
+ protected Element getElement(Document doc, String name) {
+ NodeList l = doc.getElementsByTagNameNS("http://java.sun.com/xml/ns/jbi/management-message", name);
+ Element e = (Element) l.item(0);
+ return e;
+ }
+
+ public MBeanAttributeInfo[] getAttributeInfos() throws JMException {
+ AttributeInfoHelper helper = new AttributeInfoHelper();
+ helper.addAttribute(getObjectToManage(), "currentState", "current state of the assembly");
+ helper.addAttribute(getObjectToManage(), "name", "name of the assembly");
+ helper.addAttribute(getObjectToManage(), "description", "description of the assembly");
+ helper.addAttribute(getObjectToManage(), "serviceUnits", "list of service units contained in this assembly");
+ return helper.getAttributeInfos();
+ }
+
+ public MBeanOperationInfo[] getOperationInfos() throws JMException {
+ OperationInfoHelper helper = new OperationInfoHelper();
+ helper.addOperation(getObjectToManage(), "start", "start the assembly");
+ helper.addOperation(getObjectToManage(), "stop", "stop the assembly");
+ helper.addOperation(getObjectToManage(), "shutDown", "shutdown the assembly");
+ helper.addOperation(getObjectToManage(), "getDescriptor", "retrieve the jbi descriptor for this assembly");
+ return helper.getOperationInfos();
+ }
+
+ public Object getObjectToManage() {
+ return this;
+ }
+
+ public String getType() {
+ return "ServiceAssembly";
+ }
+
+ public String getSubType() {
+ return null;
+ }
+
+ public void setPropertyChangeListener(PropertyChangeListener listener) {
+ this.listener = listener;
+ }
+
+ protected void firePropertyChanged(String name,Object oldValue, Object newValue){
+ PropertyChangeListener l = listener;
+ if (l != null){
+ PropertyChangeEvent event = new PropertyChangeEvent(this,name,oldValue,newValue);
+ l.propertyChange(event);
+ }
+ }
+
+ public ObjectName[] getServiceUnits() {
+ // TODO Auto-generated method stub
return null;
}
}
Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyMBean.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyMBean.java?rev=382984&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyMBean.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyMBean.java Fri Mar 3 16:31:49 2006
@@ -0,0 +1,30 @@
+package org.apache.servicemix.jbi.framework;
+
+import javax.jbi.management.DeploymentServiceMBean;
+import javax.management.ObjectName;
+
+
+public interface ServiceAssemblyMBean {
+
+ public static final String STARTED = DeploymentServiceMBean.STARTED;
+
+ public static final String SHUTDOWN = DeploymentServiceMBean.SHUTDOWN;
+
+ public static final String STOPPED = DeploymentServiceMBean.STOPPED;
+
+ public String getName();
+
+ public String getDescription();
+
+ public String getCurrentState();
+
+ public String getDescriptor();
+
+ public ObjectName[] getServiceUnits();
+
+ public String start() throws Exception;
+
+ public String stop() throws Exception;
+
+ public String shutDown() throws Exception;
+}
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyRegistry.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyRegistry.java?rev=382984&r1=382983&r2=382984&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyRegistry.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyRegistry.java Fri Mar 3 16:31:49 2006
@@ -16,16 +16,18 @@
package org.apache.servicemix.jbi.framework;
import java.io.File;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import javax.jbi.component.Component;
-import javax.jbi.component.ServiceUnitManager;
+
+import javax.jbi.JBIException;
import javax.jbi.management.DeploymentException;
+import javax.management.JMException;
+import javax.management.ObjectName;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.jbi.deployment.ServiceAssembly;
@@ -41,9 +43,7 @@
public class ServiceAssemblyRegistry {
private static final Log log = LogFactory.getLog(ServiceAssemblyRegistry.class);
- private Map serviceAssembilies = new ConcurrentHashMap();
-
-
+ private Map serviceAssemblies = new ConcurrentHashMap();
private Registry registry;
/**
@@ -55,52 +55,21 @@
}
/**
- * initialize service assembilies to their persisted running state
+ * Start all registered service assemblies
*/
public void start() {
- for (Iterator i = serviceAssembilies.values().iterator(); i.hasNext();){
- ServiceAssemblyLifeCycle salc = (ServiceAssemblyLifeCycle) i.next();
- salc.getCurrentState();
- if (salc.isStarted()){
- try{
- start(salc);
- }catch(DeploymentException e){
- log.error("Failed to start: " + salc);
- }
- }
- }
}
/**
* Stop service assembilies
*/
public void stop(){
- for (Iterator i = serviceAssembilies.values().iterator(); i.hasNext();){
- ServiceAssemblyLifeCycle salc = (ServiceAssemblyLifeCycle) i.next();
- if (salc.isStarted()){
- try{
- stop(salc);
- }catch(DeploymentException e){
- log.error("Failed to start: " + salc);
- }
- }
- }
}
/**
* shutDown the service
*/
public void shutDown(){
- for (Iterator i = serviceAssembilies.values().iterator(); i.hasNext();){
- ServiceAssemblyLifeCycle salc = (ServiceAssemblyLifeCycle) i.next();
- if (!salc.isShutDown()){
- try{
- shutDown(salc);
- }catch(DeploymentException e){
- log.error("Failed to start: " + salc);
- }
- }
- }
}
/**
@@ -108,43 +77,60 @@
* @param sa
* @return true if successful
* @throws DeploymentException
+ * @deprecated
*/
- public boolean register(ServiceAssembly sa) throws DeploymentException{
- boolean result=false;
- String saName=sa.getIdentification().getName();
- try{
- File stateFile=registry.getEnvironmentContext().getServiceAssemblyStateFile(saName);
- ServiceAssemblyLifeCycle salc=new ServiceAssemblyLifeCycle(sa,stateFile);
- init(salc);
- if(!serviceAssembilies.containsKey(saName)){
- serviceAssembilies.put(saName,salc);
- result=true;
- }
- }catch(IOException e){
- log.error("Failed to get state file for service assembly: "+saName);
- throw new DeploymentException(e);
+ public boolean register(ServiceAssembly sa) throws DeploymentException {
+ List sus = new ArrayList();
+ for (int i = 0; i < sa.getServiceUnits().length; i++) {
+ String suKey = registry.registerServiceUnit(
+ sa.getServiceUnits()[i],
+ sa.getIdentification().getName());
+ sus.add(suKey);
}
- return result;
+ return register(sa, (String[]) sus.toArray(new String[sus.size()]));
}
/**
- * unregister a service assembly
- *
+ * Register the Service Assembly
* @param sa
* @return true if successful
+ * @throws DeploymentException
*/
- public boolean unregister(ServiceAssembly sa){
- return unregister(sa.getIdentification().getName());
+ public boolean register(ServiceAssembly sa, String[] sus) throws DeploymentException {
+ boolean result = false;
+ String saName = sa.getIdentification().getName();
+ File stateFile = registry.getEnvironmentContext().getServiceAssemblyStateFile(saName);
+ ServiceAssemblyLifeCycle salc = new ServiceAssemblyLifeCycle(sa, sus, stateFile, registry);
+ if (!serviceAssemblies.containsKey(saName)) {
+ serviceAssemblies.put(saName, salc);
+ try {
+ ObjectName objectName = registry.getContainer().getManagementContext().createObjectName(salc);
+ registry.getContainer().getManagementContext().registerMBean(objectName, salc, ServiceAssemblyMBean.class);
+ } catch (JMException e) {
+ log.error("Could not register MBean for service assembly", e);
+ }
+ result = true;
+ }
+ return result;
}
-
/**
* unregister a service assembly
* @param name
* @return true if successful
*/
- public boolean unregister(String name){
- return serviceAssembilies.remove(name) != null;
+ public boolean unregister(String name) {
+ ServiceAssemblyLifeCycle salc = (ServiceAssemblyLifeCycle) serviceAssemblies.remove(name);
+ if (salc != null) {
+ try {
+ registry.getContainer().getManagementContext().unregisterMBean(salc);
+ } catch (JBIException e) {
+ log.error("Unable to unregister MBean for service assembly", e);
+ }
+ return true;
+ } else {
+ return false;
+ }
}
/**
@@ -152,262 +138,44 @@
* @param name
* @return the ServiceAssembly or null if it doesn't exist
*/
- public ServiceAssembly get(String name){
- ServiceAssemblyLifeCycle result = (ServiceAssemblyLifeCycle) serviceAssembilies.get(name);
- return result != null ? result.getServiceAssembly() : null;
- }
-
-
- /**
- * Start a Service Assembly
- * @param name
- * @return the status
- * @throws DeploymentException
- */
- public String start(String name) throws DeploymentException{
- String result=ServiceAssemblyLifeCycle.UNKNOWN;
- ServiceAssemblyLifeCycle salc=(ServiceAssemblyLifeCycle) serviceAssembilies.get(name);
- if(salc!=null){
- result=start(salc);
- salc.writeRunningState();
- }
- return result;
- }
-
- public String restore(String name) throws DeploymentException {
- String result = ServiceAssemblyLifeCycle.UNKNOWN;
- ServiceAssemblyLifeCycle salc = (ServiceAssemblyLifeCycle) serviceAssembilies.get(name);
- if (salc != null) {
- result = salc.getRunningStateFromStore();
- if (ServiceAssemblyLifeCycle.STARTED.equals(result)) {
- start(salc);
- } else if (ServiceAssemblyLifeCycle.SHUTDOWN.equals(result)) {
- shutDown(salc);
- }
- }
- return result;
- }
-
- void init(ServiceAssemblyLifeCycle salc) throws DeploymentException{
- if (salc != null) {
- ServiceUnit[] sus = salc.getServiceAssembly().getServiceUnits();
- if (sus != null) {
- for (int i = 0;i < sus.length;i++) {
- String suName = sus[i].getIdentification().getName();
- String componentName = sus[i].getTarget().getComponentName();
- Component component = registry.getComponent(componentName);
- if (component != null) {
- ServiceUnitManager sum = component.getServiceUnitManager();
- if (sum != null) {
- try {
- File targetDir = registry.getEnvironmentContext().getServiceUnitDirectory(componentName, suName);
- sum.init(suName, targetDir.getAbsolutePath());
- } catch (IOException e) {
- throw new DeploymentException(e);
- }
- }
- }
- }
- }
- }
- }
-
- String start(ServiceAssemblyLifeCycle salc) throws DeploymentException{
- String result = ServiceAssemblyLifeCycle.UNKNOWN;
- if (salc != null) {
- ServiceUnit[] sus = salc.getServiceAssembly().getServiceUnits();
- if (sus != null) {
- for (int i = 0;i < sus.length;i++) {
- String suName = sus[i].getIdentification().getName();
- String componentName = sus[i].getTarget().getComponentName();
- Component component = registry.getComponent(componentName);
- if (component != null) {
- ServiceUnitManager sum = component.getServiceUnitManager();
- if (sum != null) {
- sum.start(suName);
- }
- }
- }
- }
- salc.start();
- result = salc.getCurrentState();
- log.info("Started Service Assembly: " + salc.getName());
- }
- return result;
- }
-
- /**
- * Stops the service assembly and puts it in STOPPED state.
- * @param name
- *
- * @return Result/Status of this operation.
- * @throws DeploymentException
- */
- public String stop(String name) throws DeploymentException{
- String result=ServiceAssemblyLifeCycle.UNKNOWN;
- ServiceAssemblyLifeCycle salc=(ServiceAssemblyLifeCycle) serviceAssembilies.get(name);
- if(salc!=null){
- result=stop(salc);
- salc.writeRunningState();
- }
- return result;
- }
-
- String stop(ServiceAssemblyLifeCycle salc) throws DeploymentException {
- String result = ServiceAssemblyLifeCycle.UNKNOWN;
- if (salc != null) {
- ServiceUnit[] sus = salc.getServiceAssembly().getServiceUnits();
- if (sus != null) {
- for (int i = 0;i < sus.length;i++) {
- String componentName = sus[i].getTarget().getComponentName();
- Component component = registry.getComponent(componentName);
- if (component != null) {
- ServiceUnitManager sum = component.getServiceUnitManager();
- if (sum != null) {
- sum.stop(sus[i].getIdentification().getName());
- }
- }
- }
- }
- salc.stop();
- result = salc.getCurrentState();
- log.info("Stopped Service Assembly: " + salc.getName());
- }
- return result;
- }
-
- /**
- * Shutdown the service assembly and puts it in SHUTDOWN state.
- * @param name
- *
- * @return Result/Status of this operation.
- * @throws DeploymentException
- */
- public String shutDown(String name) throws DeploymentException{
- String result=ServiceAssemblyLifeCycle.UNKNOWN;
- ServiceAssemblyLifeCycle salc=(ServiceAssemblyLifeCycle) serviceAssembilies.get(name);
- if(salc!=null){
- if (salc.getCurrentState().equals(ServiceAssemblyLifeCycle.STARTED)) {
- stop(salc);
- }
- result=shutDown(salc);
- salc.writeRunningState();
- }
- return result;
+ public ServiceAssemblyLifeCycle getServiceAssembly(String saName) {
+ return (ServiceAssemblyLifeCycle) serviceAssemblies.get(saName);
}
- String shutDown(ServiceAssemblyLifeCycle salc) throws DeploymentException {
- String result = ServiceAssemblyLifeCycle.UNKNOWN;
- if (salc != null) {
- ServiceUnit[] sus = salc.getServiceAssembly().getServiceUnits();
- if (sus != null) {
- for (int i = 0;i < sus.length;i++) {
- String componentName = sus[i].getTarget().getComponentName();
- Component component = registry.getComponent(componentName);
- if (component != null) {
- ServiceUnitManager sum = component.getServiceUnitManager();
- if (sum != null) {
- sum.shutDown(sus[i].getIdentification().getName());
- }
- }
- }
- }
- salc.shutDown();
- result = salc.getCurrentState();
- log.info("Shutdown Service Assembly: " + salc.getName());
- }
- return result;
- }
-
-
- /**
- * Get the current state of the named service assembly
- * @param name
- * @return the state
- */
- public String getState(String name){
- String result = ServiceAssemblyLifeCycle.SHUTDOWN;
- ServiceAssemblyLifeCycle salc = (ServiceAssemblyLifeCycle) serviceAssembilies.get(name);
- if (salc != null) {
- result = salc.getCurrentState();
- }
- return result;
- }
-
- /**
- * Get the current description of the named service assembly
- *
- * @param name
- * @return the description
- */
- public String getDescription(String name) {
- String result = null;
- ServiceAssemblyLifeCycle salc = (ServiceAssemblyLifeCycle) serviceAssembilies.get(name);
- if (salc != null) {
- result = salc.getDescription();
- }
- return result;
- }
-
/**
* Returns a list of Service Units that are currently deployed to the given component.
*
* @param componentName name of the component.
* @return List of deployed ASA Ids.
*/
- public String[] getDeployedServiceUnitList(String componentName) {
- String[] result = null;
+ public ServiceUnitLifeCycle[] getDeployedServiceUnits(String componentName) {
+ ServiceUnitLifeCycle[] result = null;
// iterate through the service assembilies
List tmpList = new ArrayList();
- for (Iterator iter = serviceAssembilies.values().iterator();iter.hasNext();) {
+ for (Iterator iter = serviceAssemblies.values().iterator();iter.hasNext();) {
ServiceAssemblyLifeCycle salc = (ServiceAssemblyLifeCycle) iter.next();
- ServiceUnit[] sus = salc.getServiceAssembly().getServiceUnits();
+ ServiceUnitLifeCycle[] sus = salc.getDeployedSUs();
if (sus != null) {
- for (int i = 0;i < sus.length;i++) {
- if (sus[i].getTarget().getComponentName().equals(componentName)) {
- tmpList.add(sus[i].getIdentification().getName());
+ for (int i = 0; i < sus.length; i++) {
+ if (sus[i].getComponentName().equals(componentName)) {
+ tmpList.add(sus[i]);
}
}
}
}
- result = new String[tmpList.size()];
+ result = new ServiceUnitLifeCycle[tmpList.size()];
tmpList.toArray(result);
return result;
}
/**
- * Returns the description of SA deployed service unit.
- *
- * @param componentName
- * @param deployedServiceUnit
- * @return
- */
- public String getSADeployedServiceUnitDesc(String componentName, String deployedServiceUnit) {
- String result = null;
- ServiceAssemblyLifeCycle salc = (ServiceAssemblyLifeCycle) serviceAssembilies;
- ServiceUnit[] sus = salc.getServiceAssembly().getServiceUnits();
- if (sus != null) {
- for (int i = 0;i < sus.length;i++) {
- if (sus[i].getTarget().getComponentName().equals(componentName)) {
- if (sus[i].getIdentification().getName().equals(deployedServiceUnit)) {
- result = sus[i].getIdentification().getDescription();
- break;
- }
- }
- }
- }
-
- return result;
- }
-
- /**
* Returns a list of Service Assemblies deployed to the JBI enviroment.
*
* @return list of Service Assembly Name's.
*/
public String[] getDeployedServiceAssemblies() {
String[] result = null;
- Set keys = serviceAssembilies.keySet();
+ Set keys = serviceAssemblies.keySet();
result = new String[keys.size()];
keys.toArray(result);
return result;
@@ -423,7 +191,7 @@
String[] result = null;
// iterate through the service assembilies
Set tmpList = new HashSet();
- for (Iterator iter = serviceAssembilies.values().iterator();iter.hasNext();) {
+ for (Iterator iter = serviceAssemblies.values().iterator();iter.hasNext();) {
ServiceAssemblyLifeCycle salc = (ServiceAssemblyLifeCycle) iter.next();
ServiceUnit[] sus = salc.getServiceAssembly().getServiceUnits();
if (sus != null) {
@@ -448,9 +216,9 @@
public String[] getComponentsForDeployedServiceAssembly(String saName) {
String[] result = null;
Set tmpList = new HashSet();
- ServiceAssembly sa = get(saName);
+ ServiceAssemblyLifeCycle sa = getServiceAssembly(saName);
if (sa != null) {
- ServiceUnit[] sus = sa.getServiceUnits();
+ ServiceUnit[] sus = sa.getServiceAssembly().getServiceUnits();
if (sus != null) {
for (int i = 0;i < sus.length;i++) {
tmpList.add(sus[i].getTarget().getComponentName());
@@ -471,7 +239,7 @@
*/
public boolean isDeployedServiceUnit(String componentName, String suName) {
boolean result = false;
- for (Iterator iter = serviceAssembilies.values().iterator();iter.hasNext();) {
+ for (Iterator iter = serviceAssemblies.values().iterator();iter.hasNext();) {
ServiceAssemblyLifeCycle salc = (ServiceAssemblyLifeCycle) iter.next();
ServiceUnit[] sus = salc.getServiceAssembly().getServiceUnits();
if (sus != null) {
@@ -486,9 +254,5 @@
}
return result;
}
-
-
-
-
-
+
}
Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceUnitLifeCycle.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceUnitLifeCycle.java?rev=382984&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceUnitLifeCycle.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceUnitLifeCycle.java Fri Mar 3 16:31:49 2006
@@ -0,0 +1,241 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.framework;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.File;
+
+import javax.jbi.component.Component;
+import javax.jbi.component.ServiceUnitManager;
+import javax.jbi.management.DeploymentException;
+import javax.management.JMException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanOperationInfo;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.deployment.ServiceUnit;
+import org.apache.servicemix.jbi.management.AttributeInfoHelper;
+import org.apache.servicemix.jbi.management.MBeanInfoProvider;
+import org.apache.servicemix.jbi.management.OperationInfoHelper;
+
+public class ServiceUnitLifeCycle implements ServiceUnitMBean, MBeanInfoProvider {
+
+ private static final Log log = LogFactory.getLog(ServiceUnitLifeCycle.class);
+
+ private ServiceUnit serviceUnit;
+
+ private String currentState = SHUTDOWN;
+
+ private String serviceAssembly;
+
+ private Registry registry;
+
+ private PropertyChangeListener listener;
+
+ ServiceUnitLifeCycle(ServiceUnit serviceUnit,
+ String serviceAssembly,
+ Registry registry) {
+ this.serviceUnit = serviceUnit;
+ this.serviceAssembly = serviceAssembly;
+ this.registry = registry;
+ }
+
+ /**
+ * Initialize the service unit.
+ * @throws DeploymentException
+ */
+ public void init() throws DeploymentException {
+ log.info("Initializing service unit: " + getName());
+ checkComponentStarted("init");
+ ServiceUnitManager sum = getServiceUnitManager();
+ File path = getServiceUnitRootPath();
+ sum.init(getName(), path.getAbsolutePath());
+ currentState = STOPPED;
+ }
+
+ /**
+ * Start the service unit.
+ * @throws DeploymentException
+ */
+ public void start() throws DeploymentException {
+ log.info("Starting service unit: " + getName());
+ checkComponentStarted("start");
+ ServiceUnitManager sum = getServiceUnitManager();
+ sum.start(getName());
+ currentState = STARTED;
+ }
+
+ /**
+ * Stop the service unit. This suspends current messaging activities.
+ * @throws DeploymentException
+ */
+ public void stop() throws DeploymentException {
+ log.info("Stopping service unit: " + getName());
+ checkComponentStarted("stop");
+ ServiceUnitManager sum = getServiceUnitManager();
+ sum.stop(getName());
+ currentState = STOPPED;
+ }
+
+ /**
+ * Shut down the service unit.
+ * This releases resources, preparatory to uninstallation.
+ * @throws DeploymentException
+ */
+ public void shutDown() throws DeploymentException {
+ log.info("Shutting down service unit: " + getName());
+ checkComponentStartedOrStopped("shutDown");
+ ServiceUnitManager sum = getServiceUnitManager();
+ sum.shutDown(getName());
+ currentState = SHUTDOWN;
+ }
+
+ /**
+ * @return the currentState as a String
+ */
+ public String getCurrentState() {
+ return currentState;
+ }
+
+ public boolean isShutDown() {
+ return currentState.equals(SHUTDOWN);
+ }
+
+ public boolean isStopped() {
+ return currentState.equals(STOPPED);
+ }
+
+ public boolean isStarted() {
+ return currentState.equals(STARTED);
+ }
+
+ /**
+ * @return the name of the ServiceAssembly
+ */
+ public String getName() {
+ return serviceUnit.getIdentification().getName();
+ }
+
+ /**
+ * @return the description of the ServiceAssembly
+ */
+ public String getDescription() {
+ return serviceUnit.getIdentification().getDescription();
+ }
+
+ public String getComponentName() {
+ return serviceUnit.getTarget().getComponentName();
+ }
+
+ public String getServiceAssembly() {
+ return serviceAssembly;
+ }
+
+ public String getDescriptor() {
+ File suDir = getServiceUnitRootPath();
+ return AutoDeploymentService.getDescriptorAsText(suDir);
+ }
+
+ protected void checkComponentStarted(String task) throws DeploymentException {
+ String componentName = getComponentName();
+ String suName = getName();
+ LocalComponentConnector lcc = registry.getLocalComponentConnector(componentName);
+ if (lcc == null) {
+ throw ManagementSupport.componentFailure("deploy", componentName, "Target component " + componentName + " for service unit " + suName + " is not installed");
+ }
+ if (!lcc.getComponentMBean().isStarted()) {
+ throw ManagementSupport.componentFailure("deploy", componentName, "Target component " + componentName + " for service unit " + suName + " is not started");
+ }
+ if (lcc.getServiceUnitManager() == null) {
+ throw ManagementSupport.componentFailure("deploy", componentName, "Target component " + componentName + " for service unit " + suName + " does not accept deployments");
+ }
+ }
+
+ protected void checkComponentStartedOrStopped(String task) throws DeploymentException {
+ String componentName = getComponentName();
+ String suName = getName();
+ LocalComponentConnector lcc = registry.getLocalComponentConnector(componentName);
+ if (lcc == null) {
+ throw ManagementSupport.componentFailure("deploy", componentName, "Target component " + componentName + " for service unit " + suName + " is not installed");
+ }
+ if (!lcc.getComponentMBean().isStarted() && !lcc.getComponentMBean().isStopped()) {
+ throw ManagementSupport.componentFailure("deploy", componentName, "Target component " + componentName + " for service unit " + suName + " is not started");
+ }
+ if (lcc.getServiceUnitManager() == null) {
+ throw ManagementSupport.componentFailure("deploy", componentName, "Target component " + componentName + " for service unit " + suName + " does not accept deployments");
+ }
+ }
+
+ protected File getServiceUnitRootPath() {
+ String componentName = getComponentName();
+ String suName = getName();
+ File targetDir = registry.getEnvironmentContext().getServiceUnitDirectory(componentName, suName);
+ return targetDir;
+ }
+
+ protected ServiceUnitManager getServiceUnitManager() {
+ Component component = registry.getComponent(getComponentName());
+ LocalComponentConnector lcc = registry.getComponentConnector(component);
+ return lcc.getServiceUnitManager();
+ }
+
+ public MBeanAttributeInfo[] getAttributeInfos() throws JMException {
+ AttributeInfoHelper helper = new AttributeInfoHelper();
+ helper.addAttribute(getObjectToManage(), "currentState", "current state of the service unit");
+ helper.addAttribute(getObjectToManage(), "name", "name of the service unit");
+ helper.addAttribute(getObjectToManage(), "componentName", "component name of the service unit");
+ helper.addAttribute(getObjectToManage(), "serviceAssembly", "service assembly name of the service unit");
+ helper.addAttribute(getObjectToManage(), "description", "description of the service unit");
+ return helper.getAttributeInfos();
+ }
+
+ public MBeanOperationInfo[] getOperationInfos() throws JMException {
+ OperationInfoHelper helper = new OperationInfoHelper();
+ helper.addOperation(getObjectToManage(), "getDescriptor", "retrieve the jbi descriptor for this unit");
+ return helper.getOperationInfos();
+ }
+
+ public Object getObjectToManage() {
+ return this;
+ }
+
+ public String getType() {
+ return "ServiceUnit";
+ }
+
+ public String getSubType() {
+ return getComponentName();
+ }
+
+ public void setPropertyChangeListener(PropertyChangeListener listener) {
+ this.listener = listener;
+ }
+
+ protected void firePropertyChanged(String name,Object oldValue, Object newValue){
+ PropertyChangeListener l = listener;
+ if (l != null){
+ PropertyChangeEvent event = new PropertyChangeEvent(this,name,oldValue,newValue);
+ l.propertyChange(event);
+ }
+ }
+
+ public String getKey() {
+ return getComponentName() + "/" + getName();
+ }
+
+}
Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceUnitMBean.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceUnitMBean.java?rev=382984&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceUnitMBean.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceUnitMBean.java Fri Mar 3 16:31:49 2006
@@ -0,0 +1,24 @@
+package org.apache.servicemix.jbi.framework;
+
+import javax.jbi.management.DeploymentServiceMBean;
+
+public interface ServiceUnitMBean {
+
+ public String getName();
+
+ public String getDescription();
+
+ public String getComponentName();
+
+ public String getCurrentState();
+
+ public String getServiceAssembly();
+
+ public String getDescriptor();
+
+ public static final String STARTED = DeploymentServiceMBean.STARTED;
+
+ public static final String SHUTDOWN = DeploymentServiceMBean.SHUTDOWN;
+
+ public static final String STOPPED = DeploymentServiceMBean.STOPPED;
+}
Copied: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ClassLoaderService.java (from r381300, incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ClassLoaderService.java)
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ClassLoaderService.java?p2=incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ClassLoaderService.java&p1=incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ClassLoaderService.java&r1=381300&r2=382984&rev=382984&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ClassLoaderService.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ClassLoaderService.java Fri Mar 3 16:31:49 2006
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicemix.jbi.framework;
+package org.apache.servicemix.jbi.loaders;
import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
@@ -114,7 +114,7 @@
* @param sl
* @throws MalformedURLException
*/
- protected void addSharedLibrary(File dir, SharedLibrary sl)
+ public void addSharedLibrary(File dir, SharedLibrary sl)
throws MalformedURLException {
if (sl != null) {
boolean parentFirst = sl.isParentFirstClassLoaderDelegation();
@@ -145,7 +145,7 @@
*
* @param id
*/
- protected void removeSharedLibrary(String id) {
+ public void removeSharedLibrary(String id) {
sharedLibraryMap.remove(id);
}
@@ -154,7 +154,7 @@
* @param name
* @return true/false
*/
- protected boolean containsSharedLibrary(String name){
+ public boolean containsSharedLibrary(String name){
return sharedLibraryMap.containsKey(name);
}
}
Copied: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ClassLoaderUtil.java (from r381300, incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ClassLoaderUtil.java)
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ClassLoaderUtil.java?p2=incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ClassLoaderUtil.java&p1=incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ClassLoaderUtil.java&r1=381300&r2=382984&rev=382984&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ClassLoaderUtil.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ClassLoaderUtil.java Fri Mar 3 16:31:49 2006
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicemix.jbi.framework;
+package org.apache.servicemix.jbi.loaders;
import java.util.Map;
import java.lang.reflect.Field;
Copied: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/InstallationClassLoader.java (from r381300, incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallationClassLoader.java)
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/InstallationClassLoader.java?p2=incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/InstallationClassLoader.java&p1=incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallationClassLoader.java&r1=381300&r2=382984&rev=382984&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallationClassLoader.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/InstallationClassLoader.java Fri Mar 3 16:31:49 2006
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicemix.jbi.framework;
+package org.apache.servicemix.jbi.loaders;
import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList;
Copied: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ParentFirstClassLoader.java (from r381300, incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ParentFirstClassLoader.java)
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ParentFirstClassLoader.java?p2=incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ParentFirstClassLoader.java&p1=incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ParentFirstClassLoader.java&r1=381300&r2=382984&rev=382984&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ParentFirstClassLoader.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ParentFirstClassLoader.java Fri Mar 3 16:31:49 2006
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicemix.jbi.framework;
+package org.apache.servicemix.jbi.loaders;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Copied: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/SelfFirstClassLoader.java (from r381300, incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/SelfFirstClassLoader.java)
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/SelfFirstClassLoader.java?p2=incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/SelfFirstClassLoader.java&p1=incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/SelfFirstClassLoader.java&r1=381300&r2=382984&rev=382984&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/SelfFirstClassLoader.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/SelfFirstClassLoader.java Fri Mar 3 16:31:49 2006
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicemix.jbi.framework;
+package org.apache.servicemix.jbi.loaders;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/BaseLifeCycle.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/BaseLifeCycle.java?rev=382984&r1=382983&r2=382984&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/BaseLifeCycle.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/BaseLifeCycle.java Fri Mar 3 16:31:49 2006
@@ -29,8 +29,11 @@
* @version $Revision$
*/
public abstract class BaseLifeCycle implements LifeCycleMBean, MBeanInfoProvider {
+
public static final String INITIALIZED = "Initialized";
+
protected String currentState = LifeCycleMBean.UNKNOWN;
+
protected PropertyChangeListener listener;
@@ -114,7 +117,7 @@
* Set the current state
* @param newValue
*/
- public void setCurrentState(String newValue){
+ protected void setCurrentState(String newValue){
String oldValue = currentState;
this.currentState = newValue;
firePropertyChanged("currentState",oldValue,newValue);
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/BaseSystemService.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/BaseSystemService.java?rev=382984&r1=382983&r2=382984&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/BaseSystemService.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/BaseSystemService.java Fri Mar 3 16:31:49 2006
@@ -22,42 +22,48 @@
public abstract class BaseSystemService extends BaseLifeCycle {
protected JBIContainer container;
-
+
/**
* Get the name of the item
+ *
* @return the name
*/
public String getName() {
String name = getClass().getName();
int index = name.lastIndexOf(".");
- if (index >= 0 && (index+1) < name.length()) {
- name = name.substring(index+1);
+ if (index >= 0 && (index + 1) < name.length()) {
+ name = name.substring(index + 1);
}
return name;
}
/**
* Get the type of the item
+ *
* @return the type
*/
- public String getType() {
+ public String getType() {
return "SystemService";
- }
-
- public void init(JBIContainer container) throws JBIException {
- this.container = container;
- container.getManagementContext().registerSystemService(this, getServiceMBean());
-
- }
-
- public void shutDown() throws JBIException {
- stop();
- super.shutDown();
- if (container != null && container.getManagementContext() != null) {
- container.getManagementContext().unregisterMBean(this);
- }
- }
-
- protected abstract Class getServiceMBean();
-
+ }
+
+ public void init(JBIContainer container) throws JBIException {
+ this.container = container;
+ container.getManagementContext().registerSystemService(this, getServiceMBean());
+
+ }
+
+ public void shutDown() throws JBIException {
+ stop();
+ super.shutDown();
+ if (container != null && container.getManagementContext() != null) {
+ container.getManagementContext().unregisterMBean(this);
+ }
+ }
+
+ protected abstract Class getServiceMBean();
+
+ public JBIContainer getContainer() {
+ return container;
+ }
+
}
Copied: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/DeployServiceAssemblyTask.java (from r381300, incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallAssemblyTask.java)
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/DeployServiceAssemblyTask.java?p2=incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/DeployServiceAssemblyTask.java&p1=incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallAssemblyTask.java&r1=381300&r2=382984&rev=382984&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallAssemblyTask.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/DeployServiceAssemblyTask.java Fri Mar 3 16:31:49 2006
@@ -15,22 +15,16 @@
*/
package org.apache.servicemix.jbi.management.task;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.framework.AdminCommandsServiceMBean;
import org.apache.tools.ant.BuildException;
-import javax.jbi.management.DeploymentException;
-import javax.jbi.management.DeploymentServiceMBean;
-
-import java.io.IOException;
-
/**
* Install an Assembly
*
* @version $Revision$
*/
-public class InstallAssemblyTask extends JbiTask {
- private static final Log log = LogFactory.getLog(InstallAssemblyTask.class);
+public class DeployServiceAssemblyTask extends JbiTask {
+
private String file; //archivePath to install
/**
@@ -50,29 +44,14 @@
* execute the task
* @throws BuildException
*/
- public void execute() throws BuildException{
+ public void doExecute(AdminCommandsServiceMBean acs) throws Exception {
if (file == null){
- throw new BuildException("null archivePath - archivePath should be an archive");
+ throw new BuildException("null file - file should be an archive");
}
- if (file.endsWith(".zip") || file.endsWith(".jar")){
- try {
- DeploymentServiceMBean is = getDeploymentService();
- is.deploy(file);
- }
- catch (IOException e) {
- log.error("Caught an exception getting the installation service",e);
- throw new BuildException(e);
- }
- catch (DeploymentException e) {
- log.error("Deployment failed",e);
- throw new BuildException(e);
- }
- catch (Exception e) {
- log.error("Deployment failed",e);
- throw new BuildException(e);
- }
- }else {
- throw new BuildException("archivePath: " + file + " is not an archive");
+ if (!file.endsWith(".zip") && !file.endsWith(".jar")) {
+ throw new BuildException("file: " + file + " is not an archive");
}
+ acs.deployServiceAssembly(file);
}
+
}
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallComponentTask.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallComponentTask.java?rev=382984&r1=382983&r2=382984&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallComponentTask.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallComponentTask.java Fri Mar 3 16:31:49 2006
@@ -22,8 +22,6 @@
import java.util.List;
import java.util.Properties;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.jbi.framework.AdminCommandsServiceMBean;
import org.apache.tools.ant.BuildException;
@@ -33,7 +31,7 @@
* @version $Revision$
*/
public class InstallComponentTask extends JbiTask {
- private static final Log log = LogFactory.getLog(InstallComponentTask.class);
+
private String file; //file to install
private String paramsFile;
private List nestedParams;
@@ -71,33 +69,15 @@
* execute the task
* @throws BuildException
*/
- public void execute() throws BuildException{
+ public void doExecute(AdminCommandsServiceMBean acs) throws Exception {
if (file == null){
throw new BuildException("null file - file should be an archive");
}
if (!file.endsWith(".zip") && !file.endsWith(".jar")) {
throw new BuildException("file: " + file + " is not an archive");
}
- Properties props;
- try {
- props = getProperties();
- } catch (IOException e) {
- log.error("Error retrieving installation properties", e);
- throw new BuildException(e);
- }
- AdminCommandsServiceMBean acs;
- try {
- acs = getAdminCommandsService();
- } catch (IOException e) {
- log.error("Caught an exception getting the installation service", e);
- throw new BuildException(e);
- }
- try {
- acs.installComponent(file, props);
- } catch (Exception e) {
- log.error("Error installing component", e);
- throw new BuildException(e);
- }
+ Properties props = getProperties();
+ acs.installComponent(file, props);
}
private Properties getProperties() throws IOException {
@@ -130,4 +110,5 @@
this.value = value;
}
}
+
}
Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallSharedLibraryTask.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallSharedLibraryTask.java?rev=382984&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallSharedLibraryTask.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallSharedLibraryTask.java Fri Mar 3 16:31:49 2006
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.management.task;
+
+import org.apache.servicemix.jbi.framework.AdminCommandsServiceMBean;
+import org.apache.tools.ant.BuildException;
+
+/**
+ * Install a shared library
+ * @version $Revision: 359151 $
+ */
+public class InstallSharedLibraryTask extends JbiTask {
+
+ private String file; //shared library URI to install
+
+ /**
+ * @return Returns the file.
+ */
+ public String getFile() {
+ return file;
+ }
+ /**
+ * @param file The shared library URI to set.
+ */
+ public void setFile(String file) {
+ this.file = file;
+ }
+
+ /**
+ * execute the task
+ * @throws BuildException
+ */
+ public void doExecute(AdminCommandsServiceMBean acs) throws Exception {
+ if (file == null){
+ throw new BuildException("null file - file should be an archive");
+ }
+ if (!file.endsWith(".zip") && !file.endsWith(".jar")) {
+ throw new BuildException("file: " + file + " is not an archive");
+ }
+ acs.installSharedLibrary(file);
+ }
+
+}
\ No newline at end of file
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/JbiTask.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/JbiTask.java?rev=382984&r1=382983&r2=382984&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/JbiTask.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/JbiTask.java Fri Mar 3 16:31:49 2006
@@ -15,17 +15,8 @@
*/
package org.apache.servicemix.jbi.management.task;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.servicemix.jbi.container.JBIContainer;
-import org.apache.servicemix.jbi.framework.AdminCommandsServiceMBean;
-import org.apache.servicemix.jbi.framework.DeploymentService;
-import org.apache.servicemix.jbi.framework.FrameworkInstallationService;
-import org.apache.servicemix.jbi.framework.InstallationService;
-import org.apache.servicemix.jbi.management.ManagementContext;
-import org.apache.servicemix.jbi.management.ManagementContextMBean;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Task;
+import java.io.IOException;
+import java.net.MalformedURLException;
import javax.jbi.management.DeploymentServiceMBean;
import javax.management.MBeanServerInvocationHandler;
@@ -34,8 +25,14 @@
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
-import java.io.IOException;
-import java.net.MalformedURLException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.framework.AdminCommandsServiceMBean;
+import org.apache.servicemix.jbi.framework.DeploymentService;
+import org.apache.servicemix.jbi.management.ManagementContext;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
/**
* A bean for connecting to a remote JMX MBeanServer
@@ -43,7 +40,9 @@
* @version $Revision$
*/
public abstract class JbiTask extends Task {
- private static final Log log = LogFactory.getLog(JbiTask.class);
+
+ protected final Log log = LogFactory.getLog(getClass());
+
private String serverProtocol = "rmi";
private String host = "localhost";
private String containerName = JBIContainer.DEFAULT_NAME;
@@ -52,6 +51,7 @@
private String jndiPath = ManagementContext.DEFAULT_CONNECTOR_PATH;
private String username;
private String password;
+ private boolean failOnError = true;
private JMXConnector jmxConnector;
@@ -124,18 +124,6 @@
/**
- * Get the InstallationServiceMBean
- * @return the installation service MBean
- * @throws IOException
- */
- public FrameworkInstallationService getInstallationService() throws IOException{
- ObjectName objectName = getObjectName(InstallationService.class);
-
- return (FrameworkInstallationService) MBeanServerInvocationHandler.newProxyInstance(jmxConnector.getMBeanServerConnection(), objectName,
- FrameworkInstallationService.class, true);
- }
-
- /**
* Get the AdminCommandsService
* @return the main administration service MBean
* @throws IOException
@@ -161,18 +149,6 @@
/**
- * Get the ManagementContextMBean
- * @return the management service mbean
- * @throws IOException
- */
- public ManagementContextMBean getManagementContext() throws IOException{
- ObjectName objectName = getObjectName(ManagementContext.class);
-
- return (ManagementContextMBean) MBeanServerInvocationHandler.newProxyInstance(jmxConnector.getMBeanServerConnection(), objectName,
- ManagementContextMBean.class, true);
- }
-
- /**
* @return Returns the containerName.
*/
public String getContainerName() {
@@ -273,4 +249,50 @@
public void setUsername(String username) {
this.username = username;
}
+
+ /**
+ * @return Returns the failOnError.
+ */
+ public boolean isFailOnError() {
+ return failOnError;
+ }
+
+ /**
+ * @param failOnError The failOnError to set.
+ */
+ public void setFailOnError(boolean failOnError) {
+ this.failOnError = failOnError;
+ }
+
+ /**
+ * execute the task
+ *
+ * @throws BuildException
+ */
+ public void execute() throws BuildException {
+ AdminCommandsServiceMBean acs;
+ try {
+ acs = getAdminCommandsService();
+ } catch (IOException e) {
+ log.error("Error accessing ServiceMix administration", e);
+ if (isFailOnError()) {
+ throw new BuildException("Error accessing ServiceMix administration");
+ } else {
+ return;
+ }
+ }
+ try {
+ doExecute(acs);
+ } catch (Exception e) {
+ log.error("Error executing task", e);
+ if (isFailOnError()) {
+ throw new BuildException("Error accessing ServiceMix administration");
+ } else {
+ return;
+ }
+ }
+ }
+
+ protected abstract void doExecute(AdminCommandsServiceMBean acs) throws Exception;
+
}