Author: gnodet
Date: Wed Sep 27 04:48:23 2006
New Revision: 450406
URL: http://svn.apache.org/viewvc?view=rev&rev=450406
Log:
SM-569: Add BaseXBeanDeployer and ProviderEndpoint to ease the use of
servicemix-common
Add a validate method on the Endpoint
Also fix SU classloader use
Added:
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ProviderEndpoint.java
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/BaseXBeanDeployer.java
Modified:
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseServiceUnitManager.java
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java
Modified:
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseServiceUnitManager.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseServiceUnitManager.java?view=diff&rev=450406&r1=450405&r2=450406
==============================================================================
---
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseServiceUnitManager.java
(original)
+++
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseServiceUnitManager.java
Wed Sep 27 04:48:23 2006
@@ -131,6 +131,7 @@
* @see javax.jbi.component.ServiceUnitManager#start(java.lang.String)
*/
public synchronized void start(String serviceUnitName) throws
DeploymentException {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
if (logger.isDebugEnabled()) {
logger.debug("Starting service unit");
@@ -146,6 +147,7 @@
!LifeCycleMBean.SHUTDOWN.equals(su.getCurrentState())) {
throw failure("start", "ServiceUnit should be in a SHUTDOWN or
STOPPED state", null);
}
+
Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader());
su.start();
if (logger.isDebugEnabled()) {
logger.debug("Service unit started");
@@ -154,6 +156,8 @@
throw e;
} catch (Exception e) {
throw failure("start", "Unable to start service unit", e);
+ } finally {
+ Thread.currentThread().setContextClassLoader(cl);
}
}
@@ -161,6 +165,7 @@
* @see javax.jbi.component.ServiceUnitManager#stop(java.lang.String)
*/
public synchronized void stop(String serviceUnitName) throws
DeploymentException {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
if (logger.isDebugEnabled()) {
logger.debug("Stopping service unit");
@@ -175,6 +180,7 @@
if (!LifeCycleMBean.STARTED.equals(su.getCurrentState())) {
throw failure("stop", "ServiceUnit should be in a SHUTDOWN
state", null);
}
+
Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader());
su.stop();
if (logger.isDebugEnabled()) {
logger.debug("Service unit stopped");
@@ -183,6 +189,8 @@
throw e;
} catch (Exception e) {
throw failure("stop", "Unable to stop service unit", e);
+ } finally {
+ Thread.currentThread().setContextClassLoader(cl);
}
}
@@ -190,6 +198,7 @@
* @see javax.jbi.component.ServiceUnitManager#shutDown(java.lang.String)
*/
public synchronized void shutDown(String serviceUnitName) throws
DeploymentException {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
if (logger.isDebugEnabled()) {
logger.debug("Shutting down service unit");
@@ -201,6 +210,7 @@
if (su == null) {
throw failure("shutDown", "Service Unit '" + serviceUnitName +
"' is not deployed", null);
}
+
Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader());
su.shutDown();
if (logger.isDebugEnabled()) {
logger.debug("Service unit shut down");
@@ -209,6 +219,8 @@
throw e;
} catch (Exception e) {
throw failure("shutDown", "Unable to shutdown service unit", e);
+ } finally {
+ Thread.currentThread().setContextClassLoader(cl);
}
}
@@ -216,6 +228,7 @@
* @see javax.jbi.component.ServiceUnitManager#undeploy(java.lang.String,
java.lang.String)
*/
public synchronized String undeploy(String serviceUnitName, String
serviceUnitRootPath) throws DeploymentException {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
if (logger.isDebugEnabled()) {
logger.debug("Undeploying service unit");
@@ -233,6 +246,7 @@
if (!LifeCycleMBean.SHUTDOWN.equals(su.getCurrentState())) {
throw failure("undeploy", "ServiceUnit should be in a SHUTDOWN
state", null);
}
+
Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader());
doUndeploy(su);
component.getRegistry().unregisterServiceUnit(su);
if (logger.isDebugEnabled()) {
@@ -243,6 +257,8 @@
throw e;
} catch (Exception e) {
throw failure("undeploy", "Unable to undeploy service unit", e);
+ } finally {
+ Thread.currentThread().setContextClassLoader(cl);
}
}
Modified:
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java?view=diff&rev=450406&r1=450405&r2=450406
==============================================================================
---
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java
(original)
+++
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java
Wed Sep 27 04:48:23 2006
@@ -19,6 +19,7 @@
import org.apache.commons.logging.Log;
import org.w3c.dom.Document;
+import javax.jbi.management.DeploymentException;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessageExchange.Role;
import javax.wsdl.Definition;
@@ -127,6 +128,14 @@
"role: " + (getRole() == Role.PROVIDER ? "provider" :
"consumer") + "]";
}
+ /**
+ * Validate
+ * @return
+ * @throws DeploymentException
+ */
+ public void validate() throws DeploymentException {
+ }
+
public Definition getDefinition() {
return definition;
}
Added:
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ProviderEndpoint.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ProviderEndpoint.java?view=auto&rev=450406
==============================================================================
---
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ProviderEndpoint.java
(added)
+++
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ProviderEndpoint.java
Wed Sep 27 04:48:23 2006
@@ -0,0 +1,78 @@
+package org.apache.servicemix.common;
+
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.DeliveryChannel;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessageExchangeFactory;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.MessageExchange.Role;
+import javax.jbi.servicedesc.ServiceEndpoint;
+
+public abstract class ProviderEndpoint extends Endpoint implements
ExchangeProcessor {
+
+ private ServiceEndpoint activated;
+ private DeliveryChannel channel;
+ private MessageExchangeFactory exchangeFactory;
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.common.Endpoint#getRole()
+ */
+ public Role getRole() {
+ return Role.PROVIDER;
+ }
+
+ public void activate() throws Exception {
+ ComponentContext ctx =
getServiceUnit().getComponent().getComponentContext();
+ channel = ctx.getDeliveryChannel();
+ exchangeFactory = channel.createExchangeFactory();
+ activated = ctx.activateEndpoint(service, endpoint);
+ start();
+ }
+
+ public void deactivate() throws Exception {
+ stop();
+ ServiceEndpoint ep = activated;
+ activated = null;
+ ComponentContext ctx =
getServiceUnit().getComponent().getComponentContext();
+ ctx.deactivateEndpoint(ep);
+ }
+
+ public ExchangeProcessor getProcessor() {
+ return this;
+ }
+
+ protected void send(MessageExchange me) throws MessagingException {
+ if (me.getRole() == MessageExchange.Role.CONSUMER &&
+ me.getStatus() == ExchangeStatus.ACTIVE) {
+ BaseLifeCycle lf = (BaseLifeCycle)
getServiceUnit().getComponent().getLifeCycle();
+ lf.sendConsumerExchange(me, (Endpoint) this);
+ } else {
+ channel.send(me);
+ }
+ }
+
+ protected void done(MessageExchange me) throws MessagingException {
+ me.setStatus(ExchangeStatus.DONE);
+ send(me);
+ }
+
+ protected void fail(MessageExchange me, Exception error) throws
MessagingException {
+ me.setError(error);
+ send(me);
+ }
+
+ /**
+ * @return the exchangeFactory
+ */
+ public MessageExchangeFactory getExchangeFactory() {
+ return exchangeFactory;
+ }
+
+ public void start() throws Exception {
+ }
+
+ public void stop() throws Exception {
+ }
+
+}
Modified:
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java?view=diff&rev=450406&r1=450405&r2=450406
==============================================================================
---
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java
(original)
+++
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java
Wed Sep 27 04:48:23 2006
@@ -141,7 +141,7 @@
}
public ClassLoader getConfigurationClassLoader() {
- return null;
+ return component.getClass().getClassLoader();
}
}
Added:
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/BaseXBeanDeployer.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/BaseXBeanDeployer.java?view=auto&rev=450406
==============================================================================
---
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/BaseXBeanDeployer.java
(added)
+++
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/BaseXBeanDeployer.java
Wed Sep 27 04:48:23 2006
@@ -0,0 +1,54 @@
+/*
+ * 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.common.xbean;
+
+import javax.jbi.management.DeploymentException;
+
+import org.apache.servicemix.common.BaseComponent;
+import org.apache.servicemix.common.Endpoint;
+
+public class BaseXBeanDeployer extends AbstractXBeanDeployer {
+
+ private final Class[] endpointClasses;
+
+ public BaseXBeanDeployer(BaseComponent component) {
+ this(component, new Class[0]);
+ }
+
+ public BaseXBeanDeployer(BaseComponent component, Class endpointClass) {
+ this(component, new Class[] { endpointClass });
+ }
+
+ public BaseXBeanDeployer(BaseComponent component, Class[] endpointClasses)
{
+ super(component);
+ if (endpointClasses == null) {
+ throw new NullPointerException("endpointClasses must be non null");
+ }
+ this.endpointClasses = endpointClasses;
+ }
+
+ protected boolean validate(Endpoint endpoint) throws DeploymentException {
+ for (int i = 0; i < endpointClasses.length; i++) {
+ if (endpointClasses[i].isInstance(endpoint)) {
+ endpoint.validate();
+ return true;
+ }
+ }
+ return false;
+ }
+
+}