diff options
Diffstat (limited to 'source/com/c2kernel/entity/proxy/ProxyClientConnection.java')
| -rw-r--r-- | source/com/c2kernel/entity/proxy/ProxyClientConnection.java | 74 |
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;
}
-
+
}
|
