[jboss-svn-commits] JBL Code SVN: r32551 - in labs/jbossrules/trunk: drools-core/src/main/java/org/drools/command/impl and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Apr 13 09:55:10 EDT 2010
Author: salaboy21
Date: 2010-04-13 09:55:09 -0400 (Tue, 13 Apr 2010)
New Revision: 32551
Added:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/runtime/rule/InsertObjectInEntryPointCommand.java
labs/jbossrules/trunk/drools-grid/drools-grid-rio/src/main/java/org/drools/grid/distributed/WorkingMemoryEntryPointGridClient.java
labs/jbossrules/trunk/drools-grid/drools-grid-rio/src/main/java/org/drools/grid/distributed/command/GetWorkingMemoryEntryPointGridCommand.java
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/KnowledgeContextResolveFromContextCommand.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/impl/KnowledgeCommandContext.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DisconnectedFactHandle.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/EventFactHandle.java
labs/jbossrules/trunk/drools-grid/drools-grid-rio/src/main/java/org/drools/grid/distributed/StatefulKnowledgeSessionGridClient.java
labs/jbossrules/trunk/drools-grid/drools-grid-rio/src/main/java/org/drools/grid/distributed/command/NewStatefulKnowledgeSessionGridCommand.java
Log:
JBRULES-2446: Drools Services API
- drools-grid-rio using entry points with distributed services
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/KnowledgeContextResolveFromContextCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/KnowledgeContextResolveFromContextCommand.java 2010-04-13 13:34:59 UTC (rev 32550)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/KnowledgeContextResolveFromContextCommand.java 2010-04-13 13:55:09 UTC (rev 32551)
@@ -1,6 +1,7 @@
package org.drools.command;
import org.drools.KnowledgeBase;
+import org.drools.WorkingMemoryEntryPoint;
import org.drools.builder.KnowledgeBuilder;
import org.drools.command.impl.GenericCommand;
import org.drools.command.impl.KnowledgeCommandContext;
@@ -15,6 +16,7 @@
private String kbuilderIdentifier;
private String statefulKsessionName;
private String kresults;
+ private String workingMemoryEntryPointName;
private Command command;
public KnowledgeContextResolveFromContextCommand(Command command,
@@ -28,12 +30,22 @@
this.statefulKsessionName = statefulKsessionName;
this.kresults = kresults;
}
+ public KnowledgeContextResolveFromContextCommand(Command command,
+ String kbuilderIdentifier,
+ String kbaseIdentifier,
+ String statefulKsessionName,
+ String workingMemoryEntryPointName,
+ String kresults) {
+ this(command, kbuilderIdentifier, kbaseIdentifier, statefulKsessionName, kresults);
+ this.workingMemoryEntryPointName = workingMemoryEntryPointName;
+ }
public Object execute(Context context) {
KnowledgeCommandContext kcContext = new KnowledgeCommandContext( context,
(KnowledgeBuilder) context.get( this.kbuilderIdentifier ),
(KnowledgeBase) context.get( this.kbaseIdentifier ),
(StatefulKnowledgeSession) context.get( this.statefulKsessionName ),
+ (WorkingMemoryEntryPoint) context.get(this.workingMemoryEntryPointName),
(ExecutionResultImpl) context.get( this.kresults ) );
return ((GenericCommand) command).execute( kcContext );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/impl/KnowledgeCommandContext.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/impl/KnowledgeCommandContext.java 2010-04-13 13:34:59 UTC (rev 32550)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/impl/KnowledgeCommandContext.java 2010-04-13 13:55:09 UTC (rev 32551)
@@ -7,6 +7,7 @@
import org.drools.runtime.ExecutionResults;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.WorkItemManager;
+import org.drools.runtime.rule.WorkingMemoryEntryPoint;
public class KnowledgeCommandContext
implements
@@ -15,6 +16,7 @@
private KnowledgeBuilder kbuilder;
private KnowledgeBase kbase;
private StatefulKnowledgeSession statefulKsession;
+ private WorkingMemoryEntryPoint workingMemoryEntryPoint;
private ExecutionResults kresults;
public KnowledgeCommandContext(Context context,
@@ -28,6 +30,15 @@
this.statefulKsession = statefulKsession;
this.kresults = kresults;
}
+ public KnowledgeCommandContext(Context context,
+ KnowledgeBuilder kbuilder,
+ KnowledgeBase kbase,
+ StatefulKnowledgeSession statefulKsession,
+ WorkingMemoryEntryPoint workingMemoryEntryPoint,
+ ExecutionResults kresults) {
+ this(context, kbuilder, kbase, statefulKsession, kresults);
+ this.workingMemoryEntryPoint = workingMemoryEntryPoint;
+ }
public KnowledgeBuilder getKnowledgeBuilder() {
return kbuilder;
@@ -48,7 +59,16 @@
public ExecutionResults getExecutionResults() {
return this.kresults;
}
+
+ public WorkingMemoryEntryPoint getWorkingMemoryEntryPoint() {
+ return workingMemoryEntryPoint;
+ }
+
+ public void setWorkingMemoryEntryPoint(WorkingMemoryEntryPoint workingMemoryEntryPoint) {
+ this.workingMemoryEntryPoint = workingMemoryEntryPoint;
+ }
+
public ContextManager getContextManager() {
return context.getContextManager();
}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/runtime/rule/InsertObjectInEntryPointCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/runtime/rule/InsertObjectInEntryPointCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/runtime/rule/InsertObjectInEntryPointCommand.java 2010-04-13 13:55:09 UTC (rev 32551)
@@ -0,0 +1,87 @@
+package org.drools.command.runtime.rule;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+
+import org.drools.command.Context;
+import org.drools.command.impl.GenericCommand;
+import org.drools.command.impl.KnowledgeCommandContext;
+import org.drools.common.DisconnectedFactHandle;
+import org.drools.runtime.impl.ExecutionResultImpl;
+import org.drools.runtime.rule.FactHandle;
+import org.drools.runtime.rule.WorkingMemoryEntryPoint;
+
+ at XmlAccessorType(XmlAccessType.NONE)
+public class InsertObjectInEntryPointCommand
+ implements
+ GenericCommand<FactHandle> {
+
+ private static final long serialVersionUID = 1L;
+ @XmlElement
+ private Object object;
+ @XmlAttribute(name = "out-identifier", required = true)
+ private String outIdentifier;
+ private boolean returnObject = true;
+
+ public InsertObjectInEntryPointCommand() {
+ }
+
+ public InsertObjectInEntryPointCommand(Object object) {
+ this.object = object;
+ }
+
+ public InsertObjectInEntryPointCommand(Object object, String outIdentifier) {
+ super();
+ this.object = object;
+ this.outIdentifier = outIdentifier;
+ }
+
+ public FactHandle execute(Context context) {
+
+ WorkingMemoryEntryPoint ep = ((KnowledgeCommandContext) context).getWorkingMemoryEntryPoint();
+ FactHandle factHandle = ep.insert(object);
+
+ DisconnectedFactHandle disconectedHandle = new DisconnectedFactHandle(factHandle.toExternalForm());
+
+ if (outIdentifier != null) {
+ if (this.returnObject) {
+ ((ExecutionResultImpl) ((KnowledgeCommandContext) context).getExecutionResults()).getResults().put(this.outIdentifier,
+ object);
+ }
+ ((ExecutionResultImpl) ((KnowledgeCommandContext) context).getExecutionResults()).getFactHandles().put(this.outIdentifier,
+ disconectedHandle.toExternalForm());
+ }
+
+ return disconectedHandle;
+ }
+
+ public void setObject(Object object) {
+ this.object = object;
+ }
+
+ public Object getObject() {
+ return this.object;
+ }
+
+ public String getOutIdentifier() {
+ return this.outIdentifier;
+ }
+
+ public void setOutIdentifier(String outIdentifier) {
+ this.outIdentifier = outIdentifier;
+ }
+
+ public boolean isReturnObject() {
+ return returnObject;
+ }
+
+ public void setReturnObject(boolean returnObject) {
+ this.returnObject = returnObject;
+ }
+
+ public String toString() {
+ return "session.insert(" + object + ");";
+ }
+}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DisconnectedFactHandle.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DisconnectedFactHandle.java 2010-04-13 13:34:59 UTC (rev 32550)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DisconnectedFactHandle.java 2010-04-13 13:55:09 UTC (rev 32551)
@@ -1,5 +1,6 @@
package org.drools.common;
+import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/EventFactHandle.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/EventFactHandle.java 2010-04-13 13:34:59 UTC (rev 32550)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/EventFactHandle.java 2010-04-13 13:55:09 UTC (rev 32551)
@@ -68,9 +68,11 @@
/**
* @see FactHandle
+ * 1: is used for EventFactHandle
*/
public String toExternalForm() {
- return "[event fid:" + getId() + ":" + getRecency() + ":" + getObject() + "]";
+ //return "[event fid:" + getId() + ":" + getRecency() + ":" + getObject() + "]";
+ return "1:" + this.getId() + ":" + getIdentityHashCode() + ":" + getObjectHashCode() + ":" + getRecency();
}
/**
Modified: labs/jbossrules/trunk/drools-grid/drools-grid-rio/src/main/java/org/drools/grid/distributed/StatefulKnowledgeSessionGridClient.java
===================================================================
--- labs/jbossrules/trunk/drools-grid/drools-grid-rio/src/main/java/org/drools/grid/distributed/StatefulKnowledgeSessionGridClient.java 2010-04-13 13:34:59 UTC (rev 32550)
+++ labs/jbossrules/trunk/drools-grid/drools-grid-rio/src/main/java/org/drools/grid/distributed/StatefulKnowledgeSessionGridClient.java 2010-04-13 13:55:09 UTC (rev 32551)
@@ -1,7 +1,6 @@
package org.drools.grid.distributed;
-import org.drools.grid.ExecutionNodeService;
import java.util.Collection;
import java.util.Map;
@@ -30,6 +29,7 @@
import org.drools.grid.command.GetWorkItemManagerCommand;
import org.drools.grid.command.RegisterRemoteWorkItemHandlerCommand;
import org.drools.grid.command.StartProcessRemoteCommand;
+import org.drools.grid.distributed.command.GetWorkingMemoryEntryPointGridCommand;
import org.drools.grid.generic.GenericNodeConnector;
import org.drools.grid.generic.Message;
import org.drools.grid.generic.MessageSession;
@@ -133,7 +133,8 @@
kresultsId ) );
try {
- Object object = nodeConnection.write( msg ).getPayload();if ( object == null ) {
+ Object object = nodeConnection.write( msg ).getPayload();
+ if ( object == null ) {
throw new RuntimeException( "Response was not correctly received" );
}
@@ -203,8 +204,32 @@
}
public WorkingMemoryEntryPoint getWorkingMemoryEntryPoint(String name) {
- // TODO Auto-generated method stub
- return null;
+ String commandId = "ksession.execute" + messageSession.getNextId();
+ String kresultsId = "kresults_" + messageSession.getSessionId();
+
+ Message msg = new Message( messageSession.getSessionId(),
+ messageSession.counter.incrementAndGet(),
+ false,
+ new KnowledgeContextResolveFromContextCommand( new GetWorkingMemoryEntryPointGridCommand( name ),
+ null,
+ null,
+ instanceId,
+ name,
+ kresultsId ) );
+
+ try {
+ Object object = nodeConnection.write( msg ).getPayload();
+
+ if ( object == null ) {
+ throw new RuntimeException( "Response was not correctly received" );
+ }
+
+ return new WorkingMemoryEntryPointGridClient(name, nodeConnection, messageSession);
+ } catch ( Exception e ) {
+ throw new RuntimeException( "Unable to execute message",
+ e );
+ }
+
}
public Collection< ? extends WorkingMemoryEntryPoint> getWorkingMemoryEntryPoints() {
Added: labs/jbossrules/trunk/drools-grid/drools-grid-rio/src/main/java/org/drools/grid/distributed/WorkingMemoryEntryPointGridClient.java
===================================================================
--- labs/jbossrules/trunk/drools-grid/drools-grid-rio/src/main/java/org/drools/grid/distributed/WorkingMemoryEntryPointGridClient.java (rev 0)
+++ labs/jbossrules/trunk/drools-grid/drools-grid-rio/src/main/java/org/drools/grid/distributed/WorkingMemoryEntryPointGridClient.java 2010-04-13 13:55:09 UTC (rev 32551)
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2010 salaboy.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * under the License.
+ */
+
+package org.drools.grid.distributed;
+
+import java.util.Collection;
+import org.drools.FactException;
+import org.drools.FactHandle;
+import org.drools.WorkingMemoryEntryPoint;
+import org.drools.command.ExecuteCommand;
+import org.drools.command.KnowledgeContextResolveFromContextCommand;
+import org.drools.command.runtime.rule.InsertObjectCommand;
+import org.drools.command.runtime.rule.InsertObjectInEntryPointCommand;
+import org.drools.common.DisconnectedFactHandle;
+import org.drools.grid.generic.GenericNodeConnector;
+import org.drools.grid.generic.Message;
+import org.drools.grid.generic.MessageSession;
+import org.drools.runtime.ExecutionResults;
+import org.drools.runtime.ObjectFilter;
+
+/**
+ *
+ * @author salaboy
+ */
+public class WorkingMemoryEntryPointGridClient implements WorkingMemoryEntryPoint{
+
+ private GenericNodeConnector client;
+ private MessageSession messageSession;
+ private String instanceId;
+
+ public WorkingMemoryEntryPointGridClient(String instanceId, GenericNodeConnector client, MessageSession messageSession) {
+ this.client = client;
+ this.messageSession = messageSession;
+ this.instanceId = instanceId;
+ }
+
+
+
+ public FactHandle insert(Object object) throws FactException {
+ String commandId = "ksession.insert" + messageSession.getNextId();
+ String kresultsId = "kresults_" + messageSession.getSessionId();
+ System.out.println("INSTANCE ID, ENTRY POINT!!!!! ="+instanceId);
+ Message msg = new Message( messageSession.getSessionId(),
+ messageSession.counter.incrementAndGet(),
+ false,
+ new KnowledgeContextResolveFromContextCommand( new InsertObjectInEntryPointCommand(object, String.valueOf(object.hashCode()) ),
+ null,
+ null,
+ null,
+ instanceId,
+ kresultsId ) );
+
+ try {
+ Object result = client.write( msg ).getPayload();
+ if ( object == null ) {
+ throw new RuntimeException( "Response was not correctly received" );
+ }
+ FactHandle handle = new DisconnectedFactHandle(((ExecutionResults) result).getFactHandle( String.valueOf(object.hashCode()) ).toString()) ;
+
+ return handle;
+ } catch ( Exception e ) {
+ throw new RuntimeException( "Unable to execute message",
+ e );
+ }
+ }
+
+ public FactHandle insert(Object object, boolean dynamic) throws FactException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void retract(org.drools.runtime.rule.FactHandle handle) throws FactException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void update(org.drools.runtime.rule.FactHandle handle, Object object) throws FactException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public WorkingMemoryEntryPoint getWorkingMemoryEntryPoint(String name) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getEntryPointId() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public org.drools.runtime.rule.FactHandle getFactHandle(Object object) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Object getObject(org.drools.runtime.rule.FactHandle factHandle) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Collection<Object> getObjects() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Collection<Object> getObjects(ObjectFilter filter) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public <T extends org.drools.runtime.rule.FactHandle> Collection<T> getFactHandles() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public <T extends org.drools.runtime.rule.FactHandle> Collection<T> getFactHandles(ObjectFilter filter) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public long getFactCount() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+}
Added: labs/jbossrules/trunk/drools-grid/drools-grid-rio/src/main/java/org/drools/grid/distributed/command/GetWorkingMemoryEntryPointGridCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-grid/drools-grid-rio/src/main/java/org/drools/grid/distributed/command/GetWorkingMemoryEntryPointGridCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-grid/drools-grid-rio/src/main/java/org/drools/grid/distributed/command/GetWorkingMemoryEntryPointGridCommand.java 2010-04-13 13:55:09 UTC (rev 32551)
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2010 salaboy.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * under the License.
+ */
+
+package org.drools.grid.distributed.command;
+
+/**
+ *
+ * @author salaboy
+ */
+
+
+import org.drools.command.Context;
+import org.drools.command.impl.GenericCommand;
+import org.drools.command.impl.KnowledgeCommandContext;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.rule.WorkingMemoryEntryPoint;
+
+public class GetWorkingMemoryEntryPointGridCommand
+ implements
+ GenericCommand<WorkingMemoryEntryPoint> {
+
+ private String name;
+
+ public GetWorkingMemoryEntryPointGridCommand(String name) {
+ this.name = name;
+ }
+
+ public WorkingMemoryEntryPoint execute(Context context) {
+ StatefulKnowledgeSession ksession = ((KnowledgeCommandContext) context).getStatefulKnowledgesession();
+ WorkingMemoryEntryPoint ep = ksession.getWorkingMemoryEntryPoint( name );
+
+ context.getContextManager().getDefaultContext().set(name, ep); //setWorkingMemoryEntryPoint( ep );
+ //((KnowledgeCommandContext) context.getContextManager() ).set(name, ep);
+ return ep;
+ }
+
+ public String toString() {
+ return "session.getWorkingMemoryEntryPoint( " + name + " );";
+ }
+}
Modified: labs/jbossrules/trunk/drools-grid/drools-grid-rio/src/main/java/org/drools/grid/distributed/command/NewStatefulKnowledgeSessionGridCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-grid/drools-grid-rio/src/main/java/org/drools/grid/distributed/command/NewStatefulKnowledgeSessionGridCommand.java 2010-04-13 13:34:59 UTC (rev 32550)
+++ labs/jbossrules/trunk/drools-grid/drools-grid-rio/src/main/java/org/drools/grid/distributed/command/NewStatefulKnowledgeSessionGridCommand.java 2010-04-13 13:55:09 UTC (rev 32551)
@@ -33,9 +33,9 @@
KnowledgeBase kbase = ((KnowledgeCommandContext) context).getKnowledgeBase();
DirectoryNodeService registry = (DirectoryNodeService)context.get("registry");
- System.out.println("Inside Grid Command!!!!!!!!");
- System.out.println("Registry = "+registry);
- System.out.println("KbaseId = "+kbaseId);
+// System.out.println("Inside Grid Command!!!!!!!!");
+// System.out.println("Registry = "+registry);
+// System.out.println("KbaseId = "+kbaseId);
StatefulKnowledgeSession ksession;
if( kbase == null){
More information about the jboss-svn-commits
mailing list