diff options
| author | abranson <andrew.branson@cern.ch> | 2011-08-04 00:42:34 +0200 |
|---|---|---|
| committer | abranson <andrew.branson@cern.ch> | 2011-08-04 00:42:34 +0200 |
| commit | 0ec8481c10cd8277d84c7c1a785483a0a739e5a0 (patch) | |
| tree | 5f6e5d9ae75193e67e6f3b3dfa488960c5cde1d5 /source/com/c2kernel/entity | |
| parent | 036cbdba66f804743c4c838ed598d6972c4b3e17 (diff) | |
More code cleanup:
Refactored Entity Proxy Subscription to handle generics better
Rewrote RemoteMap to use TreeMap instead of the internal array for
order. It now sorts its keys by number if they parse, else as strings.
Removed a no-longer-in-progress outcome form class
Diffstat (limited to 'source/com/c2kernel/entity')
23 files changed, 478 insertions, 499 deletions
diff --git a/source/com/c2kernel/entity/C2KLocalObject.java b/source/com/c2kernel/entity/C2KLocalObject.java index 06bf867..ec30dc1 100755..100644 --- a/source/com/c2kernel/entity/C2KLocalObject.java +++ b/source/com/c2kernel/entity/C2KLocalObject.java @@ -10,23 +10,23 @@ import java.io.Serializable; * <li>Outcomes - /Outcome/SchemaType/SchemaVersion/EventId
* <li>Viewpoints - /ViewPoint/SchemaType/Name
* </ul>
- *
+ *
* @see com.c2kernel.persistency.ClusterStorage
* @see com.c2kernel.persistency.ClusterStorageManager
- *
+ *
* @author Andrew Branson
*
* $Revision: 1.5 $
* $Date: 2004/01/22 11:10:41 $
*
* Copyright (C) 2003 CERN - European Organization for Nuclear Research
- * All rights reserved.
+ * All rights reserved.
*/
public interface C2KLocalObject extends Serializable {
public void setName(String name);
public String getName();
-
+
public String getClusterType();
}
diff --git a/source/com/c2kernel/entity/CorbaServer.java b/source/com/c2kernel/entity/CorbaServer.java index 883bb1b..84d2ef2 100644 --- a/source/com/c2kernel/entity/CorbaServer.java +++ b/source/com/c2kernel/entity/CorbaServer.java @@ -39,7 +39,7 @@ public class CorbaServer { public CorbaServer() throws InvalidDataException {
mEntityCache = new SoftCache<EntityPath, Servant>(50);
-
+
// init POA
try {
setupPOA();
@@ -48,15 +48,16 @@ public class CorbaServer { Logger.error(ex);
throw new InvalidDataException("Error initialising POA", "");
}
-
+
new Thread(new Runnable() {
- public void run() {
+ @Override
+ public void run() {
Thread.currentThread().setName("ORB Invoker");
Gateway.getORB().run();
}
}).start();
}
-
+
public void close() {
try {
mPOAManager.deactivate(true, true);
@@ -64,12 +65,12 @@ public class CorbaServer { Logger.error(ex);
}
}
-
+
/**************************************************************************
* Initialises the C2KRootPOA with policies which are suitable for Factory objects
- **************************************************************************/
+ **************************************************************************/
public void setupPOA() throws Exception {
-
+
//Initialise the RootPOA
mRootPOA = org.omg.PortableServer.POAHelper.narrow(
Gateway.getORB().resolve_initial_references("RootPOA"));
@@ -78,8 +79,6 @@ public class CorbaServer { mPOAManager = mRootPOA.the_POAManager();
- org.omg.CORBA.Policy[] poaPolicies;
-
// Create POA for use by the entities
org.omg.CORBA.Policy[] policies = new org.omg.CORBA.Policy[6];
@@ -103,32 +102,32 @@ public class CorbaServer { policies );
mAgentPOA = mRootPOA.create_POA( "Agent",
mRootPOA.the_POAManager(),
- policies );
+ policies );
//Create the locators
TraceableLocator itemLocator = new TraceableLocator( mItemPOA );
- mItemPOA.set_servant_manager( itemLocator._this( Gateway.getORB() ) );
-
+ mItemPOA.set_servant_manager( itemLocator._this( Gateway.getORB() ) );
+
ActiveLocator agentLocator = new ActiveLocator( mAgentPOA );
mAgentPOA.set_servant_manager( agentLocator._this( Gateway.getORB() ) );
-
+
}
-
+
/**************************************************************************
* Returns a CORBA servant for a pre-existing entity
- **************************************************************************/
+ **************************************************************************/
private Servant getEntity(int sysKey, org.omg.PortableServer.POA poa) throws ObjectNotFoundException {
try {
EntityPath entityPath = new EntityPath(sysKey);
Servant entity = null;
synchronized (mEntityCache) {
- entity = (Servant)mEntityCache.get(entityPath);
+ entity = mEntityCache.get(entityPath);
if (entity == null) {
Logger.msg(7, "Creating new servant for "+sysKey);
-
- Class entityClass = Gateway.getLDAPLookup().getEntityClass(entityPath);
-
+
+ Class<?> entityClass = Gateway.getLDAPLookup().getEntityClass(entityPath);
+
if (entityClass == TraceableEntity.class) {
if (poa == null) poa = mItemPOA;
entity = new TraceableEntity(sysKey, poa);
@@ -141,12 +140,12 @@ public class CorbaServer { }
}
return entity;
-
+
} catch (InvalidEntityPathException ex) {
throw new ObjectNotFoundException("Invalid Entity Key", "");
- }
+ }
}
-
+
/**************************************************************************
* Wrapper for fetching Items
**************************************************************************/
@@ -186,6 +185,6 @@ public class CorbaServer { mEntityCache.put(entityPath, entity);
}
return entity;
-
+
}
}
diff --git a/source/com/c2kernel/entity/TraceableEntity.java b/source/com/c2kernel/entity/TraceableEntity.java index 49bbe47..c7aff82 100755..100644 --- a/source/com/c2kernel/entity/TraceableEntity.java +++ b/source/com/c2kernel/entity/TraceableEntity.java @@ -11,7 +11,6 @@ package com.c2kernel.entity;
-import java.util.Iterator;
import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
@@ -87,7 +86,8 @@ public class TraceableEntity extends ItemPOA /**************************************************************************
*
**************************************************************************/
- public org.omg.PortableServer.POA _default_POA()
+ @Override
+ public org.omg.PortableServer.POA _default_POA()
{
if(mPoa != null)
return mPoa;
@@ -99,7 +99,8 @@ public class TraceableEntity extends ItemPOA /**************************************************************************
*
**************************************************************************/
- public int getSystemKey()
+ @Override
+ public int getSystemKey()
{
Logger.msg(8, "TraceableEntity::getSystemKey() - " + mSystemKey);
return mSystemKey;
@@ -108,7 +109,8 @@ public class TraceableEntity extends ItemPOA /**************************************************************************
*
**************************************************************************/
- public void initialise( int agentId,
+ @Override
+ public void initialise( int agentId,
String propString,
String initWfString
)
@@ -120,22 +122,22 @@ public class TraceableEntity extends ItemPOA 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)CastorXMLUtility.unmarshall(propString);
- for (Iterator i = props.list.iterator(); i.hasNext();) {
- Property thisProp = (Property)i.next();
+ for (Object name : props.list) {
+ Property thisProp = (Property)name;
mStorage.put(mSystemKey, thisProp, props);
}
} catch (Throwable ex) {
@@ -145,10 +147,10 @@ public class TraceableEntity extends ItemPOA }
mStorage.commit(props);
}
-
+
// create wf
try {
- if (initWfString == null || initWfString.equals(""))
+ if (initWfString == null || initWfString.equals(""))
lc = new Workflow(new CompositeActivity());
else
lc = new Workflow((CompositeActivity)CastorXMLUtility.unmarshall(initWfString));
@@ -158,14 +160,15 @@ public class TraceableEntity extends ItemPOA Logger.msg(8, "TraceableEntity::initialise("+mSystemKey+") - Workflow was invalid: "+initWfString);
Logger.error(ex);
}
- }
+ }
}
/**************************************************************************
*
**************************************************************************/
//requestdata is xmlstring
- public void requestAction( int agentId,
+ @Override
+ public void requestAction( int agentId,
String stepPath,
int transitionID,
String requestData
@@ -180,31 +183,31 @@ public class TraceableEntity extends ItemPOA synchronized (this) {
try {
- Logger.msg(1, "TraceableEntity::request("+mSystemKey+") - " +
+ Logger.msg(1, "TraceableEntity::request("+mSystemKey+") - " +
Transitions.getTransitionName(transitionID) + " "+stepPath + " by " +agentId );
- AgentPath agent = new AgentPath(agentId);
+ AgentPath agent = new AgentPath(agentId);
Workflow lifeCycle = (Workflow)mStorage.get(mSystemKey, ClusterStorage.LIFECYCLE+"/workflow", null);
-
+
lifeCycle.requestAction( agent,
stepPath,
transitionID,
requestData );
-
+
// store the workflow if we've changed the state of the domain wf
- if (!(stepPath.startsWith("workflow/predefined")))
+ 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");
+ Logger.msg("Propagating AccessRightsException back to the calling agent");
throw ex;
} catch (InvalidTransitionException ex) {
- Logger.msg("Propagating InvalidTransitionException back to the calling agent");
+ 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;
+ Logger.msg("Propagating ObjectNotFoundException back to the calling agent");
+ throw ex;
// errors
} catch (ClusterStorageException ex) {
Logger.error(ex);
@@ -212,13 +215,13 @@ public class TraceableEntity extends ItemPOA } catch (InvalidEntityPathException ex) {
Logger.error(ex);
throw new AccessRightsException("Invalid Agent Id: "+agentId, "");
- } catch (InvalidDataException ex) {
+ } catch (InvalidDataException ex) {
Logger.error(ex);
- Logger.msg("Propagating InvalidDataException back to the calling agent");
+ Logger.msg("Propagating InvalidDataException back to the calling agent");
throw ex;
- } catch (ObjectAlreadyExistsException ex) {
+ } catch (ObjectAlreadyExistsException ex) {
Logger.error(ex);
- Logger.msg("Propagating ObjectAlreadyExistsException back to the calling agent");
+ Logger.msg("Propagating ObjectAlreadyExistsException back to the calling agent");
throw ex;
// non-CORBA exception hasn't been caught!
} catch (Throwable ex) {
@@ -226,13 +229,14 @@ public class TraceableEntity extends ItemPOA Logger.error(ex);
throw new InvalidDataException("Extraordinary Exception during execution:"+ex.getClass().getName()+" - "+ex.getMessage(), "");
}
- }
+ }
}
/**************************************************************************
*
**************************************************************************/
- public String queryLifeCycle( int agentId,
+ @Override
+ public String queryLifeCycle( int agentId,
boolean filter
)
throws AccessRightsException,
@@ -241,7 +245,7 @@ public class TraceableEntity extends ItemPOA {
synchronized (this) {
Logger.msg(1, "TraceableEntity::queryLifeCycle("+mSystemKey+") - agent: " + agentId);
-
+
try
{
AgentPath agent = new AgentPath(agentId);
@@ -266,21 +270,22 @@ public class TraceableEntity extends ItemPOA * @param path - the path to the object required
* the suffix 'all' retrieves a listing of all keys on that level
*
- * @return The result string in xml format
+ * @return The result string in xml format
* except 'all' which returns a comma sep list
*
* @exception ObjectNotFoundException
* ************************************************************************/
- public String queryData(String path)
+ @Override
+ public String queryData(String path)
throws AccessRightsException,
ObjectNotFoundException,
PersistencyException
{
synchronized (this) {
String result = "";
-
+
Logger.msg(1, "TraceableEntity::queryData("+mSystemKey+") - " + path );
-
+
try
{ // check for cluster contents query
@@ -289,11 +294,11 @@ public class TraceableEntity extends ItemPOA 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 += ",";
}
@@ -302,7 +307,7 @@ public class TraceableEntity extends ItemPOA 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 = CastorXMLUtility.marshall(obj);
}
@@ -316,17 +321,18 @@ public class TraceableEntity extends ItemPOA 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;
}
}
/**
*
*/
- protected void finalize() throws Throwable {
+ @Override
+ protected void finalize() throws Throwable {
Logger.msg(7, "Item "+mSystemKey+" reaped");
Gateway.getStorage().clearCache(mSystemKey, null);
super.finalize();
diff --git a/source/com/c2kernel/entity/TraceableLocator.java b/source/com/c2kernel/entity/TraceableLocator.java index 09a19e3..5f237d7 100755..100644 --- a/source/com/c2kernel/entity/TraceableLocator.java +++ b/source/com/c2kernel/entity/TraceableLocator.java @@ -44,7 +44,8 @@ public class TraceableLocator extends org.omg.PortableServer.ServantLocatorPOA /**************************************************************************
*
**************************************************************************/
- public org.omg.PortableServer.Servant preinvoke(
+ @Override
+ public org.omg.PortableServer.Servant preinvoke(
byte[] oid,
org.omg.PortableServer.POA poa,
String operation,
@@ -54,7 +55,6 @@ public class TraceableLocator extends org.omg.PortableServer.ServantLocatorPOA {
int syskey = Integer.parseInt(new String(oid));
- org.omg.PortableServer.Servant servant=null;
Logger.msg(1,"===========================================================");
Logger.msg(1,"Item called at "+new Timestamp( System.currentTimeMillis()) +": " + operation +
@@ -74,7 +74,8 @@ public class TraceableLocator extends org.omg.PortableServer.ServantLocatorPOA /**************************************************************************
*
**************************************************************************/
- public void postinvoke(
+ @Override
+ public void postinvoke(
byte[] oid,
org.omg.PortableServer.POA poa,
String operation,
diff --git a/source/com/c2kernel/entity/agent/ActiveEntity.java b/source/com/c2kernel/entity/agent/ActiveEntity.java index cb77bbb..3d45e35 100755..100644 --- a/source/com/c2kernel/entity/agent/ActiveEntity.java +++ b/source/com/c2kernel/entity/agent/ActiveEntity.java @@ -12,7 +12,12 @@ package com.c2kernel.entity.agent; import java.util.Iterator;
-import com.c2kernel.common.*;
+import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.CannotManageException;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.entity.AgentPOA;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.lookup.AgentPath;
@@ -21,6 +26,7 @@ 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.CastorXMLUtility;
import com.c2kernel.utils.Logger;
@@ -48,13 +54,13 @@ public class ActiveEntity extends AgentPOA * Connection to the persistency backeng
**************************************************************************/
private TransactionManager mDatabase = null;
-
+
/**************************************************************************
- * The agent's joblist
+ * The agent's joblist
**************************************************************************/
private JobList currentJobs;
/**
- *
+ *
* @param key
* @param poa
*/
@@ -73,7 +79,8 @@ public class ActiveEntity extends AgentPOA /**
* initialise cristal2 properties & collector
*/
- public void initialise( String agentProps )
+ @Override
+ public void initialise( String agentProps )
throws AccessRightsException,
InvalidDataException,
PersistencyException
@@ -99,7 +106,7 @@ public class ActiveEntity extends AgentPOA }
/**
- *
+ *
* @param propsString
* @return Properties
* @throws InvalidDataException Properties cannot be unmarshalled
@@ -112,7 +119,7 @@ public class ActiveEntity extends AgentPOA PropertyArrayList props = null;
// create properties
- if( !propsString.equals("") && propsString != null )
+ if( propsString != null && !propsString.equals("") )
{
try
{
@@ -126,10 +133,10 @@ public class ActiveEntity extends AgentPOA throw new InvalidDataException(ex.toString(), null);
}
- Iterator iter = props.list.iterator();
+ Iterator<Property> iter = props.list.iterator();
while( iter.hasNext() )
- mDatabase.put( mSystemKey, (C2KLocalObject)iter.next(), props );
+ mDatabase.put( mSystemKey, iter.next(), props );
}
else
{
@@ -138,12 +145,13 @@ public class ActiveEntity extends AgentPOA return props;
}
-
+
/**************************************************************************
*
*
**************************************************************************/
- public org.omg.PortableServer.POA _default_POA()
+ @Override
+ public org.omg.PortableServer.POA _default_POA()
{
if(mPOA != null)
return mPOA;
@@ -156,7 +164,8 @@ public class ActiveEntity extends AgentPOA *
*
**************************************************************************/
- public int getSystemKey()
+ @Override
+ public int getSystemKey()
{
return mSystemKey;
}
@@ -166,7 +175,8 @@ public class ActiveEntity extends AgentPOA *
*
**************************************************************************/
- public String queryData(String xpath)
+ @Override
+ public String queryData(String xpath)
throws AccessRightsException,
ObjectNotFoundException,
PersistencyException
@@ -203,7 +213,7 @@ public class ActiveEntity extends AgentPOA }
catch (ObjectNotFoundException ex) {
throw ex;
- }
+ }
catch(Throwable ex)
{
Logger.error("ActiveEntity::queryData("+mSystemKey+") - " +
@@ -218,37 +228,39 @@ public class ActiveEntity extends AgentPOA }
-
+
/**
* Called by an activity when it reckons we need to update our joblist for it
*/
-
- public synchronized void refreshJobList(int sysKey, String stepPath, String newJobs) {
+
+ @Override
+ public synchronized void refreshJobList(int sysKey, String stepPath, String newJobs) {
try {
JobArrayList newJobList = (JobArrayList)CastorXMLUtility.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 (Iterator iter = newJobList.list.iterator(); iter.hasNext();) {
- Job newJob = (Job)iter.next();
+ for (Object name : newJobList.list) {
+ Job newJob = (Job)name;
Logger.msg(6, "Adding job for "+newJob.getItemSysKey()+"/"+newJob.getStepPath()+":"+newJob.getPossibleTransition());
currentJobs.addJob(newJob);
}
-
+
} catch (Throwable ex) {
Logger.error("Could not refresh job list.");
- Logger.error(ex);
+ Logger.error(ex);
}
-
+
}
-
- public void addRole(String roleName) throws CannotManageException, ObjectNotFoundException {
+
+ @Override
+ public void addRole(String roleName) throws CannotManageException, ObjectNotFoundException {
RolePath newRole = Gateway.getLDAPLookup().getRoleManager().getRolePath(roleName);
try {
newRole.addAgent(new AgentPath(mSystemKey));
@@ -258,11 +270,12 @@ public class ActiveEntity extends AgentPOA throw new CannotManageException("Could not update role");
}
}
-
- public void removeRole(String roleName) throws CannotManageException, ObjectNotFoundException {
+
+ @Override
+ public void removeRole(String roleName) throws CannotManageException, ObjectNotFoundException {
RolePath rolePath = Gateway.getLDAPLookup().getRoleManager().getRolePath(roleName);
try {
- rolePath.removeAgent(new AgentPath(mSystemKey));
+ rolePath.removeAgent(new AgentPath(mSystemKey));
} catch (InvalidEntityPathException e) {
throw new CannotManageException("Invalid syskey for agent: "+mSystemKey, "");
} catch (ObjectCannotBeUpdated ex) {
@@ -272,7 +285,8 @@ public class ActiveEntity extends AgentPOA /**
*
*/
- protected void finalize() throws Throwable {
+ @Override
+ protected void finalize() throws Throwable {
Logger.msg(7, "Agent "+mSystemKey+" reaped");
Gateway.getStorage().clearCache(mSystemKey, null);
super.finalize();
diff --git a/source/com/c2kernel/entity/agent/ActiveLocator.java b/source/com/c2kernel/entity/agent/ActiveLocator.java index 25324ee..eb50dbf 100755..100644 --- a/source/com/c2kernel/entity/agent/ActiveLocator.java +++ b/source/com/c2kernel/entity/agent/ActiveLocator.java @@ -45,7 +45,8 @@ public class ActiveLocator extends org.omg.PortableServer.ServantLocatorPOA /**************************************************************************
*
**************************************************************************/
- public org.omg.PortableServer.Servant preinvoke(
+ @Override
+ public org.omg.PortableServer.Servant preinvoke(
byte[] oid,
org.omg.PortableServer.POA poa,
String operation,
@@ -56,8 +57,6 @@ public class ActiveLocator extends org.omg.PortableServer.ServantLocatorPOA {
int syskey = Integer.parseInt(new String(oid));
- org.omg.PortableServer.Servant servant;
-
Logger.msg(1,"===========================================================");
Logger.msg(1,"Agent called at "+new Timestamp( System.currentTimeMillis()) +": " + operation +
"(" + syskey + ")." );
@@ -76,7 +75,8 @@ public class ActiveLocator extends org.omg.PortableServer.ServantLocatorPOA /**************************************************************************
*
**************************************************************************/
- public void postinvoke(
+ @Override
+ public void postinvoke(
byte[] oid,
org.omg.PortableServer.POA poa,
String operation,
diff --git a/source/com/c2kernel/entity/agent/Job.java b/source/com/c2kernel/entity/agent/Job.java index 12423d6..b5274ec 100755..100644 --- a/source/com/c2kernel/entity/agent/Job.java +++ b/source/com/c2kernel/entity/agent/Job.java @@ -32,7 +32,7 @@ public class Job implements C2KLocalObject private int mPossibleTransition;
private int mCurrentState;
-
+
private int mTargetState;
private String mStepName;
@@ -61,7 +61,7 @@ public class Job implements C2KLocalObject }
/***************************************************************************
- *
+ *
**************************************************************************/
public Job(int sysKey, String path, int transition, int currState, int targState, String stepName, CastorHashMap actProps, String stepType, String agentName)
{
@@ -197,7 +197,8 @@ public class Job implements C2KLocalObject return mID;
}
- public String getName()
+ @Override
+ public String getName()
{
return mName;
}
@@ -208,7 +209,8 @@ public class Job implements C2KLocalObject mName = String.valueOf(id);
}
- public void setName(String name)
+ @Override
+ public void setName(String name)
{
mName = name;
try
@@ -226,7 +228,8 @@ public class Job implements C2KLocalObject item = null;
}
- public String getClusterType()
+ @Override
+ public String getClusterType()
{
return ClusterStorage.JOB;
}
@@ -322,7 +325,7 @@ public class Job implements C2KLocalObject /**
* Returns the actType.
- *
+ *
* @return String
*/
public String getStepType()
@@ -332,7 +335,7 @@ public class Job implements C2KLocalObject /**
* Sets the actType.
- *
+ *
* @param actType
* The actType to set
*/
diff --git a/source/com/c2kernel/entity/agent/JobArrayList.java b/source/com/c2kernel/entity/agent/JobArrayList.java index fa85368..dcb3215 100644 --- a/source/com/c2kernel/entity/agent/JobArrayList.java +++ b/source/com/c2kernel/entity/agent/JobArrayList.java @@ -17,14 +17,14 @@ public class JobArrayList extends CastorArrayList<Job> {
public JobArrayList()
- {
+ {
super();
}
-
+
public JobArrayList(ArrayList<Job> aList)
- {
+ {
super(aList);
}
-
+
}
diff --git a/source/com/c2kernel/entity/agent/JobList.java b/source/com/c2kernel/entity/agent/JobList.java index 15ce0dd..f8a88ee 100644 --- a/source/com/c2kernel/entity/agent/JobList.java +++ b/source/com/c2kernel/entity/agent/JobList.java @@ -3,8 +3,6 @@ package com.c2kernel.entity.agent; import java.util.Iterator;
import java.util.Vector;
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.lookup.InvalidEntityPathException;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.RemoteMap;
import com.c2kernel.utils.Logger;
@@ -15,14 +13,13 @@ import com.c2kernel.utils.Logger; * @author $Author: abranson $ $Date: 2006/03/03 13:52:21 $
* @version $Revision: 1.15 $
***************************************************************************/
-public class JobList extends RemoteMap
+public class JobList extends RemoteMap<Job>
{
/**************************************************************************
* Empty constructor for Castor
**************************************************************************/
- public JobList(int sysKey, Object locker)
- throws ObjectNotFoundException, InvalidEntityPathException
+ public JobList(int sysKey, Object locker)
{
super(sysKey, ClusterStorage.JOB, locker);
}
@@ -43,29 +40,15 @@ public class JobList extends RemoteMap /**
* Cannot be stored
*/
+ @Override
public String getClusterType() {
return null;
}
-
- public int containsJob( Job job )
- {
- Iterator actMembers = keySet().iterator();
- Job j = null;
- while( actMembers.hasNext() )
- {
- j = (Job)actMembers.next();
- if( j.equals(job) )
- return j.getID();
- }
-
- return -1;
- }
-
public Job getJob(int id) {
- return (Job)get(String.valueOf(id));
- }
+ return get(String.valueOf(id));
+ }
/**
@@ -73,12 +56,12 @@ public class JobList extends RemoteMap */
public void removeJobsWithSysKey( int sysKey )
{
- Iterator currentMembers = values().iterator();
+ Iterator<Job> currentMembers = values().iterator();
Job j = null;
while( currentMembers.hasNext() )
{
- j = (Job)currentMembers.next();
+ j = currentMembers.next();
if( j.getItemSysKey() == sysKey )
remove( String.valueOf(j.getID()) );
@@ -89,10 +72,10 @@ public class JobList extends RemoteMap public void removeJobsForStep( int sysKey, String stepPath )
{
- Iterator currentMembers = values().iterator();
+ Iterator<Job> currentMembers = values().iterator();
while( currentMembers.hasNext() )
{
- Job j = (Job)currentMembers.next();
+ Job j = currentMembers.next();
if( j.getItemSysKey() == sysKey && j.getStepPath().equals(stepPath))
remove( String.valueOf(j.getID()) );
}
@@ -104,15 +87,15 @@ public class JobList extends RemoteMap * @param string
* @return
*/
- public Vector getJobsOfSysKey(int sysKey)
+ public Vector<Job> getJobsOfSysKey(int sysKey)
{
- Iterator currentMembers = values().iterator();
+ Iterator<Job> currentMembers = values().iterator();
Job j = null;
Vector<Job> jobs = new Vector<Job>();
while( currentMembers.hasNext() )
{
- j = (Job)currentMembers.next();
+ j = currentMembers.next();
if( j.getItemSysKey() == sysKey )
jobs.add(j);
diff --git a/source/com/c2kernel/entity/proxy/AgentProxy.java b/source/com/c2kernel/entity/proxy/AgentProxy.java index af77031..f2e8283 100755..100644 --- a/source/com/c2kernel/entity/proxy/AgentProxy.java +++ b/source/com/c2kernel/entity/proxy/AgentProxy.java @@ -66,8 +66,9 @@ public class AgentProxy extends EntityProxy throw new ObjectNotFoundException();
}
}
-
- public ManageableEntity narrow() throws ObjectNotFoundException
+
+ @Override
+ public ManageableEntity narrow() throws ObjectNotFoundException
{
try {
return AgentHelper.narrow(mIOR);
@@ -85,48 +86,48 @@ public class AgentProxy extends EntityProxy 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.
- *
+ * Executes a job on the given item using this agent.
+ *
* @param item - item holding this job
* @param job - the job to execute
*/
- public void execute(ItemProxy item, Job job)
- throws AccessRightsException,
- InvalidTransitionException,
- ObjectNotFoundException,
- InvalidDataException,
+ public void execute(ItemProxy item, Job job)
+ throws AccessRightsException,
+ InvalidTransitionException,
+ ObjectNotFoundException,
+ InvalidDataException,
PersistencyException,
ObjectAlreadyExistsException
- {
+ {
OutcomeValidator validator = null;
String scriptName = job.getActPropString("ScriptName");
Date startTime = new Date();
Logger.msg(3, "AgentProxy - executing "+job.getStepPath()+" for "+path.getAgentName());
// get the outcome validator if present
- if (job.isOutcomeUsed())
+ if (job.isOutcomeUsed())
{
-
+
// get schema info from act props
String schemaName = job.getActPropString("SchemaType");
int schemaVersion;
try {
schemaVersion = Integer.parseInt(job.getActPropString("SchemaVersion"));
- } catch (Exception e) {
+ } catch (Exception e) {
throw new InvalidDataException(e.getClass().getName()+" extracing schema version", "");
}
Logger.msg(5, "AgentProxy - fetching schema "+schemaName+"_"+schemaVersion+" for validation");
// retrieve schema
Schema schema = LocalObjectLoader.getSchema(schemaName, schemaVersion);
-
+
if (schema == null)
throw new InvalidDataException("Job references outcome type "+schemaName+" version "+schemaVersion+" that does not exist in this centre.", "");
@@ -136,12 +137,12 @@ public class AgentProxy extends EntityProxy throw new InvalidDataException("Could not create validator: "+e.getMessage(), "");
}
}
-
- if(scriptName != null && scriptName.length() > 0 &&
+
+ if(scriptName != null && scriptName.length() > 0 &&
(job.getPossibleTransition() == Transitions.DONE || job.getPossibleTransition() == Transitions.COMPLETE)) {
Logger.msg(3, "AgentProxy - executing script "+scriptName);
try {
-
+
// pre-validate outcome from script if there is one
if (job.getOutcomeString()!= null && validator != null) {
Logger.msg(5, "AgentProxy - validating outcome before script execution");
@@ -151,10 +152,10 @@ public class AgentProxy extends EntityProxy throw new InvalidDataException(error, "");
}
}
-
+
// load script
ErrorInfo scriptErrors = (ErrorInfo)callScript(item, job);
-
+
if (scriptErrors.getFatal()) {
Logger.msg(3, "AgentProxy - fatal script error");
Logger.error(scriptErrors.getErrors());
@@ -174,7 +175,7 @@ public class AgentProxy extends EntityProxy if (error.length() > 0)
throw new InvalidDataException(error, "");
}
-
+
job.setAgentId(getSystemKey());
Logger.msg(3, "AgentProxy - submitting job to item proxy");
item.requestAction(job);
@@ -184,16 +185,16 @@ public class AgentProxy extends EntityProxy Logger.msg(3, "Execution took "+secsNow+" seconds");
}
}
-
+
public Object callScript(ItemProxy item, Job job) throws ScriptingEngineException {
Script script = new Script(item, this, job);
return script.execute();
}
-
+
/**
- * Standard execution of jobs. Note that this method should always be the one used from clients - all execution
- * parameters are taken from the job where they're probably going to be correct.
- *
+ * Standard execution of jobs. Note that this method should always be the one used from clients - all execution
+ * parameters are taken from the job where they're probably going to be correct.
+ *
* @param job
* @throws AccessRightsException
* @throws InvalidDataException
@@ -202,7 +203,7 @@ public class AgentProxy extends EntityProxy * @throws PersistencyException
* @throws ObjectAlreadyExistsException
*/
- public void execute(Job job)
+ public void execute(Job job)
throws AccessRightsException,
InvalidDataException,
InvalidTransitionException,
@@ -217,8 +218,8 @@ public class AgentProxy extends EntityProxy throw new ObjectNotFoundException("Job contained invalid item sysKey: "+job.getItemSysKey(), "");
}
}
-
- public void execute(ItemProxy item, String predefStep, C2KLocalObject obj)
+
+ public void execute(ItemProxy item, String predefStep, C2KLocalObject obj)
throws AccessRightsException,
InvalidDataException,
InvalidTransitionException,
@@ -235,8 +236,8 @@ public class AgentProxy extends EntityProxy }
execute(item, predefStep, param);
}
-
- public void execute(ItemProxy item, String predefStep, String param)
+
+ public void execute(ItemProxy item, String predefStep, String param)
throws AccessRightsException,
InvalidDataException,
InvalidTransitionException,
@@ -248,8 +249,8 @@ public class AgentProxy extends EntityProxy params[0] = param;
execute(item, predefStep, params);
}
-
- public void execute(ItemProxy item, String predefStep, String[] params)
+
+ public void execute(ItemProxy item, String predefStep, String[] params)
throws AccessRightsException,
InvalidDataException,
InvalidTransitionException,
@@ -259,42 +260,42 @@ public class AgentProxy extends EntityProxy {
item.requestAction(getSystemKey(), "workflow/predefined/"+predefStep, Transitions.DONE, PredefinedStep.bundleData(params));
}
-
+
/** Wrappers for scripts */
public String marshall(Object obj) throws Exception {
return CastorXMLUtility.marshall(obj);
}
-
+
public Object unmarshall(String obj) throws Exception {
return CastorXMLUtility.unmarshall(obj);
}
-
+
/** Let scripts resolve items */
public ItemProxy searchItem(String name) throws ObjectNotFoundException {
- Enumeration results = Gateway.getLDAPLookup().search(new DomainPath(""),name);
-
+ Enumeration<?> results = Gateway.getLDAPLookup().search(new DomainPath(""),name);
+
Path returnPath = null;
if (!results.hasMoreElements())
throw new ObjectNotFoundException(name, "");
-
+
while(results.hasMoreElements()) {
Path nextMatch = (Path)results.nextElement();
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);
}
-
+
public ItemProxy getItem(String path) throws ObjectNotFoundException {
return (getItem(new DomainPath(path)));
}
-
+
public ItemProxy getItem(DomainPath path) throws ObjectNotFoundException {
return (ItemProxy)Gateway.getProxyManager().getProxy(path);
}
-
+
public ItemProxy getItemBySysKey(int sysKey) throws ObjectNotFoundException, InvalidEntityPathException {
return (ItemProxy)Gateway.getProxyManager().getProxy(new EntityPath(sysKey));
}
diff --git a/source/com/c2kernel/entity/proxy/DomainPathSubscriber.java b/source/com/c2kernel/entity/proxy/DomainPathSubscriber.java index e09178d..4089325 100755..100644 --- a/source/com/c2kernel/entity/proxy/DomainPathSubscriber.java +++ b/source/com/c2kernel/entity/proxy/DomainPathSubscriber.java @@ -12,7 +12,7 @@ import com.c2kernel.lookup.DomainPath; **************************************************************************/
public interface DomainPathSubscriber {
-
+
public void pathAdded(DomainPath path);
public void pathRemoved(DomainPath path);
}
diff --git a/source/com/c2kernel/entity/proxy/EntityProxy.java b/source/com/c2kernel/entity/proxy/EntityProxy.java index b34653f..a9f6066 100644 --- a/source/com/c2kernel/entity/proxy/EntityProxy.java +++ b/source/com/c2kernel/entity/proxy/EntityProxy.java @@ -10,14 +10,17 @@ package com.c2kernel.entity.proxy;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Iterator;
import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.entity.*;
-import com.c2kernel.persistency.*;
+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.*;
+import com.c2kernel.utils.CastorXMLUtility;
+import com.c2kernel.utils.Logger;
/******************************************************************************
@@ -35,7 +38,7 @@ abstract public class EntityProxy implements ManageableEntity protected ManageableEntity mEntity = null;
protected org.omg.CORBA.Object mIOR;
protected int mSystemKey;
- private HashMap<MemberSubscription, EntityProxyObserver> mSubscriptions;
+ private HashMap<MemberSubscription<?>, EntityProxyObserver<?>> mSubscriptions;
/**************************************************************************
*
@@ -45,7 +48,7 @@ abstract public class EntityProxy implements ManageableEntity throws ObjectNotFoundException
{
Logger.msg(8,"EntityProxy::EntityProxy() - Initialising '" +systemKey+ "' entity");
-
+
initialise( ior, systemKey);
}
@@ -60,7 +63,7 @@ abstract public class EntityProxy implements ManageableEntity mIOR = ior;
mSystemKey = systemKey;
- mSubscriptions = new HashMap<MemberSubscription, EntityProxyObserver>();
+ mSubscriptions = new HashMap<MemberSubscription<?>, EntityProxyObserver<?>>();
}
@@ -74,14 +77,15 @@ abstract public class EntityProxy implements ManageableEntity }
return mEntity;
}
-
+
abstract public ManageableEntity narrow() throws ObjectNotFoundException;
-
+
/**************************************************************************
*
**************************************************************************/
//check who is using.. and if toString() is sufficient
- public int getSystemKey()
+ @Override
+ public int getSystemKey()
{
return mSystemKey;
}
@@ -90,7 +94,8 @@ abstract public class EntityProxy implements ManageableEntity /**************************************************************************
*
**************************************************************************/
- public String queryData( String path )
+ @Override
+ public String queryData( String path )
throws ObjectNotFoundException
{
@@ -114,9 +119,9 @@ abstract public class EntityProxy implements ManageableEntity } 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()));
@@ -160,39 +165,36 @@ abstract public class EntityProxy implements ManageableEntity throw new ObjectNotFoundException();
}
}
-
+
public String getName()
{
try {
- return getProperty("Name");
+ return getProperty("Name");
} catch (ObjectNotFoundException ex) {
return null;
}
}
-
+
/**************************************************************************
* Subscription methods
**************************************************************************/
- public void subscribe (EntityProxyObserver observer,
- String interest,
- boolean preload)
- {
- MemberSubscription newSub = new MemberSubscription(this, interest, observer, preload);
- synchronized (this){
- mSubscriptions.put( newSub, observer );
+ public void subscribe (MemberSubscription<?> newSub) {
+
+ newSub.setSubject(this);
+ synchronized (this){
+ mSubscriptions.put( newSub, newSub.getObserver() );
}
new Thread(newSub).start();
- Logger.msg(7, "Subscribed "+observer.getClass().getName()+" for "+interest);
+ Logger.msg(7, "Subscribed "+newSub.getObserver().getClass().getName()+" for "+newSub.interest);
}
-
- public void unsubscribe(EntityProxyObserver observer)
+ public void unsubscribe(EntityProxyObserver<?> observer)
{
synchronized (this){
- for (Iterator e = mSubscriptions.keySet().iterator(); e.hasNext();) {
- MemberSubscription thisSub = (MemberSubscription)e.next();
+ 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());
@@ -200,14 +202,13 @@ abstract public class EntityProxy implements ManageableEntity }
}
}
-
+
public void dumpSubscriptions(int logLevel) {
if (mSubscriptions.size() == 0) return;
Logger.msg(logLevel, "Subscriptions to proxy "+mSystemKey+":");
synchronized(this) {
- for (Iterator iter = mSubscriptions.keySet().iterator(); iter.hasNext();) {
- MemberSubscription element = (MemberSubscription)iter.next();
- EntityProxyObserver obs = element.getObserver();
+ for (MemberSubscription<?> element : mSubscriptions.keySet()) {
+ EntityProxyObserver<?> obs = element.getObserver();
if (obs != null)
Logger.msg(logLevel, " "+element.getObserver().getClass().getName()+" subscribed to "+element.interest);
else
@@ -215,14 +216,14 @@ abstract public class EntityProxy implements ManageableEntity }
}
}
-
+
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 e = mSubscriptions.keySet().iterator(); e.hasNext();) {
- MemberSubscription newSub = (MemberSubscription)e.next();
+ 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();
@@ -232,11 +233,12 @@ abstract public class EntityProxy implements ManageableEntity }
}
}
-
+
/**
* If this is reaped, clear out the cache for it too.
*/
- protected void finalize() throws Throwable {
+ @Override
+ protected void finalize() throws Throwable {
Logger.msg(7, "Proxy "+mSystemKey+" reaped");
Gateway.getStorage().clearCache(mSystemKey, null);
Gateway.getProxyManager().removeProxy(mSystemKey);
diff --git a/source/com/c2kernel/entity/proxy/EntityProxyManager.java b/source/com/c2kernel/entity/proxy/EntityProxyManager.java index 3224da7..8ad4576 100644 --- a/source/com/c2kernel/entity/proxy/EntityProxyManager.java +++ b/source/com/c2kernel/entity/proxy/EntityProxyManager.java @@ -10,7 +10,11 @@ package com.c2kernel.entity.proxy;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.ConcurrentModificationException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
@@ -25,12 +29,12 @@ import com.c2kernel.utils.SoftCache; import com.c2kernel.utils.server.SimpleTCPIPServer;
-public class EntityProxyManager
+public class EntityProxyManager
{
SoftCache<Integer, EntityProxy> proxyPool = new SoftCache<Integer, EntityProxy>(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;
@@ -42,8 +46,8 @@ public class EntityProxyManager public EntityProxyManager()
{
Logger.msg(5, "EntityProxyManager - Starting.....");
-
- Enumeration servers = Gateway.getLDAPLookup().searchEntities(new DomainPath("/servers"));
+
+ Enumeration<?> servers = Gateway.getLDAPLookup().searchEntities(new DomainPath("/servers"));
while(servers.hasMoreElements()) {
Path thisServerPath = (Path)servers.nextElement();
try {
@@ -52,65 +56,62 @@ public class EntityProxyManager String portStr = ((Property)Gateway.getStorage().get(syskey, ClusterStorage.PROPERTY+"/ProxyPort", null)).getValue();
int remotePort = Integer.parseInt(portStr);
connectToProxyServer(remoteServer, remotePort);
-
+
} catch (Exception ex) {
Logger.error("Exception retrieving proxy server connection data for "+thisServerPath);
Logger.error(ex);
}
}
}
-
+
public void connectToProxyServer(String name, int port) {
- ProxyServerConnection oldConn = (ProxyServerConnection)connections.get(name);
+ ProxyServerConnection oldConn = connections.get(name);
if (oldConn != null)
oldConn.shutdown();
connections.put(name, new ProxyServerConnection(name, port, this));
}
-
-
+
+
protected void resubscribe(ProxyServerConnection conn) {
synchronized (proxyPool) {
- for (Iterator iter = proxyPool.keySet().iterator(); iter.hasNext();) {
- Integer key = (Integer)iter.next();
+ for (Integer key : proxyPool.keySet()) {
ProxyMessage sub = new ProxyMessage(key.intValue(), ProxyMessage.ADDPATH, false);
Logger.msg(5, "Subscribing to entity "+key);
conn.sendMessage(sub);
}
}
}
-
+
/**
* @param sub
*/
private void sendMessage(ProxyMessage sub) {
- for (Iterator iter = connections.values().iterator(); iter.hasNext();) {
- ProxyServerConnection element = (ProxyServerConnection) iter.next();
+ for (ProxyServerConnection element : connections.values()) {
element.sendMessage(sub);
}
-
+
}
public void shutdown() {
Logger.msg("EntityProxyManager.shutdown() - flagging shutdown of server connections");
- for (Iterator iter = connections.values().iterator(); iter.hasNext();) {
- ProxyServerConnection element = (ProxyServerConnection) iter.next();
+ for (ProxyServerConnection element : connections.values()) {
element.shutdown();
}
}
-
+
protected void processMessage(ProxyMessage thisMessage) throws InvalidDataException {
if (Logger.doLog(9)) Logger.msg(9, thisMessage.toString());
-
+
if (thisMessage.getPath().equals(ProxyMessage.PINGPATH)) // ping response
return;
-
+
if (thisMessage.getSysKey() == ProxyMessage.NA) // must be domain path info
informTreeSubscribers(thisMessage.getState(), thisMessage.getPath());
else {
// proper proxy message
Logger.msg(5, "Received proxy message: "+thisMessage.toString());
Integer key = new Integer(thisMessage.getSysKey());
- EntityProxy relevant = (EntityProxy)proxyPool.get(key);
+ EntityProxy 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
@@ -120,18 +121,17 @@ public class EntityProxyManager Logger.error("Error caught notifying proxy listener "+relevant.toString()+" of "+thisMessage.toString());
Logger.error(ex);
}
- }
+ }
}
-
+
private void informTreeSubscribers(boolean state, String path) {
DomainPath last = new DomainPath(path);
DomainPath parent; boolean first = true;
synchronized(treeSubscribers) {
while((parent = last.getParent()) != null) {
-
- for (Iterator iter = treeSubscribers.keySet().iterator(); iter.hasNext();) {
- DomainPathSubscriber sub = (DomainPathSubscriber)iter.next();
- DomainPath interest = (DomainPath)treeSubscribers.get(sub);
+
+ for (DomainPathSubscriber sub : treeSubscribers.keySet()) {
+ DomainPath interest = treeSubscribers.get(sub);
if (interest.equals(parent)) {
if (state == ProxyMessage.ADDED)
sub.pathAdded(last);
@@ -142,26 +142,26 @@ public class EntityProxyManager last = parent;
first = false;
}
- }
+ }
}
-
+
public void subscribeTree(DomainPathSubscriber sub, DomainPath interest) {
synchronized(treeSubscribers) {
treeSubscribers.put(sub, interest);
}
}
-
+
public void unsubscribeTree(DomainPathSubscriber sub) {
synchronized(treeSubscribers) {
treeSubscribers.remove(sub);
- }
+ }
}
/**************************************************************************
*
**************************************************************************/
- private EntityProxy createProxy( org.omg.CORBA.Object ior,
- int systemKey,
+ private EntityProxy createProxy( org.omg.CORBA.Object ior,
+ int systemKey,
boolean isItem )
throws ObjectNotFoundException
{
@@ -185,7 +185,7 @@ public class EntityProxyManager reportCurrentProxies(9);
return ( newProxy );
}
-
+
protected void removeProxy( int systemKey )
{
ProxyMessage sub = new ProxyMessage(systemKey, ProxyMessage.DELPATH, true);
@@ -210,7 +210,7 @@ public class EntityProxyManager synchronized(proxyPool) {
EntityProxy newProxy;
// return it if it exists
- newProxy = (EntityProxy)proxyPool.get(key);
+ newProxy = proxyPool.get(key);
if (newProxy == null) {
// create a new one
newProxy = createProxy(ior, systemKey, isItem );
@@ -250,14 +250,14 @@ public class EntityProxyManager Logger.msg(logLevel, "Current proxies: ");
try {
synchronized(proxyPool) {
- Iterator i = proxyPool.keySet().iterator();
-
+ Iterator<Integer> i = proxyPool.keySet().iterator();
+
for( int count=0; i.hasNext(); count++ )
{
- Integer nextProxy = (Integer)i.next();
- EntityProxy thisProxy = (EntityProxy)proxyPool.get(nextProxy);
+ Integer nextProxy = i.next();
+ EntityProxy thisProxy = proxyPool.get(nextProxy);
if (thisProxy != null)
- Logger.msg(logLevel,
+ Logger.msg(logLevel,
"" + count + ": "
+ proxyPool.get(nextProxy).getClass().getName()
+ ": " + nextProxy);
@@ -267,12 +267,12 @@ public class EntityProxyManager Logger.msg(logLevel, "Proxy cache modified. Aborting.");
}
}
-
+
/**************************************************************************
* Static Proxy Server methods
- **************************************************************************/
-
+ **************************************************************************/
+
/**
* Initialises the Proxy event UDP server listening on 'Host.Proxy.port' from c2kprops
* @param c2kProps
@@ -286,7 +286,7 @@ public class EntityProxyManager 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 {
int portNo = Integer.parseInt(port);
@@ -298,40 +298,38 @@ public class EntityProxyManager Logger.error(ex);
}
}
-
+
public static void sendProxyEvent(ProxyMessage message) {
if (proxyServer != null && message.getPath() != null)
synchronized(proxyClients) {
- for (Iterator iter = proxyClients.iterator(); iter.hasNext();) {
- ProxyClientConnection client = (ProxyClientConnection)iter.next();
+ for (ProxyClientConnection client : proxyClients) {
client.sendMessage(message);
}
}
}
-
+
public static void reportConnections(int logLevel) {
synchronized(proxyClients) {
Logger.msg(logLevel, "Currently connected proxy clients:");
- for (Iterator iter = proxyClients.iterator(); iter.hasNext();) {
- ProxyClientConnection client = (ProxyClientConnection)iter.next();
+ 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/source/com/c2kernel/entity/proxy/EntityProxyObserver.java b/source/com/c2kernel/entity/proxy/EntityProxyObserver.java index 985143d..3ddb99c 100755..100644 --- a/source/com/c2kernel/entity/proxy/EntityProxyObserver.java +++ b/source/com/c2kernel/entity/proxy/EntityProxyObserver.java @@ -4,14 +4,14 @@ import com.c2kernel.entity.C2KLocalObject; -public interface EntityProxyObserver
+public interface EntityProxyObserver<V extends C2KLocalObject>
{
/**************************************************************************
* Subscribed items are broken apart and fed one by one to these methods.
* Replacement after an event is done by feeding the new memberbase with the same id.
* ID could be an XPath?
**************************************************************************/
- public void add(C2KLocalObject contents);
+ public void add(V contents);
/**************************************************************************
* the 'type' parameter should be an indication of the type of object
@@ -22,4 +22,6 @@ public interface EntityProxyObserver * the subscribe method of ItemProxy.
**************************************************************************/
public void remove(String id);
+
+ public void control(String control, String msg);
}
diff --git a/source/com/c2kernel/entity/proxy/ItemProxy.java b/source/com/c2kernel/entity/proxy/ItemProxy.java index 702dd26..658e0c8 100644 --- a/source/com/c2kernel/entity/proxy/ItemProxy.java +++ b/source/com/c2kernel/entity/proxy/ItemProxy.java @@ -18,7 +18,9 @@ import com.c2kernel.common.InvalidTransitionException; import com.c2kernel.common.ObjectAlreadyExistsException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.common.PersistencyException;
-import com.c2kernel.entity.*;
+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.stateMachine.Transitions;
@@ -43,10 +45,11 @@ public class ItemProxy extends EntityProxy throws ObjectNotFoundException
{
super(ior, systemKey);
-
+
}
- public ManageableEntity narrow() throws ObjectNotFoundException
+ @Override
+ public ManageableEntity narrow() throws ObjectNotFoundException
{
try {
return ItemHelper.narrow(mIOR);
@@ -86,29 +89,29 @@ public class ItemProxy extends EntityProxy } catch (Exception e) {
Logger.error(e);
throw new PersistencyException("Could not store property");
- }
+ }
}
/**************************************************************************
*
**************************************************************************/
- protected void requestAction( Job thisJob )
- throws AccessRightsException,
- InvalidTransitionException,
- ObjectNotFoundException,
- InvalidDataException,
+ protected void requestAction( Job thisJob )
+ throws AccessRightsException,
+ InvalidTransitionException,
+ ObjectNotFoundException,
+ InvalidDataException,
PersistencyException,
ObjectAlreadyExistsException
{
- String outcome = thisJob.getOutcomeString();
+ String outcome = thisJob.getOutcomeString();
// check fields that should have been filled in
- if (outcome==null)
- if (thisJob.isOutcomeUsed())
+ if (outcome==null)
+ if (thisJob.isOutcomeUsed())
throw new InvalidDataException("Outcome is required.", "");
else
- outcome="";
-
- if (thisJob.getAgentId() == -1)
- throw new InvalidDataException("No Agent specified.", "");
+ outcome="";
+
+ if (thisJob.getAgentId() == -1)
+ throw new InvalidDataException("No Agent specified.", "");
Logger.msg(7, "ItemProxy - executing "+thisJob.getStepPath()+" for "+thisJob.getAgentName());
requestAction (thisJob.getAgentId(), thisJob.getStepPath(),
@@ -128,7 +131,7 @@ public class ItemProxy extends EntityProxy PersistencyException,
ObjectAlreadyExistsException
{
- ((Item)getEntity()).requestAction( agentId,
+ ((Item)getEntity()).requestAction( agentId,
stepPath,
transitionID,
requestData );
@@ -139,9 +142,9 @@ public class ItemProxy extends EntityProxy **************************************************************************/
public String queryLifeCycle( int agentId,
boolean filter
- )
- throws AccessRightsException,
- ObjectNotFoundException,
+ )
+ throws AccessRightsException,
+ ObjectNotFoundException,
PersistencyException
{
return ((Item)getEntity()).queryLifeCycle( agentId,
@@ -168,15 +171,15 @@ public class ItemProxy extends EntityProxy }
return thisJobList.list;
}
-
+
public ArrayList<Job> getJobList(AgentProxy agent)
throws AccessRightsException,
ObjectNotFoundException,
PersistencyException
{
- return getJobList(agent.getSystemKey());
+ return getJobList(agent.getSystemKey());
}
-
+
private ArrayList<Job> getJobList(int agentId)
throws AccessRightsException,
ObjectNotFoundException,
@@ -189,7 +192,7 @@ public class ItemProxy extends EntityProxy throws AccessRightsException,
ObjectNotFoundException,
PersistencyException {
-
+
ArrayList<Job> jobList = getJobList(agentId);
for (Job job : jobList) {
int transition = job.getPossibleTransition();
@@ -200,7 +203,7 @@ public class ItemProxy extends EntityProxy return null;
}
-
+
public Job getJobByName(String actName, AgentProxy agent)
throws AccessRightsException,
ObjectNotFoundException,
diff --git a/source/com/c2kernel/entity/proxy/MemberControl.java b/source/com/c2kernel/entity/proxy/MemberControl.java deleted file mode 100755 index 5f483ae..0000000 --- a/source/com/c2kernel/entity/proxy/MemberControl.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.c2kernel.entity.proxy;
-
-import com.c2kernel.entity.C2KLocalObject;
-
-
-/**
- * @version $Revision: 1.2 $ $Date: 2004/02/04 11:02:44 $
- * @author $Author: abranson $
- */
-
-public class MemberControl implements C2KLocalObject {
-
- public static final int ERROR = -1;
- public static final int END = -2;
- public static MemberControl theEND = new MemberControl(END, null);
- private int id;
- private String name;
-
- public MemberControl(int code, String msg) {
- this.setID(code);
- switch (code) {
- case MemberControl.ERROR:
- this.setName("ERROR: The path "+msg+" was not found.");
- break;
- case MemberControl.END:
- this.setName("END: End of preload");
- break;
- default:
- this.setName("Unsupported control message code: "+code);
- }
- }
-
- public String toString() {
- return "MemberControl: "+this.getName();
- }
-
- public int getID() { return id; }
- public void setID(int id) { this.id = id; }
- public String getName() { return name; }
- public void setName(String name) { this.name = name; }
- public String getClusterType() { return null; }
-
-}
diff --git a/source/com/c2kernel/entity/proxy/MemberSubscription.java b/source/com/c2kernel/entity/proxy/MemberSubscription.java index ba2d725..157297f 100644 --- a/source/com/c2kernel/entity/proxy/MemberSubscription.java +++ b/source/com/c2kernel/entity/proxy/MemberSubscription.java @@ -8,31 +8,33 @@ import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.utils.Logger;
-public class MemberSubscription implements Runnable {
+public class MemberSubscription<C extends C2KLocalObject> implements Runnable {
+ public static final String ERROR = "Error";
+ public static final String END = "theEND";
+
EntityProxy subject;
String interest;
// keep the subscriber by weak reference, so it is not kept from the garbage collector if no longer used
- WeakReference<EntityProxyObserver> observerReference;
+ WeakReference<EntityProxyObserver<C>> observerReference;
ArrayList<String> contents = new ArrayList<String>();
boolean preLoad;
- public MemberSubscription(EntityProxy subject, String interest,
- EntityProxyObserver observer, boolean preLoad) {
+ public MemberSubscription(EntityProxyObserver<C> observer, String interest, boolean preLoad) {
setObserver(observer);
this.interest = interest;
- this.subject = subject;
this.preLoad = preLoad;
}
- public void run() {
+ @Override
+ public void run() {
Thread.currentThread().setName("Member Subscription: "+subject.getSystemKey()+":"+interest);
if (preLoad) loadChildren();
}
-
+
private void loadChildren() {
- C2KLocalObject newMember;
- EntityProxyObserver observer = getObserver();
- if (observer == null) return; //reaped
+ C newMember;
+ EntityProxyObserver<C> observer = getObserver();
+ if (observer == null) return; //reaped
try {
// fetch contents of path
String children = subject.queryData(interest+"/all");
@@ -40,22 +42,17 @@ public class MemberSubscription implements Runnable { ArrayList<String> newContents = new ArrayList<String>();
while (tok.hasMoreTokens())
newContents.add(tok.nextToken());
-
+
// look to see what's new
for (String newChild: newContents) {
-
+
// load child object
try {
- newMember = subject.getObject(interest+"/"+newChild);
+ newMember = (C)subject.getObject(interest+"/"+newChild);
contents.remove(newChild);
- } catch (ObjectNotFoundException ex) {
- newMember = new MemberControl(MemberControl.ERROR, "Listed member "+newChild+" was not found.");
- }
- try {
observer.add(newMember);
- } catch (Throwable ex) {
- Logger.error("Error publishing member to "+observer);
- Logger.error(ex);
+ } catch (ObjectNotFoundException ex) {
+ observer.control(ERROR, "Listed member "+newChild+" was not found.");
}
}
// report what's left in old contents as deleted
@@ -65,24 +62,24 @@ public class MemberSubscription implements Runnable { //replace contents arraylist
contents = newContents;
//report that we're done
- observer.add(MemberControl.theEND);
+ observer.control(END, null);
} catch (Exception ex) {
- observer.add(new MemberControl(MemberControl.ERROR, "Query on "+interest+" failed with "+ex));
- }
+ observer.control(ERROR, "Query on "+interest+" failed with "+ex);
+ }
}
-
+
public boolean isRelevant(String path) {
Logger.msg(7, "Checking relevance of "+path+" to "+interest);
return (path.startsWith(interest));
}
-
+
public void update(String path, boolean deleted) {
- EntityProxyObserver observer = getObserver();
+ EntityProxyObserver<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
return;
-
+
if (path.equals(interest)) // refresh contents
loadChildren();
else {
@@ -92,9 +89,9 @@ public class MemberSubscription implements Runnable { contents.remove(name);
observer.remove(name);
}
- else {
+ else {
try {
- C2KLocalObject newMember = subject.getObject(path);
+ C newMember = (C)subject.getObject(path);
Logger.msg(4, "Adding "+path);
contents.add(name);
observer.add(newMember);
@@ -102,17 +99,20 @@ public class MemberSubscription implements Runnable { Logger.error("Member Subscription: could not load "+path);
Logger.error(e);
}
- }
+ }
}
}
-
- public void setObserver(EntityProxyObserver observer) {
- observerReference = new WeakReference<EntityProxyObserver>(observer);
+
+ public void setObserver(EntityProxyObserver<C> observer) {
+ observerReference = new WeakReference<EntityProxyObserver<C>>(observer);
}
- public EntityProxyObserver getObserver() {
- EntityProxyObserver observer = (EntityProxyObserver)observerReference.get();
- return observer;
+ public void setSubject(EntityProxy subject) {
+ this.subject = subject;
+ }
+
+ public EntityProxyObserver<C> getObserver() {
+ return observerReference.get();
}
}
diff --git a/source/com/c2kernel/entity/proxy/ProxyClientConnection.java b/source/com/c2kernel/entity/proxy/ProxyClientConnection.java index f041012..9687f22 100644 --- a/source/com/c2kernel/entity/proxy/ProxyClientConnection.java +++ b/source/com/c2kernel/entity/proxy/ProxyClientConnection.java @@ -41,17 +41,20 @@ public class ProxyClientConnection implements SocketHandler { }
- public String getName() {
+ @Override
+ public String getName() {
return "Proxy Client Connection";
}
- public boolean isBusy() {
+ @Override
+ public boolean isBusy() {
return clientSocket != null;
}
-
- public synchronized void setSocket(Socket newSocket) {
+
+ @Override
+ public synchronized void setSocket(Socket newSocket) {
try {
- Logger.msg(1, "Proxy Client Connection "+thisClientId+" connect from "+newSocket.getInetAddress()+":"+newSocket.getPort());
+ Logger.msg(1, "Proxy Client Connection "+thisClientId+" connect from "+newSocket.getInetAddress()+":"+newSocket.getPort());
newSocket.setSoTimeout(500);
clientSocket = newSocket;
response = new PrintWriter(clientSocket.getOutputStream(), true);
@@ -66,11 +69,12 @@ public class ProxyClientConnection implements SocketHandler { closeSocket();
}
}
-
+
/**
* Main loop. Reads proxy commands from the client and acts on them.
*/
- public void run() {
+ @Override
+ public void run() {
Thread.currentThread().setName("Proxy Client Connection: "+clientSocket.getInetAddress());
Logger.msg(7, "ProxyClientConnection "+thisClientId+" - Setting up proxy client connection with "+clientSocket.getInetAddress());
try {
@@ -87,7 +91,7 @@ public class ProxyClientConnection implements SocketHandler { } catch (InvalidDataException ex) { // invalid proxy message
Logger.error("ProxyClientConnection "+thisClientId+" - Invalid proxy message: "+input);
}
-
+
}
} catch (IOException ex) {
if (!closing)
@@ -96,68 +100,70 @@ public class ProxyClientConnection implements SocketHandler { closeSocket();
Logger.msg(1, "ProxyClientConnection "+thisClientId+" closed.");
}
-
+
private void processMessage(ProxyMessage message) throws InvalidDataException {
-
+
// proxy disconnection
if (message.getPath().equals(ProxyMessage.BYEPATH)) {
Logger.msg(7, "ProxyClientConnection "+thisClientId+" disconnecting");
closeSocket();
}
-
+
// proxy checking connection
- else if (message.getPath().equals(ProxyMessage.PINGPATH))
+ else if (message.getPath().equals(ProxyMessage.PINGPATH))
response.println(ProxyMessage.pingMessage);
-
+
// new subscription to entity changes
else if (message.getPath().equals(ProxyMessage.ADDPATH)) {
Logger.msg(7, "ProxyClientConnection "+thisClientId+" subscribed to "+message.getSysKey());
synchronized (sysKeys) {
sysKeys.add(new Integer(message.getSysKey()));
- }
+ }
}
-
- // remove of subscription to entity changes
+
+ // remove of subscription to entity changes
else if (message.getPath().equals(ProxyMessage.DELPATH)) {
synchronized (sysKeys) {
sysKeys.remove(new Integer(message.getSysKey()));
- }
+ }
Logger.msg(7, "ProxyClientConnection "+thisClientId+" unsubscribed from "+message.getSysKey());
}
-
+
else // unknown message
- Logger.error("ProxyClientConnection "+thisClientId+" - Unknown message type: "+message);
-
- }
-
+ Logger.error("ProxyClientConnection "+thisClientId+" - Unknown message type: "+message);
+
+ }
+
public synchronized void sendMessage(ProxyMessage message) {
- if (clientSocket==null) return; // idle
- boolean relevant = message.getSysKey() == ProxyMessage.NA;
+ if (clientSocket==null) return; // idle
+ boolean relevant = message.getSysKey() == ProxyMessage.NA;
synchronized (sysKeys) {
- for (Iterator iter = sysKeys.iterator(); iter.hasNext() && !relevant;) {
- Integer thisKey = (Integer)iter.next();
+ for (Iterator<Integer> iter = sysKeys.iterator(); iter.hasNext() && !relevant;) {
+ Integer thisKey = iter.next();
if (thisKey.intValue() == message.getSysKey())
relevant = true;
}
}
if (!relevant) return; // not for our client
-
+
response.println(message);
}
-
- public void shutdown() {
+
+ @Override
+ public void shutdown() {
if (isBusy()) {
closing = true;
Logger.msg("ProxyClientConnection "+thisClientId+" closing.");
closeSocket();
}
}
-
- public String toString() {
+
+ @Override
+ public String toString() {
if (clientSocket == null) return thisClientId+": idle";
else return thisClientId+": "+clientSocket.getInetAddress();
}
-
+
private synchronized void closeSocket() {
if (clientSocket==null) return;
try {
@@ -171,9 +177,9 @@ public class ProxyClientConnection implements SocketHandler { synchronized (sysKeys) {
sysKeys = null;
}
-
+
clientSocket = null;
}
-
+
}
diff --git a/source/com/c2kernel/entity/proxy/ProxyMessage.java b/source/com/c2kernel/entity/proxy/ProxyMessage.java index 66f1f34..b312a44 100755..100644 --- a/source/com/c2kernel/entity/proxy/ProxyMessage.java +++ b/source/com/c2kernel/entity/proxy/ProxyMessage.java @@ -18,24 +18,24 @@ import com.c2kernel.common.InvalidDataException; **************************************************************************/
public class ProxyMessage {
-
+
// special server message paths
- public static final String BYEPATH = "bye";
+ public static final String BYEPATH = "bye";
public static final String ADDPATH = "add";
public static final String DELPATH = "del";
public static final String PINGPATH = "ping";
public static final boolean ADDED = false;
public static final boolean DELETED = true;
public static final int NA = -1;
-
- static ProxyMessage byeMessage = new ProxyMessage(NA, BYEPATH, ADDED);
- static ProxyMessage pingMessage = new ProxyMessage(NA, PINGPATH, ADDED);
-
+
+ static ProxyMessage byeMessage = new ProxyMessage(NA, BYEPATH, ADDED);
+ static ProxyMessage pingMessage = new ProxyMessage(NA, PINGPATH, ADDED);
+
private int sysKey = NA;
private String path = "";
private String server = null;
private boolean state = ADDED;
-
+
public ProxyMessage() {
super();
}
@@ -45,7 +45,7 @@ public class ProxyMessage { setPath(path);
setState(state);
}
-
+
public ProxyMessage(String line) throws InvalidDataException, IOException {
if (line == null)
throw new IOException("Null proxy message");
@@ -56,10 +56,10 @@ public class ProxyMessage { path = tok.nextToken();
if (path.startsWith("-")) {
state = DELETED;
- path = path.substring(1);
+ path = path.substring(1);
}
}
-
+
public ProxyMessage(DatagramPacket packet) throws InvalidDataException, IOException {
this(new String(packet.getData()));
}
@@ -67,7 +67,7 @@ public class ProxyMessage { public int getSysKey() {
return sysKey;
}
-
+
public void setSysKey(int sysKey) {
this.sysKey = sysKey;
}
@@ -75,30 +75,31 @@ public class ProxyMessage { public String getPath() {
return path;
}
-
+
public void setPath(String newPath) {
this.path = newPath;
}
-
+
public boolean getState() {
return state;
}
-
+
public void setState(boolean state) {
this.state = state;
}
-
- public String toString() {
- return sysKey+":"+(state?"-":"")+path;
+
+ @Override
+ public String toString() {
+ return sysKey+":"+(state?"-":"")+path;
}
public DatagramPacket getPacket(ProxySubscriber host) {
return getPacket(host.getHost(), host.getPort());
}
-
+
public DatagramPacket getPacket(InetAddress host, int port) {
byte[] packetString = toString().getBytes();
return new DatagramPacket(packetString, packetString.length, host, port);
- }
+ }
public String getServer() {
return server;
diff --git a/source/com/c2kernel/entity/proxy/ProxyServerConnection.java b/source/com/c2kernel/entity/proxy/ProxyServerConnection.java index 191492f..6807953 100755..100644 --- a/source/com/c2kernel/entity/proxy/ProxyServerConnection.java +++ b/source/com/c2kernel/entity/proxy/ProxyServerConnection.java @@ -10,7 +10,11 @@ package com.c2kernel.entity.proxy;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.InterruptedIOException;
+import java.io.PrintWriter;
import java.net.Socket;
import com.c2kernel.common.InvalidDataException;
@@ -30,7 +34,7 @@ public class ProxyServerConnection extends Thread PrintWriter serverStream;
boolean listening = false;
static boolean isServer = false;
-
+
/**
* Create an entity proxy manager to listen for proxy events and reap unused proxies
*/
@@ -43,8 +47,9 @@ public class ProxyServerConnection extends Thread listening = true;
start();
}
-
- public void run() {
+
+ @Override
+ public void run() {
Thread.currentThread().setName("Proxy Client Connection Listener to "+serverName+":"+serverPort);
while (listening) {
try {
@@ -72,14 +77,14 @@ public class ProxyServerConnection extends Thread try {
serverStream.close();
serverConnection.close();
- } catch (IOException e1) { }
+ } catch (IOException e1) { }
+
-
serverStream = null;
serverConnection = null;
}
}
-
+
if (serverStream != null) {
try {
Logger.msg(1, "Disconnecting from proxy server on "+serverName+":"+serverPort);
@@ -90,9 +95,9 @@ public class ProxyServerConnection extends Thread } catch (Exception e) {
Logger.error("Error disconnecting from proxy server.");
}
- }
+ }
}
-
+
public void connect() {
Logger.msg(3, "ProxyServerConnection - connecting to proxy server on "+serverName+":"+serverPort);
try {
@@ -111,12 +116,12 @@ public class ProxyServerConnection extends Thread serverIsActive = false;
}
}
-
+
public void shutdown() {
Logger.msg("Proxy Client: flagging shutdown.");
listening = false;
}
-
+
/**
* @param sub
*/
diff --git a/source/com/c2kernel/entity/proxy/ProxySubscriber.java b/source/com/c2kernel/entity/proxy/ProxySubscriber.java index 67d0a60..8cb85fa 100755..100644 --- a/source/com/c2kernel/entity/proxy/ProxySubscriber.java +++ b/source/com/c2kernel/entity/proxy/ProxySubscriber.java @@ -17,9 +17,9 @@ import com.c2kernel.common.InvalidDataException; public class ProxySubscriber {
- private InetAddress host;
+ private InetAddress host;
private int port;
- public ArrayList sysKeys = new ArrayList();
+ public ArrayList<?> sysKeys = new ArrayList<Object>();
public ProxySubscriber(DatagramPacket packet) throws InvalidDataException {
host = packet.getAddress();
diff --git a/source/com/c2kernel/entity/transfer/TransferItem.java b/source/com/c2kernel/entity/transfer/TransferItem.java index e4e84ec..9234650 100644 --- a/source/com/c2kernel/entity/transfer/TransferItem.java +++ b/source/com/c2kernel/entity/transfer/TransferItem.java @@ -1,17 +1,23 @@ package com.c2kernel.entity.transfer;
import java.io.File;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Enumeration;
import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.entity.*;
+import com.c2kernel.entity.C2KLocalObject;
+import com.c2kernel.entity.TraceableEntity;
import com.c2kernel.lifecycle.instance.Workflow;
-import com.c2kernel.lookup.*;
+import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.lookup.EntityPath;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.outcome.Outcome;
import com.c2kernel.process.Gateway;
-import com.c2kernel.property.*;
-import com.c2kernel.utils.*;
+import com.c2kernel.property.Property;
+import com.c2kernel.property.PropertyArrayList;
+import com.c2kernel.utils.CastorXMLUtility;
+import com.c2kernel.utils.FileStringUtility;
+import com.c2kernel.utils.Logger;
public class TransferItem {
public ArrayList<String> domainPaths;
@@ -31,7 +37,7 @@ public class TransferItem { this.sysKey = sysKey;
domainPaths = new ArrayList<String>();
Property name = (Property)Gateway.getStorage().get(sysKey, ClusterStorage.PROPERTY + "/Name", null);
- Enumeration paths = Gateway.getLDAPLookup().search(new DomainPath(), name.getValue());
+ Enumeration<?> paths = Gateway.getLDAPLookup().search(new DomainPath(), name.getValue());
while (paths.hasMoreElements()) {
DomainPath thisPath = (DomainPath)paths.nextElement();
domainPaths.add(thisPath.toString());
@@ -43,8 +49,8 @@ public class TransferItem { String[] contents = Gateway.getStorage().getClusterContents(sysKey, path);
if (contents.length > 0) {
FileStringUtility.createNewDir(dir.getCanonicalPath());
- for (int i = 0; i < contents.length; i++) {
- exportItem(new File(dir, contents[i]), path + "/" + contents[i]);
+ for (String content : contents) {
+ exportItem(new File(dir, content), path + "/" + content);
}
} else { //no children, try to dump object
try {
@@ -66,12 +72,11 @@ public class TransferItem { } catch (Exception ex) {
}
- ArrayList events, outcomes, viewpoints = new ArrayList();
// retrieve objects
- ArrayList objectFiles = FileStringUtility.listDir(dir.getCanonicalPath(), false, true);
+ ArrayList<?> objectFiles = FileStringUtility.listDir(dir.getCanonicalPath(), false, true);
ArrayList<C2KLocalObject> objects = new ArrayList<C2KLocalObject>();
- for (Iterator iter = objectFiles.iterator(); iter.hasNext();) {
- String element = (String)iter.next();
+ for (Object name : objectFiles) {
+ String element = (String)name;
String xmlFile = FileStringUtility.file2String(element);
C2KLocalObject newObj;
String choppedPath = element.substring(dir.getCanonicalPath().length()+1, element.length()-4);
@@ -88,12 +93,11 @@ public class TransferItem { EntityPath entityPath = new EntityPath(sysKey);
TraceableEntity newItem = (TraceableEntity)Gateway.getCorbaServer().createEntity(entityPath);
Gateway.getLDAPLookup().add(entityPath);
-
+
PropertyArrayList props = new PropertyArrayList();
Workflow wf = null;
// put objects
- for (Iterator iter = objects.iterator(); iter.hasNext();) {
- C2KLocalObject obj = (C2KLocalObject)iter.next();
+ for (C2KLocalObject obj : objects) {
if (obj instanceof Property)
props.list.add((Property)obj);
else if (obj instanceof Workflow)
@@ -102,7 +106,7 @@ public class TransferItem { if (wf == null)
throw new Exception("No workflow found in import for "+sysKey);
-
+
// init item
newItem.initialise(importAgentId, CastorXMLUtility.marshall(props), CastorXMLUtility.marshall(wf.search("workflow/domain")));
@@ -113,19 +117,17 @@ public class TransferItem { importByType(ClusterStorage.VIEWPOINT, objects);
Gateway.getStorage().commit(this);
// add domPaths
- for (Iterator iter = domainPaths.iterator(); iter.hasNext();) {
- String element = (String)iter.next();
+ for (String element : domainPaths) {
DomainPath newPath = new DomainPath(element, entityPath);
Gateway.getLDAPLookup().add(newPath);
}
}
-
- private void importByType(String type, ArrayList objects) throws Exception {
- for (Iterator iter = objects.iterator(); iter.hasNext();) {
- C2KLocalObject element = (C2KLocalObject)iter.next();
+
+ private void importByType(String type, ArrayList<C2KLocalObject> objects) throws Exception {
+ for (C2KLocalObject element : objects) {
if (element.getClusterType().equals(type))
Gateway.getStorage().put(sysKey, element, this);
}
-
+
}
}
\ No newline at end of file diff --git a/source/com/c2kernel/entity/transfer/TransferSet.java b/source/com/c2kernel/entity/transfer/TransferSet.java index f67ba9c..71a593a 100644 --- a/source/com/c2kernel/entity/transfer/TransferSet.java +++ b/source/com/c2kernel/entity/transfer/TransferSet.java @@ -2,7 +2,6 @@ package com.c2kernel.entity.transfer; import java.io.File;
import java.util.ArrayList;
-import java.util.Iterator;
import com.c2kernel.lookup.EntityPath;
import com.c2kernel.lookup.NextKeyManager;
@@ -23,36 +22,35 @@ import com.c2kernel.utils.Logger; public class TransferSet {
public ArrayList<TransferItem> items;
-
+
public TransferSet() {
}
-
+
public TransferSet(int[] sysKeys) {
items = new ArrayList<TransferItem>();
- for (int i = 0; i < sysKeys.length; i++) {
+ for (int sysKey : sysKeys) {
try {
- items.add(new TransferItem(sysKeys[i]));
+ items.add(new TransferItem(sysKey));
} catch (Exception ex) {
- Logger.error("Could not add item "+sysKeys[i]);
+ Logger.error("Could not add item "+sysKey);
Logger.error(ex);
}
}
}
-
+
public void exportPackage(File dir) throws Exception {
if (items==null || items.size() == 0)
throw new Exception("Nothing to dump");
FileStringUtility.createNewDir(dir.getAbsolutePath());
- for (Iterator iter = items.iterator(); iter.hasNext();) {
- TransferItem element = (TransferItem)iter.next();
+ for (TransferItem element : items) {
try {
element.exportItem(new File(dir, String.valueOf(element.sysKey)), "/");
} catch (Exception ex) {
- Logger.error("Error dumping item "+element.sysKey);
- Logger.error(ex);
+ Logger.error("Error dumping item "+element.sysKey);
+ Logger.error(ex);
}
}
-
+
try {
String self = CastorXMLUtility.marshall(this);
FileStringUtility.string2File(new File(dir, "transferSet.xml"), self);
@@ -61,10 +59,9 @@ public class TransferSet { Logger.error(ex);
}
}
-
+
public void importPackage(File rootDir) {
- for (Iterator iter = items.iterator(); iter.hasNext();) {
- TransferItem element = (TransferItem)iter.next();
+ for (TransferItem element : items) {
Logger.msg(5, "Importing "+element.sysKey);
try {
element.importItem(new File(rootDir, String.valueOf(element.sysKey)));
@@ -76,24 +73,23 @@ public class TransferSet { }
checkLastKey();
}
-
+
private void checkLastKey()
- {
+ {
// find highest key in out import set
int packageLastKey = 0;
- for (Iterator iter = items.iterator(); iter.hasNext();) {
- TransferItem element = (TransferItem)iter.next();
+ for (TransferItem element : items) {
if (element.sysKey > packageLastKey)
packageLastKey = element.sysKey;
}
-
+
try
{ // find the current last key
NextKeyManager nextKeyMan = Gateway.getLDAPLookup().getNextKeyManager();
EntityPath lastKey = nextKeyMan.getLastEntityPath();
Logger.msg(1, "Last key imported was "+packageLastKey+". LDAP lastkey was "+lastKey.getSysKey());
-
+
if (packageLastKey > lastKey.getSysKey()) { // set new last
Logger.msg(1, "Updating lastKey to "+packageLastKey);
nextKeyMan.writeLastEntityKey(packageLastKey);
@@ -102,6 +98,6 @@ public class TransferSet { catch (Exception ex)
{
Logger.error("Exception::LoadKeys::processFile() " + ex);
- }
+ }
}
}
|
