diff options
Diffstat (limited to 'src/main/java/com/c2kernel/entity')
26 files changed, 1473 insertions, 921 deletions
diff --git a/src/main/java/com/c2kernel/entity/AgentImplementation.java b/src/main/java/com/c2kernel/entity/AgentImplementation.java new file mode 100644 index 0000000..8010114 --- /dev/null +++ b/src/main/java/com/c2kernel/entity/AgentImplementation.java @@ -0,0 +1,78 @@ +package com.c2kernel.entity;
+
+import com.c2kernel.common.CannotManageException;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.entity.agent.Job;
+import com.c2kernel.entity.agent.JobArrayList;
+import com.c2kernel.entity.agent.JobList;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.lookup.InvalidItemPathException;
+import com.c2kernel.lookup.RolePath;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.utils.Logger;
+
+public class AgentImplementation extends ItemImplementation implements
+ AgentOperations {
+
+ private JobList currentJobs;
+
+ public AgentImplementation(int systemKey) {
+ super(systemKey);
+ }
+
+ /**
+ * Called by an activity when it reckons we need to update our joblist for it
+ */
+
+ @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);
+ }
+
+ }
+
+ @Override
+ public void addRole(String roleName) throws CannotManageException, ObjectNotFoundException {
+ RolePath newRole = Gateway.getLookup().getRolePath(roleName);
+ try {
+ newRole.addAgent(new AgentPath(mSystemKey));
+ } catch (InvalidItemPathException ex) {
+ throw new CannotManageException("Invalid syskey for agent: "+mSystemKey, "");
+ } catch (ObjectCannotBeUpdated ex) {
+ throw new CannotManageException("Could not update role");
+ }
+ }
+
+ @Override
+ public void removeRole(String roleName) throws CannotManageException, ObjectNotFoundException {
+ RolePath rolePath = Gateway.getLookup().getRolePath(roleName);
+ try {
+ rolePath.removeAgent(new AgentPath(mSystemKey));
+ } catch (InvalidItemPathException e) {
+ throw new CannotManageException("Invalid syskey for agent: "+mSystemKey, "");
+ } catch (ObjectCannotBeUpdated ex) {
+ throw new CannotManageException("Could not update role");
+ }
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/entity/CorbaServer.java b/src/main/java/com/c2kernel/entity/CorbaServer.java index 3d7c79b..3a01ed7 100644 --- a/src/main/java/com/c2kernel/entity/CorbaServer.java +++ b/src/main/java/com/c2kernel/entity/CorbaServer.java @@ -14,8 +14,8 @@ import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.agent.ActiveEntity;
import com.c2kernel.entity.agent.ActiveLocator;
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.process.Gateway;
import com.c2kernel.utils.Logger;
import com.c2kernel.utils.SoftCache;
@@ -31,14 +31,14 @@ import com.c2kernel.utils.SoftCache; public class CorbaServer {
- private final Map<EntityPath, Servant> mEntityCache;
+ private final Map<ItemPath, Servant> mEntityCache;
private POA mRootPOA;
private POA mItemPOA;
private POA mAgentPOA;
private POAManager mPOAManager;
public CorbaServer() throws InvalidDataException {
- mEntityCache = new SoftCache<EntityPath, Servant>(50);
+ mEntityCache = new SoftCache<ItemPath, Servant>(50);
// init POA
try {
@@ -119,14 +119,14 @@ public class CorbaServer { **************************************************************************/
private Servant getEntity(int sysKey, org.omg.PortableServer.POA poa) throws ObjectNotFoundException {
try {
- EntityPath entityPath = new EntityPath(sysKey);
+ ItemPath entityPath = new ItemPath(sysKey);
Servant entity = null;
synchronized (mEntityCache) {
entity = mEntityCache.get(entityPath);
if (entity == null) {
Logger.msg(7, "Creating new servant for "+sysKey);
- Class<?> entityClass = Gateway.getLDAPLookup().getEntityClass(entityPath);
+ Class<?> entityClass = Gateway.getLookup().getItemClass(entityPath);
if (entityClass == TraceableEntity.class) {
if (poa == null) poa = mItemPOA;
@@ -141,7 +141,7 @@ public class CorbaServer { }
return entity;
- } catch (InvalidEntityPathException ex) {
+ } catch (InvalidItemPathException ex) {
throw new ObjectNotFoundException("Invalid Entity Key", "");
}
}
@@ -164,10 +164,10 @@ public class CorbaServer { * @param entityPath
* @return
*/
- public Servant createEntity(EntityPath entityPath) throws CannotManageException, ObjectAlreadyExistsException {
+ public Servant createEntity(ItemPath entityPath) throws CannotManageException, ObjectAlreadyExistsException {
try {
if (entityPath == null)
- entityPath = Gateway.getLDAPLookup().getNextKeyManager().generateNextEntityKey();
+ entityPath = Gateway.getNextKeyManager().generateNextEntityKey();
} catch (Exception ex) {
Logger.error(ex);
throw new CannotManageException("Cannot generate next entity key");
diff --git a/src/main/java/com/c2kernel/entity/ItemImplementation.java b/src/main/java/com/c2kernel/entity/ItemImplementation.java new file mode 100644 index 0000000..b12e105 --- /dev/null +++ b/src/main/java/com/c2kernel/entity/ItemImplementation.java @@ -0,0 +1,282 @@ +package com.c2kernel.entity;
+
+import com.c2kernel.collection.Collection;
+import com.c2kernel.collection.CollectionArrayList;
+import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.InvalidDataException;
+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.InvalidItemPathException;
+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;
+
+public class ItemImplementation implements ItemOperations {
+
+ protected final TransactionManager mStorage;
+ protected final int mSystemKey;
+
+ protected ItemImplementation(int systemKey) {
+ this.mStorage = Gateway.getStorage();
+ this.mSystemKey = systemKey;
+ }
+
+ @Override
+ public int getSystemKey() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void initialise(int agentId, String propString, String initWfString,
+ String initCollsString) throws AccessRightsException,
+ InvalidDataException, PersistencyException
+ {
+ Logger.msg(5, "Item::initialise("+mSystemKey+") - agent:"+agentId);
+ Object locker = new Object();
+
+ AgentPath agentPath;
+ try {
+ agentPath = new AgentPath(agentId);
+ } catch (InvalidItemPathException e) {
+ throw new AccessRightsException("Invalid Agent Id:" + agentId);
+ }
+
+ // must supply properties
+ if (propString == null || propString.length() == 0) {
+ throw new InvalidDataException("No properties supplied", "");
+ }
+
+ // store properties
+ try {
+ PropertyArrayList props = (PropertyArrayList) Gateway
+ .getMarshaller().unmarshall(propString);
+ for (Property thisProp : props.list)
+ mStorage.put(mSystemKey, thisProp, locker);
+ } catch (Throwable ex) {
+ Logger.msg(8, "TraceableEntity::initialise(" + mSystemKey
+ + ") - Properties were invalid: " + propString);
+ Logger.error(ex);
+ mStorage.abort(locker);
+ throw new InvalidDataException("Properties were invalid", "");
+ }
+
+ // create wf
+ try {
+ Workflow lc = null;
+ if (initWfString == null || initWfString.length() == 0)
+ lc = new Workflow(new CompositeActivity());
+ else
+ lc = new Workflow((CompositeActivity) Gateway
+ .getMarshaller().unmarshall(initWfString));
+ lc.initialise(mSystemKey, agentPath);
+ mStorage.put(mSystemKey, lc, locker);
+ } catch (Throwable ex) {
+ Logger.msg(8, "TraceableEntity::initialise(" + mSystemKey
+ + ") - Workflow was invalid: " + initWfString);
+ Logger.error(ex);
+ mStorage.abort(locker);
+ throw new InvalidDataException("Workflow was invalid", "");
+ }
+
+ // init collections
+ if (initCollsString != null && initCollsString.length() > 0) {
+ try {
+ CollectionArrayList colls = (CollectionArrayList) Gateway
+ .getMarshaller().unmarshall(initCollsString);
+ for (Collection<?> thisColl : colls.list) {
+ mStorage.put(mSystemKey, thisColl, locker);
+ }
+ } catch (Throwable ex) {
+ Logger.msg(8, "TraceableEntity::initialise(" + mSystemKey
+ + ") - Collections were invalid: "
+ + initCollsString);
+ Logger.error(ex);
+ mStorage.abort(locker);
+ throw new InvalidDataException("Collections were invalid");
+ }
+ }
+ mStorage.commit(locker);
+ Logger.msg(3, "Initialisation of item " + mSystemKey
+ + " was successful");
+ }
+
+
+ @Override
+ public String requestAction(int agentId, String stepPath, int transitionID,
+ String requestData) throws AccessRightsException,
+ InvalidTransitionException, ObjectNotFoundException,
+ InvalidDataException, PersistencyException,
+ ObjectAlreadyExistsException {
+
+ 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);
+
+ String finalOutcome = 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);
+
+ return finalOutcome;
+ // 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 (InvalidItemPathException 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(), "");
+ }
+ }
+
+ @Override
+ public String queryLifeCycle(int agentId, boolean filter)
+ throws AccessRightsException, ObjectNotFoundException,
+ PersistencyException {
+ Logger.msg(1, "TraceableEntity::queryLifeCycle(" + mSystemKey
+ + ") - agent: " + agentId);
+ try {
+ AgentPath agent;
+ try {
+ agent = new AgentPath(agentId);
+ } catch (InvalidItemPathException 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.");
+ }
+ }
+
+ @Override
+ public String queryData(String path) throws AccessRightsException,
+ ObjectNotFoundException, PersistencyException {
+
+ 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 < ids.length; i++) {
+ result += ids[i];
+
+ if (i != ids.length - 1)
+ result += ",";
+ }
+ }
+ // ****************************************************************
+ else { // retrieve the object instead
+ C2KLocalObject obj = mStorage.get(mSystemKey, path, null);
+
+ // marshall it, or in the case of an outcome get the data.
+ result = Gateway.getMarshaller().marshall(obj);
+ }
+ } catch (ObjectNotFoundException ex) {
+ throw ex;
+ } catch (Throwable ex) {
+ Logger.warning("TraceableEntity::queryData(" + mSystemKey
+ + ") - " + path + " Failed: " + ex.getClass().getName());
+ throw new PersistencyException("Server exception: "
+ + ex.getClass().getName(), "");
+ }
+
+ if (Logger.doLog(9))
+ Logger.msg(9, "TraceableEntity::queryData(" + mSystemKey
+ + ") - result:" + result);
+
+ return result;
+ }
+
+ /**
+ *
+ */
+ @Override
+ protected void finalize() throws Throwable {
+ Logger.msg(7, "Item "+mSystemKey+" reaped");
+ Gateway.getStorage().clearCache(mSystemKey, null);
+ super.finalize();
+ }
+}
diff --git a/src/main/java/com/c2kernel/entity/TraceableEntity.java b/src/main/java/com/c2kernel/entity/TraceableEntity.java index b6ccd8c..a0980ee 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);
}
}
@@ -166,7 +111,7 @@ public class TraceableEntity extends ItemPOA **************************************************************************/
//requestdata is xmlstring
@Override
- public void requestAction( int agentId,
+ public String requestAction( int agentId,
String stepPath,
int transitionID,
String requestData
@@ -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(), "");
- }
+ return 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<ids.length; i++ )
- {
- result += ids[i];
-
- if( i != ids.length-1 )
- result += ",";
- }
- }
- //****************************************************************
- else
- { // retrieve the object instead
- C2KLocalObject obj = mStorage.get( mSystemKey, path, null );
-
- // marshall it, or in the case of an outcome get the data.
- result = Gateway.getMarshaller().marshall(obj);
- }
- }
- catch (ObjectNotFoundException ex) {
- throw ex;
- }
- catch(Throwable ex)
- {
- Logger.warning("TraceableEntity::queryData("+mSystemKey+") - "+
- path + " Failed: "+ex.getClass().getName());
- throw new PersistencyException("Server exception: "+ex.getClass().getName(), "");
- }
-
- if( Logger.doLog(9) )
- Logger.msg(9, "TraceableEntity::queryData("+mSystemKey+") - result:" + result );
-
- return result;
+ return mItemImpl.queryData(path);
}
}
- /**
- *
- */
- @Override
- protected void finalize() throws Throwable {
- Logger.msg(7, "Item "+mSystemKey+" reaped");
- Gateway.getStorage().clearCache(mSystemKey, null);
- super.finalize();
- }
-
}
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 diff --git a/src/main/java/com/c2kernel/entity/imports/Geometry.java b/src/main/java/com/c2kernel/entity/imports/Geometry.java new file mode 100644 index 0000000..cb973d3 --- /dev/null +++ b/src/main/java/com/c2kernel/entity/imports/Geometry.java @@ -0,0 +1,29 @@ +
+
+package com.c2kernel.entity.imports;
+
+
+
+public class Geometry implements java.io.Serializable {
+
+
+ public int x;
+
+ public int y;
+
+ public int width;
+
+ public int height;
+
+ public Geometry() {
+ super();
+ }
+
+ public Geometry(int x, int y, int width, int height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/entity/imports/ImportAgent.java b/src/main/java/com/c2kernel/entity/imports/ImportAgent.java new file mode 100644 index 0000000..26e3325 --- /dev/null +++ b/src/main/java/com/c2kernel/entity/imports/ImportAgent.java @@ -0,0 +1,60 @@ +package com.c2kernel.entity.imports;
+
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+
+import com.c2kernel.common.CannotManageException;
+import com.c2kernel.common.ObjectAlreadyExistsException;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.entity.agent.ActiveEntity;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.lookup.RolePath;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.process.module.ModuleImport;
+import com.c2kernel.property.Property;
+import com.c2kernel.property.PropertyArrayList;
+import com.c2kernel.utils.Logger;
+
+public class ImportAgent extends ModuleImport implements java.io.Serializable {
+
+ public String password;
+
+ public ArrayList<String> roles = new ArrayList<String>();
+ public ArrayList<Property> properties = new ArrayList<Property>();
+
+ public ImportAgent() {
+ }
+
+ public ImportAgent(String name, String password) {
+ this.name = name;
+ this.password = password;
+ }
+
+ public void create(int agentId) throws ObjectNotFoundException, ObjectCannotBeUpdated, NoSuchAlgorithmException, CannotManageException, ObjectAlreadyExistsException {
+ AgentPath newAgent = Gateway.getNextKeyManager().generateNextAgentKey();
+ newAgent.setAgentName(name);
+ newAgent.setPassword(password);
+ ActiveEntity newAgentEnt = (ActiveEntity)Gateway.getCorbaServer().createEntity(newAgent);
+ Gateway.getLookup().add(newAgent);
+ // assemble properties
+ properties.add(new com.c2kernel.property.Property("Name", name, true));
+ properties.add(new com.c2kernel.property.Property("Type", "Agent", false));
+ try {
+ newAgentEnt.initialise(agentId, Gateway.getMarshaller().marshall(new PropertyArrayList(properties)), null, null);
+ } catch (Exception ex) {
+ Logger.error(ex);
+ throw new CannotManageException("Error initialising new agent");
+ }
+ for (String role : roles) {
+ RolePath thisRole;
+ try {
+ thisRole = Gateway.getLookup().getRolePath(role);
+ } catch (ObjectNotFoundException ex) {
+ throw new ObjectNotFoundException("Role "+role+" does not exist.");
+ }
+ thisRole.addAgent(newAgent);
+ }
+
+ }
+}
diff --git a/src/main/java/com/c2kernel/entity/imports/ImportAggregation.java b/src/main/java/com/c2kernel/entity/imports/ImportAggregation.java new file mode 100644 index 0000000..1c75990 --- /dev/null +++ b/src/main/java/com/c2kernel/entity/imports/ImportAggregation.java @@ -0,0 +1,51 @@ +package com.c2kernel.entity.imports;
+
+import java.util.ArrayList;
+
+import com.c2kernel.collection.MembershipException;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.graph.model.GraphPoint;
+import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.property.PropertyDescription;
+import com.c2kernel.property.PropertyDescriptionList;
+import com.c2kernel.property.PropertyUtility;
+
+public class ImportAggregation implements java.io.Serializable {
+
+ public boolean isDescription;
+ public ArrayList<ImportAggregationMember> aggregationMemberList = new ArrayList<ImportAggregationMember>();
+ public String name;
+
+ public ImportAggregation() {
+ super();
+ }
+
+ public ImportAggregation(String name, boolean isDescription) {
+ this();
+ this.name = name;
+ this.isDescription = isDescription;
+ }
+
+ public com.c2kernel.collection.Aggregation create() throws MembershipException, ObjectNotFoundException {
+ com.c2kernel.collection.Aggregation newAgg = isDescription?new com.c2kernel.collection.AggregationDescription(name):new com.c2kernel.collection.AggregationInstance(name);
+ newAgg.setName(name);
+ for (ImportAggregationMember thisMem : aggregationMemberList) {
+ StringBuffer classProps = new StringBuffer();
+ if (thisMem.itemDescriptionPath != null && thisMem.itemDescriptionPath.length()>0) {
+ PropertyDescriptionList propList = PropertyUtility.getPropertyDescriptionOutcome(new DomainPath(thisMem.itemDescriptionPath).getSysKey());
+ for (PropertyDescription pd : propList.list) {
+ thisMem.props.put(pd.getName(), pd.getDefaultValue());
+ if (pd.getIsClassIdentifier())
+ classProps.append((classProps.length()>0?",":"")).append(pd.getName());
+ }
+ }
+ if (thisMem.itemPath != null && thisMem.itemPath.length()>0) {
+ int syskey = new DomainPath(thisMem.itemPath).getSysKey();
+ if (syskey == -1)
+ throw new MembershipException("Cannot find "+thisMem.itemPath+" specified for collection.");
+ newAgg.addMember(syskey, thisMem.props, classProps.toString(), new GraphPoint(thisMem.geometry.x, thisMem.geometry.y), thisMem.geometry.width, thisMem.geometry.height);
+ }
+ }
+ return newAgg;
+ }
+}
diff --git a/src/main/java/com/c2kernel/entity/imports/ImportAggregationMember.java b/src/main/java/com/c2kernel/entity/imports/ImportAggregationMember.java new file mode 100644 index 0000000..7a1cf21 --- /dev/null +++ b/src/main/java/com/c2kernel/entity/imports/ImportAggregationMember.java @@ -0,0 +1,33 @@ +package com.c2kernel.entity.imports;
+
+import com.c2kernel.utils.CastorHashMap;
+import com.c2kernel.utils.KeyValuePair;
+
+public class ImportAggregationMember implements java.io.Serializable {
+
+ public int slotNo;
+ public String itemDescriptionPath;
+ public String itemPath;
+ public Geometry geometry;
+ public CastorHashMap props = new CastorHashMap();
+
+
+ public ImportAggregationMember() {
+ super();
+ }
+
+ public ImportAggregationMember(int slotNo, String itemDescPath, String itemPath, Geometry geometry) {
+ this.slotNo = slotNo;
+ this.itemDescriptionPath = itemDescPath;
+ this.itemPath = itemPath;
+ this.geometry = geometry;
+ }
+
+ public KeyValuePair[] getKeyValuePairs() {
+ return props.getKeyValuePairs();
+ }
+
+ public void setKeyValuePairs(KeyValuePair[] pairs) {
+ props.setKeyValuePairs(pairs);
+ }
+}
diff --git a/src/main/java/com/c2kernel/entity/imports/ImportDependency.java b/src/main/java/com/c2kernel/entity/imports/ImportDependency.java new file mode 100644 index 0000000..e6ce909 --- /dev/null +++ b/src/main/java/com/c2kernel/entity/imports/ImportDependency.java @@ -0,0 +1,66 @@ +package com.c2kernel.entity.imports;
+
+import java.util.ArrayList;
+
+import com.c2kernel.collection.MembershipException;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.property.PropertyDescription;
+import com.c2kernel.property.PropertyDescriptionList;
+import com.c2kernel.property.PropertyUtility;
+import com.c2kernel.utils.CastorHashMap;
+import com.c2kernel.utils.KeyValuePair;
+
+public class ImportDependency implements java.io.Serializable {
+
+ public String name;
+ public boolean isDescription;
+ public String itemDescriptionPath;
+ public ArrayList<ImportDependencyMember> dependencyMemberList = new ArrayList<ImportDependencyMember>();
+ public CastorHashMap props = new CastorHashMap();
+
+ public ImportDependency() {
+ super();
+ }
+
+ public ImportDependency(String name) {
+ this();
+ this.name = name;
+ }
+
+ public KeyValuePair[] getKeyValuePairs() {
+ return props.getKeyValuePairs();
+ }
+
+ public void setKeyValuePairs(KeyValuePair[] pairs) {
+ props.setKeyValuePairs(pairs);
+ }
+
+ /**
+ * @return
+ */
+ public com.c2kernel.collection.Dependency create() throws MembershipException, ObjectNotFoundException {
+ com.c2kernel.collection.Dependency newDep = isDescription?new com.c2kernel.collection.DependencyDescription(name):new com.c2kernel.collection.Dependency(name);
+ if (itemDescriptionPath != null && itemDescriptionPath.length()>0) {
+ PropertyDescriptionList propList = PropertyUtility.getPropertyDescriptionOutcome(new DomainPath(itemDescriptionPath).getSysKey());
+ StringBuffer classProps = new StringBuffer();
+ for (PropertyDescription pd : propList.list) {
+ props.put(pd.getName(), pd.getDefaultValue());
+ if (pd.getIsClassIdentifier())
+ classProps.append((classProps.length()>0?",":"")).append(pd.getName());
+ }
+ newDep.setProperties(props);
+ newDep.setClassProps(classProps.toString());
+ }
+
+ for (ImportDependencyMember thisMem : dependencyMemberList) {
+ int syskey = new DomainPath(thisMem.itemPath).getSysKey();
+ if (syskey == -1)
+ throw new MembershipException("Cannot find "+thisMem.itemPath+" specified for collection.");
+ com.c2kernel.collection.DependencyMember newDepMem = newDep.addMember(syskey);
+ newDepMem.getProperties().putAll(thisMem.props);
+ }
+ return newDep;
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/entity/imports/ImportDependencyMember.java b/src/main/java/com/c2kernel/entity/imports/ImportDependencyMember.java new file mode 100644 index 0000000..6fc6b5a --- /dev/null +++ b/src/main/java/com/c2kernel/entity/imports/ImportDependencyMember.java @@ -0,0 +1,29 @@ +
+package com.c2kernel.entity.imports;
+
+import com.c2kernel.utils.CastorHashMap;
+import com.c2kernel.utils.KeyValuePair;
+
+public class ImportDependencyMember implements java.io.Serializable {
+
+
+ public String itemPath;
+ public CastorHashMap props = new CastorHashMap();
+
+ public ImportDependencyMember() {
+ super();
+ }
+
+ public ImportDependencyMember(String itemPath) {
+ this.itemPath = itemPath;
+
+ }
+
+ public KeyValuePair[] getKeyValuePairs() {
+ return props.getKeyValuePairs();
+ }
+
+ public void setKeyValuePairs(KeyValuePair[] pairs) {
+ props.setKeyValuePairs(pairs);
+ }
+}
diff --git a/src/main/java/com/c2kernel/entity/imports/ImportItem.java b/src/main/java/com/c2kernel/entity/imports/ImportItem.java new file mode 100644 index 0000000..a27d88d --- /dev/null +++ b/src/main/java/com/c2kernel/entity/imports/ImportItem.java @@ -0,0 +1,187 @@ +package com.c2kernel.entity.imports;
+
+
+import java.util.ArrayList;
+
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.XMLUnit;
+
+import com.c2kernel.collection.CollectionArrayList;
+import com.c2kernel.collection.MembershipException;
+import com.c2kernel.common.CannotManageException;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.ObjectAlreadyExistsException;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.entity.TraceableEntity;
+import com.c2kernel.events.Event;
+import com.c2kernel.events.History;
+import com.c2kernel.lifecycle.CompositeActivityDef;
+import com.c2kernel.lifecycle.instance.stateMachine.Transition;
+import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.lookup.ItemPath;
+import com.c2kernel.persistency.ClusterStorage;
+import com.c2kernel.persistency.ClusterStorageException;
+import com.c2kernel.persistency.outcome.Viewpoint;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.process.module.ModuleImport;
+import com.c2kernel.property.Property;
+import com.c2kernel.property.PropertyArrayList;
+import com.c2kernel.utils.LocalObjectLoader;
+import com.c2kernel.utils.Logger;
+
+/**
+ * Complete Structure for new item
+ *
+ * @version $Revision: 1.8 $ $Date: 2006/03/03 13:52:21 $
+ */
+
+public class ImportItem extends ModuleImport {
+
+ public String initialPath;
+ public String workflow;
+ public Integer workflowVer;
+ public ArrayList<Property> properties = new ArrayList<Property>();
+ public ArrayList<ImportAggregation> aggregationList = new ArrayList<ImportAggregation>();
+ public ArrayList<ImportDependency> dependencyList = new ArrayList<ImportDependency>();
+ public ArrayList<ImportOutcome> outcomes = new ArrayList<ImportOutcome>();
+ private String ns;
+
+ public ImportItem() {
+ }
+
+ public ImportItem(String name, String initialPath, String wf, int wfVer) {
+ this();
+ this.name = name;
+ this.initialPath = initialPath;
+ this.workflow = wf;
+ this.workflowVer = wfVer;
+ }
+
+ public void setNamespace(String ns) {
+ this.ns = ns;
+ if (initialPath == null) initialPath = "/desc/"+ns;
+ }
+
+ public String getNamespace() {
+ return ns;
+ }
+
+ public void create(int agentId, boolean reset) throws ObjectCannotBeUpdated, ObjectNotFoundException, CannotManageException, ObjectAlreadyExistsException {
+ DomainPath domPath = new DomainPath(new DomainPath(initialPath), name);
+
+ ItemPath entPath; TraceableEntity newItem;
+ if (domPath.exists()) {
+ entPath = domPath.getEntity();
+ newItem = Gateway.getCorbaServer().getItem(entPath.getSysKey());
+ }
+ else {
+ // create item
+ entPath = Gateway.getNextKeyManager().generateNextEntityKey();
+ newItem = (TraceableEntity)Gateway.getCorbaServer().createEntity(entPath);
+ Gateway.getLookup().add(entPath);
+ }
+
+ // set the name property
+ properties.add(new Property("Name", name, true));
+
+ // find workflow def
+ CompositeActivityDef compact;
+ // default workflow version is 0 if not given
+ int usedWfVer;
+ if (workflowVer == null) usedWfVer = 0;
+ else usedWfVer = workflowVer.intValue();
+ try {
+ compact = (CompositeActivityDef)LocalObjectLoader.getActDef(workflow, usedWfVer);
+ } catch (ObjectNotFoundException ex) {
+ throw new CannotManageException("Could not find workflow "+workflow+"v"+usedWfVer+" for item "+domPath, "");
+ } catch (InvalidDataException e) {
+ throw new CannotManageException("Workflow def "+workflow+" v"+usedWfVer+" for item "+domPath+" was not valid", "");
+ }
+
+ // create collections
+ CollectionArrayList colls = new CollectionArrayList();
+ for (ImportDependency element: dependencyList) {
+ try {
+ com.c2kernel.collection.Dependency newDep = element.create();
+ colls.put(newDep);
+ } catch (MembershipException ex) {
+ Logger.error(ex);
+ throw new CannotManageException("A specified member is not of the correct type in "+element.name, "");
+ }
+ }
+
+ for (ImportAggregation element : aggregationList) {
+ try {
+ com.c2kernel.collection.Aggregation newAgg = element.create();
+ colls.put(newAgg);
+ } catch (MembershipException ex) {
+ Logger.error(ex);
+ throw new CannotManageException("A specified member is not of the correct type in "+element.name, "");
+ }
+ }
+
+ // (re)initialise the new item with properties, workflow and collections
+ try {
+ newItem.initialise(
+ agentId,
+ Gateway.getMarshaller().marshall(new PropertyArrayList(properties)),
+ Gateway.getMarshaller().marshall(compact.instantiate()),
+ Gateway.getMarshaller().marshall(colls));
+ } catch (Exception ex) {
+ Logger.error("Error initialising new item "+name );
+ Logger.error(ex);
+ throw new CannotManageException("Problem initialising new item. See server log.", "");
+ }
+
+ // import outcomes
+ XMLUnit.setIgnoreWhitespace(true);
+ XMLUnit.setIgnoreComments(true);
+ History hist = new History(entPath.getSysKey(), null);
+ for (ImportOutcome thisOutcome : outcomes) {
+ com.c2kernel.persistency.outcome.Outcome newOutcome = new com.c2kernel.persistency.outcome.Outcome(-1, thisOutcome.getData(ns), thisOutcome.schema, thisOutcome.version);
+ Viewpoint impView;
+ try {
+ impView = (Viewpoint)Gateway.getStorage().get(entPath.getSysKey(), ClusterStorage.VIEWPOINT+"/"+thisOutcome.schema+"/"+thisOutcome.viewname, null);
+
+ Diff xmlDiff = new Diff(newOutcome.getDOM(), impView.getOutcome().getDOM());
+ if (xmlDiff.identical()) {
+ Logger.msg(5, "NewItem.create() - View "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name+" identical, no update required");
+ continue;
+ }
+ else {
+ Logger.msg("NewItem.create() - Difference found in view "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name+": "+xmlDiff.toString());
+ if (!reset && !impView.getEvent().getStepPath().equals("Import")) {
+ Logger.msg("Last edit was not done by import, and reset not requested. Not overwriting.");
+ continue;
+ }
+ }
+ } catch (ObjectNotFoundException ex) {
+ Logger.msg(3, "View "+thisOutcome.schema+"/"+thisOutcome.viewname+" not found in "+name+". Creating.");
+ impView = new Viewpoint(entPath.getSysKey(), thisOutcome.schema, thisOutcome.viewname, thisOutcome.version, -1);
+ } catch (ClusterStorageException e) {
+ throw new ObjectCannotBeUpdated("Could not check data for view "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name);
+ } catch (InvalidDataException e) {
+ throw new ObjectCannotBeUpdated("Could not check previous event for view "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name);
+ }
+
+ // write new view/outcome/event
+ Transition predefDone = new Transition(0, "Done", 0, 0);
+ Event newEvent = hist.addEvent("system", "Admin", "Import", "Import", "Import", thisOutcome.schema, thisOutcome.version, "PredefinedStep", 0, predefDone, thisOutcome.viewname);
+ newOutcome.setID(newEvent.getID());
+ impView.setEventId(newEvent.getID());
+ try {
+ Gateway.getStorage().put(entPath.getSysKey(), newOutcome, null);
+ Gateway.getStorage().put(entPath.getSysKey(), impView, null);
+ } catch (ClusterStorageException e) {
+ throw new ObjectCannotBeUpdated("Could not store data for view "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name);
+ }
+ }
+
+ // register domain path (before collections in case of recursive collections)
+ if (!domPath.exists()) {
+ domPath.setEntity(entPath);
+ Gateway.getLookup().add(domPath);
+ }
+ }
+}
diff --git a/src/main/java/com/c2kernel/entity/imports/ImportOutcome.java b/src/main/java/com/c2kernel/entity/imports/ImportOutcome.java new file mode 100644 index 0000000..1428483 --- /dev/null +++ b/src/main/java/com/c2kernel/entity/imports/ImportOutcome.java @@ -0,0 +1,27 @@ +package com.c2kernel.entity.imports;
+
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.process.Gateway;
+
+public class ImportOutcome {
+ public String schema, viewname, path, data;
+ public int version;
+
+ public ImportOutcome() {
+ }
+
+ public ImportOutcome(String schema, int version, String viewname, String path) {
+ super();
+ this.schema = schema;
+ this.version = version;
+ this.viewname = viewname;
+ this.path = path;
+ }
+
+ public String getData(String ns) throws ObjectNotFoundException {
+ if (data == null)
+ data = Gateway.getResource().getTextResource(ns, path);
+ return data;
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/entity/imports/ImportRole.java b/src/main/java/com/c2kernel/entity/imports/ImportRole.java new file mode 100644 index 0000000..8313c24 --- /dev/null +++ b/src/main/java/com/c2kernel/entity/imports/ImportRole.java @@ -0,0 +1,19 @@ +package com.c2kernel.entity.imports;
+
+import com.c2kernel.common.ObjectAlreadyExistsException;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.process.module.ModuleImport;
+
+public class ImportRole extends ModuleImport {
+
+ public boolean jobList;
+
+ public ImportRole() {
+ }
+
+ public void create(int agentId) throws ObjectAlreadyExistsException, ObjectCannotBeUpdated {
+ Gateway.getLookup().createRole(name, jobList);
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java b/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java index f76af10..e5a52f0 100644 --- a/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java +++ b/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java @@ -11,7 +11,7 @@ package com.c2kernel.entity.proxy;
import java.util.Date;
-import java.util.Enumeration;
+import java.util.Iterator;
import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
@@ -22,17 +22,17 @@ import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.Agent;
import com.c2kernel.entity.AgentHelper;
import com.c2kernel.entity.C2KLocalObject;
-import com.c2kernel.entity.ManageableEntity;
import com.c2kernel.entity.agent.Job;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
-import com.c2kernel.lookup.EntityPath;
-import com.c2kernel.lookup.InvalidEntityPathException;
+import com.c2kernel.lookup.InvalidItemPathException;
+import com.c2kernel.lookup.ItemPath;
import com.c2kernel.lookup.Path;
import com.c2kernel.persistency.outcome.OutcomeValidator;
import com.c2kernel.persistency.outcome.Schema;
import com.c2kernel.process.Gateway;
+import com.c2kernel.process.auth.Authenticator;
import com.c2kernel.scripting.ErrorInfo;
import com.c2kernel.scripting.Script;
import com.c2kernel.scripting.ScriptErrorException;
@@ -47,51 +47,43 @@ import com.c2kernel.utils.Logger; * @version $Revision: 1.37 $ $Date: 2005/10/05 07:39:36 $
* @author $Author: abranson $
******************************************************************************/
-public class AgentProxy extends EntityProxy
+public class AgentProxy extends ItemProxy
{
- AgentPath path;
+ AgentPath agentPath;
+ Authenticator auth;
/**************************************************************************
* Creates an AgentProxy without cache and change notification
**************************************************************************/
- public AgentProxy( org.omg.CORBA.Object ior,
+ protected AgentProxy( org.omg.CORBA.Object ior,
int systemKey)
throws ObjectNotFoundException
{
- super(ior, systemKey);
- try {
- path = new AgentPath(systemKey);
- } catch (InvalidEntityPathException e) {
+ super(ior, systemKey);
+ try {
+ agentPath = new AgentPath(systemKey);
+ mPath = agentPath;
+ } catch (InvalidItemPathException e) {
throw new ObjectNotFoundException();
}
}
- @Override
- public ManageableEntity narrow() throws ObjectNotFoundException
+ public Authenticator getAuthObj() {
+ return auth;
+ }
+
+ public void setAuthObj(Authenticator auth) {
+ this.auth = auth;
+ }
+
+ @Override
+ public Agent narrow() throws ObjectNotFoundException
{
try {
return AgentHelper.narrow(mIOR);
} catch (org.omg.CORBA.BAD_PARAM ex) { }
throw new ObjectNotFoundException("CORBA Object was not an Agent, or the server is down.");
}
- /**************************************************************************
- *
- *
- **************************************************************************/
- public void initialise( String agentProps, String collector )
- throws AccessRightsException,
- InvalidDataException,
- PersistencyException,
- ObjectNotFoundException
- {
- Logger.msg(7, "AgentProxy::initialise - started");
-
- ((Agent)getEntity()).initialise( agentProps );
- }
-
- public AgentPath getPath() {
- return path;
- }
/**
* Executes a job on the given item using this agent.
@@ -100,7 +92,7 @@ public class AgentProxy extends EntityProxy * @param job - the job to execute
* @throws ScriptErrorException
*/
- public void execute(ItemProxy item, Job job)
+ public String execute(ItemProxy item, Job job)
throws AccessRightsException,
InvalidTransitionException,
ObjectNotFoundException,
@@ -111,7 +103,7 @@ public class AgentProxy extends EntityProxy {
OutcomeValidator validator = null;
Date startTime = new Date();
- Logger.msg(3, "AgentProxy - executing "+job.getStepPath()+" for "+path.getAgentName());
+ Logger.msg(3, "AgentProxy - executing "+job.getStepPath()+" for "+agentPath.getAgentName());
// get the outcome validator if present
if (job.hasOutcome())
{
@@ -170,12 +162,14 @@ public class AgentProxy extends EntityProxy job.setAgentId(getSystemKey());
Logger.msg(3, "AgentProxy - submitting job to item proxy");
- item.requestAction(job);
+ String result = item.requestAction(job);
if (Logger.doLog(3)) {
Date timeNow = new Date();
long secsNow = (timeNow.getTime()-startTime.getTime())/1000;
Logger.msg(3, "Execution took "+secsNow+" seconds");
}
+
+ return result;
}
private Object callScript(ItemProxy item, Job job) throws ScriptingEngineException {
@@ -196,7 +190,7 @@ public class AgentProxy extends EntityProxy * @throws ObjectAlreadyExistsException
* @throws ScriptErrorException
*/
- public void execute(Job job)
+ public String execute(Job job)
throws AccessRightsException,
InvalidDataException,
InvalidTransitionException,
@@ -206,14 +200,14 @@ public class AgentProxy extends EntityProxy ScriptErrorException
{
try {
- ItemProxy targetItem = (ItemProxy)Gateway.getProxyManager().getProxy(new EntityPath(job.getItemSysKey()));
- execute(targetItem, job);
- } catch (InvalidEntityPathException e) {
+ ItemProxy targetItem = Gateway.getProxyManager().getProxy(new ItemPath(job.getItemSysKey()));
+ return execute(targetItem, job);
+ } catch (InvalidItemPathException e) {
throw new ObjectNotFoundException("Job contained invalid item sysKey: "+job.getItemSysKey(), "");
}
}
- public void execute(ItemProxy item, String predefStep, C2KLocalObject obj)
+ public String execute(ItemProxy item, String predefStep, C2KLocalObject obj)
throws AccessRightsException,
InvalidDataException,
InvalidTransitionException,
@@ -228,10 +222,10 @@ public class AgentProxy extends EntityProxy Logger.error(ex);
throw new InvalidDataException("Error on marshall", "");
}
- execute(item, predefStep, param);
+ return execute(item, predefStep, param);
}
- public void execute(ItemProxy item, String predefStep, String... params)
+ public String execute(ItemProxy item, String predefStep, String... params)
throws AccessRightsException,
InvalidDataException,
InvalidTransitionException,
@@ -239,7 +233,7 @@ public class AgentProxy extends EntityProxy PersistencyException,
ObjectAlreadyExistsException
{
- item.requestAction(getSystemKey(), "workflow/predefined/"+predefStep, PredefinedStep.DONE, PredefinedStep.bundleData(params));
+ return item.getItem().requestAction(getSystemKey(), "workflow/predefined/"+predefStep, PredefinedStep.DONE, PredefinedStep.bundleData(params));
}
/** Wrappers for scripts */
@@ -253,31 +247,36 @@ public class AgentProxy extends EntityProxy /** Let scripts resolve items */
public ItemProxy searchItem(String name) throws ObjectNotFoundException {
- Enumeration<Path> results = Gateway.getLDAPLookup().search(new DomainPath(""),name);
+ Iterator<Path> results = Gateway.getLookup().search(new DomainPath(""),name);
Path returnPath = null;
- if (!results.hasMoreElements())
+ if (!results.hasNext())
throw new ObjectNotFoundException(name, "");
- while(results.hasMoreElements()) {
- Path nextMatch = results.nextElement();
+ while(results.hasNext()) {
+ Path nextMatch = results.next();
if (returnPath != null && nextMatch.getSysKey() != -1 && returnPath.getSysKey() != nextMatch.getSysKey())
throw new ObjectNotFoundException("Too many items with that name");
returnPath = nextMatch;
}
- return (ItemProxy)Gateway.getProxyManager().getProxy(returnPath);
+ return Gateway.getProxyManager().getProxy(returnPath);
}
public ItemProxy getItem(String itemPath) throws ObjectNotFoundException {
return (getItem(new DomainPath(itemPath)));
}
- public ItemProxy getItem(Path itemPath) throws ObjectNotFoundException {
- return (ItemProxy)Gateway.getProxyManager().getProxy(itemPath);
+ @Override
+ public AgentPath getPath() {
+ return agentPath;
+ }
+
+ public ItemProxy getItem(Path itemPath) throws ObjectNotFoundException {
+ return Gateway.getProxyManager().getProxy(itemPath);
}
- public ItemProxy getItemBySysKey(int sysKey) throws ObjectNotFoundException, InvalidEntityPathException {
- return (ItemProxy)Gateway.getProxyManager().getProxy(new EntityPath(sysKey));
+ public ItemProxy getItemBySysKey(int sysKey) throws ObjectNotFoundException, InvalidItemPathException {
+ return Gateway.getProxyManager().getProxy(new ItemPath(sysKey));
}
}
diff --git a/src/main/java/com/c2kernel/entity/proxy/EntityProxy.java b/src/main/java/com/c2kernel/entity/proxy/EntityProxy.java deleted file mode 100644 index cb76a19..0000000 --- a/src/main/java/com/c2kernel/entity/proxy/EntityProxy.java +++ /dev/null @@ -1,247 +0,0 @@ -/**************************************************************************
- * EntityProxy.java
- *
- * $Revision: 1.35 $
- * $Date: 2005/05/10 11:40:09 $
- *
- * Copyright (C) 2001 CERN - European Organization for Nuclear Research
- * All rights reserved.
- **************************************************************************/
-
-package com.c2kernel.entity.proxy;
-
-import java.util.HashMap;
-import java.util.Iterator;
-
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.entity.C2KLocalObject;
-import com.c2kernel.entity.ManageableEntity;
-import com.c2kernel.persistency.ClusterStorageException;
-import com.c2kernel.process.Gateway;
-import com.c2kernel.property.Property;
-import com.c2kernel.utils.Logger;
-
-
-/******************************************************************************
-* It is a wrapper for the connection and communication with Entities.
-* It can cache data loaded from the Entity to reduce communication with it.
-* This cache is syncronised with corresponding Entity through an event mechanism.
-*
-* @version $Revision: 1.35 $ $Date: 2005/05/10 11:40:09 $
-* @author $Author: abranson $
-******************************************************************************/
-
-abstract public class EntityProxy implements ManageableEntity
-{
-
- protected ManageableEntity mEntity = null;
- protected org.omg.CORBA.Object mIOR;
- protected int mSystemKey;
- private HashMap<MemberSubscription<?>, EntityProxyObserver<?>> mSubscriptions;
-
- /**************************************************************************
- *
- **************************************************************************/
- protected EntityProxy( org.omg.CORBA.Object ior,
- int systemKey)
- throws ObjectNotFoundException
- {
- Logger.msg(8,"EntityProxy::EntityProxy() - Initialising '" +systemKey+ "' entity");
-
- initialise( ior, systemKey);
- }
-
- /**************************************************************************
- *
- **************************************************************************/
- private void initialise( org.omg.CORBA.Object ior,
- int systemKey)
- throws ObjectNotFoundException
- {
- Logger.msg(8, "EntityProxy::initialise() - Initialising '" +systemKey+ "' entity");
-
- mIOR = ior;
- mSystemKey = systemKey;
- mSubscriptions = new HashMap<MemberSubscription<?>, EntityProxyObserver<?>>();
- }
-
-
- /**************************************************************************
- *
- **************************************************************************/
- public ManageableEntity getEntity() throws ObjectNotFoundException
- {
- if (mEntity == null) {
- mEntity = narrow();
- }
- return mEntity;
- }
-
- abstract public ManageableEntity narrow() throws ObjectNotFoundException;
-
- /**************************************************************************
- *
- **************************************************************************/
- //check who is using.. and if toString() is sufficient
- @Override
- public int getSystemKey()
- {
- return mSystemKey;
- }
-
-
- /**************************************************************************
- *
- **************************************************************************/
- @Override
- public String queryData( String path )
- throws ObjectNotFoundException
- {
-
- try {
- Logger.msg(7, "EntityProxy.queryData() - "+mSystemKey+"/"+path);
- if (path.endsWith("all")) {
- Logger.msg(7, "EntityProxy.queryData() - listing contents");
- String[] result = Gateway.getStorage().getClusterContents(mSystemKey, path.substring(0, path.length()-3));
- StringBuffer retString = new StringBuffer();
- for (int i = 0; i < result.length; i++) {
- retString.append(result[i]);
- if (i<result.length-1) retString.append(",");
- }
- Logger.msg(7, "EntityProxy.queryData() - "+retString.toString());
- return retString.toString();
- }
- C2KLocalObject target = Gateway.getStorage().get(mSystemKey, path, null);
- return Gateway.getMarshaller().marshall(target);
- } catch (ObjectNotFoundException e) {
- throw e;
- } catch (Exception e) {
- Logger.error(e);
- return "<ERROR>"+e.getMessage()+"</ERROR>";
- }
- }
-
- public String[] getContents( String path ) throws ObjectNotFoundException {
- try {
- return Gateway.getStorage().getClusterContents(mSystemKey, path.substring(0, path.length()));
- } catch (ClusterStorageException e) {
- throw new ObjectNotFoundException(e.toString());
- }
- }
-
-
- /**************************************************************************
- *
- **************************************************************************/
- public C2KLocalObject getObject( String xpath )
- throws ObjectNotFoundException
- {
- // load from storage, falling back to proxy loader if not found in others
- try
- {
- return Gateway.getStorage().get( mSystemKey, xpath , null);
- }
- catch( ClusterStorageException ex )
- {
- Logger.msg(4, "Exception loading object :"+mSystemKey+"/"+xpath);
- throw new ObjectNotFoundException( ex.toString() );
- }
- }
-
-
-
- public String getProperty( String name )
- throws ObjectNotFoundException
- {
- Logger.msg(5, "Get property "+name+" from syskey/"+mSystemKey);
- Property prop = (Property)getObject("Property/"+name);
- try
- {
- return prop.getValue();
- }
- catch (NullPointerException ex)
- {
- throw new ObjectNotFoundException();
- }
- }
-
- public String getName()
- {
- try {
- return getProperty("Name");
- } catch (ObjectNotFoundException ex) {
- return null;
- }
- }
-
-
- /**************************************************************************
- * Subscription methods
- **************************************************************************/
-
- public void subscribe (MemberSubscription<?> newSub) {
-
- newSub.setSubject(this);
- synchronized (this){
- mSubscriptions.put( newSub, newSub.getObserver() );
- }
- new Thread(newSub).start();
- Logger.msg(7, "Subscribed "+newSub.getObserver().getClass().getName()+" for "+newSub.interest);
- }
-
- public void unsubscribe(EntityProxyObserver<?> observer)
- {
- synchronized (this){
- for (Iterator<MemberSubscription<?>> e = mSubscriptions.keySet().iterator(); e.hasNext();) {
- MemberSubscription<?> thisSub = e.next();
- if (mSubscriptions.get( thisSub ) == observer) {
- e.remove();
- Logger.msg(7, "Unsubscribed "+observer.getClass().getName());
- }
- }
- }
- }
-
- public void dumpSubscriptions(int logLevel) {
- if (mSubscriptions.size() == 0) return;
- Logger.msg(logLevel, "Subscriptions to proxy "+mSystemKey+":");
- synchronized(this) {
- for (MemberSubscription<?> element : mSubscriptions.keySet()) {
- EntityProxyObserver<?> obs = element.getObserver();
- if (obs != null)
- Logger.msg(logLevel, " "+element.getObserver().getClass().getName()+" subscribed to "+element.interest);
- else
- Logger.msg(logLevel, " Phantom subscription to "+element.interest);
- }
- }
- }
-
- public void notify(ProxyMessage message) {
- Logger.msg(4, "EntityProxy.notify() - Received change notification for "+message.getPath()+" on "+mSystemKey);
- synchronized (this){
- if (!message.getServer().equals(EntityProxyManager.serverName))
- Gateway.getStorage().clearCache(mSystemKey, message.getPath());
- for (Iterator<MemberSubscription<?>> e = mSubscriptions.keySet().iterator(); e.hasNext();) {
- MemberSubscription<?> newSub = e.next();
- if (newSub.getObserver() == null) { // phantom
- Logger.msg(4, "Removing phantom subscription to "+newSub.interest);
- e.remove();
- }
- else
- newSub.update(message.getPath(), message.getState());
- }
- }
- }
-
- /**
- * If this is reaped, clear out the cache for it too.
- */
- @Override
- protected void finalize() throws Throwable {
- Logger.msg(7, "Proxy "+mSystemKey+" reaped");
- Gateway.getStorage().clearCache(mSystemKey, null);
- Gateway.getProxyManager().removeProxy(mSystemKey);
- super.finalize();
- }
-
-}
diff --git a/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java b/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java index 0e6859d..454da6d 100644 --- a/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java +++ b/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java @@ -10,25 +10,40 @@ package com.c2kernel.entity.proxy;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.exolab.castor.mapping.MappingException;
+import org.exolab.castor.xml.MarshalException;
+import org.exolab.castor.xml.ValidationException;
import com.c2kernel.collection.Collection;
-import com.c2kernel.collection.CollectionMember;
+import com.c2kernel.collection.CollectionArrayList;
import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.common.ObjectAlreadyExistsException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.common.PersistencyException;
+import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.entity.Item;
import com.c2kernel.entity.ItemHelper;
-import com.c2kernel.entity.ManageableEntity;
import com.c2kernel.entity.agent.Job;
import com.c2kernel.entity.agent.JobArrayList;
+import com.c2kernel.lifecycle.instance.CompositeActivity;
import com.c2kernel.lifecycle.instance.Workflow;
+import com.c2kernel.lookup.InvalidItemPathException;
+import com.c2kernel.lookup.ItemPath;
+import com.c2kernel.lookup.Path;
import com.c2kernel.persistency.ClusterStorage;
+import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.Gateway;
+import com.c2kernel.property.Property;
+import com.c2kernel.property.PropertyArrayList;
+import com.c2kernel.utils.CastorXMLUtility;
import com.c2kernel.utils.Logger;
/******************************************************************************
@@ -38,43 +53,86 @@ import com.c2kernel.utils.Logger; * @version $Revision: 1.25 $ $Date: 2005/05/10 11:40:09 $
* @author $Author: abranson $
******************************************************************************/
-public class ItemProxy extends EntityProxy
+public class ItemProxy
{
+ protected Item mItem = null;
+ protected org.omg.CORBA.Object mIOR;
+ protected int mSystemKey;
+ protected Path mPath;
+ private final HashMap<MemberSubscription<?>, ProxyObserver<?>>
+ mSubscriptions;
+
/**************************************************************************
- *
+ *
**************************************************************************/
protected ItemProxy( org.omg.CORBA.Object ior,
int systemKey)
throws ObjectNotFoundException
{
- super(ior, systemKey);
+ Logger.msg(8, "ItemProxy::initialise() - Initialising entity " +systemKey);
+
+ mIOR = ior;
+ mSystemKey = systemKey;
+ mSubscriptions = new HashMap<MemberSubscription<?>, ProxyObserver<?>>();
+ try {
+ mPath = new ItemPath(systemKey);
+ } catch (InvalidItemPathException e) {
+ throw new ObjectNotFoundException();
+ }
}
+
+ public int getSystemKey()
+ {
+ return mSystemKey;
+ }
+
+ public Path getPath() {
+ return mPath;
+ }
+
+ protected Item getItem() throws ObjectNotFoundException {
+ if (mItem == null)
+ mItem = narrow();
+ return mItem;
+ }
- @Override
- public ManageableEntity narrow() throws ObjectNotFoundException
+ public Item narrow() throws ObjectNotFoundException
{
try {
return ItemHelper.narrow(mIOR);
} catch (org.omg.CORBA.BAD_PARAM ex) { }
throw new ObjectNotFoundException("CORBA Object was not an Item, or the server is down.");
}
- /**************************************************************************
+ /**
+ * @throws MappingException
+ * @throws IOException
+ * @throws ValidationException
+ * @throws MarshalException ************************************************************************
*
*
**************************************************************************/
- public void initialise( int agentId,
- String itemProps,
- String workflow )
+ public void initialise( int agentId,
+ PropertyArrayList itemProps,
+ CompositeActivity workflow,
+ CollectionArrayList colls
+ )
throws AccessRightsException,
InvalidDataException,
PersistencyException,
- ObjectNotFoundException
+ ObjectNotFoundException, MarshalException, ValidationException, IOException, MappingException
{
Logger.msg(7, "ItemProxy::initialise - started");
-
- ((Item)getEntity()).initialise( agentId, itemProps, workflow );
+ CastorXMLUtility xml = Gateway.getMarshaller();
+ if (itemProps == null) throw new InvalidDataException("No initial properties supplied");
+ String propString = xml.marshall(itemProps);
+ String wfString = "";
+ if (workflow != null) wfString = xml.marshall(workflow);
+ String collString = "";
+ if (colls != null) collString = xml.marshall(colls);
+
+ getItem().initialise( agentId, propString, wfString, collString);
}
public void setProperty(AgentProxy agent, String name, String value)
@@ -100,7 +158,7 @@ public class ItemProxy extends EntityProxy /**************************************************************************
*
**************************************************************************/
- protected void requestAction( Job thisJob )
+ public String requestAction( Job thisJob )
throws AccessRightsException,
InvalidTransitionException,
ObjectNotFoundException,
@@ -120,44 +178,10 @@ public class ItemProxy extends EntityProxy throw new InvalidDataException("No Agent specified.", "");
Logger.msg(7, "ItemProxy - executing "+thisJob.getStepPath()+" for "+thisJob.getAgentName());
- requestAction (thisJob.getAgentId(), thisJob.getStepPath(),
+ return getItem().requestAction (thisJob.getAgentId(), thisJob.getStepPath(),
thisJob.getTransition().getId(), outcome);
}
- //requestData is xmlString
- public void requestAction( int agentId,
- String stepPath,
- int transitionID,
- String requestData
- )
- throws AccessRightsException,
- InvalidTransitionException,
- ObjectNotFoundException,
- InvalidDataException,
- PersistencyException,
- ObjectAlreadyExistsException
- {
- ((Item)getEntity()).requestAction( agentId,
- stepPath,
- transitionID,
- requestData );
- }
-
- /**************************************************************************
- *
- **************************************************************************/
- public String queryLifeCycle( int agentId,
- boolean filter
- )
- throws AccessRightsException,
- ObjectNotFoundException,
- PersistencyException
- {
- return ((Item)getEntity()).queryLifeCycle( agentId,
- filter );
- }
-
-
/**************************************************************************
*
**************************************************************************/
@@ -168,7 +192,7 @@ public class ItemProxy extends EntityProxy {
JobArrayList thisJobList;
try {
- String jobs = queryLifeCycle(agentId, filter);
+ String jobs = getItem().queryLifeCycle(agentId, filter);
thisJobList = (JobArrayList)Gateway.getMarshaller().unmarshall(jobs);
}
catch (Exception e) {
@@ -208,8 +232,8 @@ public class ItemProxy extends EntityProxy }
- public Collection<? extends CollectionMember> getCollection(String collName) throws ObjectNotFoundException {
- return (Collection<? extends CollectionMember>)getObject(ClusterStorage.COLLECTION+"/"+collName);
+ public Collection<?> getCollection(String collName) throws ObjectNotFoundException {
+ return (Collection<?>)getObject(ClusterStorage.COLLECTION+"/"+collName);
}
public Workflow getWorkflow() throws ObjectNotFoundException {
@@ -226,4 +250,159 @@ public class ItemProxy extends EntityProxy PersistencyException {
return getJobByName(actName, agent.getSystemKey());
}
+
+ /**
+ * If this is reaped, clear out the cache for it too.
+ */
+ @Override
+ protected void finalize() throws Throwable {
+ Logger.msg(7, "Proxy "+mSystemKey+" reaped");
+ Gateway.getStorage().clearCache(mSystemKey, null);
+ Gateway.getProxyManager().removeProxy(mSystemKey);
+ super.finalize();
+ }
+
+ /**************************************************************************
+ *
+ **************************************************************************/
+ public String queryData( String path )
+ throws ObjectNotFoundException
+ {
+
+ try {
+ Logger.msg(7, "EntityProxy.queryData() - "+mSystemKey+"/"+path);
+ if (path.endsWith("all")) {
+ Logger.msg(7, "EntityProxy.queryData() - listing contents");
+ String[] result = Gateway.getStorage().getClusterContents(mSystemKey, path.substring(0, path.length()-3));
+ StringBuffer retString = new StringBuffer();
+ for (int i = 0; i < result.length; i++) {
+ retString.append(result[i]);
+ if (i<result.length-1) retString.append(",");
+ }
+ Logger.msg(7, "EntityProxy.queryData() - "+retString.toString());
+ return retString.toString();
+ }
+ C2KLocalObject target = Gateway.getStorage().get(mSystemKey, path, null);
+ return Gateway.getMarshaller().marshall(target);
+ } catch (ObjectNotFoundException e) {
+ throw e;
+ } catch (Exception e) {
+ Logger.error(e);
+ return "<ERROR>"+e.getMessage()+"</ERROR>";
+ }
+ }
+
+ public String[] getContents( String path ) throws ObjectNotFoundException {
+ try {
+ return Gateway.getStorage().getClusterContents(mSystemKey, path.substring(0, path.length()));
+ } catch (ClusterStorageException e) {
+ throw new ObjectNotFoundException(e.toString());
+ }
+ }
+
+
+ /**************************************************************************
+ *
+ **************************************************************************/
+ public C2KLocalObject getObject( String xpath )
+ throws ObjectNotFoundException
+ {
+ // load from storage, falling back to proxy loader if not found in others
+ try
+ {
+ return Gateway.getStorage().get( mSystemKey, xpath , null);
+ }
+ catch( ClusterStorageException ex )
+ {
+ Logger.msg(4, "Exception loading object :"+mSystemKey+"/"+xpath);
+ throw new ObjectNotFoundException( ex.toString() );
+ }
+ }
+
+
+
+ public String getProperty( String name )
+ throws ObjectNotFoundException
+ {
+ Logger.msg(5, "Get property "+name+" from syskey/"+mSystemKey);
+ Property prop = (Property)getObject("Property/"+name);
+ try
+ {
+ return prop.getValue();
+ }
+ catch (NullPointerException ex)
+ {
+ throw new ObjectNotFoundException();
+ }
+ }
+
+ public String getName()
+ {
+ try {
+ return getProperty("Name");
+ } catch (ObjectNotFoundException ex) {
+ return null;
+ }
+ }
+
+
+
+
+ /**************************************************************************
+ * Subscription methods
+ **************************************************************************/
+
+ public void subscribe(MemberSubscription<?> newSub) {
+
+ newSub.setSubject(this);
+ synchronized (this){
+ mSubscriptions.put( newSub, newSub.getObserver() );
+ }
+ new Thread(newSub).start();
+ Logger.msg(7, "Subscribed "+newSub.getObserver().getClass().getName()+" for "+newSub.interest);
+ }
+
+ public void unsubscribe(ProxyObserver<?> observer)
+ {
+ synchronized (this){
+ for (Iterator<MemberSubscription<?>> e = mSubscriptions.keySet().iterator(); e.hasNext();) {
+ MemberSubscription<?> thisSub = e.next();
+ if (mSubscriptions.get( thisSub ) == observer) {
+ e.remove();
+ Logger.msg(7, "Unsubscribed "+observer.getClass().getName());
+ }
+ }
+ }
+ }
+
+ public void dumpSubscriptions(int logLevel) {
+ if (mSubscriptions.size() == 0) return;
+ Logger.msg(logLevel, "Subscriptions to proxy "+mSystemKey+":");
+ synchronized(this) {
+ for (MemberSubscription<?> element : mSubscriptions.keySet()) {
+ ProxyObserver<?> obs = element.getObserver();
+ if (obs != null)
+ Logger.msg(logLevel, " "+element.getObserver().getClass().getName()+" subscribed to "+element.interest);
+ else
+ Logger.msg(logLevel, " Phantom subscription to "+element.interest);
+ }
+ }
+ }
+
+ public void notify(ProxyMessage message) {
+ Logger.msg(4, "EntityProxy.notify() - Received change notification for "+message.getPath()+" on "+mSystemKey);
+ synchronized (this){
+ if (Gateway.getProxyServer()== null || !message.getServer().equals(Gateway.getProxyServer().getServerName()))
+ Gateway.getStorage().clearCache(mSystemKey, message.getPath());
+ for (Iterator<MemberSubscription<?>> e = mSubscriptions.keySet().iterator(); e.hasNext();) {
+ MemberSubscription<?> newSub = e.next();
+ if (newSub.getObserver() == null) { // phantom
+ Logger.msg(4, "Removing phantom subscription to "+newSub.interest);
+ e.remove();
+ }
+ else
+ newSub.update(message.getPath(), message.getState());
+ }
+ }
+ }
}
diff --git a/src/main/java/com/c2kernel/entity/proxy/MemberSubscription.java b/src/main/java/com/c2kernel/entity/proxy/MemberSubscription.java index 1de18f8..01994e4 100644 --- a/src/main/java/com/c2kernel/entity/proxy/MemberSubscription.java +++ b/src/main/java/com/c2kernel/entity/proxy/MemberSubscription.java @@ -12,14 +12,14 @@ public class MemberSubscription<C extends C2KLocalObject> implements Runnable { public static final String ERROR = "Error";
public static final String END = "theEND";
- EntityProxy subject;
+ ItemProxy subject;
String interest;
// keep the subscriber by weak reference, so it is not kept from the garbage collector if no longer used
- WeakReference<EntityProxyObserver<C>> observerReference;
+ WeakReference<ProxyObserver<C>> observerReference;
ArrayList<String> contents = new ArrayList<String>();
boolean preLoad;
- public MemberSubscription(EntityProxyObserver<C> observer, String interest, boolean preLoad) {
+ public MemberSubscription(ProxyObserver<C> observer, String interest, boolean preLoad) {
setObserver(observer);
this.interest = interest;
this.preLoad = preLoad;
@@ -33,7 +33,7 @@ public class MemberSubscription<C extends C2KLocalObject> implements Runnable { private void loadChildren() {
C newMember;
- EntityProxyObserver<C> observer = getObserver();
+ ProxyObserver<C> observer = getObserver();
if (observer == null) return; //reaped
try {
// fetch contents of path
@@ -77,7 +77,7 @@ public class MemberSubscription<C extends C2KLocalObject> implements Runnable { }
public void update(String path, boolean deleted) {
- EntityProxyObserver<C> observer = getObserver();
+ ProxyObserver<C> observer = getObserver();
if (observer == null) return; //reaped
Logger.msg(7, "Processing proxy message path "+path +" for "+observer+". Interest: "+interest+" Was Deleted:"+deleted);
if (!path.startsWith(interest)) // doesn't concern us
@@ -106,15 +106,15 @@ public class MemberSubscription<C extends C2KLocalObject> implements Runnable { }
}
- public void setObserver(EntityProxyObserver<C> observer) {
- observerReference = new WeakReference<EntityProxyObserver<C>>(observer);
+ public void setObserver(ProxyObserver<C> observer) {
+ observerReference = new WeakReference<ProxyObserver<C>>(observer);
}
- public void setSubject(EntityProxy subject) {
+ public void setSubject(ItemProxy subject) {
this.subject = subject;
}
- public EntityProxyObserver<C> getObserver() {
+ public ProxyObserver<C> getObserver() {
return observerReference.get();
}
}
diff --git a/src/main/java/com/c2kernel/entity/proxy/ProxyClientConnection.java b/src/main/java/com/c2kernel/entity/proxy/ProxyClientConnection.java index 9687f22..3a7e129 100644 --- a/src/main/java/com/c2kernel/entity/proxy/ProxyClientConnection.java +++ b/src/main/java/com/c2kernel/entity/proxy/ProxyClientConnection.java @@ -11,6 +11,7 @@ import java.util.ArrayList; import java.util.Iterator;
import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
import com.c2kernel.utils.server.SocketHandler;
@@ -36,7 +37,7 @@ public class ProxyClientConnection implements SocketHandler { public ProxyClientConnection() {
super();
thisClientId = ++clientId;
- EntityProxyManager.registerProxyClient(this);
+ Gateway.getProxyServer().registerProxyClient(this);
Logger.msg(1, "Proxy Client Connection Handler "+thisClientId+" ready.");
}
diff --git a/src/main/java/com/c2kernel/entity/proxy/EntityProxyManager.java b/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java index c49e7f5..2b2e0e9 100644 --- a/src/main/java/com/c2kernel/entity/proxy/EntityProxyManager.java +++ b/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java @@ -1,5 +1,5 @@ /**************************************************************************
- * EntityProxyFactory.java
+ * ProxyManager.java
*
* $Revision: 1.45 $
* $Date: 2005/05/10 11:40:09 $
@@ -12,7 +12,6 @@ package com.c2kernel.entity.proxy; import java.util.ArrayList;
import java.util.ConcurrentModificationException;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
@@ -26,30 +25,24 @@ import com.c2kernel.process.Gateway; import com.c2kernel.property.Property;
import com.c2kernel.utils.Logger;
import com.c2kernel.utils.SoftCache;
-import com.c2kernel.utils.server.SimpleTCPIPServer;
-public class EntityProxyManager
+public class ProxyManager
{
- SoftCache<Integer, EntityProxy> proxyPool = new SoftCache<Integer, EntityProxy>(50);
+ SoftCache<Integer, ItemProxy> proxyPool = new SoftCache<Integer, ItemProxy>(50);
HashMap<DomainPathSubscriber, DomainPath> treeSubscribers = new HashMap<DomainPathSubscriber, DomainPath>();
HashMap<String, ProxyServerConnection> connections = new HashMap<String, ProxyServerConnection>();
- // server objects
- static ArrayList<ProxyClientConnection> proxyClients = new ArrayList<ProxyClientConnection>();
- static SimpleTCPIPServer proxyServer = null;
- static String serverName = null;
-
/**
- * Create an entity proxy manager to listen for proxy events and reap unused proxies
+ * Create a proxy manager to listen for proxy events and reap unused proxies
*/
- public EntityProxyManager()
+ public ProxyManager()
{
- Logger.msg(5, "EntityProxyManager - Starting.....");
+ Logger.msg(5, "ProxyManager - Starting.....");
- Enumeration<Path> servers = Gateway.getLDAPLookup().searchEntities(new DomainPath("/servers"));
- while(servers.hasMoreElements()) {
- Path thisServerPath = servers.nextElement();
+ Iterator<Path> servers = Gateway.getLookup().searchEntities(new DomainPath("/servers"));
+ while(servers.hasNext()) {
+ Path thisServerPath = servers.next();
try {
int syskey = thisServerPath.getSysKey();
String remoteServer = ((Property)Gateway.getStorage().get(syskey, ClusterStorage.PROPERTY+"/Name", null)).getValue();
@@ -76,7 +69,7 @@ public class EntityProxyManager synchronized (proxyPool) {
for (Integer key : proxyPool.keySet()) {
ProxyMessage sub = new ProxyMessage(key.intValue(), ProxyMessage.ADDPATH, false);
- Logger.msg(5, "Subscribing to entity "+key);
+ Logger.msg(5, "Subscribing to item "+key);
conn.sendMessage(sub);
}
}
@@ -93,7 +86,7 @@ public class EntityProxyManager }
public void shutdown() {
- Logger.msg("EntityProxyManager.shutdown() - flagging shutdown of server connections");
+ Logger.msg("ProxyManager.shutdown() - flagging shutdown of server connections");
for (ProxyServerConnection element : connections.values()) {
element.shutdown();
}
@@ -111,7 +104,7 @@ public class EntityProxyManager // proper proxy message
Logger.msg(5, "Received proxy message: "+thisMessage.toString());
Integer key = new Integer(thisMessage.getSysKey());
- EntityProxy relevant = proxyPool.get(key);
+ ItemProxy relevant = proxyPool.get(key);
if (relevant == null)
Logger.warning("Received proxy message for sysKey "+thisMessage.getSysKey()+" which we don't have a proxy for.");
else
@@ -161,23 +154,23 @@ public class EntityProxyManager /**************************************************************************
*
**************************************************************************/
- private EntityProxy createProxy( org.omg.CORBA.Object ior,
+ private ItemProxy createProxy( org.omg.CORBA.Object ior,
int systemKey,
- boolean isItem )
+ boolean isAgent )
throws ObjectNotFoundException
{
- EntityProxy newProxy = null;
+ ItemProxy newProxy = null;
- Logger.msg(5, "EntityProxyFactory::creating proxy on entity " + systemKey);
+ Logger.msg(5, "ProxyManager::creating proxy on Item " + systemKey);
- if( isItem )
+ if( isAgent )
{
- newProxy = new ItemProxy(ior, systemKey);
+ newProxy = new AgentProxy(ior, systemKey);
}
else
{
- newProxy = new AgentProxy(ior, systemKey);
+ newProxy = new ItemProxy(ior, systemKey);
}
// subscribe to changes from server
@@ -190,31 +183,29 @@ public class EntityProxyManager protected void removeProxy( int systemKey )
{
ProxyMessage sub = new ProxyMessage(systemKey, ProxyMessage.DELPATH, true);
- Logger.msg(5,"EntityProxyManager.removeProxy() - Unsubscribing to proxy informer for "+systemKey);
+ Logger.msg(5,"ProxyManager.removeProxy() - Unsubscribing to proxy informer for "+systemKey);
sendMessage(sub);
}
/**************************************************************************
- * EntityProxy getProxy( ManageableEntity, SystemKey)
- *
* Called by the other GetProxy methods. Fills in either the ior or the
* SystemKey
**************************************************************************/
- private EntityProxy getProxy( org.omg.CORBA.Object ior,
+ private ItemProxy getProxy( org.omg.CORBA.Object ior,
int systemKey,
- boolean isItem )
+ boolean isAgent )
throws ObjectNotFoundException
{
Integer key = new Integer(systemKey);
synchronized(proxyPool) {
- EntityProxy newProxy;
+ ItemProxy newProxy;
// return it if it exists
newProxy = proxyPool.get(key);
if (newProxy == null) {
// create a new one
- newProxy = createProxy(ior, systemKey, isItem );
+ newProxy = createProxy(ior, systemKey, isAgent );
proxyPool.put(key, newProxy);
}
return newProxy;
@@ -223,22 +214,28 @@ public class EntityProxyManager }
/**************************************************************************
- * EntityProxy getProxy( String )
+ * ItemProxy getProxy( String )
*
* Proxy from Alias
**************************************************************************/
- public EntityProxy getProxy( Path path )
+ public ItemProxy getProxy( Path path )
throws ObjectNotFoundException
{
//convert namePath to dn format
- Logger.msg(8,"EntityProxyFactory::getProxy(" + path.toString() + ")");
- boolean isItem = !(path.getEntity() instanceof AgentPath);
- return getProxy( Gateway.getLDAPLookup().getIOR(path),
+ Logger.msg(8,"ProxyManager::getProxy(" + path.toString() + ")");
+ boolean isAgent = (path.getEntity() instanceof AgentPath);
+ return getProxy( Gateway.getLookup().resolve(path),
path.getSysKey(),
- isItem );
+ isAgent );
}
+
+ public AgentProxy getAgentProxy( AgentPath path )
+ throws ObjectNotFoundException
+ {
+ return (AgentProxy) getProxy(path);
+ }
/**************************************************************************
* void reportCurrentProxies()
@@ -256,7 +253,7 @@ public class EntityProxyManager for( int count=0; i.hasNext(); count++ )
{
Integer nextProxy = i.next();
- EntityProxy thisProxy = proxyPool.get(nextProxy);
+ ItemProxy thisProxy = proxyPool.get(nextProxy);
if (thisProxy != null)
Logger.msg(logLevel,
"" + count + ": "
@@ -270,70 +267,6 @@ public class EntityProxyManager }
- /**************************************************************************
- * Static Proxy Server methods
- **************************************************************************/
-
- /**
- * Initialises the Proxy event UDP server listening on 'Host.Proxy.port' from c2kprops
- * @param c2kProps
- */
- public static void initServer()
- {
- Logger.msg(5, "EntityProxyFactory::initServer - Starting.....");
- int port = Gateway.getProperties().getInt("ItemServer.Proxy.port", 0);
- serverName = Gateway.getProperties().getProperty("ItemServer.name");
- if (port == 0) {
- Logger.error("ItemServer.Proxy.port not defined in connect file. Remote proxies will not be informed of entity changes.");
- return;
- }
-
- // set up the proxy server
- try {
- Logger.msg(5, "EntityProxyFactory::initServer - Initialising proxy informer on port "+port);
- proxyServer = new SimpleTCPIPServer(port, ProxyClientConnection.class, 200);
- proxyServer.startListening();
- } catch (Exception ex) {
- Logger.error("Error setting up Proxy Server. Remote proxies will not be informed of entity changes.");
- Logger.error(ex);
- }
- }
-
- public static void sendProxyEvent(ProxyMessage message) {
- if (proxyServer != null && message.getPath() != null)
- synchronized(proxyClients) {
- for (ProxyClientConnection client : proxyClients) {
- client.sendMessage(message);
- }
- }
- }
-
- public static void reportConnections(int logLevel) {
- synchronized(proxyClients) {
- Logger.msg(logLevel, "Currently connected proxy clients:");
- for (ProxyClientConnection client : proxyClients) {
- Logger.msg(logLevel, " "+client);
- }
- }
- }
-
- public static void shutdownServer() {
- if (proxyServer != null) {
- Logger.msg(1, "EntityProxyManager: Closing Server.");
- proxyServer.stopListening();
- }
- }
-
- public static void registerProxyClient(ProxyClientConnection client) {
- synchronized(proxyClients) {
- proxyClients.add(client);
- }
- }
-
- public static void unRegisterProxyClient(ProxyClientConnection client) {
- synchronized(proxyClients) {
- proxyClients.remove(client);
- }
- }
+
}
diff --git a/src/main/java/com/c2kernel/entity/proxy/EntityProxyObserver.java b/src/main/java/com/c2kernel/entity/proxy/ProxyObserver.java index 3ddb99c..b15a972 100644 --- a/src/main/java/com/c2kernel/entity/proxy/EntityProxyObserver.java +++ b/src/main/java/com/c2kernel/entity/proxy/ProxyObserver.java @@ -4,7 +4,7 @@ import com.c2kernel.entity.C2KLocalObject; -public interface EntityProxyObserver<V extends C2KLocalObject>
+public interface ProxyObserver<V extends C2KLocalObject>
{
/**************************************************************************
* Subscribed items are broken apart and fed one by one to these methods.
diff --git a/src/main/java/com/c2kernel/entity/proxy/ProxyServer.java b/src/main/java/com/c2kernel/entity/proxy/ProxyServer.java new file mode 100644 index 0000000..c576cda --- /dev/null +++ b/src/main/java/com/c2kernel/entity/proxy/ProxyServer.java @@ -0,0 +1,106 @@ +package com.c2kernel.entity.proxy;
+
+import java.util.ArrayList;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import com.c2kernel.process.Gateway;
+import com.c2kernel.utils.Logger;
+import com.c2kernel.utils.server.SimpleTCPIPServer;
+
+public class ProxyServer implements Runnable {
+
+ // server objects
+ ArrayList<ProxyClientConnection> proxyClients;
+ SimpleTCPIPServer proxyListener = null;
+ String serverName = null;
+ boolean keepRunning = true;
+ LinkedBlockingQueue<ProxyMessage> messageQueue;
+
+ public ProxyServer(String serverName) {
+ Logger.msg(5, "ProxyManager::initServer - Starting.....");
+ int port = Gateway.getProperties().getInt("ItemServer.Proxy.port", 0);
+ this.serverName = serverName;
+ this.proxyClients = new ArrayList<ProxyClientConnection>();
+ this.messageQueue = new LinkedBlockingQueue<ProxyMessage>();
+
+ if (port == 0) {
+ Logger.error("ItemServer.Proxy.port not defined in connect file. Remote proxies will not be informed of changes.");
+ return;
+ }
+
+ // set up the proxy server
+ try {
+ Logger.msg(5, "ProxyManager::initServer - Initialising proxy informer on port "+port);
+ proxyListener = new SimpleTCPIPServer(port, ProxyClientConnection.class, 200);
+ proxyListener.startListening();
+ } catch (Exception ex) {
+ Logger.error("Error setting up Proxy Server. Remote proxies will not be informed of changes.");
+ Logger.error(ex);
+ }
+ // start the message queue delivery thread
+ new Thread(this).start();
+ }
+
+ @Override
+ public void run() {
+
+ while(keepRunning) {
+ ProxyMessage message = messageQueue.poll();
+ if (message != null) {
+ synchronized(proxyClients) {
+ for (ProxyClientConnection client : proxyClients) {
+ client.sendMessage(message);
+ }
+ }
+ } else
+ try {
+ synchronized(this) { wait(); }
+ } catch (InterruptedException e) { }
+ }
+
+ }
+
+ public String getServerName() {
+ return serverName;
+ }
+
+ public void sendProxyEvent(ProxyMessage message) {
+ try {
+ synchronized(this) {
+ messageQueue.put(message);
+ notify();
+ }
+ } catch (InterruptedException e) { }
+ }
+
+ public void reportConnections(int logLevel) {
+ synchronized(proxyClients) {
+ Logger.msg(logLevel, "Currently connected proxy clients:");
+ for (ProxyClientConnection client : proxyClients) {
+ Logger.msg(logLevel, " "+client);
+ }
+ }
+ }
+
+ public void shutdownServer() {
+ Logger.msg(1, "ProxyManager: Closing Server.");
+ proxyListener.stopListening();
+ synchronized(this) {
+ keepRunning = false;
+ notify();
+ }
+ }
+
+ public void registerProxyClient(ProxyClientConnection client) {
+ synchronized(proxyClients) {
+ proxyClients.add(client);
+ }
+ }
+
+ public void unRegisterProxyClient(ProxyClientConnection client) {
+ synchronized(proxyClients) {
+ proxyClients.remove(client);
+ }
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/entity/proxy/ProxyServerConnection.java b/src/main/java/com/c2kernel/entity/proxy/ProxyServerConnection.java index 6807953..54ca787 100644 --- a/src/main/java/com/c2kernel/entity/proxy/ProxyServerConnection.java +++ b/src/main/java/com/c2kernel/entity/proxy/ProxyServerConnection.java @@ -29,7 +29,7 @@ public class ProxyServerConnection extends Thread String serverName;
int serverPort;
Socket serverConnection;
- EntityProxyManager manager;
+ ProxyManager manager;
// for talking to the proxy server
PrintWriter serverStream;
boolean listening = false;
@@ -38,7 +38,7 @@ public class ProxyServerConnection extends Thread /**
* Create an entity proxy manager to listen for proxy events and reap unused proxies
*/
- public ProxyServerConnection(String host, int port, EntityProxyManager manager)
+ public ProxyServerConnection(String host, int port, ProxyManager manager)
{
Logger.msg(5, "ProxyServerConnection - Initialising connection to "+host+":"+port);
serverName = host;
diff --git a/src/main/java/com/c2kernel/entity/transfer/TransferItem.java b/src/main/java/com/c2kernel/entity/transfer/TransferItem.java index 520063a..9a4cfc5 100644 --- a/src/main/java/com/c2kernel/entity/transfer/TransferItem.java +++ b/src/main/java/com/c2kernel/entity/transfer/TransferItem.java @@ -2,14 +2,14 @@ package com.c2kernel.entity.transfer; import java.io.File;
import java.util.ArrayList;
-import java.util.Enumeration;
+import java.util.Iterator;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.entity.TraceableEntity;
import com.c2kernel.lifecycle.instance.Workflow;
import com.c2kernel.lookup.DomainPath;
-import com.c2kernel.lookup.EntityPath;
+import com.c2kernel.lookup.ItemPath;
import com.c2kernel.lookup.Path;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.outcome.Outcome;
@@ -26,7 +26,7 @@ public class TransferItem { public TransferItem() throws Exception {
try {
- importAgentId = Gateway.getLDAPLookup().getRoleManager().getAgentPath("system").getSysKey();
+ importAgentId = Gateway.getLookup().getAgentPath("system").getSysKey();
} catch (ObjectNotFoundException e) {
Logger.error("TransferItem - System user not found!");
throw e;
@@ -37,9 +37,9 @@ public class TransferItem { this.sysKey = sysKey;
domainPaths = new ArrayList<String>();
Property name = (Property)Gateway.getStorage().get(sysKey, ClusterStorage.PROPERTY + "/Name", null);
- Enumeration<Path> paths = Gateway.getLDAPLookup().search(new DomainPath(), name.getValue());
- while (paths.hasMoreElements()) {
- DomainPath thisPath = (DomainPath)paths.nextElement();
+ Iterator<Path> paths = Gateway.getLookup().search(new DomainPath(), name.getValue());
+ while (paths.hasNext()) {
+ DomainPath thisPath = (DomainPath)paths.next();
domainPaths.add(thisPath.toString());
}
}
@@ -89,9 +89,9 @@ public class TransferItem { }
// create item
- EntityPath entityPath = new EntityPath(sysKey);
+ ItemPath entityPath = new ItemPath(sysKey);
TraceableEntity newItem = (TraceableEntity)Gateway.getCorbaServer().createEntity(entityPath);
- Gateway.getLDAPLookup().add(entityPath);
+ Gateway.getLookup().add(entityPath);
PropertyArrayList props = new PropertyArrayList();
Workflow wf = null;
@@ -107,7 +107,10 @@ public class TransferItem { throw new Exception("No workflow found in import for "+sysKey);
// init item
- newItem.initialise(importAgentId, Gateway.getMarshaller().marshall(props), Gateway.getMarshaller().marshall(wf.search("workflow/domain")));
+ newItem.initialise(importAgentId,
+ Gateway.getMarshaller().marshall(props),
+ Gateway.getMarshaller().marshall(wf.search("workflow/domain")),
+ null);
// store objects
importByType(ClusterStorage.COLLECTION, objects);
@@ -118,7 +121,7 @@ public class TransferItem { // add domPaths
for (String element : domainPaths) {
DomainPath newPath = new DomainPath(element, entityPath);
- Gateway.getLDAPLookup().add(newPath);
+ Gateway.getLookup().add(newPath);
}
}
diff --git a/src/main/java/com/c2kernel/entity/transfer/TransferSet.java b/src/main/java/com/c2kernel/entity/transfer/TransferSet.java index 7a3ba2e..7a5833f 100644 --- a/src/main/java/com/c2kernel/entity/transfer/TransferSet.java +++ b/src/main/java/com/c2kernel/entity/transfer/TransferSet.java @@ -3,8 +3,8 @@ package com.c2kernel.entity.transfer; import java.io.File;
import java.util.ArrayList;
-import com.c2kernel.lookup.EntityPath;
-import com.c2kernel.lookup.NextKeyManager;
+import com.c2kernel.lookup.ItemPath;
+import com.c2kernel.persistency.NextKeyManager;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.FileStringUtility;
import com.c2kernel.utils.Logger;
@@ -84,8 +84,8 @@ public class TransferSet { try
{ // find the current last key
- NextKeyManager nextKeyMan = Gateway.getLDAPLookup().getNextKeyManager();
- EntityPath lastKey = nextKeyMan.getLastEntityPath();
+ NextKeyManager nextKeyMan = Gateway.getNextKeyManager();
+ ItemPath lastKey = nextKeyMan.getLastEntityPath();
Logger.msg(1, "Last key imported was "+packageLastKey+". LDAP lastkey was "+lastKey.getSysKey());
|
