[jboss-svn-commits] JBL Code SVN: r32004 - in labs/jbossrules/branches/salaboy_ServiceAPIs: drools-services-grid and 20 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Mar 9 09:35:52 EST 2010


Author: salaboy21
Date: 2010-03-09 09:35:51 -0500 (Tue, 09 Mar 2010)
New Revision: 32004

Added:
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/pom.xml
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/DirectoryService.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/ExecutionGridConnection.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/GenericMessageGridHandlerImpl.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/GridExecutionNodeConnection.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/GridNodeExecutionService.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/KnowledgeBaseGridClient.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/KnowledgeBaseProviderGridClient.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/KnowledgeBuilderGridClient.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/KnowledgeBuilderProviderGridClient.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/StatefulKnowledgeSessionGridClient.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/WorkItemManagerGridClient.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/command/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/command/NewStatefulKnowledgeSessionGridCommand.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/impl/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/impl/DirectoryServiceImpl.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/impl/GridNodeExecutionServiceImpl.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/rio/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/rio/RioConnector.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/util/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/util/IDEntry.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/resources/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/conf/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/conf/test-config.groovy
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/java/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/java/org/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/java/org/drools/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/java/org/drools/services/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/java/org/drools/services/ExecutionNodeBaseTest.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/java/org/drools/services/ITGridExecutionTest.java
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/resources/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/resources/org/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/resources/org/drools/
   labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/resources/org/drools/executionNodeService.groovy
Log:
JBRULES-2446: Drools Services API
	- drools-services-grid initial commit


Property changes on: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid
___________________________________________________________________
Name: svn:ignore
   + target


Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/pom.xml
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/pom.xml	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/pom.xml	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>drools</artifactId>
+    <groupId>org.drools</groupId>
+    <version>5.1.0.SNAPSHOT</version>
+  </parent>
+  <groupId>org.drools</groupId>
+  <artifactId>drools-services-grid</artifactId>
+  <version>5.1.0.SNAPSHOT</version>
+  <name>Drools :: Services :: Grid</name>
+  <url>http://maven.apache.org</url>
+  <packaging>oar</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.6</version>
+      <scope>test</scope>
+    </dependency>
+
+     <!-- Drools Runtime -->
+        <dependency>
+            <groupId>org.drools</groupId>
+            <artifactId>drools-api</artifactId>
+
+            <type>jar</type>
+        </dependency>
+
+        <dependency>
+            <groupId>org.drools</groupId>
+            <artifactId>drools-core</artifactId>
+
+        </dependency>
+
+       <!-- Drools Services -->
+       <dependency>
+            <groupId>org.drools</groupId>
+            <artifactId>drools-services</artifactId>
+            <version>5.1.0.SNAPSHOT</version>
+        </dependency>
+
+        <!-- RIO Runtime -->
+         <dependency>
+            <groupId>org.rioproject</groupId>
+            <artifactId>rio</artifactId>
+            <version>4.0-M3</version>
+        </dependency>
+
+        <!-- RIO Test framework -->
+        <dependency>
+            <groupId>org.rioproject</groupId>
+            <artifactId>rio-test</artifactId>
+            <version>4.0-M3</version>
+            <scope>test</scope>
+        </dependency>
+
+  </dependencies>
+  <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-rio-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <opstring>src/test/resources/org/drools/executionNodeService.groovy</opstring>
+                    <createJar>
+                        <classifier>dl</classifier>
+                        <in>org.drools.services</in>
+                        <topclasses>
+                            <topclass>org.drools.services.grid.GridNodeExecutionService</topclass>
+                            <topclass>org.drools.services.grid.DirectoryService</topclass>
+                            <topclass>org.drools.services.grid.util.IDEntry</topclass>
+                            <topclass>org.drools.services.generic.GenericIoWriter</topclass>
+                        </topclasses>
+                    </createJar>
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+
+            <plugin>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <excludes>
+                        <exclude>**/*IT*.java</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>failsafe-maven-plugin</artifactId>
+                <version>2.4.3-alpha-1</version>
+                <configuration>
+                    <forkMode>always</forkMode>
+                    <argLine>-DRIO_TEST_ATTACH</argLine>
+                    <systemProperties>
+
+                        <property>
+                            <name>opstring</name>
+                            <value>src/test/resources/org/drools/executionNodeService.groovy</value>
+                        </property>
+                        <property>
+                            <name>org.rioproject.test.config</name>
+                            <value>src/test/conf/test-config.groovy</value>
+                        </property>
+                    </systemProperties>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>integration-test</goal>
+                            <goal>verify</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+    <repositories>
+        <repository>
+            <id>rio</id>
+            <url>http://www.rio-project.org/maven2</url>
+        </repository>
+        <repository>
+            <id>elastic-grid</id>
+            <url>http://maven.elastic-grid.com</url>
+        </repository>
+      
+    </repositories>
+
+    <pluginRepositories>
+        <pluginRepository>
+            <id>rio</id>
+            <url>http://www.rio-project.org/maven2</url>
+        </pluginRepository>
+
+        <pluginRepository>
+
+            <id>elastic-grid</id>
+            <url>http://maven.elastic-grid.com</url>
+
+        </pluginRepository>
+    </pluginRepositories>
+</project>

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/DirectoryService.java
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/DirectoryService.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/DirectoryService.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,22 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.drools.services.grid;
+
+import java.rmi.RemoteException;
+import org.drools.KnowledgeBase;
+
+
+/**
+ *
+ * @author salaboy
+ */
+
+public interface DirectoryService {
+    public void register(String executorId, String sessionServiceId) throws RemoteException;
+    public GridNodeExecutionService lookup(String executorId) throws RemoteException;
+    public void registerKBase(String kbaseId, String sessionServiceId) throws RemoteException;
+    public KnowledgeBase lookupKBase(String kbaseId) throws RemoteException;
+}

Copied: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/ExecutionGridConnection.java (from rev 31993, labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services/src/main/java/org/drools/services/ExecutionGridConnection.java)
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/ExecutionGridConnection.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/ExecutionGridConnection.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,80 @@
+/*
+ *  Copyright 2010 salaboy.
+ * 
+ *  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.
+ *  under the License.
+ */
+
+package org.drools.services.grid;
+
+import java.util.List;
+import org.drools.services.ExecutionNode;
+
+/**
+ *
+ * @author salaboy
+ */
+public class ExecutionGridConnection {
+    private List<ExecutionNode> nodes;
+    private DirectoryService directory;
+    private String url;
+
+    public ExecutionGridConnection() {
+
+    }
+
+    public void addNode(ExecutionNode node) {
+
+       this.nodes.add(node);
+
+    }
+
+    public ExecutionGridConnection(String url) {
+        this.url = url;
+    }
+
+    public List<ExecutionNode> connect(){
+        return this.nodes;
+    }
+
+    public List<ExecutionNode> getNodes() {
+        return nodes;
+    }
+
+    public void setNodes(List<ExecutionNode> nodes) {
+        this.nodes = nodes;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public DirectoryService getDirectory() {
+        return directory;
+    }
+
+    public void setDirectory(DirectoryService directory) {
+        this.directory = directory;
+    }
+
+    public ExecutionNode getPreferedExecutionNode() {
+        return nodes.get(0);
+    }
+
+    
+    
+}

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/GenericMessageGridHandlerImpl.java
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/GenericMessageGridHandlerImpl.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/GenericMessageGridHandlerImpl.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,143 @@
+package org.drools.services.grid;
+
+import java.io.IOException;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceTemplate;
+import net.jini.discovery.LookupDiscoveryManager;
+import net.jini.lease.LeaseRenewalManager;
+import net.jini.lookup.ServiceDiscoveryManager;
+
+import org.drools.SystemEventListener;
+import org.drools.command.FinishedCommand;
+import org.drools.command.impl.ContextImpl;
+import org.drools.command.impl.GenericCommand;
+import org.drools.runtime.impl.ExecutionResultImpl;
+import org.drools.services.generic.ExecutionNodeData;
+import org.drools.services.generic.GenericIoWriter;
+import org.drools.services.generic.GenericMessageHandler;
+import org.drools.services.generic.Message;
+
+
+public class GenericMessageGridHandlerImpl implements GenericMessageHandler {
+    private SystemEventListener systemEventListener;
+
+    private ExecutionNodeData  data;
+    private DirectoryService registry;
+
+    public GenericMessageGridHandlerImpl(ExecutionNodeData data,
+                                 SystemEventListener systemEventListener) {
+        this.systemEventListener = systemEventListener;
+        this.data = data;
+        
+        Class[] classes = new Class[]{org.drools.services.grid.DirectoryService.class};
+        ServiceTemplate tmpl = new ServiceTemplate(null, classes,null);
+
+        LookupDiscoveryManager lookupDiscovery = null;
+        try {
+            lookupDiscovery = new LookupDiscoveryManager(LookupDiscoveryManager.ALL_GROUPS, null, null);
+        } catch (IOException ex) {
+            Logger.getLogger(GenericMessageGridHandlerImpl.class.getName()).log(Level.SEVERE, null, ex);
+        }
+
+        System.out.println("Discovering Manager service ...");
+
+        ServiceDiscoveryManager serviceDiscovery =  null;
+        try {
+            serviceDiscovery = new ServiceDiscoveryManager(lookupDiscovery, new LeaseRenewalManager());
+        } catch (IOException ex) {
+            Logger.getLogger(GenericMessageGridHandlerImpl.class.getName()).log(Level.SEVERE, null, ex);
+        }
+
+        /* Wait no more then 10 seconds to discover the service */
+        ServiceItem item = null;
+        try {
+            try {
+                item = serviceDiscovery.lookup(tmpl, null, 1000);
+            } catch (RemoteException ex) {
+                Logger.getLogger(GenericMessageGridHandlerImpl.class.getName()).log(Level.SEVERE, null, ex);
+            }
+        } catch (InterruptedException ex) {
+            Logger.getLogger(GenericMessageGridHandlerImpl.class.getName()).log(Level.SEVERE, null, ex);
+        }
+        serviceDiscovery.terminate();
+
+        if(item != null) {
+            System.out.println("Discovered Registry service");
+            if(item.service instanceof DirectoryService){
+                registry = (DirectoryService)item.service;
+
+            }
+
+
+        } else {
+            System.out.println("Registry service not discovered, make sure the"+
+                               "service is deployed");
+        }
+
+    }
+
+  
+
+    
+
+    
+    /* (non-Javadoc)
+     * @see org.drools.vsm.GenericMessageHandler#messageReceived(org.drools.vsm.GenericIoWriter, org.drools.vsm.Message)
+     */
+    public void messageReceived(GenericIoWriter session,
+                                Message msg) throws Exception {
+        systemEventListener.debug( "Message receieved : " + msg );
+
+
+        // we always need to process a List, for genericity, but don't force a List on the payload
+        List<GenericCommand> commands;
+        if ( msg.getPayload() instanceof List ) {
+            commands = (List<GenericCommand>) msg.getPayload();
+        } else {
+            commands = new ArrayList<GenericCommand>();
+            commands.add( (GenericCommand) msg.getPayload() );
+        }
+
+        // Setup the evaluation context 
+        ContextImpl localSessionContext = new ContextImpl( "session_" + msg.getSessionId(),
+                                                           this.data.getContextManager(),
+                                                           this.data.getTemp() );        
+        ExecutionResultImpl localKresults = new ExecutionResultImpl();
+        localSessionContext.set( "kresults_" + msg.getSessionId(),
+                                 localKresults );
+        System.out.println("Registering the registry itself!!!!!!!!!!!!!!!!!! = "+registry);
+        localSessionContext.set("registry", registry);
+        
+        for ( GenericCommand cmd : commands ) {
+            // evaluate the commands
+            cmd.execute( localSessionContext );
+        }
+
+        if(localSessionContext.get("kbase") != null){
+            session.write( new Message( msg.getSessionId(),
+                                        msg.getResponseId(),
+                                        msg.isAsync(),
+                                        localSessionContext.get("kbase") ), null );
+        
+        } else if ( !msg.isAsync() && localKresults.getIdentifiers().isEmpty() ) {
+            // if it's not an async invocation and their are no results, just send a simple notification message
+            session.write( new Message( msg.getSessionId(),
+                                        msg.getResponseId(),
+                                        msg.isAsync(),
+                                        new FinishedCommand() ), null );
+
+
+        }  else{
+            // return the payload
+            session.write( new Message( msg.getSessionId(),
+                                        msg.getResponseId(),
+                                        msg.isAsync(),
+                                        localKresults ), null );
+        }
+    }
+}

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/GridExecutionNodeConnection.java
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/GridExecutionNodeConnection.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/GridExecutionNodeConnection.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,352 @@
+package org.drools.services.grid;
+
+import java.rmi.RemoteException;
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.drools.KnowledgeBase;
+import org.drools.KnowledgeBaseFactoryService;
+import org.drools.agent.KnowledgeAgentProvider;
+import org.drools.builder.DecisionTableConfiguration;
+import org.drools.builder.KnowledgeBuilder;
+import org.drools.builder.KnowledgeBuilderConfiguration;
+import org.drools.builder.KnowledgeBuilderFactoryService;
+import org.drools.command.Command;
+import org.drools.command.FinishedCommand;
+import org.drools.command.KnowledgeContextResolveFromContextCommand;
+
+import org.drools.persistence.jpa.JPAKnowledgeServiceProvider;
+import org.drools.runtime.CommandExecutor;
+import org.drools.runtime.Environment;
+import org.drools.runtime.ExecutionResults;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.services.ExecutionNode;
+import org.drools.services.command.ExecutionNodeClientConnectCommand;
+import org.drools.services.command.LookupCommand;
+import org.drools.services.command.RegisterCommand;
+import org.drools.services.generic.GenericConnector;
+import org.drools.services.generic.Message;
+import org.drools.services.grid.rio.RioConnector;
+
+import org.drools.vsm.HumanTaskServiceProvider;
+
+import org.drools.vsm.ServiceManager;
+
+
+public class GridExecutionNodeConnection
+    implements
+    ServiceManager {
+	private String name;
+
+    public GenericConnector client;
+
+    private List<GenericConnector> services;
+
+    public AtomicInteger    counter;
+
+    private int sessionId = -1;
+
+    //@TODO: i need to refactor this to a service in the list of services???
+    private DirectoryService registryService;
+
+    public GridExecutionNodeConnection(String name, GenericConnector client) {
+    	this.name = name;
+    	this.client = client;
+    	this.counter = new AtomicInteger();
+        this.services = null;
+    }
+    
+    public GridExecutionNodeConnection(String name, GenericConnector client, List<GenericConnector> services) {
+        this(name, client);
+        this.services = services;
+    }
+
+     
+
+    public boolean connect() {
+        boolean connected = this.client.connect();
+
+        if ( connected ) {
+            String commandId = "serviceManager.connected" + getNextId();
+            String kresultsId = "kresults_" + getSessionId();
+
+            Message msg = new Message( -1,
+                                       counter.incrementAndGet(),
+                                       false,
+                                       new KnowledgeContextResolveFromContextCommand( new ExecutionNodeClientConnectCommand( commandId ),
+                                                                                      null,
+                                                                                      null,
+                                                                                      null,
+                                                                                      kresultsId ) );
+
+            try {
+                Object object = client.write( msg ).getPayload();
+
+                if ( object == null ) {
+                    throw new RuntimeException( "Response was not correctly received" );
+                }
+
+                sessionId = (Integer) ((ExecutionResults) object).getValue( commandId );
+
+                connected = true;
+            } catch ( Exception e ) {
+                throw new RuntimeException( "Unable to execute message",
+                                            e );
+            }
+        }
+        // Connecting with services
+        if (this.services != null) {
+        	for (GenericConnector connector : services){
+        		boolean serviceConnected = connector.connect();
+        		if ( serviceConnected ){
+        			System.out.println("Service Connected");
+                        }
+        	}
+        }
+
+        return connected;
+    }
+
+	public void disconnect() {
+		this.client.disconnect();
+		if (this.services != null){
+			for (GenericConnector connector : this.services){
+				connector.disconnect();
+                        }
+                }
+	}
+
+   
+
+    public KnowledgeAgentProvider getKnowledgeAgentFactory() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public JPAKnowledgeServiceProvider JPAKnowledgeService() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Environment getEnvironment() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Collection<String> list() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void register(String identifier,
+                         CommandExecutor executor) {
+        String commandId = "client.lookup" + getNextId();
+        String kresultsId = "kresults_" + getSessionId();
+
+        int type;
+        if ( executor instanceof StatefulKnowledgeSession ) {
+            type = 0;
+        } else {
+            throw new IllegalArgumentException( "Type is not supported for registration" );
+        }
+
+        Message msg = new Message( getSessionId(),
+                                   counter.incrementAndGet(),
+                                   false,
+                                   new KnowledgeContextResolveFromContextCommand( new RegisterCommand( identifier,
+                                                                                                       ((StatefulKnowledgeSessionGridClient) executor).getInstanceId(),
+                                                                                                       type ),
+                                                                                  null,
+                                                                                  null,
+                                                                                  null,
+                                                                                  null ) );
+        System.out.println("Registering "+identifier + " - - "+client.getId());
+        try {
+            
+            registryService.register(identifier, client.getId());
+        } catch (RemoteException ex) {
+            Logger.getLogger(GridExecutionNodeConnection.class.getName()).log(Level.SEVERE, null, ex);
+        }
+        try {
+
+
+            Object object = client.write( msg ).getPayload();
+            
+            
+            if ( !(object instanceof FinishedCommand) ) {
+                throw new RuntimeException( "Response was not correctly ended" );
+            }
+        } catch ( Exception e ) {
+            throw new RuntimeException( "Unable to execute message",
+                                        e );
+        }
+    }
+
+    public CommandExecutor lookup(String identifier) {
+        String commandId = "client.lookup" + getNextId();
+        String kresultsId = "kresults_" + getSessionId();
+
+        Message msg = new Message( getSessionId(),
+                                   counter.incrementAndGet(),
+                                   false,
+                                   new KnowledgeContextResolveFromContextCommand( new LookupCommand( identifier,
+                                                                                                     commandId ),
+                                                                                  null,
+                                                                                  null,
+                                                                                  null,
+                                                                                  kresultsId ) );
+        System.out.println("Looking up the session with identifier = "+identifier);
+            try {
+            //First I need to get the correct client GridNodeExecutionService with the identifier
+            
+            client.setSession(registryService.lookup(identifier));
+        } catch (RemoteException ex) {
+            Logger.getLogger(GridExecutionNodeConnection.class.getName()).log(Level.SEVERE, null, ex);
+        }
+        try {
+            Object object = client.write( msg ).getPayload();
+
+            if ( object == null ) {
+                throw new RuntimeException( "Response was not correctly received" );
+            }
+            String value = (String) ((ExecutionResults) object).getValue( commandId );
+            String type = String.valueOf( value.charAt( 0 ) );
+            String instanceId = value.substring( 2 );
+
+            CommandExecutor executor = null;
+            switch ( Integer.parseInt( type ) ) {
+                case 0 : {
+                    executor = new StatefulKnowledgeSessionGridClient( instanceId,
+                                                                         this );
+                    break;
+                }
+                default : {
+
+                }
+
+            }
+
+            return executor;
+        } catch ( Exception e ) {
+            throw new RuntimeException( "Unable to execute message",
+                                        e );
+        }
+    }
+
+    public void release(Object object) {
+        // TODO Auto-generated method stub
+    }
+
+    public void release(String identifier) {
+        // TODO Auto-generated method stub
+    }
+
+    public HumanTaskServiceProvider getHumanTaskService() {
+    	//return new HumanTaskServiceGridProviderImpl(this);
+        //@TODO: create human task service module project
+        return null;
+    }
+
+    @Override
+    public KnowledgeBuilderFactoryService getKnowledgeBuilderFactoryService() {
+        return new KnowledgeBuilderProviderGridClient( this );
+    }
+
+    @Override
+    public KnowledgeBaseFactoryService getKnowledgeBaseFactoryService() {
+        return new KnowledgeBaseProviderGridClient( this );
+    }
+
+    public static class RemoveKnowledgeBuilderProvider implements KnowledgeBuilderFactoryService {
+
+        public DecisionTableConfiguration newDecisionTableConfiguration() {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public KnowledgeBuilder newKnowledgeBuilder() {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public KnowledgeBuilder newKnowledgeBuilder(KnowledgeBuilderConfiguration conf) {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public KnowledgeBuilder newKnowledgeBuilder(KnowledgeBase kbase) {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public KnowledgeBuilder newKnowledgeBuilder(KnowledgeBase kbase,
+                                                    KnowledgeBuilderConfiguration conf) {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public KnowledgeBuilderConfiguration newKnowledgeBuilderConfiguration() {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public KnowledgeBuilderConfiguration newKnowledgeBuilderConfiguration(Properties properties,
+                                                                              ClassLoader classLoader) {
+            // TODO Auto-generated method stub
+            return null;
+        }
+    }
+
+    public int getSessionId() {
+        return sessionId;
+    }
+
+    public int getNextId() {
+        return this.counter.incrementAndGet();
+    }
+
+    public ExecutionResults execute(Command command) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+	public List<GenericConnector> getServices() {
+		return services;
+	}
+	
+	public String getName() {
+		return this.name;
+	}
+
+    public DirectoryService getRegistryService() {
+        return registryService;
+    }
+
+    public void setRegistryService(DirectoryService registryService) {
+        this.registryService = registryService;
+    }
+
+    public void setCurrentSessionService(GridNodeExecutionService sessionService){
+        this.client.setSession(sessionService);
+    }
+    
+//    public List<GridNodeExecutionService> getSessionServices(){
+////        List<GridNodeExecutionService> sessionServices =
+////        ((RioConnector)this.client).getSessionServices();
+////        List<String> ids = new ArrayList<String>();
+////        for(GridNodeExecutionService ss : sessionServices){
+////            try {
+////                ids.add(ss.getId());
+////            } catch (RemoteException ex) {
+////                Logger.getLogger(ServiceManagerGridClient.class.getName()).log(Level.SEVERE, null, ex);
+////            }
+////        }
+////        return ids;
+//        return ((RioConnector)this.client).getNodeServices();
+//    }
+//
+}

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/GridNodeExecutionService.java
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/GridNodeExecutionService.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/GridNodeExecutionService.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,20 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.drools.services.grid;
+
+import java.rmi.RemoteException;
+import org.drools.services.generic.GenericIoWriter;
+import org.drools.services.generic.Message;
+
+
+/**
+ *
+ * @author salaboy
+ */
+public interface GridNodeExecutionService extends GenericIoWriter {
+    public String  getId() throws RemoteException;
+    public Message write(Message msg) throws RemoteException;    
+    
+}

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/KnowledgeBaseGridClient.java
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/KnowledgeBaseGridClient.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/KnowledgeBaseGridClient.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,190 @@
+package org.drools.services.grid;
+
+import java.rmi.RemoteException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import java.util.Collection;
+import java.util.UUID;
+
+import org.drools.KnowledgeBase;
+import org.drools.command.FinishedCommand;
+import org.drools.command.KnowledgeBaseAddKnowledgePackagesCommand;
+import org.drools.command.KnowledgeContextResolveFromContextCommand;
+import org.drools.command.SetVariableCommand;
+import org.drools.definition.KnowledgePackage;
+import org.drools.definition.process.Process;
+import org.drools.definition.rule.Rule;
+import org.drools.definition.type.FactType;
+import org.drools.event.knowledgebase.KnowledgeBaseEventListener;
+import org.drools.runtime.Environment;
+import org.drools.runtime.KnowledgeSessionConfiguration;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.StatelessKnowledgeSession;
+import org.drools.services.generic.CollectionClient;
+import org.drools.services.generic.Message;
+import org.drools.services.grid.command.NewStatefulKnowledgeSessionGridCommand;
+
+
+public class KnowledgeBaseGridClient
+    implements
+    KnowledgeBase {
+
+    private GridExecutionNodeConnection nodeConnection;
+    private String                     instanceId;
+
+    public KnowledgeBaseGridClient(String instanceId,
+                                     GridExecutionNodeConnection nodeConnection) {
+        this.instanceId = instanceId;
+        this.nodeConnection = nodeConnection;
+    }
+
+    public void addKnowledgePackages(Collection<KnowledgePackage> kpackages) {
+        String kresultsId = "kresults_" + nodeConnection.getSessionId();
+
+        String kuilderInstanceId = ((CollectionClient<KnowledgePackage>) kpackages).getParentInstanceId();
+        Message msg = new Message( nodeConnection.getSessionId(),
+                                   nodeConnection.counter.incrementAndGet(),
+                                   false,
+                                   new KnowledgeContextResolveFromContextCommand( new KnowledgeBaseAddKnowledgePackagesCommand(),
+                                                                                  kuilderInstanceId,
+                                                                                  instanceId,
+                                                                                  null,
+                                                                                  kresultsId ) );
+        try {
+            //I should register the kbase ID??
+            nodeConnection.getRegistryService().registerKBase(instanceId, nodeConnection.client.getId());
+        } catch (RemoteException ex) {
+            Logger.getLogger(KnowledgeBaseGridClient.class.getName()).log(Level.SEVERE, null, ex);
+        }
+
+        try {
+            Object object = nodeConnection.client.write( msg ).getPayload();
+
+            if ( !(object instanceof FinishedCommand) ) {
+                throw new RuntimeException( "Response was not correctly ended" );
+            }
+
+        } catch ( Exception e ) {
+            throw new RuntimeException( "Unable to execute message",
+                                        e );
+        }
+    }
+
+    public FactType getFactType(String packageName,
+                                String typeName) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public KnowledgePackage getKnowledgePackage(String packageName) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Collection<KnowledgePackage> getKnowledgePackages() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Process getProcess(String processId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Rule getRule(String packageName,
+                        String ruleName) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public StatefulKnowledgeSession newStatefulKnowledgeSession() {
+        return newStatefulKnowledgeSession( null,
+                                            null );
+    }
+
+    public StatefulKnowledgeSession newStatefulKnowledgeSession(KnowledgeSessionConfiguration conf,
+                                                                Environment environment) {
+        String kresultsId = "kresults_" + nodeConnection.getSessionId();
+
+        String localId = UUID.randomUUID().toString();
+
+        Message msg = new Message( nodeConnection.getSessionId(),
+                                   nodeConnection.counter.incrementAndGet(),
+                                   false,
+                                   new SetVariableCommand( "__TEMP__",
+                                                           localId,
+                                                           new KnowledgeContextResolveFromContextCommand( new NewStatefulKnowledgeSessionGridCommand( null, instanceId ),
+                                                                                                          null,
+                                                                                                          instanceId,
+                                                                                                          null,
+                                                                                                          kresultsId ) ) );
+
+        try {
+            Object object = nodeConnection.client.write( msg ).getPayload();
+            
+            if ( !(object instanceof FinishedCommand) ) {
+                throw new RuntimeException( "Response was not correctly ended" );
+            }
+
+        } catch ( Exception e ) {
+            throw new RuntimeException( "Unable to execute message",
+                                        e );
+        }
+
+        return new StatefulKnowledgeSessionGridClient( localId,
+                                                         nodeConnection );
+    }
+
+    public StatelessKnowledgeSession newStatelessKnowledgeSession(KnowledgeSessionConfiguration conf) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public StatelessKnowledgeSession newStatelessKnowledgeSession() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void removeKnowledgePackage(String packageName) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void removeProcess(String processId) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void removeRule(String packageName,
+                           String ruleName) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void addEventListener(KnowledgeBaseEventListener listener) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public Collection<KnowledgeBaseEventListener> getKnowledgeBaseEventListeners() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void removeEventListener(KnowledgeBaseEventListener listener) {
+        // TODO Auto-generated method stub
+
+    }
+
+	public void removeFunction(String packageName, String ruleName) {
+		// TODO Auto-generated method stub
+	}
+
+   
+
+    public void setServiceManager(GridExecutionNodeConnection serviceManager) {
+        this.nodeConnection = serviceManager;
+    }
+
+}

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/KnowledgeBaseProviderGridClient.java
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/KnowledgeBaseProviderGridClient.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/KnowledgeBaseProviderGridClient.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,106 @@
+package org.drools.services.grid;
+
+
+import java.util.Properties;
+import java.util.UUID;
+
+import org.drools.KnowledgeBase;
+import org.drools.KnowledgeBaseConfiguration;
+import org.drools.KnowledgeBaseFactoryService;
+
+import org.drools.command.FinishedCommand;
+import org.drools.command.NewKnowledgeBaseCommand;
+import org.drools.command.SetVariableCommand;
+import org.drools.runtime.Environment;
+import org.drools.runtime.KnowledgeSessionConfiguration;
+import org.drools.services.generic.Message;
+
+
+public class KnowledgeBaseProviderGridClient
+    implements
+    KnowledgeBaseFactoryService {
+    private GridExecutionNodeConnection serviceManager;
+    private String localId = "";
+    public KnowledgeBaseProviderGridClient(GridExecutionNodeConnection serviceManager) {
+        this.serviceManager = serviceManager;
+    }
+
+    public Environment newEnvironment() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public KnowledgeBase newKnowledgeBase() {
+        return newKnowledgeBase( ( KnowledgeBaseConfiguration ) null );
+    }
+
+    public KnowledgeBase newKnowledgeBase(KnowledgeBaseConfiguration conf) {
+        //return new NewKnowledgeBaseCommand(null);
+        if(localId == null || localId.equals("")){
+            localId = UUID.randomUUID().toString();
+        }
+
+        Message msg = new Message( serviceManager.getSessionId(),
+                                   serviceManager.counter.incrementAndGet(),
+                                   false,
+                                   new SetVariableCommand( "__TEMP__",
+                                                           localId,
+                                                           new NewKnowledgeBaseCommand( null ) ) );
+        try {
+            Object object = serviceManager.client.write( msg ).getPayload();
+
+            if ( !(object instanceof FinishedCommand) ) {
+                throw new RuntimeException( "Response was not correctly ended" );
+            }
+
+        } catch ( Exception e ) {
+            throw new RuntimeException( "Unable to execute message",
+                                        e );
+        } 
+
+        return new KnowledgeBaseGridClient( localId,
+                                              serviceManager );
+
+    }
+
+    public KnowledgeBaseConfiguration newKnowledgeBaseConfiguration() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public KnowledgeBaseConfiguration newKnowledgeBaseConfiguration(Properties properties,
+                                                                    ClassLoader classLoader) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public KnowledgeSessionConfiguration newKnowledgeSessionConfiguration() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public KnowledgeSessionConfiguration newKnowledgeSessionConfiguration(Properties properties) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public KnowledgeBase newKnowledgeBase(String kbaseId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public KnowledgeBase newKnowledgeBase(String kbaseId,
+                                          KnowledgeBaseConfiguration conf) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public String getLocalId() {
+        return localId;
+    }
+
+    public void setLocalId(String localId) {
+        this.localId = localId;
+    } 
+ 
+}

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/KnowledgeBuilderGridClient.java
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/KnowledgeBuilderGridClient.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/KnowledgeBuilderGridClient.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,139 @@
+package org.drools.services.grid;
+
+import org.drools.KnowledgeBase;
+
+import java.util.Collection;
+
+import org.drools.builder.KnowledgeBuilder;
+import org.drools.builder.KnowledgeBuilderErrors;
+import org.drools.builder.ResourceConfiguration;
+import org.drools.builder.ResourceType;
+import org.drools.command.FinishedCommand;
+import org.drools.command.KnowledgeContextResolveFromContextCommand;
+import org.drools.command.builder.KnowledgeBuilderAddCommand;
+import org.drools.command.builder.KnowledgeBuilderGetErrorsCommand;
+import org.drools.command.builder.KnowledgeBuilderHasErrorsCommand;
+import org.drools.definition.KnowledgePackage;
+import org.drools.io.Resource;
+import org.drools.runtime.ExecutionResults;
+import org.drools.services.generic.CollectionClient;
+import org.drools.services.generic.Message;
+
+
+public class KnowledgeBuilderGridClient
+    implements
+    KnowledgeBuilder {
+    private GridExecutionNodeConnection serviceManager;
+    private String                     instanceId;
+
+    public KnowledgeBuilderGridClient(String instanceId,
+                                        GridExecutionNodeConnection serviceManager) {
+        this.instanceId = instanceId;
+        this.serviceManager = serviceManager;
+    }
+
+    public void add(Resource resource,
+                    ResourceType resourceType) {
+        add( resource,
+             resourceType,
+             null );
+    }
+
+    public void add(Resource resource,
+                    ResourceType resourceType,
+                    ResourceConfiguration configuration) {
+        Message msg = new Message( serviceManager.getSessionId(),
+                                   serviceManager.counter.incrementAndGet(),
+                                   false,
+                                   new KnowledgeContextResolveFromContextCommand( new KnowledgeBuilderAddCommand( resource,
+                                                                                                                  resourceType,
+                                                                                                                  configuration ),
+                                                                                  instanceId,
+                                                                                  null,
+                                                                                  null,
+                                                                                  null ) );
+
+        try {
+            Object object = serviceManager.client.write( msg ).getPayload();
+
+            if ( !(object instanceof FinishedCommand) ) {
+                throw new RuntimeException( "Response was not correctly ended" );
+            }
+
+        } catch ( Exception e ) {
+            throw new RuntimeException( "Unable to execute message",
+                                        e );
+        }
+
+    }
+
+    public KnowledgeBuilderErrors getErrors() {
+        String commandId = "kbuilder.getErrors_" + serviceManager.getNextId();
+        String kresultsId = "kresults_" + serviceManager.getSessionId();
+
+        Message msg = new Message( serviceManager.getSessionId(),
+                                   serviceManager.counter.incrementAndGet(),
+                                   false,
+                                   new KnowledgeContextResolveFromContextCommand( new KnowledgeBuilderGetErrorsCommand( commandId ),
+                                                                                  instanceId,
+                                                                                  null,
+                                                                                  null,
+                                                                                  kresultsId ) );
+
+        try {
+            Object object = serviceManager.client.write( msg ).getPayload();
+
+            if ( object == null ) {
+                throw new RuntimeException( "Response was not correctly received" );
+            }
+
+            return (KnowledgeBuilderErrors) ((ExecutionResults) object).getValue( commandId );            
+
+        } catch ( Exception e ) {
+            throw new RuntimeException( "Unable to execute message",
+                                        e );
+        }
+        
+    }
+
+    public Collection<KnowledgePackage> getKnowledgePackages() {
+        return new CollectionClient<KnowledgePackage>( this.instanceId );
+    }
+
+    public boolean hasErrors() {
+        String commandId = "kbuilder.hasErrors_" + serviceManager.getNextId();
+        String kresultsId = "kresults_" + serviceManager.getSessionId();
+
+        Message msg = new Message( serviceManager.getSessionId(),
+                                   serviceManager.getNextId(),
+                                   false,
+                                   new KnowledgeContextResolveFromContextCommand( new KnowledgeBuilderHasErrorsCommand( commandId ),
+                                                                                  instanceId,
+                                                                                  null,
+                                                                                  null,
+                                                                                  kresultsId ) );
+
+        try {
+            Object object = serviceManager.client.write( msg ).getPayload();
+
+            if ( object == null ) {
+                throw new RuntimeException( "Response was not correctly received" );
+            }
+
+            return (Boolean) ((ExecutionResults) object).getValue( commandId );
+
+        } catch ( Exception e ) {
+            throw new RuntimeException( "Unable to execute message",
+                                        e );
+        }
+        
+        
+        
+    }
+
+    @Override
+    public KnowledgeBase newKnowledgeBase() {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+}

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/KnowledgeBuilderProviderGridClient.java
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/KnowledgeBuilderProviderGridClient.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/KnowledgeBuilderProviderGridClient.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,89 @@
+/**
+ * 
+ */
+package org.drools.services.grid;
+
+
+import java.util.Properties;
+import java.util.UUID;
+
+import org.drools.KnowledgeBase;
+import org.drools.builder.DecisionTableConfiguration;
+import org.drools.builder.KnowledgeBuilder;
+import org.drools.builder.KnowledgeBuilderConfiguration;
+import org.drools.builder.KnowledgeBuilderFactoryService;
+
+import org.drools.command.FinishedCommand;
+import org.drools.command.SetVariableCommand;
+import org.drools.command.builder.NewKnowledgeBuilderCommand;
+import org.drools.services.generic.Message;
+
+
+public class KnowledgeBuilderProviderGridClient
+    implements
+    KnowledgeBuilderFactoryService {
+    private GridExecutionNodeConnection nodeConnection;
+
+    public KnowledgeBuilderProviderGridClient(GridExecutionNodeConnection nodeConnection) {
+        this.nodeConnection = nodeConnection;
+    }
+
+    public DecisionTableConfiguration newDecisionTableConfiguration() {
+        // TODO Auto-generated method stub
+        return null; 
+    }
+
+    public KnowledgeBuilder newKnowledgeBuilder() {
+        String localId = UUID.randomUUID().toString();
+
+        Message msg = new Message( nodeConnection.getSessionId(),
+                                   nodeConnection.counter.incrementAndGet(),
+                                   false,
+                                   new SetVariableCommand( "__TEMP__",
+                                                           localId,
+                                                           new NewKnowledgeBuilderCommand( null ) ) );
+
+        try {
+            Object object = nodeConnection.client.write( msg ).getPayload();
+
+            if ( !(object instanceof FinishedCommand) ) {
+                throw new RuntimeException( "Response was not correctly ended" );
+            }
+
+        } catch ( Exception e ) {
+            throw new RuntimeException( "Unable to execute message",
+                                        e );
+        }
+
+        return new KnowledgeBuilderGridClient( localId,
+                                                 nodeConnection );
+    }
+
+    public KnowledgeBuilder newKnowledgeBuilder(KnowledgeBuilderConfiguration conf) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public KnowledgeBuilder newKnowledgeBuilder(KnowledgeBase kbase) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public KnowledgeBuilder newKnowledgeBuilder(KnowledgeBase kbase,
+                                                KnowledgeBuilderConfiguration conf) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public KnowledgeBuilderConfiguration newKnowledgeBuilderConfiguration() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public KnowledgeBuilderConfiguration newKnowledgeBuilderConfiguration(Properties properties,
+                                                                          ClassLoader classLoader) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}
\ No newline at end of file

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/StatefulKnowledgeSessionGridClient.java
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/StatefulKnowledgeSessionGridClient.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/StatefulKnowledgeSessionGridClient.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,420 @@
+package org.drools.services.grid;
+
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.drools.KnowledgeBase;
+import org.drools.command.Command;
+import org.drools.command.ExecuteCommand;
+import org.drools.command.KnowledgeContextResolveFromContextCommand;
+import org.drools.command.runtime.rule.FireAllRulesCommand;
+import org.drools.event.process.ProcessEventListener;
+import org.drools.event.rule.AgendaEventListener;
+import org.drools.event.rule.WorkingMemoryEventListener;
+import org.drools.runtime.Calendars;
+import org.drools.runtime.Environment;
+import org.drools.runtime.ExecutionResults;
+import org.drools.runtime.ExitPoint;
+import org.drools.runtime.Globals;
+import org.drools.runtime.ObjectFilter;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.process.ProcessInstance;
+import org.drools.runtime.process.WorkItemManager;
+import org.drools.runtime.rule.Agenda;
+import org.drools.runtime.rule.AgendaFilter;
+import org.drools.runtime.rule.FactHandle;
+import org.drools.runtime.rule.QueryResults;
+import org.drools.runtime.rule.WorkingMemoryEntryPoint;
+import org.drools.services.command.GetWorkItemManagerCommand;
+import org.drools.services.command.RegisterRemoteWorkItemHandlerCommand;
+import org.drools.services.command.StartProcessRemoteCommand;
+import org.drools.services.generic.Message;
+import org.drools.time.SessionClock;
+
+
+public class StatefulKnowledgeSessionGridClient
+    implements
+    StatefulKnowledgeSession {
+
+    private GridExecutionNodeConnection serviceManager;
+    private String                     instanceId;
+
+    public StatefulKnowledgeSessionGridClient(String instanceId,
+                                                GridExecutionNodeConnection serviceManager) {
+        this.instanceId = instanceId;
+        this.serviceManager = serviceManager;
+    }
+
+    public String getInstanceId() {
+        return this.instanceId;
+    }
+
+    public void dispose() {
+        // TODO Auto-generated method stub
+
+    }
+
+    public int getId() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public int fireAllRules() {
+        String commandId = "ksession.fireAllRules" + serviceManager.getNextId();
+        String kresultsId = "kresults_" + serviceManager.getSessionId();
+
+        Message msg = new Message( serviceManager.getSessionId(),
+                                   serviceManager.counter.incrementAndGet(),
+                                   false,
+                                   new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand( commandId ),
+                                                                                  null,
+                                                                                  null,
+                                                                                  instanceId,
+                                                                                  kresultsId ) );
+        try {
+            Object object = serviceManager.client.write( msg ).getPayload();
+
+            if ( object == null ) {
+                throw new RuntimeException( "Response was not correctly received" );
+            }
+
+            return (Integer) ((ExecutionResults) object).getValue( commandId );
+        } catch ( Exception e ) {
+            throw new RuntimeException( "Unable to execute message",
+                                        e );
+        }
+    }
+
+    public int fireAllRules(int max) {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public int fireAllRules(AgendaFilter agendaFilter) {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public void fireUntilHalt() {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void fireUntilHalt(AgendaFilter agendaFilter) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public ExecutionResults execute(Command command) {
+        String commandId = "ksession.execute" + serviceManager.getNextId();
+        String kresultsId = "kresults_" + serviceManager.getSessionId();
+
+        Message msg = new Message( serviceManager.getSessionId(),
+                                   serviceManager.counter.incrementAndGet(),
+                                   false,
+                                   new KnowledgeContextResolveFromContextCommand( new ExecuteCommand( commandId,
+                                                                                                      command ),
+                                                                                  null,
+                                                                                  null,
+                                                                                  instanceId,
+                                                                                  kresultsId ) );
+
+        try {
+            Object object = serviceManager.client.write( msg ).getPayload();if ( object == null ) {
+                throw new RuntimeException( "Response was not correctly received" );
+            }
+
+            return (ExecutionResults) ((ExecutionResults) object).getValue( commandId );
+        } catch ( Exception e ) {
+            throw new RuntimeException( "Unable to execute message",
+                                        e );
+        }
+    }
+
+    public Environment getEnvironment() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Object getGlobal(String identifier) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Globals getGlobals() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public KnowledgeBase getKnowledgeBase() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public <T extends SessionClock> T getSessionClock() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void registerExitPoint(String name,
+                                  ExitPoint exitPoint) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void setGlobal(String identifier,
+                          Object object) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void unregisterExitPoint(String name) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public Agenda getAgenda() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public QueryResults getQueryResults(String query) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public QueryResults getQueryResults(String query,
+                                        Object[] arguments) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public WorkingMemoryEntryPoint getWorkingMemoryEntryPoint(String name) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Collection< ? extends WorkingMemoryEntryPoint> getWorkingMemoryEntryPoints() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void halt() {
+        // TODO Auto-generated method stub
+
+    }
+
+    public FactHandle getFactHandle(Object object) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public <T extends FactHandle> Collection<T> getFactHandles() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public <T extends FactHandle> Collection<T> getFactHandles(ObjectFilter filter) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Object getObject(FactHandle factHandle) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Collection<Object> getObjects() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Collection<Object> getObjects(ObjectFilter filter) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public FactHandle insert(Object object) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void retract(FactHandle handle) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void update(FactHandle handle,
+                       Object object) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void abortProcessInstance(long id) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public ProcessInstance getProcessInstance(long id) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Collection<ProcessInstance> getProcessInstances() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public WorkItemManager getWorkItemManager() {
+    	 String kresultsId = "kresults_" + serviceManager.getSessionId();
+         Message msg = new Message( serviceManager.getSessionId(),
+                                    serviceManager.counter.incrementAndGet(),
+                                    true,
+                                    new KnowledgeContextResolveFromContextCommand( new GetWorkItemManagerCommand(),
+                                                                                   null,
+                                                                                   null,
+                                                                                   instanceId,
+                                                                                   kresultsId ) );
+         try {
+             Object payload = serviceManager.client.write( msg ).getPayload();
+             WorkItemManager workItemManager = (WorkItemManager) ((ExecutionResults) payload).getValue( "workItemManager" );
+             ((WorkItemManagerGridClient)workItemManager).setServiceManager(serviceManager);
+             ((WorkItemManagerGridClient)workItemManager).setInstanceId(instanceId);
+             return workItemManager;
+         } catch ( Exception e ) {
+             throw new RuntimeException( "Unable to execute message", e );
+         }
+    }
+    
+    public void registerWorkItemHandler(String name, String workItemHandler){
+        
+        String kresultsId = "kresults_" + serviceManager.getSessionId();
+
+        Message msg = new Message( serviceManager.getSessionId(),
+                                   serviceManager.counter.incrementAndGet(),
+                                   false,
+                                   new KnowledgeContextResolveFromContextCommand( new RegisterRemoteWorkItemHandlerCommand(name, workItemHandler ),
+                                                                                  null,
+                                                                                  null,
+                                                                                  instanceId,
+                                                                                  kresultsId ) );
+
+        try {
+            serviceManager.client.write( msg );
+            
+        } catch ( Exception e ) {
+            throw new RuntimeException( "Unable to execute message",
+                                        e );
+        }
+
+
+    }
+
+    public void signalEvent(String type,
+                            Object event) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public ProcessInstance startProcess(String processId) {
+        String commandId = "ksession.execute" + serviceManager.getNextId();
+        String kresultsId = "kresults_" + serviceManager.getSessionId();
+
+        Message msg = new Message( serviceManager.getSessionId(),
+                                   serviceManager.counter.incrementAndGet(),
+                                   false,
+                                   new KnowledgeContextResolveFromContextCommand( new StartProcessRemoteCommand( processId ),
+                                                                                  null,
+                                                                                  null,
+                                                                                  instanceId,
+                                                                                  kresultsId ) );
+
+        try {
+            Object object = serviceManager.client.write( msg ).getPayload();
+            if ( object == null ) {
+                throw new RuntimeException( "Response was not correctly received" );
+            }
+
+            return (ProcessInstance) ((ExecutionResults) object).getValue( processId );
+        } catch ( Exception e ) {
+            throw new RuntimeException( "Unable to execute message",
+                                        e );
+        }
+        
+    }
+
+    public ProcessInstance startProcess(String processId,
+                                        Map<String, Object> parameters) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void addEventListener(WorkingMemoryEventListener listener) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void addEventListener(AgendaEventListener listener) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public Collection<AgendaEventListener> getAgendaEventListeners() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Collection<WorkingMemoryEventListener> getWorkingMemoryEventListeners() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void removeEventListener(WorkingMemoryEventListener listener) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void removeEventListener(AgendaEventListener listener) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void addEventListener(ProcessEventListener listener) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public Collection<ProcessEventListener> getProcessEventListeners() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void removeEventListener(ProcessEventListener listener) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public String getEntryPointId() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public long getFactCount() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public void signalEvent(String type,
+                            Object event,
+                            long processInstanceId) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public Calendars getCalendars() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/WorkItemManagerGridClient.java
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/WorkItemManagerGridClient.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/WorkItemManagerGridClient.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,58 @@
+package org.drools.services.grid;
+
+
+import java.io.Serializable;
+import java.util.Map;
+
+import org.drools.command.KnowledgeContextResolveFromContextCommand;
+import org.drools.command.runtime.process.CompleteWorkItemCommand;
+import org.drools.runtime.process.WorkItemHandler;
+import org.drools.runtime.process.WorkItemManager;
+import org.drools.services.generic.Message;
+
+
+/**
+ *
+ * @author Lucas Amador
+ */
+public class WorkItemManagerGridClient implements WorkItemManager, Serializable {
+
+	private static final long serialVersionUID = 1L;
+	
+	private GridExecutionNodeConnection serviceManager;
+	private String instanceId;
+
+	public void abortWorkItem(long id) {
+		throw new UnsupportedOperationException("Not supported yet.");
+	}
+
+	public void completeWorkItem(long id, Map<String, Object> results) {
+		String kresultsId = "kresults_" + serviceManager.getSessionId();
+        Message msg = new Message( serviceManager.getSessionId(),
+                                   serviceManager.counter.incrementAndGet(),
+                                   true,
+                                   new KnowledgeContextResolveFromContextCommand( new CompleteWorkItemCommand(id, results),
+                                                                                  null,
+                                                                                  null,
+                                                                                  instanceId,
+                                                                                  kresultsId ) );
+        try {
+            serviceManager.client.write( msg );
+        } catch ( Exception e ) {
+            throw new RuntimeException( "Unable to execute message", e );
+        }
+	}
+
+	public void registerWorkItemHandler(String workItemName, WorkItemHandler handler) {
+		throw new UnsupportedOperationException("Not supported yet.");
+	}
+
+	public void setServiceManager(GridExecutionNodeConnection serviceManager) {
+		this.serviceManager = serviceManager;
+	}
+
+	public void setInstanceId(String instanceId) {
+		this.instanceId = instanceId;
+	}
+
+}

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/command/NewStatefulKnowledgeSessionGridCommand.java
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/command/NewStatefulKnowledgeSessionGridCommand.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/command/NewStatefulKnowledgeSessionGridCommand.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,61 @@
+package org.drools.services.grid.command;
+
+import java.rmi.RemoteException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.drools.KnowledgeBase;
+import org.drools.command.Context;
+import org.drools.command.impl.GenericCommand;
+import org.drools.command.impl.KnowledgeCommandContext;
+import org.drools.runtime.KnowledgeSessionConfiguration;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.services.grid.DirectoryService;
+
+
+public class NewStatefulKnowledgeSessionGridCommand
+    implements
+    GenericCommand<StatefulKnowledgeSession> {
+
+    private KnowledgeSessionConfiguration ksessionConf;
+    private String kbaseId;
+    
+    public NewStatefulKnowledgeSessionGridCommand(KnowledgeSessionConfiguration ksessionConf) {
+        this.ksessionConf = ksessionConf;
+    }
+
+    public NewStatefulKnowledgeSessionGridCommand(KnowledgeSessionConfiguration ksessionConf, String kbaseId) {
+        this.ksessionConf = ksessionConf;
+        this.kbaseId = kbaseId;
+    }
+    
+
+    public StatefulKnowledgeSession execute(Context context) {
+
+        KnowledgeBase kbase = ((KnowledgeCommandContext) context).getKnowledgeBase();
+        DirectoryService registry = (DirectoryService)context.get("registry");
+        System.out.println("Inside Grid Command!!!!!!!!");
+        System.out.println("Registry = "+registry);
+        System.out.println("KbaseId = "+kbaseId);
+        StatefulKnowledgeSession ksession;
+
+        if( kbase == null){
+            try {
+                //@TODO: need to find the best way to injec the service in the command or the command executor.
+                //lookup in the registry service.
+                kbase = registry.lookupKBase(kbaseId);
+            } catch (RemoteException ex) {
+                Logger.getLogger(NewStatefulKnowledgeSessionGridCommand.class.getName()).log(Level.SEVERE, null, ex);
+            }
+        }
+        if ( this.ksessionConf == null ) {
+            System.out.println("Kbase inside the newStatefull Session = "+kbase);
+            ksession = kbase.newStatefulKnowledgeSession();
+            
+        } else {
+            ksession = kbase.newStatefulKnowledgeSession( this.ksessionConf, null );
+        }
+
+        return ksession;
+    }
+
+}

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/impl/DirectoryServiceImpl.java
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/impl/DirectoryServiceImpl.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/impl/DirectoryServiceImpl.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,96 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.drools.services.grid.impl;
+
+import java.rmi.RemoteException;
+import java.util.HashMap;
+import java.util.Map;
+import org.drools.KnowledgeBase;
+import org.drools.command.KnowledgeContextResolveFromContextCommand;
+import org.drools.command.runtime.GetKnowledgeBaseCommand;
+import org.drools.services.generic.Message;
+import org.drools.services.grid.GridNodeExecutionService;
+import org.drools.services.grid.DirectoryService;
+
+
+/**
+ *
+ * @author salaboy
+ */
+public class DirectoryServiceImpl implements DirectoryService{
+
+    
+
+    private Map<String, String> registry = new HashMap<String, String>();
+
+    private Map<String, String> kbaseregistry = new HashMap<String, String>();
+
+    public DirectoryServiceImpl() {
+    }
+
+    
+    private Iterable<GridNodeExecutionService> nodeServices;
+    @Override
+    public void register(String sessionId, String sessionServiceId) throws RemoteException {
+        System.out.println("Registering: "+  sessionId + " -- "+sessionServiceId);
+        registry.put(sessionId, sessionServiceId);
+    }
+
+    @Override
+    public GridNodeExecutionService lookup(String sessionId) throws RemoteException {
+        GridNodeExecutionService sessionService = null;
+        String sessionServiceId = (String)registry.get(sessionId);
+        System.out.println("Registry = "+ registry.toString());
+        System.out.println("Nodes Services = "+nodeServices);
+        for(GridNodeExecutionService ss : nodeServices){
+            System.out.println("Session Service id = "+ss.getId() + "needs to match with ="+sessionServiceId);
+            if(ss.getId().equals(sessionServiceId)){
+                sessionService = ss;
+            }
+        }     
+
+        return sessionService;
+    }
+
+
+    public void setSessionServices(Iterable<GridNodeExecutionService> nodeServices) {
+        this.nodeServices = nodeServices;
+    }
+
+    @Override
+    public void registerKBase(String kbaseId, String nodeServiceId) throws RemoteException {
+        System.out.println("Registering KnowledgeBase = "+kbaseId +" -in NS=" +nodeServiceId);
+        kbaseregistry.put(kbaseId, nodeServiceId);
+    }
+
+    @Override
+    public KnowledgeBase lookupKBase(String kbaseId) throws RemoteException{
+        GridNodeExecutionService nodeService = null;
+        String nodeServiceId = (String)kbaseregistry.get(kbaseId);
+        System.out.println("Kbase Registry = "+ kbaseregistry.toString());
+        System.out.println("Session Services = "+nodeService);
+        for(GridNodeExecutionService ns : nodeServices){
+            System.out.println("Node Service id = "+ns.getId() + "needs to match with ="+nodeServiceId);
+            if(ns.getId().equals(nodeServiceId)){
+                nodeService = ns;
+            }
+        }
+        System.out.println("Node Service = "+nodeService);
+        
+        try {
+            Message msg = nodeService.write(new Message(999,1000,false, new KnowledgeContextResolveFromContextCommand( new GetKnowledgeBaseCommand(), null, kbaseId, null, null)));
+            System.out.println("MSG returned by nodeService = "+msg);
+            if (msg.getPayload() instanceof KnowledgeBase) {
+                System.out.println("Kbase in the payload: "+(KnowledgeBase)msg.getPayload());
+                return (KnowledgeBase)msg.getPayload();
+            }
+            return null;
+        } catch ( Exception e ) {
+            throw new RuntimeException( "Unable to execute message",
+                                        e );
+        }
+    }
+}

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/impl/GridNodeExecutionServiceImpl.java
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/impl/GridNodeExecutionServiceImpl.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/impl/GridNodeExecutionServiceImpl.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,90 @@
+/*
+ *  Copyright 2009 salaboy.
+ * 
+ *  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.
+ *  under the License.
+ */
+package org.drools.services.grid.impl;
+
+import java.rmi.RemoteException;
+import java.util.UUID;
+
+import org.drools.SystemEventListener;
+import org.drools.SystemEventListenerFactory;
+import org.drools.services.generic.BlockingGenericIoWriter;
+import org.drools.services.generic.GenericMessageHandler;
+import org.drools.services.generic.Message;
+import org.drools.services.generic.MessageResponseHandler;
+import org.drools.services.generic.ExecutionNodeData;
+import org.drools.services.grid.GenericMessageGridHandlerImpl;
+import org.drools.services.grid.GridNodeExecutionService;
+import org.drools.services.grid.util.IDEntry;
+
+import org.rioproject.core.jsb.ServiceBeanContext;
+
+/**
+ *
+ * @author salaboy
+ */
+public class GridNodeExecutionServiceImpl implements GridNodeExecutionService {
+
+    private GenericMessageHandler handler;
+    private String id;
+    
+
+    public GridNodeExecutionServiceImpl() {
+        this.id = UUID.randomUUID().toString();
+        handler = new GenericMessageGridHandlerImpl(new ExecutionNodeData(), SystemEventListenerFactory.getSystemEventListener());
+    }
+
+    public GridNodeExecutionServiceImpl(ExecutionNodeData data,
+            SystemEventListener systemEventListener) {
+        handler = new GenericMessageGridHandlerImpl(data, systemEventListener); 
+    }
+
+    public Message write(Message msg) throws RemoteException {
+        BlockingGenericIoWriter blockingWriter = new BlockingGenericIoWriter();
+        try {
+            handler.messageReceived(blockingWriter, msg);
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RemoteException(e.getMessage());
+        }
+
+        return blockingWriter.getMessage();
+    }
+
+    public GenericMessageHandler getGenericMessageHandler() {
+        return this.handler;
+    }
+
+    public void write(Message msg,
+            MessageResponseHandler responseHandler) {
+        throw new UnsupportedOperationException();
+    }
+
+    public void setServiceBeanContext(ServiceBeanContext context) {
+        context.addAttribute(new IDEntry(this.id));
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+   
+    
+}

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/rio/RioConnector.java
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/rio/RioConnector.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/rio/RioConnector.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,131 @@
+package org.drools.services.grid.rio;
+
+
+import java.rmi.RemoteException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.net.SocketAddress;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.drools.SystemEventListener;
+import org.drools.services.generic.GenericConnector;
+import org.drools.services.generic.Message;
+import org.drools.services.generic.MessageResponseHandler;
+import org.drools.services.grid.GridNodeExecutionService;
+
+
+public class RioConnector
+    implements
+    GenericConnector {  
+
+    protected final String                 name;
+    protected AtomicInteger                counter;
+    protected GridNodeExecutionService               nodeService;
+    //protected List<GridNodeExecutionService>         nodeServices;
+    protected SocketAddress                address;
+    protected SystemEventListener          eventListener;
+  
+    public RioConnector(String name,
+                        SystemEventListener eventListener
+                       ) {
+        if ( name == null ) {
+            throw new IllegalArgumentException( "Name can not be null" );
+        }
+        this.name = name;
+        this.counter = new AtomicInteger();
+        this.eventListener = eventListener;
+   
+    }
+
+    public RioConnector(String name,
+                        SystemEventListener eventListener,
+                        //List<GridNodeExecutionService> sessionServices
+                        GridNodeExecutionService nodeService
+                        ) {
+        if ( name == null ) {
+            throw new IllegalArgumentException( "Name can not be null" );
+        }
+        this.name = name;
+        this.counter = new AtomicInteger();
+        this.eventListener = eventListener;
+        this.nodeService = nodeService;
+       // this.nodeServices = sessionServices;
+       
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.vsm.mina.Messenger#connect()
+     */
+    public boolean connect() {
+        
+        return true;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.vsm.mina.Messenger#disconnect()
+     */
+    public void disconnect() {
+        //I don't need to be disconected
+    }
+
+    public Message write(Message msg) {
+        if ( nodeService != null ) {
+            try {
+
+                Message returnMessage = this.nodeService.write( msg );
+                return returnMessage;
+                //                ioHandler.messageReceived( sessionService ,
+                //                                           returnMessage );
+
+            } catch ( RemoteException ex ) {
+                Logger.getLogger( RioConnector.class.getName() ).log( Level.SEVERE,
+                                                                      null,
+                                                                      ex );
+            } catch ( Exception ex ) {
+                Logger.getLogger( RioConnector.class.getName() ).log( Level.SEVERE,
+                                                                      null,
+                                                                      ex );
+            }
+        }
+        throw new IllegalStateException( "sessionService should not be null" );
+    }
+    
+    public void write(Message msg,
+                      MessageResponseHandler responseHandler) {
+        throw new UnsupportedOperationException();
+    }
+
+ 
+    public String getId() {
+        try {
+            return nodeService.getId();
+        } catch (RemoteException ex) {
+            Logger.getLogger(RioConnector.class.getName()).log(Level.SEVERE, null, ex);
+        }
+        return null;
+    }
+
+    public GridNodeExecutionService getCurrentNodeService() {
+        return nodeService;
+    }
+
+//    public List<GridNodeExecutionService> getNodeServices() {
+//        return nodeServices;
+//    }
+
+    
+
+    
+    public void setSession(Object object) {
+        this.nodeService = (GridNodeExecutionService) object;
+        try {
+            System.out.println("Setting Node Service = " + nodeService.getId());
+        } catch (RemoteException ex) {
+            Logger.getLogger(RioConnector.class.getName()).log(Level.SEVERE, null, ex);
+        }
+    }
+
+
+
+}

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/util/IDEntry.java
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/util/IDEntry.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/main/java/org/drools/services/grid/util/IDEntry.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,22 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.drools.services.grid.util;
+
+/**
+ *
+ * @author salaboy
+ */
+public class IDEntry extends net.jini.entry.AbstractEntry{
+    public String id;
+
+   public IDEntry() {
+       super();
+   }
+
+   public IDEntry(String id) {
+       this. id = id;
+   }
+}

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/conf/test-config.groovy
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/conf/test-config.groovy	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/conf/test-config.groovy	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,13 @@
+/*
+ * Configuration file for integration test cases
+ */
+ITGridExecutionTest {
+    groups = "ITGridExecutionTest"
+    numCybernodes = 1
+    numMonitors = 1
+    //numLookups = 1
+    opstring = 'src/test/resources/org/drools/executionNodeService.groovy'
+    autoDeploy = true
+    //harvest = true
+}
+

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/java/org/drools/services/ExecutionNodeBaseTest.java
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/java/org/drools/services/ExecutionNodeBaseTest.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/java/org/drools/services/ExecutionNodeBaseTest.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,88 @@
+/*
+ *  Copyright 2010 salaboy.
+ * 
+ *  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.
+ *  under the License.
+ */
+
+package org.drools.services;
+
+
+import org.drools.KnowledgeBase;
+import org.drools.services.ExecutionNode;
+import org.drools.KnowledgeBaseFactoryService;
+import org.drools.builder.KnowledgeBuilder;
+import org.drools.builder.KnowledgeBuilderFactoryService;
+import org.drools.builder.ResourceType;
+import org.drools.io.ResourceFactory;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.junit.Assert;
+import org.junit.Test;
+/**
+ *
+ * @author salaboy
+ */
+
+public class ExecutionNodeBaseTest {
+
+    protected ExecutionNode node;
+
+    public ExecutionNodeBaseTest() {
+        
+    }
+
+
+    @Test
+    public void fireAllRules(){
+
+        String str = "";
+        str += "package org.drools \n";
+        str += "global java.util.List list \n";
+        str += "rule rule1 \n";
+        str += "    dialect \"java\" \n";
+        str += "when \n";
+        str += "then \n";
+        str += "    System.out.println( \"hello1!!!\" ); \n";
+        str += "end \n";
+        str += "rule rule2 \n";
+        str += "    dialect \"java\" \n";
+        str += "when \n";
+        str += "then \n";
+        str += "    System.out.println( \"hello2!!!\" ); \n";
+        str += "end \n";
+
+         
+        KnowledgeBuilder kbuilder = node.get(KnowledgeBuilderFactoryService.class).newKnowledgeBuilder();
+        kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ),
+                      ResourceType.DRL );
+
+        if ( kbuilder.hasErrors() ) {
+            System.out.println( "Errors: " + kbuilder.getErrors() );
+        }
+
+        KnowledgeBase kbase = node.get(KnowledgeBaseFactoryService.class).newKnowledgeBase();
+        Assert.assertNotNull(kbase);
+
+        kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+
+        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
+        Assert.assertNotNull(ksession);
+
+        int fired = ksession.fireAllRules();
+        Assert.assertEquals( 2, fired );
+
+
+    }
+  
+
+}

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/java/org/drools/services/ITGridExecutionTest.java
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/java/org/drools/services/ITGridExecutionTest.java	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/java/org/drools/services/ITGridExecutionTest.java	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,91 @@
+package org.drools.services;
+
+import junit.framework.Assert;
+
+import net.jini.core.lookup.ServiceItem;
+import org.drools.KnowledgeBaseFactoryService;
+import org.drools.SystemEventListenerFactory;
+import org.drools.builder.KnowledgeBuilderFactoryService;
+import org.drools.services.generic.ExecutionNodeData;
+import org.drools.services.grid.ExecutionGridConnection;
+import org.drools.services.grid.GridExecutionNodeConnection;
+import org.drools.services.grid.GridNodeExecutionService;
+import org.drools.services.grid.KnowledgeBaseProviderGridClient;
+import org.drools.services.grid.KnowledgeBuilderProviderGridClient;
+import org.drools.services.grid.DirectoryService;
+import org.drools.services.grid.rio.RioConnector;
+import org.drools.vsm.AcceptorService;
+
+
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.rioproject.test.RioTestRunner;
+import org.rioproject.test.SetTestManager;
+import org.rioproject.test.TestManager;
+
+ at RunWith(RioTestRunner.class)
+public class ITGridExecutionTest extends ExecutionNodeBaseTest {
+
+    AcceptorService server;
+    @SetTestManager
+    static TestManager testManager;
+
+    @Before
+    public void setUp() throws Exception {
+        ExecutionNodeData nodeData = new ExecutionNodeData();
+        Assert.assertNotNull(testManager);
+        //setup Server
+        //GridNodeExecutionService sessionService = (GridNodeExecutionService) testManager.waitForService(GridNodeExecutionService.class);
+        ServiceItem[] nodeServiceItems = testManager.getServiceItems(GridNodeExecutionService.class);
+        //List<GridNodeExecutionService> nodeServices = new ArrayList<GridNodeExecutionService>();
+        System.out.println("Node Service Items =" + nodeServiceItems.length);
+        ExecutionGridConnection connection = new ExecutionGridConnection();
+        for (int i = 0; i < nodeServiceItems.length; i++) {
+            if (nodeServiceItems[i].service instanceof GridNodeExecutionService) {
+
+                //sessionServices.add((GridNodeExecutionService) sessionServiceItems[i].service);
+
+                ExecutionNode node = new ExecutionNode();
+                node.set(KnowledgeBuilderFactoryService.class, 
+                        new KnowledgeBuilderProviderGridClient(
+                            new GridExecutionNodeConnection(
+                            ((GridNodeExecutionService)nodeServiceItems[i].service).getId(),
+                            new RioConnector("client1",SystemEventListenerFactory.getSystemEventListener(),
+                                (GridNodeExecutionService)nodeServiceItems[i].service))
+                            ));
+                node.set(KnowledgeBaseFactoryService.class,
+                            new KnowledgeBaseProviderGridClient(
+                            new GridExecutionNodeConnection(
+                            ((GridNodeExecutionService)nodeServiceItems[i].service).getId(),
+                            new RioConnector("client2",SystemEventListenerFactory.getSystemEventListener(),
+                                (GridNodeExecutionService)nodeServiceItems[i].service))
+                            ));
+                connection.addNode(node);
+            }
+        }
+
+
+
+
+
+
+
+       // Assert.assertNotNull(nodeServices);
+        DirectoryService directoryService = (DirectoryService) testManager.waitForService(DirectoryService.class);
+        Assert.assertNotNull(directoryService);
+
+        connection.setDirectory(directoryService);
+
+
+        node = connection.getPreferedExecutionNode();
+
+
+
+    }
+//    @After
+//    public void tearDown() throws Exception {
+//
+//        ((ServiceManagerGridClient) client).disconnect();
+//        //this.server.stop();
+//    }
+}

Added: labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/resources/org/drools/executionNodeService.groovy
===================================================================
--- labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/resources/org/drools/executionNodeService.groovy	                        (rev 0)
+++ labs/jbossrules/branches/salaboy_ServiceAPIs/drools-services-grid/src/test/resources/org/drools/executionNodeService.groovy	2010-03-09 14:35:51 UTC (rev 32004)
@@ -0,0 +1,43 @@
+import org.rioproject.config.Constants
+
+deployment(name:'executionNodeService') {
+    /* Configuration for the discovery group that the service should join.
+     * This first checks if the org.rioproject.groups property is set, if not
+     * the user name is used */
+    groups System.getProperty(Constants.GROUPS_PROPERTY_NAME,
+                              System.getProperty('user.name'))
+
+    /* Declares the artifacts required for deployment. Note the 'dl'
+     * classifier used for the 'download' jar */
+    artifact id:'service', 'org.drools:drools-services-grid:5.1.0.SNAPSHOT'
+    artifact id:'service-dl', 'org.drools:drools-services-grid:dl:5.1.0.SNAPSHOT'
+
+    /*
+     * Declare the service to be deployed. The number of instances deployed
+     * defaults to 1. If you require > 1 instances change as needed
+     */
+    service(name: 'GridNodeExecutionService') {
+        interfaces {
+            classes 'org.drools.services.grid.GridNodeExecutionService'
+            artifact ref:'service-dl'
+        }
+        implementation(class:'org.drools.services.grid.impl.GridNodeExecutionServiceImpl') {
+            artifact ref:'service'
+        }
+         //association (name:'RegistryService', type:'uses', property:'registryService')
+        maintain 2
+    }
+    service(name: 'DirectoryService') {
+        interfaces {
+            classes 'org.drools.services.grid.DirectoryService'
+            artifact ref:'service-dl'
+        }
+        implementation(class:'org.drools.services.grid.impl.DirectoryServiceImpl') {
+            artifact ref:'service'
+        }
+         
+            association (name:'GridNodeExecutionService', type:'uses', property:'nodeServices')
+         
+        maintain 1
+    }
+}
\ No newline at end of file



More information about the jboss-svn-commits mailing list