Mercurial > hg > Applications > TreeVNC
changeset 331:42fcc9419498
add error message, add lostParent case by fail to connectTo.
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/protocol/Protocol.java Tue Feb 03 02:54:08 2015 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/Protocol.java Tue Feb 03 12:31:48 2015 +0900 @@ -180,7 +180,7 @@ * FramebufferUpdateRequest messages. The client should send * FramebufferUpdateRequest messages with incremental set to true when it has * finished processing one FramebufferUpdate and is ready to process another. - * With a fast client, the rate at which FramebufferUpdateRequests are sent + * With a first client, the rate at which FramebufferUpdateRequests are sent * should be regulated to avoid hogging the network. */ public void startNormalHandling(IRfbSessionListener rfbSessionListener,
--- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Tue Feb 03 02:54:08 2015 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Tue Feb 03 12:31:48 2015 +0900 @@ -201,6 +201,7 @@ Thread.sleep(i); } catch (InterruptedException e) { // nothing. + System.out.println("any thread has interrupted the current thread."); } }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/CheckDelay.java Tue Feb 03 02:54:08 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/CheckDelay.java Tue Feb 03 12:31:48 2015 +0900 @@ -10,8 +10,7 @@ private ByteBuffer msg; - public CheckDelay(int i, int j, int width, int height, long time, - EncodingType checkDelay) throws UnsupportedEncodingException { + public CheckDelay(int i, int j, int width, int height, long time, EncodingType checkDelay) { msg = ByteBuffer.allocate(24).order(ByteOrder.BIG_ENDIAN); msg.put((byte) 0); // FrameBufferUpdate
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/CreateConnectionParam.java Tue Feb 03 02:54:08 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/CreateConnectionParam.java Tue Feb 03 12:31:48 2015 +0900 @@ -36,12 +36,8 @@ public void sendWhereToConnect(ViewerInterface v) { rfb.setConnectionParam(this); TreeVncProtocol echo = new TreeVncProtocol(hostName,portNumber); - try { - echo.whereToConnect(myHostName,rfb.getAcceptPort()); - } catch (IOException e) { - System.out.println("sendWhereToConnect : cannot connect to root "+e.getMessage()); - } - } + echo.whereToConnect(myHostName,rfb.getAcceptPort()); + } public synchronized void setHostName(String _hostName, int port, String _myHostName) { hostName = _hostName;
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/FindRoot.java Tue Feb 03 02:54:08 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/FindRoot.java Tue Feb 03 12:31:48 2015 +0900 @@ -90,6 +90,7 @@ soc.close(); } catch (IOException e) { e.printStackTrace(); + System.out.println("cannot is close."); } } @@ -138,7 +139,8 @@ * the thread is waiting accept system call, * close the socket causes exception, * which will terminated the thread. - * + * + * unused. */ public void interrupt() { stopFlag = true;
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MulticastQueue.java Tue Feb 03 02:54:08 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MulticastQueue.java Tue Feb 03 12:31:48 2015 +0900 @@ -42,6 +42,7 @@ try { wait(); } catch (InterruptedException e) { + System.out.println("any thread has interrupted the current thread."); } } return b; @@ -100,6 +101,7 @@ try { next = node.next(); }catch(InterruptedException _e){ + System.out.println("any thread has interrupted the current thread."); continue; } item = next.getItem();
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/RequestScreenThread.java Tue Feb 03 02:54:08 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/RequestScreenThread.java Tue Feb 03 12:31:48 2015 +0900 @@ -1,5 +1,6 @@ package jp.ac.u_ryukyu.treevnc; +import com.glavsoft.exceptions.TransportException; import com.glavsoft.rfb.protocol.Protocol; public class RequestScreenThread implements Runnable { @@ -27,14 +28,13 @@ wait(); } Thread.sleep(3000); - rfb.writeFramebufferUpdateRequest(0, 0, protocol.getFbWidth(), - protocol.getFbHeight(), false); - - } catch (Exception e) { + rfb.writeFramebufferUpdateRequest(0, 0, protocol.getFbWidth(), protocol.getFbHeight(), false); + } catch (InterruptedException e) { e.printStackTrace(); + System.out.println("any thread has interrupted the current thread"); break; - } - } + } + } }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/SendCheckDelay.java Tue Feb 03 02:54:08 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/SendCheckDelay.java Tue Feb 03 12:31:48 2015 +0900 @@ -15,7 +15,7 @@ this.rfb = rfb; } - public void sendCheckDelay() throws UnsupportedEncodingException { + public void sendCheckDelay() { LinkedList<ByteBuffer> checkdelay = new LinkedList<ByteBuffer>(); long time = System.currentTimeMillis(); checkdelay.add(new CheckDelay(0, 0, 0, 0, time, EncodingType.CHECK_DELAY).getMessage()); @@ -34,8 +34,7 @@ } } catch (InterruptedException e) { e.printStackTrace(); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + System.out.println("any thread has interrupted the current thread"); } } }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeManagement.java Tue Feb 03 02:54:08 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeManagement.java Tue Feb 03 12:31:48 2015 +0900 @@ -85,12 +85,7 @@ me.setHostName(myHostName); if (deadParent.getTreeNum() == 0) { // if dead root, connect me. - try { - connectTo(me, lostParentNode); - } catch (IOException e) { - System.out.println("root to lostParentNode Connection Faild (lostParent)"); - System.exit(0); - } + connectTo(me, lostParentNode); return; } if (getChildNode(deadParent, 0) == null) return; @@ -109,49 +104,34 @@ moveLastNodeToLostNodePosition(deadChild.getTreeNum()); lostNodeConnection(deadChild); } - } - - /** - * send reconnect to all children - * @param oldParent - */ - private void lostNodeConnection(TreeVNCNode oldParent) { - if (nodeList.size() < oldParent.getTreeNum()+1) { - return; - } - TreeVNCNode newparent = nodeList.get(oldParent.getTreeNum()); - TreeVNCNode grandfather = getParentNode(newparent.getTreeNum()); - - try { - connectTo(grandfather, newparent); - } catch (IOException e) { - System.out.println("grandfather to newparent Connection Faild (lostParent)"); - System.out.println("try lostNodeParent again."); - if(getChildNode(newparent, 0) == null) return; - moveLastNodeToLostNodePosition(newparent.getTreeNum()); - lostNodeConnection(newparent); - } - - for(int i=0; i < treebranch; i++) { - TreeVNCNode child = getChildNode(newparent, i); - if (child != null) { - try { - connectTo(newparent, child); - } catch (IOException e) { - System.out.println("newparent to child Connection Faild (lostParent)"); - System.exit(0); - } - } - } - if (showTreeNode) { showTreeNode(); } } + /** + * send reconnect to all children + * @param deadNode + */ + private void lostNodeConnection(TreeVNCNode deadNode) { + if (nodeList.size() < deadNode.getTreeNum()+1) { + return; + } + TreeVNCNode newparent = nodeList.get(deadNode.getTreeNum()); + TreeVNCNode grandfather = getParentNode(newparent.getTreeNum()); + connectTo(grandfather, newparent); + + for(int i=0; i < treebranch; i++) { + TreeVNCNode child = getChildNode(newparent, i); + if (child != null) { + connectTo(newparent, child); + } + } + } - public void connectTo(TreeVNCNode newparent, TreeVNCNode n) throws IOException { + + public void connectTo(TreeVNCNode newparent, TreeVNCNode n) { TreeVncProtocol vc1 = new TreeVncProtocol(n.getHostname(),n.getPort()); short nodeId = (short) n.getTreeNum(); vc1.connectTo(newparent.getHostname(), newparent.getPort(), isLeader(n), nodeId); @@ -181,22 +161,12 @@ if (nodeList.size() >= treebranch + 1) { TreeVNCNode parent = getParentNode(node.getTreeNum()); checkParameter(parent.getTreeNum(), nodeList.size(), isLeader(node)); - try { - connectTo(parent, node); - } catch (IOException e) { - System.out.println("parent : Connection Faild (decideWhereToConnect)"); - System.exit(0); - } + connectTo(parent, node); } else { // connect to me TreeVNCNode me = nodeList.getFirst(); me.setHostName(localhostname); - try { - connectTo(me, node); - } catch (IOException e) { - System.out.println("root : Connection Faild (decideWhereToConnect)"); - System.exit(0); - } + connectTo(me, node); } if (showTreeNode) { showTreeNode();
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Tue Feb 03 02:54:08 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Tue Feb 03 12:31:48 2015 +0900 @@ -166,6 +166,7 @@ myHostPort = rootHostPort; } catch (UnknownHostException e) { e.printStackTrace(); + System.out.println("cannot be resolved into an root address"); } } else { rootHostName = getConnectionParam().getHostName(); @@ -302,6 +303,7 @@ break; } catch (IOException e1) { } catch (TransportException e1) { + System.out.println("cannot send ClientToServerMessage"); e1.printStackTrace(); } return; @@ -418,8 +420,7 @@ - public void writeFramebufferUpdateRequest(int x, int y, int w, int h, - boolean incremental) throws TransportException { + public void writeFramebufferUpdateRequest(int x, int y, int w, int h, boolean incremental) { byte[] b = new byte[10]; b[0] = (byte) FramebufferUpdateRequest; // 3 is FrameBufferUpdateRequest
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRootFinderListener.java Tue Feb 03 02:54:08 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRootFinderListener.java Tue Feb 03 12:31:48 2015 +0900 @@ -60,11 +60,7 @@ int singleWidth = vps.getRfb().getSingleWidth(); int singleHeight = vps.getRfb().getSingleHeight(); t.setSingleSize(singleWidth, singleHeight); - try { - t.findRootReply(vps.getRfb().getAcceptPort()); - } catch (IOException e) { - e.printStackTrace(); - } + t.findRootReply(vps.getRfb().getAcceptPort()); if(stopFlag) break; } } catch (Exception e) {
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncProtocol.java Tue Feb 03 02:54:08 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncProtocol.java Tue Feb 03 12:31:48 2015 +0900 @@ -32,33 +32,62 @@ is = new BufferedReader(new InputStreamReader(echoSocket.getInputStream())); } - public void findRootReply(int port) throws IOException { - sendWithHostAndPort(TreeCommand.FIND_ROOT_REPLY, null, port, (short) 0); + public void findRootReply(int port) { + try { + sendWithHostAndPort(TreeCommand.FIND_ROOT_REPLY, null, port, (short) 0); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("cannot send findRootReplay"); + } } - public void whereToConnect(String hostname, int port) throws IOException { - sendWithHostAndPort(TreeCommand.WHERE_TO_CONNECT, hostname, port, (short) 0); + public void whereToConnect(String hostname, int port) { + try { + sendWithHostAndPort(TreeCommand.WHERE_TO_CONNECT, hostname, port, (short) 0); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("cannot send whereToConnect"); + } } - public void connectTo(String hostname, int port,int leaderFlag, short yourId) throws IOException{ + public void connectTo(String hostname, int port,int leaderFlag, short yourId) { TreeCommand command = leaderFlag == 1 ? TreeCommand.CONNECT_TO_AS_LEADER : TreeCommand.CONNECT_TO; - sendWithHostAndPort(command, hostname, port, yourId); + try { + sendWithHostAndPort(command, hostname, port, yourId); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("cannot send connectTo"); + } } - public void lostParent(String hostname, int port) throws IOException { - sendWithHostAndPort(TreeCommand.LOST_PARENT, hostname, port, (short) 0); + public void lostParent(String hostname, int port) { + try { + sendWithHostAndPort(TreeCommand.LOST_PARENT, hostname, port, (short) 0); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("cannot send lostParent"); + } } public void lostLeftChild(String hostname, int port) { - sendWithHostAndPort(TreeCommand.LOST_LEFT_CHILD, hostname, port, (short) 0); + try { + sendWithHostAndPort(TreeCommand.LOST_LEFT_CHILD, hostname, port, (short) 0); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("cannot send lostLeftChild"); + } } public void lostRightChild(String hostname, int port) { - sendWithHostAndPort(TreeCommand.LOST_RIGHT_CHILD, hostname, port, (short) 0); + try { + sendWithHostAndPort(TreeCommand.LOST_RIGHT_CHILD, hostname, port, (short) 0); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("cannot send lostRightChild"); + } } - public void sendWithHostAndPort(TreeCommand command, String hostname, int port, short value) { - try { + public void sendWithHostAndPort(TreeCommand command, String hostname, int port, short value) throws IOException { openport(); if (hostname == null) { // in case of root finder, we can't get localaddress from datagram packet. @@ -78,10 +107,6 @@ while (buf.hasRemaining()) buf.put((byte) 0); buf.flip(); sendCommandToTheRoot(buf); - } catch (IOException e) { - System.out.println("cannot send command to the root."); - streamClose(); - } } public void sendCommandToTheRoot(ByteBuffer buf) throws IOException {
--- a/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingConnectionWorkerFactory.java Tue Feb 03 02:54:08 2015 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingConnectionWorkerFactory.java Tue Feb 03 12:31:48 2015 +0900 @@ -55,7 +55,7 @@ @Override public NetworkConnectionWorker createNetworkConnectionWorker() { - return new SwingNetworkConnectionWorker(parentWindow); + return new SwingNetworkConnectionWorker(parentWindow, myRfb); } @Override
--- a/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingNetworkConnectionWorker.java Tue Feb 03 02:54:08 2015 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingNetworkConnectionWorker.java Tue Feb 03 12:31:48 2015 +0900 @@ -26,6 +26,8 @@ import com.glavsoft.viewer.*; import com.glavsoft.viewer.swing.ssh.SshConnectionManager; +import jp.ac.u_ryukyu.treevnc.TreeRFBProto; +import jp.ac.u_ryukyu.treevnc.TreeVncProtocol; import javax.swing.*; import java.io.IOException; @@ -46,8 +48,15 @@ private boolean hasSshSupport; private ConnectionParams connectionParams; private ConnectionPresenter presenter; + private TreeRFBProto rfb; + public SwingNetworkConnectionWorker(JFrame parentWindow, TreeRFBProto myRfb) { + this.parentWindow = parentWindow; + this.rfb = myRfb; + logger = Logger.getLogger(getClass().getName()); + } + public SwingNetworkConnectionWorker(JFrame parentWindow) { this.parentWindow = parentWindow; logger = Logger.getLogger(getClass().getName()); @@ -120,6 +129,21 @@ presenter.showMessage("Interrupted"); presenter.connectionFailed(); } catch (ExecutionException e) { + + // lostparent + System.out.println("lost parent"); + TreeVncProtocol echo = new TreeVncProtocol(connectionParams.getHostName(), connectionParams.getPortNumber()); + int counter = 3; + while(counter-- > 0) { + try { + echo.lostParent(rfb.getMyAddress(),rfb.getAcceptPort()); + break; + } catch (Exception e1) { + logger.severe("Cannot send lostHost: " + e1.getMessage()); + } + } + + String errorMessage = null; try { throw e.getCause(); @@ -158,6 +182,7 @@ presenter.clearMessage(); presenter.connectionFailed(); } + } @Override