Mercurial > hg > Members > riono > TreeVNC_ja_comment
changeset 174:2e1530139169
reorganization
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Sat Jun 21 17:28:59 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Sun Jun 22 11:22:52 2014 +0900 @@ -155,7 +155,9 @@ int counter = 3; while(counter-- > 0) { try { - echo.lostParent(rfb.getMyAddress(),rfb.getAcceptPort()); + if (rfb.isLeader()) { + echo.lostParent(rfb.getMyAddress(),rfb.getAcceptPort()); + } break; } catch (Exception e1) { logger.severe("Cannot send lostHost: " + e1.getMessage());
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Sat Jun 21 17:28:59 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Sun Jun 22 11:22:52 2014 +0900 @@ -4,6 +4,7 @@ import java.net.BindException; import java.net.ServerSocket; import java.net.Socket; +import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.LinkedList; @@ -14,6 +15,8 @@ import jp.ac.u_ryukyu.treevnc.client.TreeVncProtocol; import jp.ac.u_ryukyu.treevnc.server.RequestScreenThread; +import jp.ac.u_ryukyu.treevnc.server.TreeManagement; +import jp.ac.u_ryukyu.treevnc.server.TreeRootFinderListener; import jp.ac.u_ryukyu.treevnc.server.VncProxyService; import com.glavsoft.exceptions.TransportException; @@ -24,6 +27,7 @@ import com.glavsoft.transport.Reader; import com.glavsoft.transport.Writer; import com.glavsoft.viewer.ViewerInterface; +import com.glavsoft.viewer.swing.ConnectionParams; public abstract class MyRfbProto { @@ -35,6 +39,7 @@ public MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>(); private RequestScreenThread rThread; public int acceptPort = 0; + private String myAddress; protected boolean readyReconnect = false; private boolean cuiVersion; private long counter = 0; // packet serial number @@ -45,18 +50,19 @@ private Inflater inflater = new Inflater(); private Deflater deflater = new Deflater(); - VncProxyService viewer; + ViewerInterface viewer; private short id; + private boolean leader; + private TreeManagement treeManager; + private TreeVncCommandChannelListener acceptThread; + private boolean firstTime; + private TreeRootFinderListener getCast; public MyRfbProto() { rThread = new RequestScreenThread(this); } - public void setVncProxy(VncProxyService viewer) { - this.viewer = viewer; - } - abstract public boolean isRoot() ; public ProtocolContext getContext() { @@ -305,11 +311,11 @@ } public void setViewer(ViewerInterface v) { - treeProtocol.setViewer(v); + viewer = v; } public ViewerInterface getViewer() { - return treeProtocol.getViewer(); + return viewer; } public TreeVncProtocol getEcho() { @@ -357,7 +363,7 @@ } } - public synchronized void waitForReady(VncProxyService vncProxyService) throws InterruptedException { + public synchronized void waitForReady(ViewerInterface vncProxyService) throws InterruptedException { while (!readyReconnect) { wait(); } @@ -395,7 +401,7 @@ } public String getMyAddress() { - return treeProtocol.getMyAddress(); + return myAddress; } /** @@ -583,5 +589,84 @@ return id; } + public void setMyAddress(String myHostName) { + this.myAddress = myHostName; + + } + + public void setLeader(boolean leader) { + this.leader = leader; + } + + public boolean isLeader() { + return leader; + } + + public void setTreeManager(TreeManagement clients) { + treeManager = clients; + } + + public TreeManagement getTreeManger() { + return treeManager; + } + + /** + * chnageVNCServer is called when host change. + * + * @param vncProxyService + * @param hostName + * HostAddress + * @param width + * FrameWidth + * @param height + * FrameHeight + * @param id + * @throws InterruptedException + */ + public void changeVNCServer(ViewerInterface vncProxyService, String hostName, int width, int height, short id) + throws UnknownHostException, IOException, InterruptedException { + // stop reader stop + stopReceiverTask(); + vncProxyService.inhelitClients(vncProxyService, hostName); + orderRecconection(vncProxyService, hostName, id); + } + + public void orderRecconection(ViewerInterface vncProxyService, String hostName, short id) throws UnknownHostException, IOException, InterruptedException { + waitForReady(vncProxyService); + sendDesktopSizeChange(id); + } + + /** + * start accepting children + * run rootFinderListener if necessary + * @param vncProxyService TODO + */ + public void createConnectionAndStart(ViewerInterface vncProxyService) { + selectPort(ConnectionParams.DEFAULT_VNC_ROOT); + if (treeManager!=null) { + treeManager.getList().getFirst().setPort(getAcceptPort()); + } + acceptThread = new TreeVncCommandChannelListener(this, getAcceptPort()); + Thread thread = new Thread(acceptThread, "TreeVNC-accept"); + thread.start(); + if(firstTime) { + getCast = new TreeRootFinderListener(vncProxyService); + thread = new Thread(getCast, "tree-root-find-listener"); + thread.start(); + firstTime = false; + } + } + + public void initRoot(ViewerInterface vncProxyService, String hostName) { + treeManager = new TreeManagement(hostName, ConnectionParams.DEFAULT_VNC_ROOT,this); + vncProxyService.setTreeManager(treeManager); + vncProxyService.initRootViewer(hostName); + createConnectionAndStart(vncProxyService); + } + + public TreeVncCommandChannelListener getAcceptThread() { + return acceptThread; + } + }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommand.java Sat Jun 21 17:28:59 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommand.java Sun Jun 22 11:22:52 2014 +0900 @@ -77,7 +77,7 @@ * @param myHostName */ void handleWhereToConnect(int port, String hostname, String myHostName) { - rfb.viewer.decideWhereToConnect(hostname,port,myHostName); + rfb.getTreeManger().decideWhereToConnect(hostname,port,myHostName); } /** @@ -95,8 +95,10 @@ return; // we don't have parent } rfb.setId(id); + rfb.setMyAddress(myHostName); + rfb.setLeader(leader); try { - rfb.treeProtocol.connectToParenet(port, hostname, myHostName, leader); + rfb.getViewer().connectToParenet(port, hostname); } catch (IOException e) { System.out.println(e.getMessage()); } @@ -119,7 +121,7 @@ * @param hostname */ private void handleLostParent(int port, String hostname) { - rfb.viewer.fixLostParent(hostname,port); + rfb.getTreeManger().fixLostParent(hostname,port); } public TreeCommand getCommand () {
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyVncClient.java Sat Jun 21 17:28:59 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyVncClient.java Sun Jun 22 11:22:52 2014 +0900 @@ -64,7 +64,7 @@ parser.parse(argv); if (parser.isSet(ParametersHandler.ARG_HELP)) { - printUsage(parser.optionsUsage()); + Viewer.printUsage(parser.optionsUsage()); System.exit(0); } MyVncClient myClient = new MyVncClient(parser);
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncProtocol.java Sat Jun 21 17:28:59 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncProtocol.java Sun Jun 22 11:22:52 2014 +0900 @@ -4,44 +4,33 @@ import java.net.*; import java.nio.ByteBuffer; import java.nio.ByteOrder; - -import com.glavsoft.rfb.protocol.ProtocolContext; import com.glavsoft.rfb.protocol.ProtocolContext.TreeCommand; -import com.glavsoft.viewer.ViewerInterface; public class TreeVncProtocol { private BufferedReader is = null; private DataOutputStream os = null; private Socket echoSocket = null; - private int echoPort; - public ViewerInterface client; - private String parentAddress; - public boolean leaderFlag; - private String myAddress; + private int rootPort; + private String rootAddress; public TreeVncProtocol(String name, int echoPort) { - this.echoPort = echoPort; - this.parentAddress = name; + this.rootPort = echoPort; + this.rootAddress = name; } - public void setLeader(boolean f) { - leaderFlag = f; - } - public void openport() { try { - echoSocket = new Socket(parentAddress, echoPort); - echoSocket.setReuseAddress(true); + echoSocket = new Socket(rootAddress, rootPort); + // echoSocket.setReuseAddress(true); os = new DataOutputStream(echoSocket.getOutputStream()); is = new BufferedReader(new InputStreamReader( echoSocket.getInputStream())); } catch (UnknownHostException e) { - System.err.println("Don't know about host: "+parentAddress); + System.err.println("Don't know about host: "+rootAddress); } catch (IOException e) { - System.out.println(parentAddress + " Connection Faild"); + System.out.println(rootAddress + " Connection Faild"); System.exit(0); } - } public void findRootReply(int port) throws IOException { @@ -98,43 +87,4 @@ echoSocket.close(); } - public void setViewer(ViewerInterface v) { - client = v; - } - - public ViewerInterface getViewer() { - return client; - } - - public String getMyAddress() { - return myAddress; - } - - public String getParentAddress() { - return parentAddress; - } - - public int getParentPort() { - return echoPort; - } - - /** - * Start client with new parent (including reconnection) - * @param port - * @param hostname - * @param myHostName - * @param leader - * @throws IOException - */ - public void connectToParenet(int port, String hostname, String myHostName, boolean leader) - throws IOException { - this.leaderFlag = leader; - this.myAddress = myHostName; - client.setTeminationType(false); - client.closeApp(); - client.setConnectionParam(hostname, port); - client.run(); - } - - } \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/TreeManagement.java Sat Jun 21 17:28:59 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/TreeManagement.java Sun Jun 22 11:22:52 2014 +0900 @@ -89,6 +89,7 @@ lostNodeConnection(deadParent); // if lostParentNode is the last one, we don't need reconnection // Thread.sleep(intv_time); + showTreeNode(); } /**
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/TreeRootFinderListener.java Sat Jun 21 17:28:59 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/TreeRootFinderListener.java Sun Jun 22 11:22:52 2014 +0900 @@ -7,18 +7,20 @@ import java.net.UnknownHostException; import jp.ac.u_ryukyu.treevnc.client.TreeVncProtocol; + import com.glavsoft.rfb.protocol.ProtocolContext.TreeCommand; +import com.glavsoft.viewer.ViewerInterface; import com.glavsoft.viewer.swing.ConnectionParams; public class TreeRootFinderListener implements Runnable { public static final String McastAddr = "224.0.0.1"; static final int BufSize = 1024; private boolean stopFlag = false; - private VncProxyService vps; + private ViewerInterface vps; private MulticastSocket soc; - public TreeRootFinderListener(VncProxyService _vps) { - vps = _vps; + public TreeRootFinderListener(ViewerInterface vncProxyService) { + vps = vncProxyService; } /**
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Sat Jun 21 17:28:59 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Sun Jun 22 11:22:52 2014 +0900 @@ -1,12 +1,9 @@ package jp.ac.u_ryukyu.treevnc.server; import java.awt.event.*; -import java.io.*; -import java.net.UnknownHostException; -import java.util.LinkedList; import java.util.logging.Logger; -import jp.ac.u_ryukyu.treevnc.TreeVncCommandChannelListener; +import jp.ac.u_ryukyu.treevnc.MyRfbProto; import com.glavsoft.core.SettingsChangedEvent; import com.glavsoft.rfb.IChangeSettingsListener; import com.glavsoft.rfb.IRfbSessionListener; @@ -27,14 +24,10 @@ public static Logger logger = Logger.getLogger("com.glavsoft"); private boolean forceReconnection; private String reconnectionReason; - private TreeVncCommandChannelListener acceptThread; - private TreeRootFinderListener getCast; - private TreeManagement clients; + public TreeManagement clients; static VncProxyService currentVps; private int fbWidth = 0; - private boolean firstTime = true; - - private int vncport = ConnectionParams.DEFAULT_RFB_PORT; + public int vncport = ConnectionParams.DEFAULT_RFB_PORT; public VncProxyService() { ProtocolSettings.getDefaultSettings(); @@ -47,8 +40,6 @@ myRfb = vps.myRfb; forceReconnection = vps.forceReconnection; reconnectionReason = vps.reconnectionReason; - acceptThread = vps.acceptThread; - getCast = vps.getCast; clients = vps.clients; } @@ -66,54 +57,22 @@ System.exit(0); } VncProxyService vps = new VncProxyService(); - vps.initRoot("localhost"); + vps.myRfb.initRoot(vps, "localhost"); } - private void initRoot(String hostName) { - myRfb = new MyRfbProtoProxy(); - myRfb.setVncProxy(this); - clients = new TreeManagement(hostName, ConnectionParams.DEFAULT_VNC_ROOT,myRfb); - isApplet = false; - setIsTreeVNC(true); - setConnectionParam(hostName,vncport); - isApplet = true; - run(); - createConnectionAndStart(); - } - /** * start new VNC server receiver with * inherited clients * @param vs * @param hostName */ - private void inhelitClients(VncProxyService vs, String hostName) { + public void inhelitClients(VncProxyService vs, String hostName) { myRfb.setReadyReconnect(false); setConnectionParam(hostName,vncport); isApplet = true; this.setNoConnection(false); run(); - firstTime = false; - createConnectionAndStart(); - } - - /** - * start accepting children - * run rootFinderListener if necessary - */ - public void createConnectionAndStart() { - myRfb.selectPort(ConnectionParams.DEFAULT_VNC_ROOT); - if (clients!=null) { - clients.getList().getFirst().setPort(myRfb.getAcceptPort()); - } - acceptThread = new TreeVncCommandChannelListener(myRfb, myRfb.getAcceptPort()); - Thread thread = new Thread(acceptThread, "TreeVNC-accept"); - thread.start(); - if(firstTime) { - getCast = new TreeRootFinderListener(this); - thread = new Thread(getCast, "tree-root-find-listener"); - thread.start(); - } + myRfb.createConnectionAndStart(this); } public void proxyStart(String[] argv, int width, int height) { @@ -131,9 +90,17 @@ printUsage(parser.optionsUsage()); System.exit(0); } - initRoot("localhost"); + myRfb = new MyRfbProtoProxy(); + myRfb.initRoot(this, "localhost"); } + public void initRootViewer(String hostName) { + isApplet = false; + setIsTreeVNC(true); + setConnectionParam(hostName,vncport); + isApplet = true; + run(); + } @Override public void destroy() { @@ -152,58 +119,10 @@ @Override public void rfbSessionStopped(final String reason) { - - } - - - /** - * chnageVNCServer is called when host change. - * - * @param hostName - * HostAddress - * @param width - * FrameWidth - * @param height - * FrameHeight - * @param id - * @throws InterruptedException - */ - public void changeVNCServer(String hostName, int width, int height, short id) - throws UnknownHostException, IOException, InterruptedException { - // stop reader stop - myRfb.stopReceiverTask(); - inhelitClients(this, hostName); - orderRecconection(hostName, id); } @Override public void settingsChanged(SettingsChangedEvent event) { - - } - - public void setFirstTime(boolean flag) { - firstTime = flag; } - public void orderRecconection(String hostName, short id) throws UnknownHostException, IOException, InterruptedException { - myRfb.waitForReady(this); - myRfb.sendDesktopSizeChange(id); - } - - public LinkedList<TreeVNCNode> clientList() { - return clients.getList(); - } - - public void decideWhereToConnect(String hostname, int port,String localhostname) { - clients.decideWhereToConnect(hostname,port,localhostname); - } - - public void fixLostParent(String hostname, int port) { - clients.fixLostParent(hostname,port); - clients.showTreeNode(); - } - - public TreeVncCommandChannelListener getAcceptThread() { - return this.acceptThread; - } }
--- a/src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java Sat Jun 21 17:28:59 2014 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java Sun Jun 22 11:22:52 2014 +0900 @@ -21,6 +21,7 @@ import jp.ac.u_ryukyu.treevnc.CreateConnectionParam; import jp.ac.u_ryukyu.treevnc.MyRfbProto; import jp.ac.u_ryukyu.treevnc.client.MyRfbProtoClient; +import jp.ac.u_ryukyu.treevnc.server.TreeManagement; public class CuiViewer implements Runnable, WindowListener, ViewerInterface { @@ -262,4 +263,38 @@ @Override public void createRootSelectionPanel() { } + + @Override + public void connectToParenet(int port, String hostname) throws IOException { + setTeminationType(false); + closeApp(); + setConnectionParam(hostname, port); + run(); + } + + @Override + public void changeVNCServer(String newHostName, int i, int j, short id) { + + } + + @Override + public void initRoot(String hostName, MyRfbProto myRfb) { + + } + + @Override + public void inhelitClients(ViewerInterface vncProxyService, String hostName) { + + } + + @Override + public void setTreeManager(TreeManagement treeManager) { + + } + + @Override + public void initRootViewer(String hostName) { + + } + }
--- a/src/viewer_swing/java/com/glavsoft/viewer/TreeViewer.java Sat Jun 21 17:28:59 2014 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/TreeViewer.java Sun Jun 22 11:22:52 2014 +0900 @@ -35,8 +35,8 @@ v.startTreeViewer(); } } - if (vps!=null && vps.getAcceptThread()!=null) { - vps.getAcceptThread().waitForShutdown(); + if (vps!=null && vps.getRfb().getAcceptThread()!=null) { + vps.getRfb().getAcceptThread().waitForShutdown(); } } @@ -62,7 +62,7 @@ // open display and connect to some tree node. viewer = true; } else if ("--version".equals(args[i])) { - System.out.println("version :" + VncProxyService.ver()); + System.out.println("version :" + Viewer.ver()); System.exit(0); } else if ("-ns".equals(args[i])) { permitChangeScreen = false;
--- a/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Sat Jun 21 17:28:59 2014 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Sun Jun 22 11:22:52 2014 +0900 @@ -48,6 +48,7 @@ import jp.ac.u_ryukyu.treevnc.CreateConnectionParam; import jp.ac.u_ryukyu.treevnc.MyRfbProto; import jp.ac.u_ryukyu.treevnc.client.MyRfbProtoClient; +import jp.ac.u_ryukyu.treevnc.server.TreeManagement; @SuppressWarnings("serial") public class Viewer extends JApplet implements Runnable, WindowListener , ViewerInterface{ @@ -320,8 +321,20 @@ cp.getAcceptThread().waitForShutdown(); } - - + + /** + * Start client with new parent (including reconnection) + * @param port + * @param hostname + * @throws IOException + */ + @Override + public void connectToParenet(int port, String hostname) throws IOException { + setTeminationType(false); + closeApp(); + setConnectionParam(hostname, port); + run(); + } public void setConnectionParam(String hostName, int port) { connectionParams.setHostName(hostName); @@ -346,4 +359,37 @@ @Override public void createRootSelectionPanel() { } + + @Override + public void changeVNCServer(String newHostName, int i, int j, short id) { + + } + + @Override + public void initRoot(String hostName, MyRfbProto myRfb) { + isApplet = false; + setIsTreeVNC(true); + setConnectionParam(hostName,ConnectionParams.DEFAULT_RFB_PORT); + isApplet = true; + run(); + } + + @Override + public void inhelitClients(ViewerInterface vncProxyService, String hostName) { + // TODO Auto-generated method stub + + } + + @Override + public void setTreeManager(TreeManagement treeManager) { + // TODO Auto-generated method stub + + } + + @Override + public void initRootViewer(String hostName) { + // TODO Auto-generated method stub + + } + }
--- a/src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java Sat Jun 21 17:28:59 2014 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java Sun Jun 22 11:22:52 2014 +0900 @@ -1,8 +1,10 @@ package com.glavsoft.viewer; +import java.io.IOException; import java.net.Socket; import jp.ac.u_ryukyu.treevnc.MyRfbProto; +import jp.ac.u_ryukyu.treevnc.server.TreeManagement; public interface ViewerInterface extends Runnable { @@ -29,4 +31,17 @@ public void startTreeViewer(); public void createRootSelectionPanel(); + + public void connectToParenet(int port, String hostname) throws IOException; + + public void changeVNCServer(String newHostName, int i, int j, short id); + + public void initRoot(String hostName, MyRfbProto myRfb); + + public void inhelitClients(ViewerInterface vncProxyService, String hostName); + + public void setTreeManager(TreeManagement treeManager); + + public void initRootViewer(String hostName); + }