summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/entity/proxy
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/proxy
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/proxy')
-rw-r--r--src/main/java/com/c2kernel/entity/proxy/AgentProxy.java36
-rw-r--r--src/main/java/com/c2kernel/entity/proxy/ItemProxy.java95
-rw-r--r--src/main/java/com/c2kernel/entity/proxy/MemberSubscription.java2
-rw-r--r--src/main/java/com/c2kernel/entity/proxy/ProxyClientConnection.java31
-rw-r--r--src/main/java/com/c2kernel/entity/proxy/ProxyManager.java73
-rw-r--r--src/main/java/com/c2kernel/entity/proxy/ProxyMessage.java38
6 files changed, 118 insertions, 157 deletions
diff --git a/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java b/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java
index 173f239..1f24229 100644
--- a/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java
+++ b/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java
@@ -50,22 +50,18 @@ import com.c2kernel.utils.Logger;
public class AgentProxy extends ItemProxy
{
- AgentPath agentPath;
+ AgentPath mAgentPath;
+ String mAgentName;
Authenticator auth;
/**************************************************************************
* Creates an AgentProxy without cache and change notification
**************************************************************************/
protected AgentProxy( org.omg.CORBA.Object ior,
- int systemKey)
+ AgentPath agentPath)
throws ObjectNotFoundException
{
- super(ior, systemKey);
- try {
- agentPath = new AgentPath(systemKey);
- mPath = agentPath;
- } catch (InvalidItemPathException e) {
- throw new ObjectNotFoundException();
- }
+ super(ior, agentPath);
+ mAgentPath = agentPath;
}
public Authenticator getAuthObj() {
@@ -103,7 +99,7 @@ public class AgentProxy extends ItemProxy
{
OutcomeValidator validator = null;
Date startTime = new Date();
- Logger.msg(3, "AgentProxy - executing "+job.getStepPath()+" for "+agentPath.getAgentName());
+ Logger.msg(3, "AgentProxy - executing "+job.getStepPath()+" for "+mAgentPath.getAgentName());
// get the outcome validator if present
if (job.hasOutcome())
{
@@ -160,7 +156,7 @@ public class AgentProxy extends ItemProxy
throw new InvalidDataException(error, "");
}
- job.setAgentId(getSystemKey());
+ job.setAgentPath(mAgentPath);
Logger.msg(3, "AgentProxy - submitting job to item proxy");
String result = item.requestAction(job);
if (Logger.doLog(3)) {
@@ -199,12 +195,8 @@ public class AgentProxy extends ItemProxy
ObjectAlreadyExistsException,
ScriptErrorException
{
- try {
- ItemProxy targetItem = Gateway.getProxyManager().getProxy(new ItemPath(job.getItemSysKey()));
- return execute(targetItem, job);
- } catch (InvalidItemPathException e) {
- throw new ObjectNotFoundException("Job contained invalid item sysKey: "+job.getItemSysKey(), "");
- }
+ ItemProxy targetItem = Gateway.getProxyManager().getProxy(job.getItemPath());
+ return execute(targetItem, job);
}
public String execute(ItemProxy item, String predefStep, C2KLocalObject obj)
@@ -233,7 +225,7 @@ public class AgentProxy extends ItemProxy
PersistencyException,
ObjectAlreadyExistsException
{
- return item.getItem().requestAction(getSystemKey(), "workflow/predefined/"+predefStep, PredefinedStep.DONE, PredefinedStep.bundleData(params));
+ return item.getItem().requestAction(mAgentPath.getSystemKey(), "workflow/predefined/"+predefStep, PredefinedStep.DONE, PredefinedStep.bundleData(params));
}
/** Wrappers for scripts */
@@ -255,7 +247,7 @@ public class AgentProxy extends ItemProxy
while(results.hasNext()) {
Path nextMatch = results.next();
- if (returnPath != null && nextMatch.getSysKey() != -1 && returnPath.getSysKey() != nextMatch.getSysKey())
+ if (returnPath != null && nextMatch.getUUID() != null && !returnPath.getUUID().equals(nextMatch.getUUID()))
throw new ObjectNotFoundException("Too many items with that name");
returnPath = nextMatch;
}
@@ -269,14 +261,14 @@ public class AgentProxy extends ItemProxy
@Override
public AgentPath getPath() {
- return agentPath;
+ return mAgentPath;
}
public ItemProxy getItem(Path itemPath) throws ObjectNotFoundException {
return Gateway.getProxyManager().getProxy(itemPath);
}
- public ItemProxy getItemBySysKey(int sysKey) throws ObjectNotFoundException, InvalidItemPathException {
- return Gateway.getProxyManager().getProxy(new ItemPath(sysKey));
+ public ItemProxy getItemByUUID(String uuid) throws ObjectNotFoundException, InvalidItemPathException {
+ return Gateway.getProxyManager().getProxy(new ItemPath(uuid));
}
}
diff --git a/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java b/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java
index 454da6d..987873f 100644
--- a/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java
+++ b/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java
@@ -34,9 +34,8 @@ import com.c2kernel.entity.agent.Job;
import com.c2kernel.entity.agent.JobArrayList;
import com.c2kernel.lifecycle.instance.CompositeActivity;
import com.c2kernel.lifecycle.instance.Workflow;
-import com.c2kernel.lookup.InvalidItemPathException;
+import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
-import com.c2kernel.lookup.Path;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.persistency.outcome.Viewpoint;
@@ -57,9 +56,8 @@ public class ItemProxy
{
protected Item mItem = null;
+ protected ItemPath mItemPath;
protected org.omg.CORBA.Object mIOR;
- protected int mSystemKey;
- protected Path mPath;
private final HashMap<MemberSubscription<?>, ProxyObserver<?>>
mSubscriptions;
@@ -67,29 +65,18 @@ public class ItemProxy
*
**************************************************************************/
protected ItemProxy( org.omg.CORBA.Object ior,
- int systemKey)
- throws ObjectNotFoundException
+ ItemPath itemPath)
{
- Logger.msg(8, "ItemProxy::initialise() - Initialising entity " +systemKey);
+ Logger.msg(8, "ItemProxy::initialise() - Initialising item proxy " +itemPath);
mIOR = ior;
- mSystemKey = systemKey;
+ mItemPath = itemPath;
mSubscriptions = new HashMap<MemberSubscription<?>, ProxyObserver<?>>();
- try {
- mPath = new ItemPath(systemKey);
- } catch (InvalidItemPathException e) {
- throw new ObjectNotFoundException();
- }
}
-
- public int getSystemKey()
- {
- return mSystemKey;
- }
- public Path getPath() {
- return mPath;
+ public ItemPath getPath() {
+ return mItemPath;
}
protected Item getItem() throws ObjectNotFoundException {
@@ -105,23 +92,13 @@ public class ItemProxy
} catch (org.omg.CORBA.BAD_PARAM ex) { }
throw new ObjectNotFoundException("CORBA Object was not an Item, or the server is down.");
}
- /**
- * @throws MappingException
- * @throws IOException
- * @throws ValidationException
- * @throws MarshalException ************************************************************************
- *
- *
- **************************************************************************/
- public void initialise( int agentId,
+
+ public void initialise( AgentPath agentId,
PropertyArrayList itemProps,
CompositeActivity workflow,
CollectionArrayList colls
)
- throws AccessRightsException,
- InvalidDataException,
- PersistencyException,
- ObjectNotFoundException, MarshalException, ValidationException, IOException, MappingException
+ throws AccessRightsException, InvalidDataException, PersistencyException, ObjectNotFoundException, MarshalException, ValidationException, IOException, MappingException
{
Logger.msg(7, "ItemProxy::initialise - started");
CastorXMLUtility xml = Gateway.getMarshaller();
@@ -132,7 +109,7 @@ public class ItemProxy
String collString = "";
if (colls != null) collString = xml.marshall(colls);
- getItem().initialise( agentId, propString, wfString, collString);
+ getItem().initialise( agentId.getSystemKey(), propString, wfString, collString);
}
public void setProperty(AgentProxy agent, String name, String value)
@@ -174,25 +151,25 @@ public class ItemProxy
else
outcome="";
- if (thisJob.getAgentId() == -1)
+ if (thisJob.getAgentPath() == null)
throw new InvalidDataException("No Agent specified.", "");
Logger.msg(7, "ItemProxy - executing "+thisJob.getStepPath()+" for "+thisJob.getAgentName());
- return getItem().requestAction (thisJob.getAgentId(), thisJob.getStepPath(),
+ return getItem().requestAction (thisJob.getAgentPath().getSystemKey(), thisJob.getStepPath(),
thisJob.getTransition().getId(), outcome);
}
/**************************************************************************
*
**************************************************************************/
- private ArrayList<Job> getJobList(int agentId, boolean filter)
+ private ArrayList<Job> getJobList(AgentPath agentPath, boolean filter)
throws AccessRightsException,
ObjectNotFoundException,
PersistencyException
{
JobArrayList thisJobList;
try {
- String jobs = getItem().queryLifeCycle(agentId, filter);
+ String jobs = getItem().queryLifeCycle(agentPath.getSystemKey(), filter);
thisJobList = (JobArrayList)Gateway.getMarshaller().unmarshall(jobs);
}
catch (Exception e) {
@@ -207,23 +184,15 @@ public class ItemProxy
ObjectNotFoundException,
PersistencyException
{
- return getJobList(agent.getSystemKey());
- }
-
- private ArrayList<Job> getJobList(int agentId)
- throws AccessRightsException,
- ObjectNotFoundException,
- PersistencyException
- {
- return getJobList(agentId, true);
+ return getJobList(agent.getPath(), true);
}
- private Job getJobByName(String actName, int agentId)
+ private Job getJobByName(String actName, AgentPath agent)
throws AccessRightsException,
ObjectNotFoundException,
PersistencyException {
- ArrayList<Job> jobList = getJobList(agentId);
+ ArrayList<Job> jobList = getJobList(agent, true);
for (Job job : jobList) {
if (job.getStepName().equals(actName) && job.hasOutcome())
return job;
@@ -248,7 +217,7 @@ public class ItemProxy
throws AccessRightsException,
ObjectNotFoundException,
PersistencyException {
- return getJobByName(actName, agent.getSystemKey());
+ return getJobByName(actName, agent.getPath());
}
/**
@@ -256,9 +225,9 @@ public class ItemProxy
*/
@Override
protected void finalize() throws Throwable {
- Logger.msg(7, "Proxy "+mSystemKey+" reaped");
- Gateway.getStorage().clearCache(mSystemKey, null);
- Gateway.getProxyManager().removeProxy(mSystemKey);
+ Logger.msg(7, "Proxy "+mItemPath+" reaped");
+ Gateway.getStorage().clearCache(mItemPath, null);
+ Gateway.getProxyManager().removeProxy(mItemPath);
super.finalize();
}
@@ -270,10 +239,10 @@ public class ItemProxy
{
try {
- Logger.msg(7, "EntityProxy.queryData() - "+mSystemKey+"/"+path);
+ Logger.msg(7, "EntityProxy.queryData() - "+mItemPath+"/"+path);
if (path.endsWith("all")) {
Logger.msg(7, "EntityProxy.queryData() - listing contents");
- String[] result = Gateway.getStorage().getClusterContents(mSystemKey, path.substring(0, path.length()-3));
+ String[] result = Gateway.getStorage().getClusterContents(mItemPath, path.substring(0, path.length()-3));
StringBuffer retString = new StringBuffer();
for (int i = 0; i < result.length; i++) {
retString.append(result[i]);
@@ -282,7 +251,7 @@ public class ItemProxy
Logger.msg(7, "EntityProxy.queryData() - "+retString.toString());
return retString.toString();
}
- C2KLocalObject target = Gateway.getStorage().get(mSystemKey, path, null);
+ C2KLocalObject target = Gateway.getStorage().get(mItemPath, path, null);
return Gateway.getMarshaller().marshall(target);
} catch (ObjectNotFoundException e) {
throw e;
@@ -294,7 +263,7 @@ public class ItemProxy
public String[] getContents( String path ) throws ObjectNotFoundException {
try {
- return Gateway.getStorage().getClusterContents(mSystemKey, path.substring(0, path.length()));
+ return Gateway.getStorage().getClusterContents(mItemPath, path.substring(0, path.length()));
} catch (ClusterStorageException e) {
throw new ObjectNotFoundException(e.toString());
}
@@ -310,11 +279,11 @@ public class ItemProxy
// load from storage, falling back to proxy loader if not found in others
try
{
- return Gateway.getStorage().get( mSystemKey, xpath , null);
+ return Gateway.getStorage().get( mItemPath, xpath , null);
}
catch( ClusterStorageException ex )
{
- Logger.msg(4, "Exception loading object :"+mSystemKey+"/"+xpath);
+ Logger.msg(4, "Exception loading object :"+mItemPath+"/"+xpath);
throw new ObjectNotFoundException( ex.toString() );
}
}
@@ -324,7 +293,7 @@ public class ItemProxy
public String getProperty( String name )
throws ObjectNotFoundException
{
- Logger.msg(5, "Get property "+name+" from syskey/"+mSystemKey);
+ Logger.msg(5, "Get property "+name+" from item "+mItemPath);
Property prop = (Property)getObject("Property/"+name);
try
{
@@ -377,7 +346,7 @@ public class ItemProxy
public void dumpSubscriptions(int logLevel) {
if (mSubscriptions.size() == 0) return;
- Logger.msg(logLevel, "Subscriptions to proxy "+mSystemKey+":");
+ Logger.msg(logLevel, "Subscriptions to proxy "+mItemPath+":");
synchronized(this) {
for (MemberSubscription<?> element : mSubscriptions.keySet()) {
ProxyObserver<?> obs = element.getObserver();
@@ -390,10 +359,10 @@ public class ItemProxy
}
public void notify(ProxyMessage message) {
- Logger.msg(4, "EntityProxy.notify() - Received change notification for "+message.getPath()+" on "+mSystemKey);
+ Logger.msg(4, "EntityProxy.notify() - Received change notification for "+message.getPath()+" on "+mItemPath);
synchronized (this){
if (Gateway.getProxyServer()== null || !message.getServer().equals(Gateway.getProxyServer().getServerName()))
- Gateway.getStorage().clearCache(mSystemKey, message.getPath());
+ Gateway.getStorage().clearCache(mItemPath, message.getPath());
for (Iterator<MemberSubscription<?>> e = mSubscriptions.keySet().iterator(); e.hasNext();) {
MemberSubscription<?> newSub = e.next();
if (newSub.getObserver() == null) { // phantom
diff --git a/src/main/java/com/c2kernel/entity/proxy/MemberSubscription.java b/src/main/java/com/c2kernel/entity/proxy/MemberSubscription.java
index 01994e4..5fed443 100644
--- a/src/main/java/com/c2kernel/entity/proxy/MemberSubscription.java
+++ b/src/main/java/com/c2kernel/entity/proxy/MemberSubscription.java
@@ -27,7 +27,7 @@ public class MemberSubscription<C extends C2KLocalObject> implements Runnable {
@Override
public void run() {
- Thread.currentThread().setName("Member Subscription: "+subject.getSystemKey()+":"+interest);
+ Thread.currentThread().setName("Member Subscription: "+subject.getPath()+":"+interest);
if (preLoad) loadChildren();
}
diff --git a/src/main/java/com/c2kernel/entity/proxy/ProxyClientConnection.java b/src/main/java/com/c2kernel/entity/proxy/ProxyClientConnection.java
index 3a7e129..95104cf 100644
--- a/src/main/java/com/c2kernel/entity/proxy/ProxyClientConnection.java
+++ b/src/main/java/com/c2kernel/entity/proxy/ProxyClientConnection.java
@@ -11,6 +11,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.lookup.ItemPath;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
import com.c2kernel.utils.server.SocketHandler;
@@ -29,7 +30,7 @@ public class ProxyClientConnection implements SocketHandler {
Socket clientSocket = null;
static int clientId = -1;
int thisClientId;
- ArrayList<Integer> sysKeys;
+ ArrayList<ItemPath> subscribedItems;
PrintWriter response;
BufferedReader request;
boolean closing = false;
@@ -59,7 +60,7 @@ public class ProxyClientConnection implements SocketHandler {
newSocket.setSoTimeout(500);
clientSocket = newSocket;
response = new PrintWriter(clientSocket.getOutputStream(), true);
- sysKeys = new ArrayList<Integer>();
+ subscribedItems = new ArrayList<ItemPath>();
} catch (SocketException ex) {
Logger.msg("Could not set socket timeout:");
Logger.error(ex);
@@ -116,18 +117,18 @@ public class ProxyClientConnection implements SocketHandler {
// 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()));
+ Logger.msg(7, "ProxyClientConnection "+thisClientId+" subscribed to "+message.getItemPath());
+ synchronized (subscribedItems) {
+ subscribedItems.add(message.getItemPath());
}
}
// remove of subscription to entity changes
else if (message.getPath().equals(ProxyMessage.DELPATH)) {
- synchronized (sysKeys) {
- sysKeys.remove(new Integer(message.getSysKey()));
+ synchronized (subscribedItems) {
+ subscribedItems.remove(message.getItemPath());
}
- Logger.msg(7, "ProxyClientConnection "+thisClientId+" unsubscribed from "+message.getSysKey());
+ Logger.msg(7, "ProxyClientConnection "+thisClientId+" unsubscribed from "+message.getItemPath());
}
else // unknown message
@@ -137,11 +138,11 @@ public class ProxyClientConnection implements SocketHandler {
public synchronized void sendMessage(ProxyMessage message) {
if (clientSocket==null) return; // idle
- boolean relevant = message.getSysKey() == ProxyMessage.NA;
- synchronized (sysKeys) {
- for (Iterator<Integer> iter = sysKeys.iterator(); iter.hasNext() && !relevant;) {
- Integer thisKey = iter.next();
- if (thisKey.intValue() == message.getSysKey())
+ boolean relevant = message.getItemPath() == null;
+ synchronized (subscribedItems) {
+ for (Iterator<ItemPath> iter = subscribedItems.iterator(); iter.hasNext() && !relevant;) {
+ ItemPath thisKey = iter.next();
+ if (thisKey.equals(message.getItemPath()))
relevant = true;
}
}
@@ -175,8 +176,8 @@ public class ProxyClientConnection implements SocketHandler {
Logger.error("ProxyClientConnection "+thisClientId+" - Could not close socket.");
Logger.error(e);
}
- synchronized (sysKeys) {
- sysKeys = null;
+ synchronized (subscribedItems) {
+ subscribedItems = null;
}
clientSocket = null;
diff --git a/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java b/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java
index 6a35c88..d95c86e 100644
--- a/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java
+++ b/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java
@@ -19,6 +19,7 @@ import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.lookup.ItemPath;
import com.c2kernel.lookup.Path;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.process.Gateway;
@@ -29,7 +30,7 @@ import com.c2kernel.utils.SoftCache;
public class ProxyManager
{
- SoftCache<Integer, ItemProxy> proxyPool = new SoftCache<Integer, ItemProxy>(50);
+ SoftCache<ItemPath, ItemProxy> proxyPool = new SoftCache<ItemPath, ItemProxy>(50);
HashMap<DomainPathSubscriber, DomainPath> treeSubscribers = new HashMap<DomainPathSubscriber, DomainPath>();
HashMap<String, ProxyServerConnection> connections = new HashMap<String, ProxyServerConnection>();
@@ -42,17 +43,16 @@ public class ProxyManager
Iterator<Path> servers = Gateway.getLookup().search(new DomainPath("/servers"), new Property("Type", "Server", false));
while(servers.hasNext()) {
- Path thisServerPath = servers.next();
+ Path thisServerResult = servers.next();
try {
- Logger.msg(thisServerPath.dump());
- int syskey = thisServerPath.getSysKey();
- String remoteServer = ((Property)Gateway.getStorage().get(syskey, ClusterStorage.PROPERTY+"/Name", null)).getValue();
- String portStr = ((Property)Gateway.getStorage().get(syskey, ClusterStorage.PROPERTY+"/ProxyPort", null)).getValue();
+ ItemPath thisServerPath = thisServerResult.getItemPath();
+ String remoteServer = ((Property)Gateway.getStorage().get(thisServerPath, ClusterStorage.PROPERTY+"/Name", null)).getValue();
+ String portStr = ((Property)Gateway.getStorage().get(thisServerPath, 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("Exception retrieving proxy server connection data for "+thisServerResult);
Logger.error(ex);
}
}
@@ -68,8 +68,8 @@ public class ProxyManager
protected void resubscribe(ProxyServerConnection conn) {
synchronized (proxyPool) {
- for (Integer key : proxyPool.keySet()) {
- ProxyMessage sub = new ProxyMessage(key.intValue(), ProxyMessage.ADDPATH, false);
+ for (ItemPath key : proxyPool.keySet()) {
+ ProxyMessage sub = new ProxyMessage(key, ProxyMessage.ADDPATH, false);
Logger.msg(5, "Subscribing to item "+key);
conn.sendMessage(sub);
}
@@ -99,15 +99,14 @@ public class ProxyManager
if (thisMessage.getPath().equals(ProxyMessage.PINGPATH)) // ping response
return;
- if (thisMessage.getSysKey() == ProxyMessage.NA) // must be domain path info
+ if (thisMessage.getItemPath() == null) // 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());
- ItemProxy relevant = proxyPool.get(key);
+ ItemProxy relevant = proxyPool.get(thisMessage.getItemPath());
if (relevant == null)
- Logger.warning("Received proxy message for sysKey "+thisMessage.getSysKey()+" which we don't have a proxy for.");
+ Logger.warning("Received proxy message for sysKey "+thisMessage.getItemPath()+" which we don't have a proxy for.");
else
try {
relevant.notify(thisMessage);
@@ -156,35 +155,32 @@ public class ProxyManager
*
**************************************************************************/
private ItemProxy createProxy( org.omg.CORBA.Object ior,
- int systemKey,
- boolean isAgent )
+ ItemPath itemPath)
throws ObjectNotFoundException
{
ItemProxy newProxy = null;
- Logger.msg(5, "ProxyManager::creating proxy on Item " + systemKey);
+ Logger.msg(5, "ProxyManager::creating proxy on Item " + itemPath);
- if( isAgent )
- {
- newProxy = new AgentProxy(ior, systemKey);
+ if( itemPath instanceof AgentPath ) {
+ newProxy = new AgentProxy(ior, (AgentPath)itemPath);
}
- else
- {
- newProxy = new ItemProxy(ior, systemKey);
+ else {
+ newProxy = new ItemProxy(ior, itemPath);
}
// subscribe to changes from server
- ProxyMessage sub = new ProxyMessage(systemKey, ProxyMessage.ADDPATH, false);
+ ProxyMessage sub = new ProxyMessage(itemPath, ProxyMessage.ADDPATH, false);
sendMessage(sub);
reportCurrentProxies(9);
return ( newProxy );
}
- protected void removeProxy( int systemKey )
+ protected void removeProxy( ItemPath itemPath )
{
- ProxyMessage sub = new ProxyMessage(systemKey, ProxyMessage.DELPATH, true);
- Logger.msg(5,"ProxyManager.removeProxy() - Unsubscribing to proxy informer for "+systemKey);
+ ProxyMessage sub = new ProxyMessage(itemPath, ProxyMessage.DELPATH, true);
+ Logger.msg(5,"ProxyManager.removeProxy() - Unsubscribing to proxy informer for "+itemPath);
sendMessage(sub);
}
@@ -194,20 +190,18 @@ public class ProxyManager
* SystemKey
**************************************************************************/
private ItemProxy getProxy( org.omg.CORBA.Object ior,
- int systemKey,
- boolean isAgent )
+ ItemPath itemPath)
throws ObjectNotFoundException
{
- Integer key = new Integer(systemKey);
synchronized(proxyPool) {
ItemProxy newProxy;
// return it if it exists
- newProxy = proxyPool.get(key);
+ newProxy = proxyPool.get(itemPath);
if (newProxy == null) {
// create a new one
- newProxy = createProxy(ior, systemKey, isAgent );
- proxyPool.put(key, newProxy);
+ newProxy = createProxy(ior, itemPath);
+ proxyPool.put(itemPath, newProxy);
}
return newProxy;
@@ -222,13 +216,12 @@ public class ProxyManager
public ItemProxy getProxy( Path path )
throws ObjectNotFoundException
{
-
- //convert namePath to dn format
+ ItemPath itemPath;
+ if (path instanceof ItemPath) itemPath = (ItemPath)path;
+ else itemPath = path.getItemPath();
Logger.msg(8,"ProxyManager::getProxy(" + path.toString() + ")");
- boolean isAgent = (path.getEntity() instanceof AgentPath);
- return getProxy( Gateway.getLookup().resolve(path),
- path.getSysKey(),
- isAgent );
+ return getProxy( Gateway.getLookup().resolve(itemPath),
+ itemPath );
}
@@ -249,11 +242,11 @@ public class ProxyManager
Logger.msg(logLevel, "Current proxies: ");
try {
synchronized(proxyPool) {
- Iterator<Integer> i = proxyPool.keySet().iterator();
+ Iterator<ItemPath> i = proxyPool.keySet().iterator();
for( int count=0; i.hasNext(); count++ )
{
- Integer nextProxy = i.next();
+ ItemPath nextProxy = i.next();
ItemProxy thisProxy = proxyPool.get(nextProxy);
if (thisProxy != null)
Logger.msg(logLevel,
diff --git a/src/main/java/com/c2kernel/entity/proxy/ProxyMessage.java b/src/main/java/com/c2kernel/entity/proxy/ProxyMessage.java
index 62866eb..f90c976 100644
--- a/src/main/java/com/c2kernel/entity/proxy/ProxyMessage.java
+++ b/src/main/java/com/c2kernel/entity/proxy/ProxyMessage.java
@@ -2,9 +2,10 @@ package com.c2kernel.entity.proxy;
import java.io.IOException;
import java.net.DatagramPacket;
-import java.util.StringTokenizer;
import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.lookup.InvalidItemPathException;
+import com.c2kernel.lookup.ItemPath;
/**************************************************************************
@@ -25,12 +26,11 @@ public class ProxyMessage {
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(null, BYEPATH, ADDED);
+ static ProxyMessage pingMessage = new ProxyMessage(null, PINGPATH, ADDED);
- private int sysKey = NA;
+ private ItemPath itemPath = null;
private String path = "";
private String server = null;
private boolean state = ADDED;
@@ -38,9 +38,9 @@ public class ProxyMessage {
public ProxyMessage() {
super();
}
- public ProxyMessage(int sysKey, String path, boolean state) {
+ public ProxyMessage(ItemPath itemPath, String path, boolean state) {
this();
- setSysKey(sysKey);
+ setItemPath(itemPath);
setPath(path);
setState(state);
}
@@ -48,11 +48,17 @@ public class ProxyMessage {
public ProxyMessage(String line) throws InvalidDataException, IOException {
if (line == null)
throw new IOException("Null proxy message");
- StringTokenizer tok = new StringTokenizer(line,":");
- if (tok.countTokens()!=2)
+ String[] tok = line.split(":");
+ if (tok.length != 2)
throw new InvalidDataException("String '"+line+"' does not constitute a valid proxy message.", "");
- sysKey = Integer.parseInt(tok.nextToken());
- path = tok.nextToken();
+ if (tok[0].length() > 0 && !tok[0].equals("tree")) {
+ try {
+ itemPath = new ItemPath(tok[0]);
+ } catch (InvalidItemPathException e) {
+ throw new InvalidDataException("Item in proxy message "+line+" was not valid");
+ }
+ }
+ path = tok[1];
if (path.startsWith("-")) {
state = DELETED;
path = path.substring(1);
@@ -63,12 +69,12 @@ public class ProxyMessage {
this(new String(packet.getData()));
}
- public int getSysKey() {
- return sysKey;
+ public ItemPath getItemPath() {
+ return itemPath;
}
- public void setSysKey(int sysKey) {
- this.sysKey = sysKey;
+ public void setItemPath(ItemPath itemPath) {
+ this.itemPath = itemPath;
}
public String getPath() {
@@ -89,7 +95,7 @@ public class ProxyMessage {
@Override
public String toString() {
- return sysKey+":"+(state?"-":"")+path;
+ return (itemPath==null?"tree":itemPath.getUUID())+":"+(state?"-":"")+path;
}
public String getServer() {