Mercurial > hg > Applications > AliceVNC
changeset 34:aace9df1462e
refactor
author | sugi |
---|---|
date | Thu, 13 Nov 2014 16:09:09 +0900 |
parents | 6f5986d8ecd5 |
children | 1fa4b7b8d19f e6e5b45c921d |
files | src/main/java/jp/ac/u_ryukyu/alicevnc/AliceVNCMessage.java src/main/java/jp/ac/u_ryukyu/alicevnc/CheckCurrentInfo.java src/main/java/jp/ac/u_ryukyu/alicevnc/CheckMyName.java src/main/java/jp/ac/u_ryukyu/alicevnc/NegotiateVNCServer.java src/main/java/jp/ac/u_ryukyu/alicevnc/ReceiveAliceVNCMessage.java src/main/java/jp/ac/u_ryukyu/alicevnc/ReceiveChangeRequest.java src/main/java/jp/ac/u_ryukyu/alicevnc/SendChangeRequest.java src/main/java/jp/ac/u_ryukyu/alicevnc/StopProxy.java |
diffstat | 8 files changed, 102 insertions(+), 99 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/alicevnc/AliceVNCMessage.java Sun Nov 09 17:33:43 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/alicevnc/AliceVNCMessage.java Thu Nov 13 16:09:09 2014 +0900 @@ -6,7 +6,6 @@ @Message public class AliceVNCMessage { - //TODO class name change public int messageID; public List<String> route; public boolean allowChange = false; @@ -20,11 +19,19 @@ messageID = type.getId(); } + public String getNextAddress(){ + int last = route.size() - 1; + String address = route.get(last); + route.remove(last); + return address; + } + public enum MessageType{ ChangeRequest(1), StartNegotiate(2), CurrentVNCInfo(3), - StopProxy(4); + StopProxy(4), + DeniedRequest(5); private final int id; private MessageType(final int id) {
--- a/src/main/java/jp/ac/u_ryukyu/alicevnc/CheckCurrentInfo.java Sun Nov 09 17:33:43 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/alicevnc/CheckCurrentInfo.java Thu Nov 13 16:09:09 2014 +0900 @@ -19,39 +19,37 @@ @Override public void run() { - System.out.println("check"); AliceVNCMessage current = info.asClass(AliceVNCMessage.class); - if (current.allowChange) { - // send Stop message to current - current.messageID = MessageType.StopProxy.getId(); - int last = current.route.size() - 1; - String address = current.route.get(last); - current.route.remove(last); - ods.put(address, "changeRequest", current); - - AliceVNCMessage mes = new AliceVNCMessage(MessageType.StartNegotiate); - mes.route = new ArrayList<String>(); - for (String s : order.route) { - mes.route.add(s); - } - mes.name = "node0"; + if (order.name.equals(current.name)) { + // need check route and node name + ods.update("currentServer", current); + } else { + if (current.allowChange) { + // send Stop message to current + current.messageID = MessageType.StopProxy.getId(); + String address = current.getNextAddress(); + ods.put(address, "AliceVNCMessage", current); - last = mes.route.size() - 1; - address = mes.route.get(last); - mes.route.remove(last); - ods.put(address, "changeRequest", mes); - } else { - // not allow to change - int last = order.route.size() - 1; - String address = order.route.get(last); - order.route.remove(last); - ods.put(address, "changeRequest", order); + AliceVNCMessage mes = new AliceVNCMessage(MessageType.StartNegotiate); + mes.route = new ArrayList<String>(); + for (String s : order.route) { + mes.route.add(s); + } + mes.name = "node0"; + address = mes.getNextAddress(); + ods.put(address, "AliceVNCMessage", mes); + } else { + // not allow to change + order.messageID = MessageType.DeniedRequest.getId(); + order.name = "node0"; + String address = order.getNextAddress(); + ods.put(address, "AliceVNCMessage", order); - // update current server info - ods.update("currentServer", current); + // update current server info + ods.update("currentServer", current); + } } - new ReceiveChangeRequest(); + new ReceiveAliceVNCMessage(); } - }
--- a/src/main/java/jp/ac/u_ryukyu/alicevnc/CheckMyName.java Sun Nov 09 17:33:43 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/alicevnc/CheckMyName.java Thu Nov 13 16:09:09 2014 +0900 @@ -21,7 +21,7 @@ new CreateWindow("parent"); } - new ReceiveChangeRequest(); + new ReceiveAliceVNCMessage(); new SendChangeRequest(); }
--- a/src/main/java/jp/ac/u_ryukyu/alicevnc/NegotiateVNCServer.java Sun Nov 09 17:33:43 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/alicevnc/NegotiateVNCServer.java Thu Nov 13 16:09:09 2014 +0900 @@ -35,7 +35,7 @@ currentServerInfo.allowChange = conf.getAllowChange(); ArrayList<String> list = new ArrayList<String>(); currentServerInfo.route = list; - ods.put("changeRequest", currentServerInfo); + ods.put("AliceVNCMessage", currentServerInfo); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/alicevnc/ReceiveAliceVNCMessage.java Thu Nov 13 16:09:09 2014 +0900 @@ -0,0 +1,62 @@ +package jp.ac.u_ryukyu.alicevnc; + +import java.util.List; + +import jp.ac.u_ryukyu.alicevnc.AliceVNCMessage.MessageType; +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class ReceiveAliceVNCMessage extends CodeSegment { + private Receiver info = ids.create(CommandType.TAKE); + private Receiver info1 = ids.create(CommandType.PEEK); // connection list + + public ReceiveAliceVNCMessage() { + info.setKey("AliceVNCMessage"); + info1.setKey("_CLIST"); + } + + @Override + public void run() { + AliceVNCMessage order = info.asClass(AliceVNCMessage.class); + + @SuppressWarnings("unchecked") + List<String> clist = info1.asClass(List.class); + if (order.messageID == MessageType.ChangeRequest.getId()|| + order.messageID == MessageType.CurrentVNCInfo.getId()) { + if (clist.contains("parent")){ + order.route.add(info.from); + ods.put("parent", "AliceVNCMessage", order); + new ReceiveAliceVNCMessage(); + } else { // this node is root. + order.route.add(info.from); + if (order.messageID == MessageType.CurrentVNCInfo.getId()) { + ods.put("currentServer", order); + new ReceiveAliceVNCMessage(); + } else { + new CheckCurrentInfo(order); // check change Server flag. + } + } + } else if (order.messageID == MessageType.StartNegotiate.getId()|| + order.messageID == MessageType.StopProxy.getId()|| + order.messageID == MessageType.DeniedRequest.getId()) { + if (order.route.size() == 0) { + // this node send ChangeVNCRequest + if (order.messageID == MessageType.StartNegotiate.getId()){ + // negotiate VNCServer by Viewer + ods.put("vncRight", true); + new NegotiateVNCServer(); + new ReceiveAliceVNCMessage(); + } else if(order.messageID == MessageType.StopProxy.getId()) { + new StopProxy(); + } else if (order.messageID == MessageType.DeniedRequest.getId()) { + // pop up window or message + } + } else { + String address = order.getNextAddress(); + ods.put(address, "AliceVNCMessage", order); + new ReceiveAliceVNCMessage(); + } + } + } +} \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/alicevnc/ReceiveChangeRequest.java Sun Nov 09 17:33:43 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -package jp.ac.u_ryukyu.alicevnc; - -import java.util.List; - -import jp.ac.u_ryukyu.alicevnc.AliceVNCMessage.MessageType; -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -public class ReceiveChangeRequest extends CodeSegment { - private Receiver info = ids.create(CommandType.TAKE); - private Receiver info1 = ids.create(CommandType.PEEK); // connection list - - public ReceiveChangeRequest() { - info.setKey("changeRequest"); - info1.setKey("_CLIST"); - } - - @Override - public void run() { - AliceVNCMessage order = info.asClass(AliceVNCMessage.class); - - @SuppressWarnings("unchecked") - List<String> clist = info1.asClass(List.class); - if (order.messageID == MessageType.ChangeRequest.getId()|| - order.messageID == MessageType.CurrentVNCInfo.getId()) { - if (clist.contains("parent")){ - order.route.add(info.from); - ods.put("parent", "changeRequest", order); - new ReceiveChangeRequest(); - } else { // this node is root. - order.route.add(info.from); - if (order.messageID == MessageType.CurrentVNCInfo.getId()) { - ods.put("currentServer", order); - new ReceiveChangeRequest(); - } else { - System.out.println("coming Server change request from "+ order.name+" "+order.route.size()); - new CheckCurrentInfo(order); // check change Server flag. - } - } - } else if (order.messageID == MessageType.StartNegotiate.getId()|| - order.messageID == MessageType.StopProxy.getId()) { - if (order.route.size() == 0) { - if (order.messageID == MessageType.StartNegotiate.getId()){ - // this node send ChangeVNCRequest - System.out.println("coming StartNegotiate from "+ order.name); - - // negotiate VNCServer by Viewer - ods.put("vncRight", true); - new NegotiateVNCServer(); - new ReceiveChangeRequest(); - } else { - new StopProxy(); - } - } else { - int last = order.route.size() - 1; - String address = order.route.get(last); - order.route.remove(last); - ods.put(address, "changeRequest", order); - new ReceiveChangeRequest(); - } - } - } -} \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/alicevnc/SendChangeRequest.java Sun Nov 09 17:33:43 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/alicevnc/SendChangeRequest.java Thu Nov 13 16:09:09 2014 +0900 @@ -40,7 +40,7 @@ address = "parent"; } - ods.put(address, "changeRequest", mes); + ods.put(address, "AliceVNCMessage", mes); new SendChangeRequest(); }
--- a/src/main/java/jp/ac/u_ryukyu/alicevnc/StopProxy.java Sun Nov 09 17:33:43 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/alicevnc/StopProxy.java Thu Nov 13 16:09:09 2014 +0900 @@ -18,7 +18,7 @@ System.out.println("call clean up session"); Viewer v = info.asClass(Viewer.class); v.closeApp(); - new ReceiveChangeRequest(); + new ReceiveAliceVNCMessage(); } }