diff options
Diffstat (limited to 'source/com/c2kernel/entity/proxy/EntityProxyManager.java')
| -rw-r--r-- | source/com/c2kernel/entity/proxy/EntityProxyManager.java | 106 |
1 files changed, 52 insertions, 54 deletions
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);
|
