changeset 131:95f53663295c

lost host and parent not found
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 07 Jun 2014 00:39:46 +0900
parents 1f6bfaa3281b
children 84f167f9956a
files src/main/java/com/glavsoft/rfb/protocol/ProtocolContext.java src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java src/main/java/jp/ac/u_ryukyu/treevnc/client/GetHostClient.java src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncProtocol.java
diffstat 4 files changed, 25 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/protocol/ProtocolContext.java	Sat Jun 07 00:03:13 2014 +0900
+++ b/src/main/java/com/glavsoft/rfb/protocol/ProtocolContext.java	Sat Jun 07 00:39:46 2014 +0900
@@ -90,6 +90,7 @@
     public static final int CONNECT_TO = 223;
 	public static final int CONNECT_TO_AS_LEADER = 224;
     public static final int	LOST_PARENT = 225;
+    public static final int NOT_FOUND_PARENT = 226;
     
 	
 }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java	Sat Jun 07 00:03:13 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java	Sat Jun 07 00:39:46 2014 +0900
@@ -257,7 +257,7 @@
 					requestThreadNotify();
 
 					// after this, we discard upward packet.
-					new Thread(reader, "discard-upward-comm").start(); 
+					new Thread(reader, "upward-packet-processing").start(); 
 					// writeFramebufferUpdateRequest(0,0, framebufferWidth,
 					// framebufferHeight, false );
 					for (;;) {
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/GetHostClient.java	Sat Jun 07 00:03:13 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/GetHostClient.java	Sat Jun 07 00:39:46 2014 +0900
@@ -19,10 +19,8 @@
 
 public class GetHostClient implements Runnable {
 	final int BUFSIZE = 1024;
-	private byte[] buf = new byte[BUFSIZE];
 	private InetAddress mAddr;
 	private MulticastSocket soc;
-	private String str;
 
     private ServerSocket server = null;
     private BufferedReader is;
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncProtocol.java	Sat Jun 07 00:03:13 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncProtocol.java	Sat Jun 07 00:39:46 2014 +0900
@@ -5,8 +5,6 @@
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 
-import jp.ac.u_ryukyu.treevnc.server.VncProxyService;
-
 import com.glavsoft.rfb.protocol.ProtocolContext;
 import com.glavsoft.viewer.ViewerImpl;
 
@@ -64,10 +62,14 @@
 	}
 
 	public void lostParent(String hostname, int port) throws IOException {
-		sendWithHostAndPort(ProtocolContext.LOST_PARENT, hostname, port);
+        sendWithHostAndPort(ProtocolContext.LOST_PARENT, hostname, port);
 	}
 	
 
+    private void notFoundParent(int p) throws IOException {
+        sendWithHostAndPort(ProtocolContext.NOT_FOUND_PARENT, "", p);
+    }
+
 	public void sendWithHostAndPort(int command, String hostname, int port)
 			throws IOException {
 		
@@ -127,47 +129,31 @@
 
 	/**
 	 * Call at lost host
+	 * @throws IOException 
+	 * @throws NumberFormatException 
 	 */
-	public boolean lostHost() {
-		if (echoSocket != null && os != null && is != null) {
-			try {
-				if (runflag) {
-					return true;
-				}
-				sendDataProxy();
-				reConnectionMain(echoSocket);
-				streamClose();
-			} catch (UnknownHostException e) {
-				System.err.println("Trying to connect to unknown host: " + e);
-			} catch (IOException e) {
-				return false;
-			} catch (NullPointerException e) {
-				//openport();
-				System.out.println("notFoundParents");
-				//notfoundParent();
-			}
-		}
+	public boolean lostHost() throws NumberFormatException, IOException {
+	    openport();
+	    if (runflag) return true;
+	    if ("1".equals(leaderFlag)) {
+	        openport();
+            lostParent(treeNum,Integer.parseInt(parentNum));   // "1"
+	        streamClose();
+	    }
 		return true;
 	}
 
 	public boolean notfoundParent() {
-		if (echoSocket != null && os != null && is != null) {
-			runflag = true;
-			try {
-				sendDataProxy("2", parentNum, null);
-				getProxyData(is, echoSocket);
-				reConnectionMain(echoSocket);
-				streamClose();
-			} catch (UnknownHostException e) {
-				System.err.println("Trying to connect to unknown host: " + e);
-			} catch (IOException e) {
-				System.err.println("IOException: " + e);
-			}
-		}
-		return true;
+	    openport();
+	    runflag = true;
+	    try {
+	        notFoundParent(Integer.parseInt(parentNum)); // 2
+	    } catch (Exception e) {
+	    }   
+	    return true;
 	}
 
-	public TreeVncProtocol Interruption(Socket _clientSocket) {
+    public TreeVncProtocol Interruption(Socket _clientSocket) {
 		clientSocket = _clientSocket;
 		try {
 			BufferedReader lostis = new BufferedReader(new InputStreamReader(
@@ -207,7 +193,6 @@
 				client.setSocket(soc);
 				if (soc != null) 
 					client.run();
-
 				break;
 			} catch (IOException e) {
 				break;