From b086f57f56bf0eb9dab9cf321a0f69aaaae84347 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 30 May 2012 08:37:45 +0200 Subject: Initial Maven Conversion --- .../com/c2kernel/entity/agent/ActiveEntity.java | 295 ++++++++++++++++++ .../com/c2kernel/entity/agent/ActiveLocator.java | 87 ++++++ src/main/java/com/c2kernel/entity/agent/Job.java | 346 +++++++++++++++++++++ .../com/c2kernel/entity/agent/JobArrayList.java | 30 ++ .../java/com/c2kernel/entity/agent/JobList.java | 108 +++++++ 5 files changed, 866 insertions(+) create mode 100644 src/main/java/com/c2kernel/entity/agent/ActiveEntity.java create mode 100644 src/main/java/com/c2kernel/entity/agent/ActiveLocator.java create mode 100644 src/main/java/com/c2kernel/entity/agent/Job.java create mode 100644 src/main/java/com/c2kernel/entity/agent/JobArrayList.java create mode 100644 src/main/java/com/c2kernel/entity/agent/JobList.java (limited to 'src/main/java/com/c2kernel/entity/agent') diff --git a/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java b/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java new file mode 100644 index 0000000..3d45e35 --- /dev/null +++ b/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java @@ -0,0 +1,295 @@ +/************************************************************************** + * BasicAgent.java + * + * $Revision: 1.39 $ + * $Date: 2005/04/26 06:48:12 $ + * + * Copyright (C) 2001-2003 CERN - European Organization for Nuclear Research + * All rights reserved. + **************************************************************************/ + +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.ObjectNotFoundException; +import com.c2kernel.common.PersistencyException; +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.CastorXMLUtility; +import com.c2kernel.utils.Logger; + +/************************************************************************** + * ActiveEntity + * + * @author $Author: abranson $ $Date: 2005/04/26 06:48:12 $ + * @version $Revision: 1.39 $ + **************************************************************************/ +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 + */ + 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."); + } + + /** + * 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)CastorXMLUtility.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 iter = props.list.iterator(); + + while( iter.hasNext() ) + mDatabase.put( mSystemKey, iter.next(), props ); + } + else + { + Logger.warning("ActiveEntity::initProps() - NO Properties!"); + } + + return props; + } + + /************************************************************************** + * + * + **************************************************************************/ + @Override + public org.omg.PortableServer.POA _default_POA() + { + if(mPOA != null) + return mPOA; + else + return super._default_POA(); + } + + + /************************************************************************** + * + * + **************************************************************************/ + @Override + public int getSystemKey() + { + return mSystemKey; + } + + + /************************************************************************** + * + * + **************************************************************************/ + @Override + public String queryData(String xpath) + 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 0) + try + { + Viewpoint view = (Viewpoint) Gateway.getStorage().get(getItemSysKey(), ClusterStorage.VIEWPOINT + "/" + getSchemaType() + "/" + viewName, null); + mOutcome = view.getOutcome().getData(); + } catch (Exception ex) + { // not found, return null + } + } + return mOutcome; + } + + public Outcome getOutcome() + { + Logger.msg(1, "Get outcome"); + return new Outcome(-1, getOutcomeString(), getSchemaType(), getSchemaVersion()); + } + + public int getAgentId() throws ObjectNotFoundException + { + if (mAgentId == -1) + mAgentId = Gateway.getLDAPLookup().getRoleManager().getAgentPath(getAgentName()).getSysKey(); + return mAgentId; + } + + public void setAgentId(int id) + { + mAgentId = id; + agent = null; + } + + public String getAgentName() + { + if (mAgentName == null) + mAgentName = (String) mActProps.get("AgentName"); + return mAgentName; + } + + public void setAgentName(String agentName) + { + mAgentName = agentName; + } + + public String getAgentRole() + { + if (mAgentRole == null) + mAgentRole = (String) mActProps.get("Agent Role"); + return mAgentRole; + } + + public void setAgentRole(String role) + { + mAgentRole = role; + } + + public boolean isOutcomeUsed() + { + String schemaType = getSchemaType(); + return (Boolean.TRUE.equals(getActProp("AlwaysUseOutcome")) || mPossibleTransition == Transitions.DONE || mPossibleTransition == Transitions.COMPLETE) && !(schemaType == null || schemaType.equals("")); + } + + public int getID() + { + return mID; + } + + @Override + public String getName() + { + return mName; + } + + public void setID(int id) + { + mID = id; + mName = String.valueOf(id); + } + + @Override + public void setName(String name) + { + mName = name; + try + { + mID = Integer.parseInt(name); + } catch (NumberFormatException ex) + { + mID = -1; + } + } + + public void setItemSysKey(int sysKey) + { + mItemSysKey = sysKey; + item = null; + } + + @Override + public String getClusterType() + { + return ClusterStorage.JOB; + } + + public boolean equals(Job job) + { + return (getItemSysKey() == job.getItemSysKey()) && this.mStepPath.equals(job.mStepPath) && this.mPossibleTransition == job.mPossibleTransition; + } + + public Object getActProp(String name) + { + return mActProps.get(name); + } + + public String getActPropString(String name) + { + try + { + return mActProps.get(name).toString(); + } catch (NullPointerException ex) + { + return null; + } + } + + public String getStepName() + { + return mStepName; + } + + public void setStepName(String string) + { + mStepName = string; + } + + public String getStepPath() + { + return mStepPath; + } + + public void setStepPath(String string) + { + mStepPath = string; + } + + public int getPossibleTransition() + { + return mPossibleTransition; + } + + public void setPossibleTransition(int lint) + { + mPossibleTransition = lint; + } + + public CastorHashMap getActProps() + { + return mActProps; + } + + public void setActProps(CastorHashMap map) + { + mActProps = map; + } + + public KeyValuePair[] getKeyValuePairs() + { + return mActProps.getKeyValuePairs(); + } + + public void setKeyValuePairs(KeyValuePair[] pairs) + { + mActProps.setKeyValuePairs(pairs); + } + + public int getCurrentState() + { + return mCurrentState; + } + + public void setCurrentState(int string) + { + mCurrentState = string; + } + + public int getTargetState() { + return mTargetState; + } + + public void setTargetState(int mTargetState) { + this.mTargetState = mTargetState; + } + + /** + * Returns the actType. + * + * @return String + */ + public String getStepType() + { + return mStepType; + } + + /** + * Sets the actType. + * + * @param actType + * The actType to set + */ + public void setStepType(String actType) + { + mStepType = actType; + } +} \ No newline at end of file diff --git a/src/main/java/com/c2kernel/entity/agent/JobArrayList.java b/src/main/java/com/c2kernel/entity/agent/JobArrayList.java new file mode 100644 index 0000000..dcb3215 --- /dev/null +++ b/src/main/java/com/c2kernel/entity/agent/JobArrayList.java @@ -0,0 +1,30 @@ +/************************************************************************** + * + * $Revision: 1.2 $ + * $Date: 2003/06/20 11:44:30 $ + * + * Copyright (C) 2001 CERN - European Organization for Nuclear Research + * All rights reserved. + **************************************************************************/ + +package com.c2kernel.entity.agent; + +import java.util.ArrayList; + +import com.c2kernel.utils.CastorArrayList; + +public class JobArrayList extends CastorArrayList +{ + + public JobArrayList() + { + super(); + } + + public JobArrayList(ArrayList aList) + { + super(aList); + } + + +} diff --git a/src/main/java/com/c2kernel/entity/agent/JobList.java b/src/main/java/com/c2kernel/entity/agent/JobList.java new file mode 100644 index 0000000..f8a88ee --- /dev/null +++ b/src/main/java/com/c2kernel/entity/agent/JobList.java @@ -0,0 +1,108 @@ +package com.c2kernel.entity.agent; + +import java.util.Iterator; +import java.util.Vector; + +import com.c2kernel.persistency.ClusterStorage; +import com.c2kernel.persistency.RemoteMap; +import com.c2kernel.utils.Logger; + + +/************************************************************************** +* +* @author $Author: abranson $ $Date: 2006/03/03 13:52:21 $ +* @version $Revision: 1.15 $ +***************************************************************************/ +public class JobList extends RemoteMap +{ + + /************************************************************************** + * Empty constructor for Castor + **************************************************************************/ + public JobList(int sysKey, Object locker) + { + super(sysKey, ClusterStorage.JOB, locker); + } + + + /************************************************************************** + * + **************************************************************************/ + public void addJob( Job job ) + { + synchronized(this) { + int jobId = getLastId()+1; + job.setID(jobId); + put(String.valueOf(jobId), job); + } + } + + /** + * Cannot be stored + */ + @Override + public String getClusterType() { + return null; + } + + + public Job getJob(int id) { + return get(String.valueOf(id)); + } + + + /** + * @param job + */ + public void removeJobsWithSysKey( int sysKey ) + { + Iterator currentMembers = values().iterator(); + Job j = null; + + while( currentMembers.hasNext() ) + { + j = currentMembers.next(); + + if( j.getItemSysKey() == sysKey ) + remove( String.valueOf(j.getID()) ); + } + + Logger.msg(5, "JobList::removeJobsWithSysKey() - " + sysKey + " DONE." ); + } + + public void removeJobsForStep( int sysKey, String stepPath ) + { + Iterator currentMembers = values().iterator(); + while( currentMembers.hasNext() ) + { + Job j = currentMembers.next(); + if( j.getItemSysKey() == sysKey && j.getStepPath().equals(stepPath)) + remove( String.valueOf(j.getID()) ); + } + + Logger.msg(5, "JobList::removeJobsForStep() - " + sysKey + " DONE." ); + } + /** + * @param itemKey + * @param string + * @return + */ + public Vector getJobsOfSysKey(int sysKey) + { + Iterator currentMembers = values().iterator(); + Job j = null; + Vector jobs = new Vector(); + + while( currentMembers.hasNext() ) + { + j = currentMembers.next(); + + if( j.getItemSysKey() == sysKey ) + jobs.add(j); + } + + Logger.msg(5, "JobList::getJobsOfSysKey() - returning " + jobs.size() + " Jobs." ); + + return jobs; + } +} \ No newline at end of file -- cgit v1.2.3