summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/entity/agent
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/c2kernel/entity/agent')
-rw-r--r--src/main/java/com/c2kernel/entity/agent/ActiveEntity.java263
-rw-r--r--src/main/java/com/c2kernel/entity/agent/Job.java103
2 files changed, 135 insertions, 231 deletions
diff --git a/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java b/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java
index 8d4dbfd..a799b62 100644
--- a/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java
+++ b/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java
@@ -10,24 +10,15 @@
package com.c2kernel.entity.agent;
-import java.util.Iterator;
-
import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.CannotManageException;
import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.InvalidTransitionException;
+import com.c2kernel.common.ObjectAlreadyExistsException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.common.PersistencyException;
+import com.c2kernel.entity.AgentImplementation;
import com.c2kernel.entity.AgentPOA;
-import com.c2kernel.entity.C2KLocalObject;
-import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.InvalidEntityPathException;
-import com.c2kernel.lookup.RolePath;
-import com.c2kernel.persistency.ClusterStorageException;
-import com.c2kernel.persistency.TransactionManager;
-import com.c2kernel.process.Gateway;
-import com.c2kernel.property.Property;
-import com.c2kernel.property.PropertyArrayList;
import com.c2kernel.utils.Logger;
/**************************************************************************
@@ -39,111 +30,17 @@ import com.c2kernel.utils.Logger;
public class ActiveEntity extends AgentPOA
{
- /**************************************************************************
- * The CORBA Portable Object Adapter which holds the Agent
- **************************************************************************/
- private org.omg.PortableServer.POA mPOA = null;
-
- /**************************************************************************
- * The C2Kernel system key of the Agent
- **************************************************************************/
- private int mSystemKey = -1;
-
- /**************************************************************************
- * Connection to the persistency backeng
- **************************************************************************/
- private TransactionManager mDatabase = null;
-
- /**************************************************************************
- * The agent's joblist
- **************************************************************************/
- private JobList currentJobs;
- /**
- *
- * @param key
- * @param poa
- */
+ private final org.omg.PortableServer.POA mPoa;
+ private final AgentImplementation mAgentImpl;
+
public ActiveEntity( int key,
org.omg.PortableServer.POA poa )
{
Logger.msg(5, "ActiveEntity::constructor() - SystemKey:" + key );
-
- mSystemKey = key;
- mPOA = poa;
- mDatabase = Gateway.getStorage();
-
- Logger.msg(5, "ActiveEntity::constructor - completed.");
+ mPoa = poa;
+ mAgentImpl = new AgentImplementation(key);
}
- /**
- * initialise cristal2 properties & collector
- */
- @Override
- public void initialise( String agentProps )
- throws AccessRightsException,
- InvalidDataException,
- PersistencyException
- {
- PropertyArrayList props = null;
- Logger.msg(1, "ActiveEntity::initialise("+mSystemKey+")");
- //initialise cristal2 properties & collector
- try
- {
- props = initProps( agentProps );
- mDatabase.commit( props );
- }
- catch( ClusterStorageException ex )
- {
- Logger.error("ActiveEntity::init() - Failed to init props/collector, aborting!");
- Logger.error(ex);
-
- mDatabase.abort( props );
- throw new PersistencyException("Failed to init props => transaction aborted!");
- }
-
- Logger.msg(5, "ActiveEntity::init() - completed.");
- }
-
- /**
- *
- * @param propsString
- * @return Properties
- * @throws InvalidDataException Properties cannot be unmarshalled
- * @throws ClusterStorageException
- */
- private PropertyArrayList initProps( String propsString )
- throws InvalidDataException,
- ClusterStorageException
- {
- PropertyArrayList props = null;
-
- // create properties
- if( propsString != null && !propsString.equals("") )
- {
- try
- {
- props = (PropertyArrayList)Gateway.getMarshaller().unmarshall(propsString);
- }
- catch( Exception ex )
- {
- //any exception during unmarshall indicates that data was
- //incorrect or the castor mapping was not set up
- Logger.error(ex);
- throw new InvalidDataException(ex.toString(), null);
- }
-
- Iterator<Property> iter = props.list.iterator();
-
- while( iter.hasNext() )
- mDatabase.put( mSystemKey, iter.next(), props );
- }
- else
- {
- Logger.warning("ActiveEntity::initProps() - NO Properties!");
- }
-
- return props;
- }
/**************************************************************************
*
@@ -152,8 +49,8 @@ public class ActiveEntity extends AgentPOA
@Override
public org.omg.PortableServer.POA _default_POA()
{
- if(mPOA != null)
- return mPOA;
+ if(mPoa != null)
+ return mPoa;
else
return super._default_POA();
}
@@ -166,7 +63,7 @@ public class ActiveEntity extends AgentPOA
@Override
public int getSystemKey()
{
- return mSystemKey;
+ return mAgentImpl.getSystemKey();
}
@@ -175,55 +72,14 @@ public class ActiveEntity extends AgentPOA
*
**************************************************************************/
@Override
- public String queryData(String xpath)
+ public String queryData(String path)
throws AccessRightsException,
ObjectNotFoundException,
PersistencyException
{
- String result = "";
- int allPos = -1;
-
- Logger.msg(1, "ActiveEntity::queryData("+mSystemKey+") - " + xpath );
-
- try
- {
- if( (allPos=xpath.indexOf("all")) != -1 )
- {
- String query = xpath.substring(0,allPos);
- String[] ids = mDatabase.getClusterContents( mSystemKey, query );
-
- for( int i=0; i<ids.length; i++ )
- {
-
- result += ids[i];
-
- if( i != ids.length-1 )
- result += ",";
- }
- }
- //****************************************************************
- else
- {
- C2KLocalObject obj = mDatabase.get( mSystemKey, xpath, null );
-
- result = Gateway.getMarshaller().marshall(obj);
- }
-
- }
- catch (ObjectNotFoundException ex) {
- throw ex;
- }
- catch(Throwable ex)
- {
- Logger.error("ActiveEntity::queryData("+mSystemKey+") - " +
- xpath + " FAILED");
- Logger.error(ex);
- result = "<ERROR/>";
- }
-
- Logger.msg(7, "ActiveEntity::queryData("+mSystemKey+") - result:" + result );
-
- return result;
+ synchronized (this) {
+ return mAgentImpl.queryData(path);
+ }
}
@@ -233,62 +89,55 @@ public class ActiveEntity extends AgentPOA
*/
@Override
- public synchronized void refreshJobList(int sysKey, String stepPath, String newJobs) {
- try {
- JobArrayList newJobList = (JobArrayList)Gateway.getMarshaller().unmarshall(newJobs);
-
- // get our joblist
- if (currentJobs == null)
- currentJobs = new JobList( mSystemKey, null);
-
- // remove old jobs for this item
- currentJobs.removeJobsForStep( sysKey, stepPath );
-
- // merge new jobs in
- for (Object name : newJobList.list) {
- Job newJob = (Job)name;
- Logger.msg(6, "Adding job for "+newJob.getItemSysKey()+"/"+newJob.getStepPath()+":"+newJob.getTransition().getId());
- currentJobs.addJob(newJob);
- }
-
- } catch (Throwable ex) {
- Logger.error("Could not refresh job list.");
- Logger.error(ex);
- }
-
+ public void refreshJobList(int sysKey, String stepPath, String newJobs) {
+ synchronized (this) {
+ mAgentImpl.refreshJobList(sysKey, stepPath, newJobs);
+ }
}
@Override
public void addRole(String roleName) throws CannotManageException, ObjectNotFoundException {
- RolePath newRole = Gateway.getLDAPLookup().getRoleManager().getRolePath(roleName);
- try {
- newRole.addAgent(new AgentPath(mSystemKey));
- } catch (InvalidEntityPathException ex) {
- throw new CannotManageException("Invalid syskey for agent: "+mSystemKey, "");
- } catch (ObjectCannotBeUpdated ex) {
- throw new CannotManageException("Could not update role");
- }
+ synchronized (this) {
+ mAgentImpl.addRole(roleName);
+ }
}
@Override
public void removeRole(String roleName) throws CannotManageException, ObjectNotFoundException {
- RolePath rolePath = Gateway.getLDAPLookup().getRoleManager().getRolePath(roleName);
- try {
- rolePath.removeAgent(new AgentPath(mSystemKey));
- } catch (InvalidEntityPathException e) {
- throw new CannotManageException("Invalid syskey for agent: "+mSystemKey, "");
- } catch (ObjectCannotBeUpdated ex) {
- throw new CannotManageException("Could not update role");
- }
- }
- /**
- *
- */
- @Override
- protected void finalize() throws Throwable {
- Logger.msg(7, "Agent "+mSystemKey+" reaped");
- Gateway.getStorage().clearCache(mSystemKey, null);
- super.finalize();
+ synchronized (this) {
+ mAgentImpl.removeRole(roleName);
+ }
}
+
+ @Override
+ public void initialise(int agentId, String propString, String initWfString,
+ String initCollsString) throws AccessRightsException,
+ InvalidDataException, PersistencyException, ObjectNotFoundException {
+ synchronized (this) {
+ mAgentImpl.initialise(agentId, propString, initWfString, initCollsString);
+ }
+
+ }
+
+ @Override
+ public String requestAction(int agentID, String stepPath, int transitionID,
+ String requestData) throws AccessRightsException,
+ InvalidTransitionException, ObjectNotFoundException,
+ InvalidDataException, PersistencyException,
+ ObjectAlreadyExistsException {
+
+ synchronized (this) {
+ return mAgentImpl.requestAction(agentID, stepPath, transitionID, requestData);
+ }
+
+ }
+ @Override
+ public String queryLifeCycle(int agentId, boolean filter)
+ throws AccessRightsException, ObjectNotFoundException,
+ PersistencyException {
+ synchronized (this) {
+ return mAgentImpl.queryLifeCycle(agentId, filter);
+ }
+ }
}
diff --git a/src/main/java/com/c2kernel/entity/agent/Job.java b/src/main/java/com/c2kernel/entity/agent/Job.java
index 02dd541..cef35ef 100644
--- a/src/main/java/com/c2kernel/entity/agent/Job.java
+++ b/src/main/java/com/c2kernel/entity/agent/Job.java
@@ -1,5 +1,7 @@
package com.c2kernel.entity.agent;
+import java.util.HashMap;
+
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.C2KLocalObject;
@@ -7,10 +9,12 @@ import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.lifecycle.instance.Activity;
import com.c2kernel.lifecycle.instance.stateMachine.Transition;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.EntityPath;
-import com.c2kernel.lookup.InvalidEntityPathException;
+import com.c2kernel.lookup.InvalidItemPathException;
+import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
+import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.persistency.outcome.Outcome;
+import com.c2kernel.persistency.outcome.OutcomeInitiator;
import com.c2kernel.persistency.outcome.Schema;
import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.Gateway;
@@ -63,6 +67,10 @@ public class Job implements C2KLocalObject
private ItemProxy item = null;
private boolean outcomeSet;
+
+ // outcome initiator cache
+
+ static private HashMap<String, OutcomeInitiator> ocInitCache = new HashMap<String, OutcomeInitiator>();
/***************************************************************************
* Empty constructor for Castor
@@ -156,7 +164,7 @@ public class Job implements C2KLocalObject
public int getAgentId() throws ObjectNotFoundException {
if (agentId == -1)
- agentId = Gateway.getLDAPLookup().getRoleManager().getAgentPath(getAgentName()).getSysKey();
+ agentId = Gateway.getLookup().getAgentPath(getAgentName()).getSysKey();
return agentId;
}
@@ -244,9 +252,9 @@ public class Job implements C2KLocalObject
}
}
- public ItemProxy getItemProxy() throws ObjectNotFoundException, InvalidEntityPathException {
+ public ItemProxy getItemProxy() throws ObjectNotFoundException, InvalidItemPathException {
if (item == null)
- item = (ItemProxy) Gateway.getProxyManager().getProxy(new EntityPath(itemSysKey));
+ item = Gateway.getProxyManager().getProxy(new ItemPath(itemSysKey));
return item;
}
@@ -273,26 +281,72 @@ public class Job implements C2KLocalObject
Logger.error(e);
}
}
+
+ public String getLastView() throws InvalidDataException {
+ String viewName = (String) getActProp("Viewpoint");
+ if (viewName.length() > 0) {
+ // find schema
+ String schemaName;
+ try {
+ schemaName = getSchemaName();
+ } catch (ObjectNotFoundException e1) {
+ throw new InvalidDataException("Schema "+getActProp("SchemaType")+" v"+getActProp("SchemaVersion")+" not found");
+ }
+
+ try {
+ Viewpoint view = (Viewpoint) Gateway.getStorage().get(getItemSysKey(),
+ ClusterStorage.VIEWPOINT + "/" + schemaName + "/" + viewName, null);
+ return view.getOutcome().getData();
+ } catch (ObjectNotFoundException ex) { // viewpoint doesn't exist yet
+ return null;
+ } catch (ClusterStorageException e) {
+ Logger.error(e);
+ throw new InvalidDataException("ViewpointOutcomeInitiator: ClusterStorageException loading viewpoint "
+ + ClusterStorage.VIEWPOINT + "/" + schemaName + "/" + viewName+" in syskey "+getItemSysKey());
+ }
+ }
+ else
+ return null;
+ }
+
+ public OutcomeInitiator getOutcomeInitiator() throws InvalidDataException {
+ String ocInitName = (String) getActProp("OutcomeInit");
+ OutcomeInitiator ocInit;
+ if (ocInitName.length() > 0) {
+ String ocPropName = "OutcomeInit."+ocInitName;
+ synchronized (ocInitCache) {
+ ocInit = ocInitCache.get(ocPropName);
+ if (ocInit == null) {
+ Object ocInitObj = Gateway.getProperties().get(ocPropName);
+ if (ocInitObj instanceof String) {
+ try {
+ ocInitObj = Class.forName((String)ocInitObj).newInstance();
+ } catch (Exception e) {
+ Logger.error(e);
+ throw new InvalidDataException("Could not instantiate OutcomeInstantiator "+ocInitObj+" for "+ocPropName);
+ }
+ }
+ ocInit = (OutcomeInitiator)ocInitObj; // throw runtime class cast if it isn't one
+ ocInitCache.put(ocPropName, ocInit);
+ }
+ }
+ return ocInit;
+ }
+ else
+ return null;
+ }
- public String getOutcomeString()
+ public String getOutcomeString() throws InvalidDataException
{
- if (outcomeData == null && isOutcomeRequired())
- {
- String viewName = (String) getActProp("Viewpoint");
- outcomeData = null;
- if (viewName.length() > 0)
- try
- {
- Viewpoint view = (Viewpoint) Gateway.getStorage().get(getItemSysKey(), ClusterStorage.VIEWPOINT + "/" + getSchemaName() + "/" + viewName, null);
- outcomeData = view.getOutcome().getData();
- outcomeSet = true;
- } catch (Exception ex)
- {
- outcomeData = null;
- outcomeSet = false;
- }
-
- }
+ if (outcomeData == null && transition.hasOutcome(actProps)) {
+ outcomeData = getLastView();
+ if (outcomeData == null) {
+ OutcomeInitiator ocInit = getOutcomeInitiator();
+ if (ocInit != null)
+ outcomeData = ocInit.initOutcome(this);
+ }
+ if (outcomeData != null) outcomeSet = true;
+ }
return outcomeData;
}
@@ -335,6 +389,7 @@ public class Job implements C2KLocalObject
public String getActPropString(String name)
{
- return String.valueOf(actProps.get(name));
+ Object obj = getActProp(name);
+ return obj==null?null:String.valueOf(obj);
}
} \ No newline at end of file