From a1f0ecbb6a2bea6aa214322c412af2f3c5ce124b Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 7 May 2014 17:33:13 +0200 Subject: Agent now extends Item, so they can have workflows. All traces of the old 'Entity' superclasses should be removed, including proxies and paths. Very large change, breaks API compatibility with CRISTAL 2.x. Fixes #135 --- .../java/com/c2kernel/entity/TraceableEntity.java | 207 +-------------------- 1 file changed, 10 insertions(+), 197 deletions(-) (limited to 'src/main/java/com/c2kernel/entity/TraceableEntity.java') diff --git a/src/main/java/com/c2kernel/entity/TraceableEntity.java b/src/main/java/com/c2kernel/entity/TraceableEntity.java index b6ccd8c..ffd5859 100644 --- a/src/main/java/com/c2kernel/entity/TraceableEntity.java +++ b/src/main/java/com/c2kernel/entity/TraceableEntity.java @@ -18,17 +18,6 @@ import com.c2kernel.common.InvalidTransitionException; import com.c2kernel.common.ObjectAlreadyExistsException; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.common.PersistencyException; -import com.c2kernel.entity.agent.JobArrayList; -import com.c2kernel.lifecycle.instance.CompositeActivity; -import com.c2kernel.lifecycle.instance.Workflow; -import com.c2kernel.lookup.AgentPath; -import com.c2kernel.lookup.InvalidEntityPathException; -import com.c2kernel.persistency.ClusterStorage; -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; /************************************************************************** @@ -62,10 +51,8 @@ import com.c2kernel.utils.Logger; public class TraceableEntity extends ItemPOA { - private final int mSystemKey; private final org.omg.PortableServer.POA mPoa; - private final TransactionManager mStorage; - + private final ItemImplementation mItemImpl; /************************************************************************** * Constructor used by the Locator only @@ -74,10 +61,8 @@ public class TraceableEntity extends ItemPOA org.omg.PortableServer.POA poa ) { Logger.msg(5,"TraceableEntity::constructor() - SystemKey:" + key ); - - mSystemKey = key; - mPoa = poa; - mStorage = Gateway.getStorage(); + mPoa = poa; + mItemImpl = new ItemImplementation(key); } @@ -100,8 +85,7 @@ public class TraceableEntity extends ItemPOA @Override public int getSystemKey() { - Logger.msg(8, "TraceableEntity::getSystemKey() - " + mSystemKey); - return mSystemKey; + return mItemImpl.getSystemKey(); } /************************************************************************** @@ -110,54 +94,15 @@ public class TraceableEntity extends ItemPOA @Override public void initialise( int agentId, String propString, - String initWfString + String initWfString, + String initCollsString ) throws AccessRightsException, InvalidDataException, PersistencyException { - Logger.msg(5, "TraceableEntity::initialise("+mSystemKey+") - agent:"+agentId); synchronized (this) { - Workflow lc = null; - PropertyArrayList props = null; - - AgentPath agentPath; - try { - agentPath = new AgentPath(agentId); - } catch (InvalidEntityPathException e) { - throw new AccessRightsException("Invalid Agent Id:" + agentId); - } - - //unmarshalling checks the validity of the received strings - - // create properties - if (!propString.equals("")) { - try { - props = (PropertyArrayList)Gateway.getMarshaller().unmarshall(propString); - for (Object name : props.list) { - Property thisProp = (Property)name; - mStorage.put(mSystemKey, thisProp, props); - } - } catch (Throwable ex) { - Logger.msg(8, "TraceableEntity::initialise("+mSystemKey+ ") - Properties were invalid: "+propString); - Logger.error(ex); - mStorage.abort(props); - } - mStorage.commit(props); - } - - // create wf - try { - if (initWfString == null || initWfString.equals("")) - lc = new Workflow(new CompositeActivity()); - else - lc = new Workflow((CompositeActivity)Gateway.getMarshaller().unmarshall(initWfString)); - lc.initialise(mSystemKey, agentPath); - mStorage.put(mSystemKey, lc, null); - } catch (Throwable ex) { - Logger.msg(8, "TraceableEntity::initialise("+mSystemKey+") - Workflow was invalid: "+initWfString); - Logger.error(ex); - } + mItemImpl.initialise(agentId, propString, initWfString, initCollsString); } } @@ -179,55 +124,7 @@ public class TraceableEntity extends ItemPOA ObjectAlreadyExistsException { synchronized (this) { - try { - - Logger.msg(1, "TraceableEntity::request("+mSystemKey+") - " + - transitionID + " "+stepPath + " by " +agentId ); - - AgentPath agent = new AgentPath(agentId); - Workflow lifeCycle = (Workflow)mStorage.get(mSystemKey, ClusterStorage.LIFECYCLE+"/workflow", null); - - lifeCycle.requestAction( agent, - stepPath, - mSystemKey, - transitionID, - requestData ); - - // store the workflow if we've changed the state of the domain wf - if (!(stepPath.startsWith("workflow/predefined"))) - mStorage.put(mSystemKey, lifeCycle, null); - - // Normal operation exceptions - } catch (AccessRightsException ex) { - Logger.msg("Propagating AccessRightsException back to the calling agent"); - throw ex; - } catch (InvalidTransitionException ex) { - Logger.msg("Propagating InvalidTransitionException back to the calling agent"); - throw ex; - } catch (ObjectNotFoundException ex) { - Logger.msg("Propagating ObjectNotFoundException back to the calling agent"); - throw ex; - // errors - } catch (ClusterStorageException ex) { - Logger.error(ex); - throw new PersistencyException("Error on storage: "+ex.getMessage(), ""); - } catch (InvalidEntityPathException ex) { - Logger.error(ex); - throw new AccessRightsException("Invalid Agent Id: "+agentId, ""); - } catch (InvalidDataException ex) { - Logger.error(ex); - Logger.msg("Propagating InvalidDataException back to the calling agent"); - throw ex; - } catch (ObjectAlreadyExistsException ex) { - Logger.error(ex); - Logger.msg("Propagating ObjectAlreadyExistsException back to the calling agent"); - throw ex; - // non-CORBA exception hasn't been caught! - } catch (Throwable ex) { - Logger.error("Unknown Error: requestAction on "+mSystemKey+" by "+agentId+" executing "+stepPath); - Logger.error(ex); - throw new InvalidDataException("Extraordinary Exception during execution:"+ex.getClass().getName()+" - "+ex.getMessage(), ""); - } + mItemImpl.requestAction(agentId, stepPath, transitionID, requestData); } } @@ -243,38 +140,7 @@ public class TraceableEntity extends ItemPOA PersistencyException { synchronized (this) { - Logger.msg(1, "TraceableEntity::queryLifeCycle("+mSystemKey+") - agent: " + agentId); - try { - AgentPath agent; - try { - agent = new AgentPath(agentId); - } catch (InvalidEntityPathException e) { - throw new AccessRightsException("Agent "+agentId+" doesn't exist"); - } - Workflow wf; - try { - wf = (Workflow)mStorage.get(mSystemKey, ClusterStorage.LIFECYCLE+"/workflow", null); - } catch (ClusterStorageException e) { - Logger.error("TraceableEntity::queryLifeCycle("+mSystemKey+") - Error loading workflow"); - Logger.error(e); - throw new PersistencyException("Error loading workflow"); - } - JobArrayList jobBag = new JobArrayList(); - CompositeActivity domainWf = (CompositeActivity)wf.search("workflow/domain"); - jobBag.list = filter?domainWf.calculateJobs(agent, mSystemKey, true):domainWf.calculateAllJobs(agent, mSystemKey, true); - Logger.msg(1, "TraceableEntity::queryLifeCycle("+mSystemKey+") - Returning "+jobBag.list.size()+" jobs."); - try { - return Gateway.getMarshaller().marshall( jobBag ); - } catch (Exception e) { - Logger.error(e); - throw new PersistencyException("Error marshalling job bag"); - } - } - catch ( Throwable ex ) { - Logger.error("TraceableEntity::queryLifeCycle("+mSystemKey+") - Unknown error"); - Logger.error(ex); - throw new PersistencyException("Unknown error querying jobs. Please see server log."); - } + return mItemImpl.queryLifeCycle(agentId, filter); } } @@ -296,60 +162,7 @@ public class TraceableEntity extends ItemPOA PersistencyException { synchronized (this) { - String result = ""; - - Logger.msg(1, "TraceableEntity::queryData("+mSystemKey+") - " + path ); - - try - { // check for cluster contents query - - if (path.endsWith("/all")) - { - int allPos = path.lastIndexOf("all"); - String query = path.substring(0,allPos); - String[] ids = mStorage.getClusterContents( mSystemKey, query ); - - for( int i=0; i