Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #23 from sotty/master

Avoid thread and memory leaks
  • Loading branch information...
commit 3eb5bbb38b965adc505a9f08e0034a9311f49ad6 2 parents 658a5b2 + 06fb39a
Salaboy authored

Showing 18 changed files with 199 additions and 120 deletions. Show diff stats Hide diff stats

  1. 8  drools-mas-core/src/main/java/org/drools/mas/core/DroolsAgent.java
  2. 17  drools-mas-core/src/main/java/org/drools/mas/core/DroolsAgentFactory.java
  3. 11  drools-mas-core/src/main/java/org/drools/mas/core/SessionManager.java
  4. 4  drools-mas-core/src/main/resources/org/drools/mas/acl_common.drl
  5. 1  drools-mas-core/src/main/resources/org/drools/mas/acl_content_based_routing.drl
  6. 10  drools-mas-core/src/main/resources/org/drools/mas/acl_internal.drl
  7. 16  drools-mas-core/src/test/java/org/drools/mas/core/tests/GridTests.java
  8. 2  drools-mas-core/src/test/java/org/drools/mas/core/tests/SpringAgentTest.java
  9. 47  drools-mas-core/src/test/java/org/drools/mas/core/tests/TestAgent.java
  10. 6  drools-mas-core/src/test/resources/session2.drl
  11. 121  drools-mas-generic-client/pom.xml
  12. 13  drools-mas-generic-client/src/main/java/org/drools/mas/helpers/SyncDialogueHelper.java
  13. 22  drools-mas-util/src/main/java/org/drools/mas/util/helper/ResponseContent.java
  14. 8  examples/drools-mas-emergency-agent-client/pom.xml
  15. 5  examples/drools-mas-emergency-agent-client/src/test/java/org/drools/mas/EmergencyAgentServiceRemoteTest.java
  16. 13  examples/drools-mas-emergency-agent-model/pom.xml
  17. 2  examples/drools-mas-emergency-agent/src/main/resources/knowledge/agent-brain_hello-module.drl
  18. 13  pom.xml
8  drools-mas-core/src/main/java/org/drools/mas/core/DroolsAgent.java
@@ -21,6 +21,8 @@
21 21
 import java.util.List;
22 22
 import java.util.Set;
23 23
 import org.drools.grid.*;
  24
+import org.drools.impl.StatefulKnowledgeSessionImpl;
  25
+import org.drools.management.DroolsManagementAgent;
24 26
 import org.drools.mas.util.MessageContentEncoder;
25 27
 import org.drools.runtime.StatefulKnowledgeSession;
26 28
 
@@ -103,6 +105,9 @@ public void tell( ACLMessage msg ) {
103 105
      * Destructor
104 106
      */
105 107
     public void dispose() {
  108
+        DroolsManagementAgent kmanagement = DroolsManagementAgent.getInstance();
  109
+        kmanagement.unregisterKnowledgeSession( ( (StatefulKnowledgeSessionImpl ) mind).getInternalWorkingMemory() );
  110
+
106 111
         //TODO : what if another agent is using this grid's nodes?
107 112
         try {
108 113
             if ( logger.isInfoEnabled() ) {
@@ -144,6 +149,9 @@ public void dispose() {
144 149
         } finally {
145 150
             grid.dispose();
146 151
         }
  152
+        // Should have already been disposed...
  153
+        mind.dispose();
  154
+
147 155
     }
148 156
 
149 157
 
17  drools-mas-core/src/main/java/org/drools/mas/core/DroolsAgentFactory.java
@@ -15,6 +15,7 @@
15 15
  */
16 16
 package org.drools.mas.core;
17 17
 
  18
+import org.drools.grid.helper.GridHelper;
18 19
 import org.drools.grid.remote.StatefulKnowledgeSessionRemoteClient;
19 20
 import org.drools.mas.util.helper.NodeLocator;
20 21
 import org.drools.runtime.StatefulKnowledgeSession;
@@ -62,7 +63,7 @@
62 63
     private static DroolsAgentFactory singleton;
63 64
 
64 65
     public static DroolsAgentFactory getInstance() {
65  
-        if (singleton == null) {
  66
+        if ( singleton == null ) {
66 67
             singleton = new DroolsAgentFactory();
67 68
         }
68 69
         return singleton;
@@ -76,15 +77,20 @@ public DroolsAgent spawn( DroolsAgentConfiguration config ) {
76 77
         configureGrid( grid, config.getPort() );
77 78
 
78 79
         AgentID aid = new AgentID();
79  
-        aid.setName( config.getAgentId() );
80  
-        aid.setLocalName( config.getAgentId() );
  80
+            aid.setName( config.getAgentId() );
  81
+            aid.setLocalName( config.getAgentId() );
  82
+
81 83
         if ( logger.isInfoEnabled() ) {
82 84
             logger.info( " >>> Spawning Agent => Name: " + aid.getName() );
83 85
         }
  86
+
84 87
         try {
  88
+
85 89
             if ( logger.isDebugEnabled() ) {
86 90
                 logger.debug("  ### Creating Agent Mind: " + config.getAgentId() + "- CS: " + config.getChangeset() +" - mind location: " +config.getMindNodeLocation() );
87 91
             }
  92
+
  93
+
88 94
             SessionManager manager = SessionManager.create( config, null, grid, false );
89 95
             if ( manager == null ) {
90 96
                 logger.error( "SOMETHING BAD HAPPENED WHILE TRYING TO CREATE AN AGENT, could not create sessionManager" );
@@ -94,9 +100,6 @@ public DroolsAgent spawn( DroolsAgentConfiguration config ) {
94 100
             StatefulKnowledgeSession mind = manager.getStatefulKnowledgeSession();
95 101
 
96 102
             DroolsManagementAgent kmanagement = DroolsManagementAgent.getInstance();
97  
-
98  
-            //kmanagement.registerKnowledgeBase((ReteooRuleBase) ((KnowledgeBaseImpl) mind.get).getRuleBase());
99  
-
100 103
             kmanagement.registerKnowledgeSession( ( (StatefulKnowledgeSessionImpl) mind ).getInternalWorkingMemory() );
101 104
 
102 105
             if ( logger.isDebugEnabled() ) {
@@ -150,7 +153,7 @@ public DroolsAgent spawn( DroolsAgentConfiguration config ) {
150 153
 
151 154
             return new DroolsAgent( grid, aid, mind );
152 155
         } catch ( Throwable t ) {
153  
-            if (t.getCause() != null){
  156
+            if ( t.getCause() != null ){
154 157
                 logger.error( "SOMETHING BAD HAPPENED WHILE TRYING TO CREATE AN AGENT " + t.getMessage() + ", due to " + t.getCause().getMessage() );
155 158
             }else{
156 159
                 logger.error( "SOMETHING BAD HAPPENED WHILE TRYING TO CREATE AN AGENT " + t.getMessage());
11  drools-mas-core/src/main/java/org/drools/mas/core/SessionManager.java
@@ -26,8 +26,10 @@
26 26
 import org.drools.grid.*;
27 27
 import org.drools.grid.api.ResourceDescriptor;
28 28
 import org.drools.grid.service.directory.Address;
  29
+import org.drools.impl.EnvironmentImpl;
29 30
 import org.drools.io.Resource;
30 31
 import org.drools.io.impl.ByteArrayResource;
  32
+import org.drools.runtime.Environment;
31 33
 import org.drools.runtime.KnowledgeSessionConfiguration;
32 34
 import org.drools.runtime.StatefulKnowledgeSession;
33 35
 import org.drools.runtime.conf.ClockTypeOption;
@@ -193,9 +195,11 @@ protected SessionManager( String id, KnowledgeBase kbase, GridNode node ) {
193 195
         }
194 196
 
195 197
         conf.setProperty( ClockTypeOption.PROPERTY_NAME, ClockType.REALTIME_CLOCK.toExternalForm() );
  198
+        Environment env = new EnvironmentImpl();
  199
+        env.set( "sessionId", id );
196 200
 
197 201
 //        this.kSession = kAgent.getKnowledgeBase().newStatefulKnowledgeSession(conf, null);
198  
-        this.kSession = kbase.newStatefulKnowledgeSession( conf, null );
  202
+        this.kSession = kbase.newStatefulKnowledgeSession( conf, env );
199 203
         if ( ! node.isRemote() ) {
200 204
             addKnowledgeAgent( id, kbase, node );
201 205
         }
@@ -205,6 +209,9 @@ protected SessionManager( String id, KnowledgeBase kbase, GridNode node ) {
205 209
             logger.info( " ### SessionManager : Registering session " + id + " in node: " + node.getId() );
206 210
         }
207 211
         node.set( id, this.kSession );
  212
+        if ( ! node.isRemote() ) {
  213
+            kSession.setGlobal( "grid", node.getGrid() );
  214
+        }
208 215
 
209 216
     }
210 217
 
@@ -344,7 +351,7 @@ public static void addResource( Grid grid, String nodeId, String sessionId, Stri
344 351
             KnowledgeAgent kAgent;
345 352
             GridNode node = grid.getGridNode( nodeId );
346 353
             if ( node == null || node.isRemote() ) {
347  
-                kAgent = GridHelper.getKnowledgeAgentRemoteClient( grid, nodeId, sessionId );
  354
+                kAgent = GridHelper.getInstance().getKnowledgeAgentRemoteClient( grid, nodeId, sessionId );
348 355
             } else {
349 356
                 kAgent = node.get( sessionId + "_kAgent", KnowledgeAgent.class );
350 357
             }
4  drools-mas-core/src/main/resources/org/drools/mas/acl_common.drl
@@ -82,9 +82,9 @@ rule "Init Grid"
82 82
 salience 999
83 83
 when
84 84
 then
85  
-    // need to initialize Grid in remote nodes
86 85
     if ( kcontext.getKnowledgeRuntime().getGlobal( "grid" ) == null ) {
87  
-        kcontext.getKnowledgeRuntime().setGlobal( "grid", GridHelper.createGrid() );
  86
+        LoggerHelper.error( "Fatal error, global object GRID is not set" );
  87
+//        kcontext.getKnowledgeRuntime().setGlobal( "grid", GridHelper.getInstance().createGrid() );
88 88
     }
89 89
 end
90 90
 
1  drools-mas-core/src/main/resources/org/drools/mas/acl_content_based_routing.drl
@@ -30,7 +30,6 @@ import org.drools.mas.util.LoggerHelper;
30 30
 import org.drools.mas.core.DroolsAgentConfiguration;
31 31
 import org.drools.mas.util.helper.SessionLocator;
32 32
 import org.drools.mas.util.helper.NodeLocator;
33  
-import org.drools.grid.helper.GridHelper;
34 33
 import org.drools.mas.util.helper.NoHandlerFault;
35 34
 
36 35
 
10  drools-mas-core/src/main/resources/org/drools/mas/acl_internal.drl
@@ -28,12 +28,14 @@ import org.drools.command.CommandFactory;
28 28
 import org.drools.command.BatchExecutionCommand;
29 29
 import org.drools.grid.remote.command.AsyncBatchExecutionCommandImpl;
30 30
 import org.drools.runtime.rule.QueryResults;
  31
+import org.drools.grid.helper.GridHelper;
31 32
 import org.drools.mas.Act;
32 33
 import org.drools.mas.body.content.*;
33 34
 import org.drools.mas.body.acts.*;
34 35
 import org.drools.mas.util.MessageContentHelper;
35 36
 import org.drools.mas.util.MessageContentFactory;
36 37
 import org.drools.command.runtime.rule.QueryCommand;
  38
+import org.drools.grid.helper.GridHelper;
37 39
 import java.util.List;
38 40
 import java.util.ArrayList;
39 41
 
@@ -67,7 +69,7 @@ then
67 69
     
68 70
     retract( $cmd );
69 71
 
70  
-    StatefulKnowledgeSession kSession = GridHelper.getStatefulKnowledgeSession( grid, $nodeId, $sessionId, true );
  72
+    StatefulKnowledgeSession kSession = GridHelper.getInstance().getStatefulKnowledgeSession( grid, $nodeId, $sessionId, true );
71 73
     if ( LoggerHelper.isDebugEnabled() ) {
72 74
             LoggerHelper.debug( " ### INTERNAL RULES: Trying to execute in = " + kSession );
73 75
         }
@@ -119,7 +121,7 @@ then
119 121
     retract( $cmd );
120 122
     
121 123
    
122  
-    StatefulKnowledgeSession kSession = GridHelper.getStatefulKnowledgeSession( grid, $nodeId, $sessionId, true );
  124
+    StatefulKnowledgeSession kSession = GridHelper.getInstance().getStatefulKnowledgeSession( grid, $nodeId, $sessionId, true );
123 125
     kSession.execute( $act );
124 126
     kSession.execute( CommandFactory.newFireAllRules() );
125 127
 end
@@ -214,7 +216,7 @@ then
214 216
         LoggerHelper.debug(" ### INTERNAL: FIXING QUERYIF RESULTS " + $sessionId );
215 217
     }
216 218
     if( $data instanceof QueryResultsDescriptor ) {
217  
-        $data = GridHelper.getQueryResultRemoteClient( grid, $nodeId, $sessionId,
  219
+        $data = GridHelper.getInstance().getQueryResultRemoteClient( grid, $nodeId, $sessionId,
218 220
                 ( (QueryResultsDescriptor) $data ).getQueryName(), ( (QueryResultsDescriptor) $data ).getQueryId() );
219 221
     }
220 222
     modify ( $cont ) {
@@ -259,7 +261,7 @@ then
259 261
         LoggerHelper.debug(" ### INTERNAL: FIXING RESULTS FOR QUERYREF " + $data);
260 262
     }
261 263
     if( $data instanceof QueryResultsDescriptor ) {
262  
-        $data = GridHelper.getQueryResultRemoteClient( grid, $nodeId, $sessionId,
  264
+        $data = GridHelper.getInstance().getQueryResultRemoteClient( grid, $nodeId, $sessionId,
263 265
                 ( (QueryResultsDescriptor) $data ).getQueryName(), ( (QueryResultsDescriptor) $data ).getQueryId() );
264 266
     }
265 267
 
16  drools-mas-core/src/test/java/org/drools/mas/core/tests/GridTests.java
@@ -68,7 +68,9 @@ public static void setUpClass() throws Exception {
68 68
         }
69 69
         System.out.println("DB for white pages started! ");
70 70
 
71  
-        GridHelper.reset();
  71
+//        WhitePages wps = new JpaWhitePages( Persistence.createEntityManagerFactory("org.drools.grid") );
  72
+//
  73
+//        GridHelper.getInstance().reinitialize( wps );
72 74
     }
73 75
 
74 76
     @AfterClass
@@ -83,7 +85,8 @@ public static void tearDownClass() {
83 85
     
84 86
     private Map<String, GridServiceDescription> coreServicesMap;
85 87
     protected Grid grid1;
86  
-    
  88
+    protected Grid grid2;
  89
+
87 90
     protected GridNode remoteN1;
88 91
     private static Server server;
89 92
 
@@ -107,7 +110,7 @@ private void createRemoteNode(){
107 110
                         8000,
108 111
                         new JpaWhitePages( Persistence.createEntityManagerFactory( "org.drools.grid" ) ) );
109 112
 
110  
-        Grid grid2 = new GridImpl("peer2", new HashMap<String, Object>() );
  113
+        grid2 = new GridImpl("peer2", new HashMap<String, Object>() );
111 114
         configureGrid1( grid2,
112 115
                         -1,
113 116
                         grid1.get( WhitePages.class ) );
@@ -183,7 +186,8 @@ protected StatefulKnowledgeSession createSession(){
183 186
 
184 187
          String rule = "package test\n"
185 188
                  + "import mock.MockFact;\n"
186  
-                 + "global MockFact myGlobalObj;\n"
  189
+                 + "global MockFact myGlobalObj;\n" +
  190
+                 "  global org.drools.grid.Grid grid; \n"
187 191
                  + "query getMyObjects(String n)\n"
188 192
                  + "  $mo: MockFact(name == n)\n"
189 193
                  + "end\n"
@@ -229,7 +233,7 @@ protected StatefulKnowledgeSession createSession(){
229 233
     @Test
230 234
     public void remoteKAgentResourceLoadTest() throws InterruptedException {
231 235
         StatefulKnowledgeSession ksession = createSession();
232  
-        ksession.setGlobal("myGlobalObj", new MockFact("myglobalObj",10));
  236
+        ksession.setGlobal( "myGlobalObj", new MockFact( "myglobalObj", 10 ) );
233 237
 
234 238
         int fired = ksession.fireAllRules();
235 239
         Assert.assertEquals(0, fired);
@@ -244,7 +248,7 @@ public void remoteKAgentResourceLoadTest() throws InterruptedException {
244 248
         ((InternalResource) changeSetRes).setResourceType( ResourceType.CHANGE_SET );
245 249
 
246 250
 
247  
-        KnowledgeAgent kAgent = GridHelper.getKnowledgeAgentRemoteClient( GridHelper.createGrid(), remoteN1.getId(), "ksession-rules" );
  251
+        KnowledgeAgent kAgent = GridHelper.getInstance().getKnowledgeAgentRemoteClient( grid2, remoteN1.getId(), "ksession-rules" );
248 252
         kAgent.applyChangeSet( changeSetRes );
249 253
 
250 254
         Thread.sleep( 5000 );
2  drools-mas-core/src/test/java/org/drools/mas/core/tests/SpringAgentTest.java
@@ -60,8 +60,6 @@ public static void setUpClass() throws Exception {
60 60
         }
61 61
         logger.info("DB for white pages started! ");
62 62
 
63  
-        GridHelper.reset();
64  
-        
65 63
         logger.info( "----------------------------------------------------------------------------------------------" );
66 64
         logger.info( "PRE-Setup Complete \n\n\n\n\n" );
67 65
     }
47  drools-mas-core/src/test/java/org/drools/mas/core/tests/TestAgent.java
@@ -18,6 +18,8 @@
18 18
 import java.sql.SQLException;
19 19
 
20 20
 import org.drools.grid.helper.GridHelper;
  21
+import org.drools.grid.service.directory.WhitePages;
  22
+import org.drools.grid.service.directory.impl.JpaWhitePages;
21 23
 import org.drools.mas.body.acts.Failure;
22 24
 import org.drools.mas.body.content.Query;
23 25
 import org.drools.mas.body.acts.InformIf;
@@ -49,6 +51,8 @@
49 51
 import org.slf4j.Logger;
50 52
 import org.slf4j.LoggerFactory;
51 53
 
  54
+import javax.persistence.Persistence;
  55
+
52 56
 public class TestAgent {
53 57
 
54 58
     private static DroolsAgent mainAgent;
@@ -68,9 +72,18 @@ public static void setupDB() {
68 72
             logger.error( ex.getMessage() );
69 73
         }
70 74
         logger.info("DB for white pages started! ");
  75
+    }
71 76
 
72  
-        // force DB initialization
73  
-        GridHelper.reset();
  77
+    @Test
  78
+    @Ignore( "Manual use only, test for memory leaks" )
  79
+    public void stressTest() throws InterruptedException {
  80
+        for ( int j = 0; j < 100; j++ ) {
  81
+            if ( j > 0 ) {
  82
+                createAgents();
  83
+            }
  84
+            testRequest();
  85
+            mainAgent.dispose();
  86
+        }
74 87
     }
75 88
 
76 89
     @Before
@@ -586,7 +599,7 @@ public void testQueryRefFailure() throws InterruptedException {
586 599
         assertEquals( Act.FAILURE, ans.get(1).getPerformative() );
587 600
 
588 601
     }
589  
-    
  602
+
590 603
     @Test
591 604
     public void testDynamicResourceAddition() throws Exception{
592 605
 
@@ -595,34 +608,34 @@ public void testDynamicResourceAddition() throws Exception{
595 608
         for (Object o : target.getObjects()) {
596 609
             System.err.println("\t Assets BEFORE the inform : " + o);
597 610
         }
598  
-        
  611
+
599 612
         Assert.assertFalse(target.getObjects().contains("--------@@   It's alive!!   @@--------------"));
600  
-        
  613
+
601 614
         Assert.assertNull(target.getKnowledgeBase().getRule("org.drools.mas.test", "Test this"));
602  
-        
  615
+
603 616
         ClasspathURLResourceLocator uRLResourceLocator = new ClasspathURLResourceLocator(
604  
-            "classpath:newResource.drl", 
605  
-            ResourceType.DRL
  617
+                "classpath:newResource.drl",
  618
+                ResourceType.DRL
606 619
         );
607 620
         uRLResourceLocator.setName("patient1");
608  
-        
  621
+
609 622
         ACLMessageFactory factory = new ACLMessageFactory(Encodings.XML);
610 623
         ACLMessage info = factory.newInformMessage("me", "you", uRLResourceLocator);
611 624
         mainAgent.tell(info);
612  
-        
  625
+
613 626
         waitForAnswers( info.getId(), 0, 1000, 50 );
614  
-        
  627
+
615 628
         for (Object o : target.getObjects()) {
616 629
             System.err.println("\t Assets AFTER the inform : " + o);
617 630
         }
618  
-        
  631
+
619 632
         //This string comes from newResource.drl
620 633
         Assert.assertTrue( target.getObjects().contains("--------@@   It's alive!!   @@--------------") );
621 634
         Assert.assertNotNull( target.getKnowledgeBase().getRule( "org.drools.mas.test", "Test this") );
622  
-        
623  
-        
624  
-        
  635
+
  636
+
  637
+
625 638
     }
626  
-    
627  
-    
  639
+
  640
+
628 641
 }
6  drools-mas-core/src/test/resources/session2.drl
@@ -90,7 +90,7 @@ rule "Action_Request : squareRoot - Result "
90 90
         
91 91
     then
92 92
        retract($a);
93  
-       ResponseContent.deliverResponse( $nodeId, $sessionId, $msgId, $return, null );
  93
+       ResponseContent.deliverResponse( grid, $nodeId, $sessionId, $msgId, $return, null );
94 94
 end
95 95
 
96 96
 rule "Action_Request : no logic to deal with this kind request"
@@ -101,7 +101,7 @@ when
101 101
 then
102 102
     retract( $a );
103 103
     Fault fault = new NoHandlerFault( $msgId, "No known way to process a request " + $actName );
104  
-    ResponseContent.deliverResponse( $nodeId, $sessionId, $msgId, null, fault );
  104
+    ResponseContent.deliverResponse( grid, $nodeId, $sessionId, $msgId, null, fault );
105 105
 end
106 106
 
107 107
 
@@ -113,7 +113,7 @@ when
113 113
 then
114 114
     retract( $a );
115 115
     Fault fault = new ExecutionFault( $msgId,"can't extract the square root of " + $x );
116  
-    ResponseContent.deliverResponse( $nodeId, $sessionId, $msgId, null, fault );
  116
+    ResponseContent.deliverResponse( grid, $nodeId, $sessionId, $msgId, null, fault );
117 117
 end
118 118
 
119 119
 
121  drools-mas-generic-client/pom.xml
@@ -17,61 +17,68 @@
17 17
 
18 18
 <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
19 19
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
20  
-    <modelVersion>4.0.0</modelVersion>
21  
-   
22  
-    <groupId>org.drools.mas</groupId>
23  
-    <artifactId>drools-mas-generic-client</artifactId>
24  
-    <version>1.0.Final</version>
25  
-    
26  
-    <name>Drools MAS :: Generic Agent Client</name>
27  
-    <url>http://maven.apache.org</url>
28  
-    <build>
29  
-        <plugins>
30  
-       
31  
-        </plugins>
32  
-    </build>
33  
-    <repositories>
34  
-        <repository>
35  
-            <url>http://download.java.net/maven/2</url>
36  
-            <id>metro</id>
37  
-            <layout>default</layout>
38  
-            <name>Repository for library[metro]</name>
39  
-        </repository>
40  
-    </repositories>
41  
-    <pluginRepositories>
42  
-        <pluginRepository>
43  
-            <name>java.net</name>
44  
-            <id>java.net</id>
45  
-            <url>http://download.java.net/maven/2/</url>
46  
-        </pluginRepository>
47  
-    </pluginRepositories>
48  
-    <properties>
49  
-        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
50  
-    </properties>
51  
-    <dependencies>
52  
-        
53  
-        <dependency>
54  
-            <groupId>org.drools.mas</groupId>
55  
-            <artifactId>drools-mas-util</artifactId>
56  
-            <version>1.0.Final</version>
57  
-        </dependency>
58  
-        <dependency>
59  
-            <groupId>javax.xml</groupId>
60  
-            <artifactId>webservices-api</artifactId>
61  
-            <version>1.4</version>
62  
-        </dependency>
63  
-       
64  
-        <dependency>
65  
-            <groupId>com.sun.xml.ws</groupId>
66  
-            <artifactId>webservices-rt</artifactId>
67  
-            <version>1.4</version>
68  
-            <scope>provided</scope>
69  
-        </dependency>
70  
-        <dependency>
71  
-            <groupId>junit</groupId>
72  
-            <artifactId>junit</artifactId>
73  
-            <version>4.8.1</version>
74  
-            <scope>test</scope>
75  
-        </dependency>
76  
-    </dependencies>
  20
+  <modelVersion>4.0.0</modelVersion>
  21
+
  22
+  <groupId>org.drools.mas</groupId>
  23
+  <artifactId>drools-mas-generic-client</artifactId>
  24
+  <version>1.0.Final</version>
  25
+
  26
+  <name>Drools MAS :: Generic Agent Client</name>
  27
+  <url>http://maven.apache.org</url>
  28
+  <build>
  29
+    <plugins>
  30
+      <plugin>
  31
+        <groupId>org.apache.maven.plugins</groupId>
  32
+        <artifactId>maven-compiler-plugin</artifactId>
  33
+        <configuration>
  34
+          <source>1.5</source>
  35
+          <target>1.5</target>
  36
+        </configuration>
  37
+      </plugin>
  38
+    </plugins>
  39
+  </build>
  40
+  <repositories>
  41
+    <repository>
  42
+      <url>http://download.java.net/maven/2</url>
  43
+      <id>metro</id>
  44
+      <layout>default</layout>
  45
+      <name>Repository for library[metro]</name>
  46
+    </repository>
  47
+  </repositories>
  48
+  <pluginRepositories>
  49
+    <pluginRepository>
  50
+      <name>java.net</name>
  51
+      <id>java.net</id>
  52
+      <url>http://download.java.net/maven/2/</url>
  53
+    </pluginRepository>
  54
+  </pluginRepositories>
  55
+  <properties>
  56
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  57
+  </properties>
  58
+  <dependencies>
  59
+
  60
+    <dependency>
  61
+      <groupId>org.drools.mas</groupId>
  62
+      <artifactId>drools-mas-util</artifactId>
  63
+      <version>1.0.Final</version>
  64
+    </dependency>
  65
+    <dependency>
  66
+      <groupId>javax.xml</groupId>
  67
+      <artifactId>webservices-api</artifactId>
  68
+      <version>1.4</version>
  69
+    </dependency>
  70
+
  71
+    <dependency>
  72
+      <groupId>com.sun.xml.ws</groupId>
  73
+      <artifactId>webservices-rt</artifactId>
  74
+      <version>1.4</version>
  75
+      <scope>provided</scope>
  76
+    </dependency>
  77
+    <dependency>
  78
+      <groupId>junit</groupId>
  79
+      <artifactId>junit</artifactId>
  80
+      <version>4.8.1</version>
  81
+      <scope>test</scope>
  82
+    </dependency>
  83
+  </dependencies>
77 84
 </project>
13  drools-mas-generic-client/src/main/java/org/drools/mas/helpers/SyncDialogueHelper.java
@@ -234,16 +234,23 @@ public String invokeDisconfirm( String sender, String receiver, Object propositi
234 234
             long waitTime = minWaitTime;
235 235
             do {
236 236
                 try {
237  
-                    logger.debug( " >>> Waiting for answers (" + waitTime + ") for: Message ->  " + msgRef );
  237
+                    logger.debug( " >>> [" + msgid + "] Waiting for " + numExpectedMessages + " answers (" + waitTime + ") for: Message ->  " + msgRef + " , now I have " + answers.size() );
  238
+                    logger.debug( answers.toString() );
238 239
                     Thread.sleep( waitTime );
239 240
                 } catch ( InterruptedException ex ) {
240 241
                     logger.error( ex.getMessage() );
241 242
                 }
242  
-                List<ACLMessage> incomingAnswers = asyncServicePort.getResponses(msgid);
  243
+                logger.debug( " >>> [" + msgid + "] Wake up with " + answers );
  244
+                List<ACLMessage> incomingAnswers = asyncServicePort.getResponses( msgid );
  245
+                logger.debug( " >>> [" + msgid + "] Incoming new " + incomingAnswers );
243 246
                 answers.addAll( incomingAnswers );
  247
+                logger.debug( " >>> [" + msgid + "] After adding new " + answers );
244 248
 
245 249
                 waitTime *= 2;
246  
-            } while ( answers.size() != numExpectedMessages && waitTime < maxTimeout );
  250
+            } while ( answers.size() < numExpectedMessages && waitTime < maxTimeout );
  251
+            if ( answers.size() < numExpectedMessages ) {
  252
+                logger.equals( " >>> [" + msgid + "] Expecting " + numExpectedMessages + " but got " + answers.size() );
  253
+            }
247 254
             return answers;
248 255
         }
249 256
 
22  drools-mas-util/src/main/java/org/drools/mas/util/helper/ResponseContent.java
@@ -26,19 +26,19 @@
26 26
 
27 27
     private static Logger logger = LoggerFactory.getLogger( ResponseContent.class );
28 28
 
29  
-    public static void deliverResponse( String nodeId, String sessionId, String msgId, Object ret, Fault fault ) {
30  
-        deliverResponse( nodeId, sessionId, msgId, ret, fault, false );
31  
-    }
  29
+//    public static void deliverResponse( String nodeId, String sessionId, String msgId, Object ret, Fault fault ) {
  30
+//        deliverResponse( nodeId, sessionId, msgId, ret, fault, false );
  31
+//    }
32 32
 
33 33
     public static void deliverResponse( Grid grid, String nodeId, String sessionId, String msgId, Object ret, Fault fault ) {
34  
-            deliverResponse( grid, nodeId, sessionId, msgId, ret, fault, false );
35  
-        }
36  
-
37  
-    public static void deliverResponse( String nodeId, String sessionId, String msgId, Object ret, Fault fault, boolean needEncoding ) {
38  
-        Grid grid = GridHelper.createGrid();
39  
-        deliverResponse( grid, nodeId, sessionId, msgId, ret, fault, needEncoding );
  34
+        deliverResponse( grid, nodeId, sessionId, msgId, ret, fault, false );
40 35
     }
41  
-    
  36
+
  37
+//    public static void deliverResponse( String nodeId, String sessionId, String msgId, Object ret, Fault fault, boolean needEncoding ) {
  38
+//        Grid grid = GridHelper.getInstance().createGrid();
  39
+//        deliverResponse( grid, nodeId, sessionId, msgId, ret, fault, needEncoding );
  40
+//    }
  41
+
42 42
     public static void deliverResponse( Grid grid, String nodeId, String sessionId, String msgId, Object ret, Fault fault, boolean needEncoding ) {
43 43
         try {
44 44
             if ( logger.isDebugEnabled() ) {
@@ -67,7 +67,7 @@ public static void deliverResponse( Grid grid, String nodeId, String sessionId,
67 67
                 logger.debug( "(" + Thread.currentThread().getId() + ")" + Thread.currentThread().getName() + "Content helper fault is expected to be null " + fault );
68 68
             }
69 69
 
70  
-            StatefulKnowledgeSession kSession = GridHelper.getStatefulKnowledgeSession( grid, nodeId, sessionId, true );
  70
+            StatefulKnowledgeSession kSession = GridHelper.getInstance().getStatefulKnowledgeSession( grid, nodeId, sessionId, true );
71 71
 
72 72
             if ( logger.isDebugEnabled() ) {
73 73
                 logger.debug( "(" + Thread.currentThread().getId() + ")"+Thread.currentThread().getName() +"Content helper ksession found!"  );
8  examples/drools-mas-emergency-agent-client/pom.xml
@@ -161,6 +161,14 @@
161 161
         </configuration>
162 162
       </plugin>
163 163
 
  164
+      <plugin>
  165
+        <groupId>org.apache.maven.plugins</groupId>
  166
+        <artifactId>maven-compiler-plugin</artifactId>
  167
+        <configuration>
  168
+          <source>1.5</source>
  169
+          <target>1.5</target>
  170
+        </configuration>
  171
+      </plugin>
164 172
 
165 173
     </plugins>
166 174
   </build>
5  ...ples/drools-mas-emergency-agent-client/src/test/java/org/drools/mas/EmergencyAgentServiceRemoteTest.java
@@ -58,15 +58,12 @@ public void tearDown() {
58 58
 
59 59
     @Test
60 60
     public void testSimpleInformWithHelper() {
61  
-        DialogueHelper agentHelper = new DialogueHelper( endpoint );
  61
+        SyncDialogueHelper agentHelper = new SyncDialogueHelper( endpoint );
62 62
 
63 63
         MockFact fact = new MockFact( "patient1", 18 );
64 64
 
65 65
         String iid = agentHelper.invokeInform( "me", "you", fact );
66 66
 
67  
-        List<ACLMessage> result = agentHelper.getAgentAnswers( iid );
68  
-        
69  
-        assertEquals( 0, result.size() );
70 67
     }
71 68
 
72 69
     @Test
13  examples/drools-mas-emergency-agent-model/pom.xml
@@ -14,6 +14,19 @@
14 14
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15 15
   </properties>
16 16
 
  17
+  <build>
  18
+    <plugins>
  19
+      <plugin>
  20
+        <groupId>org.apache.maven.plugins</groupId>
  21
+        <artifactId>maven-compiler-plugin</artifactId>
  22
+        <configuration>
  23
+          <source>1.5</source>
  24
+          <target>1.5</target>
  25
+        </configuration>
  26
+      </plugin>
  27
+    </plugins>
  28
+  </build>
  29
+
17 30
   <dependencies>
18 31
     <dependency>
19 32
       <groupId>junit</groupId>
2  examples/drools-mas-emergency-agent/src/main/resources/knowledge/agent-brain_hello-module.drl
@@ -44,7 +44,7 @@ when
44 44
     coordinateEmergency( $return; )
45 45
 then
46 46
     retract( $action );
47  
-    ResponseContent.deliverResponse( $nodeId, $sessionId, $msgId, $return, null );
  47
+    ResponseContent.deliverResponse( grid, $nodeId, $sessionId, $msgId, $return, null );
48 48
 end
49 49
 
50 50
 
13  pom.xml
@@ -166,4 +166,17 @@
166 166
     </dependencies>
167 167
   </dependencyManagement>
168 168
 
  169
+  <build>
  170
+    <plugins>
  171
+      <plugin>
  172
+        <groupId>org.apache.maven.plugins</groupId>
  173
+        <artifactId>maven-compiler-plugin</artifactId>
  174
+        <configuration>
  175
+          <source>1.5</source>
  176
+          <target>1.5</target>
  177
+        </configuration>
  178
+      </plugin>
  179
+    </plugins>
  180
+  </build>
  181
+
169 182
 </project>

0 notes on commit 3eb5bbb

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