You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by jb...@apache.org on 2009/04/21 09:50:12 UTC

svn commit: r767061 - in /servicemix/components/engines/servicemix-exec/trunk/src/main: java/org/apache/servicemix/exec/ExecEndpoint.java resources/ resources/META-INF/ resources/META-INF/spring/ resources/META-INF/spring/servicemix-exec.xml

Author: jbonofre
Date: Tue Apr 21 07:50:12 2009
New Revision: 767061

URL: http://svn.apache.org/viewvc?rev=767061&view=rev
Log:
Add the component bean descriptor.
Begin the endpoint provider process.

Added:
    servicemix/components/engines/servicemix-exec/trunk/src/main/resources/
    servicemix/components/engines/servicemix-exec/trunk/src/main/resources/META-INF/
    servicemix/components/engines/servicemix-exec/trunk/src/main/resources/META-INF/spring/
    servicemix/components/engines/servicemix-exec/trunk/src/main/resources/META-INF/spring/servicemix-exec.xml   (with props)
Modified:
    servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/ExecEndpoint.java

Modified: servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/ExecEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/ExecEndpoint.java?rev=767061&r1=767060&r2=767061&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/ExecEndpoint.java (original)
+++ servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/ExecEndpoint.java Tue Apr 21 07:50:12 2009
@@ -16,24 +16,70 @@
  */
 package org.apache.servicemix.exec;
 
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
 import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.RobustInOnly;
+import javax.jbi.messaging.MessageExchange.Role;
 
 import org.apache.servicemix.common.endpoints.ConsumerEndpoint;
 
 /**
- * ServiceMix Exec component endpoint
+ * Represents an exec endpoint.
  * 
  * @author jbonofre
  * @org.apache.xbean.XBean element="endpoint"
  */
 public class ExecEndpoint extends ConsumerEndpoint {
     
-    private String command;
-    private int timeout;
+    private String command; // the command can be static (define in the descriptor) or provided in the incoming message
     
-    // TODO
-    public void process(MessageExchange exchange) {
-        // TODO
+    @Override
+    public void process(MessageExchange exchange) throws Exception {
+        // for now, the component acts as a provider, this means that another component has requested our service
+        // As this exchange is active, this is either an in or a fault (out are sent by this component)
+        if (exchange.getRole() == Role.PROVIDER) {
+            if (exchange.getStatus() == ExchangeStatus.DONE) {
+                // exchange is finished
+                return;
+            } else if (exchange.getStatus() == ExchangeStatus.ERROR) {
+                // exchange has been aborted with an exception
+                return;
+            } else {
+                // exchange is active
+                this.handleProviderExchange(exchange);
+            }
+        } else {
+            // exchange role is not yet supported (consumer)
+            throw new IllegalStateException("Unsupported role: " + exchange.getRole());
+        }
+    }
+    
+    /**
+     * <p>
+     * Handlers on the message exchange (provider role).
+     * </p>
+     * 
+     * @param exchange the <code>MessageExchange</code>.
+     * @throws Exception if the <code>MessageExchange</code> doesn't contain in message or if an unexpected error occurs.
+     */
+    protected void handleProviderExchange(MessageExchange exchange) throws Exception {
+        // fault message
+        if (exchange.getFault() != null) {
+            done(exchange);
+        } else if (exchange.getMessage("in") != null) {
+            // in message presents
+            if (exchange instanceof InOnly || exchange instanceof RobustInOnly) {
+                // the MEP is InOnly based
+                if (logger.isDebugEnabled()) {
+                    logger.debug("Received exchange: " + exchange);
+                }
+                // TODO parse the in message, extract command/args and execute command
+            }
+        } else {
+            // the message exchange is not compliant with the default MEP
+            throw new IllegalStateException("Provider exchange is ACTIVE, but no in or fault is provided.");
+        }
     }
 
 }

Added: servicemix/components/engines/servicemix-exec/trunk/src/main/resources/META-INF/spring/servicemix-exec.xml
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-exec/trunk/src/main/resources/META-INF/spring/servicemix-exec.xml?rev=767061&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-exec/trunk/src/main/resources/META-INF/spring/servicemix-exec.xml (added)
+++ servicemix/components/engines/servicemix-exec/trunk/src/main/resources/META-INF/spring/servicemix-exec.xml Tue Apr 21 07:50:12 2009
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:ctx="http://www.springframework.org/schema/context"
+       xmlns:osgi="http://www.springframework.org/schema/osgi"
+       xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
+       xmlns:util="http://www.springframework.org/schema/util"
+       xsi:schemaLocation="
+  http://www.springframework.org/schema/beans
+  http://www.springframework.org/schema/beans/spring-beans.xsd
+  http://www.springframework.org/schema/context
+  http://www.springframework.org/schema/context/spring-context.xsd
+  http://www.springframework.org/schema/util
+  http://www.springframework.org/schema/util/spring-util.xsd
+  http://www.springframework.org/schema/osgi
+  http://www.springframework.org/schema/osgi/spring-osgi.xsd
+  http://www.springframework.org/schema/osgi-compendium
+  http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd">
+  
+    <bean id="servicemix-exec" class="org.apache.servicemix.exec.ExecComponent">
+        <property name="executorFactory" ref="executorFactory"/>
+    </bean>
+    
+    <bean id="executorFactory" class="org.apache.servicemix.executors.impl.ExecutorFactoryImpl">
+        <property name="defaultConfig">
+            <bean class="org.apache.servicemix.executors.impl.ExecutorConfig">
+                <property name="corePoolSize" value="${threadPoolCorePoolSize}"/>
+                <property name="maximumPoolSize" value="${threadPoolMaximumPoolSize}"/>
+                <property name="queueSize" value="${threadPoolQueueSize}"/>
+            </bean>
+        </property>
+    </bean>
+    
+    <bean id="endpoint-tracker" class="org.apache.servicemix.common.osgi.EndpointTracker">
+        <property name="component" ref="servicemix-exec"/>
+    </bean>
+    
+    <osgi:list id="endpoints"
+               interface="org.apache.servicemix.common.osgi.EndpointWrapper"
+               cardinality="0..N">
+        <osgi:listener ref="endpoint-tracker" bind-method="register" unbind-method="unregister"/>
+    </osgi:list>
+    
+    <osgi:service ref="servicemix-exec" interface="javax.jbi.component.Component">
+        <osgi:service-properties>
+            <entry key="NAME" value="servicemix-exec"/>
+            <entry key="TYPE" value="service-engine"/>
+        </osgi:service-properties>
+    </osgi:service>
+    
+    <osgix:cm-properties id="cmProps" persistent-id="servicemix-exec">
+        <prop key="threadPoolCorePoolSize">8</prop>
+        <prop key="threadPoolMaximumPoolSize">32</prop>
+        <prop key="threadPoolQueueSize">256</prop>
+    </osgix:cm-properties>
+    
+    <ctx:property-placeholder properties-ref="cmProps"/>
+
+</beans>
\ No newline at end of file

Propchange: servicemix/components/engines/servicemix-exec/trunk/src/main/resources/META-INF/spring/servicemix-exec.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain