[jboss-svn-commits] JBL Code SVN: r34104 - in labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid: drools-grid-local/src/main/java/org/drools/grid/local and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jul 21 13:43:45 EDT 2010
Author: salaboy21
Date: 2010-07-21 13:43:44 -0400 (Wed, 21 Jul 2010)
New Revision: 34104
Modified:
labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-api/src/main/java/org/drools/grid/DirectoryNodeLocalImpl.java
labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-api/src/main/java/org/drools/grid/GenericConnectorFactory.java
labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-api/src/main/java/org/drools/grid/GridConnection.java
labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-local/src/main/java/org/drools/grid/local/KnowledgeBaseProviderLocalClient.java
labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-remote-api/src/main/java/org/drools/grid/remote/KnowledgeBaseProviderRemoteClient.java
Log:
adding support creating kbases using kbaseconfiguration
Modified: labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-api/src/main/java/org/drools/grid/DirectoryNodeLocalImpl.java
===================================================================
--- labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-api/src/main/java/org/drools/grid/DirectoryNodeLocalImpl.java 2010-07-21 17:26:01 UTC (rev 34103)
+++ labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-api/src/main/java/org/drools/grid/DirectoryNodeLocalImpl.java 2010-07-21 17:43:44 UTC (rev 34104)
@@ -33,58 +33,54 @@
*/
public class DirectoryNodeLocalImpl implements DirectoryNodeService {
-
private Map<String, String> executorsMap = new HashMap<String, String>();
private Map<String, String> kbasesMap = new HashMap<String, String>();
private Map<String, KnowledgeBase> kbasesInstancesMap = new HashMap<String, KnowledgeBase>();
-
-
+
public DirectoryNodeLocalImpl() {
-
}
public String getId() throws ConnectorException {
- return "Local:Directory:";
+ return "Local:Directory:";
}
public void register(String executorId, String resourceId) throws ConnectorException, RemoteException {
- System.out.println("Registering: " + executorId + " -- " + resourceId);
executorsMap.put(executorId, resourceId);
}
- public void register(String executorId, GenericNodeConnector resourceConnector) throws ConnectorException, RemoteException {
- System.out.println("Registering: " + executorId + " -- " + resourceConnector.getId());
+ public void register(String executorId, GenericNodeConnector resourceConnector) throws ConnectorException, RemoteException {
+
executorsMap.put(executorId, resourceConnector.getId());
-
+
}
public GenericNodeConnector lookup(String executorId) throws ConnectorException, RemoteException {
String nodeConnectorId = (String) executorsMap.get(executorId);
- System.out.println("NodeConnectorID = "+nodeConnectorId);
+
return GenericConnectorFactory.newNodeConnector(nodeConnectorId);
}
+
public void registerKBase(String kbaseId, KnowledgeBase kbase) throws ConnectorException, RemoteException {
this.kbasesMap.put(kbaseId, "local");
this.kbasesInstancesMap.put(kbaseId, kbase);
}
+
public void registerKBase(String kbaseId, String resourceId) throws ConnectorException, RemoteException {
this.kbasesMap.put(kbaseId, resourceId);
}
public KnowledgeBase lookupKBase(String kbaseId) throws ConnectorException, RemoteException {
String resourceId = this.kbasesMap.get(kbaseId); //based on the id I should create a kbase client
- System.out.println(">>>>>>>>Resource ID where the kbase is located: "+resourceId);
- if(resourceId.equals("local")){
+ if (resourceId.equals("local")) {
return this.kbasesInstancesMap.get(kbaseId);
}
return KnowledgeBaseClientFactory.newKnowledgeBaseClient(resourceId);
-
+
}
-
public Map<String, String> getExecutorsMap() throws ConnectorException, RemoteException {
return this.executorsMap;
}
@@ -113,9 +109,7 @@
throw new UnsupportedOperationException("Not supported yet.");
}
-
-
- public ConnectorType getConnectorType() {
+ public ConnectorType getConnectorType() {
return ConnectorType.LOCAL;
}
@@ -125,7 +119,7 @@
public Map<String, String> getKBasesMap() throws ConnectorException, RemoteException {
return kbasesMap;
- }
+ }
public void unregisterKBase(String kbaseId) throws ConnectorException, RemoteException {
throw new UnsupportedOperationException("Not supported yet.");
@@ -150,7 +144,4 @@
public AtomicInteger getCounter() {
throw new UnsupportedOperationException("Not supported yet.");
}
-
-
-
}
Modified: labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-api/src/main/java/org/drools/grid/GenericConnectorFactory.java
===================================================================
--- labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-api/src/main/java/org/drools/grid/GenericConnectorFactory.java 2010-07-21 17:26:01 UTC (rev 34103)
+++ labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-api/src/main/java/org/drools/grid/GenericConnectorFactory.java 2010-07-21 17:43:44 UTC (rev 34104)
@@ -31,7 +31,7 @@
public class GenericConnectorFactory {
public static GenericNodeConnector newNodeConnector(String connectorString) {
- System.out.println("Creating a connector for: " + connectorString);
+
if(connectorString == null || connectorString.equals("")){
return null;
}
Modified: labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-api/src/main/java/org/drools/grid/GridConnection.java
===================================================================
--- labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-api/src/main/java/org/drools/grid/GridConnection.java 2010-07-21 17:26:01 UTC (rev 34103)
+++ labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-api/src/main/java/org/drools/grid/GridConnection.java 2010-07-21 17:43:44 UTC (rev 34104)
@@ -70,16 +70,16 @@
} else {
connector = getBestNode(strategy);
}
- System.out.println(">>>>>>>> Connector = " + connector);
+
NodeConnectionType type;
try {
type = connector.getNodeConnectionType();
- System.out.println(">>>>>>>> Type = " + type);
+
connector.connect();
type.setConnector(connector);
type.setConnection(this);
-
+
node = NodeFactory.newExecutionNode(type);
} catch (RemoteException ex) {
Logger.getLogger(GridConnection.class.getName()).log(Level.SEVERE, null, ex);
@@ -106,26 +106,25 @@
// }
GenericNodeConnector connector = null;
//if the strategy is null use the default one
-
+
if (strategy == null) {
connector = getBestDirectory(new StaticIncrementalDirectorySelectionStrategy());
} else {
connector = getBestDirectory(strategy);
}
-// connector.connect();
-// directoryNode = connector.getDirectoryNodeService();
- System.out.println(">>>>>>>> Connector = " + connector);
+
+
NodeConnectionType type;
DirectoryNode directoryNode = null;
try {
type = connector.getNodeConnectionType();
- System.out.println(">>>>>>>> Type = " + type);
+
connector.connect();
type.setConnector(connector);
type.setConnection(this);
-
+
directoryNode = NodeFactory.newDirectoryNode(type);
} catch (RemoteException ex) {
Logger.getLogger(GridConnection.class.getName()).log(Level.SEVERE, null, ex);
@@ -168,7 +167,7 @@
NodeConnectionType type;
try {
type = connector.getNodeConnectionType();
- System.out.println(">>>>>>>> Type = " + type);
+
connector.connect();
type.setConnector(connector);
@@ -182,12 +181,12 @@
}
public List<DirectoryNode> getDirectoryNodes() throws ConnectorException {
- List<DirectoryNode> directoryNodes = new ArrayList<DirectoryNode>();
+ List<DirectoryNode> directoryNodes = new ArrayList<DirectoryNode>();
for (GenericNodeConnector connector : directoryNodeConnectors) {
NodeConnectionType type;
try {
type = connector.getNodeConnectionType();
- System.out.println(">>>>>>>> Type = " + type);
+
connector.connect();
type.setConnector(connector);
type.setConnection(this);
@@ -197,7 +196,7 @@
}
}
return directoryNodes;
-
+
}
public List<HumanTaskNodeService> getHumanTaskNodes() {
Modified: labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-local/src/main/java/org/drools/grid/local/KnowledgeBaseProviderLocalClient.java
===================================================================
--- labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-local/src/main/java/org/drools/grid/local/KnowledgeBaseProviderLocalClient.java 2010-07-21 17:26:01 UTC (rev 34103)
+++ labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-local/src/main/java/org/drools/grid/local/KnowledgeBaseProviderLocalClient.java 2010-07-21 17:43:44 UTC (rev 34104)
@@ -58,27 +58,30 @@
public KnowledgeBase newKnowledgeBase(String kbaseId) {
KnowledgeBase kbase = decoratee.newKnowledgeBase(kbaseId);
- try{
+ registerKbaseInDirectories(kbaseId, kbase);
+ return kbase;
+ }
+
+ private void registerKbaseInDirectories(String kbaseId, KnowledgeBase kbase) throws IllegalStateException {
+ try {
ConnectorType connectorType = nodeConnector.getConnectorType();
-
DirectoryNodeService directory = nodeConnector.getConnection().getDirectoryNode().get(DirectoryNodeService.class);
- if(connectorType == ConnectorType.LOCAL){
+ if (connectorType == ConnectorType.LOCAL) {
directory.registerKBase(kbaseId, kbase);
- }
- else{
+ } else {
directory.registerKBase(kbaseId, nodeConnector.getId());
}
directory.dispose();
- } catch (Exception e){
+ } catch (Exception e) {
throw new IllegalStateException("Unable to register kbase " + kbaseId + " in directory", e);
}
- return kbase;
}
public KnowledgeBase newKnowledgeBase(String kbaseId,
KnowledgeBaseConfiguration conf) {
- // TODO Auto-generated method stub
- return null;
+ KnowledgeBase kbase = decoratee.newKnowledgeBase(kbaseId,conf);
+ registerKbaseInDirectories(kbaseId, kbase);
+ return kbase;
}
}
Modified: labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-remote-api/src/main/java/org/drools/grid/remote/KnowledgeBaseProviderRemoteClient.java
===================================================================
--- labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-remote-api/src/main/java/org/drools/grid/remote/KnowledgeBaseProviderRemoteClient.java 2010-07-21 17:26:01 UTC (rev 34103)
+++ labs/jbossrules/branches/salaboy_drools_grid_api_separation/drools-grid/drools-grid-remote-api/src/main/java/org/drools/grid/remote/KnowledgeBaseProviderRemoteClient.java 2010-07-21 17:43:44 UTC (rev 34104)
@@ -90,6 +90,7 @@
}
public KnowledgeBase newKnowledgeBase(String kbaseId) {
+ //TODO: I need to replace this random id with the kbase ID and test it
String localId = UUID.randomUUID().toString();
Message msg = new Message( messageSession.getSessionId(),
@@ -98,17 +99,50 @@
new SetVariableCommand( "__TEMP__",
localId,
new NewKnowledgeBaseCommand( null ) ) );
+ registerKBaseInDirectories(kbaseId);
+
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 );
+ }
+
+ return new KnowledgeBaseRemoteClient( localId,
+ client, messageSession );
+
+ }
+
+ private void registerKBaseInDirectories(String kbaseId) {
+ try {
DirectoryNodeService directory = client.getConnection().getDirectoryNode().get(DirectoryNodeService.class);
-
directory.registerKBase(kbaseId, client.getId());
directory.dispose();
-
} catch (RemoteException ex) {
Logger.getLogger(KnowledgeBaseProviderRemoteClient.class.getName()).log(Level.SEVERE, null, ex);
} catch (ConnectorException ex) {
Logger.getLogger(KnowledgeBaseProviderRemoteClient.class.getName()).log(Level.SEVERE, null, ex);
}
+ }
+
+ public KnowledgeBase newKnowledgeBase(String kbaseId,
+ KnowledgeBaseConfiguration conf) {
+ //TODO: I need to replace this random id with the kbase ID and test it
+ String localId = UUID.randomUUID().toString();
+
+ Message msg = new Message( messageSession.getSessionId(),
+ messageSession.counter.incrementAndGet(),
+ false,
+ new SetVariableCommand( "__TEMP__",
+ localId,
+ new NewKnowledgeBaseCommand( conf ) ) );
+ registerKBaseInDirectories(kbaseId);
+
try {
Object object = client.write( msg ).getPayload();
@@ -123,13 +157,6 @@
return new KnowledgeBaseRemoteClient( localId,
client, messageSession );
-
}
- public KnowledgeBase newKnowledgeBase(String kbaseId,
- KnowledgeBaseConfiguration conf) {
- // TODO Auto-generated method stub
- return null;
- }
-
}
More information about the jboss-svn-commits
mailing list