summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/entity/CorbaServer.java
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-09-09 12:13:21 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-09-09 12:13:21 +0200
commitda731d2bb81666b9c697d9099da632e7dfcdc0f7 (patch)
tree567693c3c48f3d15ecbb2dac4f9db03bb6e58c72 /src/main/java/com/c2kernel/entity/CorbaServer.java
parentae1e79e33fd30e3d8bcedbef8891a14a048276d7 (diff)
Replaced int sysKey Item identifier with UUID, which is now portable.
ItemPath objects are now used to identify Items throughout the kernel, replacing ints and Integers.
Diffstat (limited to 'src/main/java/com/c2kernel/entity/CorbaServer.java')
-rw-r--r--src/main/java/com/c2kernel/entity/CorbaServer.java109
1 files changed, 51 insertions, 58 deletions
diff --git a/src/main/java/com/c2kernel/entity/CorbaServer.java b/src/main/java/com/c2kernel/entity/CorbaServer.java
index 60c10a8..324a7c1 100644
--- a/src/main/java/com/c2kernel/entity/CorbaServer.java
+++ b/src/main/java/com/c2kernel/entity/CorbaServer.java
@@ -14,7 +14,7 @@ import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.agent.ActiveEntity;
import com.c2kernel.entity.agent.ActiveLocator;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.InvalidItemPathException;
+import com.c2kernel.lookup.InvalidAgentPathException;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
@@ -31,14 +31,14 @@ import com.c2kernel.utils.SoftCache;
public class CorbaServer {
- private final Map<ItemPath, Servant> mEntityCache;
+ private final Map<ItemPath, Servant> mItemCache;
private POA mRootPOA;
private POA mItemPOA;
private POA mAgentPOA;
private POAManager mPOAManager;
public CorbaServer() throws InvalidDataException {
- mEntityCache = new SoftCache<ItemPath, Servant>(50);
+ mItemCache = new SoftCache<ItemPath, Servant>(50);
// init POA
try {
@@ -116,74 +116,67 @@ public class CorbaServer {
/**************************************************************************
* Returns a CORBA servant for a pre-existing entity
+ * @throws ObjectNotFoundException
**************************************************************************/
- private Servant getItem(int sysKey, org.omg.PortableServer.POA poa) throws ObjectNotFoundException {
- try {
- ItemPath itemPath = Gateway.getLookup().getItemPath(sysKey);
- Servant item = null;
- synchronized (mEntityCache) {
- item = mEntityCache.get(itemPath);
- if (item == null) {
- Logger.msg(7, "Creating new servant for "+sysKey);
-
- if (itemPath instanceof AgentPath) {
- if (poa == null) poa = mAgentPOA;
- item = new ActiveEntity(sysKey, poa);
- }
- else if (itemPath instanceof ItemPath) {
- if (poa == null) poa = mItemPOA;
- item = new TraceableEntity(sysKey, poa);
- }
-
- mEntityCache.put(itemPath, item);
- }
+ public TraceableEntity getItem(ItemPath itemPath) throws ObjectNotFoundException {
+ Servant item = null;
+ if (!itemPath.exists()) throw new ObjectNotFoundException(itemPath+" does not exist", "");
+ synchronized (mItemCache) {
+ item = mItemCache.get(itemPath);
+ if (item == null) {
+ Logger.msg(7, "Creating new servant for "+itemPath);
+ item = new TraceableEntity(itemPath, mItemPOA);
+ mItemCache.put(itemPath, item);
}
- return item;
-
- } catch (InvalidItemPathException ex) {
- throw new ObjectNotFoundException("Invalid Entity Key", "");
}
+ return (TraceableEntity)item;
}
/**************************************************************************
- * Wrapper for fetching Items
- **************************************************************************/
- public TraceableEntity getItem(int sysKey) throws ObjectNotFoundException {
- return (TraceableEntity)getItem(sysKey, mItemPOA);
- }
-
- /**************************************************************************
- * Wrapper for fetching Agents
+ * Returns a CORBA servant for a pre-existing entity
**************************************************************************/
- public ActiveEntity getAgent(int sysKey) throws ObjectNotFoundException {
- return (ActiveEntity)getItem(sysKey, mAgentPOA);
+ public ActiveEntity getAgent(AgentPath agentPath) throws InvalidAgentPathException, ObjectNotFoundException {
+ Servant agent = null;
+ if (!agentPath.exists()) throw new ObjectNotFoundException(agentPath+" does not exist", "");
+ synchronized (mItemCache) {
+ agent = mItemCache.get(agentPath);
+ if (agent == null) {
+ Logger.msg(7, "Creating new servant for "+agentPath);
+ agent = new ActiveEntity(agentPath, mAgentPOA);
+ mItemCache.put(agentPath, agent);
+ }
+ else if (!(agent instanceof ActiveEntity))
+ throw new InvalidAgentPathException("Item "+agentPath+" was not an agent");
+ }
+ return (ActiveEntity)agent;
}
/**
- * @param entityPath
+ * @param itemPath
* @return
*/
- public Servant createEntity(ItemPath entityPath) throws CannotManageException, ObjectAlreadyExistsException {
- try {
- if (entityPath == null)
- entityPath = Gateway.getNextKeyManager().generateNextEntityKey();
- } catch (Exception ex) {
- Logger.error(ex);
- throw new CannotManageException("Cannot generate next entity key");
+ public TraceableEntity createItem(ItemPath itemPath) throws CannotManageException, ObjectAlreadyExistsException {
+
+ if (itemPath.exists()) throw new ObjectAlreadyExistsException();
+ org.omg.CORBA.Object obj = mItemPOA.create_reference_with_id(itemPath.getOID(), ItemHelper.id());
+ itemPath.setIOR(obj);
+ TraceableEntity item = new TraceableEntity(itemPath, mItemPOA);
+ synchronized (mItemCache) {
+ mItemCache.put(itemPath, item);
}
- boolean isAgent = entityPath instanceof AgentPath;
- POA myPOA = isAgent?mAgentPOA:mItemPOA;
- org.omg.CORBA.Object obj = myPOA.create_reference_with_id(entityPath.getOID(), isAgent?AgentHelper.id():ItemHelper.id());
- entityPath.setIOR(obj);
- Servant entity;
- if (isAgent)
- entity = new ActiveEntity(entityPath.getSysKey(), myPOA);
- else
- entity = new TraceableEntity(entityPath.getSysKey(), myPOA);
- synchronized (mEntityCache) {
- mEntityCache.put(entityPath, entity);
+ return item;
+ }
+
+ public ActiveEntity createAgent(AgentPath agentPath) throws CannotManageException, ObjectAlreadyExistsException {
+ if (agentPath.exists()) throw new ObjectAlreadyExistsException();
+ org.omg.CORBA.Object obj = mAgentPOA.create_reference_with_id(agentPath.getOID(), AgentHelper.id());
+ agentPath.setIOR(obj);
+ ActiveEntity agent;
+ agent = new ActiveEntity(agentPath, mAgentPOA);
+ synchronized (mItemCache) {
+ mItemCache.put(agentPath, agent);
}
- return entity;
-
+ return agent;
+
}
}