summaryrefslogtreecommitdiff
path: root/src/main/java/org/cristalise/kernel/entity/agent
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/cristalise/kernel/entity/agent')
-rw-r--r--src/main/java/org/cristalise/kernel/entity/agent/ActiveEntity.java156
-rw-r--r--src/main/java/org/cristalise/kernel/entity/agent/ActiveLocator.java100
-rw-r--r--src/main/java/org/cristalise/kernel/entity/agent/AgentImplementation.java137
-rw-r--r--src/main/java/org/cristalise/kernel/entity/agent/Job.java484
-rw-r--r--src/main/java/org/cristalise/kernel/entity/agent/JobArrayList.java42
-rw-r--r--src/main/java/org/cristalise/kernel/entity/agent/JobList.java138
-rw-r--r--src/main/java/org/cristalise/kernel/entity/agent/package-info.java32
7 files changed, 1089 insertions, 0 deletions
diff --git a/src/main/java/org/cristalise/kernel/entity/agent/ActiveEntity.java b/src/main/java/org/cristalise/kernel/entity/agent/ActiveEntity.java
new file mode 100644
index 0000000..46d60ac
--- /dev/null
+++ b/src/main/java/org/cristalise/kernel/entity/agent/ActiveEntity.java
@@ -0,0 +1,156 @@
+/**
+ * This file is part of the CRISTAL-iSE kernel.
+ * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * http://www.fsf.org/licensing/licenses/lgpl.html
+ */
+package org.cristalise.kernel.entity.agent;
+
+import org.cristalise.kernel.common.AccessRightsException;
+import org.cristalise.kernel.common.CannotManageException;
+import org.cristalise.kernel.common.InvalidCollectionModification;
+import org.cristalise.kernel.common.InvalidDataException;
+import org.cristalise.kernel.common.InvalidTransitionException;
+import org.cristalise.kernel.common.ObjectAlreadyExistsException;
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.common.PersistencyException;
+import org.cristalise.kernel.common.SystemKey;
+import org.cristalise.kernel.entity.AgentPOA;
+import org.cristalise.kernel.lookup.AgentPath;
+import org.cristalise.kernel.utils.Logger;
+
+
+/**************************************************************************
+ * ActiveEntity - the CORBA object representing the Agent. All functionality
+ * is delegated to the AgentImplementation, which extends ItemImplementation,
+ * as this cannot extend its equivalent TraceableEntity
+ *
+ **************************************************************************/
+public class ActiveEntity extends AgentPOA
+{
+
+ private final org.omg.PortableServer.POA mPoa;
+ private final AgentImplementation mAgentImpl;
+
+ public ActiveEntity( AgentPath key,
+ org.omg.PortableServer.POA poa )
+ {
+ Logger.msg(5, "ActiveEntity::constructor() - SystemKey:" + key );
+ mPoa = poa;
+ mAgentImpl = new AgentImplementation(key);
+ }
+
+
+ /**************************************************************************
+ *
+ *
+ **************************************************************************/
+ @Override
+ public org.omg.PortableServer.POA _default_POA()
+ {
+ if(mPoa != null)
+ return mPoa;
+ else
+ return super._default_POA();
+ }
+
+
+ /**************************************************************************
+ *
+ *
+ **************************************************************************/
+ @Override
+ public SystemKey getSystemKey()
+ {
+ return mAgentImpl.getSystemKey();
+ }
+
+
+ /**************************************************************************
+ *
+ *
+ **************************************************************************/
+ @Override
+ public String queryData(String path)
+ throws AccessRightsException,
+ ObjectNotFoundException,
+ PersistencyException
+ {
+ synchronized (this) {
+ return mAgentImpl.queryData(path);
+ }
+ }
+
+
+
+ /**
+ * Called by an activity when it reckons we need to update our joblist for it
+ */
+
+ @Override
+ public void refreshJobList(SystemKey sysKey, String stepPath, String newJobs) {
+ synchronized (this) {
+ mAgentImpl.refreshJobList(sysKey, stepPath, newJobs);
+ }
+ }
+
+ @Override
+ public void addRole(String roleName) throws CannotManageException, ObjectNotFoundException {
+ synchronized (this) {
+ mAgentImpl.addRole(roleName);
+ }
+ }
+
+ @Override
+ public void removeRole(String roleName) throws CannotManageException, ObjectNotFoundException {
+ synchronized (this) {
+ mAgentImpl.removeRole(roleName);
+ }
+ }
+
+ @Override
+ public void initialise(SystemKey agentId, String propString, String initWfString,
+ String initCollsString) throws AccessRightsException,
+ InvalidDataException, PersistencyException, ObjectNotFoundException {
+ synchronized (this) {
+ mAgentImpl.initialise(agentId, propString, initWfString, initCollsString);
+ }
+
+ }
+
+ @Override
+ public String requestAction(SystemKey agentID, String stepPath, int transitionID,
+ String requestData) throws AccessRightsException,
+ InvalidTransitionException, ObjectNotFoundException,
+ InvalidDataException, PersistencyException,
+ ObjectAlreadyExistsException, InvalidCollectionModification {
+
+ synchronized (this) {
+ return mAgentImpl.requestAction(agentID, stepPath, transitionID, requestData);
+ }
+
+ }
+
+ @Override
+ public String queryLifeCycle(SystemKey agentId, boolean filter)
+ throws AccessRightsException, ObjectNotFoundException,
+ PersistencyException {
+ synchronized (this) {
+ return mAgentImpl.queryLifeCycle(agentId, filter);
+ }
+ }
+}
diff --git a/src/main/java/org/cristalise/kernel/entity/agent/ActiveLocator.java b/src/main/java/org/cristalise/kernel/entity/agent/ActiveLocator.java
new file mode 100644
index 0000000..1a55c99
--- /dev/null
+++ b/src/main/java/org/cristalise/kernel/entity/agent/ActiveLocator.java
@@ -0,0 +1,100 @@
+/**
+ * This file is part of the CRISTAL-iSE kernel.
+ * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * http://www.fsf.org/licensing/licenses/lgpl.html
+ */
+package org.cristalise.kernel.entity.agent;
+
+
+import java.nio.ByteBuffer;
+import java.sql.Timestamp;
+
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.common.SystemKey;
+import org.cristalise.kernel.lookup.AgentPath;
+import org.cristalise.kernel.lookup.InvalidItemPathException;
+import org.cristalise.kernel.process.Gateway;
+import org.cristalise.kernel.utils.Logger;
+
+
+
+/**************************************************************************
+ *
+ * @author $Author: abranson $ $Date: 2005/10/05 07:39:36 $
+ * @version $Revision: 1.9 $
+ **************************************************************************/
+public class ActiveLocator extends org.omg.PortableServer.ServantLocatorPOA
+{
+
+ /**************************************************************************
+ *
+ **************************************************************************/
+ public ActiveLocator()
+ {
+ }
+
+
+ /**************************************************************************
+ *
+ **************************************************************************/
+ @Override
+ public org.omg.PortableServer.Servant preinvoke(
+ byte[] oid,
+ org.omg.PortableServer.POA poa,
+ String operation,
+ org.omg.PortableServer.ServantLocatorPackage.CookieHolder cookie )
+ {
+
+ try
+ {
+ ByteBuffer bb = ByteBuffer.wrap(oid);
+ long msb = bb.getLong();
+ long lsb = bb.getLong();
+ AgentPath syskey = new AgentPath(new SystemKey(msb, lsb));
+
+ Logger.msg(1,"===========================================================");
+ Logger.msg(1,"Agent called at "+new Timestamp( System.currentTimeMillis()) +": " + operation +
+ "(" + syskey + ")." );
+
+ return Gateway.getCorbaServer().getAgent(syskey);
+
+ }
+ catch (ObjectNotFoundException ex)
+ {
+ Logger.error("ObjectNotFoundException::ActiveLocator::preinvoke() "+ex.toString());
+ throw new org.omg.CORBA.OBJECT_NOT_EXIST();
+ } catch (InvalidItemPathException ex) {
+ Logger.error("InvalidItemPathException::ActiveLocator::preinvoke() "+ex.toString());
+ throw new org.omg.CORBA.INV_OBJREF();
+ }
+ }
+
+
+ /**************************************************************************
+ *
+ **************************************************************************/
+ @Override
+ public void postinvoke(
+ byte[] oid,
+ org.omg.PortableServer.POA poa,
+ String operation,
+ java.lang.Object the_cookie,
+ org.omg.PortableServer.Servant the_servant )
+ {
+ }
+}
diff --git a/src/main/java/org/cristalise/kernel/entity/agent/AgentImplementation.java b/src/main/java/org/cristalise/kernel/entity/agent/AgentImplementation.java
new file mode 100644
index 0000000..26c2f2f
--- /dev/null
+++ b/src/main/java/org/cristalise/kernel/entity/agent/AgentImplementation.java
@@ -0,0 +1,137 @@
+/**
+ * This file is part of the CRISTAL-iSE kernel.
+ * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * http://www.fsf.org/licensing/licenses/lgpl.html
+ */
+package org.cristalise.kernel.entity.agent;
+
+import org.cristalise.kernel.common.CannotManageException;
+import org.cristalise.kernel.common.ObjectCannotBeUpdated;
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.common.SystemKey;
+import org.cristalise.kernel.entity.AgentOperations;
+import org.cristalise.kernel.entity.ItemImplementation;
+import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStepContainer;
+import org.cristalise.kernel.lifecycle.instance.predefined.agent.AgentPredefinedStepContainer;
+import org.cristalise.kernel.lookup.AgentPath;
+import org.cristalise.kernel.lookup.ItemPath;
+import org.cristalise.kernel.lookup.RolePath;
+import org.cristalise.kernel.process.Gateway;
+import org.cristalise.kernel.utils.Logger;
+
+
+/**
+ * Implementation of Agent, though called from the CORBA implementation ActiveEntity.
+ *
+ * <p>The Agent is an extension of the Item that can execute Jobs, and in doing so
+ * change the state of Item workflows, submit data to them in the form of Outcomes
+ * and run any scripts associated with those activities. In this server object,
+ * none of this specific Agent work is performed - it all must be done using the
+ * client API. The server implementation only manages the Agent's data: its roles
+ * and persistent Jobs.
+ */
+public class AgentImplementation extends ItemImplementation implements
+ AgentOperations {
+
+ private JobList currentJobs;
+ private final AgentPath mAgentPath;
+
+ public AgentImplementation(AgentPath path) {
+ super(path);
+ mAgentPath = path;
+ }
+
+
+ /**
+ * Updates an Agent's list of Jobs relating to a particular activity. Only
+ * Activities that are assigned to a Role that is flagged to push Jobs do this.
+ *
+ */
+ @Override
+ public synchronized void refreshJobList(SystemKey sysKey, String stepPath, String newJobs) {
+ try {
+ ItemPath itemPath = new ItemPath(sysKey);
+ JobArrayList newJobList = (JobArrayList)Gateway.getMarshaller().unmarshall(newJobs);
+
+ // get our joblist
+ if (currentJobs == null)
+ currentJobs = new JobList( itemPath, null);
+
+ // remove old jobs for this item
+ currentJobs.removeJobsForStep( itemPath, stepPath );
+
+ // merge new jobs in
+ for (Object name : newJobList.list) {
+ Job newJob = (Job)name;
+ Logger.msg(6, "Adding job for "+newJob.getItemPath()+"/"+newJob.getStepPath()+":"+newJob.getTransition().getId());
+ currentJobs.addJob(newJob);
+ }
+
+ } catch (Throwable ex) {
+ Logger.error("Could not refresh job list.");
+ Logger.error(ex);
+ }
+
+ }
+
+ /** Adds the given Role to this Agent. Called from the SetAgentRoles
+ * predefined step.
+ *
+ * @param roleName - the new Role to add
+ * @throws CannotManageException When the process has no lookup manager
+ * @throws ObjectNotFoundException
+ *
+ */
+ @Override
+ public void addRole(String roleName) throws CannotManageException, ObjectNotFoundException {
+ RolePath newRole = Gateway.getLookup().getRolePath(roleName);
+ try {
+ Gateway.getLookupManager().addRole(mAgentPath, newRole);
+ } catch (ObjectCannotBeUpdated ex) {
+ throw new CannotManageException("Could not update role");
+ }
+ }
+
+ /**
+ * Removes the given Role from this Agent. Called by the SetAgentRoles
+ * predefined step.
+ *
+ * @param roleName
+ */
+ @Override
+ public void removeRole(String roleName) throws CannotManageException, ObjectNotFoundException {
+ RolePath rolePath = Gateway.getLookup().getRolePath(roleName);
+ try {
+ Gateway.getLookupManager().removeRole(mAgentPath, rolePath);
+ } catch (ObjectCannotBeUpdated ex) {
+ throw new CannotManageException("Could not update role");
+ }
+ }
+
+ /**
+ * Agents have their own predefined step containers. They contain the standard
+ * predefined steps, plus special Agent ones related to Agent management and
+ * instantiation.
+ *
+ * @see org.cristalise.kernel.lifecycle.instance.predefined.agent.AgentPredefinedStepContainer
+ */
+ @Override
+ protected PredefinedStepContainer getNewPredefStepContainer() {
+ return new AgentPredefinedStepContainer();
+ }
+}
diff --git a/src/main/java/org/cristalise/kernel/entity/agent/Job.java b/src/main/java/org/cristalise/kernel/entity/agent/Job.java
new file mode 100644
index 0000000..bd74d51
--- /dev/null
+++ b/src/main/java/org/cristalise/kernel/entity/agent/Job.java
@@ -0,0 +1,484 @@
+/**
+ * This file is part of the CRISTAL-iSE kernel.
+ * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * http://www.fsf.org/licensing/licenses/lgpl.html
+ */
+package org.cristalise.kernel.entity.agent;
+
+import java.util.HashMap;
+
+import org.cristalise.kernel.common.InvalidDataException;
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.common.PersistencyException;
+import org.cristalise.kernel.entity.C2KLocalObject;
+import org.cristalise.kernel.entity.proxy.ItemProxy;
+import org.cristalise.kernel.lifecycle.instance.Activity;
+import org.cristalise.kernel.lifecycle.instance.stateMachine.Transition;
+import org.cristalise.kernel.lookup.AgentPath;
+import org.cristalise.kernel.lookup.InvalidAgentPathException;
+import org.cristalise.kernel.lookup.InvalidItemPathException;
+import org.cristalise.kernel.lookup.ItemPath;
+import org.cristalise.kernel.persistency.ClusterStorage;
+import org.cristalise.kernel.persistency.outcome.Outcome;
+import org.cristalise.kernel.persistency.outcome.OutcomeInitiator;
+import org.cristalise.kernel.persistency.outcome.Schema;
+import org.cristalise.kernel.persistency.outcome.Viewpoint;
+import org.cristalise.kernel.process.Gateway;
+import org.cristalise.kernel.scripting.ErrorInfo;
+import org.cristalise.kernel.utils.CastorHashMap;
+import org.cristalise.kernel.utils.KeyValuePair;
+import org.cristalise.kernel.utils.Logger;
+
+
+/*******************************************************************************
+ * @author $Author: abranson $ $Date: 2005/05/20 13:07:49 $
+ * @version $Revision: 1.62 $
+ ******************************************************************************/
+
+public class Job implements C2KLocalObject
+{
+ // persistent
+
+ private int id;
+
+ private ItemPath itemPath;
+
+ private String stepName;
+
+ private String stepPath;
+
+ private String stepType;
+
+ private Transition transition;
+
+ private String originStateName;
+
+ private String targetStateName;
+
+ private String agentRole;
+
+ private CastorHashMap actProps = new CastorHashMap();
+
+ // non-persistent
+
+ private String name;
+
+ private AgentPath agentPath;
+
+ private String agentName;
+
+ private String outcomeData;
+
+ private ErrorInfo error;
+
+ private ItemProxy item = null;
+
+ private boolean outcomeSet;
+
+ // outcome initiator cache
+
+ static private HashMap<String, OutcomeInitiator> ocInitCache = new HashMap<String, OutcomeInitiator>();
+
+ /***************************************************************************
+ * Empty constructor for Castor
+ **************************************************************************/
+ public Job()
+ {
+ }
+
+ public Job(Activity act, ItemPath itemPath, Transition transition, AgentPath agent, String role) throws InvalidDataException, ObjectNotFoundException, InvalidAgentPathException {
+
+ setItemPath(itemPath);
+ setStepPath(act.getPath());
+ setTransition(transition);
+ setOriginStateName(act.getStateMachine().getState(transition.getOriginStateId()).getName());
+ setTargetStateName(act.getStateMachine().getState(transition.getTargetStateId()).getName());
+ setStepName(act.getName());
+ setActProps(act.getProperties());
+ setStepType(act.getType());
+ if (agent != null) setAgentName(agent.getAgentName());
+ setAgentRole(role);
+ }
+
+
+ // Castor persistent fields
+
+ public String getOriginStateName() {
+ return originStateName;
+ }
+
+ public void setOriginStateName(String originStateName) {
+ this.originStateName = originStateName;
+ }
+
+ public String getTargetStateName() {
+ return targetStateName;
+ }
+
+ public void setTargetStateName(String targetStateName) {
+ this.targetStateName = targetStateName;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ name = String.valueOf(id);
+ }
+
+ public ItemPath getItemPath() {
+ return itemPath;
+ }
+
+ public void setItemPath(ItemPath path) {
+ itemPath = path;
+ item = null;
+ }
+
+ public void setItemUUID( String uuid ) throws InvalidItemPathException
+ {
+ setItemPath(new ItemPath(uuid));
+ }
+
+ public String getItemUUID() {
+ return getItemPath().getUUID().toString();
+ }
+
+ public String getStepName() {
+ return stepName;
+ }
+
+ public void setStepName(String string) {
+ stepName = string;
+ }
+
+ public String getStepPath() {
+ return stepPath;
+ }
+
+ public void setStepPath(String string) {
+ stepPath = string;
+ }
+
+ public String getStepType() {
+ return stepType;
+ }
+
+ public void setStepType(String actType) {
+ stepType = actType;
+ }
+
+ public Transition getTransition() {
+ return transition;
+ }
+
+ public void setTransition(Transition transition) {
+ this.transition = transition;
+ }
+
+ public AgentPath getAgentPath() throws ObjectNotFoundException {
+ if (agentPath == null && getAgentName() != null) {
+ agentPath = Gateway.getLookup().getAgentPath(getAgentName());
+ }
+ return agentPath;
+ }
+
+ public void setAgentPath(AgentPath agentPath) {
+ this.agentPath = agentPath;
+ agentName = agentPath.getAgentName();
+ }
+
+ public void setAgentUUID( String uuid )
+ {
+ if (uuid != null)
+ try {
+ setAgentPath(AgentPath.fromUUIDString(uuid));
+ } catch (InvalidAgentPathException e) {
+ Logger.error("Invalid agent path in Job: "+uuid);
+ }
+ }
+
+ public String getAgentUUID() {
+ try {
+ if (getAgentPath() != null)
+ return getAgentPath().getUUID().toString();
+ } catch (ObjectNotFoundException e) { }
+ return null;
+ }
+
+ public String getAgentName()
+ {
+ if (agentName == null)
+ agentName = (String) actProps.get("Agent Name");
+ return agentName;
+ }
+
+ public void setAgentName(String agentName) throws ObjectNotFoundException
+ {
+ this.agentName = agentName;
+ agentPath = Gateway.getLookup().getAgentPath(agentName);
+ }
+
+ public String getAgentRole() {
+ return agentRole;
+ }
+
+ public void setAgentRole(String role) {
+ agentRole = role;
+ }
+
+ public String getSchemaName() throws InvalidDataException, ObjectNotFoundException {
+ if (transition.hasOutcome(actProps)) {
+ Schema schema = transition.getSchema(actProps);
+ return schema.docType;
+ }
+ return null;
+ }
+
+ public int getSchemaVersion() throws InvalidDataException, ObjectNotFoundException {
+ if (transition.hasOutcome(actProps)) {
+ Schema schema = transition.getSchema(actProps);
+ return schema.docVersion;
+ }
+ return -1;
+ }
+
+ public boolean isOutcomeRequired()
+ {
+ return transition.hasOutcome(actProps) && transition.getOutcome().isRequired();
+ }
+
+ public String getScriptName() {
+ if (transition.hasScript(actProps)) {
+ return transition.getScript().getScriptName();
+ }
+ return null;
+ }
+
+ public int getScriptVersion() throws InvalidDataException {
+ if (transition.hasScript(actProps)) {
+ return transition.getScriptVersion(actProps);
+ }
+ return -1;
+ }
+
+ public KeyValuePair[] getKeyValuePairs() {
+ return actProps.getKeyValuePairs();
+ }
+
+ public void setKeyValuePairs(KeyValuePair[] pairs) {
+ actProps.setKeyValuePairs(pairs);
+ }
+
+ // Non-persistent fields
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ try {
+ id = Integer.parseInt(name);
+ } catch (NumberFormatException ex) {
+ id = -1;
+ }
+ }
+
+ public ItemProxy getItemProxy() throws ObjectNotFoundException, InvalidItemPathException {
+ if (item == null)
+ item = Gateway.getProxyManager().getProxy(itemPath);
+ return item;
+ }
+
+ public String getDescription()
+ {
+ String desc = (String) actProps.get("Description");
+ if (desc == null)
+ desc = "No Description";
+ return desc;
+ }
+ public void setOutcome(String outcome)
+ {
+ outcomeData = outcome;
+ outcomeSet = !(outcomeData == null);
+ }
+
+ public void setError(ErrorInfo errors)
+ {
+ error = errors;
+ try {
+ outcomeData = Gateway.getMarshaller().marshall(error);
+ } catch (Exception e) {
+ Logger.error("Error marshalling ErrorInfo in job");
+ 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(itemPath,
+ ClusterStorage.VIEWPOINT + "/" + schemaName + "/" + viewName, null);
+ return view.getOutcome().getData();
+ } catch (ObjectNotFoundException ex) { // viewpoint doesn't exist yet
+ return null;
+ } catch (PersistencyException e) {
+ Logger.error(e);
+ throw new InvalidDataException("ViewpointOutcomeInitiator: PersistencyException loading viewpoint "
+ + ClusterStorage.VIEWPOINT + "/" + schemaName + "/" + viewName+" in item "+itemPath.getUUID());
+ }
+ }
+ 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;
+ if (!Gateway.getProperties().containsKey(ocPropName)) {
+ throw new InvalidDataException("Outcome instantiator "+ocPropName+" isn't defined");
+ }
+ try {
+ ocInitObj = Gateway.getProperties().getInstance(ocPropName);
+ } catch (Exception e) {
+ Logger.error(e);
+ throw new InvalidDataException("Outcome instantiator "+ocPropName+" couldn't be instantiated");
+ }
+ ocInit = (OutcomeInitiator)ocInitObj; // throw runtime class cast if it isn't one
+ ocInitCache.put(ocPropName, ocInit);
+ }
+ }
+ return ocInit;
+ }
+ else
+ return null;
+ }
+
+ public String getOutcomeString() throws InvalidDataException
+ {
+ 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;
+ }
+
+ public Outcome getOutcome() throws InvalidDataException, ObjectNotFoundException
+ {
+ return new Outcome(-1, getOutcomeString(), getSchemaName(), getSchemaVersion());
+ }
+
+ public boolean hasOutcome() {
+ return transition.hasOutcome(actProps);
+ }
+
+ public boolean hasScript() {
+ return transition.hasScript(actProps);
+ }
+
+ public boolean isOutcomeSet() {
+ return outcomeSet;
+ }
+
+ @Override
+ public String getClusterType()
+ {
+ return ClusterStorage.JOB;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((itemPath == null) ? 0 : itemPath.hashCode());
+ result = prime * result
+ + ((stepPath == null) ? 0 : stepPath.hashCode());
+ result = prime * result
+ + ((transition == null) ? 0 : transition.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Job other = (Job) obj;
+ if (itemPath == null) {
+ if (other.itemPath != null)
+ return false;
+ } else if (!itemPath.equals(other.itemPath))
+ return false;
+ if (stepPath == null) {
+ if (other.stepPath != null)
+ return false;
+ } else if (!stepPath.equals(other.stepPath))
+ return false;
+ if (transition == null) {
+ if (other.transition != null)
+ return false;
+ } else if (!transition.equals(other.transition))
+ return false;
+ return true;
+ }
+
+
+ private void setActProps(CastorHashMap actProps) {
+ this.actProps = actProps;
+ }
+
+ public Object getActProp(String name)
+ {
+ return actProps.get(name);
+ }
+
+ public String getActPropString(String name)
+ {
+ Object obj = getActProp(name);
+ return obj==null?null:String.valueOf(obj);
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/cristalise/kernel/entity/agent/JobArrayList.java b/src/main/java/org/cristalise/kernel/entity/agent/JobArrayList.java
new file mode 100644
index 0000000..f4233fb
--- /dev/null
+++ b/src/main/java/org/cristalise/kernel/entity/agent/JobArrayList.java
@@ -0,0 +1,42 @@
+/**
+ * This file is part of the CRISTAL-iSE kernel.
+ * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * http://www.fsf.org/licensing/licenses/lgpl.html
+ */
+package org.cristalise.kernel.entity.agent;
+
+import java.util.ArrayList;
+
+import org.cristalise.kernel.utils.CastorArrayList;
+
+
+public class JobArrayList extends CastorArrayList<Job>
+{
+
+ public JobArrayList()
+ {
+ super();
+ }
+
+ public JobArrayList(ArrayList<Job> aList)
+ {
+ super(aList);
+ }
+
+
+}
diff --git a/src/main/java/org/cristalise/kernel/entity/agent/JobList.java b/src/main/java/org/cristalise/kernel/entity/agent/JobList.java
new file mode 100644
index 0000000..b4e2a27
--- /dev/null
+++ b/src/main/java/org/cristalise/kernel/entity/agent/JobList.java
@@ -0,0 +1,138 @@
+/**
+ * This file is part of the CRISTAL-iSE kernel.
+ * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * http://www.fsf.org/licensing/licenses/lgpl.html
+ */
+package org.cristalise.kernel.entity.agent;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.cristalise.kernel.lookup.ItemPath;
+import org.cristalise.kernel.persistency.ClusterStorage;
+import org.cristalise.kernel.persistency.RemoteMap;
+import org.cristalise.kernel.utils.Logger;
+
+
+
+/**************************************************************************
+*
+* @author $Author: abranson $ $Date: 2006/03/03 13:52:21 $
+* @version $Revision: 1.15 $
+***************************************************************************/
+public class JobList extends RemoteMap<Job>
+{
+
+ /**************************************************************************
+ * Empty constructor for Castor
+ **************************************************************************/
+ public JobList(ItemPath itemPath, Object locker)
+ {
+ super(itemPath, ClusterStorage.JOB, locker);
+ }
+
+
+ /**************************************************************************
+ *
+ **************************************************************************/
+ public void addJob( Job job )
+ {
+ synchronized(this) {
+ int jobId = getLastId()+1;
+ job.setId(jobId);
+ put(String.valueOf(jobId), job);
+ }
+ }
+
+ /**
+ * Cannot be stored
+ */
+ @Override
+ public String getClusterType() {
+ return null;
+ }
+
+
+ public Job getJob(int id) {
+ return get(String.valueOf(id));
+ }
+
+
+ /**
+ * @param job
+ */
+ public void removeJobsForItem( ItemPath itemPath )
+ {
+ Iterator<Job> currentMembers = values().iterator();
+ Job j = null;
+
+ while( currentMembers.hasNext() )
+ {
+ j = currentMembers.next();
+
+ if( j.getItemPath().equals(itemPath) )
+ remove( String.valueOf(j.getId()) );
+ }
+
+ Logger.msg(5, "JobList::removeJobsWithSysKey() - " + itemPath + " DONE." );
+ }
+
+ public void removeJobsForStep( ItemPath itemPath, String stepPath )
+ {
+ ArrayList<String> staleJobs = new ArrayList<String>();
+ Iterator<String> jobIter = keySet().iterator();
+ while( jobIter.hasNext() )
+ {
+ String jid = jobIter.next();
+ Job j = get(jid);
+ if( j.getItemPath().equals(itemPath) && j.getStepPath().equals(stepPath))
+ staleJobs.add(jid);
+ }
+
+ Logger.msg(3, "JobList.removeJobsForStep() - removing "+staleJobs.size());
+
+ for (String jid : staleJobs) {
+ remove(jid);
+ }
+ Logger.msg(5, "JobList::removeJobsForStep() - " + itemPath + " DONE." );
+ }
+ /**
+ * @param itemKey
+ * @param string
+ * @return
+ */
+ public Vector<Job> getJobsOfItem( ItemPath itemPath )
+ {
+ Iterator<Job> currentMembers = values().iterator();
+ Job j = null;
+ Vector<Job> jobs = new Vector<Job>();
+
+ while( currentMembers.hasNext() )
+ {
+ j = currentMembers.next();
+
+ if( j.getItemPath().equals(itemPath) )
+ jobs.add(j);
+ }
+
+ Logger.msg(5, "JobList::getJobsOfSysKey() - returning " + jobs.size() + " Jobs." );
+
+ return jobs;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/cristalise/kernel/entity/agent/package-info.java b/src/main/java/org/cristalise/kernel/entity/agent/package-info.java
new file mode 100644
index 0000000..f5e146b
--- /dev/null
+++ b/src/main/java/org/cristalise/kernel/entity/agent/package-info.java
@@ -0,0 +1,32 @@
+/**
+ * This file is part of the CRISTAL-iSE kernel.
+ * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * http://www.fsf.org/licensing/licenses/lgpl.html
+ */
+/**
+ * The implementation of Agents, and their Jobs.
+ *
+ * <p>This package contains the classes for the implementation of
+ * Agents on the CRISTAL server. They correspond to the Item implementations in
+ * the parent package.
+ * <p>This package also contains the {@link Job} object implementation, as well
+ * as the RemoteMap JobList, and the marshallable container JobArrayList.
+ *
+ */
+
+package org.cristalise.kernel.entity.agent; \ No newline at end of file