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 2008/01/04 00:38:05 UTC
svn commit: r608674 - in /servicemix/smx4/nmr/trunk/jbi:
commands/src/main/java/org/apache/servicemix/jbi/commands/
deployer/src/main/java/org/apache/servicemix/jbi/deployer/
deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/
runtime/src/m...
Author: gnodet
Date: Thu Jan 3 15:37:55 2008
New Revision: 608674
URL: http://svn.apache.org/viewvc?rev=608674&view=rev
Log:
Fix lots of things wrt to JBI
Added:
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/PendingException.java
Modified:
servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/ListCommand.java
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/Component.java
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceUnitImpl.java
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentRegistryImpl.java
servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/IntegrationTest.java
Modified: servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/ListCommand.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/ListCommand.java?rev=608674&r1=608673&r2=608674&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/ListCommand.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/ListCommand.java Thu Jan 3 15:37:55 2008
@@ -46,6 +46,7 @@
for (Component component : components) {
io.out.println(component.getName() + " - " + component.getCurrentState() + " - " + component.getDescription());
}
+ io.out.println();
}
List<ServiceAssembly> assemblies = getServiceAssemblies();
@@ -55,6 +56,7 @@
for (ServiceAssembly assembly : assemblies) {
io.out.println(assembly.getName() + " - " + assembly.getCurrentState() + " - " + assembly.getDescription());
}
+ io.out.println();
}
return null; //To change body of implemented methods use File | Settings | File Templates.
}
Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/Component.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/Component.java?rev=608674&r1=608673&r2=608674&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/Component.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/Component.java Thu Jan 3 15:37:55 2008
@@ -23,4 +23,9 @@
*/
String getDescription();
+ /**
+ * Access to the JBI component
+ * @return
+ */
+ javax.jbi.component.Component getComponent();
}
Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java?rev=608674&r1=608673&r2=608674&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java Thu Jan 3 15:37:55 2008
@@ -74,7 +74,7 @@
}
private void onBundleStarted(Bundle bundle) {
- if (match(bundle)) {
+ if (match(bundle) && !bundles.contains(bundle)) {
register(bundle);
bundles.add(bundle);
}
Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java?rev=608674&r1=608673&r2=608674&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java Thu Jan 3 15:37:55 2008
@@ -55,7 +55,7 @@
public ComponentImpl(ComponentDesc componentDesc, javax.jbi.component.Component component) {
this.componentDesc = componentDesc;
- this.component = component;
+ this.component = new ComponentWrapper(component);
}
public String getName() {
Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java?rev=608674&r1=608673&r2=608674&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java Thu Jan 3 15:37:55 2008
@@ -69,12 +69,15 @@
private Map<Bundle, List<ServiceRegistration>> services;
+ private List<Bundle> pendingBundles;
+
private File jbiRootDir;
public Deployer() throws JBIException{
sharedLibraries = new ConcurrentHashMap<String, SharedLibraryImpl>();
serviceAssemblies = new ConcurrentHashMap<String, ServiceAssemblyImpl>();
services = new ConcurrentHashMap<Bundle, List<ServiceRegistration>>();
+ pendingBundles = new ArrayList<Bundle>();
// TODO: control that using properties
jbiRootDir = new File(System.getProperty("servicemix.base"), "jbi");
jbiRootDir.mkdirs();
@@ -104,6 +107,9 @@
} else {
installSharedLibrary(descriptor.getSharedLibrary(), bundle);
}
+ } catch (PendingException e) {
+ pendingBundles.add(e.getBundle());
+ LOGGER.warn("JBI artifact requirements not met. Installation pending.");
} catch (Exception e) {
LOGGER.error("Error handling bundle event", e);
}
@@ -111,14 +117,29 @@
@Override
protected void unregister(Bundle bundle) {
+ pendingBundles.remove(bundle);
List<ServiceRegistration> registrations = services.remove(bundle);
- for (ServiceRegistration reg : registrations) {
- reg.unregister();
+ if (registrations != null) {
+ for (ServiceRegistration reg : registrations) {
+ try {
+ reg.unregister();
+ } catch (IllegalStateException e) {
+ // Ignore
+ }
+ }
}
}
protected void installComponent(ComponentDesc componentDesc, Bundle bundle) throws Exception {
LOGGER.debug("Bundle '" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "' is a JBI component");
+ // Check requirements
+ if (componentDesc.getSharedLibraries() != null) {
+ for (SharedLibraryList sl : componentDesc.getSharedLibraries()) {
+ if (sharedLibraries.get(sl.getName()) == null) {
+ throw new PendingException(bundle, "SharedLibrary not installed: " + sl.getName());
+ }
+ }
+ }
// Create component class loader
ClassLoader classLoader = createComponentClassLoader(componentDesc, bundle);
Thread.currentThread().setContextClassLoader(classLoader);
@@ -134,17 +155,27 @@
LOGGER.debug("Registering JBI component");
registerService(bundle, Component.class.getName(), component, props);
registerService(bundle, javax.jbi.component.Component.class.getName(), component.getComponent(), props);
+ // Check pending bundles
+ checkPendingBundles();
}
protected void deployServiceAssembly(ServiceAssemblyDesc serviceAssembyDesc, Bundle bundle) throws Exception {
LOGGER.debug("Bundle '" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "' is a JBI service assembly");
+ // Check requirements
+ for (ServiceUnitDesc sud : serviceAssembyDesc.getServiceUnits()) {
+ String componentName = sud.getTarget().getComponentName();
+ Component component = getComponent(componentName);
+ if (component == null) {
+ throw new PendingException(bundle, "Component not installed: " + componentName);
+ }
+ }
// Create the SA directory
File saDir = new File(jbiRootDir, Long.toString(bundle.getBundleId()));
FileUtil.deleteFile(saDir);
FileUtil.buildDirectory(saDir);
// Iterate each SU and deploy it
List<ServiceUnitImpl> sus = new ArrayList<ServiceUnitImpl>();
- for (ServiceUnitDesc sud : Arrays.asList(serviceAssembyDesc.getServiceUnits())) {
+ for (ServiceUnitDesc sud : serviceAssembyDesc.getServiceUnits()) {
// Create directory for this SU
File suRootDir = new File(saDir, sud.getIdentification().getName());
suRootDir.mkdirs();
@@ -154,7 +185,7 @@
FileUtil.unpackArchive(zipUrl, suRootDir);
// Find component
String componentName = sud.getTarget().getComponentName();
- javax.jbi.component.Component component = getComponent(componentName);
+ Component component = getComponent(componentName);
// Create service unit object
ServiceUnitImpl su = new ServiceUnitImpl(sud, suRootDir, component);
su.deploy();
@@ -181,6 +212,16 @@
props.put(NAME, sharedLibraryDesc.getIdentification().getName());
LOGGER.debug("Registering JBI Shared Library");
registerService(bundle, SharedLibrary.class.getName(), sl, props);
+ // Check pending bundles
+ checkPendingBundles();
+ }
+
+ protected void checkPendingBundles() {
+ List<Bundle> pending = pendingBundles;
+ pendingBundles = new ArrayList<Bundle>();
+ for (Bundle bundle : pending) {
+ register(bundle);
+ }
}
protected void registerService(Bundle bundle, String clazz, Object service, Dictionary props) {
@@ -194,11 +235,11 @@
registrations.add(reg);
}
- protected javax.jbi.component.Component getComponent(String name) {
+ protected Component getComponent(String name) {
String filter = "(" + NAME + "=" + name + ")";
BundleContext context = getBundleContext();
- ServiceReference reference = OsgiServiceReferenceUtils.getServiceReference(context, javax.jbi.component.Component.class.getName(), filter);
- return (javax.jbi.component.Component) OsgiServiceUtils.getService(context, reference);
+ ServiceReference reference = OsgiServiceReferenceUtils.getServiceReference(context, Component.class.getName(), filter);
+ return (Component) OsgiServiceUtils.getService(context, reference);
}
protected ClassLoader createComponentClassLoader(ComponentDesc component, Bundle bundle) {
Added: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/PendingException.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/PendingException.java?rev=608674&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/PendingException.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/PendingException.java Thu Jan 3 15:37:55 2008
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.deployer.impl;
+
+import org.osgi.framework.Bundle;
+
+public class PendingException extends Exception {
+
+ private Bundle bundle;
+
+ public PendingException(Bundle bundle, String msg) {
+ super(msg);
+ this.bundle = bundle;
+ }
+
+ public Bundle getBundle() {
+ return bundle;
+ }
+}
Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java?rev=608674&r1=608673&r2=608674&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java Thu Jan 3 15:37:55 2008
@@ -95,7 +95,7 @@
public void stop() throws JBIException {
transition(State.Stopped);
}
-
+
protected void transition(State to) throws JBIException {
// TODO: reject invalid transitions, for example Started -> Shutdown
// we need to either automatically follow the intermediate steps, or just throw an exception
Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceUnitImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceUnitImpl.java?rev=608674&r1=608673&r2=608674&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceUnitImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceUnitImpl.java Thu Jan 3 15:37:55 2008
@@ -19,14 +19,14 @@
import java.io.File;
import javax.jbi.JBIException;
-import javax.jbi.component.Component;
+import javax.jbi.management.ComponentLifeCycleMBean;
+import javax.jbi.management.DeploymentException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.deployer.Component;
import org.apache.servicemix.jbi.deployer.ServiceUnit;
import org.apache.servicemix.jbi.deployer.descriptor.ServiceUnitDesc;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
public class ServiceUnitImpl implements ServiceUnit {
@@ -66,23 +66,43 @@
}
public void deploy() throws JBIException {
- component.getServiceUnitManager().deploy(getName(), getRootDir().getAbsolutePath());
+ component.getComponent().getServiceUnitManager().deploy(getName(), getRootDir().getAbsolutePath());
}
public void init() throws JBIException {
- component.getServiceUnitManager().init(getName(), getRootDir().getAbsolutePath());
+ component.getComponent().getServiceUnitManager().init(getName(), getRootDir().getAbsolutePath());
}
- public void shutdown() throws JBIException {
- component.getServiceUnitManager().shutDown(getName());
- }
-
public void start() throws JBIException {
- component.getServiceUnitManager().start(getName());
+ checkComponentStarted("start");
+ component.getComponent().getServiceUnitManager().start(getName());
}
public void stop() throws JBIException {
- component.getServiceUnitManager().stop(getName());
+ checkComponentStarted("stop");
+ component.getComponent().getServiceUnitManager().stop(getName());
+ }
+
+ public void shutdown() throws JBIException {
+ checkComponentStartedOrStopped("shutDown");
+ component.getComponent().getServiceUnitManager().shutDown(getName());
+ }
+
+ public void undeploy() throws JBIException {
+ component.getComponent().getServiceUnitManager().undeploy(getName(), getRootDir().getAbsolutePath());
+ }
+
+ protected void checkComponentStarted(String task) throws DeploymentException {
+ if (!ComponentLifeCycleMBean.STARTED.equals(component.getCurrentState())) {
+ throw new DeploymentException("Component " + component.getName() + " is not started!");
+ }
+ }
+
+ protected void checkComponentStartedOrStopped(String task) throws DeploymentException {
+ if (!ComponentLifeCycleMBean.STARTED.equals(component.getCurrentState())
+ && !ComponentLifeCycleMBean.STOPPED.equals(component.getCurrentState())) {
+ throw new DeploymentException("Component " + component.getName() + " is shut down!");
+ }
}
}
Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java?rev=608674&r1=608673&r2=608674&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java Thu Jan 3 15:37:55 2008
@@ -96,7 +96,7 @@
public synchronized void deactivateEndpoint(ServiceEndpoint endpoint) throws JBIException {
EndpointImpl ep = (EndpointImpl) endpoint;
- nmr.getEndpointRegistry().register(ep, null);
+ nmr.getEndpointRegistry().unregister(ep, null);
endpoints.remove(ep);
}
Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentRegistryImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentRegistryImpl.java?rev=608674&r1=608673&r2=608674&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentRegistryImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentRegistryImpl.java Thu Jan 3 15:37:55 2008
@@ -61,13 +61,16 @@
*/
public void register(Component component, Map<String, ?> properties) {
try {
+ if (components.containsValue(component)) {
+ // Component is already registered
+ return;
+ }
if (properties == null) {
properties = new HashMap<String, Object>();
}
String name = (String) properties.get(NAME);
ComponentContext context = new ComponentContextImpl(nmr, component, properties);
component.getLifeCycle().init(context);
- component.getLifeCycle().start();
if (name != null) {
components.put(name, component);
} else {
@@ -84,16 +87,14 @@
* @param component the component to unregister
*/
public void unregister(Component component, Map<String, ?> properties) {
- try {
- component.getLifeCycle().stop();
- component.getLifeCycle().shutDown();
+ //try {
String name = properties != null ? (String) properties.get(NAME) : null;
if (name != null) {
components.remove(name);
}
- } catch (JBIException e) {
- throw new ServiceMixException(e);
- }
+ //} catch (JBIException e) {
+ // throw new ServiceMixException(e);
+ //}
}
public Component getComponent(String name) {
Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/IntegrationTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/IntegrationTest.java?rev=608674&r1=608673&r2=608674&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/IntegrationTest.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/IntegrationTest.java Thu Jan 3 15:37:55 2008
@@ -76,6 +76,7 @@
ep.getTarget().setService(new QName("target"));
eip.setEndpoints(new EIPEndpoint[] { ep });
reg.register(eip, null);
+ eip.getLifeCycle().start();
Channel channel = smx.createChannel();
Exchange e = channel.createExchange(Pattern.InOnly);