From da731d2bb81666b9c697d9099da632e7dfcdc0f7 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 9 Sep 2014 12:13:21 +0200 Subject: 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. --- src/main/java/com/c2kernel/entity/agent/Job.java | 74 +++++++++++++++++------- 1 file changed, 53 insertions(+), 21 deletions(-) (limited to 'src/main/java/com/c2kernel/entity/agent/Job.java') diff --git a/src/main/java/com/c2kernel/entity/agent/Job.java b/src/main/java/com/c2kernel/entity/agent/Job.java index cef35ef..fe2084d 100644 --- a/src/main/java/com/c2kernel/entity/agent/Job.java +++ b/src/main/java/com/c2kernel/entity/agent/Job.java @@ -1,6 +1,7 @@ package com.c2kernel.entity.agent; import java.util.HashMap; +import java.util.UUID; import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectNotFoundException; @@ -9,6 +10,7 @@ import com.c2kernel.entity.proxy.ItemProxy; import com.c2kernel.lifecycle.instance.Activity; import com.c2kernel.lifecycle.instance.stateMachine.Transition; import com.c2kernel.lookup.AgentPath; +import com.c2kernel.lookup.InvalidAgentPathException; import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.persistency.ClusterStorage; @@ -34,7 +36,7 @@ public class Job implements C2KLocalObject private int id; - private int itemSysKey; + private ItemPath itemPath; private String stepName; @@ -48,8 +50,6 @@ public class Job implements C2KLocalObject private String targetStateName; - private int agentId = -1; - private String agentRole; private CastorHashMap actProps = new CastorHashMap(); @@ -58,6 +58,8 @@ public class Job implements C2KLocalObject private String name; + private AgentPath agentPath; + private String agentName; private String outcomeData; @@ -79,9 +81,9 @@ public class Job implements C2KLocalObject { } - public Job(Activity act, int itemSysKey, Transition transition, AgentPath agent, String role) throws InvalidDataException, ObjectNotFoundException { + public Job(Activity act, ItemPath itemPath, Transition transition, AgentPath agent, String role) throws InvalidDataException, ObjectNotFoundException, InvalidAgentPathException { - setItemSysKey(itemSysKey); + setItemPath(itemPath); setStepPath(act.getPath()); setTransition(transition); setOriginStateName(act.getStateMachine().getState(transition.getOriginStateId()).getName()); @@ -89,7 +91,7 @@ public class Job implements C2KLocalObject setStepName(act.getName()); setActProps(act.getProperties()); setStepType(act.getType()); - setAgentName(agent.getAgentName()); + if (agent != null) setAgentName(agent.getAgentName()); setAgentRole(role); } @@ -121,15 +123,24 @@ public class Job implements C2KLocalObject name = String.valueOf(id); } - public int getItemSysKey() { - return itemSysKey; + public ItemPath getItemPath() { + return itemPath; } - public void setItemSysKey(int sysKey) { - itemSysKey = sysKey; + public void setItemPath(ItemPath path) { + itemPath = path; item = null; } + public void setItemUUID( String uuid ) + { + setItemPath(new ItemPath(UUID.fromString(uuid))); + } + + public String getItemUUID() { + return getItemPath().getUUID().toString(); + } + public String getStepName() { return stepName; } @@ -162,14 +173,34 @@ public class Job implements C2KLocalObject this.transition = transition; } - public int getAgentId() throws ObjectNotFoundException { - if (agentId == -1) - agentId = Gateway.getLookup().getAgentPath(getAgentName()).getSysKey(); - return agentId; + public AgentPath getAgentPath() throws ObjectNotFoundException { + if (agentPath == null && getAgentName() != null) { + agentPath = Gateway.getLookup().getAgentPath(getAgentName()); + } + return agentPath; } - public void setAgentId(int id) { - agentId = id; + public void setAgentPath(AgentPath agentPath) { + this.agentPath = agentPath; + agentName = agentPath.getAgentName(); + } + + public void setAgentUUID( String uuid ) + { + if (uuid != null) + try { + setAgentPath(new AgentPath(UUID.fromString(uuid))); + } catch (InvalidAgentPathException e) { + Logger.error("Invalid agent path in Job: "+uuid); + } + } + + public String getAgentUUID() { + try { + if (getAgentPath() != null) + return getAgentPath().getUUID().toString(); + } catch (ObjectNotFoundException e) { } + return null; } public String getAgentName() @@ -179,9 +210,10 @@ public class Job implements C2KLocalObject return agentName; } - public void setAgentName(String agentName) + public void setAgentName(String agentName) throws ObjectNotFoundException { this.agentName = agentName; + agentPath = Gateway.getLookup().getAgentPath(agentName); } public String getAgentRole() { @@ -254,7 +286,7 @@ public class Job implements C2KLocalObject public ItemProxy getItemProxy() throws ObjectNotFoundException, InvalidItemPathException { if (item == null) - item = Gateway.getProxyManager().getProxy(new ItemPath(itemSysKey)); + item = Gateway.getProxyManager().getProxy(itemPath); return item; } @@ -294,7 +326,7 @@ public class Job implements C2KLocalObject } try { - Viewpoint view = (Viewpoint) Gateway.getStorage().get(getItemSysKey(), + Viewpoint view = (Viewpoint) Gateway.getStorage().get(itemPath, ClusterStorage.VIEWPOINT + "/" + schemaName + "/" + viewName, null); return view.getOutcome().getData(); } catch (ObjectNotFoundException ex) { // viewpoint doesn't exist yet @@ -302,7 +334,7 @@ public class Job implements C2KLocalObject } catch (ClusterStorageException e) { Logger.error(e); throw new InvalidDataException("ViewpointOutcomeInitiator: ClusterStorageException loading viewpoint " - + ClusterStorage.VIEWPOINT + "/" + schemaName + "/" + viewName+" in syskey "+getItemSysKey()); + + ClusterStorage.VIEWPOINT + "/" + schemaName + "/" + viewName+" in item "+itemPath.getUUID()); } } else @@ -375,7 +407,7 @@ public class Job implements C2KLocalObject public boolean equals(Job job) { - return (getItemSysKey() == job.getItemSysKey()) && this.stepPath.equals(job.stepPath) && transition.getId() == job.getTransition().getId(); + return (itemPath.equals(job.getItemPath()) && this.stepPath.equals(job.stepPath) && transition.getId() == job.getTransition().getId()); } private void setActProps(CastorHashMap actProps) { -- cgit v1.2.3