[jboss-svn-commits] JBL Code SVN: r31524 - in labs/jbossrules/branches/salaboy_grid-rio: drools-core/src/main/java/org/drools/command/runtime and 10 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Feb 9 13:16:05 EST 2010
Author: salaboy21
Date: 2010-02-09 13:16:04 -0500 (Tue, 09 Feb 2010)
New Revision: 31524
Added:
labs/jbossrules/branches/salaboy_grid-rio/drools-core/src/main/java/org/drools/command/GetKnowledgeBaseCommand.java
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/GenericMessageGridHandlerImpl.java
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/HumanTaskServiceGridProviderImpl.java
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/KnowledgeBaseGridClient.java
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/KnowledgeBaseProviderGridClient.java
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/KnowledgeBuilderGridClient.java
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/KnowledgeBuilderProviderGridClient.java
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/RegistryService.java
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/ServiceManagerGridClient.java
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/SessionService.java
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/StatefulKnowledgeSessionGridClient.java
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/WorkItemManagerGridClient.java
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/rio/RioConnector.java
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/rio/command/
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/rio/command/NewStatefulKnowledgeSessionGridCommand.java
Removed:
labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/HumanTaskServiceGridProviderImpl.java
labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBaseGridClient.java
labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBaseProviderGridClient.java
labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBuilderGridClient.java
labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBuilderProviderGridClient.java
labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/RegistryService.java
labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/ServiceManagerGridClient.java
labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/SessionService.java
labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/StatefulKnowledgeSessionGridClient.java
labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/WorkItemManagerGridClient.java
labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/rio/RioConnector.java
Modified:
labs/jbossrules/branches/salaboy_grid-rio/drools-core/src/main/java/org/drools/command/KnowledgeContextResolveFromContextCommand.java
labs/jbossrules/branches/salaboy_grid-rio/drools-core/src/main/java/org/drools/command/runtime/GetKnowledgeBaseCommand.java
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/pom.xml
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/rio/service/RegistryServiceImpl.java
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/rio/service/SessionServiceImpl.java
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/test/java/org/drools/vms/ServiceManagerTestBaseGrid.java
labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/test/resources/org/drools/sessionService.groovy
Log:
sharing kbases between sessionservices
Added: labs/jbossrules/branches/salaboy_grid-rio/drools-core/src/main/java/org/drools/command/GetKnowledgeBaseCommand.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-core/src/main/java/org/drools/command/GetKnowledgeBaseCommand.java (rev 0)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-core/src/main/java/org/drools/command/GetKnowledgeBaseCommand.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -0,0 +1,25 @@
+package org.drools.command;
+
+import org.drools.KnowledgeBase;
+import org.drools.KnowledgeBaseConfiguration;
+import org.drools.KnowledgeBaseFactory;
+import org.drools.command.Context;
+import org.drools.command.impl.GenericCommand;
+import org.drools.command.impl.KnowledgeCommandContext;
+
+public class GetKnowledgeBaseCommand
+ implements
+ GenericCommand<KnowledgeBase> {
+
+
+ public GetKnowledgeBaseCommand() {
+
+ }
+
+ public KnowledgeBase execute(Context context) {
+ KnowledgeBase kbase = ((KnowledgeCommandContext) context).getKnowledgeBase();
+
+ return kbase;
+ }
+
+}
Modified: labs/jbossrules/branches/salaboy_grid-rio/drools-core/src/main/java/org/drools/command/KnowledgeContextResolveFromContextCommand.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-core/src/main/java/org/drools/command/KnowledgeContextResolveFromContextCommand.java 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-core/src/main/java/org/drools/command/KnowledgeContextResolveFromContextCommand.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -35,6 +35,8 @@
(KnowledgeBase) context.get( this.kbaseIdentifier ),
(StatefulKnowledgeSession) context.get( this.statefulKsessionName ),
(ExecutionResultImpl) context.get( this.kresults ) );
+ System.out.println("Kbase Identifier inside RevolveContext = "+this.kbaseIdentifier +"-kbase ="+(KnowledgeBase) context.get( this.kbaseIdentifier ));
+ System.out.println("Ksession Identifier inside RevolveContext = "+this.statefulKsessionName +"-kbase ="+(StatefulKnowledgeSession) context.get( this.statefulKsessionName ));
return ((GenericCommand) command).execute( kcContext );
}
Modified: labs/jbossrules/branches/salaboy_grid-rio/drools-core/src/main/java/org/drools/command/runtime/GetKnowledgeBaseCommand.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-core/src/main/java/org/drools/command/runtime/GetKnowledgeBaseCommand.java 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-core/src/main/java/org/drools/command/runtime/GetKnowledgeBaseCommand.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -1,13 +1,9 @@
package org.drools.command.runtime;
import org.drools.KnowledgeBase;
-import org.drools.RuleBase;
import org.drools.command.Context;
import org.drools.command.impl.GenericCommand;
import org.drools.command.impl.KnowledgeCommandContext;
-import org.drools.impl.KnowledgeBaseImpl;
-import org.drools.reteoo.ReteooWorkingMemory;
-import org.drools.runtime.StatefulKnowledgeSession;
public class GetKnowledgeBaseCommand
implements
@@ -17,8 +13,9 @@
}
public KnowledgeBase execute(Context context) {
- StatefulKnowledgeSession ksession = ((KnowledgeCommandContext) context).getStatefulKnowledgesession();
- return ksession.getKnowledgeBase();
+ KnowledgeBase kbase = ((KnowledgeCommandContext) context).getKnowledgeBase();
+ System.out.println("The kbase is ="+kbase);
+ return kbase;
}
public String toString() {
Modified: labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/pom.xml
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/pom.xml 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/pom.xml 2010-02-09 18:16:04 UTC (rev 31524)
@@ -29,13 +29,15 @@
<groupId>org.drools</groupId>
<artifactId>drools-vsm</artifactId>
<version>5.1.0.SNAPSHOT</version>
- </dependency>
+ <type>jar</type>
+ </dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-api</artifactId>
<version>5.1.0.SNAPSHOT</version>
+ <type>jar</type>
</dependency>
-
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -43,7 +45,7 @@
<scope>test</scope>
</dependency>
</dependencies>
-
+
<build>
<plugins>
<plugin>
@@ -55,7 +57,7 @@
<createJar>
<classifier>dl</classifier>
<in>org.drools.vsm</in>
-
+
<topclasses>
<topclass>org.drools.vsm.grid.SessionService</topclass>
<topclass>org.drools.vsm.grid.RegistryService</topclass>
@@ -88,14 +90,14 @@
<forkMode>always</forkMode>
<argLine>-DRIO_TEST_ATTACH</argLine>
<systemProperties>
-
+
<property>
<name>opstring</name>
<value>src/test/resources/org/drools/sessionService.groovy</value>
</property>
<property>
<name>org.rioproject.test.config</name>
- <value>src/test/conf/test-config.groovy</value>
+ <value>src/test/conf/test-config.groovy</value>
</property>
</systemProperties>
</configuration>
@@ -141,3 +143,6 @@
</project>
+
+
+
Added: labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/GenericMessageGridHandlerImpl.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/GenericMessageGridHandlerImpl.java (rev 0)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/GenericMessageGridHandlerImpl.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -0,0 +1,134 @@
+package org.drools.vsm.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.vsm.GenericIoWriter;
+import org.drools.vsm.GenericMessageHandler;
+import org.drools.vsm.Message;
+import org.drools.vsm.ServiceManagerData;
+
+public class GenericMessageGridHandlerImpl implements GenericMessageHandler {
+ private SystemEventListener systemEventListener;
+
+ private ServiceManagerData data;
+ private RegistryService registry;
+
+ public GenericMessageGridHandlerImpl(ServiceManagerData data,
+ SystemEventListener systemEventListener) {
+ this.systemEventListener = systemEventListener;
+ this.data = data;
+
+ Class[] classes = new Class[]{org.drools.vsm.grid.RegistryService.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 RegistryService){
+ registry = (RegistryService)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 ( !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 );
+ }
+ }
+}
Copied: labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/HumanTaskServiceGridProviderImpl.java (from rev 31136, labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/HumanTaskServiceGridProviderImpl.java)
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/HumanTaskServiceGridProviderImpl.java (rev 0)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/HumanTaskServiceGridProviderImpl.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -0,0 +1,35 @@
+package org.drools.vsm.grid;
+
+import org.drools.vsm.remote.*;
+import org.drools.task.service.HumanTaskServiceImpl;
+import org.drools.vsm.GenericConnector;
+import org.drools.vsm.HumanTaskService;
+import org.drools.vsm.HumanTaskServiceProvider;
+
+/**
+ *
+ * @author Lucas Amador
+ *
+ */
+public class HumanTaskServiceGridProviderImpl implements HumanTaskServiceProvider {
+
+ private final ServiceManagerGridClient serviceManager;
+
+ public HumanTaskServiceGridProviderImpl(ServiceManagerGridClient serviceManager) {
+ this.serviceManager = serviceManager;
+ }
+
+ public HumanTaskService newHumanTaskServiceClient() {
+ // TOOD: implemente a best way to identify the human task services of the other ones inexistents
+ if (serviceManager.getServices()==null)
+ return null;
+ GenericConnector humanTaskServiceConnector = serviceManager.getServices().get(0);
+ if (humanTaskServiceConnector==null)
+ return null;
+ return new HumanTaskServiceImpl( humanTaskServiceConnector,
+ serviceManager.counter,
+ serviceManager.getName(),
+ serviceManager.getSessionId());
+ }
+
+}
Copied: labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/KnowledgeBaseGridClient.java (from rev 31158, labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBaseGridClient.java)
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/KnowledgeBaseGridClient.java (rev 0)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/KnowledgeBaseGridClient.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -0,0 +1,190 @@
+package org.drools.vsm.grid;
+
+import java.rmi.RemoteException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.drools.vsm.remote.*;
+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.NewStatefulKnowledgeSessionCommand;
+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.vsm.CollectionClient;
+import org.drools.vsm.Message;
+import org.drools.vsm.rio.command.NewStatefulKnowledgeSessionGridCommand;
+
+public class KnowledgeBaseGridClient
+ implements
+ KnowledgeBase {
+
+ private ServiceManagerGridClient serviceManager;
+ private String instanceId;
+
+ public KnowledgeBaseGridClient(String instanceId,
+ ServiceManagerGridClient serviceManager) {
+ this.instanceId = instanceId;
+ this.serviceManager = serviceManager;
+ }
+
+ public void addKnowledgePackages(Collection<KnowledgePackage> kpackages) {
+ String kresultsId = "kresults_" + serviceManager.getSessionId();
+
+ String kuilderInstanceId = ((CollectionClient<KnowledgePackage>) kpackages).getParentInstanceId();
+ Message msg = new Message( serviceManager.getSessionId(),
+ serviceManager.counter.incrementAndGet(),
+ false,
+ new KnowledgeContextResolveFromContextCommand( new KnowledgeBaseAddKnowledgePackagesCommand(),
+ kuilderInstanceId,
+ instanceId,
+ null,
+ kresultsId ) );
+ try {
+ //I should register the kbase ID??
+ serviceManager.getRegistryService().registerKBase(instanceId, serviceManager.client.getId());
+ } catch (RemoteException ex) {
+ Logger.getLogger(KnowledgeBaseGridClient.class.getName()).log(Level.SEVERE, null, ex);
+ }
+
+ 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 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_" + serviceManager.getSessionId();
+
+ String localId = UUID.randomUUID().toString();
+
+ Message msg = new Message( serviceManager.getSessionId(),
+ serviceManager.counter.incrementAndGet(),
+ false,
+ new SetVariableCommand( "__TEMP__",
+ localId,
+ new KnowledgeContextResolveFromContextCommand( new NewStatefulKnowledgeSessionGridCommand( null, instanceId ),
+ null,
+ instanceId,
+ null,
+ kresultsId ) ) );
+
+ 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 StatefulKnowledgeSessionGridClient( localId,
+ serviceManager );
+ }
+
+ 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(ServiceManagerGridClient serviceManager) {
+ this.serviceManager = serviceManager;
+ }
+
+}
Copied: labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/KnowledgeBaseProviderGridClient.java (from rev 31136, labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBaseProviderGridClient.java)
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/KnowledgeBaseProviderGridClient.java (rev 0)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/KnowledgeBaseProviderGridClient.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -0,0 +1,104 @@
+package org.drools.vsm.grid;
+
+import org.drools.vsm.remote.*;
+import java.util.Properties;
+import java.util.UUID;
+
+import org.drools.KnowledgeBase;
+import org.drools.KnowledgeBaseConfiguration;
+import org.drools.KnowledgeBaseProvider;
+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.vsm.Message;
+
+public class KnowledgeBaseProviderGridClient
+ implements
+ KnowledgeBaseProvider {
+ private ServiceManagerGridClient serviceManager;
+ private String localId = "";
+ public KnowledgeBaseProviderGridClient(ServiceManagerGridClient 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;
+ }
+
+}
Copied: labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/KnowledgeBuilderGridClient.java (from rev 31136, labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBuilderGridClient.java)
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/KnowledgeBuilderGridClient.java (rev 0)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/KnowledgeBuilderGridClient.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -0,0 +1,132 @@
+package org.drools.vsm.grid;
+
+import org.drools.vsm.remote.*;
+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.vsm.CollectionClient;
+import org.drools.vsm.Message;
+
+public class KnowledgeBuilderGridClient
+ implements
+ KnowledgeBuilder {
+ private ServiceManagerGridClient serviceManager;
+ private String instanceId;
+
+ public KnowledgeBuilderGridClient(String instanceId,
+ ServiceManagerGridClient 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 );
+ }
+
+
+
+ }
+
+}
Copied: labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/KnowledgeBuilderProviderGridClient.java (from rev 31136, labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBuilderProviderGridClient.java)
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/KnowledgeBuilderProviderGridClient.java (rev 0)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/KnowledgeBuilderProviderGridClient.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -0,0 +1,87 @@
+/**
+ *
+ */
+package org.drools.vsm.grid;
+
+import org.drools.vsm.remote.*;
+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.KnowledgeBuilderProvider;
+import org.drools.command.FinishedCommand;
+import org.drools.command.SetVariableCommand;
+import org.drools.command.builder.NewKnowledgeBuilderCommand;
+import org.drools.vsm.Message;
+
+public class KnowledgeBuilderProviderGridClient
+ implements
+ KnowledgeBuilderProvider {
+ private ServiceManagerGridClient serviceManager;
+
+ public KnowledgeBuilderProviderGridClient(ServiceManagerGridClient serviceManager) {
+ this.serviceManager = serviceManager;
+ }
+
+ public DecisionTableConfiguration newDecisionTableConfiguration() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public KnowledgeBuilder newKnowledgeBuilder() {
+ String localId = UUID.randomUUID().toString();
+
+ Message msg = new Message( serviceManager.getSessionId(),
+ serviceManager.counter.incrementAndGet(),
+ false,
+ new SetVariableCommand( "__TEMP__",
+ localId,
+ new NewKnowledgeBuilderCommand( 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 KnowledgeBuilderGridClient( localId,
+ serviceManager );
+ }
+
+ 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
Copied: labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/RegistryService.java (from rev 31136, labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/RegistryService.java)
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/RegistryService.java (rev 0)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/RegistryService.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -0,0 +1,22 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.drools.vsm.grid;
+
+import java.rmi.RemoteException;
+import org.drools.KnowledgeBase;
+
+
+/**
+ *
+ * @author salaboy
+ */
+
+public interface RegistryService {
+ public void register(String executorId, String sessionServiceId) throws RemoteException;
+ public SessionService 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_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/ServiceManagerGridClient.java (from rev 31158, labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/ServiceManagerGridClient.java)
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/ServiceManagerGridClient.java (rev 0)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/ServiceManagerGridClient.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -0,0 +1,340 @@
+package org.drools.vsm.grid;
+
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+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.KnowledgeBaseProvider;
+import org.drools.agent.KnowledgeAgentProvider;
+import org.drools.builder.DecisionTableConfiguration;
+import org.drools.builder.KnowledgeBuilder;
+import org.drools.builder.KnowledgeBuilderConfiguration;
+import org.drools.builder.KnowledgeBuilderProvider;
+import org.drools.command.Command;
+import org.drools.command.FinishedCommand;
+import org.drools.command.KnowledgeContextResolveFromContextCommand;
+import org.drools.command.vsm.LookupCommand;
+import org.drools.command.vsm.RegisterCommand;
+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.vsm.GenericConnector;
+import org.drools.vsm.HumanTaskServiceProvider;
+import org.drools.vsm.Message;
+import org.drools.vsm.ServiceManager;
+import org.drools.vsm.command.ServiceManagerClientConnectCommand;
+import org.drools.vsm.rio.RioConnector;
+
+public class ServiceManagerGridClient
+ 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 RegistryService registryService;
+
+ public ServiceManagerGridClient(String name, GenericConnector client) {
+ this.name = name;
+ this.client = client;
+ this.counter = new AtomicInteger();
+ this.services = null;
+ }
+
+ public ServiceManagerGridClient(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 ServiceManagerClientConnectCommand( 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 KnowledgeBuilderProvider getKnowledgeBuilderFactory() {
+ return new KnowledgeBuilderProviderGridClient( this );
+ }
+
+ public KnowledgeBaseProvider getKnowledgeBaseFactory() {
+ return new KnowledgeBaseProviderGridClient( this );
+ }
+
+ 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(ServiceManagerGridClient.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 SessionService with the identifier
+
+ client.setSession(registryService.lookup(identifier));
+ } catch (RemoteException ex) {
+ Logger.getLogger(ServiceManagerGridClient.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);
+ }
+
+ public static class RemoveKnowledgeBuilderProvider implements KnowledgeBuilderProvider {
+
+ 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 RegistryService getRegistryService() {
+ return registryService;
+ }
+
+ public void setRegistryService(RegistryService registryService) {
+ this.registryService = registryService;
+ }
+
+ public void setCurrentSessionService(SessionService sessionService){
+ this.client.setSession(sessionService);
+ }
+
+ public List<SessionService> getSessionServices(){
+// List<SessionService> sessionServices =
+// ((RioConnector)this.client).getSessionServices();
+// List<String> ids = new ArrayList<String>();
+// for(SessionService 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).getSessionServices();
+ }
+
+}
Copied: labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/SessionService.java (from rev 31136, labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/SessionService.java)
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/SessionService.java (rev 0)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/SessionService.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -0,0 +1,20 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.drools.vsm.grid;
+
+import java.rmi.RemoteException;
+
+import org.drools.vsm.GenericIoWriter;
+import org.drools.vsm.Message;
+
+/**
+ *
+ * @author salaboy
+ */
+public interface SessionService extends GenericIoWriter {
+ public String getId() throws RemoteException;
+ public Message write(Message msg) throws RemoteException;
+
+}
Copied: labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/StatefulKnowledgeSessionGridClient.java (from rev 31136, labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/StatefulKnowledgeSessionGridClient.java)
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/StatefulKnowledgeSessionGridClient.java (rev 0)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/StatefulKnowledgeSessionGridClient.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -0,0 +1,419 @@
+package org.drools.vsm.grid;
+
+import org.drools.vsm.remote.*;
+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.command.vsm.GetWorkItemManagerCommand;
+import org.drools.command.vsm.RegisterRemoteWorkItemHandlerCommand;
+import org.drools.command.vsm.StartProcessRemoteCommand;
+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.time.SessionClock;
+import org.drools.vsm.Message;
+
+public class StatefulKnowledgeSessionGridClient
+ implements
+ StatefulKnowledgeSession {
+
+ private ServiceManagerGridClient serviceManager;
+ private String instanceId;
+
+ public StatefulKnowledgeSessionGridClient(String instanceId,
+ ServiceManagerGridClient 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;
+ }
+
+}
Copied: labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/WorkItemManagerGridClient.java (from rev 31136, labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/WorkItemManagerGridClient.java)
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/WorkItemManagerGridClient.java (rev 0)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/grid/WorkItemManagerGridClient.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -0,0 +1,59 @@
+package org.drools.vsm.grid;
+
+import org.drools.vsm.remote.*;
+import java.io.Serializable;
+import java.util.Map;
+
+import org.drools.command.KnowledgeContextResolveFromContextCommand;
+import org.drools.command.runtime.process.CompleteWorkItemCommand;
+import org.drools.command.vsm.GetWorkItemManagerCommand;
+import org.drools.runtime.ExecutionResults;
+import org.drools.runtime.process.WorkItemHandler;
+import org.drools.runtime.process.WorkItemManager;
+import org.drools.vsm.Message;
+
+/**
+ *
+ * @author Lucas Amador
+ */
+public class WorkItemManagerGridClient implements WorkItemManager, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private ServiceManagerGridClient 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(ServiceManagerGridClient serviceManager) {
+ this.serviceManager = serviceManager;
+ }
+
+ public void setInstanceId(String instanceId) {
+ this.instanceId = instanceId;
+ }
+
+}
Added: labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/rio/RioConnector.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/rio/RioConnector.java (rev 0)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/rio/RioConnector.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -0,0 +1,125 @@
+package org.drools.vsm.rio;
+
+import org.drools.vsm.grid.SessionService;
+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.vsm.GenericConnector;
+import org.drools.vsm.Message;
+import org.drools.vsm.MessageResponseHandler;
+
+public class RioConnector
+ implements
+ GenericConnector {
+
+ protected final String name;
+ protected AtomicInteger counter;
+ protected SessionService currentSessionService;
+ protected List<SessionService> sessionServices;
+ 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<SessionService> sessionServices
+ ) {
+ if ( name == null ) {
+ throw new IllegalArgumentException( "Name can not be null" );
+ }
+ this.name = name;
+ this.counter = new AtomicInteger();
+ this.eventListener = eventListener;
+ this.sessionServices = 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 ( currentSessionService != null ) {
+ try {
+
+ Message returnMessage = this.currentSessionService.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 currentSessionService.getId();
+ } catch (RemoteException ex) {
+ Logger.getLogger(RioConnector.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ return null;
+ }
+
+ public SessionService getCurrentSessionService() {
+ return currentSessionService;
+ }
+
+ public List<SessionService> getSessionServices() {
+ return sessionServices;
+ }
+
+
+ public void setSession(Object object) {
+ this.currentSessionService = (SessionService) object;
+ try {
+ System.out.println("Setting session = " + currentSessionService.getId());
+ } catch (RemoteException ex) {
+ Logger.getLogger(RioConnector.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+
+
+}
Added: labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/rio/command/NewStatefulKnowledgeSessionGridCommand.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/rio/command/NewStatefulKnowledgeSessionGridCommand.java (rev 0)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/rio/command/NewStatefulKnowledgeSessionGridCommand.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -0,0 +1,61 @@
+package org.drools.vsm.rio.command;
+
+import java.rmi.RemoteException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.drools.KnowledgeBase;
+import org.drools.KnowledgeBaseConfiguration;
+import org.drools.KnowledgeBaseFactory;
+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.vsm.grid.RegistryService;
+
+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();
+ RegistryService registry = (RegistryService)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;
+ }
+
+}
Modified: labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/rio/service/RegistryServiceImpl.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/rio/service/RegistryServiceImpl.java 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/rio/service/RegistryServiceImpl.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -8,6 +8,10 @@
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.vsm.Message;
import org.drools.vsm.grid.RegistryService;
import org.drools.vsm.grid.SessionService;
@@ -19,6 +23,8 @@
private Map<String, String> registry = new HashMap<String, String>();
+ private Map<String, String> kbaseregistry = new HashMap<String, String>();
+
public RegistryServiceImpl() {
}
@@ -51,4 +57,36 @@
this.sessionServices = sessionServices;
}
+ @Override
+ public void registerKBase(String kbaseId, String sessionServiceId) throws RemoteException {
+ System.out.println("Registering KnowledgeBase = "+kbaseId +" -in SS=" +sessionServiceId);
+ kbaseregistry.put(kbaseId, sessionServiceId);
+ }
+
+ @Override
+ public KnowledgeBase lookupKBase(String kbaseId) throws RemoteException{
+ SessionService sessionService = null;
+ String sessionServiceId = (String)kbaseregistry.get(kbaseId);
+ System.out.println("Kbase Registry = "+ kbaseregistry.toString());
+ System.out.println("Session Services = "+sessionServices);
+ for(SessionService ss : sessionServices){
+ System.out.println("Session Service id = "+ss.getId() + "needs to match with ="+sessionServiceId);
+ if(ss.getId().equals(sessionServiceId)){
+ sessionService = ss;
+ }
+ }
+ System.out.println("Session Service = "+sessionService);
+
+ try {
+ Message msg = sessionService.write(new Message(999,1000,false, new KnowledgeContextResolveFromContextCommand( new GetKnowledgeBaseCommand(), null, kbaseId, null, null)));
+ System.out.println("MSG returned by sessionService = "+msg);
+ if (msg.getPayload() instanceof KnowledgeBase) {
+ return (KnowledgeBase)msg.getPayload();
+ }
+ return null;
+ } catch ( Exception e ) {
+ throw new RuntimeException( "Unable to execute message",
+ e );
+ }
+ }
}
Modified: labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/rio/service/SessionServiceImpl.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/rio/service/SessionServiceImpl.java 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/main/java/org/drools/vsm/rio/service/SessionServiceImpl.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -23,10 +23,10 @@
import org.drools.SystemEventListenerFactory;
import org.drools.vsm.BlockingGenericIoWriter;
import org.drools.vsm.GenericMessageHandler;
-import org.drools.vsm.GenericMessageHandlerImpl;
import org.drools.vsm.Message;
import org.drools.vsm.MessageResponseHandler;
import org.drools.vsm.ServiceManagerData;
+import org.drools.vsm.grid.GenericMessageGridHandlerImpl;
import org.drools.vsm.grid.SessionService;
import org.drools.vsm.rio.utils.IDEntry;
import org.rioproject.core.jsb.ServiceBeanContext;
@@ -39,15 +39,16 @@
private GenericMessageHandler handler;
private String id;
+
public SessionServiceImpl() {
this.id = UUID.randomUUID().toString();
- handler = new GenericMessageHandlerImpl(new ServiceManagerData(), SystemEventListenerFactory.getSystemEventListener());
+ handler = new GenericMessageGridHandlerImpl(new ServiceManagerData(), SystemEventListenerFactory.getSystemEventListener());
}
public SessionServiceImpl(ServiceManagerData data,
SystemEventListener systemEventListener) {
- handler = new GenericMessageHandlerImpl(data, systemEventListener);
+ handler = new GenericMessageGridHandlerImpl(data, systemEventListener);
}
public Message write(Message msg) throws RemoteException {
@@ -82,4 +83,7 @@
public void setId(String id) {
this.id = id;
}
+
+
+
}
Modified: labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/test/java/org/drools/vms/ServiceManagerTestBaseGrid.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/test/java/org/drools/vms/ServiceManagerTestBaseGrid.java 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/test/java/org/drools/vms/ServiceManagerTestBaseGrid.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -208,7 +208,7 @@
str += "then \n";
str += " System.out.println( \"hello2!!!\" ); \n";
str += "end \n";
-
+ ((ServiceManagerGridClient)this.client).setCurrentSessionService((SessionService)((ServiceManagerGridClient)this.client).getSessionServices().get(0));
KnowledgeBuilderProvider kbuilderFactory = this.client.getKnowledgeBuilderFactory();
KnowledgeBuilder kbuilder = kbuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ),
@@ -222,7 +222,7 @@
KnowledgeBase kbase = kbaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
- ((ServiceManagerGridClient)this.client).setCurrentSessionService((SessionService)((ServiceManagerGridClient)this.client).getSessionServices().get(0));
+
StatefulKnowledgeSession ksession1 = kbase.newStatefulKnowledgeSession();
System.out.println("registering ksession1!");
this.client.register( "ksession1", ksession1 );
@@ -262,4 +262,72 @@
(int) (Integer) results2.getValue( "fired" ) );
}
+
+
+ @Test
+ public void sharingKbases(){
+
+ 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";
+ ((ServiceManagerGridClient)this.client).setCurrentSessionService((SessionService)((ServiceManagerGridClient)this.client).getSessionServices().get(0));
+ KnowledgeBuilderProvider kbuilderFactory = this.client.getKnowledgeBuilderFactory();
+ KnowledgeBuilder kbuilder = kbuilderFactory.newKnowledgeBuilder();
+ kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ),
+ ResourceType.DRL );
+
+ if ( kbuilder.hasErrors() ) {
+ System.out.println( "Errors: " + kbuilder.getErrors() );
+ }
+
+ KnowledgeBaseProvider kbaseFactory = this.client.getKnowledgeBaseFactory();
+ ((KnowledgeBaseProviderGridClient)kbaseFactory).setLocalId("MyFirstKBase");
+ KnowledgeBase kbase = kbaseFactory.newKnowledgeBase();
+
+ kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+
+ StatefulKnowledgeSession ksession1 = kbase.newStatefulKnowledgeSession();
+ System.out.println("registering ksession1!");
+ this.client.register( "ksession1", ksession1 );
+
+
+
+ System.out.println("Let's go for the Second ksession");
+ ((ServiceManagerGridClient)this.client).setCurrentSessionService((SessionService)((ServiceManagerGridClient)this.client).getSessionServices().get(1));
+// //If I do this here.. and I don't create a new Kbase. the context got nothing and cannot find the kbase in the new session service.. of course
+//
+
+
+//
+ StatefulKnowledgeSession ksession2 = kbase.newStatefulKnowledgeSession();
+ System.out.println("registering ksession2!");
+ this.client.register( "ksession2", ksession2 );
+
+ System.out.println("Lookuping up ksession1 !");
+ ExecutionResults results1 = this.client.lookup( "ksession1" ).execute( new FireAllRulesCommand( "fired" ) );
+
+ Assert.assertEquals( 2,
+ (int) (Integer) results1.getValue( "fired" ) );
+
+ System.out.println("Lookuping up ksession2 !");
+ ExecutionResults results2 = this.client.lookup( "ksession2" ).execute( new FireAllRulesCommand( "fired" ) );
+
+ Assert.assertEquals( 2,
+ (int) (Integer) results2.getValue( "fired" ) );
+
+ }
+
+
}
Modified: labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/test/resources/org/drools/sessionService.groovy
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/test/resources/org/drools/sessionService.groovy 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-grid-rio/src/test/resources/org/drools/sessionService.groovy 2010-02-09 18:16:04 UTC (rev 31524)
@@ -24,6 +24,7 @@
implementation(class:'org.drools.vsm.rio.service.SessionServiceImpl') {
artifact ref:'service'
}
+ //association (name:'RegistryService', type:'uses', property:'registryService')
maintain 2
}
service(name: 'RegistryService') {
Deleted: labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/HumanTaskServiceGridProviderImpl.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/HumanTaskServiceGridProviderImpl.java 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/HumanTaskServiceGridProviderImpl.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -1,35 +0,0 @@
-package org.drools.vsm.grid;
-
-import org.drools.vsm.remote.*;
-import org.drools.task.service.HumanTaskServiceImpl;
-import org.drools.vsm.GenericConnector;
-import org.drools.vsm.HumanTaskService;
-import org.drools.vsm.HumanTaskServiceProvider;
-
-/**
- *
- * @author Lucas Amador
- *
- */
-public class HumanTaskServiceGridProviderImpl implements HumanTaskServiceProvider {
-
- private final ServiceManagerGridClient serviceManager;
-
- public HumanTaskServiceGridProviderImpl(ServiceManagerGridClient serviceManager) {
- this.serviceManager = serviceManager;
- }
-
- public HumanTaskService newHumanTaskServiceClient() {
- // TOOD: implemente a best way to identify the human task services of the other ones inexistents
- if (serviceManager.getServices()==null)
- return null;
- GenericConnector humanTaskServiceConnector = serviceManager.getServices().get(0);
- if (humanTaskServiceConnector==null)
- return null;
- return new HumanTaskServiceImpl( humanTaskServiceConnector,
- serviceManager.counter,
- serviceManager.getName(),
- serviceManager.getSessionId());
- }
-
-}
Deleted: labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBaseGridClient.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBaseGridClient.java 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBaseGridClient.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -1,180 +0,0 @@
-package org.drools.vsm.grid;
-
-import org.drools.vsm.remote.*;
-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.NewStatefulKnowledgeSessionCommand;
-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.vsm.CollectionClient;
-import org.drools.vsm.Message;
-
-public class KnowledgeBaseGridClient
- implements
- KnowledgeBase {
-
- private ServiceManagerGridClient serviceManager;
- private String instanceId;
-
- public KnowledgeBaseGridClient(String instanceId,
- ServiceManagerGridClient serviceManager) {
- this.instanceId = instanceId;
- this.serviceManager = serviceManager;
- }
-
- public void addKnowledgePackages(Collection<KnowledgePackage> kpackages) {
- String kresultsId = "kresults_" + serviceManager.getSessionId();
-
- String kuilderInstanceId = ((CollectionClient<KnowledgePackage>) kpackages).getParentInstanceId();
- Message msg = new Message( serviceManager.getSessionId(),
- serviceManager.counter.incrementAndGet(),
- false,
- new KnowledgeContextResolveFromContextCommand( new KnowledgeBaseAddKnowledgePackagesCommand(),
- kuilderInstanceId,
- instanceId,
- null,
- kresultsId ) );
-
- 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 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_" + serviceManager.getSessionId();
-
- String localId = UUID.randomUUID().toString();
-
- Message msg = new Message( serviceManager.getSessionId(),
- serviceManager.counter.incrementAndGet(),
- false,
- new SetVariableCommand( "__TEMP__",
- localId,
- new KnowledgeContextResolveFromContextCommand( new NewStatefulKnowledgeSessionCommand( null ),
- null,
- instanceId,
- null,
- kresultsId ) ) );
-
- 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 StatefulKnowledgeSessionGridClient( localId,
- serviceManager );
- }
-
- 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(ServiceManagerGridClient serviceManager) {
- this.serviceManager = serviceManager;
- }
-
-}
Deleted: labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBaseProviderGridClient.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBaseProviderGridClient.java 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBaseProviderGridClient.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -1,95 +0,0 @@
-package org.drools.vsm.grid;
-
-import org.drools.vsm.remote.*;
-import java.util.Properties;
-import java.util.UUID;
-
-import org.drools.KnowledgeBase;
-import org.drools.KnowledgeBaseConfiguration;
-import org.drools.KnowledgeBaseProvider;
-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.vsm.Message;
-
-public class KnowledgeBaseProviderGridClient
- implements
- KnowledgeBaseProvider {
- private ServiceManagerGridClient serviceManager;
-
- public KnowledgeBaseProviderGridClient(ServiceManagerGridClient 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);
-
- String 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;
- }
-
-}
Deleted: labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBuilderGridClient.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBuilderGridClient.java 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBuilderGridClient.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -1,132 +0,0 @@
-package org.drools.vsm.grid;
-
-import org.drools.vsm.remote.*;
-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.vsm.CollectionClient;
-import org.drools.vsm.Message;
-
-public class KnowledgeBuilderGridClient
- implements
- KnowledgeBuilder {
- private ServiceManagerGridClient serviceManager;
- private String instanceId;
-
- public KnowledgeBuilderGridClient(String instanceId,
- ServiceManagerGridClient 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 );
- }
-
-
-
- }
-
-}
Deleted: labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBuilderProviderGridClient.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBuilderProviderGridClient.java 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/KnowledgeBuilderProviderGridClient.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -1,87 +0,0 @@
-/**
- *
- */
-package org.drools.vsm.grid;
-
-import org.drools.vsm.remote.*;
-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.KnowledgeBuilderProvider;
-import org.drools.command.FinishedCommand;
-import org.drools.command.SetVariableCommand;
-import org.drools.command.builder.NewKnowledgeBuilderCommand;
-import org.drools.vsm.Message;
-
-public class KnowledgeBuilderProviderGridClient
- implements
- KnowledgeBuilderProvider {
- private ServiceManagerGridClient serviceManager;
-
- public KnowledgeBuilderProviderGridClient(ServiceManagerGridClient serviceManager) {
- this.serviceManager = serviceManager;
- }
-
- public DecisionTableConfiguration newDecisionTableConfiguration() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public KnowledgeBuilder newKnowledgeBuilder() {
- String localId = UUID.randomUUID().toString();
-
- Message msg = new Message( serviceManager.getSessionId(),
- serviceManager.counter.incrementAndGet(),
- false,
- new SetVariableCommand( "__TEMP__",
- localId,
- new NewKnowledgeBuilderCommand( 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 KnowledgeBuilderGridClient( localId,
- serviceManager );
- }
-
- 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
Deleted: labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/RegistryService.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/RegistryService.java 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/RegistryService.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -1,19 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.drools.vsm.grid;
-
-import java.rmi.RemoteException;
-
-
-/**
- *
- * @author salaboy
- */
-
-public interface RegistryService {
- public void register(String executorId, String sessionServiceId) throws RemoteException;
- public SessionService lookup(String executorId) throws RemoteException;
-}
Deleted: labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/ServiceManagerGridClient.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/ServiceManagerGridClient.java 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/ServiceManagerGridClient.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -1,340 +0,0 @@
-package org.drools.vsm.grid;
-
-import java.rmi.RemoteException;
-import java.util.ArrayList;
-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.KnowledgeBaseProvider;
-import org.drools.agent.KnowledgeAgentProvider;
-import org.drools.builder.DecisionTableConfiguration;
-import org.drools.builder.KnowledgeBuilder;
-import org.drools.builder.KnowledgeBuilderConfiguration;
-import org.drools.builder.KnowledgeBuilderProvider;
-import org.drools.command.Command;
-import org.drools.command.FinishedCommand;
-import org.drools.command.KnowledgeContextResolveFromContextCommand;
-import org.drools.command.vsm.LookupCommand;
-import org.drools.command.vsm.RegisterCommand;
-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.vsm.GenericConnector;
-import org.drools.vsm.HumanTaskServiceProvider;
-import org.drools.vsm.Message;
-import org.drools.vsm.ServiceManager;
-import org.drools.vsm.command.ServiceManagerClientConnectCommand;
-import org.drools.vsm.rio.RioConnector;
-
-public class ServiceManagerGridClient
- 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 RegistryService registryService;
-
- public ServiceManagerGridClient(String name, GenericConnector client) {
- this.name = name;
- this.client = client;
- this.counter = new AtomicInteger();
- this.services = null;
- }
-
- public ServiceManagerGridClient(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 ServiceManagerClientConnectCommand( 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 KnowledgeBuilderProvider getKnowledgeBuilderFactory() {
- return new KnowledgeBuilderProviderGridClient( this );
- }
-
- public KnowledgeBaseProvider getKnowledgeBaseFactory() {
- return new KnowledgeBaseProviderGridClient( this );
- }
-
- 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(ServiceManagerGridClient.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 SessionService with the identifier
-
- client.setSession(registryService.lookup(identifier));
- } catch (RemoteException ex) {
- Logger.getLogger(ServiceManagerGridClient.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);
- }
-
- public static class RemoveKnowledgeBuilderProvider implements KnowledgeBuilderProvider {
-
- 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 RegistryService getRegistryService() {
- return registryService;
- }
-
- public void setRegistryService(RegistryService registryService) {
- this.registryService = registryService;
- }
-
- public void setCurrentSessionService(SessionService sessionService){
- this.client.setSession(sessionService);
- }
-
- public List<SessionService> getSessionServices(){
-// List<SessionService> sessionServices =
-// ((RioConnector)this.client).getSessionServices();
-// List<String> ids = new ArrayList<String>();
-// for(SessionService 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).getSessionServices();
- }
-
-}
Deleted: labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/SessionService.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/SessionService.java 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/SessionService.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -1,20 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package org.drools.vsm.grid;
-
-import java.rmi.RemoteException;
-
-import org.drools.vsm.GenericIoWriter;
-import org.drools.vsm.Message;
-
-/**
- *
- * @author salaboy
- */
-public interface SessionService extends GenericIoWriter {
- public String getId() throws RemoteException;
- public Message write(Message msg) throws RemoteException;
-
-}
Deleted: labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/StatefulKnowledgeSessionGridClient.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/StatefulKnowledgeSessionGridClient.java 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/StatefulKnowledgeSessionGridClient.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -1,419 +0,0 @@
-package org.drools.vsm.grid;
-
-import org.drools.vsm.remote.*;
-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.command.vsm.GetWorkItemManagerCommand;
-import org.drools.command.vsm.RegisterRemoteWorkItemHandlerCommand;
-import org.drools.command.vsm.StartProcessRemoteCommand;
-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.time.SessionClock;
-import org.drools.vsm.Message;
-
-public class StatefulKnowledgeSessionGridClient
- implements
- StatefulKnowledgeSession {
-
- private ServiceManagerGridClient serviceManager;
- private String instanceId;
-
- public StatefulKnowledgeSessionGridClient(String instanceId,
- ServiceManagerGridClient 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;
- }
-
-}
Deleted: labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/WorkItemManagerGridClient.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/WorkItemManagerGridClient.java 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/grid/WorkItemManagerGridClient.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -1,59 +0,0 @@
-package org.drools.vsm.grid;
-
-import org.drools.vsm.remote.*;
-import java.io.Serializable;
-import java.util.Map;
-
-import org.drools.command.KnowledgeContextResolveFromContextCommand;
-import org.drools.command.runtime.process.CompleteWorkItemCommand;
-import org.drools.command.vsm.GetWorkItemManagerCommand;
-import org.drools.runtime.ExecutionResults;
-import org.drools.runtime.process.WorkItemHandler;
-import org.drools.runtime.process.WorkItemManager;
-import org.drools.vsm.Message;
-
-/**
- *
- * @author Lucas Amador
- */
-public class WorkItemManagerGridClient implements WorkItemManager, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private ServiceManagerGridClient 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(ServiceManagerGridClient serviceManager) {
- this.serviceManager = serviceManager;
- }
-
- public void setInstanceId(String instanceId) {
- this.instanceId = instanceId;
- }
-
-}
Deleted: labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/rio/RioConnector.java
===================================================================
--- labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/rio/RioConnector.java 2010-02-09 18:15:35 UTC (rev 31523)
+++ labs/jbossrules/branches/salaboy_grid-rio/drools-vsm/src/main/java/org/drools/vsm/rio/RioConnector.java 2010-02-09 18:16:04 UTC (rev 31524)
@@ -1,125 +0,0 @@
-package org.drools.vsm.rio;
-
-import org.drools.vsm.grid.SessionService;
-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.vsm.GenericConnector;
-import org.drools.vsm.Message;
-import org.drools.vsm.MessageResponseHandler;
-
-public class RioConnector
- implements
- GenericConnector {
-
- protected final String name;
- protected AtomicInteger counter;
- protected SessionService currentSessionService;
- protected List<SessionService> sessionServices;
- 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<SessionService> sessionServices
- ) {
- if ( name == null ) {
- throw new IllegalArgumentException( "Name can not be null" );
- }
- this.name = name;
- this.counter = new AtomicInteger();
- this.eventListener = eventListener;
- this.sessionServices = 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 ( currentSessionService != null ) {
- try {
-
- Message returnMessage = this.currentSessionService.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 currentSessionService.getId();
- } catch (RemoteException ex) {
- Logger.getLogger(RioConnector.class.getName()).log(Level.SEVERE, null, ex);
- }
- return null;
- }
-
- public SessionService getCurrentSessionService() {
- return currentSessionService;
- }
-
- public List<SessionService> getSessionServices() {
- return sessionServices;
- }
-
-
- public void setSession(Object object) {
- this.currentSessionService = (SessionService) object;
- try {
- System.out.println("Setting session = " + currentSessionService.getId());
- } catch (RemoteException ex) {
- Logger.getLogger(RioConnector.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
-
-
-
-}
More information about the jboss-svn-commits
mailing list