comparison src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java @ 47:f3b775d3592a

create newVps.
author one
date Thu, 06 Dec 2012 17:51:29 +0900
parents d2741b80399e
children 6ebe870da138
comparison
equal deleted inserted replaced
46:d2741b80399e 47:f3b775d3592a
53 private AcceptThread acceptThread; 53 private AcceptThread acceptThread;
54 private GetBroadCastProxy getCast; 54 private GetBroadCastProxy getCast;
55 public AcceptClient aClient; 55 public AcceptClient aClient;
56 public int opendPort; 56 public int opendPort;
57 57
58 private VncProxyService prevVps;
59 static VncProxyService currentVps;
60
58 // public AcceptClient acc; 61 // public AcceptClient acc;
59 62
60 private void initProxy(Parser parser) { 63 private void initProxy(Parser parser) {
61 aClient = new AcceptClient(); 64 aClient = new AcceptClient();
62 ParametersHandler.completeSettingsFromCLI(parser, connectionParams, 65 ParametersHandler.completeSettingsFromCLI(parser, connectionParams,
74 uiSettings = super.uiSettings; 77 uiSettings = super.uiSettings;
75 connectionParams.hostName = "localhost"; 78 connectionParams.hostName = "localhost";
76 } 79 }
77 80
78 81
82 public VncProxyService(VncProxyService vps, String hostName) {
83 this();
84 connectionParams.hostName = hostName;
85 rfb = vps.rfb;
86 isClient = vps.isClient;
87 forceReconnection = vps.forceReconnection;
88 reconnectionReason = vps.reconnectionReason;
89 acceptThread = vps.acceptThread;
90 getCast = vps.getCast;
91 aClient = vps.aClient;
92 opendPort = vps.opendPort;
93 prevVps = vps;
94 }
95
79 public static void main(String[] argv) { 96 public static void main(String[] argv) {
80 String[] mainArgs = argv; 97 String[] mainArgs = argv;
81 System.out.println(mainArgs.length); 98 System.out.println(mainArgs.length);
82 // input into arguments Decision 99 // input into arguments Decision
83 100
116 } 133 }
117 } 134 }
118 135
119 private void setArguments(String[] mainArgs) { 136 private void setArguments(String[] mainArgs) {
120 } 137 }
121 138
122 @Override 139
123 public void run() { 140 public boolean run1() {
141
124 rfb = new MyRfbProtoProxy(); 142 rfb = new MyRfbProtoProxy();
125 // getHostData(); 143 // getHostData();
126 if (forceReconnection) { 144 if (forceReconnection) {
127 connectionManager.showReconnectDialog("Connection lost", 145 connectionManager.showReconnectDialog("Connection lost",
128 reconnectionReason); 146 reconnectionReason);
164 containerFrame = createContainer(); 182 containerFrame = createContainer();
165 connectionManager.setContainerFrame(containerFrame); 183 connectionManager.setContainerFrame(containerFrame);
166 updateFrameTitle(); 184 updateFrameTitle();
167 containerFrame.dispose(); 185 containerFrame.dispose();
168 containerFrame = null; 186 containerFrame = null;
169 if (tempWorkingProtocol != null) 187 if (prevVps != null) {
170 tempWorkingProtocol.cleanUpSession(); 188 prevVps.cleanUpSession();
189 prevVps = null;
190 }
191 currentVps = this;
171 workingProtocol.startNormalHandling(this, surface, 192 workingProtocol.startNormalHandling(this, surface,
172 clipboardController, rfb); 193 clipboardController, rfb);
173 // rfb.setInitData(workingProtocol.getInitData()); too early 194 // rfb.setInitData(workingProtocol.getInitData()); too early
174 // workingProtocol.startNormalHandling(this, surface, 195 // workingProtocol.startNormalHandling(this, surface,
175 // clipboardController); 196 // clipboardController);
199 connectionManager.showReconnectDialog("Connection Error", 220 connectionManager.showReconnectDialog("Connection Error",
200 "Connection Error" + ": " + e.getMessage()); 221 "Connection Error" + ": " + e.getMessage());
201 logger.severe(e.getMessage()); 222 logger.severe(e.getMessage());
202 } 223 }
203 } 224 }
225 return !tryAgain;
226 }
227
228 private void cleanUpSession() {
229 if (prevVps != null) {
230 prevVps.cleanUpSession();
231 prevVps = null;
232 }
233 workingProtocol.cleanUpSession();
204 } 234 }
205 235
206 public void createConnectionAndStart() { 236 public void createConnectionAndStart() {
207 Thread thread; 237 Thread thread;
208 opendPort = rfb.selectPort(5999); 238 opendPort = rfb.selectPort(5999);
334 } 364 }
335 365
336 public void changeVNCServer(String hostName) throws UnknownHostException, 366 public void changeVNCServer(String hostName) throws UnknownHostException,
337 IOException { 367 IOException {
338 // sender and reader stop 368 // sender and reader stop
339 tempWorkingProtocol = workingProtocol; 369 VncProxyService newVps = new VncProxyService(this,hostName);
340 // run call and change workingProtocol 370 // run call and change workingProtocol
341 this.connectionParams.hostName = hostName; 371 newVps.connectionParams.hostName = hostName;
342 this.run(); 372 if (newVps.run1()) {
343 this.createConnectionAndStart(); 373 newVps.createConnectionAndStart();
344 createSocketAndSend(aClient.getList(), String.valueOf(opendPort)); 374 newVps.createSocketAndSend(aClient.getList(), String.valueOf(opendPort));
375 } else {
376 newVps.cleanUpSession();
377 }
345 } 378 }
346 379
347 } 380 }