Skip to content
Browse files

Dynamic resource addition

  • Loading branch information...
1 parent 43f5e6f commit 79ef0f94c748f6428e0964ed2f897762749b5985 @sotty sotty committed
View
2 drools-mas-acl/pom.xml
@@ -58,7 +58,7 @@
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
- <version>1.2.2</version>
+ <version>1.4.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jettison</groupId>
View
12 drools-mas-core/src/main/java/org/drools/mas/core/DroolsAgentFactory.java
@@ -110,12 +110,12 @@ public DroolsAgent spawn( DroolsAgentConfiguration config ) {
SessionManager sm = SessionManager.create( config, descr, grid, true );
StatefulKnowledgeSession mindSet = sm.getStatefulKnowledgeSession();
- try{
- mindSet.setGlobal( "grid", grid );
- } catch (Exception e){
- //maybe 'grid' is not even defined in subsession
- logger.debug("Global 'grid' not set on session '"+descr.getSessionId()+"' due to "+e.getMessage());
- }
+// try{
+// mindSet.setGlobal( "grid", grid );
+// } catch (Exception e){
+// //maybe 'grid' is not even defined in subsession
+// logger.debug("Global 'grid' not set on session '"+descr.getSessionId()+"' due to "+e.getMessage());
+// }
mindSet.fireAllRules();
View
9 drools-mas-core/src/main/java/org/drools/mas/core/SessionManager.java
@@ -119,6 +119,10 @@ public static SessionManager create( String sessionId, DroolsAgentConfiguration
// should indicate that someone else left an orphan row in the WP
node = grid.claimGridNode( nodeId );
grid.get( SocketService.class ).addService( nodeId, port, node );
+
+ if ( forceRemote && ! node.isRemote() ) {
+ node = grid.asRemoteNode( node );
+ }
}
@@ -127,8 +131,11 @@ public static SessionManager create( String sessionId, DroolsAgentConfiguration
logger.debug( " ### Session Manager: Creating a new Local Node" );
}
node = createLocalNode( grid, nodeId );
-
grid.get( SocketService.class ).addService( nodeId, port, node );
+
+ if ( forceRemote && ! node.isRemote() ) {
+ node = grid.asRemoteNode( node );
+ }
}
} else {
View
20 drools-mas-core/src/main/resources/org/drools/mas/acl_common.drl
@@ -30,6 +30,7 @@ import org.drools.mas.util.LoggerHelper;
import org.drools.mas.util.helper.SessionLocator;
import org.drools.grid.Grid;
+import org.drools.grid.helper.GridHelper;
import org.drools.grid.api.impl.ResourceDescriptorImpl;
import org.drools.grid.api.ResourceDescriptor;
@@ -39,8 +40,8 @@ import org.drools.builder.ResourceType;
global Grid grid;
declare ResourceAdditionRequest
- URL: URL
- type: ResourceType
+ URL : URL
+ type : ResourceType
end
query queryIf( Object $o )
@@ -77,6 +78,16 @@ end
//end
+rule "Init Grid"
+salience 999
+when
+then
+ // need to initialize Grid in remote nodes
+ if ( kcontext.getKnowledgeRuntime().getGlobal( "grid" ) == null ) {
+ kcontext.getKnowledgeRuntime().setGlobal( "grid", GridHelper.createGrid() );
+ }
+end
+
rule "Add Resource"
when
$rar: ResourceAdditionRequest($url: URL, $type: type)
@@ -88,10 +99,7 @@ then
rd.setResourceURL($url);
rd.setType($type);
- //SessionManager.addResource(grid, $nodeId, $sessionId, rd);
-
- SessionManager.addResource(drools.getWorkingMemory(), rd);
+ SessionManager.addResource( grid, $nodeId, $sessionId, rd );
-
retract($rar);
end
View
4 drools-mas-core/src/test/java/org/drools/mas/core/tests/TestAgent.java
@@ -79,9 +79,9 @@ public void createAgents() {
DroolsAgentConfiguration mainConfig = new DroolsAgentConfiguration();
mainConfig.setAgentId( "Mock Test Agent" );
mainConfig.setChangeset( "mainTestAgent_changeset.xml" );
- DroolsAgentConfiguration.SubSessionDescriptor subDescr1 = new DroolsAgentConfiguration.SubSessionDescriptor( "session1", "sub1.xml", "local-mock-test-agent" );
+ DroolsAgentConfiguration.SubSessionDescriptor subDescr1 = new DroolsAgentConfiguration.SubSessionDescriptor( "session1", "sub1.xml", "mock-test-agent" );
mainConfig.addSubSession( subDescr1 );
- DroolsAgentConfiguration.SubSessionDescriptor subDescr2 = new DroolsAgentConfiguration.SubSessionDescriptor( "session2", "sub2.xml", "local-mock-test-agent" );
+ DroolsAgentConfiguration.SubSessionDescriptor subDescr2 = new DroolsAgentConfiguration.SubSessionDescriptor( "session2", "sub2.xml", "mock-test-agent" );
mainConfig.addSubSession( subDescr2 );
mainConfig.setMindNodeLocation( "local-mock-test-agent" );
mainConfig.setPort( 7000 );
View
2 examples/drools-mas-emergency-agent/src/main/resources/META-INF/applicationContext.xml
@@ -21,7 +21,7 @@ http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<bean id="async-agent-service" class="org.drools.mas.AsyncDroolsAgentServiceImpl" destroy-method="dispose">
<property name="agent" ref="agent"/>
</bean>
- <bean id="agent-service" class="org.drools.mas.SynchronousDroolsAgentServiceImpl" destroy-method="dispose">
+ <bean id="agent-service" class="org.drools.mas.SynchronousDroolsAgentServiceImpl" >
<property name="agent" ref="agent"/>
</bean>

0 comments on commit 79ef0f9

Please sign in to comment.
Something went wrong with that request. Please try again.