summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/entity/proxy/ProxyClientConnection.java
diff options
context:
space:
mode:
authorabranson <andrew.branson@cern.ch>2011-08-04 00:42:34 +0200
committerabranson <andrew.branson@cern.ch>2011-08-04 00:42:34 +0200
commit0ec8481c10cd8277d84c7c1a785483a0a739e5a0 (patch)
tree5f6e5d9ae75193e67e6f3b3dfa488960c5cde1d5 /source/com/c2kernel/entity/proxy/ProxyClientConnection.java
parent036cbdba66f804743c4c838ed598d6972c4b3e17 (diff)
More code cleanup:
Refactored Entity Proxy Subscription to handle generics better Rewrote RemoteMap to use TreeMap instead of the internal array for order. It now sorts its keys by number if they parse, else as strings. Removed a no-longer-in-progress outcome form class
Diffstat (limited to 'source/com/c2kernel/entity/proxy/ProxyClientConnection.java')
-rw-r--r--source/com/c2kernel/entity/proxy/ProxyClientConnection.java74
1 files changed, 40 insertions, 34 deletions
diff --git a/source/com/c2kernel/entity/proxy/ProxyClientConnection.java b/source/com/c2kernel/entity/proxy/ProxyClientConnection.java
index f041012..9687f22 100644
--- a/source/com/c2kernel/entity/proxy/ProxyClientConnection.java
+++ b/source/com/c2kernel/entity/proxy/ProxyClientConnection.java
@@ -41,17 +41,20 @@ public class ProxyClientConnection implements SocketHandler {
}
- public String getName() {
+ @Override
+ public String getName() {
return "Proxy Client Connection";
}
- public boolean isBusy() {
+ @Override
+ public boolean isBusy() {
return clientSocket != null;
}
-
- public synchronized void setSocket(Socket newSocket) {
+
+ @Override
+ public synchronized void setSocket(Socket newSocket) {
try {
- Logger.msg(1, "Proxy Client Connection "+thisClientId+" connect from "+newSocket.getInetAddress()+":"+newSocket.getPort());
+ Logger.msg(1, "Proxy Client Connection "+thisClientId+" connect from "+newSocket.getInetAddress()+":"+newSocket.getPort());
newSocket.setSoTimeout(500);
clientSocket = newSocket;
response = new PrintWriter(clientSocket.getOutputStream(), true);
@@ -66,11 +69,12 @@ public class ProxyClientConnection implements SocketHandler {
closeSocket();
}
}
-
+
/**
* Main loop. Reads proxy commands from the client and acts on them.
*/
- public void run() {
+ @Override
+ public void run() {
Thread.currentThread().setName("Proxy Client Connection: "+clientSocket.getInetAddress());
Logger.msg(7, "ProxyClientConnection "+thisClientId+" - Setting up proxy client connection with "+clientSocket.getInetAddress());
try {
@@ -87,7 +91,7 @@ public class ProxyClientConnection implements SocketHandler {
} catch (InvalidDataException ex) { // invalid proxy message
Logger.error("ProxyClientConnection "+thisClientId+" - Invalid proxy message: "+input);
}
-
+
}
} catch (IOException ex) {
if (!closing)
@@ -96,68 +100,70 @@ public class ProxyClientConnection implements SocketHandler {
closeSocket();
Logger.msg(1, "ProxyClientConnection "+thisClientId+" closed.");
}
-
+
private void processMessage(ProxyMessage message) throws InvalidDataException {
-
+
// proxy disconnection
if (message.getPath().equals(ProxyMessage.BYEPATH)) {
Logger.msg(7, "ProxyClientConnection "+thisClientId+" disconnecting");
closeSocket();
}
-
+
// proxy checking connection
- else if (message.getPath().equals(ProxyMessage.PINGPATH))
+ else if (message.getPath().equals(ProxyMessage.PINGPATH))
response.println(ProxyMessage.pingMessage);
-
+
// 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()));
- }
+ }
}
-
- // remove of subscription to entity changes
+
+ // remove of subscription to entity changes
else if (message.getPath().equals(ProxyMessage.DELPATH)) {
synchronized (sysKeys) {
sysKeys.remove(new Integer(message.getSysKey()));
- }
+ }
Logger.msg(7, "ProxyClientConnection "+thisClientId+" unsubscribed from "+message.getSysKey());
}
-
+
else // unknown message
- Logger.error("ProxyClientConnection "+thisClientId+" - Unknown message type: "+message);
-
- }
-
+ Logger.error("ProxyClientConnection "+thisClientId+" - Unknown message type: "+message);
+
+ }
+
public synchronized void sendMessage(ProxyMessage message) {
- if (clientSocket==null) return; // idle
- boolean relevant = message.getSysKey() == ProxyMessage.NA;
+ if (clientSocket==null) return; // idle
+ boolean relevant = message.getSysKey() == ProxyMessage.NA;
synchronized (sysKeys) {
- for (Iterator iter = sysKeys.iterator(); iter.hasNext() && !relevant;) {
- Integer thisKey = (Integer)iter.next();
+ for (Iterator<Integer> iter = sysKeys.iterator(); iter.hasNext() && !relevant;) {
+ Integer thisKey = iter.next();
if (thisKey.intValue() == message.getSysKey())
relevant = true;
}
}
if (!relevant) return; // not for our client
-
+
response.println(message);
}
-
- public void shutdown() {
+
+ @Override
+ public void shutdown() {
if (isBusy()) {
closing = true;
Logger.msg("ProxyClientConnection "+thisClientId+" closing.");
closeSocket();
}
}
-
- public String toString() {
+
+ @Override
+ public String toString() {
if (clientSocket == null) return thisClientId+": idle";
else return thisClientId+": "+clientSocket.getInetAddress();
}
-
+
private synchronized void closeSocket() {
if (clientSocket==null) return;
try {
@@ -171,9 +177,9 @@ public class ProxyClientConnection implements SocketHandler {
synchronized (sysKeys) {
sysKeys = null;
}
-
+
clientSocket = null;
}
-
+
}