Mercurial > hg > Database > Alice
changeset 419:aefbe41fcf12 dispose
change tab to space
line wrap: on
line diff
--- a/src/main/java/alice/codesegment/CodeSegment.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/codesegment/CodeSegment.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,22 +6,22 @@ import alice.datasegment.Receiver; public abstract class CodeSegment implements Runnable { - - public InputDataSegment ids = new InputDataSegment(this); - public OutputDataSegment ods = new OutputDataSegment(); - public ArrayList<Receiver> list = new ArrayList<Receiver>(); - - public void execute() { - ids.receive(); - } - - public void recycle(){ - ids.init(); - ids.setCounter(list.size()); - for (Receiver receiver : list) { - receiver.index = 0; - ids.recommand(receiver); - } - } + + public InputDataSegment ids = new InputDataSegment(this); + public OutputDataSegment ods = new OutputDataSegment(); + public ArrayList<Receiver> list = new ArrayList<Receiver>(); + + public void execute() { + ids.receive(); + } + + public void recycle(){ + ids.init(); + ids.setCounter(list.size()); + for (Receiver receiver : list) { + receiver.index = 0; + ids.recommand(receiver); + } + } }
--- a/src/main/java/alice/codesegment/CodeSegmentManager.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/codesegment/CodeSegmentManager.java Tue Jul 15 16:00:22 2014 +0900 @@ -8,24 +8,24 @@ public class CodeSegmentManager { - private static CodeSegmentManager instance = new CodeSegmentManager(); - private ThreadPoolExecutor codeSegmentExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), // initial number of threads - Runtime.getRuntime().availableProcessors(), - Integer.MAX_VALUE, // keepAliveTime - TimeUnit.SECONDS, - new LinkedBlockingQueue<Runnable>()); - private Logger logger = Logger.getLogger(CodeSegmentManager.class); + private static CodeSegmentManager instance = new CodeSegmentManager(); + private ThreadPoolExecutor codeSegmentExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), // initial number of threads + Runtime.getRuntime().availableProcessors(), + Integer.MAX_VALUE, // keepAliveTime + TimeUnit.SECONDS, + new LinkedBlockingQueue<Runnable>()); + private Logger logger = Logger.getLogger(CodeSegmentManager.class); - public static CodeSegmentManager get() { - return instance; - } + public static CodeSegmentManager get() { + return instance; + } - public static void submit(CodeSegment cs) { - CodeSegmentManager csManager = CodeSegmentManager.get(); - csManager.codeSegmentExecutor.execute(cs); - if (csManager.logger.isDebugEnabled()) { - csManager.logger.debug(cs.getClass().getName()); - } - } - + public static void submit(CodeSegment cs) { + CodeSegmentManager csManager = CodeSegmentManager.get(); + csManager.codeSegmentExecutor.execute(cs); + if (csManager.logger.isDebugEnabled()) { + csManager.logger.debug(cs.getClass().getName()); + } + } + }
--- a/src/main/java/alice/codesegment/OutputDataSegment.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/codesegment/OutputDataSegment.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,116 +6,116 @@ public class OutputDataSegment { - /** - * for local - */ + /** + * for local + */ + + public void flip(Receiver receiver) { + DataSegment.getLocal().put(receiver.key, receiver.getObj()); + } - public void flip(Receiver receiver) { - DataSegment.getLocal().put(receiver.key, receiver.getObj()); - } - - public void flip(Receiver receiver, CommandType type) { - switch (type) { - case PUT: - DataSegment.getLocal().put(receiver.key, receiver.getObj()); - break; - case UPDATE: - DataSegment.getLocal().update(receiver.key, receiver.getObj()); - break; - default: - break; - } - } + public void flip(Receiver receiver, CommandType type) { + switch (type) { + case PUT: + DataSegment.getLocal().put(receiver.key, receiver.getObj()); + break; + case UPDATE: + DataSegment.getLocal().update(receiver.key, receiver.getObj()); + break; + default: + break; + } + } - public void put(String key, Object val) { - DataSegment.getLocal().put(key, val); - } + public void put(String key, Object val) { + DataSegment.getLocal().put(key, val); + } - public void quickPut(String key, Object val) { - put(key, val); - } + public void quickPut(String key, Object val) { + put(key, val); + } - public void update(String key, Object val) { - DataSegment.getLocal().update(key, val); - } + public void update(String key, Object val) { + DataSegment.getLocal().update(key, val); + } - public void quickuUpdate(String key, Object val) { - update(key, val); - } + public void quickuUpdate(String key, Object val) { + update(key, val); + } - /** - * for remote - */ - public void put(String managerKey, String key, Object val) { - if (!managerKey.equals("local")){ - DataSegment.get(managerKey).put(key,val); - } else { - put(key, val); - } - } + /** + * for remote + */ + public void put(String managerKey, String key, Object val) { + if (!managerKey.equals("local")){ + DataSegment.get(managerKey).put(key,val); + } else { + put(key, val); + } + } - public void quickPut(String managerKey, String key, Object val) { - if (!managerKey.equals("local")){ - DataSegment.get(managerKey).quickPut(key, val); - } else { - put(key, val); - } - } + public void quickPut(String managerKey, String key, Object val) { + if (!managerKey.equals("local")){ + DataSegment.get(managerKey).quickPut(key, val); + } else { + put(key, val); + } + } - public void update(String managerKey, String key, Object val) { - if (!managerKey.equals("local")){ - DataSegment.get(managerKey).update(key, val); - } else { - update(key, val); - } - } + public void update(String managerKey, String key, Object val) { + if (!managerKey.equals("local")){ + DataSegment.get(managerKey).update(key, val); + } else { + update(key, val); + } + } - public void quickUpdate(String managerKey, String key, Object val) { - if (!managerKey.equals("local")){ - DataSegment.get(managerKey).update(key, val); - } else { - update(key, val); - } - } + public void quickUpdate(String managerKey, String key, Object val) { + if (!managerKey.equals("local")){ + DataSegment.get(managerKey).update(key, val); + } else { + update(key, val); + } + } - /** - * kill the Alice process after send other messages. - * - * @param managerKey - */ + /** + * kill the Alice process after send other messages. + * + * @param managerKey + */ - public void finish(String managerKey) { - DataSegment.get(managerKey).finish(); - } + public void finish(String managerKey) { + DataSegment.get(managerKey).finish(); + } - /** - * close socket for RemoteDataSegment after send other messages. - * - * @param managerKey - */ + /** + * close socket for RemoteDataSegment after send other messages. + * + * @param managerKey + */ - public void close(String managerKey) { - DataSegment.get(managerKey).close(); - } + public void close(String managerKey) { + DataSegment.get(managerKey).close(); + } - /** - * "key" is not remote DataSegment's key. - * "Ping Response" return in this "key" - * - * @param managerKey - * @param key - */ - public void ping(String managerKey, String returnKey) { - DataSegment.get(managerKey).ping(returnKey); - } - - /** - * this method is to forcibly close socket - * - * @param managerKey - */ + /** + * "key" is not remote DataSegment's key. + * "Ping Response" return in this "key" + * + * @param managerKey + * @param key + */ + public void ping(String managerKey, String returnKey) { + DataSegment.get(managerKey).ping(returnKey); + } - public void shutdown(String managerKey){ - DataSegment.get(managerKey).shutdown(); - } + /** + * this method is to forcibly close socket + * + * @param managerKey + */ + + public void shutdown(String managerKey){ + DataSegment.get(managerKey).shutdown(); + } }
--- a/src/main/java/alice/codesegment/SingletonMessage.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/codesegment/SingletonMessage.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,11 +3,11 @@ import org.msgpack.MessagePack; public class SingletonMessage { - - private static final MessagePack instance = new MessagePack(); - - public static MessagePack getInstance(){ - return instance; - } + + private static final MessagePack instance = new MessagePack(); + + public static MessagePack getInstance(){ + return instance; + } }
--- a/src/main/java/alice/daemon/AcceptThread.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/daemon/AcceptThread.java Tue Jul 15 16:00:22 2014 +0900 @@ -10,34 +10,34 @@ public class AcceptThread extends Thread { - private ServerSocket ss; - private Logger log = Logger.getLogger(AcceptThread.class); - public int counter = 0; + private ServerSocket ss; + private Logger log = Logger.getLogger(AcceptThread.class); + public int counter = 0; + + public AcceptThread(ServerSocket ss, String name) { + super(name); + this.ss = ss; + } - public AcceptThread(ServerSocket ss, String name) { - super(name); - this.ss = ss; - } - - @Override - public void run() { - while (true) { - try { - Socket socket = ss.accept(); - socket.setTcpNoDelay(true); - log.info("Accept " + socket.getInetAddress().getHostName() + ":" + socket.getPort()); - Connection connection = new Connection(socket); - String key = "accept" + counter; - IncomingTcpConnection incoming = - new IncomingTcpConnection(connection, DataSegment.get("local"), key); - incoming.start(); - DataSegment.setAccept(key, incoming); - new OutboundTcpConnection(connection).start(); - counter++; - } catch (IOException e) { - e.printStackTrace(); - } - } - } + @Override + public void run() { + while (true) { + try { + Socket socket = ss.accept(); + socket.setTcpNoDelay(true); + log.info("Accept " + socket.getInetAddress().getHostName() + ":" + socket.getPort()); + Connection connection = new Connection(socket); + String key = "accept" + counter; + IncomingTcpConnection incoming = + new IncomingTcpConnection(connection, DataSegment.get("local"), key); + incoming.start(); + DataSegment.setAccept(key, incoming); + new OutboundTcpConnection(connection).start(); + counter++; + } catch (IOException e) { + e.printStackTrace(); + } + } + } }
--- a/src/main/java/alice/daemon/AliceDaemon.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/daemon/AliceDaemon.java Tue Jul 15 16:00:22 2014 +0900 @@ -12,50 +12,50 @@ import org.apache.log4j.WriterAppender; public class AliceDaemon { - - private Config conf; - private AcceptThread acceptThread; - private Logger log = Logger.getLogger(AliceDaemon.class); - - public AliceDaemon(Config conf) { - this.conf = conf; - setLogger(); - } - - private void setLogger() { - Logger root = Logger.getRootLogger(); - if (conf.level != null) - root.setLevel(conf.level); - if (conf.logFile == null) - return; - PatternLayout layout = new PatternLayout(); - layout.setConversionPattern("%d %-5p %c - %m [%t] (%F:%L)%n"); - try { - FileWriter writer = new FileWriter(conf.logFile); - WriterAppender writerAppender = new WriterAppender(layout, writer); - root.removeAllAppenders(); - root.addAppender(writerAppender); - } catch (IOException e) { - e.printStackTrace(); - } - log.info("configured"); - } - - public void listen() { - try { - ServerSocketChannel ssChannel = ServerSocketChannel.open(); - ServerSocket ss = ssChannel.socket(); - ss.setReuseAddress(true); - + + private Config conf; + private AcceptThread acceptThread; + private Logger log = Logger.getLogger(AliceDaemon.class); + + public AliceDaemon(Config conf) { + this.conf = conf; + setLogger(); + } + + private void setLogger() { + Logger root = Logger.getRootLogger(); + if (conf.level != null) + root.setLevel(conf.level); + if (conf.logFile == null) + return; + PatternLayout layout = new PatternLayout(); + layout.setConversionPattern("%d %-5p %c - %m [%t] (%F:%L)%n"); + try { + FileWriter writer = new FileWriter(conf.logFile); + WriterAppender writerAppender = new WriterAppender(layout, writer); + root.removeAllAppenders(); + root.addAppender(writerAppender); + } catch (IOException e) { + e.printStackTrace(); + } + log.info("configured"); + } + + public void listen() { + try { + ServerSocketChannel ssChannel = ServerSocketChannel.open(); + ServerSocket ss = ssChannel.socket(); + ss.setReuseAddress(true); + //InetSocketAddress a = new InetSocketAddress("::", conf.localPort); InetSocketAddress a = new InetSocketAddress(InetAddress.getLocalHost(), conf.localPort); //System.out.println(a); ss.bind(a); - acceptThread = new AcceptThread(ss, "ACCEPT" + conf.localPort); - acceptThread.start(); - } catch (IOException e) { - e.printStackTrace(); - } - - } + acceptThread = new AcceptThread(ss, "ACCEPT" + conf.localPort); + acceptThread.start(); + } catch (IOException e) { + e.printStackTrace(); + } + + } }
--- a/src/main/java/alice/daemon/CommandMessage.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/daemon/CommandMessage.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,21 +5,21 @@ @Message public class CommandMessage { - public int type; - public int index; - public int seq; - public String key; - public Value val; - public boolean flag; - - public CommandMessage() {} - - public CommandMessage(int type, int index, int seq, String key, Value val, boolean flag) { - this.type = type; - this.index = index; - this.seq = seq; - this.key = key; - this.val = val; - this.flag = flag; - } + public int type; + public int index; + public int seq; + public String key; + public Value val; + public boolean flag; + + public CommandMessage() {} + + public CommandMessage(int type, int index, int seq, String key, Value val, boolean flag) { + this.type = type; + this.index = index; + this.seq = seq; + this.key = key; + this.val = val; + this.flag = flag; + } }
--- a/src/main/java/alice/daemon/Config.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/daemon/Config.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,38 +4,38 @@ public class Config { - public int localPort = 10000; - public String logFile = null; - public Level level = null; - public String MCSTADDR = "224.0.0.1"; - public String nis = "en1"; - - public Config(String[] args) { - for (int i = 0; i< args.length; i++) { - if ("-p".equals(args[i])) { - localPort = Integer.parseInt(args[++i]); - } else if ("-log".equals(args[i])) { - logFile = args[++i]; - } else if ("-n".equals(args[i])) { - nis = args[++i]; - } else if ("-a".equals(args[i])) { - MCSTADDR = args[++i]; - } else if ("-level".equals(args[i])) { - String levelStr = args[++i]; - if (levelStr.equals("fatal")) { - level = Level.FATAL; - } else if (levelStr.equals("error")) { - level = Level.ERROR; - } else if (levelStr.equals("warn")) { - level = Level.WARN; - } else if (levelStr.equals("info")) { - level = Level.INFO; - } else if (levelStr.equals("debug")) { - level = Level.DEBUG; - } - } - } + public int localPort = 10000; + public String logFile = null; + public Level level = null; + public String MCSTADDR = "224.0.0.1"; + public String nis = "en1"; - } + public Config(String[] args) { + for (int i = 0; i< args.length; i++) { + if ("-p".equals(args[i])) { + localPort = Integer.parseInt(args[++i]); + } else if ("-log".equals(args[i])) { + logFile = args[++i]; + } else if ("-n".equals(args[i])) { + nis = args[++i]; + } else if ("-a".equals(args[i])) { + MCSTADDR = args[++i]; + } else if ("-level".equals(args[i])) { + String levelStr = args[++i]; + if (levelStr.equals("fatal")) { + level = Level.FATAL; + } else if (levelStr.equals("error")) { + level = Level.ERROR; + } else if (levelStr.equals("warn")) { + level = Level.WARN; + } else if (levelStr.equals("info")) { + level = Level.INFO; + } else if (levelStr.equals("debug")) { + level = Level.DEBUG; + } + } + } + + } }
--- a/src/main/java/alice/daemon/Connection.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/daemon/Connection.java Tue Jul 15 16:00:22 2014 +0900 @@ -12,61 +12,61 @@ public class Connection { - public Socket socket; - public LinkedBlockingQueue<Command> sendQueue = new LinkedBlockingQueue<Command>(); + public Socket socket; + public LinkedBlockingQueue<Command> sendQueue = new LinkedBlockingQueue<Command>(); - public Connection(Socket socket) { - this.socket = socket; - } + public Connection(Socket socket) { + this.socket = socket; + } - public Connection() {} + public Connection() {} - public void sendCommand(Command cmd) { - try { - sendQueue.put(cmd); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } + public void sendCommand(Command cmd) { + try { + sendQueue.put(cmd); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } - public String getInfoString() { - return socket.getInetAddress().getHostName() - + ":" + socket.getPort(); - } + public String getInfoString() { + return socket.getInetAddress().getHostName() + + ":" + socket.getPort(); + } - public synchronized void write(Command cmd) { - CommandMessage cmdMsg = cmd.convert(); - ByteBuffer buffer; - try { - buffer = ByteBuffer.wrap(SingletonMessage.getInstance().write(cmdMsg)); - while (buffer.hasRemaining()) { - socket.getChannel().write(buffer); - } - } catch (ClosedChannelException e) { - // when put dataSegment to remote if connection close this dataSemgent put. - putConnectionInfo(); + public synchronized void write(Command cmd) { + CommandMessage cmdMsg = cmd.convert(); + ByteBuffer buffer; + try { + buffer = ByteBuffer.wrap(SingletonMessage.getInstance().write(cmdMsg)); + while (buffer.hasRemaining()) { + socket.getChannel().write(buffer); + } + } catch (ClosedChannelException e) { + // when put dataSegment to remote if connection close this dataSemgent put. + putConnectionInfo(); - } catch (IOException e) { - e.printStackTrace(); - } - } + } catch (IOException e) { + e.printStackTrace(); + } + } - public void close(){ - try { - socket.shutdownOutput(); - socket.shutdownInput(); - socket.close(); - } catch (ClosedChannelException e) { - putConnectionInfo(); - } catch (IOException e) { - e.printStackTrace(); - } + public void close(){ + try { + socket.shutdownOutput(); + socket.shutdownInput(); + socket.close(); + } catch (ClosedChannelException e) { + putConnectionInfo(); + } catch (IOException e) { + e.printStackTrace(); + } - } - - public void putConnectionInfo() { - ConnectionInfo c = new ConnectionInfo(socket.getInetAddress().toString() ,socket.getPort()); - DataSegment.getLocal().put("disconnect", c); - - } + } + + public void putConnectionInfo() { + ConnectionInfo c = new ConnectionInfo(socket.getInetAddress().toString() ,socket.getPort()); + DataSegment.getLocal().put("disconnect", c); + + } }
--- a/src/main/java/alice/daemon/IncomingTcpConnection.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/daemon/IncomingTcpConnection.java Tue Jul 15 16:00:22 2014 +0900 @@ -15,89 +15,89 @@ import alice.topology.manager.keeparive.RespondData; public class IncomingTcpConnection extends Thread { - - public Connection connection; - public DataSegmentManager manager; - public String reverseKey; - private LocalDataSegmentManager lmanager = DataSegment.getLocal(); + + public Connection connection; + public DataSegmentManager manager; + public String reverseKey; + private LocalDataSegmentManager lmanager = DataSegment.getLocal(); + + public IncomingTcpConnection(DataSegmentManager manager) { + this.manager = manager; + } + + public IncomingTcpConnection(Connection connection, DataSegmentManager manager, String reverseKey) { + this.manager = manager; + this.connection = connection; + this.reverseKey = reverseKey; + } + + public LocalDataSegmentManager getLocalDataSegmentManager(){ + return lmanager; + } - public IncomingTcpConnection(DataSegmentManager manager) { - this.manager = manager; - } - - public IncomingTcpConnection(Connection connection, DataSegmentManager manager, String reverseKey) { - this.manager = manager; - this.connection = connection; - this.reverseKey = reverseKey; - } - - public LocalDataSegmentManager getLocalDataSegmentManager(){ - return lmanager; - } - - /** - * pipeline thread for receiving - */ - public void run() { - Unpacker unpacker = null; - try { - unpacker = SingletonMessage.getInstance().createUnpacker(connection.socket.getInputStream()); - } catch (IOException e) { - e.printStackTrace(); - } - if (unpacker == null) { - return; - } - while (true) { - try { - CommandMessage msg = unpacker.read(CommandMessage.class); - CommandType type = CommandType.getCommandTypeFromId(msg.type); - switch (type) { - case UPDATE: - lmanager.getDataSegmentKey(msg.key) - .runCommand(new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey)); - break; - case PUT: - lmanager.getDataSegmentKey(msg.key) - .runCommand(new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey)); - break; - case PEEK: - lmanager.getDataSegmentKey(msg.key) - .runCommand(new Command(type, null, null, null, msg.index, msg.seq, connection, null, null, msg.flag)); - break; - case TAKE: - lmanager.getDataSegmentKey(msg.key) - .runCommand(new Command(type, null, null, null, msg.index, msg.seq, connection, null, null, msg.flag)); - break; - case REMOVE: - lmanager.getDataSegmentKey(msg.key) - .runCommand(new Command(type, null, null, null, 0, 0, null, null, null)); - break; - case REPLY: - Command cmd = manager.getAndRemoveCmd(msg.seq); - cmd.cs.ids.reply(cmd.receiver, new Command(type, null, null, msg.val, msg.index, msg.seq, null, null, null)); - cmd=null; - break; - case PING: - DataSegment.get(reverseKey).response(msg.key); - break; - case RESPONSE: - DataSegment.getLocal().put(msg.key, new RespondData(reverseKey, System.currentTimeMillis())); - break; - default: - break; - } - } catch (ClosedChannelException e) { - connection.putConnectionInfo(); - connection.sendCommand(new Command(CommandType.CLOSE, null, null, null, 0, 0, null, null, null)); - return; - } catch (EOFException e) { - connection.sendCommand(new Command(CommandType.CLOSE, null, null, null, 0, 0, null, null, null)); - return; - } catch (IOException e) { - e.printStackTrace(); - } - } - } + /** + * pipeline thread for receiving + */ + public void run() { + Unpacker unpacker = null; + try { + unpacker = SingletonMessage.getInstance().createUnpacker(connection.socket.getInputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + if (unpacker == null) { + return; + } + while (true) { + try { + CommandMessage msg = unpacker.read(CommandMessage.class); + CommandType type = CommandType.getCommandTypeFromId(msg.type); + switch (type) { + case UPDATE: + lmanager.getDataSegmentKey(msg.key) + .runCommand(new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey)); + break; + case PUT: + lmanager.getDataSegmentKey(msg.key) + .runCommand(new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey)); + break; + case PEEK: + lmanager.getDataSegmentKey(msg.key) + .runCommand(new Command(type, null, null, null, msg.index, msg.seq, connection, null, null, msg.flag)); + break; + case TAKE: + lmanager.getDataSegmentKey(msg.key) + .runCommand(new Command(type, null, null, null, msg.index, msg.seq, connection, null, null, msg.flag)); + break; + case REMOVE: + lmanager.getDataSegmentKey(msg.key) + .runCommand(new Command(type, null, null, null, 0, 0, null, null, null)); + break; + case REPLY: + Command cmd = manager.getAndRemoveCmd(msg.seq); + cmd.cs.ids.reply(cmd.receiver, new Command(type, null, null, msg.val, msg.index, msg.seq, null, null, null)); + cmd=null; + break; + case PING: + DataSegment.get(reverseKey).response(msg.key); + break; + case RESPONSE: + DataSegment.getLocal().put(msg.key, new RespondData(reverseKey, System.currentTimeMillis())); + break; + default: + break; + } + } catch (ClosedChannelException e) { + connection.putConnectionInfo(); + connection.sendCommand(new Command(CommandType.CLOSE, null, null, null, 0, 0, null, null, null)); + return; + } catch (EOFException e) { + connection.sendCommand(new Command(CommandType.CLOSE, null, null, null, 0, 0, null, null, null)); + return; + } catch (IOException e) { + e.printStackTrace(); + } + } + } }
--- a/src/main/java/alice/daemon/MulticastConnection.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/daemon/MulticastConnection.java Tue Jul 15 16:00:22 2014 +0900 @@ -9,45 +9,45 @@ import alice.datasegment.Command; public class MulticastConnection extends Connection { - private DatagramChannel dc; - private SocketAddress sAddr; + private DatagramChannel dc; + private SocketAddress sAddr; - public MulticastConnection(DatagramChannel d, SocketAddress s) { - dc = d; - sAddr = s; - } + public MulticastConnection(DatagramChannel d, SocketAddress s) { + dc = d; + sAddr = s; + } - // may need to add infomation who send on ds. - @Override - public synchronized void write(Command cmd){ - CommandMessage cmdMsg = cmd.convert(); - ByteBuffer buffer; - try { - buffer = ByteBuffer.wrap(SingletonMessage.getInstance().write(cmdMsg)); - while (buffer.hasRemaining()){ - dc.send(buffer, sAddr); - } - } catch (IOException e) { - e.printStackTrace(); - } + // may need to add infomation who send on ds. + @Override + public synchronized void write(Command cmd){ + CommandMessage cmdMsg = cmd.convert(); + ByteBuffer buffer; + try { + buffer = ByteBuffer.wrap(SingletonMessage.getInstance().write(cmdMsg)); + while (buffer.hasRemaining()){ + dc.send(buffer, sAddr); + } + } catch (IOException e) { + e.printStackTrace(); + } - } + } - @Override - public void close(){ - try { - dc.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void receive(ByteBuffer receiveData){ - try { - dc.receive(receiveData); - } catch (IOException e) { - e.printStackTrace(); - } - } + @Override + public void close(){ + try { + dc.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void receive(ByteBuffer receiveData){ + try { + dc.receive(receiveData); + } catch (IOException e) { + e.printStackTrace(); + } + } }
--- a/src/main/java/alice/daemon/OutboundTcpConnection.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/daemon/OutboundTcpConnection.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,35 +3,35 @@ import alice.datasegment.Command; public class OutboundTcpConnection extends Thread { - - public Connection connection; - - public OutboundTcpConnection(Connection connection) { - this.connection = connection; - } - - /** - * pipeline thread for transmission - */ - public void run() { - while (true) { - try { - Command cmd = connection.sendQueue.take(); - switch (cmd.type) { - case CLOSE: - connection.close(); - return; - case FINISH: - System.exit(0); - return; - default: - break; - } - connection.write(cmd); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - + + public Connection connection; + + public OutboundTcpConnection(Connection connection) { + this.connection = connection; + } + + /** + * pipeline thread for transmission + */ + public void run() { + while (true) { + try { + Command cmd = connection.sendQueue.take(); + switch (cmd.type) { + case CLOSE: + connection.close(); + return; + case FINISH: + System.exit(0); + return; + default: + break; + } + connection.write(cmd); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + }
--- a/src/main/java/alice/datasegment/Command.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/datasegment/Command.java Tue Jul 15 16:00:22 2014 +0900 @@ -10,101 +10,101 @@ import alice.daemon.Connection; public class Command { - public CommandType type; - public String key; - public Receiver receiver; - public Value val; - public int index; - public int seq; - public Connection connection; // for remote - public BlockingQueue<Command> replyQueue; - public CodeSegment cs; - public String reverseKey; - public Object obj; - public boolean flag; + public CommandType type; + public String key; + public Receiver receiver; + public Value val; + public int index; + public int seq; + public Connection connection; // for remote + public BlockingQueue<Command> replyQueue; + public CodeSegment cs; + public String reverseKey; + public Object obj; + public boolean flag; + + public Command(CommandType cmdType, Receiver receiver, String key, Value val, int index, int seq, BlockingQueue<Command> replyQueue, CodeSegment cs, String reverseKey) { + this.type = cmdType; + this.receiver = receiver; + this.key = key; + this.val = val; + this.index = index; + this.seq = seq; + this.replyQueue = replyQueue; + this.cs = cs; + this.reverseKey = reverseKey; + this.flag = false; + } + + public Command(CommandType cmdType, Receiver receiver, String key, Value val, int index, int seq, BlockingQueue<Command> replyQueue, CodeSegment cs, String reverseKey, boolean flag) { + this.type = cmdType; + this.receiver = receiver; + this.key = key; + this.val = val; + this.index = index; + this.seq = seq; + this.replyQueue = replyQueue; + this.cs = cs; + this.reverseKey = reverseKey; + this.flag = flag; + } - public Command(CommandType cmdType, Receiver receiver, String key, Value val, int index, int seq, BlockingQueue<Command> replyQueue, CodeSegment cs, String reverseKey) { - this.type = cmdType; - this.receiver = receiver; - this.key = key; - this.val = val; - this.index = index; - this.seq = seq; - this.replyQueue = replyQueue; - this.cs = cs; - this.reverseKey = reverseKey; - this.flag = false; - } - - public Command(CommandType cmdType, Receiver receiver, String key, Value val, int index, int seq, BlockingQueue<Command> replyQueue, CodeSegment cs, String reverseKey, boolean flag) { - this.type = cmdType; - this.receiver = receiver; - this.key = key; - this.val = val; - this.index = index; - this.seq = seq; - this.replyQueue = replyQueue; - this.cs = cs; - this.reverseKey = reverseKey; - this.flag = flag; - } - - public Command(CommandType cmdType, Receiver receiver, String key, Value val, int index, int seq, Connection connection, CodeSegment cs, String reverseKey, boolean flag) { - this.type = cmdType; - this.receiver = receiver; - this.key = key; - this.val = val; - this.index = index; - this.seq = seq; - this.connection = connection; - this.cs = cs; - this.reverseKey = reverseKey; - this.flag = flag; - } - - public Command(CommandType cmdType, Receiver receiver, String key, Object obj, int index, int seq, BlockingQueue<Command> replyQueue, CodeSegment cs, String reverseKey) { - this.type = cmdType; - this.receiver = receiver; - this.key = key; - this.obj = obj; - this.index = index; - this.seq = seq; - this.replyQueue = replyQueue; - this.cs = cs; - this.reverseKey = reverseKey; - this.flag = false; - } - - public Command(CommandType cmdType, Receiver receiver, String key, Value val, Object obj, int index, int seq, BlockingQueue<Command> replyQueue, CodeSegment cs, String reverseKey) { - this.type = cmdType; - this.receiver = receiver; - this.key = key; - this.val = val; - this.obj = obj; - this.index = index; - this.seq = seq; - this.replyQueue = replyQueue; - this.cs = cs; - this.reverseKey = reverseKey; - this.flag = false; - } - - public String getCommandString() { - String csName = "null"; - if (cs != null) { - csName = cs.toString(); - } - return this.type + "\t" + key + "\t" + val + "\tindex=" + index + "\tcs=" + csName; - } - public CommandMessage convert() { - if (val==null&&obj!=null){ - try { - this.val = SingletonMessage.getInstance().unconvert(obj); - } catch (IOException e) { - e.printStackTrace(); - } - } - return new CommandMessage(type.id, index, seq, key, val, flag); - } - + public Command(CommandType cmdType, Receiver receiver, String key, Value val, int index, int seq, Connection connection, CodeSegment cs, String reverseKey, boolean flag) { + this.type = cmdType; + this.receiver = receiver; + this.key = key; + this.val = val; + this.index = index; + this.seq = seq; + this.connection = connection; + this.cs = cs; + this.reverseKey = reverseKey; + this.flag = flag; + } + + public Command(CommandType cmdType, Receiver receiver, String key, Object obj, int index, int seq, BlockingQueue<Command> replyQueue, CodeSegment cs, String reverseKey) { + this.type = cmdType; + this.receiver = receiver; + this.key = key; + this.obj = obj; + this.index = index; + this.seq = seq; + this.replyQueue = replyQueue; + this.cs = cs; + this.reverseKey = reverseKey; + this.flag = false; + } + + public Command(CommandType cmdType, Receiver receiver, String key, Value val, Object obj, int index, int seq, BlockingQueue<Command> replyQueue, CodeSegment cs, String reverseKey) { + this.type = cmdType; + this.receiver = receiver; + this.key = key; + this.val = val; + this.obj = obj; + this.index = index; + this.seq = seq; + this.replyQueue = replyQueue; + this.cs = cs; + this.reverseKey = reverseKey; + this.flag = false; + } + + public String getCommandString() { + String csName = "null"; + if (cs != null) { + csName = cs.toString(); + } + return this.type + "\t" + key + "\t" + val + "\tindex=" + index + "\tcs=" + csName; + } + public CommandMessage convert() { + if (val==null&&obj!=null){ + try { + this.val = SingletonMessage.getInstance().unconvert(obj); + } catch (IOException e) { + e.printStackTrace(); + } + } + return new CommandMessage(type.id, index, seq, key, val, flag); + } + }
--- a/src/main/java/alice/datasegment/CommandType.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/datasegment/CommandType.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,46 +3,46 @@ import java.util.HashMap; public enum CommandType { - PUT, - UPDATE, // remove a DataSegment value and put - PEEK, - TAKE, - REMOVE, - REPLY, - CLOSE, - FINISH, - PING, - RESPONSE; - - public int id; - public static HashMap<Integer, CommandType> hash = new HashMap<Integer, CommandType>(); - private static int lastId = 0; - - private CommandType(int id) { - this.id = id; - setLastId(id); - } - - private CommandType() { - this.id = incrementLastId(); - } - - private void setLastId(int id) { - lastId =id; - } - - private int incrementLastId() { - return ++lastId; - } - - public static CommandType getCommandTypeFromId(int id) { - return hash.get(id); - } - - static { - for (CommandType type : CommandType.values()) { - hash.put(type.id, type); - } - } - + PUT, + UPDATE, // remove a DataSegment value and put + PEEK, + TAKE, + REMOVE, + REPLY, + CLOSE, + FINISH, + PING, + RESPONSE; + + public int id; + public static HashMap<Integer, CommandType> hash = new HashMap<Integer, CommandType>(); + private static int lastId = 0; + + private CommandType(int id) { + this.id = id; + setLastId(id); + } + + private CommandType() { + this.id = incrementLastId(); + } + + private void setLastId(int id) { + lastId =id; + } + + private int incrementLastId() { + return ++lastId; + } + + public static CommandType getCommandTypeFromId(int id) { + return hash.get(id); + } + + static { + for (CommandType type : CommandType.values()) { + hash.put(type.id, type); + } + } + }
--- a/src/main/java/alice/datasegment/DataSegment.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/datasegment/DataSegment.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,50 +5,50 @@ import alice.daemon.IncomingTcpConnection; public class DataSegment { - - private static DataSegment dataSegment = new DataSegment(); - private LocalDataSegmentManager local = new LocalDataSegmentManager(); - private ConcurrentHashMap<String, DataSegmentManager> dataSegmentManagers = new ConcurrentHashMap<String, DataSegmentManager>(); //TODO Over Head - private ConcurrentHashMap<String, IncomingTcpConnection> acceptHash = new ConcurrentHashMap<String, IncomingTcpConnection>(); - - private DataSegment() { - dataSegmentManagers.put("local", local); - } - - public static DataSegmentManager get(String key) { - return dataSegment.dataSegmentManagers.get(key); - } + + private static DataSegment dataSegment = new DataSegment(); + private LocalDataSegmentManager local = new LocalDataSegmentManager(); + private ConcurrentHashMap<String, DataSegmentManager> dataSegmentManagers = new ConcurrentHashMap<String, DataSegmentManager>(); //TODO Over Head + private ConcurrentHashMap<String, IncomingTcpConnection> acceptHash = new ConcurrentHashMap<String, IncomingTcpConnection>(); + + private DataSegment() { + dataSegmentManagers.put("local", local); + } + + public static DataSegmentManager get(String key) { + return dataSegment.dataSegmentManagers.get(key); + } + + public static LocalDataSegmentManager getLocal() { + return dataSegment.local; + } + + public static void register(String key, DataSegmentManager manager) { + dataSegment.dataSegmentManagers.put(key, manager); + } - public static LocalDataSegmentManager getLocal() { - return dataSegment.local; - } - - public static void register(String key, DataSegmentManager manager) { - dataSegment.dataSegmentManagers.put(key, manager); - } - - public static RemoteDataSegmentManager connect(String connectionKey, String reverseKey, String hostName, int port) { - RemoteDataSegmentManager manager = new RemoteDataSegmentManager(connectionKey, reverseKey, hostName, port); - register(connectionKey, manager); - return manager; - } - - public static MulticastDataSegmentManager connectMulticast(String connectionKey ,String MCSTADDR, int port, String nis){ - MulticastDataSegmentManager manager = new MulticastDataSegmentManager(connectionKey ,MCSTADDR, port, nis); - register("multicast", manager); - return manager; - } - - public static void setAccept(String key, IncomingTcpConnection incoming) { - dataSegment.acceptHash.put(key, incoming); - } - - public static IncomingTcpConnection getAccept(String key) { - return dataSegment.acceptHash.get(key); - } - - public static void remove(String key){ - dataSegment.dataSegmentManagers.remove(key); - } - + public static RemoteDataSegmentManager connect(String connectionKey, String reverseKey, String hostName, int port) { + RemoteDataSegmentManager manager = new RemoteDataSegmentManager(connectionKey, reverseKey, hostName, port); + register(connectionKey, manager); + return manager; + } + + public static MulticastDataSegmentManager connectMulticast(String connectionKey ,String MCSTADDR, int port, String nis){ + MulticastDataSegmentManager manager = new MulticastDataSegmentManager(connectionKey ,MCSTADDR, port, nis); + register("multicast", manager); + return manager; + } + + public static void setAccept(String key, IncomingTcpConnection incoming) { + dataSegment.acceptHash.put(key, incoming); + } + + public static IncomingTcpConnection getAccept(String key) { + return dataSegment.acceptHash.get(key); + } + + public static void remove(String key){ + dataSegment.dataSegmentManagers.remove(key); + } + }
--- a/src/main/java/alice/datasegment/DataSegmentKey.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/datasegment/DataSegmentKey.java Tue Jul 15 16:00:22 2014 +0900 @@ -11,93 +11,93 @@ * */ public class DataSegmentKey { - - private ArrayList<DataSegmentValue> dataList = new ArrayList<DataSegmentValue>(); - private ArrayList<Command> waitList = new ArrayList<Command>(); - private int tailIndex = 1; - - public synchronized void runCommand(Command cmd) { - switch (cmd.type) { - case UPDATE: - if (dataList.size() != 0) { - dataList.remove(0); - } - case PUT: - int index = tailIndex; - tailIndex++; - DataSegmentValue dsv = new DataSegmentValue(index, cmd.val, cmd.obj, cmd.reverseKey); - dataList.add(dsv); - // Process waiting peek and take commands - for (Iterator<Command> iter = waitList.iterator(); iter.hasNext(); ) { - Command waitCmd = iter.next(); - if (waitCmd.index < index) { - replyValue(waitCmd ,dsv); - iter.remove(); - if (waitCmd.type == CommandType.TAKE) { // someone is waiting for this put or update command - dataList.remove(dsv); - break; - } - } - } - break; - case PEEK: - if (cmd.index >= tailIndex) { - waitList.add(cmd); - break; - } - boolean waitFlag2 = true; - for (DataSegmentValue data : dataList) { - if (data.index > cmd.index) { - replyValue(cmd ,data); - waitFlag2 = false; - break; - } - } - if (waitFlag2) - waitList.add(cmd); - break; - case TAKE: - if (cmd.index >= tailIndex) { - waitList.add(cmd); - break; - } - boolean waitFlag = true; - for (Iterator<DataSegmentValue> iter = dataList.iterator(); iter.hasNext(); ) { - DataSegmentValue data = iter.next(); - if (data.index > cmd.index) { - replyValue(cmd ,data); - iter.remove(); - waitFlag = false; - break; - } - } - if (waitFlag) - waitList.add(cmd); - break; - case REMOVE: - // TODO: implements later - break; - default: - } + + private ArrayList<DataSegmentValue> dataList = new ArrayList<DataSegmentValue>(); + private ArrayList<Command> waitList = new ArrayList<Command>(); + private int tailIndex = 1; - } - - public void replyValue(Command cmd, DataSegmentValue data){ - if (cmd.cs!=null){ // if cmd has cs-instance, it means Command from local. - cmd.cs.ids.reply(cmd.receiver, new Command(CommandType.REPLY, null, null, data.val, data.obj, data.index, cmd.seq, null, null, data.from)); - } else { - try { - if (!cmd.flag){ - cmd.connection.sendQueue.put(new Command(CommandType.REPLY, null, null, data.val, data.obj, data.index, cmd.seq, null, null, data.from)); - } - else { - cmd.connection.write(new Command(CommandType.REPLY, null, null, data.val, data.obj, data.index, cmd.seq, null, null, data.from)); - } - - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - + public synchronized void runCommand(Command cmd) { + switch (cmd.type) { + case UPDATE: + if (dataList.size() != 0) { + dataList.remove(0); + } + case PUT: + int index = tailIndex; + tailIndex++; + DataSegmentValue dsv = new DataSegmentValue(index, cmd.val, cmd.obj, cmd.reverseKey); + dataList.add(dsv); + // Process waiting peek and take commands + for (Iterator<Command> iter = waitList.iterator(); iter.hasNext(); ) { + Command waitCmd = iter.next(); + if (waitCmd.index < index) { + replyValue(waitCmd ,dsv); + iter.remove(); + if (waitCmd.type == CommandType.TAKE) { // someone is waiting for this put or update command + dataList.remove(dsv); + break; + } + } + } + break; + case PEEK: + if (cmd.index >= tailIndex) { + waitList.add(cmd); + break; + } + boolean waitFlag2 = true; + for (DataSegmentValue data : dataList) { + if (data.index > cmd.index) { + replyValue(cmd ,data); + waitFlag2 = false; + break; + } + } + if (waitFlag2) + waitList.add(cmd); + break; + case TAKE: + if (cmd.index >= tailIndex) { + waitList.add(cmd); + break; + } + boolean waitFlag = true; + for (Iterator<DataSegmentValue> iter = dataList.iterator(); iter.hasNext(); ) { + DataSegmentValue data = iter.next(); + if (data.index > cmd.index) { + replyValue(cmd ,data); + iter.remove(); + waitFlag = false; + break; + } + } + if (waitFlag) + waitList.add(cmd); + break; + case REMOVE: + // TODO: implements later + break; + default: + } + + } + + public void replyValue(Command cmd, DataSegmentValue data){ + if (cmd.cs!=null){ // if cmd has cs-instance, it means Command from local. + cmd.cs.ids.reply(cmd.receiver, new Command(CommandType.REPLY, null, null, data.val, data.obj, data.index, cmd.seq, null, null, data.from)); + } else { + try { + if (!cmd.flag){ + cmd.connection.sendQueue.put(new Command(CommandType.REPLY, null, null, data.val, data.obj, data.index, cmd.seq, null, null, data.from)); + } + else { + cmd.connection.write(new Command(CommandType.REPLY, null, null, data.val, data.obj, data.index, cmd.seq, null, null, data.from)); + } + + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + }
--- a/src/main/java/alice/datasegment/DataSegmentManager.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/datasegment/DataSegmentManager.java Tue Jul 15 16:00:22 2014 +0900 @@ -9,63 +9,63 @@ import alice.codesegment.CodeSegment; public abstract class DataSegmentManager { - - protected ConcurrentHashMap<Integer, Command> seqHash = new ConcurrentHashMap<Integer, Command>(); - protected LinkedBlockingQueue<Command> replyQueue = new LinkedBlockingQueue<Command>(); - protected AtomicInteger seq = new AtomicInteger(1); // waiting for PUT or UPDATE at unique sequence number - // but it doesn't need for Local - - protected Runnable replyThread = new Runnable() { - Logger logger = Logger.getLogger("reply"); - @Override - public void run() { - while (true) { - try { - Command reply = replyQueue.take(); - Command cmd = getAndRemoveCmd(reply.seq); - if (cmd == null) { - logger.warn("conflict sequence number"); - continue; - } - cmd.cs.ids.reply(cmd.receiver, reply); - if (logger.isDebugEnabled()) - logger.debug(reply.getCommandString() + " " + cmd.getCommandString()); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - - }; - - public Command getAndRemoveCmd(int index){ - return seqHash.remove(index); - } - - public void addReplyCommand(Command cmd) { - try { - replyQueue.put(cmd); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - public abstract void put(String key, Object val); - public abstract void update(String key, Object val); - public abstract void peek(Receiver receiver, CodeSegment cs); - public abstract void take(Receiver receiver, CodeSegment cs); - - public abstract void quickPut(String key, Object val); - public abstract void quickUpdate(String key, Object val); - public abstract void quickPeek(Receiver receiver, CodeSegment cs); - public abstract void quickTake(Receiver receiver, CodeSegment cs); + + protected ConcurrentHashMap<Integer, Command> seqHash = new ConcurrentHashMap<Integer, Command>(); + protected LinkedBlockingQueue<Command> replyQueue = new LinkedBlockingQueue<Command>(); + protected AtomicInteger seq = new AtomicInteger(1); // waiting for PUT or UPDATE at unique sequence number + // but it doesn't need for Local + + protected Runnable replyThread = new Runnable() { + Logger logger = Logger.getLogger("reply"); + @Override + public void run() { + while (true) { + try { + Command reply = replyQueue.take(); + Command cmd = getAndRemoveCmd(reply.seq); + if (cmd == null) { + logger.warn("conflict sequence number"); + continue; + } + cmd.cs.ids.reply(cmd.receiver, reply); + if (logger.isDebugEnabled()) + logger.debug(reply.getCommandString() + " " + cmd.getCommandString()); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + }; - public abstract void remove(String key); - public abstract void shutdown(); - public abstract void close(); - public abstract void finish(); - - public abstract void ping(String returnKey); - public abstract void response(String returnKey); - + public Command getAndRemoveCmd(int index){ + return seqHash.remove(index); + } + + public void addReplyCommand(Command cmd) { + try { + replyQueue.put(cmd); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public abstract void put(String key, Object val); + public abstract void update(String key, Object val); + public abstract void peek(Receiver receiver, CodeSegment cs); + public abstract void take(Receiver receiver, CodeSegment cs); + + public abstract void quickPut(String key, Object val); + public abstract void quickUpdate(String key, Object val); + public abstract void quickPeek(Receiver receiver, CodeSegment cs); + public abstract void quickTake(Receiver receiver, CodeSegment cs); + + public abstract void remove(String key); + public abstract void shutdown(); + public abstract void close(); + public abstract void finish(); + + public abstract void ping(String returnKey); + public abstract void response(String returnKey); + }
--- a/src/main/java/alice/datasegment/DataSegmentValue.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/datasegment/DataSegmentValue.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,22 +4,22 @@ public class DataSegmentValue { - public int index; - public Value val; - public String from; - public Object obj; - - public DataSegmentValue(int index, Value val, Object obj,String reverseKey) { - this.index = index; - this.val = val; - this.from = reverseKey; - this.obj = obj; - } - - public DataSegmentValue(int index, Value val,String reverseKey) { - this.index = index; - this.val = val; - this.from = reverseKey; - } - + public int index; + public Value val; + public String from; + public Object obj; + + public DataSegmentValue(int index, Value val, Object obj,String reverseKey) { + this.index = index; + this.val = val; + this.from = reverseKey; + this.obj = obj; + } + + public DataSegmentValue(int index, Value val,String reverseKey) { + this.index = index; + this.val = val; + this.from = reverseKey; + } + }
--- a/src/main/java/alice/datasegment/LocalDataSegmentManager.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/datasegment/LocalDataSegmentManager.java Tue Jul 15 16:00:22 2014 +0900 @@ -10,163 +10,163 @@ import alice.codesegment.CodeSegment; public class LocalDataSegmentManager extends DataSegmentManager { - - private String reverseKey = "local"; - private ConcurrentHashMap<String, DataSegmentKey> dataSegments = new ConcurrentHashMap<String, DataSegmentKey>(); - private Logger logger = Logger.getLogger("local"); + + private String reverseKey = "local"; + private ConcurrentHashMap<String, DataSegmentKey> dataSegments = new ConcurrentHashMap<String, DataSegmentKey>(); + private Logger logger = Logger.getLogger("local"); + + private ThreadPoolExecutor dataSegmentExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), // initial number of threads + Runtime.getRuntime().availableProcessors(), + Integer.MAX_VALUE, // keepAliveTime + TimeUnit.SECONDS, + new LinkedBlockingQueue<Runnable>()); + + public LocalDataSegmentManager() { + new Thread(replyThread, "LocalDataSegmentManager-replyCommand").start(); + } + + public void setReverseKey(String s){ + reverseKey = s; + } + + private class RunCommand implements Runnable { + + DataSegmentKey key; + Command cmd; + + public RunCommand(DataSegmentKey key, Command cmd) { + this.key = key; + this.cmd = cmd; + } + + @Override + public void run() { + key.runCommand(cmd); + } + + } - private ThreadPoolExecutor dataSegmentExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), // initial number of threads - Runtime.getRuntime().availableProcessors(), - Integer.MAX_VALUE, // keepAliveTime - TimeUnit.SECONDS, - new LinkedBlockingQueue<Runnable>()); - - public LocalDataSegmentManager() { - new Thread(replyThread, "LocalDataSegmentManager-replyCommand").start(); - } + public void submitCommand(DataSegmentKey key, Command cmd) { + dataSegmentExecutor.execute(new RunCommand(key, cmd)); + } + + public DataSegmentKey getDataSegmentKey(String key) { + DataSegmentKey dsKey = dataSegments.get(key); + if (dsKey != null) + return dsKey; + if (key == null) + return null; + DataSegmentKey newDataSegmentKey = new DataSegmentKey(); + DataSegmentKey dataSegmentKey = dataSegments.putIfAbsent(key, newDataSegmentKey); + if (dataSegmentKey == null) { + dataSegmentKey = newDataSegmentKey; + } + return dataSegmentKey; + } + + @Override + public void put(String key, Object val) { + DataSegmentKey dataSegmentKey = getDataSegmentKey(key); + Command cmd = new Command(CommandType.PUT, null, key, val, 0, 0, null, null, reverseKey); + dataSegmentKey.runCommand(cmd); + if (logger.isDebugEnabled()) + logger.debug(cmd.getCommandString()); + } + + @Override + public void quickPut(String key, Object val) { + put(key, val); + } + + /** + * Enqueue update command to the queue of each DataSegment key + */ - public void setReverseKey(String s){ - reverseKey = s; - } - - private class RunCommand implements Runnable { - - DataSegmentKey key; - Command cmd; - - public RunCommand(DataSegmentKey key, Command cmd) { - this.key = key; - this.cmd = cmd; - } - - @Override - public void run() { - key.runCommand(cmd); - } - - } - - public void submitCommand(DataSegmentKey key, Command cmd) { - dataSegmentExecutor.execute(new RunCommand(key, cmd)); - } - - public DataSegmentKey getDataSegmentKey(String key) { - DataSegmentKey dsKey = dataSegments.get(key); - if (dsKey != null) - return dsKey; - if (key == null) - return null; - DataSegmentKey newDataSegmentKey = new DataSegmentKey(); - DataSegmentKey dataSegmentKey = dataSegments.putIfAbsent(key, newDataSegmentKey); - if (dataSegmentKey == null) { - dataSegmentKey = newDataSegmentKey; - } - return dataSegmentKey; - } - - @Override - public void put(String key, Object val) { - DataSegmentKey dataSegmentKey = getDataSegmentKey(key); - Command cmd = new Command(CommandType.PUT, null, key, val, 0, 0, null, null, reverseKey); - dataSegmentKey.runCommand(cmd); - if (logger.isDebugEnabled()) - logger.debug(cmd.getCommandString()); - } - - @Override - public void quickPut(String key, Object val) { - put(key, val); - } - - /** - * Enqueue update command to the queue of each DataSegment key - */ - - @Override - public void update(String key, Object val) { - DataSegmentKey dataSegmentKey = getDataSegmentKey(key); - Command cmd = new Command(CommandType.UPDATE, null, key, val, 0, 0, null, null, reverseKey); - dataSegmentKey.runCommand(cmd); - if (logger.isDebugEnabled()) - logger.debug(cmd.getCommandString()); - } - - @Override - public void quickUpdate(String key, Object val) { - update(key, val); - } - - @Override - public void take(Receiver receiver, CodeSegment cs) { - DataSegmentKey dataSegmentKey = getDataSegmentKey(receiver.key); - int seq = this.seq.getAndIncrement(); - Command cmd = new Command(CommandType.TAKE, receiver, receiver.key, null, receiver.index, seq, replyQueue, cs, null); - dataSegmentKey.runCommand(cmd); - if (logger.isDebugEnabled()) - logger.debug(cmd.getCommandString()); - } + @Override + public void update(String key, Object val) { + DataSegmentKey dataSegmentKey = getDataSegmentKey(key); + Command cmd = new Command(CommandType.UPDATE, null, key, val, 0, 0, null, null, reverseKey); + dataSegmentKey.runCommand(cmd); + if (logger.isDebugEnabled()) + logger.debug(cmd.getCommandString()); + } + + @Override + public void quickUpdate(String key, Object val) { + update(key, val); + } + + @Override + public void take(Receiver receiver, CodeSegment cs) { + DataSegmentKey dataSegmentKey = getDataSegmentKey(receiver.key); + int seq = this.seq.getAndIncrement(); + Command cmd = new Command(CommandType.TAKE, receiver, receiver.key, null, receiver.index, seq, replyQueue, cs, null); + dataSegmentKey.runCommand(cmd); + if (logger.isDebugEnabled()) + logger.debug(cmd.getCommandString()); + } + + @Override + public void quickTake(Receiver receiver, CodeSegment cs) { + take(receiver, cs); + } + + @Override + public void peek(Receiver receiver, CodeSegment cs) { + DataSegmentKey dataSegmentKey = getDataSegmentKey(receiver.key); + int seq = this.seq.getAndIncrement(); + Command cmd = new Command(CommandType.PEEK, receiver, receiver.key, null, receiver.index, seq, replyQueue, cs, null); + dataSegmentKey.runCommand(cmd); + if (logger.isDebugEnabled()) + logger.debug(cmd.getCommandString()); + } - @Override - public void quickTake(Receiver receiver, CodeSegment cs) { - take(receiver, cs); - } - - @Override - public void peek(Receiver receiver, CodeSegment cs) { - DataSegmentKey dataSegmentKey = getDataSegmentKey(receiver.key); - int seq = this.seq.getAndIncrement(); - Command cmd = new Command(CommandType.PEEK, receiver, receiver.key, null, receiver.index, seq, replyQueue, cs, null); - dataSegmentKey.runCommand(cmd); - if (logger.isDebugEnabled()) - logger.debug(cmd.getCommandString()); - } - - @Override - public void quickPeek(Receiver receiver, CodeSegment cs) { - peek(receiver, cs); - } + @Override + public void quickPeek(Receiver receiver, CodeSegment cs) { + peek(receiver, cs); + } + + @Override + public void remove(String key) { + DataSegmentKey dataSegmentKey = getDataSegmentKey(key); + Command cmd = new Command(CommandType.REMOVE, null, key, null, 0, 0, replyQueue, null, null); + dataSegmentKey.runCommand(cmd); + if (logger.isDebugEnabled()) + logger.debug(cmd.getCommandString()); + } + + @Override public void finish() { + System.exit(0); + } + + @Override + public void close() { + + } - @Override - public void remove(String key) { - DataSegmentKey dataSegmentKey = getDataSegmentKey(key); - Command cmd = new Command(CommandType.REMOVE, null, key, null, 0, 0, replyQueue, null, null); - dataSegmentKey.runCommand(cmd); - if (logger.isDebugEnabled()) - logger.debug(cmd.getCommandString()); - } - - @Override public void finish() { - System.exit(0); - } + public void recommand(Receiver receiver, CodeSegment cs) { + DataSegmentKey dataSegmentKey = getDataSegmentKey(receiver.key); + int seq = this.seq.getAndIncrement(); + Command cmd = new Command(receiver.type, receiver, receiver.key, null, receiver.index, seq, replyQueue, cs, null); + dataSegmentKey.runCommand(cmd); + if (logger.isDebugEnabled()) + logger.debug(cmd.getCommandString()); - @Override - public void close() { - - } + } - public void recommand(Receiver receiver, CodeSegment cs) { - DataSegmentKey dataSegmentKey = getDataSegmentKey(receiver.key); - int seq = this.seq.getAndIncrement(); - Command cmd = new Command(receiver.type, receiver, receiver.key, null, receiver.index, seq, replyQueue, cs, null); - dataSegmentKey.runCommand(cmd); - if (logger.isDebugEnabled()) - logger.debug(cmd.getCommandString()); - - } + @Override + public void ping(String returnKey) { + + } - @Override - public void ping(String returnKey) { - - } + @Override + public void response(String returnKey) { + + } - @Override - public void response(String returnKey) { - - } + @Override + public void shutdown() { - @Override - public void shutdown() { - - } + } }
--- a/src/main/java/alice/datasegment/MulticastDataSegmentManager.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/datasegment/MulticastDataSegmentManager.java Tue Jul 15 16:00:22 2014 +0900 @@ -16,52 +16,52 @@ import alice.daemon.OutboundTcpConnection; public class MulticastDataSegmentManager extends RemoteDataSegmentManager { - - public MulticastDataSegmentManager(String connectionKey ,final String MCASTADDR, final int port, final String nis) { - logger = Logger.getLogger(connectionKey); - InetAddress mAddr; - try { - mAddr = InetAddress.getByName(MCASTADDR); + + public MulticastDataSegmentManager(String connectionKey ,final String MCASTADDR, final int port, final String nis) { + logger = Logger.getLogger(connectionKey); + InetAddress mAddr; + try { + mAddr = InetAddress.getByName(MCASTADDR); + + DatagramChannel dcr = createDatagramChannel(mAddr, port, nis); + dcr.bind(new InetSocketAddress(port)); + SocketAddress sAddrr = new InetSocketAddress(mAddr,port); + MulticastConnection receiver = new MulticastConnection(dcr, sAddrr); - DatagramChannel dcr = createDatagramChannel(mAddr, port, nis); - dcr.bind(new InetSocketAddress(port)); - SocketAddress sAddrr = new InetSocketAddress(mAddr,port); - MulticastConnection receiver = new MulticastConnection(dcr, sAddrr); - - DatagramChannel dcs = createDatagramChannel(mAddr, port, nis); - SocketAddress sAddrs = new InetSocketAddress(mAddr,port); - connection = new MulticastConnection(dcs, sAddrs); // sender + DatagramChannel dcs = createDatagramChannel(mAddr, port, nis); + SocketAddress sAddrs = new InetSocketAddress(mAddr,port); + connection = new MulticastConnection(dcs, sAddrs); // sender + + new IncomingUdpConnection((MulticastConnection) connection, receiver, this).start(); + new OutboundTcpConnection(connection).start(); // OutboundUdpConnection sender + + } catch (Exception e) { + e.printStackTrace(); + } + + } - new IncomingUdpConnection((MulticastConnection) connection, receiver, this).start(); - new OutboundTcpConnection(connection).start(); // OutboundUdpConnection sender - - } catch (Exception e) { - e.printStackTrace(); - } - - } - - private DatagramChannel createDatagramChannel(InetAddress group, int port, String nis) { - DatagramChannel dc = null; - NetworkInterface ni; - try { - ni = NetworkInterface.getByName(nis); - if (ni==null) { - System.err.println("Can't open network interface "+nis); - throw new IOException(); - } - if (!ni.supportsMulticast()) { - System.err.println("Network interface does not support multicast"+nis); - throw new IOException(); - } - - dc = DatagramChannel.open(StandardProtocolFamily.INET); - dc.setOption(StandardSocketOptions.SO_REUSEADDR, true); - dc.setOption(StandardSocketOptions.IP_MULTICAST_IF, ni); - dc.join(group, ni); - } catch (Exception e) { - e.printStackTrace(); - } - return dc; - } + private DatagramChannel createDatagramChannel(InetAddress group, int port, String nis) { + DatagramChannel dc = null; + NetworkInterface ni; + try { + ni = NetworkInterface.getByName(nis); + if (ni==null) { + System.err.println("Can't open network interface "+nis); + throw new IOException(); + } + if (!ni.supportsMulticast()) { + System.err.println("Network interface does not support multicast"+nis); + throw new IOException(); + } + + dc = DatagramChannel.open(StandardProtocolFamily.INET); + dc.setOption(StandardSocketOptions.SO_REUSEADDR, true); + dc.setOption(StandardSocketOptions.IP_MULTICAST_IF, ni); + dc.join(group, ni); + } catch (Exception e) { + e.printStackTrace(); + } + return dc; + } }
--- a/src/main/java/alice/datasegment/ReceiveLocalData.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/datasegment/ReceiveLocalData.java Tue Jul 15 16:00:22 2014 +0900 @@ -9,47 +9,47 @@ import alice.datasegment.ReceiverData; public class ReceiveLocalData implements ReceiverData { - private Object obj; + private Object obj; - public ReceiveLocalData(Object obj2) { - this.obj = obj2; - } + public ReceiveLocalData(Object obj2) { + this.obj = obj2; + } - public String asString() { - return (String) obj; - } + public String asString() { + return (String) obj; + } - public int asInteger() { - return (Integer) obj; - } + public int asInteger() { + return (Integer) obj; + } - public Float asFloat() { - return (Float) obj; - } + public Float asFloat() { + return (Float) obj; + } - public ArrayValue asArray(){ - return (ArrayValue) obj; - } - - @SuppressWarnings("unchecked") - public <T> T asClass(Class<T> clazz) { - return (T) obj; + public ArrayValue asArray(){ + return (ArrayValue) obj; + } - } + @SuppressWarnings("unchecked") + public <T> T asClass(Class<T> clazz) { + return (T) obj; + + } - @Override - public Value getVal() { - try { - return SingletonMessage.getInstance().unconvert(obj); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } + @Override + public Value getVal() { + try { + return SingletonMessage.getInstance().unconvert(obj); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } - @Override - public Object getObj() { - return obj; - } + @Override + public Object getObj() { + return obj; + } }
--- a/src/main/java/alice/datasegment/ReceiveRemoteData.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/datasegment/ReceiveRemoteData.java Tue Jul 15 16:00:22 2014 +0900 @@ -9,61 +9,61 @@ import alice.codesegment.SingletonMessage; public class ReceiveRemoteData implements ReceiverData { - public Value val; + public Value val; - public ReceiveRemoteData() { - } + public ReceiveRemoteData() { + } - public ReceiveRemoteData(Value val2) { - this.val = val2; - } + public ReceiveRemoteData(Value val2) { + this.val = val2; + } - public String asString() { - if (val.getType() == ValueType.RAW) { - return val.asRawValue().getString(); - } - return null; - } + public String asString() { + if (val.getType() == ValueType.RAW) { + return val.asRawValue().getString(); + } + return null; + } - public int asInteger() { - if (val.getType() == ValueType.INTEGER) { - return val.asIntegerValue().getInt(); - } - return 0; - } + public int asInteger() { + if (val.getType() == ValueType.INTEGER) { + return val.asIntegerValue().getInt(); + } + return 0; + } - public Float asFloat() { - if (val.getType() == ValueType.FLOAT) { - return val.asFloatValue().getFloat(); - } - return 0.0f; - } + public Float asFloat() { + if (val.getType() == ValueType.FLOAT) { + return val.asFloatValue().getFloat(); + } + return 0.0f; + } + + public ArrayValue asArray(){ + if (val.getType() == ValueType.ARRAY){ + return val.asArrayValue(); + } + return null; + } - public ArrayValue asArray(){ - if (val.getType() == ValueType.ARRAY){ - return val.asArrayValue(); - } - return null; - } - - public <T> T asClass(Class<T> clazz) { - try { - return SingletonMessage.getInstance().convert(val, clazz); - } catch (IOException e) { - e.printStackTrace(); - } - return null; + public <T> T asClass(Class<T> clazz) { + try { + return SingletonMessage.getInstance().convert(val, clazz); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + + } - } - - @Override - public Value getVal() { - return val; - } + @Override + public Value getVal() { + return val; + } - @Override - public Object getObj() { - return val; - } - + @Override + public Object getObj() { + return val; + } + } \ No newline at end of file
--- a/src/main/java/alice/datasegment/ReceiverData.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/datasegment/ReceiverData.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,12 +5,12 @@ public interface ReceiverData { - public String asString(); - public int asInteger(); - public Float asFloat() ; - public ArrayValue asArray(); - public <T> T asClass(Class<T> clazz); - public Value getVal(); - public Object getObj(); - + public String asString(); + public int asInteger(); + public Float asFloat() ; + public ArrayValue asArray(); + public <T> T asClass(Class<T> clazz); + public Value getVal(); + public Object getObj(); + } \ No newline at end of file
--- a/src/main/java/alice/datasegment/RemoteDataSegmentManager.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/datasegment/RemoteDataSegmentManager.java Tue Jul 15 16:00:22 2014 +0900 @@ -12,151 +12,151 @@ import alice.daemon.OutboundTcpConnection; public class RemoteDataSegmentManager extends DataSegmentManager { - - Connection connection; - Logger logger; - - public RemoteDataSegmentManager(){} - - public RemoteDataSegmentManager(String connectionKey, final String reverseKey, final String hostName, final int port) { - logger = Logger.getLogger(connectionKey); - connection = new Connection(); - final RemoteDataSegmentManager manager = this; - new Thread(replyThread, "RemoteDataSegmentManager-" + connectionKey).start(); - new Thread("Connect-" + connectionKey) { - public void run() { - boolean connect = true; - do { - try { - SocketChannel sc = SocketChannel.open(new InetSocketAddress(hostName, port)); - connection.socket = sc.socket(); - connection.socket.setTcpNoDelay(true); - connect = false; - logger.info("Connect to " + connection.getInfoString()); - } catch (IOException e) { - try { - Thread.sleep(50); - } catch (InterruptedException e1) { - e1.printStackTrace(); - } - } - } while (connect); - new IncomingTcpConnection(connection, manager, reverseKey).start(); - new OutboundTcpConnection(connection).start(); - } - }.start(); - } - - /** - * send put command to target DataSegment - */ - @Override - public void put(String key, Object val) { - Command cmd = new Command(CommandType.PUT, null, key, val, 0, 0, null, null, null); - connection.sendCommand(cmd); // put command on the transmission thread - if (logger.isDebugEnabled()) - logger.debug(cmd.getCommandString()); - } - - @Override - public void quickPut(String key, Object val) { - Command cmd = new Command(CommandType.PUT, null, key, val, 0, 0, null, null, null); - connection.write(cmd); // put command is executed right now - if (logger.isDebugEnabled()) - logger.debug(cmd.getCommandString()); - } - - @Override - public void update(String key, Object val) { - Command cmd = new Command(CommandType.UPDATE, null, key, val, 0, 0, null, null, null); - connection.sendCommand(cmd); - if (logger.isDebugEnabled()) - logger.debug(cmd.getCommandString()); - } - - @Override - public void quickUpdate(String key, Object val) { - Command cmd = new Command(CommandType.UPDATE, null, key, val, 0, 0, null, null, null); - connection.write(cmd); - if (logger.isDebugEnabled()) - logger.debug(cmd.getCommandString()); - } + + Connection connection; + Logger logger; + + public RemoteDataSegmentManager(){} + + public RemoteDataSegmentManager(String connectionKey, final String reverseKey, final String hostName, final int port) { + logger = Logger.getLogger(connectionKey); + connection = new Connection(); + final RemoteDataSegmentManager manager = this; + new Thread(replyThread, "RemoteDataSegmentManager-" + connectionKey).start(); + new Thread("Connect-" + connectionKey) { + public void run() { + boolean connect = true; + do { + try { + SocketChannel sc = SocketChannel.open(new InetSocketAddress(hostName, port)); + connection.socket = sc.socket(); + connection.socket.setTcpNoDelay(true); + connect = false; + logger.info("Connect to " + connection.getInfoString()); + } catch (IOException e) { + try { + Thread.sleep(50); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + } + } while (connect); + new IncomingTcpConnection(connection, manager, reverseKey).start(); + new OutboundTcpConnection(connection).start(); + } + }.start(); + } + + /** + * send put command to target DataSegment + */ + @Override + public void put(String key, Object val) { + Command cmd = new Command(CommandType.PUT, null, key, val, 0, 0, null, null, null); + connection.sendCommand(cmd); // put command on the transmission thread + if (logger.isDebugEnabled()) + logger.debug(cmd.getCommandString()); + } + + @Override + public void quickPut(String key, Object val) { + Command cmd = new Command(CommandType.PUT, null, key, val, 0, 0, null, null, null); + connection.write(cmd); // put command is executed right now + if (logger.isDebugEnabled()) + logger.debug(cmd.getCommandString()); + } + + @Override + public void update(String key, Object val) { + Command cmd = new Command(CommandType.UPDATE, null, key, val, 0, 0, null, null, null); + connection.sendCommand(cmd); + if (logger.isDebugEnabled()) + logger.debug(cmd.getCommandString()); + } + + @Override + public void quickUpdate(String key, Object val) { + Command cmd = new Command(CommandType.UPDATE, null, key, val, 0, 0, null, null, null); + connection.write(cmd); + if (logger.isDebugEnabled()) + logger.debug(cmd.getCommandString()); + } - @Override - public void take(Receiver receiver, CodeSegment cs) { - int seq = this.seq.getAndIncrement(); - Command cmd = new Command(CommandType.TAKE, receiver, receiver.key, null, receiver.index, seq, replyQueue, cs, null); - seqHash.put(seq, cmd); - connection.sendCommand(cmd); - if (logger.isDebugEnabled()) - logger.debug(cmd.getCommandString()); - } - - public void quickTake(Receiver receiver, CodeSegment cs) { - int seq = this.seq.getAndIncrement(); - Command cmd = new Command(CommandType.TAKE, receiver, receiver.key, null, receiver.index, seq, replyQueue, cs, null, true); - seqHash.put(seq, cmd); - connection.write(cmd); - if (logger.isDebugEnabled()) - logger.debug(cmd.getCommandString()); - } + @Override + public void take(Receiver receiver, CodeSegment cs) { + int seq = this.seq.getAndIncrement(); + Command cmd = new Command(CommandType.TAKE, receiver, receiver.key, null, receiver.index, seq, replyQueue, cs, null); + seqHash.put(seq, cmd); + connection.sendCommand(cmd); + if (logger.isDebugEnabled()) + logger.debug(cmd.getCommandString()); + } + + public void quickTake(Receiver receiver, CodeSegment cs) { + int seq = this.seq.getAndIncrement(); + Command cmd = new Command(CommandType.TAKE, receiver, receiver.key, null, receiver.index, seq, replyQueue, cs, null, true); + seqHash.put(seq, cmd); + connection.write(cmd); + if (logger.isDebugEnabled()) + logger.debug(cmd.getCommandString()); + } + + @Override + public void peek(Receiver receiver, CodeSegment cs) { + int seq = this.seq.getAndIncrement(); + Command cmd = new Command(CommandType.PEEK, receiver, receiver.key, null, receiver.index, seq, replyQueue, cs, null); + seqHash.put(seq, cmd); + connection.sendCommand(cmd); + if (logger.isDebugEnabled()) + logger.debug(cmd.getCommandString()); + } + + public void quickPeek(Receiver receiver, CodeSegment cs) { + int seq = this.seq.getAndIncrement(); + Command cmd = new Command(CommandType.PEEK, receiver, receiver.key, null, receiver.index, seq, replyQueue, cs, null, true); + seqHash.put(seq, cmd); + connection.write(cmd); + if (logger.isDebugEnabled()) + logger.debug(cmd.getCommandString()); - @Override - public void peek(Receiver receiver, CodeSegment cs) { - int seq = this.seq.getAndIncrement(); - Command cmd = new Command(CommandType.PEEK, receiver, receiver.key, null, receiver.index, seq, replyQueue, cs, null); - seqHash.put(seq, cmd); - connection.sendCommand(cmd); - if (logger.isDebugEnabled()) - logger.debug(cmd.getCommandString()); - } - - public void quickPeek(Receiver receiver, CodeSegment cs) { - int seq = this.seq.getAndIncrement(); - Command cmd = new Command(CommandType.PEEK, receiver, receiver.key, null, receiver.index, seq, replyQueue, cs, null, true); - seqHash.put(seq, cmd); - connection.write(cmd); - if (logger.isDebugEnabled()) - logger.debug(cmd.getCommandString()); - - } + } - @Override - public void remove(String key) { - Command cmd = new Command(CommandType.REMOVE, null, key, null, 0, 0, null, null, null); - connection.sendCommand(cmd); - if (logger.isDebugEnabled()) - logger.debug(cmd.getCommandString()); - } + @Override + public void remove(String key) { + Command cmd = new Command(CommandType.REMOVE, null, key, null, 0, 0, null, null, null); + connection.sendCommand(cmd); + if (logger.isDebugEnabled()) + logger.debug(cmd.getCommandString()); + } + + @Override + public void finish() { + Command cmd = new Command(CommandType.FINISH, null, null, null, 0, 0, null, null, null); + connection.sendCommand(cmd); + } - @Override - public void finish() { - Command cmd = new Command(CommandType.FINISH, null, null, null, 0, 0, null, null, null); - connection.sendCommand(cmd); - } + @Override + public void ping(String returnKey) { + Command cmd = new Command(CommandType.PING, null, returnKey, null, 0, 0, null, null, null); + connection.write(cmd); + } - @Override - public void ping(String returnKey) { - Command cmd = new Command(CommandType.PING, null, returnKey, null, 0, 0, null, null, null); - connection.write(cmd); - } - - @Override - public void response(String returnKey) { - Command cmd = new Command(CommandType.RESPONSE, null, returnKey, null, 0, 0, null, null, null); - connection.write(cmd); - } + @Override + public void response(String returnKey) { + Command cmd = new Command(CommandType.RESPONSE, null, returnKey, null, 0, 0, null, null, null); + connection.write(cmd); + } - @Override - public void close() { - Command cmd = new Command(CommandType.CLOSE, null, null, null, 0, 0, null, null, null); - connection.sendCommand(cmd); - } - - @Override - public void shutdown() { - connection.close(); - } + @Override + public void close() { + Command cmd = new Command(CommandType.CLOSE, null, null, null, 0, 0, null, null, null); + connection.sendCommand(cmd); + } + + @Override + public void shutdown() { + connection.close(); + } }
--- a/src/main/java/alice/test/codesegment/api/FlipCodeSegment.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/api/FlipCodeSegment.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,19 +3,19 @@ import alice.codesegment.CodeSegment; public class FlipCodeSegment extends CodeSegment{ - - private String key; - public FlipCodeSegment(String _key){ - this.key = _key; - } - - @Override - public void run() { - Integer num = 0; - ods.put(key, num); - - //System.out.println("Key is " +key); - new FlipTest(key); - } - + + private String key; + public FlipCodeSegment(String _key){ + this.key = _key; + } + + @Override + public void run() { + Integer num = 0; + ods.put(key, num); + + //System.out.println("Key is " +key); + new FlipTest(key); + } + }
--- a/src/main/java/alice/test/codesegment/api/FlipTest.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/api/FlipTest.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,34 +5,34 @@ import alice.datasegment.Receiver; public class FlipTest extends CodeSegment{ - - private Receiver arg1 = ids.create(CommandType.PEEK); - public static long t = 0; - public static boolean flag = false; - public static int count = 10000; - public FlipTest(String key){ - arg1.setKey(key); - } - - public FlipTest(String key, int index){ - arg1.setKey(key, index); - } + + private Receiver arg1 = ids.create(CommandType.PEEK); + public static long t = 0; + public static boolean flag = false; + public static int count = 10000; + public FlipTest(String key){ + arg1.setKey(key); + } + + public FlipTest(String key, int index){ + arg1.setKey(key, index); + } - @Override - public void run() { - if(flag){ - System.out.println(System.currentTimeMillis() - t +" ms"); - System.exit(0); - } - t = System.currentTimeMillis(); - for (int i=0;i<count;i++) - ods.flip(arg1); - //ods.put(arg1.key ,arg1.getObj()); - flag=true; + @Override + public void run() { + if(flag){ + System.out.println(System.currentTimeMillis() - t +" ms"); + System.exit(0); + } + t = System.currentTimeMillis(); + for (int i=0;i<count;i++) + ods.flip(arg1); + //ods.put(arg1.key ,arg1.getObj()); + flag=true; - new FlipTest(arg1.key,count); - - } + new FlipTest(arg1.key,count); + + } }
--- a/src/main/java/alice/test/codesegment/api/PeekCodeSegment.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/api/PeekCodeSegment.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,25 +5,25 @@ import alice.datasegment.Receiver; public class PeekCodeSegment extends CodeSegment{ - private Receiver info0 = ids.create(CommandType.PEEK); - public PeekCodeSegment(String key) { - info0.setKey(key); - } + private Receiver info0 = ids.create(CommandType.PEEK); + public PeekCodeSegment(String key) { + info0.setKey(key); + } - @Override - public void run() { - if (StartCodeSegment.count>10000){ - System.out.println(System.currentTimeMillis()-StartCodeSegment.t +" ms"); - StartCodeSegment.count = 0; - - if (++StartCodeSegment.cnt>100){ - System.exit(0); - } - } else { - if(StartCodeSegment.count==1)StartCodeSegment.t = System.currentTimeMillis(); - StartCodeSegment.count++; - } - new PeekCodeSegment(info0.key); - } + @Override + public void run() { + if (StartCodeSegment.count>10000){ + System.out.println(System.currentTimeMillis()-StartCodeSegment.t +" ms"); + StartCodeSegment.count = 0; + + if (++StartCodeSegment.cnt>100){ + System.exit(0); + } + } else { + if(StartCodeSegment.count==1)StartCodeSegment.t = System.currentTimeMillis(); + StartCodeSegment.count++; + } + new PeekCodeSegment(info0.key); + } }
--- a/src/main/java/alice/test/codesegment/api/PutCodeSegment.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/api/PutCodeSegment.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,30 +3,30 @@ import alice.codesegment.CodeSegment; public class PutCodeSegment extends CodeSegment{ - - private static int count = 0; - - @Override - public synchronized void run() { - - int[] array = new int[1000]; - for (int i = 0;i< 999; i++) - array[i] = i; - - if (count % 10 == 0) - System.out.println((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "MB"); - if (count >= 10000000) { - System.exit(0); - } - ods.put("local", "num", array); - count++; - try { - wait(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - new PutCodeSegment().execute(); - } - + + private static int count = 0; + + @Override + public synchronized void run() { + + int[] array = new int[1000]; + for (int i = 0;i< 999; i++) + array[i] = i; + + if (count % 10 == 0) + System.out.println((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "MB"); + if (count >= 10000000) { + System.exit(0); + } + ods.put("local", "num", array); + count++; + try { + wait(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + new PutCodeSegment().execute(); + } + }
--- a/src/main/java/alice/test/codesegment/api/StartCodeSegment.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/api/StartCodeSegment.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,49 +6,49 @@ import alice.test.codesegment.local.bitonicsort.DataList; public class StartCodeSegment extends CodeSegment { - String[] args; - public static int count = 1; - public static int cnt = 1; - public static long t = 0; - - - public StartCodeSegment(String[] args){ - this.args = args; - } + String[] args; + public static int count = 1; + public static int cnt = 1; + public static long t = 0; + + + public StartCodeSegment(String[] args){ + this.args = args; + } - @Override - public void run() { - for (String arg : args) { - if ("-update".equals(arg)) { - UpdateCodeSegment cs1 = new UpdateCodeSegment(); - cs1.ds1.setKey("key"); - int[] array = new int[65536]; - array[0] = 0; - ods.update("local", "key", array); + @Override + public void run() { + for (String arg : args) { + if ("-update".equals(arg)) { + UpdateCodeSegment cs1 = new UpdateCodeSegment(); + cs1.ds1.setKey("key"); + int[] array = new int[65536]; + array[0] = 0; + ods.update("local", "key", array); - } else if ("-put".equals(arg)) { - new PutCodeSegment().execute(); + } else if ("-put".equals(arg)) { + new PutCodeSegment().execute(); - } else if ("-take".equals(arg)) { - new PutCodeSegment().execute(); - new TakeCodeSegment("num"); + } else if ("-take".equals(arg)) { + new PutCodeSegment().execute(); + new TakeCodeSegment("num"); - } else if ("-flip".equals(arg)) { - new FlipCodeSegment("key").execute(); - } else if ("-peek".equals(arg)) { - System.out.println("start peek Test"); - String key = "peek"; - int size = 100000; - DataList list = new DataList(size); - Random rnd = new Random(); - for (int cnt = 0; cnt < size; cnt++) { - list.table[cnt] = rnd.nextInt(100000) + 10; - } - ods.put(key, list); - new PeekCodeSegment(key); - } - } - - } + } else if ("-flip".equals(arg)) { + new FlipCodeSegment("key").execute(); + } else if ("-peek".equals(arg)) { + System.out.println("start peek Test"); + String key = "peek"; + int size = 100000; + DataList list = new DataList(size); + Random rnd = new Random(); + for (int cnt = 0; cnt < size; cnt++) { + list.table[cnt] = rnd.nextInt(100000) + 10; + } + ods.put(key, list); + new PeekCodeSegment(key); + } + } + + } }
--- a/src/main/java/alice/test/codesegment/api/TakeCodeSegment.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/api/TakeCodeSegment.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,15 +5,15 @@ import alice.datasegment.Receiver; public class TakeCodeSegment extends CodeSegment { - - Receiver ds1 = ids.create(CommandType.TAKE); - - public TakeCodeSegment(String key){ - this.ds1.setKey(key); - } - @Override - public void run() { - new TakeCodeSegment(ds1.key); - - } + + Receiver ds1 = ids.create(CommandType.TAKE); + + public TakeCodeSegment(String key){ + this.ds1.setKey(key); + } + @Override + public void run() { + new TakeCodeSegment(ds1.key); + + } }
--- a/src/main/java/alice/test/codesegment/api/TestApiAlice.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/api/TestApiAlice.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,12 +5,12 @@ public class TestApiAlice { - /** - * @param args - */ - public static void main(String[] args) { - new AliceDaemon(new Config(args)).listen(); - new StartCodeSegment(args).execute(); - } + /** + * @param args + */ + public static void main(String[] args) { + new AliceDaemon(new Config(args)).listen(); + new StartCodeSegment(args).execute(); + } }
--- a/src/main/java/alice/test/codesegment/api/UpdateCodeSegment.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/api/UpdateCodeSegment.java Tue Jul 15 16:00:22 2014 +0900 @@ -8,21 +8,21 @@ import alice.datasegment.Receiver; public class UpdateCodeSegment extends CodeSegment { - Receiver ds1 = ids.create(CommandType.PEEK); + Receiver ds1 = ids.create(CommandType.PEEK); - @Override - public void run() { - UpdateCodeSegment cs1 = new UpdateCodeSegment(); - cs1.ds1.setKey("key", ds1.index); - Value[] array = ((Value)ds1.getVal()).asArrayValue().getElementArray(); - int val = array[0].asIntegerValue().getInt(); - if (val % 10 == 0) - System.out.println((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "MB"); - if (val >= 10000000) { - System.exit(0); - } - array[0] = ValueFactory.createIntegerValue(val + 1); - ods.update("local", "key", array); - } + @Override + public void run() { + UpdateCodeSegment cs1 = new UpdateCodeSegment(); + cs1.ds1.setKey("key", ds1.index); + Value[] array = ((Value)ds1.getVal()).asArrayValue().getElementArray(); + int val = array[0].asIntegerValue().getInt(); + if (val % 10 == 0) + System.out.println((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "MB"); + if (val >= 10000000) { + System.exit(0); + } + array[0] = ValueFactory.createIntegerValue(val + 1); + ods.update("local", "key", array); + } }
--- a/src/main/java/alice/test/codesegment/local/SingletonTestCodeSegment.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/SingletonTestCodeSegment.java Tue Jul 15 16:00:22 2014 +0900 @@ -7,28 +7,28 @@ import alice.datasegment.Receiver; public class SingletonTestCodeSegment extends CodeSegment { - Receiver arg1 = ids.create(CommandType.PEEK); - private static SingletonTestCodeSegment instance = new SingletonTestCodeSegment(); - private SingletonTestCodeSegment(){} - - public static SingletonTestCodeSegment getInstance(){ - return instance; - } - - @Override - public void run() { - System.out.println("type = " + arg1.type); - System.out.println("index = " + arg1.index); - System.out.println("data = " + arg1.getVal()); - System.out.println(((Value)arg1.getVal()).getType()); - - if (arg1.index == 10) { - System.exit(0); - return; - } - - this.recycle(); - ods.update("local", "key2", "String data"); - } + Receiver arg1 = ids.create(CommandType.PEEK); + private static SingletonTestCodeSegment instance = new SingletonTestCodeSegment(); + private SingletonTestCodeSegment(){} + + public static SingletonTestCodeSegment getInstance(){ + return instance; + } + + @Override + public void run() { + System.out.println("type = " + arg1.type); + System.out.println("index = " + arg1.index); + System.out.println("data = " + arg1.getVal()); + System.out.println(((Value)arg1.getVal()).getType()); + + if (arg1.index == 10) { + System.exit(0); + return; + } + + this.recycle(); + ods.update("local", "key2", "String data"); + } }
--- a/src/main/java/alice/test/codesegment/local/StartCodeSegment.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/StartCodeSegment.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,17 +4,17 @@ public class StartCodeSegment extends CodeSegment { - @Override - public void run() { - System.out.println("run StartCodeSegment"); - - TestCodeSegment cs = new TestCodeSegment(); - cs.arg1.setKey("key1"); // unbound datasegment key1 is created and connect to cs. - // cs is waiting for local.key1 - System.out.println("create TestCodeSegment"); - - ods.update("local", "key1", "String data"); // bind string data to datasegment local.key1 - // this startup TestCodeSegment. - } + @Override + public void run() { + System.out.println("run StartCodeSegment"); + + TestCodeSegment cs = new TestCodeSegment(); + cs.arg1.setKey("key1"); // unbound datasegment key1 is created and connect to cs. + // cs is waiting for local.key1 + System.out.println("create TestCodeSegment"); + + ods.update("local", "key1", "String data"); // bind string data to datasegment local.key1 + // this startup TestCodeSegment. + } }
--- a/src/main/java/alice/test/codesegment/local/TestCodeSegment.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/TestCodeSegment.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,27 +6,27 @@ import org.msgpack.type.Value; public class TestCodeSegment extends CodeSegment { - - // create input datasegment arg1 - Receiver arg1 = ids.create(CommandType.PEEK); - - @Override - public void run() { - System.out.println("type = " + arg1.type); - System.out.println("index = " + arg1.index); - System.out.println("data = " + arg1.getVal()); - System.out.println(((Value)arg1.getVal()).getType()); - - if (arg1.index == 10) { - System.exit(0); - return; - } - - TestCodeSegment cs = new TestCodeSegment(); - cs.arg1.setKey("key1", arg1.index); - - // DataSegment.get("local").update - ods.update("local", "key1", "String data"); - } + + // create input datasegment arg1 + Receiver arg1 = ids.create(CommandType.PEEK); + + @Override + public void run() { + System.out.println("type = " + arg1.type); + System.out.println("index = " + arg1.index); + System.out.println("data = " + arg1.getVal()); + System.out.println(((Value)arg1.getVal()).getType()); + + if (arg1.index == 10) { + System.exit(0); + return; + } + + TestCodeSegment cs = new TestCodeSegment(); + cs.arg1.setKey("key1", arg1.index); + + // DataSegment.get("local").update + ods.update("local", "key1", "String data"); + } }
--- a/src/main/java/alice/test/codesegment/local/TestLocalAlice.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/TestLocalAlice.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,9 +4,9 @@ import alice.daemon.Config; public class TestLocalAlice { - public static void main(String args[]) { - new AliceDaemon(new Config(args)).listen(); // logger off - new StartCodeSegment().execute(); - } - + public static void main(String args[]) { + new AliceDaemon(new Config(args)).listen(); // logger off + new StartCodeSegment().execute(); + } + }
--- a/src/main/java/alice/test/codesegment/local/bitonicsort/DataInfo.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/DataInfo.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,13 +4,13 @@ @Message public class DataInfo { - public int index; - public int ptr; - - public DataInfo(){} - - public DataInfo(int _index, int _ptr){ - index = _index; - ptr = _ptr; - } + public int index; + public int ptr; + + public DataInfo(){} + + public DataInfo(int _index, int _ptr){ + index = _index; + ptr = _ptr; + } }
--- a/src/main/java/alice/test/codesegment/local/bitonicsort/DataList.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/DataList.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,59 +5,59 @@ @Message public class DataList { - public int[] table; - - public DataList(int size){ - table = new int[size]; - } - - public DataList(int[] numbers){ - table = numbers; - } - - public DataList createDataList(int start, int size){ - int[] table2 = new int[size]; - int end = start+size; - for (int i=start,j=0;i<end;i++,j++){ - table2[j] = table[i]; - } - return new DataList(table2); - } - - public void swap(int i, int j){ - int tmp = table[i]; - table[i] = table[j]; - table[j] = tmp; - } - - public void showData(){ - for (int aTable : table) { - System.out.print(aTable + " "); - } - System.out.println(); - } - - public void showData(int range){ - for(int i = 0;i<range;i++){ - System.out.print(table[i]+ " "); - - } - System.out.println(); - } - - public void showSize(){ - System.out.print("size is "+this.table.length+". "); - } - - public int getSize(){ - return this.table.length; - } + public int[] table; + + public DataList(int size){ + table = new int[size]; + } + + public DataList(int[] numbers){ + table = numbers; + } + + public DataList createDataList(int start, int size){ + int[] table2 = new int[size]; + int end = start+size; + for (int i=start,j=0;i<end;i++,j++){ + table2[j] = table[i]; + } + return new DataList(table2); + } + + public void swap(int i, int j){ + int tmp = table[i]; + table[i] = table[j]; + table[j] = tmp; + } - public static void merge(DataList list1, DataList list2) { - int[] t1 = list1.table; - int[] t2 = list2.table; - int[] t0 = list1.table.clone(); // copy to avoid destroy t1 - int i = 0, j= 0,n=0; + public void showData(){ + for (int aTable : table) { + System.out.print(aTable + " "); + } + System.out.println(); + } + + public void showData(int range){ + for(int i = 0;i<range;i++){ + System.out.print(table[i]+ " "); + + } + System.out.println(); + } + + public void showSize(){ + System.out.print("size is "+this.table.length+". "); + } + + public int getSize(){ + return this.table.length; + } + + public static void merge(DataList list1, DataList list2) { + int[] t1 = list1.table; + int[] t2 = list2.table; + int[] t0 = list1.table.clone(); // copy to avoid destroy t1 + int i = 0, j= 0,n=0; while (i< t0.length) { if (n>=t1.length) { // switch to the second list t1 = t2; n = 0; @@ -70,6 +70,6 @@ j++; n++; } } - } - + } + }
--- a/src/main/java/alice/test/codesegment/local/bitonicsort/LocalBitonicSort.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/LocalBitonicSort.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,10 +4,10 @@ import alice.daemon.Config; public class LocalBitonicSort { - public static void main(String[] args){ - new AliceDaemon(new Config(args)).listen(); // logger off - - SortConfig conf = new SortConfig(args); - new SetInfo(conf).execute(); - } + public static void main(String[] args){ + new AliceDaemon(new Config(args)).listen(); // logger off + + SortConfig conf = new SortConfig(args); + new SetInfo(conf).execute(); + } }
--- a/src/main/java/alice/test/codesegment/local/bitonicsort/MakeData.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/MakeData.java Tue Jul 15 16:00:22 2014 +0900 @@ -7,25 +7,25 @@ import alice.datasegment.Receiver; public class MakeData extends CodeSegment { - - private Receiver info1 = ids.create(CommandType.PEEK); - private Receiver info2 = ids.create(CommandType.TAKE); + + private Receiver info1 = ids.create(CommandType.PEEK); + private Receiver info2 = ids.create(CommandType.TAKE); + + public MakeData(){ + info1.setKey("sortconf"); + info2.setKey("data"); + } - public MakeData(){ - info1.setKey("sortconf"); - info2.setKey("data"); - } - - @Override - public void run() { - // This conversion over head should be remove. - SortConfig conf = info1.asClass(SortConfig.class); - DataList list = info2.asClass(DataList.class); - int size = conf.getLength(); - Random rnd = new Random(); - for (int i = 0; i < size; i++){ - list.table[i] = rnd.nextInt(100000)+10; - } - ods.update("list", list); - } + @Override + public void run() { + // This conversion over head should be remove. + SortConfig conf = info1.asClass(SortConfig.class); + DataList list = info2.asClass(DataList.class); + int size = conf.getLength(); + Random rnd = new Random(); + for (int i = 0; i < size; i++){ + list.table[i] = rnd.nextInt(100000)+10; + } + ods.update("list", list); + } }
--- a/src/main/java/alice/test/codesegment/local/bitonicsort/RangeInfo.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/RangeInfo.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,13 +4,13 @@ @Message public class RangeInfo { - public int range; - public boolean lastFlag; - - public RangeInfo(){} - public RangeInfo(int i,boolean flag){ - range = i; - lastFlag = flag; - } + public int range; + public boolean lastFlag; + + public RangeInfo(){} + public RangeInfo(int i,boolean flag){ + range = i; + lastFlag = flag; + } }
--- a/src/main/java/alice/test/codesegment/local/bitonicsort/SetInfo.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/SetInfo.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,37 +4,37 @@ public class SetInfo extends CodeSegment { - private SortConfig conf; - public static String[] range; - public static String[] array; - public static String[] count; - - public SetInfo(SortConfig conf) { - this.conf = conf; - } + private SortConfig conf; + public static String[] range; + public static String[] array; + public static String[] count; + + public SetInfo(SortConfig conf) { + this.conf = conf; + } + + @Override + public void run() { + ods.put("sortconf", conf); + ods.put("data", new DataList(conf.length)); + // sortconf and datasegments should be passed directory. - @Override - public void run() { - ods.put("sortconf", conf); - ods.put("data", new DataList(conf.length)); - // sortconf and datasegments should be passed directory. - - create_keys(); - new MakeData(); - new SetTask(); - } + create_keys(); + new MakeData(); + new SetTask(); + } + + private void create_keys() { + range = new String[conf.length]; + array = new String[conf.length]; + count = new String[conf.length]; - private void create_keys() { - range = new String[conf.length]; - array = new String[conf.length]; - count = new String[conf.length]; - - for(int i = 0 ; i < conf.length ; i++) { - range[i] = "range" + i; - array[i] = "array" + i; - count[i] = "count" + i; - } - - } - + for(int i = 0 ; i < conf.length ; i++) { + range[i] = "range" + i; + array[i] = "array" + i; + count[i] = "count" + i; + } + + } + }
--- a/src/main/java/alice/test/codesegment/local/bitonicsort/SetTask.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/SetTask.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,44 +5,44 @@ import alice.datasegment.Receiver; public class SetTask extends CodeSegment { - public static long t; - private Receiver info1 = ids.create(CommandType.PEEK); - private Receiver info2 = ids.create(CommandType.TAKE); - - SetTask(){ - info1.setKey("sortconf"); - info2.setKey("list"); - } - - @Override - public void run() { - SortConfig conf = info1.asClass(SortConfig.class); - DataList list = info2.asClass(DataList.class); - - int sort_count = conf.getSplitNum()*2; - ods.put("sort_count", sort_count*2); - - int block_num = (conf.getLength() + sort_count- 1) / sort_count; - ods.put("block_num", block_num); - - System.out.println("sort start"); - t = System.currentTimeMillis(); - { - int i; - for (i = 0; i < sort_count / 2; i++) { - // anonymous datasegmaents should be used. - ods.put(SetInfo.range[i], new RangeInfo(i,i==(sort_count/2)-1)); - ods.update(SetInfo.array[i*2], list.createDataList(i*2*block_num, block_num)); - ods.update(SetInfo.array[i*2+1], list.createDataList((i*2+1)*block_num, block_num)); - ods.update(SetInfo.count[i], 0); - new SortPhase(SetInfo.range[i],SetInfo.array[i*2],SetInfo.array[i*2+1],0,SetInfo.count[i]); - - } - new ShowData(i*2, sort_count); - - } - - - } + public static long t; + private Receiver info1 = ids.create(CommandType.PEEK); + private Receiver info2 = ids.create(CommandType.TAKE); + + SetTask(){ + info1.setKey("sortconf"); + info2.setKey("list"); + } + + @Override + public void run() { + SortConfig conf = info1.asClass(SortConfig.class); + DataList list = info2.asClass(DataList.class); + + int sort_count = conf.getSplitNum()*2; + ods.put("sort_count", sort_count*2); + + int block_num = (conf.getLength() + sort_count- 1) / sort_count; + ods.put("block_num", block_num); + + System.out.println("sort start"); + t = System.currentTimeMillis(); + { + int i; + for (i = 0; i < sort_count / 2; i++) { + // anonymous datasegmaents should be used. + ods.put(SetInfo.range[i], new RangeInfo(i,i==(sort_count/2)-1)); + ods.update(SetInfo.array[i*2], list.createDataList(i*2*block_num, block_num)); + ods.update(SetInfo.array[i*2+1], list.createDataList((i*2+1)*block_num, block_num)); + ods.update(SetInfo.count[i], 0); + new SortPhase(SetInfo.range[i],SetInfo.array[i*2],SetInfo.array[i*2+1],0,SetInfo.count[i]); + + } + new ShowData(i*2, sort_count); + + } + + + } }
--- a/src/main/java/alice/test/codesegment/local/bitonicsort/ShowData.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/ShowData.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,39 +5,39 @@ import alice.datasegment.Receiver; public class ShowData extends CodeSegment{ - - private Receiver[] info; - - public ShowData(int cnt, int index) { - info = new Receiver[cnt]; - for (int i= 0;i < cnt; i++) - info[i] = ids.create(CommandType.PEEK); - for (int i= 0;i < cnt; i++) - info[i].setKey(SetInfo.array[i],index); - - } - - @Override - public void run() { - System.out.println(System.currentTimeMillis() -SetTask.t +" ms"); - int size = 0; - for (Receiver anInfo : info) { - DataList dlist = anInfo.asClass(DataList.class); - size += dlist.table.length; - } - - DataList list = new DataList(size); - - int start = 0; - for (Receiver anInfo : info) { - DataList dlist = anInfo.asClass(DataList.class); - System.arraycopy(dlist.table, 0, list.table, start, dlist.table.length); - start += dlist.table.length; - } - System.out.println("size check :"+ list.table.length); - Sort.check(list); - System.exit(0); - } - - + + private Receiver[] info; + + public ShowData(int cnt, int index) { + info = new Receiver[cnt]; + for (int i= 0;i < cnt; i++) + info[i] = ids.create(CommandType.PEEK); + for (int i= 0;i < cnt; i++) + info[i].setKey(SetInfo.array[i],index); + + } + + @Override + public void run() { + System.out.println(System.currentTimeMillis() -SetTask.t +" ms"); + int size = 0; + for (Receiver anInfo : info) { + DataList dlist = anInfo.asClass(DataList.class); + size += dlist.table.length; + } + + DataList list = new DataList(size); + + int start = 0; + for (Receiver anInfo : info) { + DataList dlist = anInfo.asClass(DataList.class); + System.arraycopy(dlist.table, 0, list.table, start, dlist.table.length); + start += dlist.table.length; + } + System.out.println("size check :"+ list.table.length); + Sort.check(list); + System.exit(0); + } + + }
--- a/src/main/java/alice/test/codesegment/local/bitonicsort/Sort.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/Sort.java Tue Jul 15 16:00:22 2014 +0900 @@ -1,63 +1,63 @@ package alice.test.codesegment.local.bitonicsort; public class Sort { - - // this method has "stack overflow" problem - public static void quickSort(DataList data){ - int[] stack = new int[8192]; - int sp = 0; - int begin = 0; - int end = data.table.length-1; // index is up to length-1 - while(true){ - while(begin < end){ - if (end-begin< 40){ - bubbleSort(data,begin,end); - break; - } else { - int where = (begin+end)/2; - int pivot = data.table[where]; - data.table[where] = data.table[begin]; - int p = begin; - for (int i=begin+1;i<=end;i++){ - if (data.table[i]<pivot){ - p++; - if (i!=p)data.swap(p,i); - } - } - data.table[begin] = data.table[p]; - data.table[p] = pivot; - stack[sp++] = p+1; - stack[sp++] = end; - end=p-1; - } - } - if (sp==0) return; - end = stack[--sp]; - begin = stack[--sp]; - - } - } - - public static void bubbleSort(DataList data ,int begin,int end){ - for (int i=begin;i<end;i++){ - for (int j=end;j>i;j--){ - if (data.table[i] > data.table[j]){ - data.swap(i,j); - } - } - } - - - } - - public static void check(DataList data){ - System.out.println("checking ...."); - for (int i = 0; i< data.table.length-1; i++){ - if (data.table[i] > data.table[i+1]){ - System.out.println("MISS "+data.table[i]+" > "+data.table[i+1]+" Position is "+i); - return; - } - } - System.out.println("sort is succeed"); - } + + // this method has "stack overflow" problem + public static void quickSort(DataList data){ + int[] stack = new int[8192]; + int sp = 0; + int begin = 0; + int end = data.table.length-1; // index is up to length-1 + while(true){ + while(begin < end){ + if (end-begin< 40){ + bubbleSort(data,begin,end); + break; + } else { + int where = (begin+end)/2; + int pivot = data.table[where]; + data.table[where] = data.table[begin]; + int p = begin; + for (int i=begin+1;i<=end;i++){ + if (data.table[i]<pivot){ + p++; + if (i!=p)data.swap(p,i); + } + } + data.table[begin] = data.table[p]; + data.table[p] = pivot; + stack[sp++] = p+1; + stack[sp++] = end; + end=p-1; + } + } + if (sp==0) return; + end = stack[--sp]; + begin = stack[--sp]; + + } + } + + public static void bubbleSort(DataList data ,int begin,int end){ + for (int i=begin;i<end;i++){ + for (int j=end;j>i;j--){ + if (data.table[i] > data.table[j]){ + data.swap(i,j); + } + } + } + + + } + + public static void check(DataList data){ + System.out.println("checking ...."); + for (int i = 0; i< data.table.length-1; i++){ + if (data.table[i] > data.table[i+1]){ + System.out.println("MISS "+data.table[i]+" > "+data.table[i+1]+" Position is "+i); + return; + } + } + System.out.println("sort is succeed"); + } }
--- a/src/main/java/alice/test/codesegment/local/bitonicsort/SortConfig.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/SortConfig.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,36 +4,36 @@ @Message public class SortConfig { - public int length = 1200; - public int MAX_BLOCK_SIZE = 1024; - public int cpu = 1; - - public SortConfig(){} - - public SortConfig(String[] args){ - for (int i=0;i<args.length; i++){ - if ("-l".equals(args[i])){ - length = Integer.parseInt(args[++i]); - } else if ("-b".equals(args[i])){ - MAX_BLOCK_SIZE = Integer.parseInt(args[++i]); - } - } - if (length<MAX_BLOCK_SIZE) MAX_BLOCK_SIZE = length; - } + public int length = 1200; + public int MAX_BLOCK_SIZE = 1024; + public int cpu = 1; + + public SortConfig(){} + + public SortConfig(String[] args){ + for (int i=0;i<args.length; i++){ + if ("-l".equals(args[i])){ + length = Integer.parseInt(args[++i]); + } else if ("-b".equals(args[i])){ + MAX_BLOCK_SIZE = Integer.parseInt(args[++i]); + } + } + if (length<MAX_BLOCK_SIZE) MAX_BLOCK_SIZE = length; + } - public int getLength() { - return length; - } + public int getLength() { + return length; + } + + public int getblockSize() { + return MAX_BLOCK_SIZE; + } - public int getblockSize() { - return MAX_BLOCK_SIZE; - } - - public int getSplitNum(){ - if (length / cpu < MAX_BLOCK_SIZE){ - return cpu; - } else { - return (length + MAX_BLOCK_SIZE -1) / MAX_BLOCK_SIZE; - } - } + public int getSplitNum(){ + if (length / cpu < MAX_BLOCK_SIZE){ + return cpu; + } else { + return (length + MAX_BLOCK_SIZE -1) / MAX_BLOCK_SIZE; + } + } }
--- a/src/main/java/alice/test/codesegment/local/bitonicsort/SortPhase.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/SortPhase.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,56 +5,56 @@ import alice.datasegment.Receiver; public class SortPhase extends CodeSegment{ - private Receiver info0 = ids.create(CommandType.PEEK); // range - private Receiver info1 = ids.create(CommandType.TAKE); // Array1 - private Receiver info2 = ids.create(CommandType.TAKE); // Array2 - private Receiver info3 = ids.create(CommandType.PEEK); // sort_count - private Receiver info4 = ids.create(CommandType.TAKE); // count - - - public SortPhase(String key0, String key1, String key2, int index, String key4){ - info0.setKey(key0); - info1.setKey(key1,index); - info2.setKey(key2,index); - info3.setKey("sort_count"); - info4.setKey(key4); - } - - @Override - public void run() { - RangeInfo info = info0.asClass(RangeInfo.class); - DataList list1 = info1.asClass(DataList.class); - DataList list2 = info2.asClass(DataList.class); - int sort_count = info3.asInteger(); - int count = info4.asInteger(); - - int i = info.range; - //System.out.println("CS"+i+" "+info1.key+" "+info2.key+" dataIndex "+info1.index +" count "+count); - Sort.quickSort(list1); - Sort.quickSort(list2); - DataList.merge(list1,list2); - - if (count%2==0&&i==0){ - ods.flip(info1); // first block index is less than others. So put data twice. - } else if (count%2==0&&info.lastFlag){ - ods.flip(info2); // Same reason - } - - ods.flip(info1); - ods.flip(info2); - - if (count%2==0&&info.lastFlag&&count+2<sort_count/2){ - new SortPhase(info0.key, info1.key, info2.key,count+2,info4.key); - ods.update(info4.key, count+2); - } else { - String f = (count%2==1) ? SetInfo.array[2*i] : SetInfo.array[2*i+1]; - String b = (count%2==1) ? SetInfo.array[2*i+1] : SetInfo.array[2*i+2]; - - new SortPhase(info0.key, f, b, count+1, info4.key); - ods.update(info4.key, count+1); - } - - - } - + private Receiver info0 = ids.create(CommandType.PEEK); // range + private Receiver info1 = ids.create(CommandType.TAKE); // Array1 + private Receiver info2 = ids.create(CommandType.TAKE); // Array2 + private Receiver info3 = ids.create(CommandType.PEEK); // sort_count + private Receiver info4 = ids.create(CommandType.TAKE); // count + + + public SortPhase(String key0, String key1, String key2, int index, String key4){ + info0.setKey(key0); + info1.setKey(key1,index); + info2.setKey(key2,index); + info3.setKey("sort_count"); + info4.setKey(key4); + } + + @Override + public void run() { + RangeInfo info = info0.asClass(RangeInfo.class); + DataList list1 = info1.asClass(DataList.class); + DataList list2 = info2.asClass(DataList.class); + int sort_count = info3.asInteger(); + int count = info4.asInteger(); + + int i = info.range; + //System.out.println("CS"+i+" "+info1.key+" "+info2.key+" dataIndex "+info1.index +" count "+count); + Sort.quickSort(list1); + Sort.quickSort(list2); + DataList.merge(list1,list2); + + if (count%2==0&&i==0){ + ods.flip(info1); // first block index is less than others. So put data twice. + } else if (count%2==0&&info.lastFlag){ + ods.flip(info2); // Same reason + } + + ods.flip(info1); + ods.flip(info2); + + if (count%2==0&&info.lastFlag&&count+2<sort_count/2){ + new SortPhase(info0.key, info1.key, info2.key,count+2,info4.key); + ods.update(info4.key, count+2); + } else { + String f = (count%2==1) ? SetInfo.array[2*i] : SetInfo.array[2*i+1]; + String b = (count%2==1) ? SetInfo.array[2*i+1] : SetInfo.array[2*i+2]; + + new SortPhase(info0.key, f, b, count+1, info4.key); + ods.update(info4.key, count+1); + } + + + } + }
--- a/src/main/java/alice/test/codesegment/local/bitonicsort/SortTest.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/SortTest.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,53 +3,53 @@ import java.util.Random; public class SortTest { - - public static void main(String args[]){ - int size1 = 1000000; - int size2 = 1000; - int MAX = 1000000; - long t; - DataList list1 = new DataList(size1); - DataList list2 = new DataList(size1); - DataList list3 = new DataList(size2); - - Random rnd = new Random(); - for (int i = 0; i < size1; i++){ - int num = rnd.nextInt(MAX)+10; - list1.table[i] = num; - list2.table[i] = num; - } - for (int i = 0; i < size2; i++){ - int num = rnd.nextInt(MAX)+10; - list3.table[i] = num; - } - - // bubbleSort - t = System.currentTimeMillis(); - Sort.bubbleSort(list3,0,list3.table.length-1); - System.out.println("bubble sort : "+ (System.currentTimeMillis()-t)+" ms"); - Sort.check(list3); - - // quickSort - t = System.currentTimeMillis(); - Sort.quickSort(list1); - System.out.println("quick sort1 : "+ (System.currentTimeMillis()-t)+" ms"); - Sort.check(list1); - - t = System.currentTimeMillis(); - Sort.quickSort(list2); - System.out.println("quick sort2 : "+ (System.currentTimeMillis()-t)+" ms"); - Sort.check(list2); - - // merge Test - DataList.merge(list1, list2); - Sort.check(list1); - Sort.check(list2); - - // separate Test - list1.showData(50); - list1.createDataList(0, 25).showSize(); - list1.createDataList(0, 25).showData(); - list1.createDataList(25, 25).showData(); - } + + public static void main(String args[]){ + int size1 = 1000000; + int size2 = 1000; + int MAX = 1000000; + long t; + DataList list1 = new DataList(size1); + DataList list2 = new DataList(size1); + DataList list3 = new DataList(size2); + + Random rnd = new Random(); + for (int i = 0; i < size1; i++){ + int num = rnd.nextInt(MAX)+10; + list1.table[i] = num; + list2.table[i] = num; + } + for (int i = 0; i < size2; i++){ + int num = rnd.nextInt(MAX)+10; + list3.table[i] = num; + } + + // bubbleSort + t = System.currentTimeMillis(); + Sort.bubbleSort(list3,0,list3.table.length-1); + System.out.println("bubble sort : "+ (System.currentTimeMillis()-t)+" ms"); + Sort.check(list3); + + // quickSort + t = System.currentTimeMillis(); + Sort.quickSort(list1); + System.out.println("quick sort1 : "+ (System.currentTimeMillis()-t)+" ms"); + Sort.check(list1); + + t = System.currentTimeMillis(); + Sort.quickSort(list2); + System.out.println("quick sort2 : "+ (System.currentTimeMillis()-t)+" ms"); + Sort.check(list2); + + // merge Test + DataList.merge(list1, list2); + Sort.check(list1); + Sort.check(list2); + + // separate Test + list1.showData(50); + list1.createDataList(0, 25).showSize(); + list1.createDataList(0, 25).showData(); + list1.createDataList(25, 25).showData(); + } }
--- a/src/main/java/alice/test/codesegment/local/wordcount/CorrectResult.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/wordcount/CorrectResult.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,31 +6,31 @@ public class CorrectResult extends CodeSegment{ - private Receiver[] array; - - public CorrectResult(int size) { - array = new Receiver[size]; - for (int i=0;i<size;i++){ - array[i] = ids.create(CommandType.TAKE); - } - for (int i=0;i<size;i++) - array[i].setKey("result"); - } + private Receiver[] array; + + public CorrectResult(int size) { + array = new Receiver[size]; + for (int i=0;i<size;i++){ + array[i] = ids.create(CommandType.TAKE); + } + for (int i=0;i<size;i++) + array[i].setKey("result"); + } - @Override - public void run() { - int line_num = 0; - int word_num = 0; - Result result; - for (Receiver anArray : array) { - result = anArray.asClass(Result.class); - line_num += result.line_num; - word_num += result.word_num; - } - System.out.println(System.currentTimeMillis() - StartWordCount.t); - System.out.println(line_num+" "+word_num); - System.exit(0); - - } + @Override + public void run() { + int line_num = 0; + int word_num = 0; + Result result; + for (Receiver anArray : array) { + result = anArray.asClass(Result.class); + line_num += result.line_num; + word_num += result.word_num; + } + System.out.println(System.currentTimeMillis() - StartWordCount.t); + System.out.println(line_num+" "+word_num); + System.exit(0); + + } }
--- a/src/main/java/alice/test/codesegment/local/wordcount/Range.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/wordcount/Range.java Tue Jul 15 16:00:22 2014 +0900 @@ -2,15 +2,15 @@ public class Range { - public char[] array; - public char nextchar; - - public Range(int size){ - this.array = new char[size]; - } + public char[] array; + public char nextchar; - public Range(char[] _array) { - this.array = _array; - } + public Range(int size){ + this.array = new char[size]; + } + + public Range(char[] _array) { + this.array = _array; + } }
--- a/src/main/java/alice/test/codesegment/local/wordcount/ReadFileTest.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/wordcount/ReadFileTest.java Tue Jul 15 16:00:22 2014 +0900 @@ -8,39 +8,39 @@ import java.io.InputStreamReader; public class ReadFileTest { - - public static void main(String[] args){ - WordConfig conf = new WordConfig(args); - BufferedReader br = null; - int i = 0; - try { - br= new BufferedReader( - new InputStreamReader( - new FileInputStream( - new File(conf.filename) - ))); - int size = 4; // Kbyte - - Range range = new Range(size); - int check = br.read(range.array); - for (;check!=-1;i++){ - - char[] array; - array = new char[size]; - check = br.read(array); - range.nextchar = array[0]; - System.out.print(range.array); // ods - System.out.println(range.nextchar); - range = new Range(array); - } - System.out.println(i); - } catch (FileNotFoundException e) { - System.out.println("file was not found"); - System.exit(1); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } + + public static void main(String[] args){ + WordConfig conf = new WordConfig(args); + BufferedReader br = null; + int i = 0; + try { + br= new BufferedReader( + new InputStreamReader( + new FileInputStream( + new File(conf.filename) + ))); + int size = 4; // Kbyte + + Range range = new Range(size); + int check = br.read(range.array); + for (;check!=-1;i++){ + + char[] array; + array = new char[size]; + check = br.read(array); + range.nextchar = array[0]; + System.out.print(range.array); // ods + System.out.println(range.nextchar); + range = new Range(array); + } + System.out.println(i); + } catch (FileNotFoundException e) { + System.out.println("file was not found"); + System.exit(1); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } }
--- a/src/main/java/alice/test/codesegment/local/wordcount/Result.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/wordcount/Result.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,11 +4,11 @@ @Message public class Result { - public int line_num; - public int word_num; - - public Result(int line,int word){ - line_num = line; - word_num = word; - } + public int line_num; + public int word_num; + + public Result(int line,int word){ + line_num = line; + word_num = word; + } }
--- a/src/main/java/alice/test/codesegment/local/wordcount/SeparateArray.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/wordcount/SeparateArray.java Tue Jul 15 16:00:22 2014 +0900 @@ -9,45 +9,45 @@ import alice.codesegment.CodeSegment; public class SeparateArray extends CodeSegment{ - private WordConfig conf; - - SeparateArray(WordConfig conf){ - this.conf = conf; - } - - @Override - public void run() { - // cpu分だけTaskをあらかじめ作成 - int cpu_num = Runtime.getRuntime().availableProcessors(); - for (int cnt =0;cnt < cpu_num;cnt++){ - new WordCount(); - } - BufferedReader br = null; - int i = 0; - try { - br= new BufferedReader( - new InputStreamReader( - new FileInputStream( - new File(conf.filename) - ))); - int size = conf.division * 1024; // Kbyte - Range range = new Range(size); - int check = br.read(range.array); - for (;check!=-1;i++){ - char[] array; - array = new char[size]; - check = br.read(array); - range.nextchar = array[0]; - ods.put("array", range); - range = new Range(array); - } - new CorrectResult(i); - } catch (FileNotFoundException e) { - System.exit(1); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + private WordConfig conf; + + SeparateArray(WordConfig conf){ + this.conf = conf; + } + + @Override + public void run() { + // cpu分だけTaskをあらかじめ作成 + int cpu_num = Runtime.getRuntime().availableProcessors(); + for (int cnt =0;cnt < cpu_num;cnt++){ + new WordCount(); + } + BufferedReader br = null; + int i = 0; + try { + br= new BufferedReader( + new InputStreamReader( + new FileInputStream( + new File(conf.filename) + ))); + int size = conf.division * 1024; // Kbyte + Range range = new Range(size); + int check = br.read(range.array); + for (;check!=-1;i++){ + char[] array; + array = new char[size]; + check = br.read(array); + range.nextchar = array[0]; + ods.put("array", range); + range = new Range(array); + } + new CorrectResult(i); + } catch (FileNotFoundException e) { + System.exit(1); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } }
--- a/src/main/java/alice/test/codesegment/local/wordcount/StartWordCount.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/wordcount/StartWordCount.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,12 +5,12 @@ public class StartWordCount { - public static long t = System.currentTimeMillis(); - public static void main(String[] args){ - - new AliceDaemon(new Config(args)).listen(); // logger off - - WordConfig conf = new WordConfig(args); - new SeparateArray(conf).execute(); - } + public static long t = System.currentTimeMillis(); + public static void main(String[] args){ + + new AliceDaemon(new Config(args)).listen(); // logger off + + WordConfig conf = new WordConfig(args); + new SeparateArray(conf).execute(); + } }
--- a/src/main/java/alice/test/codesegment/local/wordcount/WordConfig.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/wordcount/WordConfig.java Tue Jul 15 16:00:22 2014 +0900 @@ -1,23 +1,23 @@ package alice.test.codesegment.local.wordcount; public class WordConfig { - public String filename; - public static String[] array; - public int division = 16; - - public WordConfig(String[] args) { - for (int i=0;i<args.length; i++){ - if ("-f".equals(args[i])){ - filename = args[++i]; - } else if ("-d".equals(args[i])){ - division = Integer.parseInt(args[++i]); - } - } - - if (filename==null){ - System.out.println("Usage: WordCount -f FILENAME"); - System.exit(0); - } - } + public String filename; + public static String[] array; + public int division = 16; + + public WordConfig(String[] args) { + for (int i=0;i<args.length; i++){ + if ("-f".equals(args[i])){ + filename = args[++i]; + } else if ("-d".equals(args[i])){ + division = Integer.parseInt(args[++i]); + } + } + + if (filename==null){ + System.out.println("Usage: WordCount -f FILENAME"); + System.exit(0); + } + } }
--- a/src/main/java/alice/test/codesegment/local/wordcount/WordCount.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/local/wordcount/WordCount.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,43 +5,43 @@ import alice.datasegment.Receiver; public class WordCount extends CodeSegment{ - - private Receiver info1 = ids.create(CommandType.TAKE); - - public WordCount(){ - info1.setKey("array"); - } + + private Receiver info1 = ids.create(CommandType.TAKE); + + public WordCount(){ + info1.setKey("array"); + } - @Override - public void run() { - Range r = info1.asClass(Range.class); - int word_flag = 0; - int word_num = 0; - int line_num = 0; - int i = 0; - for (; i < r.array.length; i++) { - if (r.array[i] == 0x20) { // 空白 - word_flag = 1; - } else if (r.array[i] == 0x0A) { // 改行 - line_num += 1; - word_flag = 1; - } else { - word_num += word_flag; - word_flag = 0; - } - } - word_num += word_flag; - if (r.nextchar!='\0'){ // null means last block - if ((r.array[i-1] == 0x0A||r.array[i-1] == 0x20) && - (r.nextchar == 0x0A||r.nextchar == 0x20)){ - word_num--; - } - } - - Result result = new Result(line_num,word_num); - ods.put("result", result); - recycle();//new WordCount(); - - } + @Override + public void run() { + Range r = info1.asClass(Range.class); + int word_flag = 0; + int word_num = 0; + int line_num = 0; + int i = 0; + for (; i < r.array.length; i++) { + if (r.array[i] == 0x20) { // 空白 + word_flag = 1; + } else if (r.array[i] == 0x0A) { // 改行 + line_num += 1; + word_flag = 1; + } else { + word_num += word_flag; + word_flag = 0; + } + } + word_num += word_flag; + if (r.nextchar!='\0'){ // null means last block + if ((r.array[i-1] == 0x0A||r.array[i-1] == 0x20) && + (r.nextchar == 0x0A||r.nextchar == 0x20)){ + word_num--; + } + } + + Result result = new Result(line_num,word_num); + ods.put("result", result); + recycle();//new WordCount(); + + } }
--- a/src/main/java/alice/test/codesegment/remote/RemoteIncrement.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/remote/RemoteIncrement.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,21 +6,21 @@ public class RemoteIncrement extends CodeSegment { - public Receiver num = ids.create(CommandType.TAKE); - - /** - * Increment DataSegment value up to 10 - */ - @Override - public void run() { - int num = this.num.asInteger(); - System.out.println("[CodeSegment] " + num++); - if (num == 10) System.exit(0); + public Receiver num = ids.create(CommandType.TAKE); - RemoteIncrement cs = new RemoteIncrement(); - cs.num.setKey("remote", "num"); - - ods.put("local", "num", num); - } + /** + * Increment DataSegment value up to 10 + */ + @Override + public void run() { + int num = this.num.asInteger(); + System.out.println("[CodeSegment] " + num++); + if (num == 10) System.exit(0); + + RemoteIncrement cs = new RemoteIncrement(); + cs.num.setKey("remote", "num"); + + ods.put("local", "num", num); + } }
--- a/src/main/java/alice/test/codesegment/remote/RemoteStartCodeSegment.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/remote/RemoteStartCodeSegment.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,13 +3,13 @@ import alice.codesegment.CodeSegment; public class RemoteStartCodeSegment extends CodeSegment { - - @Override - public void run() { - RemoteIncrement cs = new RemoteIncrement(); - cs.num.setKey("remote", "num"); - - ods.put("local", "num", 0); - } + + @Override + public void run() { + RemoteIncrement cs = new RemoteIncrement(); + cs.num.setKey("remote", "num"); + + ods.put("local", "num", 0); + } }
--- a/src/main/java/alice/test/codesegment/remote/TestRemoteAlice.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/remote/TestRemoteAlice.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,12 +5,12 @@ public class TestRemoteAlice { - public static void main(String[] args) { - TestRemoteConfig conf = new TestRemoteConfig(args); + public static void main(String[] args) { + TestRemoteConfig conf = new TestRemoteConfig(args); - new AliceDaemon(conf).listen(); - DataSegment.connect(conf.key, "", conf.hostname, conf.connectPort); - new RemoteStartCodeSegment().execute(); - } + new AliceDaemon(conf).listen(); + DataSegment.connect(conf.key, "", conf.hostname, conf.connectPort); + new RemoteStartCodeSegment().execute(); + } }
--- a/src/main/java/alice/test/codesegment/remote/TestRemoteConfig.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/codesegment/remote/TestRemoteConfig.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,21 +4,21 @@ public class TestRemoteConfig extends Config { - public String hostname; - public int connectPort = 10000; - public String key; + public String hostname; + public int connectPort = 10000; + public String key; - public TestRemoteConfig(String[] args) { - super(args); - for (int i = 0; i< args.length; i++) { - if ("-h".equals(args[i])) { - hostname = args[++i]; - } else if ("-cp".equals(args[i])) { - connectPort = Integer.parseInt(args[++i]); - } else if ("-key".equals(args[i])) { - key = args[++i]; - } - } - } + public TestRemoteConfig(String[] args) { + super(args); + for (int i = 0; i< args.length; i++) { + if ("-h".equals(args[i])) { + hostname = args[++i]; + } else if ("-cp".equals(args[i])) { + connectPort = Integer.parseInt(args[++i]); + } else if ("-key".equals(args[i])) { + key = args[++i]; + } + } + } }
--- a/src/main/java/alice/test/concurrent/AliceConcurrentTest.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/concurrent/AliceConcurrentTest.java Tue Jul 15 16:00:22 2014 +0900 @@ -2,17 +2,17 @@ public class AliceConcurrentTest { - public static void main(String args[]) { - - int count = 1; - - for (int i = 0; i< args.length; i++) { - if ("-c".equals(args[i])) { - count = Integer.parseInt(args[++i]); - } - } - - new StartConcurrent(count).execute(); - } - + public static void main(String args[]) { + + int count = 1; + + for (int i = 0; i< args.length; i++) { + if ("-c".equals(args[i])) { + count = Integer.parseInt(args[++i]); + } + } + + new StartConcurrent(count).execute(); + } + }
--- a/src/main/java/alice/test/concurrent/AliceFinish.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/concurrent/AliceFinish.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,20 +6,20 @@ public class AliceFinish extends CodeSegment { - private int num; - - public Receiver ds1 = ids.create(CommandType.TAKE); - - public AliceFinish(int threadNum) { - this.num = threadNum; - } + private int num; + + public Receiver ds1 = ids.create(CommandType.TAKE); + + public AliceFinish(int threadNum) { + this.num = threadNum; + } - @Override - public void run() { - if (--num == 0) System.exit(0); - - AliceFinish cs1 = new AliceFinish(num); - cs1.ds1.setKey("finish"); - } - + @Override + public void run() { + if (--num == 0) System.exit(0); + + AliceFinish cs1 = new AliceFinish(num); + cs1.ds1.setKey("finish"); + } + }
--- a/src/main/java/alice/test/concurrent/SleepCodeSegment.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/concurrent/SleepCodeSegment.java Tue Jul 15 16:00:22 2014 +0900 @@ -8,24 +8,24 @@ public class SleepCodeSegment extends CodeSegment { - public Receiver ds1 = ids.create(CommandType.TAKE); - - private int num; - - public SleepCodeSegment(int i) { - this.num = i; - } + public Receiver ds1 = ids.create(CommandType.TAKE); + + private int num; + + public SleepCodeSegment(int i) { + this.num = i; + } - @Override - public void run() { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - System.out.println("[CodeSegment-" + num + "] Hello, World!"); - - ods.put("local", "finish", ValueFactory.createNilValue()); - } + @Override + public void run() { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("[CodeSegment-" + num + "] Hello, World!"); + + ods.put("local", "finish", ValueFactory.createNilValue()); + } }
--- a/src/main/java/alice/test/concurrent/StartConcurrent.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/concurrent/StartConcurrent.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,27 +6,27 @@ public class StartConcurrent extends CodeSegment { - private int count; - - public StartConcurrent(int count) { - this.count = count; - } + private int count; + + public StartConcurrent(int count) { + this.count = count; + } + + @Override + public void run() { + int threadNum = Runtime.getRuntime().availableProcessors() * count; - @Override - public void run() { - int threadNum = Runtime.getRuntime().availableProcessors() * count; - - AliceFinish cs1 = new AliceFinish(threadNum); - cs1.ds1.setKey("finish"); - - for (int i = 0; i < threadNum; i++) { - SleepCodeSegment cs2 = new SleepCodeSegment(i); - cs2.ds1.setKey("wait"); - } - - for (int i = 0; i < threadNum; i++) { - ods.put("local", "wait", ValueFactory.createNilValue()); - } - } - + AliceFinish cs1 = new AliceFinish(threadNum); + cs1.ds1.setKey("finish"); + + for (int i = 0; i < threadNum; i++) { + SleepCodeSegment cs2 = new SleepCodeSegment(i); + cs2.ds1.setKey("wait"); + } + + for (int i = 0; i < threadNum; i++) { + ods.put("local", "wait", ValueFactory.createNilValue()); + } + } + }
--- a/src/main/java/alice/test/reflection/CSTemplate.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/reflection/CSTemplate.java Tue Jul 15 16:00:22 2014 +0900 @@ -10,7 +10,7 @@ @Override public void run() { - System.out.println("runrunrun"); + } }
--- a/src/main/java/alice/test/reflection/ReflectionTest.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/reflection/ReflectionTest.java Tue Jul 15 16:00:22 2014 +0900 @@ -8,44 +8,44 @@ public class ReflectionTest { - public static void main(String[] args){ - try { - new ReflectionTest().createCS(); - } catch (Exception e) { - e.printStackTrace(); - } - System.out.println("TEST END"); - } + public static void main(String[] args){ + try { + new ReflectionTest().createCS(); + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println("TEST END"); + } - public void createCS() throws Exception{ - - ClassPool cp = ClassPool.getDefault(); - CtClass tep = cp.get("alice.test.reflection.CSTemplate"); - CtClass rec = cp.get("alice.datasegment.Receiver"); + public void createCS() throws Exception{ + + ClassPool cp = ClassPool.getDefault(); + CtClass tep = cp.get("alice.test.reflection.CSTemplate"); + CtClass rec = cp.get("alice.datasegment.Receiver"); - // ---- define Field ----- - //CtField f1 = CtField.make("alice.datasegment.Receiver arg1 = ids.create(alice.datasegment.CommandType.PEEK);", tep); - //tep.addField(f1); - CtField f1 = new CtField(rec,"arg1",tep); - tep.addField(f1,"ids.create(alice.datasegment.CommandType.PEEK)"); + // ---- define Field ----- + //CtField f1 = CtField.make("alice.datasegment.Receiver arg1 = ids.create(alice.datasegment.CommandType.PEEK);", tep); + //tep.addField(f1); + CtField f1 = new CtField(rec,"arg1",tep); + tep.addField(f1,"ids.create(alice.datasegment.CommandType.PEEK)"); - // ---- define Constructor ----- - CtConstructor c = tep.getConstructor("()V"); - c.insertAfter("arg1.setKey(\"key1\");"); + // ---- define Constructor ----- + CtConstructor c = tep.getConstructor("()V"); + c.insertAfter("arg1.setKey(\"key1\");"); - // ---- define run ----- - CtMethod m = tep.getMethod("run", "()V"); - m.insertAfter("System.out.println(\"type = \" + arg1.type);"); - m.insertAfter("System.out.println(\"index = \" + arg1.index);"); - m.insertAfter("System.out.println(\"data = \" + arg1.getVal());"); - m.insertAfter("System.out.println(((org.msgpack.type.Value)arg1.getVal()).getType());"); - m.insertAfter("if (arg1.index==10){ System.exit(0);}"); - m.insertAfter("new alice.test.reflection.CSTemplate();"); - m.insertAfter("ods.update(\"key1\", \"String Data\");"); + // ---- define run ----- + CtMethod m = tep.getMethod("run", "()V"); + m.insertAfter("System.out.println(\"type = \" + arg1.type);"); + m.insertAfter("System.out.println(\"index = \" + arg1.index);"); + m.insertAfter("System.out.println(\"data = \" + arg1.getVal());"); + m.insertAfter("System.out.println(((org.msgpack.type.Value)arg1.getVal()).getType());"); + m.insertAfter("if (arg1.index==10){ System.exit(0);}"); + m.insertAfter("new alice.test.reflection.CSTemplate();"); + m.insertAfter("ods.update(\"key1\", \"String Data\");"); - Class<?> clazz = tep.toClass(); // load Class - @SuppressWarnings("unused") - CSTemplate cs = (CSTemplate)clazz.newInstance(); // create instance - - } + Class<?> clazz = tep.toClass(); // load Class + @SuppressWarnings("unused") + CSTemplate cs = (CSTemplate)clazz.newInstance(); // create instance + + } }
--- a/src/main/java/alice/test/topology/aquarium/AutoIncrement.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/AutoIncrement.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,43 +5,43 @@ import alice.datasegment.Receiver; public class AutoIncrement extends CodeSegment { - - private Receiver position = ids.create(CommandType.PEEK); - private Receiver number = ids.create(CommandType.PEEK); - private static final float MIN = -1.3f; - - public AutoIncrement(String key, int index) { - this.number.setKey("maxsize"); - this.position.setKey(key, index); - } + + private Receiver position = ids.create(CommandType.PEEK); + private Receiver number = ids.create(CommandType.PEEK); + private static final float MIN = -1.3f; + + public AutoIncrement(String key, int index) { + this.number.setKey("maxsize"); + this.position.setKey(key, index); + } - @Override - public void run() { - float max = this.number.asInteger() * 2 - 1 + 0.3f; - FishPoint fp = this.position.asClass(FishPoint.class); - if (fp.getX() + 0.01 > max) { - fp.setXYZ(MIN, fp.getY(), fp.getZ()); - } else if (fp.getX() + 0.01 < MIN) { - fp.setXYZ(max, fp.getY(), fp.getZ()); - } - else { - fp.setXYZ(fp.getX() + 0.01f, fp.getY(), fp.getZ()); - } - - ods.update(position.key, fp); - synchronized (this) { - try { - // TODO - // Waiting should be done in Alice kernel - // ids.create(CommandType.WAIT); - - wait(20); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - new AutoIncrement(this.position.key, this.position.index); - } - + @Override + public void run() { + float max = this.number.asInteger() * 2 - 1 + 0.3f; + FishPoint fp = this.position.asClass(FishPoint.class); + if (fp.getX() + 0.01 > max) { + fp.setXYZ(MIN, fp.getY(), fp.getZ()); + } else if (fp.getX() + 0.01 < MIN) { + fp.setXYZ(max, fp.getY(), fp.getZ()); + } + else { + fp.setXYZ(fp.getX() + 0.01f, fp.getY(), fp.getZ()); + } + + ods.update(position.key, fp); + synchronized (this) { + try { + // TODO + // Waiting should be done in Alice kernel + // ids.create(CommandType.WAIT); + + wait(20); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + new AutoIncrement(this.position.key, this.position.index); + } + }
--- a/src/main/java/alice/test/topology/aquarium/CheckLocalIndex.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/CheckLocalIndex.java Tue Jul 15 16:00:22 2014 +0900 @@ -8,26 +8,26 @@ public class CheckLocalIndex extends CodeSegment { - private Receiver data = ids.create(CommandType.PEEK); - private Receiver list = ids.create(CommandType.PEEK); - - public CheckLocalIndex(String key, int index){ - this.list.setKey("_CLIST"); - this.data.setKey(key, index); - } - - @Override - public void run() { - @SuppressWarnings("unchecked") - List<String> r = list.asClass(List.class); - for (String node : r) { - if (!node.equals(data.from)) { - System.out.println(data.from); - ods.update(node, data.key, data.getVal()); - } - } - new CheckLocalIndex(data.key, data.index); - - } + private Receiver data = ids.create(CommandType.PEEK); + private Receiver list = ids.create(CommandType.PEEK); + + public CheckLocalIndex(String key, int index){ + this.list.setKey("_CLIST"); + this.data.setKey(key, index); + } + + @Override + public void run() { + @SuppressWarnings("unchecked") + List<String> r = list.asClass(List.class); + for (String node : r) { + if (!node.equals(data.from)) { + System.out.println(data.from); + ods.update(node, data.key, data.getVal()); + } + } + new CheckLocalIndex(data.key, data.index); + + } }
--- a/src/main/java/alice/test/topology/aquarium/CheckMyName.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/CheckMyName.java Tue Jul 15 16:00:22 2014 +0900 @@ -10,88 +10,88 @@ public class CheckMyName extends CodeSegment { - private Receiver host = ids.create(CommandType.PEEK); - private Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$"); - private String key = "fish"; - - public CheckMyName(){ - host.setKey("host"); - } - - @Override - public void run(){ - String name = host.asString(); - Matcher matcher = pattern.matcher(name); - - matcher.find(); - String type = matcher.group(1); - int num = new Integer(matcher.group(2)); - ods.put("host_num", num*2); - MakeFrame frame = new MakeFrame(name,num*2); - ods.put("num", 1); - - if (type.equals("cli")){ - System.out.println("cli"+num); - new TakeMynum(); - }else if (type.equals("node")){ - System.out.println("node"+num); - if (num != 0){ - new TakeMynum(); - } else { - new SendMaxsize(0); - } - } - new CheckLocalIndex("maxsize",0); - - ods.update(key, new FishPoint(-0.1f,-0.1f)); - new SetLocation(new MakeObject(frame), key, 0); - new CheckLocalIndex(key,1); - for (int i = 0; i < 3 ; i++){ - key = "fish"+i; - if (num == 0) new AutoIncrement(key,0); - ods.update(key, new FishPoint((float)Math.random(), - (float)Math.random(), (float)Math.random())); - new SetLocation(new MakeObject(frame), key, 0); - new CheckLocalIndex(key,1); - } - - for (int i = 3; i < 6 ; i++){ - key = "fish"+i; - if (num == 1) new AutoIncrement(key,0); - Random rnd = new Random(); - int tmp = rnd.nextInt(3); - int rand = tmp + 1; - ods.update(key, new FishPoint( (float)rand, - -(float)Math.random(), -(float)Math.random())); - new SetLocation(new MakeObject(frame), key, 0); - new CheckLocalIndex(key,1); - } - - for (int i = 6; i < 9 ; i++){ - key = "fish"+i; - if (num == 2) new AutoIncrement(key,0); - Random rnd = new Random(); - int tmp = rnd.nextInt(3); - int rand = tmp + 3; - ods.update(key, new FishPoint( (float)rand, - (float)Math.random(), -(float)Math.random())); - new SetLocation(new MakeObject(frame), key, 0); - new CheckLocalIndex(key,1); - } - - for (int i = 9; i < 12 ; i++){ - key = "fish"+i; - if (num == 3) new AutoIncrement(key,0); - - Random rnd = new Random(); - int tmp = rnd.nextInt(3); - int rand = tmp + 5; - - ods.update(key, new FishPoint( (float)rand, - -(float)Math.random(), (float)Math.random())); - new SetLocation(new MakeObject(frame), key, 0); - new CheckLocalIndex(key,1); - } - - } + private Receiver host = ids.create(CommandType.PEEK); + private Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$"); + private String key = "fish"; + + public CheckMyName(){ + host.setKey("host"); + } + + @Override + public void run(){ + String name = host.asString(); + Matcher matcher = pattern.matcher(name); + + matcher.find(); + String type = matcher.group(1); + int num = new Integer(matcher.group(2)); + ods.put("host_num", num*2); + MakeFrame frame = new MakeFrame(name,num*2); + ods.put("num", 1); + + if (type.equals("cli")){ + System.out.println("cli"+num); + new TakeMynum(); + }else if (type.equals("node")){ + System.out.println("node"+num); + if (num != 0){ + new TakeMynum(); + } else { + new SendMaxsize(0); + } + } + new CheckLocalIndex("maxsize",0); + + ods.update(key, new FishPoint(-0.1f,-0.1f)); + new SetLocation(new MakeObject(frame), key, 0); + new CheckLocalIndex(key,1); + for (int i = 0; i < 3 ; i++){ + key = "fish"+i; + if (num == 0) new AutoIncrement(key,0); + ods.update(key, new FishPoint((float)Math.random(), + (float)Math.random(), (float)Math.random())); + new SetLocation(new MakeObject(frame), key, 0); + new CheckLocalIndex(key,1); + } + + for (int i = 3; i < 6 ; i++){ + key = "fish"+i; + if (num == 1) new AutoIncrement(key,0); + Random rnd = new Random(); + int tmp = rnd.nextInt(3); + int rand = tmp + 1; + ods.update(key, new FishPoint( (float)rand, + -(float)Math.random(), -(float)Math.random())); + new SetLocation(new MakeObject(frame), key, 0); + new CheckLocalIndex(key,1); + } + + for (int i = 6; i < 9 ; i++){ + key = "fish"+i; + if (num == 2) new AutoIncrement(key,0); + Random rnd = new Random(); + int tmp = rnd.nextInt(3); + int rand = tmp + 3; + ods.update(key, new FishPoint( (float)rand, + (float)Math.random(), -(float)Math.random())); + new SetLocation(new MakeObject(frame), key, 0); + new CheckLocalIndex(key,1); + } + + for (int i = 9; i < 12 ; i++){ + key = "fish"+i; + if (num == 3) new AutoIncrement(key,0); + + Random rnd = new Random(); + int tmp = rnd.nextInt(3); + int rand = tmp + 5; + + ods.update(key, new FishPoint( (float)rand, + -(float)Math.random(), (float)Math.random())); + new SetLocation(new MakeObject(frame), key, 0); + new CheckLocalIndex(key,1); + } + + } }
--- a/src/main/java/alice/test/topology/aquarium/FishMovementTopology.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/FishMovementTopology.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,10 +3,10 @@ import alice.topology.node.TopologyNodeConfig; public class FishMovementTopology { - public static void main(String[] args){ - TopologyNodeConfig conf = new TopologyNodeConfig(args); - new TopologyNode(conf, new StartFishMovement()); - - } + public static void main(String[] args){ + TopologyNodeConfig conf = new TopologyNodeConfig(args); + new TopologyNode(conf, new StartFishMovement()); + + } }
--- a/src/main/java/alice/test/topology/aquarium/FishPoint.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/FishPoint.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,45 +4,45 @@ @Message public class FishPoint { - // public fields are serialized. - public float x = 0.0f; - public float y = 0.0f; - public float z = 0.0f; - - public FishPoint(){} - - public FishPoint(float x,float y){ - this.x = x; - this.y = y; - } - - public FishPoint(float x,float y,float z){ - this.x = x; - this.y = y; - this.z = z; - } - - public void setXY(float x,float y){ - this.x = x; - this.y = y; - } - - public void setXYZ(float x,float y,float z){ - this.x = x; - this.y = y; - this.z = z; - } - - public float getX(){ - return this.x; - } - - public float getY(){ - return this.y; - } - - public float getZ(){ - return this.z; - } - + // public fields are serialized. + public float x = 0.0f; + public float y = 0.0f; + public float z = 0.0f; + + public FishPoint(){} + + public FishPoint(float x,float y){ + this.x = x; + this.y = y; + } + + public FishPoint(float x,float y,float z){ + this.x = x; + this.y = y; + this.z = z; + } + + public void setXY(float x,float y){ + this.x = x; + this.y = y; + } + + public void setXYZ(float x,float y,float z){ + this.x = x; + this.y = y; + this.z = z; + } + + public float getX(){ + return this.x; + } + + public float getY(){ + return this.y; + } + + public float getZ(){ + return this.z; + } + }
--- a/src/main/java/alice/test/topology/aquarium/KeyInputCodeSegment.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/KeyInputCodeSegment.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,52 +4,52 @@ import java.awt.event.KeyListener; public class KeyInputCodeSegment implements KeyListener{ - - MakeFrame frame; - public KeyInputCodeSegment(MakeFrame frame) { - this.frame = frame; - } + + MakeFrame frame; + public KeyInputCodeSegment(MakeFrame frame) { + this.frame = frame; + } - @Override - public void keyPressed(KeyEvent event) { - //System.out.println(event.getKeyCode()); - switch(event.getKeyCode()) - { - case 37: // left - new SendLocation(-0.1f,0.0f,0.0f); - break; - case 38: // up - new SendLocation(0.0f,0.1f,0.0f); - break; - case 39: // right - new SendLocation(0.1f,0.0f,0.0f); - break; - case 40: // down - new SendLocation(0.0f,-0.1f,0.0f); - break; - case 76: // l - new SendLocation(0.0f,0.0f,0.1f); - break; - case 78: // "n" - new RefreshWindow(frame); - break; - case 79: // "o" - new SendLocation(0.0f,0.0f,-0.1f); - break; - case 82: // "r" - new ResetFish().execute(); - break; - } - } + @Override + public void keyPressed(KeyEvent event) { + //System.out.println(event.getKeyCode()); + switch(event.getKeyCode()) + { + case 37: // left + new SendLocation(-0.1f,0.0f,0.0f); + break; + case 38: // up + new SendLocation(0.0f,0.1f,0.0f); + break; + case 39: // right + new SendLocation(0.1f,0.0f,0.0f); + break; + case 40: // down + new SendLocation(0.0f,-0.1f,0.0f); + break; + case 76: // l + new SendLocation(0.0f,0.0f,0.1f); + break; + case 78: // "n" + new RefreshWindow(frame); + break; + case 79: // "o" + new SendLocation(0.0f,0.0f,-0.1f); + break; + case 82: // "r" + new ResetFish().execute(); + break; + } + } - @Override - public void keyReleased(KeyEvent event) { - - } + @Override + public void keyReleased(KeyEvent event) { + + } - @Override - public void keyTyped(KeyEvent event) { - - } + @Override + public void keyTyped(KeyEvent event) { + + } }
--- a/src/main/java/alice/test/topology/aquarium/MakeFrame.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/MakeFrame.java Tue Jul 15 16:00:22 2014 +0900 @@ -22,93 +22,93 @@ import com.sun.j3d.utils.universe.SimpleUniverse; public class MakeFrame { - - private static final int F_SIZE_X = 800; - private static final int F_SIZE_Y = 800; - private ViewChange canvas; - private JFrame frame; - private ObjectList list = new ObjectList(); - - public MakeFrame(String str,float x) { - System.loadLibrary("jawt"); - frame = new JFrame(str); - frame.setSize(F_SIZE_X, F_SIZE_Y); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - JPanel cp = new JPanel(); - cp.setLayout(null); - frame.add(cp); - - GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); - canvas = new ViewChange(x,0.01f,config); - canvas.setBounds(0,0, F_SIZE_X, F_SIZE_Y); - cp.add(canvas); - - canvas.universe.addBranchGraph(createLight()); - canvas.universe.addBranchGraph(setBackground()); - - canvas.addKeyListener(new KeyInputCodeSegment(this)); - frame.setVisible(true); - - } - - private BranchGroup setBackground() { - BranchGroup scene = new BranchGroup(); - BufferedImage img = null; - try { - URL url = getClass().getClassLoader().getResource("images/image1.jpg"); - if (url!=null) { - img = ImageIO.read(url); - } else { - img = ImageIO.read(new File("images/image1.jpg")); - } - } catch (IOException e) { - e.printStackTrace(); - } - ImageComponent2D image = - new ImageComponent2D(ImageComponent2D.FORMAT_RGBA8,img); - Background background = new Background(image); - background.setImageScaleMode(Background.SCALE_FIT_ALL); - BoundingSphere bounds = new BoundingSphere(new Point3d(), 10.0); - background.setApplicationBounds(bounds); - scene.addChild(background); - return scene; - - } - - private BranchGroup createLight() { - BranchGroup scene = new BranchGroup(); - Color3f light_color = new Color3f(1.7f,1.7f,1.7f); - Vector3f light_direction = new Vector3f(0.0f,0.0f,-1.0f); - DirectionalLight light = new DirectionalLight(light_color,light_direction); - BoundingSphere bounds = new BoundingSphere(new Point3d(), 10.0); - light.setInfluencingBounds(bounds); - scene.addChild(light); - return scene; - } - - public void register(MakeObject obj){ - list.table.add(obj); - BranchGroup group = obj.createBranch(); - this.canvas.universe.addBranchGraph(group); - } - - public ViewChange getCanvas(){ - return this.canvas; - } - - public JFrame getJFrame(){ - return this.frame; - } - - public ObjectList getList(){ - return this.list; - } - - static public void main(String [] args) { - MakeFrame test = new MakeFrame("Test", 0); - test.setBackground(); - test.createLight(); - } - + + private static final int F_SIZE_X = 800; + private static final int F_SIZE_Y = 800; + private ViewChange canvas; + private JFrame frame; + private ObjectList list = new ObjectList(); + + public MakeFrame(String str,float x) { + System.loadLibrary("jawt"); + frame = new JFrame(str); + frame.setSize(F_SIZE_X, F_SIZE_Y); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + JPanel cp = new JPanel(); + cp.setLayout(null); + frame.add(cp); + + GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); + canvas = new ViewChange(x,0.01f,config); + canvas.setBounds(0,0, F_SIZE_X, F_SIZE_Y); + cp.add(canvas); + + canvas.universe.addBranchGraph(createLight()); + canvas.universe.addBranchGraph(setBackground()); + + canvas.addKeyListener(new KeyInputCodeSegment(this)); + frame.setVisible(true); + + } + + private BranchGroup setBackground() { + BranchGroup scene = new BranchGroup(); + BufferedImage img = null; + try { + URL url = getClass().getClassLoader().getResource("images/image1.jpg"); + if (url!=null) { + img = ImageIO.read(url); + } else { + img = ImageIO.read(new File("images/image1.jpg")); + } + } catch (IOException e) { + e.printStackTrace(); + } + ImageComponent2D image = + new ImageComponent2D(ImageComponent2D.FORMAT_RGBA8,img); + Background background = new Background(image); + background.setImageScaleMode(Background.SCALE_FIT_ALL); + BoundingSphere bounds = new BoundingSphere(new Point3d(), 10.0); + background.setApplicationBounds(bounds); + scene.addChild(background); + return scene; + + } + + private BranchGroup createLight() { + BranchGroup scene = new BranchGroup(); + Color3f light_color = new Color3f(1.7f,1.7f,1.7f); + Vector3f light_direction = new Vector3f(0.0f,0.0f,-1.0f); + DirectionalLight light = new DirectionalLight(light_color,light_direction); + BoundingSphere bounds = new BoundingSphere(new Point3d(), 10.0); + light.setInfluencingBounds(bounds); + scene.addChild(light); + return scene; + } + + public void register(MakeObject obj){ + list.table.add(obj); + BranchGroup group = obj.createBranch(); + this.canvas.universe.addBranchGraph(group); + } + + public ViewChange getCanvas(){ + return this.canvas; + } + + public JFrame getJFrame(){ + return this.frame; + } + + public ObjectList getList(){ + return this.list; + } + + static public void main(String [] args) { + MakeFrame test = new MakeFrame("Test", 0); + test.setBackground(); + test.createLight(); + } + }
--- a/src/main/java/alice/test/topology/aquarium/MakeObject.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/MakeObject.java Tue Jul 15 16:00:22 2014 +0900 @@ -21,95 +21,95 @@ import com.sun.j3d.utils.image.TextureLoader; public class MakeObject { - - private Transform3D transform; - private TransformGroup transform_group; - private ViewChange canvas; - private Matrix4d matrix; - private double s; + + private Transform3D transform; + private TransformGroup transform_group; + private ViewChange canvas; + private Matrix4d matrix; + private double s; + - - public MakeObject(MakeFrame frame){ - this.canvas = frame.getCanvas(); - this.s = 0.3; - frame.register(this); - } - - public BranchGroup createBranch(){ - BranchGroup scene = new BranchGroup(); - /*Box box = new Box(0.1f,0.1f,0.0f, + public MakeObject(MakeFrame frame){ + this.canvas = frame.getCanvas(); + this.s = 0.3; + frame.register(this); + } + + public BranchGroup createBranch(){ + BranchGroup scene = new BranchGroup(); + /*Box box = new Box(0.1f,0.1f,0.0f, Box.GENERATE_NORMALS|Box.GENERATE_TEXTURE_COORDS,createAppearance());*/ - ObjectFile obj = new ObjectFile(ObjectFile.RESIZE); - Scene img = null; - try{ - URL url=getClass().getClassLoader().getResource("objects/TUNA.obj"); - img = obj.load(url); - } catch(FileNotFoundException e){ - System.err.println(e); - System.exit(1); - } catch(ParsingErrorException e){ - System.err.println(e); - System.exit(1); - } catch(IncorrectFormatException e){ - System.err.println(e); - System.exit(1); - } - - transform_group = new TransformGroup(); - setLocation(-2.0f,-2.0f); //set out of window - transform_group.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); - transform_group.addChild(img.getSceneGroup()); - scene.addChild(transform_group); - return scene; - } - - // no use method - public Appearance createAppearance(){ - Appearance app = new Appearance(); - Image image = null; - Toolkit toolkit = Toolkit.getDefaultToolkit(); - URL url = getClass().getClassLoader().getResource("fish.jpg"); - image = toolkit.getImage(url); - MediaTracker mt = new MediaTracker(canvas); - mt.addImage(image, 0); - mt.checkAll(true); - try { - mt.waitForID(0); - - }catch (InterruptedException e){ - e.printStackTrace(); - - } - Texture texture = new TextureLoader(image,canvas).getTexture(); - app.setTexture(texture); - return app; - - } - - public void setScale(float size){ - s = size; - } - - public void setLocation(float x,float y){ - transform = new Transform3D(); - matrix = new Matrix4d(s,0,0,x, - 0,s,0,y, - 0,0,s,0, - 0,0,0,1); - transform.set(matrix); - transform_group.setTransform(transform); - } - - public void setLocation(float x,float y,float z){ - transform = new Transform3D(); - matrix = new Matrix4d(s,0,0,x, - 0,s,0,y, - 0,0,s,z, - 0,0,0,1); - transform.set(matrix); - transform_group.setTransform(transform); - } - - + ObjectFile obj = new ObjectFile(ObjectFile.RESIZE); + Scene img = null; + try{ + URL url=getClass().getClassLoader().getResource("objects/TUNA.obj"); + img = obj.load(url); + } catch(FileNotFoundException e){ + System.err.println(e); + System.exit(1); + } catch(ParsingErrorException e){ + System.err.println(e); + System.exit(1); + } catch(IncorrectFormatException e){ + System.err.println(e); + System.exit(1); + } + + transform_group = new TransformGroup(); + setLocation(-2.0f,-2.0f); //set out of window + transform_group.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); + transform_group.addChild(img.getSceneGroup()); + scene.addChild(transform_group); + return scene; + } + + // no use method + public Appearance createAppearance(){ + Appearance app = new Appearance(); + Image image = null; + Toolkit toolkit = Toolkit.getDefaultToolkit(); + URL url = getClass().getClassLoader().getResource("fish.jpg"); + image = toolkit.getImage(url); + MediaTracker mt = new MediaTracker(canvas); + mt.addImage(image, 0); + mt.checkAll(true); + try { + mt.waitForID(0); + + }catch (InterruptedException e){ + e.printStackTrace(); + + } + Texture texture = new TextureLoader(image,canvas).getTexture(); + app.setTexture(texture); + return app; + + } + + public void setScale(float size){ + s = size; + } + + public void setLocation(float x,float y){ + transform = new Transform3D(); + matrix = new Matrix4d(s,0,0,x, + 0,s,0,y, + 0,0,s,0, + 0,0,0,1); + transform.set(matrix); + transform_group.setTransform(transform); + } + + public void setLocation(float x,float y,float z){ + transform = new Transform3D(); + matrix = new Matrix4d(s,0,0,x, + 0,s,0,y, + 0,0,s,z, + 0,0,0,1); + transform.set(matrix); + transform_group.setTransform(transform); + } + + }
--- a/src/main/java/alice/test/topology/aquarium/MouseViewEvent.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/MouseViewEvent.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,49 +4,49 @@ import java.awt.event.MouseMotionListener; public class MouseViewEvent implements MouseMotionListener { - - int new_x, new_y; - int pre_x, pre_y; - ViewChange v; - - public MouseViewEvent(ViewChange v) { - this.v = v; - - } + + int new_x, new_y; + int pre_x, pre_y; + ViewChange v; + + public MouseViewEvent(ViewChange v) { + this.v = v; + + } + + @Override + public void mouseDragged(MouseEvent event) { + new_x = event.getX(); + new_y = event.getY(); + + v.theta -= v.sensitivity * (new_y - pre_y); + v.phi += v.sensitivity * (new_x - pre_x); + v.camera_y = v.distance * (float)Math.sin(v.theta); + v.camera_xz = v.distance * (float)Math.cos(v.theta); - @Override - public void mouseDragged(MouseEvent event) { - new_x = event.getX(); - new_y = event.getY(); - - v.theta -= v.sensitivity * (new_y - pre_y); - v.phi += v.sensitivity * (new_x - pre_x); - v.camera_y = v.distance * (float)Math.sin(v.theta); - v.camera_xz = v.distance * (float)Math.cos(v.theta); - - v.camera_x = v.camera_xz * (float)Math.sin(v.phi); - v.camera_z = v.camera_xz * (float)Math.cos(v.phi); - v.Vector_camera_pos.x = v.camera_x; - v.Vector_camera_pos.y = v.camera_y; - v.Vector_camera_pos.z = v.camera_z; - - v.Transform_camera_pos.setIdentity(); - v.Transform_camera_pos.setTranslation(v.Vector_camera_pos); - - v.Transform_camera_theta.rotX(-v.theta); - v.Transform_camera_phi.rotY(v.phi); - v.Transform_camera_phi.mul(v.Transform_camera_theta); - v.Transform_camera_pos.mul(v.Transform_camera_phi); - v.Camera.setTransform(v.Transform_camera_pos); - pre_x = event.getX(); - pre_y = event.getY(); - - } - - @Override - public void mouseMoved(MouseEvent event) { - pre_x = event.getX(); - pre_y = event.getY(); - } + v.camera_x = v.camera_xz * (float)Math.sin(v.phi); + v.camera_z = v.camera_xz * (float)Math.cos(v.phi); + v.Vector_camera_pos.x = v.camera_x; + v.Vector_camera_pos.y = v.camera_y; + v.Vector_camera_pos.z = v.camera_z; + + v.Transform_camera_pos.setIdentity(); + v.Transform_camera_pos.setTranslation(v.Vector_camera_pos); + + v.Transform_camera_theta.rotX(-v.theta); + v.Transform_camera_phi.rotY(v.phi); + v.Transform_camera_phi.mul(v.Transform_camera_theta); + v.Transform_camera_pos.mul(v.Transform_camera_phi); + v.Camera.setTransform(v.Transform_camera_pos); + pre_x = event.getX(); + pre_y = event.getY(); + + } + + @Override + public void mouseMoved(MouseEvent event) { + pre_x = event.getX(); + pre_y = event.getY(); + } }
--- a/src/main/java/alice/test/topology/aquarium/ObjectList.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/ObjectList.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,5 +4,5 @@ import java.util.List; public class ObjectList { - public List<MakeObject> table = new ArrayList<MakeObject>(); + public List<MakeObject> table = new ArrayList<MakeObject>(); }
--- a/src/main/java/alice/test/topology/aquarium/RefreshWindow.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/RefreshWindow.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,25 +4,25 @@ import alice.datasegment.Receiver; public class RefreshWindow extends CodeSegment { - private Receiver num = ids.create(CommandType.PEEK); - private Receiver host = ids.create(CommandType.PEEK); - private MakeFrame frame; - - public RefreshWindow(MakeFrame frame){ - this.host.setKey("host"); - this.num.setKey("host_num"); - this.frame = frame; - } - - @Override - public void run() { - frame.getJFrame().dispose(); - ObjectList list = frame.getList(); - frame = new MakeFrame(host.asString(),num.asInteger()); - for (MakeObject obj : list.table) { - frame.register(obj); - } - } + private Receiver num = ids.create(CommandType.PEEK); + private Receiver host = ids.create(CommandType.PEEK); + private MakeFrame frame; + + public RefreshWindow(MakeFrame frame){ + this.host.setKey("host"); + this.num.setKey("host_num"); + this.frame = frame; + } + + @Override + public void run() { + frame.getJFrame().dispose(); + ObjectList list = frame.getList(); + frame = new MakeFrame(host.asString(),num.asInteger()); + for (MakeObject obj : list.table) { + frame.register(obj); + } + } }
--- a/src/main/java/alice/test/topology/aquarium/ResetFish.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/ResetFish.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,14 +3,14 @@ import alice.codesegment.CodeSegment; public class ResetFish extends CodeSegment { - - public ResetFish(){} + + public ResetFish(){} - @Override - public void run() { - FishPoint fp = new FishPoint(0.0f,0.0f,0.0f); - ods.update("fish", fp); - - } + @Override + public void run() { + FishPoint fp = new FishPoint(0.0f,0.0f,0.0f); + ods.update("fish", fp); + + } }
--- a/src/main/java/alice/test/topology/aquarium/SendLocation.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/SendLocation.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,25 +6,25 @@ public class SendLocation extends CodeSegment { - - private Receiver position = ids.create(CommandType.PEEK); - float x; - float y; - float z; - - public SendLocation(float x,float y,float z){ - this.x = x; - this.y = y; - this.z = z; - position.setKey("fish"); - } - - @Override - public void run() { - FishPoint fp = this.position.asClass(FishPoint.class); - fp.setXYZ(fp.getX()+x, fp.getY()+y, fp.getZ()+z); - ods.update("fish", fp); - - } + + private Receiver position = ids.create(CommandType.PEEK); + float x; + float y; + float z; + + public SendLocation(float x,float y,float z){ + this.x = x; + this.y = y; + this.z = z; + position.setKey("fish"); + } + + @Override + public void run() { + FishPoint fp = this.position.asClass(FishPoint.class); + fp.setXYZ(fp.getX()+x, fp.getY()+y, fp.getZ()+z); + ods.update("fish", fp); + + } }
--- a/src/main/java/alice/test/topology/aquarium/SendMaxsize.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/SendMaxsize.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,17 +6,17 @@ public class SendMaxsize extends CodeSegment{ - private Receiver max = ids.create(CommandType.PEEK); - - public SendMaxsize(int index){ - this.max.setKey("num", index); - } - - @Override - public void run() { - int size = max.asInteger(); - ods.update("maxsize",size); - new SendMaxsize(this.max.index); - } + private Receiver max = ids.create(CommandType.PEEK); + + public SendMaxsize(int index){ + this.max.setKey("num", index); + } + + @Override + public void run() { + int size = max.asInteger(); + ods.update("maxsize",size); + new SendMaxsize(this.max.index); + } }
--- a/src/main/java/alice/test/topology/aquarium/SetLocation.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/SetLocation.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,22 +6,22 @@ public class SetLocation extends CodeSegment{ - - private Receiver position = ids.create(CommandType.PEEK); - private MakeObject obj; - - public SetLocation(MakeObject obj ,String key, int index){ - this.obj = obj; - this.position.setKey(key,index); - } - - @Override - public void run(){ - FishPoint fp = this.position.asClass(FishPoint.class); - obj.setLocation(fp.getX(), fp.getY(), fp.getZ()); - new SetLocation(obj, position.key, position.index); - - } - + + private Receiver position = ids.create(CommandType.PEEK); + private MakeObject obj; + + public SetLocation(MakeObject obj ,String key, int index){ + this.obj = obj; + this.position.setKey(key,index); + } + + @Override + public void run(){ + FishPoint fp = this.position.asClass(FishPoint.class); + obj.setLocation(fp.getX(), fp.getY(), fp.getZ()); + new SetLocation(obj, position.key, position.index); + + } + }
--- a/src/main/java/alice/test/topology/aquarium/StartFishMovement.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/StartFishMovement.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,10 +3,10 @@ import alice.codesegment.CodeSegment; public class StartFishMovement extends CodeSegment{ - @Override - public void run(){ - new CheckMyName(); - } - + @Override + public void run(){ + new CheckMyName(); + } + }
--- a/src/main/java/alice/test/topology/aquarium/TakeMynum.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/TakeMynum.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,23 +5,23 @@ import alice.datasegment.Receiver; public class TakeMynum extends CodeSegment { - - private Receiver mynum = ids.create(CommandType.TAKE); - - public TakeMynum(){ - this.mynum.setKey("num"); - } - - public TakeMynum(int index){ - this.mynum.setKey("num", index); - } + + private Receiver mynum = ids.create(CommandType.TAKE); + + public TakeMynum(){ + this.mynum.setKey("num"); + } - @Override - public void run() { - new TakePnum(this.mynum); - ods.put("num", 0); - new TakeMynum(this.mynum.index+1); - } + public TakeMynum(int index){ + this.mynum.setKey("num", index); + } + + @Override + public void run() { + new TakePnum(this.mynum); + ods.put("num", 0); + new TakeMynum(this.mynum.index+1); + } }
--- a/src/main/java/alice/test/topology/aquarium/TakePnum.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/TakePnum.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,20 +5,20 @@ import alice.datasegment.Receiver; public class TakePnum extends CodeSegment { - // this CodeSegment has bug - - private Receiver pnum = ids.create(CommandType.TAKE); - private Receiver mynum; - - public TakePnum(Receiver data){ - this.pnum.setKey("parent", "num"); - this.mynum = data; - } + // this CodeSegment has bug + + private Receiver pnum = ids.create(CommandType.TAKE); + private Receiver mynum; - @Override - public void run() { - ods.update("parent", "num", - this.pnum.asInteger()+this.mynum.asInteger()); - } + public TakePnum(Receiver data){ + this.pnum.setKey("parent", "num"); + this.mynum = data; + } + + @Override + public void run() { + ods.update("parent", "num", + this.pnum.asInteger()+this.mynum.asInteger()); + } }
--- a/src/main/java/alice/test/topology/aquarium/ViewChange.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/ViewChange.java Tue Jul 15 16:00:22 2014 +0900 @@ -8,51 +8,51 @@ public class ViewChange extends Canvas3D { - private static final long serialVersionUID = 1L; - float sensitivity; - float distance = 2.5f; - float camera_x, camera_y, camera_z, camera_xz, camera_xy, camera_yz = 0; - float phi = 0; // flow - float theta = 0; - - SimpleUniverse universe; - TransformGroup Camera; - Transform3D Transform_camera_pos; - Transform3D Transform_camera_phi; - Transform3D Transform_camera_theta; - Vector3f Vector_camera_pos; - - public ViewChange(float x, float Sensitivity, GraphicsConfiguration config){ - super(config); - - sensitivity = Sensitivity; - universe = new SimpleUniverse(this); - ViewingPlatform vp = universe.getViewingPlatform(); - Camera = vp.getViewPlatformTransform(); + private static final long serialVersionUID = 1L; + float sensitivity; + float distance = 2.5f; + float camera_x, camera_y, camera_z, camera_xz, camera_xy, camera_yz = 0; + float phi = 0; // flow + float theta = 0; + + SimpleUniverse universe; + TransformGroup Camera; + Transform3D Transform_camera_pos; + Transform3D Transform_camera_phi; + Transform3D Transform_camera_theta; + Vector3f Vector_camera_pos; + + public ViewChange(float x, float Sensitivity, GraphicsConfiguration config){ + super(config); + + sensitivity = Sensitivity; + universe = new SimpleUniverse(this); + ViewingPlatform vp = universe.getViewingPlatform(); + Camera = vp.getViewPlatformTransform(); - camera_y = distance * (float)Math.sin(theta); - camera_xz = distance * (float)Math.cos(theta); - System.out.println(x); - camera_x = x; - camera_z = camera_xz * (float)Math.cos(phi); - - Vector_camera_pos = new Vector3f(camera_x, camera_y, camera_z); - Transform_camera_pos = new Transform3D(); - Transform_camera_pos.setTranslation(Vector_camera_pos); - Transform_camera_phi = new Transform3D(); - Transform_camera_theta = new Transform3D(); - Transform_camera_theta.rotX(-theta); - Transform_camera_phi.rotY(phi); - Transform_camera_theta.mul(Transform_camera_phi); - Transform_camera_pos.mul(Transform_camera_theta); + camera_y = distance * (float)Math.sin(theta); + camera_xz = distance * (float)Math.cos(theta); + System.out.println(x); + camera_x = x; + camera_z = camera_xz * (float)Math.cos(phi); - Camera.setTransform(Transform_camera_pos); + Vector_camera_pos = new Vector3f(camera_x, camera_y, camera_z); + Transform_camera_pos = new Transform3D(); + Transform_camera_pos.setTranslation(Vector_camera_pos); + Transform_camera_phi = new Transform3D(); + Transform_camera_theta = new Transform3D(); + Transform_camera_theta.rotX(-theta); + Transform_camera_phi.rotY(phi); + Transform_camera_theta.mul(Transform_camera_phi); + Transform_camera_pos.mul(Transform_camera_theta); - addMouseMotionListener(new MouseViewEvent(this)); - - } - - - + Camera.setTransform(Transform_camera_pos); + + addMouseMotionListener(new MouseViewEvent(this)); + + } + + + }
--- a/src/main/java/alice/test/topology/aquarium/fx/AddObject.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/AddObject.java Tue Jul 15 16:00:22 2014 +0900 @@ -8,57 +8,57 @@ import alice.datasegment.Receiver; public class AddObject extends CodeSegment { - // add Object on javaFx Scene - private Receiver info = ids.create(CommandType.TAKE); // objectList - private Receiver info1 = ids.create(CommandType.TAKE); // fish Object made from CreateObject CS - private Receiver info2 = ids.create(CommandType.PEEK); // node name - private boolean executed = false; - - public AddObject(){ - info.setKey("root"); - info1.setKey("addOffer"); - info2.setKey("host"); - } - - @Override - public void run() { - - - if (!executed) { - executed = true; - // javafx's Scene can be accessed only FX application thread. - Platform.runLater(this); - } else { - boolean duplication = false; - Group root = info.asClass(Group.class); - Group obj = info1.asClass(Group.class); - String myName = info2.asString(); - - for (Node n : root.getChildren()){ - if (n.getId().equals(obj.getId())) - duplication = true; - } - - if (!duplication) { - root.getChildren().add(obj); - System.out.println(obj.getId()+" add"); - ods.put(obj.getId()+"Fish", obj); + // add Object on javaFx Scene + private Receiver info = ids.create(CommandType.TAKE); // objectList + private Receiver info1 = ids.create(CommandType.TAKE); // fish Object made from CreateObject CS + private Receiver info2 = ids.create(CommandType.PEEK); // node name + private boolean executed = false; + + public AddObject(){ + info.setKey("root"); + info1.setKey("addOffer"); + info2.setKey("host"); + } + + @Override + public void run() { + + + if (!executed) { + executed = true; + // javafx's Scene can be accessed only FX application thread. + Platform.runLater(this); + } else { + boolean duplication = false; + Group root = info.asClass(Group.class); + Group obj = info1.asClass(Group.class); + String myName = info2.asString(); - // controlled own fish - if (myName.equals(obj.getId())){ - new CalculatePosition(obj.getId()+"FishdiffP"); - } - new SetTranslate(obj.getId()+"Fish"); - - FishInfo fishInfo = new FishInfo(); - fishInfo.name = obj.getId(); - fishInfo.size = obj.getScaleX(); - ods.put("register", fishInfo); - } - ods.flip(info); - new AddObject(); - } - } - + for (Node n : root.getChildren()){ + if (n.getId().equals(obj.getId())) + duplication = true; + } + + if (!duplication) { + root.getChildren().add(obj); + System.out.println(obj.getId()+" add"); + ods.put(obj.getId()+"Fish", obj); + + // controlled own fish + if (myName.equals(obj.getId())){ + new CalculatePosition(obj.getId()+"FishdiffP"); + } + new SetTranslate(obj.getId()+"Fish"); + + FishInfo fishInfo = new FishInfo(); + fishInfo.name = obj.getId(); + fishInfo.size = obj.getScaleX(); + ods.put("register", fishInfo); + } + ods.flip(info); + new AddObject(); + } + } + }
--- a/src/main/java/alice/test/topology/aquarium/fx/Aquarium.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/Aquarium.java Tue Jul 15 16:00:22 2014 +0900 @@ -20,92 +20,92 @@ public class Aquarium extends Application { - private OutputDataSegment ods = new OutputDataSegment(); - - @Override - public void start(Stage primaryStage) throws IOException { - String myName = getParameters().getRaw().get(0); // name - primaryStage.setTitle("Aquarium "+ myName); - primaryStage.setResizable(false); - primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>(){ - @Override - public void handle(WindowEvent event) { - // should send finish DataSegment - System.exit(0); - } - }); - - Scene scene = new Scene(createContent()); - scene.setOnKeyPressed(new EventHandler<KeyEvent>() { - public void handle(KeyEvent t) { - FishInfo info = null; - switch (t.getCode()) { - case RIGHT: - info = new FishInfo(0.1,0,0); - info.rolY = -1; - info.rotate = 90; - break; - case LEFT: - info = new FishInfo(-0.1,0,0); - info.rolY = 1; - info.rotate = 90; - break; - case UP: - info = new FishInfo(0,-0.1,0); - info.rolX = -1; - info.rotate = 90; - break; - case DOWN: - info = new FishInfo(0,0.1,0); - info.rolX = 1; - info.rotate = 90; - break; - case N: - info = new FishInfo(0,0,0.1); - info.rolX = -1; - break; - case M: - info = new FishInfo(0,0,-0.1); - info.rotate = 180; - break; - default: // do nothing - // reset. send median position. after implement - info = new FishInfo(0,0,0); - break; - } - ods.update(myName+"FishdiffP", info); - } - }); - primaryStage.setScene(scene); - primaryStage.show(); - } + private OutputDataSegment ods = new OutputDataSegment(); + + @Override + public void start(Stage primaryStage) throws IOException { + String myName = getParameters().getRaw().get(0); // name + primaryStage.setTitle("Aquarium "+ myName); + primaryStage.setResizable(false); + primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>(){ + @Override + public void handle(WindowEvent event) { + // should send finish DataSegment + System.exit(0); + } + }); - private Parent createContent(){ - Group root = new Group(); - ods.put("root", root); + Scene scene = new Scene(createContent()); + scene.setOnKeyPressed(new EventHandler<KeyEvent>() { + public void handle(KeyEvent t) { + FishInfo info = null; + switch (t.getCode()) { + case RIGHT: + info = new FishInfo(0.1,0,0); + info.rolY = -1; + info.rotate = 90; + break; + case LEFT: + info = new FishInfo(-0.1,0,0); + info.rolY = 1; + info.rotate = 90; + break; + case UP: + info = new FishInfo(0,-0.1,0); + info.rolX = -1; + info.rotate = 90; + break; + case DOWN: + info = new FishInfo(0,0.1,0); + info.rolX = 1; + info.rotate = 90; + break; + case N: + info = new FishInfo(0,0,0.1); + info.rolX = -1; + break; + case M: + info = new FishInfo(0,0,-0.1); + info.rotate = 180; + break; + default: // do nothing + // reset. send median position. after implement + info = new FishInfo(0,0,0); + break; + } + ods.update(myName+"FishdiffP", info); + } + }); + primaryStage.setScene(scene); + primaryStage.show(); + } - // Create and position camera - PerspectiveCamera camera = new PerspectiveCamera(true); - camera.getTransforms().addAll( - new Rotate(0, Rotate.Y_AXIS), - new Rotate(0, Rotate.X_AXIS), - new Translate(0, 0, -15)); - camera.setId("camera"); + private Parent createContent(){ + Group root = new Group(); + ods.put("root", root); - root.getChildren().add(camera); + // Create and position camera + PerspectiveCamera camera = new PerspectiveCamera(true); + camera.getTransforms().addAll( + new Rotate(0, Rotate.Y_AXIS), + new Rotate(0, Rotate.X_AXIS), + new Translate(0, 0, -15)); + camera.setId("camera"); - // Use a SubScene - SubScene subScene = new SubScene(root, 800, 700, true, SceneAntialiasing.BALANCED); - subScene.setFill(Color.TRANSPARENT); - subScene.setCamera(camera); - Group parent = new Group(subScene); + root.getChildren().add(camera); - return parent; - } + // Use a SubScene + SubScene subScene = new SubScene(root, 800, 700, true, SceneAntialiasing.BALANCED); + subScene.setFill(Color.TRANSPARENT); + subScene.setCamera(camera); + Group parent = new Group(subScene); + + return parent; + } - public static void main(String[] args) { - launch(args); - } + public static void main(String[] args) { + launch(args); + } }
--- a/src/main/java/alice/test/topology/aquarium/fx/CalculatePosition.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/CalculatePosition.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,37 +6,37 @@ public class CalculatePosition extends CodeSegment { - private Receiver info = ids.create(CommandType.TAKE); // diff fish position value - private Receiver info1 = ids.create(CommandType.TAKE); // absolute fish position value - private Receiver info2 = ids.create(CommandType.PEEK); - - public CalculatePosition(String key){ - info.setKey(key); - info1.setKey("OwnFishP"); - info2.setKey("host"); - - } - - @Override - public void run() { - FishInfo dfp = info.asClass(FishInfo.class); - FishInfo afp = info1.asClass(FishInfo.class); - String myName = info2.asString(); - - afp.setX(afp.getX() + dfp.getX()); - afp.setY(afp.getY() + dfp.getY()); - afp.setZ(afp.getZ() + dfp.getZ()); - ods.update(info1.key, afp); - - FishInfo fishInfo = new FishInfo(afp.getX(),afp.getY(),afp.getZ()); - fishInfo.rolX = dfp.rolX; - fishInfo.rolY = dfp.rolY; - fishInfo.rolZ = dfp.rolZ; - fishInfo.rotate = dfp.rotate; - ods.update(myName+"FishabsoluteP", fishInfo); - - this.recycle(); - } - + private Receiver info = ids.create(CommandType.TAKE); // diff fish position value + private Receiver info1 = ids.create(CommandType.TAKE); // absolute fish position value + private Receiver info2 = ids.create(CommandType.PEEK); + + public CalculatePosition(String key){ + info.setKey(key); + info1.setKey("OwnFishP"); + info2.setKey("host"); + + } + + @Override + public void run() { + FishInfo dfp = info.asClass(FishInfo.class); + FishInfo afp = info1.asClass(FishInfo.class); + String myName = info2.asString(); + + afp.setX(afp.getX() + dfp.getX()); + afp.setY(afp.getY() + dfp.getY()); + afp.setZ(afp.getZ() + dfp.getZ()); + ods.update(info1.key, afp); + + FishInfo fishInfo = new FishInfo(afp.getX(),afp.getY(),afp.getZ()); + fishInfo.rolX = dfp.rolX; + fishInfo.rolY = dfp.rolY; + fishInfo.rolZ = dfp.rolZ; + fishInfo.rotate = dfp.rotate; + ods.update(myName+"FishabsoluteP", fishInfo); + + this.recycle(); + } + }
--- a/src/main/java/alice/test/topology/aquarium/fx/CheckAllFishInfoExist.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/CheckAllFishInfoExist.java Tue Jul 15 16:00:22 2014 +0900 @@ -15,46 +15,46 @@ import alice.datasegment.Receiver; public class CheckAllFishInfoExist extends CodeSegment { - // this CS check all fish object exist in scene + // this CS check all fish object exist in scene - private Receiver info = ids.create(CommandType.TAKE); // fishInfoList - private Receiver info1 = ids.create(CommandType.PEEK); + private Receiver info = ids.create(CommandType.TAKE); // fishInfoList + private Receiver info1 = ids.create(CommandType.PEEK); - public CheckAllFishInfoExist(){ - info.setKey("receiveRegisteredList"); - info1.setKey("root"); - } + public CheckAllFishInfoExist(){ + info.setKey("receiveRegisteredList"); + info1.setKey("root"); + } - @Override - public void run() { - try { - new SendDataOthers(info, info.key); - ods.put("registeredList", info.getVal()); - ArrayValue fishInfoList = info.asClass(Value.class).asArrayValue(); - MessagePack msg = SingletonMessage.getInstance(); - Group root = info1.asClass(Group.class); - for (Value v : fishInfoList){ - boolean exist = false; - FishInfo info = msg.convert(v, FishInfo.class); - if (info.name != null) { - for (Node n : root.getChildren()) { - if (info.name.equals(n.getId())) { - exist = true; - break; - } - } - - if (!exist) { - info.fromCheckExist = true; - ods.put("fishData", info); - } - } - } + @Override + public void run() { + try { + new SendDataOthers(info, info.key); + ods.put("registeredList", info.getVal()); + ArrayValue fishInfoList = info.asClass(Value.class).asArrayValue(); + MessagePack msg = SingletonMessage.getInstance(); + Group root = info1.asClass(Group.class); + for (Value v : fishInfoList){ + boolean exist = false; + FishInfo info = msg.convert(v, FishInfo.class); + if (info.name != null) { + for (Node n : root.getChildren()) { + if (info.name.equals(n.getId())) { + exist = true; + break; + } + } - } catch (IOException e) { - e.printStackTrace(); - } - this.recycle(); - } + if (!exist) { + info.fromCheckExist = true; + ods.put("fishData", info); + } + } + } + + } catch (IOException e) { + e.printStackTrace(); + } + this.recycle(); + } }
--- a/src/main/java/alice/test/topology/aquarium/fx/CheckMyName.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/CheckMyName.java Tue Jul 15 16:00:22 2014 +0900 @@ -9,47 +9,47 @@ import alice.datasegment.Receiver; public class CheckMyName extends CodeSegment { - private Receiver host = ids.create(CommandType.PEEK); - private Pattern pattern = Pattern.compile("^(node|cli|local)([0-9]+)$"); - private int INNER_WIDTH = 10; - - public CheckMyName(){ - host.setKey("host"); - } + private Receiver host = ids.create(CommandType.PEEK); + private Pattern pattern = Pattern.compile("^(node|cli|local)([0-9]+)$"); + private int INNER_WIDTH = 10; + + public CheckMyName(){ + host.setKey("host"); + } - @Override - public void run() { - String name = host.asString(); - Matcher matcher = pattern.matcher(name); - matcher.find(); + @Override + public void run() { + String name = host.asString(); + Matcher matcher = pattern.matcher(name); + matcher.find(); + + // use view scope + int num = new Integer(matcher.group(2)); + // scope: A_n = 5 + 10(n - 1); + int median = INNER_WIDTH * num; + ods.put("median", median); // node0 median : 0 + // node1 median : 10 + // node2 median : 20 - // use view scope - int num = new Integer(matcher.group(2)); - // scope: A_n = 5 + 10(n - 1); - int median = INNER_WIDTH * num; - ods.put("median", median); // node0 median : 0 - // node1 median : 10 - // node2 median : 20 - - if (num == 0){ - // only root node create fishInfoList registered all fishInfo - // fishInfoList send children for checking all Fish object in own scene - new RegisterList(); - ods.put("registeredList", new ArrayList<FishInfo>()); - } - - new CheckAllFishInfoExist(); + if (num == 0){ + // only root node create fishInfoList registered all fishInfo + // fishInfoList send children for checking all Fish object in own scene + new RegisterList(); + ods.put("registeredList", new ArrayList<FishInfo>()); + } + + new CheckAllFishInfoExist(); - FishInfo fishInfo = new FishInfo(median,0,0); - fishInfo.setName(name); - - ods.put("OwnFishP", fishInfo.clone()); - ods.put("fishData", fishInfo); + FishInfo fishInfo = new FishInfo(median,0,0); + fishInfo.setName(name); + + ods.put("OwnFishP", fishInfo.clone()); + ods.put("fishData", fishInfo); - new CreateObject(); - new AddObject(); - - String[] args = {name}; - Aquarium.main(args); - } + new CreateObject(); + new AddObject(); + + String[] args = {name}; + Aquarium.main(args); + } }
--- a/src/main/java/alice/test/topology/aquarium/fx/CreateObject.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/CreateObject.java Tue Jul 15 16:00:22 2014 +0900 @@ -17,54 +17,54 @@ public class CreateObject extends CodeSegment{ - private Receiver info = ids.create(CommandType.TAKE); // fishInfo - + private Receiver info = ids.create(CommandType.TAKE); // fishInfo + + + public CreateObject(){ + info.setKey("fishData"); - public CreateObject(){ - info.setKey("fishData"); - - } + } + + @Override + public void run() { + FishInfo fishInfo = info.asClass(FishInfo.class); - @Override - public void run() { - FishInfo fishInfo = info.asClass(FishInfo.class); - - Group obj = new Group(); - addColladaObject(obj); + Group obj = new Group(); + addColladaObject(obj); - obj.setScaleX(fishInfo.size); - obj.setScaleY(fishInfo.size); - obj.setScaleZ(fishInfo.size); - obj.setId(fishInfo.name); + obj.setScaleX(fishInfo.size); + obj.setScaleY(fishInfo.size); + obj.setScaleZ(fishInfo.size); + obj.setId(fishInfo.name); + + ods.put("addOffer", obj); + if (!fishInfo.fromCheckExist) + new SendDataOthers(info, "fishData"); - ods.put("addOffer", obj); - if (!fishInfo.fromCheckExist) - new SendDataOthers(info, "fishData"); - - new CreateObject(); - } + new CreateObject(); + } - // for read *.obj file - public void addObject(Group obj){ - BooleanProperty showWireframe = new SimpleBooleanProperty(false); - ObjModelImporter objImporter = new ObjModelImporter(); - objImporter.read(getClass().getClassLoader().getResource("objects/Scooter-smgrps.obj")); + // for read *.obj file + public void addObject(Group obj){ + BooleanProperty showWireframe = new SimpleBooleanProperty(false); + ObjModelImporter objImporter = new ObjModelImporter(); + objImporter.read(getClass().getClassLoader().getResource("objects/Scooter-smgrps.obj")); + + MeshView[] dukeMesh = objImporter.getImport(); + objImporter.close(); - MeshView[] dukeMesh = objImporter.getImport(); - objImporter.close(); + for (MeshView _dukeMesh : dukeMesh) { + obj.getChildren().addAll(_dukeMesh); + _dukeMesh.drawModeProperty().bind(new When(showWireframe).then(DrawMode.LINE).otherwise(DrawMode.FILL)); + } + } - for (MeshView _dukeMesh : dukeMesh) { - obj.getChildren().addAll(_dukeMesh); - _dukeMesh.drawModeProperty().bind(new When(showWireframe).then(DrawMode.LINE).otherwise(DrawMode.FILL)); - } - } - - // for read *.dae file - public void addColladaObject(Group obj){ - ColModelImporter colImporter = new ColModelImporter(); - colImporter.read(getClass().getClassLoader().getResource("objects/seymourplane-150-im.dae")); - Node[] node = colImporter.getImport(); - obj.getChildren().add(node[0]); - } + // for read *.dae file + public void addColladaObject(Group obj){ + ColModelImporter colImporter = new ColModelImporter(); + colImporter.read(getClass().getClassLoader().getResource("objects/seymourplane-150-im.dae")); + Node[] node = colImporter.getImport(); + obj.getChildren().add(node[0]); + } }
--- a/src/main/java/alice/test/topology/aquarium/fx/FishInfo.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/FishInfo.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,67 +4,67 @@ @Message public class FishInfo { - // public fields are serialized. - public double x = 0; - public double y = 0; - public double z = 0; - public String name; - public double size = 0.1; - public String type = "defalut"; // use select object type. after implement may be... - - public double rolX = 0; // these parameters use RotationAxis - public double rolY = 0; - public double rolZ = 0; - public double rotate = 0; - - public boolean fromCheckExist = false; - - public FishInfo(){ - // this constructor is nothing to do, but need for serializing with MessagePack - } - - public FishInfo(double x,double y,double z){ - this.x = x; - this.y = y; - this.z = z; - } - - public void setName(String name){ - this.name = name; - } - - public void setSize(double size){ - this.size = size; - } - - public double getX(){ - return this.x; - } - - public void setX(double x){ - this.x = x; - } - - public double getY(){ - return this.y; - } - - public void setY(double y){ - this.y = y; - } - - public double getZ(){ - return this.z; - } - - public void setZ(double z){ - this.z = z; - } - - public FishInfo clone(){ - FishInfo info = new FishInfo(this.x,this.y,this.z); - info.setName(this.name); - return info; - } + // public fields are serialized. + public double x = 0; + public double y = 0; + public double z = 0; + public String name; + public double size = 0.1; + public String type = "defalut"; // use select object type. after implement may be... + + public double rolX = 0; // these parameters use RotationAxis + public double rolY = 0; + public double rolZ = 0; + public double rotate = 0; + + public boolean fromCheckExist = false; + + public FishInfo(){ + // this constructor is nothing to do, but need for serializing with MessagePack + } + + public FishInfo(double x,double y,double z){ + this.x = x; + this.y = y; + this.z = z; + } + + public void setName(String name){ + this.name = name; + } + + public void setSize(double size){ + this.size = size; + } + + public double getX(){ + return this.x; + } + + public void setX(double x){ + this.x = x; + } + + public double getY(){ + return this.y; + } + + public void setY(double y){ + this.y = y; + } + + public double getZ(){ + return this.z; + } + + public void setZ(double z){ + this.z = z; + } + + public FishInfo clone(){ + FishInfo info = new FishInfo(this.x,this.y,this.z); + info.setName(this.name); + return info; + } }
--- a/src/main/java/alice/test/topology/aquarium/fx/RegisterList.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/RegisterList.java Tue Jul 15 16:00:22 2014 +0900 @@ -8,25 +8,25 @@ public class RegisterList extends CodeSegment{ - private Receiver info = ids.create(CommandType.TAKE); // created fish object info - private Receiver info1 = ids.create(CommandType.TAKE); // created fish List - - public RegisterList(){ - info.setKey("register"); - info1.setKey("registeredList"); - } - - @Override - public void run() { - FishInfo fishInfo = info.asClass(FishInfo.class); - - @SuppressWarnings("unchecked") - List<FishInfo> list = info1.asClass(List.class); - - list.add(fishInfo); - ods.update(info1.key, list); - new SendDataOthers(info1, "receiveRegisteredList"); - new RegisterList(); - } + private Receiver info = ids.create(CommandType.TAKE); // created fish object info + private Receiver info1 = ids.create(CommandType.TAKE); // created fish List + + public RegisterList(){ + info.setKey("register"); + info1.setKey("registeredList"); + } + + @Override + public void run() { + FishInfo fishInfo = info.asClass(FishInfo.class); + + @SuppressWarnings("unchecked") + List<FishInfo> list = info1.asClass(List.class); + + list.add(fishInfo); + ods.update(info1.key, list); + new SendDataOthers(info1, "receiveRegisteredList"); + new RegisterList(); + } }
--- a/src/main/java/alice/test/topology/aquarium/fx/SendDataOthers.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/SendDataOthers.java Tue Jul 15 16:00:22 2014 +0900 @@ -7,26 +7,26 @@ import alice.datasegment.Receiver; public class SendDataOthers extends CodeSegment { - // this CodeSegment is bad. - - private Receiver info = ids.create(CommandType.PEEK); - private Receiver info1; // should use dataSegment - private String key; // should use dataSegment - - public SendDataOthers(Receiver r, String key){ - this.key = key; - info1 = r; - info.setKey("_CLIST"); - } - - @Override - public void run() { - @SuppressWarnings("unchecked") - List<String> nodes = info.asClass(List.class); - for (String node : nodes) { - if (!info1.from.equals(node)) - ods.put(node, key, info1.getVal()); - } - } + // this CodeSegment is bad. + + private Receiver info = ids.create(CommandType.PEEK); + private Receiver info1; // should use dataSegment + private String key; // should use dataSegment + + public SendDataOthers(Receiver r, String key){ + this.key = key; + info1 = r; + info.setKey("_CLIST"); + } + + @Override + public void run() { + @SuppressWarnings("unchecked") + List<String> nodes = info.asClass(List.class); + for (String node : nodes) { + if (!info1.from.equals(node)) + ods.put(node, key, info1.getVal()); + } + } }
--- a/src/main/java/alice/test/topology/aquarium/fx/SetTranslate.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/SetTranslate.java Tue Jul 15 16:00:22 2014 +0900 @@ -8,40 +8,40 @@ import alice.datasegment.Receiver; public class SetTranslate extends CodeSegment { - - private Receiver info = ids.create(CommandType.TAKE); // object instance - private Receiver info1 = ids.create(CommandType.TAKE); // absolute fish position value - private Receiver info2 = ids.create(CommandType.PEEK); // median - private boolean executed = false; - - public SetTranslate(String key) { - info.setKey(key); - info1.setKey(key+"absoluteP"); - info2.setKey("median"); - } + + private Receiver info = ids.create(CommandType.TAKE); // object instance + private Receiver info1 = ids.create(CommandType.TAKE); // absolute fish position value + private Receiver info2 = ids.create(CommandType.PEEK); // median + private boolean executed = false; + + public SetTranslate(String key) { + info.setKey(key); + info1.setKey(key+"absoluteP"); + info2.setKey("median"); + } - @Override - public void run() { - if (!executed) { - executed = true; - new SendDataOthers(info1, info1.key); - // javafx's Scene can be accessed only FX application thread. - Platform.runLater(this); - } else { - Group fish = info.asClass(Group.class); - FishInfo fp = info1.asClass(FishInfo.class); - int median = info2.asInteger(); - - fish.setRotate(fp.rotate); - fish.setRotationAxis(new Point3D(fp.rolX,fp.rolY,fp.rolZ)); - fish.setTranslateX(fp.getX() - median); - fish.setTranslateY(fp.getY()); - fish.setTranslateZ(fp.getZ()); - ods.flip(info); + @Override + public void run() { + if (!executed) { + executed = true; + new SendDataOthers(info1, info1.key); + // javafx's Scene can be accessed only FX application thread. + Platform.runLater(this); + } else { + Group fish = info.asClass(Group.class); + FishInfo fp = info1.asClass(FishInfo.class); + int median = info2.asInteger(); - executed = false; - new SetTranslate(info.key); - } - } + fish.setRotate(fp.rotate); + fish.setRotationAxis(new Point3D(fp.rolX,fp.rolY,fp.rolZ)); + fish.setTranslateX(fp.getX() - median); + fish.setTranslateY(fp.getY()); + fish.setTranslateZ(fp.getZ()); + ods.flip(info); + + executed = false; + new SetTranslate(info.key); + } + } }
--- a/src/main/java/alice/test/topology/aquarium/fx/StartAquariumFX.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/StartAquariumFX.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,15 +4,15 @@ import alice.topology.node.TopologyNodeConfig; public class StartAquariumFX { - public static void main(String args[]){ - TopologyNodeConfig conf = new TopologyNodeConfig(args); - if (conf.getManagerHostName() !=null){ - new TopologyNode(conf, new StartCodeSegment()); - } else { - StartCodeSegment cs = new StartCodeSegment(); - cs.ods.put("host", "local0"); - cs.execute(); - } - } + public static void main(String args[]){ + TopologyNodeConfig conf = new TopologyNodeConfig(args); + if (conf.getManagerHostName() !=null){ + new TopologyNode(conf, new StartCodeSegment()); + } else { + StartCodeSegment cs = new StartCodeSegment(); + cs.ods.put("host", "local0"); + cs.execute(); + } + } }
--- a/src/main/java/alice/test/topology/aquarium/fx/StartCodeSegment.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/StartCodeSegment.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,9 +4,9 @@ public class StartCodeSegment extends CodeSegment{ - @Override - public void run() { - new CheckMyName(); - } + @Override + public void run() { + new CheckMyName(); + } }
--- a/src/main/java/alice/test/topology/fish/AssignStartX.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/fish/AssignStartX.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,35 +6,35 @@ public class AssignStartX extends CodeSegment { - public Receiver routing = ids.create(CommandType.PEEK); - public int startX; - public int index; + public Receiver routing = ids.create(CommandType.PEEK); + public int startX; + public int index; + + public AssignStartX(int startX, int index) { + this.startX = startX; + this.index = index; + } + + @Override + public void run() { + System.out.println("AssignStartX: " + startX); - public AssignStartX(int startX, int index) { - this.startX = startX; - this.index = index; - } - - @Override - public void run() { - System.out.println("AssignStartX: " + startX); - - RoutingTable routing = this.routing.asClass(RoutingTable.class); - int x = startX; - System.out.println("RoutingTable: " + this.routing.getVal()); - if (this.index >= this.routing.index) { - AssignStartX cs = new AssignStartX(startX, index); - cs.routing.setKey("local", "routing", this.routing.index); - return; - } - for (Routing r : routing.table) { - System.out.println(r.name); - ods.update(r.name, "startX", x); - System.out.println("Assign: " + r.name + ".startX = " + x); - x += r.width; - } - PeekStartX cs = new PeekStartX(this.routing.index); - cs.startX.setKey("local", "startX", this.index); - } + RoutingTable routing = this.routing.asClass(RoutingTable.class); + int x = startX; + System.out.println("RoutingTable: " + this.routing.getVal()); + if (this.index >= this.routing.index) { + AssignStartX cs = new AssignStartX(startX, index); + cs.routing.setKey("local", "routing", this.routing.index); + return; + } + for (Routing r : routing.table) { + System.out.println(r.name); + ods.update(r.name, "startX", x); + System.out.println("Assign: " + r.name + ".startX = " + x); + x += r.width; + } + PeekStartX cs = new PeekStartX(this.routing.index); + cs.startX.setKey("local", "startX", this.index); + } }
--- a/src/main/java/alice/test/topology/fish/CheckMyName.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/fish/CheckMyName.java Tue Jul 15 16:00:22 2014 +0900 @@ -8,51 +8,51 @@ import alice.datasegment.Receiver; public class CheckMyName extends CodeSegment { - - private Receiver host = ids.create(CommandType.PEEK); - - public CheckMyName(){ - host.setKey("host"); - } - - @Override - public void run() { - String name = host.asString(); - Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$"); - Matcher matcher = pattern.matcher(name); - - matcher.find(); - String type = matcher.group(1); - int num = new Integer(matcher.group(2)); - - if (type.equals("cli")) { - System.out.println("********************I am cli" + num); - ods.update("local", "width", 400); - - GetStartX cs = new GetStartX(); - cs.startX.setKey("local", "startX"); - - } else if (type.equals("node")) { - System.out.println("********************I am node" + num); - WidthReceiver cs = new WidthReceiver(); - cs.widths.setKey("local", "widths"); - cs.routing.setKey("local", "routing"); - - PeekStartX cs2 = new PeekStartX(0); - cs2.startX.setKey("local", "startX"); - - ods.put("local", "routing", new RoutingTable()); - if (num == 0) { // First node ("node0") check - StartStartX cs3 = new StartStartX(); - cs3.width.setKey("local", "width"); - //ods.update("local", "startX", 0); - return; - } - } - - SendWidth cs = new SendWidth(); - cs.width.setKey("local", "width"); + + private Receiver host = ids.create(CommandType.PEEK); + + public CheckMyName(){ + host.setKey("host"); + } + + @Override + public void run() { + String name = host.asString(); + Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$"); + Matcher matcher = pattern.matcher(name); + + matcher.find(); + String type = matcher.group(1); + int num = new Integer(matcher.group(2)); + + if (type.equals("cli")) { + System.out.println("********************I am cli" + num); + ods.update("local", "width", 400); - } + GetStartX cs = new GetStartX(); + cs.startX.setKey("local", "startX"); + + } else if (type.equals("node")) { + System.out.println("********************I am node" + num); + WidthReceiver cs = new WidthReceiver(); + cs.widths.setKey("local", "widths"); + cs.routing.setKey("local", "routing"); + + PeekStartX cs2 = new PeekStartX(0); + cs2.startX.setKey("local", "startX"); + + ods.put("local", "routing", new RoutingTable()); + if (num == 0) { // First node ("node0") check + StartStartX cs3 = new StartStartX(); + cs3.width.setKey("local", "width"); + //ods.update("local", "startX", 0); + return; + } + } + + SendWidth cs = new SendWidth(); + cs.width.setKey("local", "width"); + + } }
--- a/src/main/java/alice/test/topology/fish/DistributedFish.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/fish/DistributedFish.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,10 +4,10 @@ public class DistributedFish { - public static void main(String[] args) { - FishConfig conf = new FishConfig(args); - new TopologyNode(conf, new StartFish()); + public static void main(String[] args) { + FishConfig conf = new FishConfig(args); + new TopologyNode(conf, new StartFish()); - } + } }
--- a/src/main/java/alice/test/topology/fish/FishConfig.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/fish/FishConfig.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,9 +4,9 @@ public class FishConfig extends TopologyNodeConfig { - public FishConfig(String[] args) { - super(args); - - } - + public FishConfig(String[] args) { + super(args); + + } + }
--- a/src/main/java/alice/test/topology/fish/GetStartX.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/fish/GetStartX.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,16 +6,16 @@ public class GetStartX extends CodeSegment { - public Receiver startX = ids.create(CommandType.PEEK); - - @Override - public void run() { - int startX = this.startX.asInteger(); - - System.out.println("GetStartX: " + startX); - - GetStartX cs = new GetStartX(); - cs.startX.setKey("local", "startX", this.startX.index); - } + public Receiver startX = ids.create(CommandType.PEEK); + + @Override + public void run() { + int startX = this.startX.asInteger(); + + System.out.println("GetStartX: " + startX); + + GetStartX cs = new GetStartX(); + cs.startX.setKey("local", "startX", this.startX.index); + } }
--- a/src/main/java/alice/test/topology/fish/PeekStartX.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/fish/PeekStartX.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,18 +6,18 @@ public class PeekStartX extends CodeSegment { - public Receiver startX = ids.create(CommandType.PEEK); - public int index; - - public PeekStartX(int index) { - this.index = index; - } - - @Override - public void run() { - int startX = this.startX.asInteger(); - AssignStartX cs = new AssignStartX(startX, this.startX.index); - cs.routing.setKey("routing", this.startX.index); - } + public Receiver startX = ids.create(CommandType.PEEK); + public int index; + + public PeekStartX(int index) { + this.index = index; + } + + @Override + public void run() { + int startX = this.startX.asInteger(); + AssignStartX cs = new AssignStartX(startX, this.startX.index); + cs.routing.setKey("routing", this.startX.index); + } }
--- a/src/main/java/alice/test/topology/fish/Routing.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/fish/Routing.java Tue Jul 15 16:00:22 2014 +0900 @@ -9,27 +9,27 @@ @Message public class Routing { - public String name; - public int id; - public int width; - @Optional public int startX; - - public Routing() {} - - public Routing(String name, int width) { - this.name = name; - this.width = width; - Pattern pattern = Pattern.compile("^child([0-9]+)$"); - Matcher matcher = pattern.matcher(name); - matcher.find(); - id = new Integer(matcher.group(1)); - } + public String name; + public int id; + public int width; + @Optional public int startX; + + public Routing() {} - public Routing(String name, int id, int width, int startX) { - this.name = name; - this.id = id; - this.width = width; - this.startX = startX; - } - + public Routing(String name, int width) { + this.name = name; + this.width = width; + Pattern pattern = Pattern.compile("^child([0-9]+)$"); + Matcher matcher = pattern.matcher(name); + matcher.find(); + id = new Integer(matcher.group(1)); + } + + public Routing(String name, int id, int width, int startX) { + this.name = name; + this.id = id; + this.width = width; + this.startX = startX; + } + }
--- a/src/main/java/alice/test/topology/fish/RoutingTable.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/fish/RoutingTable.java Tue Jul 15 16:00:22 2014 +0900 @@ -8,7 +8,7 @@ @Message public class RoutingTable { - int sumWidth = 0; - List<Routing> table = new ArrayList<Routing>(); - + int sumWidth = 0; + List<Routing> table = new ArrayList<Routing>(); + }
--- a/src/main/java/alice/test/topology/fish/SendWidth.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/fish/SendWidth.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,18 +5,18 @@ import alice.datasegment.Receiver; public class SendWidth extends CodeSegment { - - Receiver width = ids.create(CommandType.PEEK); + + Receiver width = ids.create(CommandType.PEEK); - @Override - public void run() { - int width = this.width.asInteger(); - ods.put("parent", "widths", width); - - System.out.println("send widths: " + width); - - SendWidth cs = new SendWidth(); - cs.width.setKey("width", this.width.index); - } + @Override + public void run() { + int width = this.width.asInteger(); + ods.put("parent", "widths", width); + + System.out.println("send widths: " + width); + + SendWidth cs = new SendWidth(); + cs.width.setKey("width", this.width.index); + } }
--- a/src/main/java/alice/test/topology/fish/StartFish.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/fish/StartFish.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,10 +4,10 @@ public class StartFish extends CodeSegment { - @Override - public void run() { - new CheckMyName(); // separate processing - - } + @Override + public void run() { + new CheckMyName(); // separate processing + + } }
--- a/src/main/java/alice/test/topology/fish/StartStartX.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/fish/StartStartX.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,14 +5,14 @@ import alice.datasegment.Receiver; public class StartStartX extends CodeSegment { - - public Receiver width = ids.create(CommandType.PEEK); - - @Override - public void run() { - ods.update("local", "startX", 0); - StartStartX cs = new StartStartX(); - cs.width.setKey("local", "width", this.width.index); - } + + public Receiver width = ids.create(CommandType.PEEK); + + @Override + public void run() { + ods.update("local", "startX", 0); + StartStartX cs = new StartStartX(); + cs.width.setKey("local", "width", this.width.index); + } }
--- a/src/main/java/alice/test/topology/fish/WidthReceiver.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/fish/WidthReceiver.java Tue Jul 15 16:00:22 2014 +0900 @@ -12,90 +12,90 @@ import alice.datasegment.Receiver; public class WidthReceiver extends CodeSegment { - - public Receiver widths = ids.create(CommandType.TAKE); - public Receiver routing = ids.create(CommandType.PEEK); - - @Override - public void run() { - int width = this.widths.asInteger(); - String from = this.widths.from; - RoutingTable routing = this.routing.asClass(RoutingTable.class); - Routing newRouting = new Routing(from, width); - boolean update = false; - for (Routing r : routing.table) { - if (r.id == newRouting.id) { - routing.sumWidth -= r.width; - routing.sumWidth += newRouting.width; - r.width = width; - update = true; - break; - } - } - if (!update) { - routing.table.add(newRouting); - Collections.sort(routing.table, new Comparator<Routing>() { - @Override - public int compare(Routing o1, Routing o2) { - return o1.id - o2.id; - } + + public Receiver widths = ids.create(CommandType.TAKE); + public Receiver routing = ids.create(CommandType.PEEK); - @Override - public Comparator<Routing> reversed() { - return null; - } + @Override + public void run() { + int width = this.widths.asInteger(); + String from = this.widths.from; + RoutingTable routing = this.routing.asClass(RoutingTable.class); + Routing newRouting = new Routing(from, width); + boolean update = false; + for (Routing r : routing.table) { + if (r.id == newRouting.id) { + routing.sumWidth -= r.width; + routing.sumWidth += newRouting.width; + r.width = width; + update = true; + break; + } + } + if (!update) { + routing.table.add(newRouting); + Collections.sort(routing.table, new Comparator<Routing>() { + @Override + public int compare(Routing o1, Routing o2) { + return o1.id - o2.id; + } - @Override - public Comparator<Routing> thenComparing( - Comparator<? super Routing> other) { - return null; - } + @Override + public Comparator<Routing> reversed() { + return null; + } + + @Override + public Comparator<Routing> thenComparing( + Comparator<? super Routing> other) { + return null; + } - @Override - public <U> Comparator<Routing> thenComparing( - Function<? super Routing, ? extends U> keyExtractor, - Comparator<? super U> keyComparator) { - return null; - } + @Override + public <U> Comparator<Routing> thenComparing( + Function<? super Routing, ? extends U> keyExtractor, + Comparator<? super U> keyComparator) { + return null; + } - @Override - public <U extends Comparable<? super U>> Comparator<Routing> thenComparing( - Function<? super Routing, ? extends U> keyExtractor) { - return null; - } + @Override + public <U extends Comparable<? super U>> Comparator<Routing> thenComparing( + Function<? super Routing, ? extends U> keyExtractor) { + return null; + } - @Override - public Comparator<Routing> thenComparingInt( - ToIntFunction<? super Routing> keyExtractor) { - return null; - } + @Override + public Comparator<Routing> thenComparingInt( + ToIntFunction<? super Routing> keyExtractor) { + return null; + } - @Override - public Comparator<Routing> thenComparingLong( - ToLongFunction<? super Routing> keyExtractor) { - return null; - } + @Override + public Comparator<Routing> thenComparingLong( + ToLongFunction<? super Routing> keyExtractor) { + return null; + } - @Override - public Comparator<Routing> thenComparingDouble( - ToDoubleFunction<? super Routing> keyExtractor) { - return null; - } - }); - routing.sumWidth += width; - } - - System.out.println("SUM WIDTH: " + routing.sumWidth); - - System.out.println("NODE NUM: " + routing.table.size()); - - ods.update("width", routing.sumWidth); - ods.update("routing", routing); - - WidthReceiver cs = new WidthReceiver(); - cs.widths.setKey("widths", this.widths.index); - cs.routing.setKey("routing"); - //cs.routing.setKey("routing", this.routing.index); - } + @Override + public Comparator<Routing> thenComparingDouble( + ToDoubleFunction<? super Routing> keyExtractor) { + return null; + } + }); + routing.sumWidth += width; + } + + System.out.println("SUM WIDTH: " + routing.sumWidth); + + System.out.println("NODE NUM: " + routing.table.size()); + + ods.update("width", routing.sumWidth); + ods.update("routing", routing); + + WidthReceiver cs = new WidthReceiver(); + cs.widths.setKey("widths", this.widths.index); + cs.routing.setKey("routing"); + //cs.routing.setKey("routing", this.routing.index); + } }
--- a/src/main/java/alice/test/topology/ring/CheckMyName.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/ring/CheckMyName.java Tue Jul 15 16:00:22 2014 +0900 @@ -8,32 +8,32 @@ public class CheckMyName extends CodeSegment { - public Receiver ds1 = ids.create(CommandType.PEEK); - - private Logger logger = Logger.getLogger(CheckMyName.class); - private RingTopologyConfig conf; - - public CheckMyName(RingTopologyConfig conf) { - this.conf = conf; - } - - @Override - public void run() { - String host = this.ds1.asString(); - logger.debug(host); - if (host.equals("node0")) { - ods.put("local", "c", new byte[conf.size]); - FirstRingMessagePassing cs1 = new FirstRingMessagePassing(conf.count, conf.nodeNum); - cs1.ds1.setKey("c"); - RingFinish cs2 = new RingFinish("manager"); - cs2.finish.setKey("finish"); - } else { - ods.close("manager"); - RingMessagePassing cs1 = new RingMessagePassing(); - cs1.ds1.setKey("c"); - RingFinish cs2 = new RingFinish("right"); - cs2.finish.setKey("finish"); - } - } + public Receiver ds1 = ids.create(CommandType.PEEK); + + private Logger logger = Logger.getLogger(CheckMyName.class); + private RingTopologyConfig conf; + + public CheckMyName(RingTopologyConfig conf) { + this.conf = conf; + } + + @Override + public void run() { + String host = this.ds1.asString(); + logger.debug(host); + if (host.equals("node0")) { + ods.put("local", "c", new byte[conf.size]); + FirstRingMessagePassing cs1 = new FirstRingMessagePassing(conf.count, conf.nodeNum); + cs1.ds1.setKey("c"); + RingFinish cs2 = new RingFinish("manager"); + cs2.finish.setKey("finish"); + } else { + ods.close("manager"); + RingMessagePassing cs1 = new RingMessagePassing(); + cs1.ds1.setKey("c"); + RingFinish cs2 = new RingFinish("right"); + cs2.finish.setKey("finish"); + } + } }
--- a/src/main/java/alice/test/topology/ring/FirstRingMessagePassing.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/ring/FirstRingMessagePassing.java Tue Jul 15 16:00:22 2014 +0900 @@ -7,37 +7,37 @@ import alice.datasegment.Receiver; public class FirstRingMessagePassing extends CodeSegment { - - public Receiver ds1 = ids.create(CommandType.TAKE); - private long startTime; - private int count; - private int nodeNum; - - public FirstRingMessagePassing(long startTime, int count, int nodeNum) { - this.startTime = startTime; - this.count = count; - this.nodeNum = nodeNum; - } - - public FirstRingMessagePassing(int count, int nodeNum) { // at first - this.startTime = System.nanoTime(); - this.count = count; - this.nodeNum = nodeNum; - } - - @Override - public void run() { - ods.put("right", "c", ds1.getVal()); // copy whole DataSegment to the right - if (ds1.index > count) { // after count time update of ds1 - ods.put("right", "finish", ValueFactory.createNilValue()); - long endTime = System.nanoTime(); - long time = endTime - startTime; - System.out.println(nodeNum + " " + time / count / 1000000.0); - return; - } - - FirstRingMessagePassing cs = new FirstRingMessagePassing(startTime, count, nodeNum); - cs.ds1.setKey("c"); - } + + public Receiver ds1 = ids.create(CommandType.TAKE); + private long startTime; + private int count; + private int nodeNum; + + public FirstRingMessagePassing(long startTime, int count, int nodeNum) { + this.startTime = startTime; + this.count = count; + this.nodeNum = nodeNum; + } + + public FirstRingMessagePassing(int count, int nodeNum) { // at first + this.startTime = System.nanoTime(); + this.count = count; + this.nodeNum = nodeNum; + } + + @Override + public void run() { + ods.put("right", "c", ds1.getVal()); // copy whole DataSegment to the right + if (ds1.index > count) { // after count time update of ds1 + ods.put("right", "finish", ValueFactory.createNilValue()); + long endTime = System.nanoTime(); + long time = endTime - startTime; + System.out.println(nodeNum + " " + time / count / 1000000.0); + return; + } + + FirstRingMessagePassing cs = new FirstRingMessagePassing(startTime, count, nodeNum); + cs.ds1.setKey("c"); + } }
--- a/src/main/java/alice/test/topology/ring/RingFinish.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/ring/RingFinish.java Tue Jul 15 16:00:22 2014 +0900 @@ -7,18 +7,18 @@ import alice.datasegment.Receiver; public class RingFinish extends CodeSegment { - - private String sendKey; - public Receiver finish = ids.create(CommandType.TAKE); - - public RingFinish(String sendKey) { - this.sendKey = sendKey; - } + + private String sendKey; + public Receiver finish = ids.create(CommandType.TAKE); - @Override - public void run() { - ods.put(sendKey, "finish", ValueFactory.createNilValue()); - ods.finish(sendKey); - } + public RingFinish(String sendKey) { + this.sendKey = sendKey; + } + + @Override + public void run() { + ods.put(sendKey, "finish", ValueFactory.createNilValue()); + ods.finish(sendKey); + } }
--- a/src/main/java/alice/test/topology/ring/RingMessagePassing.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/ring/RingMessagePassing.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,13 +6,13 @@ public class RingMessagePassing extends CodeSegment { - public Receiver ds1 = ids.create(CommandType.TAKE); + public Receiver ds1 = ids.create(CommandType.TAKE); - @Override - public void run() { - ods.put("right", "c", this.ds1.getVal()); - RingMessagePassing cs = new RingMessagePassing(); - cs.ds1.setKey("c"); - } + @Override + public void run() { + ods.put("right", "c", this.ds1.getVal()); + RingMessagePassing cs = new RingMessagePassing(); + cs.ds1.setKey("c"); + } }
--- a/src/main/java/alice/test/topology/ring/RingTopology.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/ring/RingTopology.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,10 +3,10 @@ import alice.topology.node.TopologyNode; public class RingTopology { - - public static void main(String[] args) { - RingTopologyConfig conf = new RingTopologyConfig(args); - new TopologyNode(conf, new StartRing(conf)); - } - + + public static void main(String[] args) { + RingTopologyConfig conf = new RingTopologyConfig(args); + new TopologyNode(conf, new StartRing(conf)); + } + }
--- a/src/main/java/alice/test/topology/ring/RingTopologyConfig.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/ring/RingTopologyConfig.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,22 +3,22 @@ import alice.topology.node.TopologyNodeConfig; public class RingTopologyConfig extends TopologyNodeConfig { - - public int count = 10; - public int size = 10; - public int nodeNum = 10; - - public RingTopologyConfig(String[] args) { - super(args); - for (int i = 0; i < args.length; i++) { - if ("-count".equals(args[i])) { - this.count = Integer.parseInt(args[++i]); - } else if ("-size".equals(args[i])) { - this.size = Integer.parseInt(args[++i]); - } else if ("-nodeNum".equals(args[i])) { - this.nodeNum = Integer.parseInt(args[++i]); - } - } - } + + public int count = 10; + public int size = 10; + public int nodeNum = 10; + + public RingTopologyConfig(String[] args) { + super(args); + for (int i = 0; i < args.length; i++) { + if ("-count".equals(args[i])) { + this.count = Integer.parseInt(args[++i]); + } else if ("-size".equals(args[i])) { + this.size = Integer.parseInt(args[++i]); + } else if ("-nodeNum".equals(args[i])) { + this.nodeNum = Integer.parseInt(args[++i]); + } + } + } }
--- a/src/main/java/alice/test/topology/ring/StartRing.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/ring/StartRing.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,14 +3,14 @@ import alice.codesegment.CodeSegment; public class StartRing extends CodeSegment { - private RingTopologyConfig conf; - public StartRing(RingTopologyConfig conf) { - this.conf = conf; - } - @Override - public void run() { - CheckMyName cs = new CheckMyName(conf); - cs.ds1.setKey("host"); - } + private RingTopologyConfig conf; + public StartRing(RingTopologyConfig conf) { + this.conf = conf; + } + @Override + public void run() { + CheckMyName cs = new CheckMyName(conf); + cs.ds1.setKey("host"); + } }
--- a/src/main/java/alice/test/topology/share/AutoIncrement.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/share/AutoIncrement.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,24 +5,24 @@ import alice.datasegment.Receiver; public class AutoIncrement extends CodeSegment { - - public Receiver position = ids.create(CommandType.PEEK); - - public AutoIncrement(String key,int index){ - this.position.setKey(key, index); - } + + public Receiver position = ids.create(CommandType.PEEK); + + public AutoIncrement(String key,int index){ + this.position.setKey(key, index); + } - @Override - public void run() { - synchronized(this){ - try { - wait(50); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - ods.update(position.key, new DataInfo(System.nanoTime())); - new AutoIncrement(position.key ,position.index); - } - + @Override + public void run() { + synchronized(this){ + try { + wait(50); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + ods.update(position.key, new DataInfo(System.nanoTime())); + new AutoIncrement(position.key ,position.index); + } + }
--- a/src/main/java/alice/test/topology/share/CheckLocalIndex.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/share/CheckLocalIndex.java Tue Jul 15 16:00:22 2014 +0900 @@ -8,37 +8,37 @@ public class CheckLocalIndex extends CodeSegment { - private Receiver data = ids.create(CommandType.PEEK); - private Receiver list = ids.create(CommandType.PEEK); - private Receiver host = ids.create(CommandType.PEEK); + private Receiver data = ids.create(CommandType.PEEK); + private Receiver list = ids.create(CommandType.PEEK); + private Receiver host = ids.create(CommandType.PEEK); + + + public CheckLocalIndex(String key, int index) { + this.host.setKey("host"); + this.list.setKey("_CLIST"); + this.data.setKey(key, index); + } - - public CheckLocalIndex(String key, int index) { - this.host.setKey("host"); - this.list.setKey("_CLIST"); - this.data.setKey(key, index); - } - - @Override - public void run() { - @SuppressWarnings("unchecked") - List<String> r = list.asClass(List.class); - int count = 0; - boolean flag = false; - for (String node : r) { - if (node.equals("parent")) { - flag = true; - } - if (!node.equals(this.data.from)) { - ods.update(node, data.key, data.getVal()); - count++; - } - } - if (count == 0 && flag) { - ods.put("parent", "data", data.getVal()); - } - new CheckLocalIndex(data.key, data.index); - - } + @Override + public void run() { + @SuppressWarnings("unchecked") + List<String> r = list.asClass(List.class); + int count = 0; + boolean flag = false; + for (String node : r) { + if (node.equals("parent")) { + flag = true; + } + if (!node.equals(this.data.from)) { + ods.update(node, data.key, data.getVal()); + count++; + } + } + if (count == 0 && flag) { + ods.put("parent", "data", data.getVal()); + } + new CheckLocalIndex(data.key, data.index); + + } }
--- a/src/main/java/alice/test/topology/share/CheckMyName.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/share/CheckMyName.java Tue Jul 15 16:00:22 2014 +0900 @@ -9,40 +9,40 @@ public class CheckMyName extends CodeSegment { - Receiver host = ids.create(CommandType.PEEK); - Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$"); - String key = "fish"; - - public CheckMyName(){ - this.host.setKey("host"); - } - - @Override - public void run(){ - - String name = host.asString(); - Matcher matcher = pattern.matcher(name); - - matcher.find(); - String type = matcher.group(1); - int num = new Integer(matcher.group(2)); - - if (type.equals("cli")){ - System.out.println("cli"+num); - new SendData(0); - - }else if (type.equals("node")){ - System.out.println("node"+num); - if (num != 0){ - new SendData(0); - }else{ - new LookUpData("data",0); - } - } - for (int i =0 ;i<1000000;i++){} - ods.update(key, new DataInfo()); - - if (num == 0) new AutoIncrement(key,0); - new CheckLocalIndex(key,1); - } + Receiver host = ids.create(CommandType.PEEK); + Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$"); + String key = "fish"; + + public CheckMyName(){ + this.host.setKey("host"); + } + + @Override + public void run(){ + + String name = host.asString(); + Matcher matcher = pattern.matcher(name); + + matcher.find(); + String type = matcher.group(1); + int num = new Integer(matcher.group(2)); + + if (type.equals("cli")){ + System.out.println("cli"+num); + new SendData(0); + + }else if (type.equals("node")){ + System.out.println("node"+num); + if (num != 0){ + new SendData(0); + }else{ + new LookUpData("data",0); + } + } + for (int i =0 ;i<1000000;i++){} + ods.update(key, new DataInfo()); + + if (num == 0) new AutoIncrement(key,0); + new CheckLocalIndex(key,1); + } }
--- a/src/main/java/alice/test/topology/share/DataInfo.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/share/DataInfo.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,19 +4,19 @@ @Message public class DataInfo { - public long setTime = 0; - - public DataInfo(){} - - public DataInfo(long t){ - setTime = t; - } - - public void setTime(long t){ - setTime = t; - } - - public long getTime(){ - return setTime; - } + public long setTime = 0; + + public DataInfo(){} + + public DataInfo(long t){ + setTime = t; + } + + public void setTime(long t){ + setTime = t; + } + + public long getTime(){ + return setTime; + } }
--- a/src/main/java/alice/test/topology/share/LookUpData.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/share/LookUpData.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,27 +6,27 @@ public class LookUpData extends CodeSegment{ - private Receiver data = ids.create(CommandType.PEEK); - String key; - int depth; - - public LookUpData(String key,int index){ - this.key = key; - this.data.setKey(key, index); - } - - public LookUpData(String key,int index, int depth){ - this.key = key; - this.depth = depth; - this.data.setKey(key, index); - } + private Receiver data = ids.create(CommandType.PEEK); + String key; + int depth; + + public LookUpData(String key,int index){ + this.key = key; + this.data.setKey(key, index); + } - @Override - public void run(){ - new LookUpData(this.key,this.data.index); - DataInfo di = data.asClass(DataInfo.class); - System.out.println(System.nanoTime()-di.getTime()); + public LookUpData(String key,int index, int depth){ + this.key = key; + this.depth = depth; + this.data.setKey(key, index); + } - } - + @Override + public void run(){ + new LookUpData(this.key,this.data.index); + DataInfo di = data.asClass(DataInfo.class); + System.out.println(System.nanoTime()-di.getTime()); + + } + } \ No newline at end of file
--- a/src/main/java/alice/test/topology/share/SendData.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/share/SendData.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,16 +5,16 @@ import alice.datasegment.Receiver; public class SendData extends CodeSegment{ - private Receiver data = ids.create(CommandType.PEEK); - - public SendData(int index){ - this.data.setKey("data", index); - } - - @Override - public void run(){ - new SendData(this.data.index); - ods.put("parent", "data", this.data.getVal()); - } - + private Receiver data = ids.create(CommandType.PEEK); + + public SendData(int index){ + this.data.setKey("data", index); + } + + @Override + public void run(){ + new SendData(this.data.index); + ods.put("parent", "data", this.data.getVal()); + } + } \ No newline at end of file
--- a/src/main/java/alice/test/topology/share/ShareConfig.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/share/ShareConfig.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,10 +3,10 @@ import alice.topology.node.TopologyNodeConfig; public class ShareConfig extends TopologyNodeConfig { - - public ShareConfig(String[] args){ - super(args); - } - + + public ShareConfig(String[] args){ + super(args); + } + }
--- a/src/main/java/alice/test/topology/share/ShareTopology.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/share/ShareTopology.java Tue Jul 15 16:00:22 2014 +0900 @@ -2,10 +2,10 @@ import alice.topology.node.TopologyNode; public class ShareTopology { - public static void main(String[] args){ - ShareConfig conf = new ShareConfig(args); - new TopologyNode(conf, new StartFishMovement()); - - } + public static void main(String[] args){ + ShareConfig conf = new ShareConfig(args); + new TopologyNode(conf, new StartFishMovement()); + + } }
--- a/src/main/java/alice/test/topology/share/StartFishMovement.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/topology/share/StartFishMovement.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,10 +3,10 @@ import alice.codesegment.CodeSegment; public class StartFishMovement extends CodeSegment{ - @Override - public void run(){ - new CheckMyName(); - } - + @Override + public void run(){ + new CheckMyName(); + } + }
--- a/src/main/java/alice/topology/HostMessage.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/HostMessage.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,25 +4,25 @@ @Message public class HostMessage { - - public String name; - public int port; - public String connectionName; - public String reverseName; - public String absName; - public String parentAbsName; - - public HostMessage() { } - public HostMessage(String name, int port) { - this.name = name; - this.port = port; - } + + public String name; + public int port; + public String connectionName; + public String reverseName; + public String absName; + public String parentAbsName; - public HostMessage(String name, int port, String connectionName, String reverseName) { - this.name = name; - this.port = port; - this.connectionName = connectionName; - this.reverseName = reverseName; - } - + public HostMessage() { } + public HostMessage(String name, int port) { + this.name = name; + this.port = port; + } + + public HostMessage(String name, int port, String connectionName, String reverseName) { + this.name = name; + this.port = port; + this.connectionName = connectionName; + this.reverseName = reverseName; + } + }
--- a/src/main/java/alice/topology/manager/ComingServiceHosts.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/ComingServiceHosts.java Tue Jul 15 16:00:22 2014 +0900 @@ -12,49 +12,49 @@ public class ComingServiceHosts extends CodeSegment{ - Receiver info = ids.create(CommandType.TAKE); - Receiver info1 = ids.create(CommandType.TAKE); - Receiver info2 = ids.create(CommandType.TAKE); // HashMap - int BINATY_TREE = 2; - - public ComingServiceHosts(){ - info.setKey("host"); - info1.setKey("hostCount"); - info2.setKey("nodeConnectionInfo"); - } - - @Override - public void run() { - HostMessage host = info.asClass(HostMessage.class); - int comingHostCount = info1.asInteger(); - @SuppressWarnings("unchecked") - HashMap<String, HostMessage> parentInfo = info2.asClass(HashMap.class); - String nodeName = "node"+comingHostCount; - // Manager connect to Node - DataSegment.connect(nodeName, "", host.name, host.port); - ods.put(nodeName, "host", nodeName); - ods.update(info1.key, comingHostCount+1); - - for (int i=1;i < BINATY_TREE+1; i++) { - int num = 2 * comingHostCount+i; - HostMessage newHost = new HostMessage(host.name, host.port, "parent", "child"+(i-1)); - newHost.parentAbsName = nodeName; - newHost.absName = "node"+num; - parentInfo.put(newHost.absName, newHost); - ods.put(newHost.absName, newHost); - } - if (comingHostCount!=0) { - HostMessage parent = parentInfo.get(nodeName); - HostMessage newHost = new HostMessage(host.name, host.port, parent.reverseName, parent.connectionName); - ods.put(parent.parentAbsName, newHost); - } - - ods.put("nodeConnectionInfo", parentInfo); - ods.put(nodeName, ValueFactory.createNilValue()); - if (comingHostCount==0) - ods.put("start", ValueFactory.createNilValue()); - - this.recycle(); - } + Receiver info = ids.create(CommandType.TAKE); + Receiver info1 = ids.create(CommandType.TAKE); + Receiver info2 = ids.create(CommandType.TAKE); // HashMap + int BINATY_TREE = 2; + + public ComingServiceHosts(){ + info.setKey("host"); + info1.setKey("hostCount"); + info2.setKey("nodeConnectionInfo"); + } + + @Override + public void run() { + HostMessage host = info.asClass(HostMessage.class); + int comingHostCount = info1.asInteger(); + @SuppressWarnings("unchecked") + HashMap<String, HostMessage> parentInfo = info2.asClass(HashMap.class); + String nodeName = "node"+comingHostCount; + // Manager connect to Node + DataSegment.connect(nodeName, "", host.name, host.port); + ods.put(nodeName, "host", nodeName); + ods.update(info1.key, comingHostCount+1); + + for (int i=1;i < BINATY_TREE+1; i++) { + int num = 2 * comingHostCount+i; + HostMessage newHost = new HostMessage(host.name, host.port, "parent", "child"+(i-1)); + newHost.parentAbsName = nodeName; + newHost.absName = "node"+num; + parentInfo.put(newHost.absName, newHost); + ods.put(newHost.absName, newHost); + } + if (comingHostCount!=0) { + HostMessage parent = parentInfo.get(nodeName); + HostMessage newHost = new HostMessage(host.name, host.port, parent.reverseName, parent.connectionName); + ods.put(parent.parentAbsName, newHost); + } + + ods.put("nodeConnectionInfo", parentInfo); + ods.put(nodeName, ValueFactory.createNilValue()); + if (comingHostCount==0) + ods.put("start", ValueFactory.createNilValue()); + + this.recycle(); + } }
--- a/src/main/java/alice/topology/manager/ConfigWaiter.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/ConfigWaiter.java Tue Jul 15 16:00:22 2014 +0900 @@ -7,23 +7,23 @@ import alice.datasegment.Receiver; public class ConfigWaiter extends CodeSegment { - - public Receiver done = ids.create(CommandType.TAKE); - public int count; - - public ConfigWaiter(int nodeNum) { - this.count = nodeNum; - } + + public Receiver done = ids.create(CommandType.TAKE); + public int count; + + public ConfigWaiter(int nodeNum) { + this.count = nodeNum; + } - @Override - public void run() { - count--; - if (count == 0) { - ods.put("local", "start", ValueFactory.createNilValue()); - return; - } - ConfigWaiter cs3 = new ConfigWaiter(count); - cs3.done.setKey("local", "done"); - } + @Override + public void run() { + count--; + if (count == 0) { + ods.put("local", "start", ValueFactory.createNilValue()); + return; + } + ConfigWaiter cs3 = new ConfigWaiter(count); + cs3.done.setKey("local", "done"); + } }
--- a/src/main/java/alice/topology/manager/NodeInfo.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/NodeInfo.java Tue Jul 15 16:00:22 2014 +0900 @@ -1,14 +1,14 @@ package alice.topology.manager; public class NodeInfo { - - public String sourceNodeName; - public String connectionName; - public String reverseName; - - public NodeInfo(String source, String connection) { - this.sourceNodeName = source; - this.connectionName = connection; - } - + + public String sourceNodeName; + public String connectionName; + public String reverseName; + + public NodeInfo(String source, String connection) { + this.sourceNodeName = source; + this.connectionName = connection; + } + }
--- a/src/main/java/alice/topology/manager/StartTopologyManager.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/StartTopologyManager.java Tue Jul 15 16:00:22 2014 +0900 @@ -20,74 +20,74 @@ public class StartTopologyManager extends CodeSegment { - TopologyManagerConfig conf; - Logger logger = Logger.getLogger(StartTopologyManager.class); + TopologyManagerConfig conf; + Logger logger = Logger.getLogger(StartTopologyManager.class); - public StartTopologyManager(TopologyManagerConfig conf) { - this.conf = conf; - } + public StartTopologyManager(TopologyManagerConfig conf) { + this.conf = conf; + } - @Override - public void run() { - if (!conf.extendTopology) { - LinkedList<String> nodeNames = new LinkedList<String>(); - HashMap<String, LinkedList<NodeInfo>> topology = new HashMap<String, LinkedList<NodeInfo>>(); - int nodeNum = 0; - try { - FileReader reader = new FileReader(new File(conf.confFilePath)); - Parser parser = new Parser(); - parser.parse(reader); - ArrayList<Graph> graphs = parser.getGraphs(); - for (Graph graph : graphs) { - ArrayList<Node> nodes = graph.getNodes(false); - nodeNum = nodes.size(); - for (Node node : nodes) { - String nodeName = node.getId().getId(); - nodeNames.add(nodeName); - topology.put(nodeName, new LinkedList<NodeInfo>()); - } - ArrayList<Edge> edges = graph.getEdges(); - HashMap<String, NodeInfo> hash = new HashMap<String, NodeInfo>(); - for (Edge edge : edges) { - String connection = edge.getAttribute("label"); - String source = edge.getSource().getNode().getId().getId(); - String target = edge.getTarget().getNode().getId().getId(); - LinkedList<NodeInfo> sources = topology.get(target); - NodeInfo nodeInfo = new NodeInfo(source, connection); - sources.add(nodeInfo); - hash.put(source + "," + target, nodeInfo); - } - for (Edge edge : edges) { - String connection = edge.getAttribute("label"); - String source = edge.getSource().getNode().getId().getId(); - String target = edge.getTarget().getNode().getId().getId(); - NodeInfo nodeInfo = hash.get(target + "," + source); - if (nodeInfo != null) { - nodeInfo.reverseName = connection; - } - } - } + @Override + public void run() { + if (!conf.extendTopology) { + LinkedList<String> nodeNames = new LinkedList<String>(); + HashMap<String, LinkedList<NodeInfo>> topology = new HashMap<String, LinkedList<NodeInfo>>(); + int nodeNum = 0; + try { + FileReader reader = new FileReader(new File(conf.confFilePath)); + Parser parser = new Parser(); + parser.parse(reader); + ArrayList<Graph> graphs = parser.getGraphs(); + for (Graph graph : graphs) { + ArrayList<Node> nodes = graph.getNodes(false); + nodeNum = nodes.size(); + for (Node node : nodes) { + String nodeName = node.getId().getId(); + nodeNames.add(nodeName); + topology.put(nodeName, new LinkedList<NodeInfo>()); + } + ArrayList<Edge> edges = graph.getEdges(); + HashMap<String, NodeInfo> hash = new HashMap<String, NodeInfo>(); + for (Edge edge : edges) { + String connection = edge.getAttribute("label"); + String source = edge.getSource().getNode().getId().getId(); + String target = edge.getTarget().getNode().getId().getId(); + LinkedList<NodeInfo> sources = topology.get(target); + NodeInfo nodeInfo = new NodeInfo(source, connection); + sources.add(nodeInfo); + hash.put(source + "," + target, nodeInfo); + } + for (Edge edge : edges) { + String connection = edge.getAttribute("label"); + String source = edge.getSource().getNode().getId().getId(); + String target = edge.getTarget().getNode().getId().getId(); + NodeInfo nodeInfo = hash.get(target + "," + source); + if (nodeInfo != null) { + nodeInfo.reverseName = connection; + } + } + } - } catch (FileNotFoundException e) { - logger.error("File not found: " + conf.confFilePath); - e.printStackTrace(); - } catch (ParseException e) { - logger.error("File format error: " + conf.confFilePath); - e.printStackTrace(); - } + } catch (FileNotFoundException e) { + logger.error("File not found: " + conf.confFilePath); + e.printStackTrace(); + } catch (ParseException e) { + logger.error("File format error: " + conf.confFilePath); + e.printStackTrace(); + } - new IncomingHosts(topology, nodeNames); + new IncomingHosts(topology, nodeNames); - ConfigWaiter cs3 = new ConfigWaiter(nodeNum); - cs3.done.setKey("local", "done"); - } else { - System.out.println("mode -t"); - HashMap<String,HostMessage> parentInfo = new HashMap<String,HostMessage>(); - int cominghostCount = 0; - ods.put("nodeConnectionInfo", parentInfo); - ods.put("hostCount", cominghostCount); - new ComingServiceHosts(); - } - } + ConfigWaiter cs3 = new ConfigWaiter(nodeNum); + cs3.done.setKey("local", "done"); + } else { + System.out.println("mode -t"); + HashMap<String,HostMessage> parentInfo = new HashMap<String,HostMessage>(); + int cominghostCount = 0; + ods.put("nodeConnectionInfo", parentInfo); + ods.put("hostCount", cominghostCount); + new ComingServiceHosts(); + } + } }
--- a/src/main/java/alice/topology/manager/TopologyFinish.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/TopologyFinish.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,10 +5,10 @@ import alice.datasegment.Receiver; public class TopologyFinish extends CodeSegment { - public Receiver finish = ids.create(CommandType.TAKE); - @Override - public void run() { - System.exit(0); - } + public Receiver finish = ids.create(CommandType.TAKE); + @Override + public void run() { + System.exit(0); + } }
--- a/src/main/java/alice/topology/manager/TopologyManager.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/TopologyManager.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,10 +4,10 @@ public class TopologyManager { - public static void main(String[] args) { - TopologyManagerConfig conf = new TopologyManagerConfig(args); - new AliceDaemon(conf).listen(); - new StartTopologyManager(conf).execute(); - } + public static void main(String[] args) { + TopologyManagerConfig conf = new TopologyManagerConfig(args); + new AliceDaemon(conf).listen(); + new StartTopologyManager(conf).execute(); + } }
--- a/src/main/java/alice/topology/manager/TopologyManagerConfig.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/TopologyManagerConfig.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,19 +3,19 @@ import alice.daemon.Config; public class TopologyManagerConfig extends Config { - - public String confFilePath; - public boolean extendTopology = false; - - public TopologyManagerConfig(String[] args) { - super(args); - for (int i = 0; i < args.length; i++) { - if ("-conf".equals(args[i])) { - confFilePath = args[++i]; - } else if ("-t".equals(args[i])) { - extendTopology = true; - } - } - } + + public String confFilePath; + public boolean extendTopology = false; + + public TopologyManagerConfig(String[] args) { + super(args); + for (int i = 0; i < args.length; i++) { + if ("-conf".equals(args[i])) { + confFilePath = args[++i]; + } else if ("-t".equals(args[i])) { + extendTopology = true; + } + } + } }
--- a/src/main/java/alice/topology/manager/keeparive/CheckExistTask.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/keeparive/CheckExistTask.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,16 +5,16 @@ import alice.datasegment.Receiver; public class CheckExistTask extends CodeSegment{ - private Receiver info = ids.create(CommandType.PEEK); // TaskInfo - - public CheckExistTask(){ - info.setKey("_TASKINFO"); - } - - @Override - public void run() { - new CreateSchedule(); - - } + private Receiver info = ids.create(CommandType.PEEK); // TaskInfo + + public CheckExistTask(){ + info.setKey("_TASKINFO"); + } + + @Override + public void run() { + new CreateSchedule(); + + } }
--- a/src/main/java/alice/topology/manager/keeparive/CreateSchedule.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/keeparive/CreateSchedule.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,20 +5,20 @@ import alice.datasegment.Receiver; public class CreateSchedule extends CodeSegment{ - private Receiver info1 = ids.create(CommandType.TAKE); // WaitingList - private Receiver info2 = ids.create(CommandType.TAKE); // TaskInfo - - public CreateSchedule(){ - info1.setKey("_WAITINGLIST"); - info2.setKey("_TASKINFO"); - } + private Receiver info1 = ids.create(CommandType.TAKE); // WaitingList + private Receiver info2 = ids.create(CommandType.TAKE); // TaskInfo + + public CreateSchedule(){ + info1.setKey("_WAITINGLIST"); + info2.setKey("_TASKINFO"); + } - @Override - public void run() { - ListManager manager = info1.asClass(ListManager.class); - TaskInfo newTask = info2.asClass(TaskInfo.class); - manager.addTask(newTask); - ods.update("_WAITINGLIST", manager); - new CheckExistTask(); - } + @Override + public void run() { + ListManager manager = info1.asClass(ListManager.class); + TaskInfo newTask = info2.asClass(TaskInfo.class); + manager.addTask(newTask); + ods.update("_WAITINGLIST", manager); + new CheckExistTask(); + } }
--- a/src/main/java/alice/topology/manager/keeparive/CreateTask.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/keeparive/CreateTask.java Tue Jul 15 16:00:22 2014 +0900 @@ -7,28 +7,28 @@ import alice.datasegment.Receiver; public class CreateTask extends CodeSegment{ - private Receiver info = ids.create(CommandType.PEEK); - - public CreateTask(){ - info.setKey("_CLIST"); - } - - @Override - public void run(){ - ods.put("_WAITINGLIST", new ListManager()); - @SuppressWarnings("unchecked") - List<String> list = info.asClass(List.class); - - new CheckExistTask(); - TaskExecuter.getInstance().setKey(); - for (String manager : list){ - int i = 5; - TaskInfo task = new TaskInfo(TaskType.PING); - task.setInfo(manager, "_FORM_"+manager, i * 1000); - ods.put("_TASKINFO", task); - i +=5; - } - - } + private Receiver info = ids.create(CommandType.PEEK); + + public CreateTask(){ + info.setKey("_CLIST"); + } + + @Override + public void run(){ + ods.put("_WAITINGLIST", new ListManager()); + @SuppressWarnings("unchecked") + List<String> list = info.asClass(List.class); + + new CheckExistTask(); + TaskExecuter.getInstance().setKey(); + for (String manager : list){ + int i = 5; + TaskInfo task = new TaskInfo(TaskType.PING); + task.setInfo(manager, "_FORM_"+manager, i * 1000); + ods.put("_TASKINFO", task); + i +=5; + } + + } }
--- a/src/main/java/alice/topology/manager/keeparive/KeepAlive.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/keeparive/KeepAlive.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,9 +4,9 @@ import alice.topology.node.TopologyNodeConfig; public class KeepAlive { - public static void main(String[] args) { - TopologyNodeConfig conf = new TopologyNodeConfig(args); - new TopologyNode(conf, new StartKeepAlive()); - } + public static void main(String[] args) { + TopologyNodeConfig conf = new TopologyNodeConfig(args); + new TopologyNode(conf, new StartKeepAlive()); + } }
--- a/src/main/java/alice/topology/manager/keeparive/ListManager.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/keeparive/ListManager.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,83 +3,83 @@ import java.util.LinkedList; public class ListManager { - private LinkedList<TaskInfo> list = new LinkedList<TaskInfo>(); + private LinkedList<TaskInfo> list = new LinkedList<TaskInfo>(); - public LinkedList<TaskInfo> getTaskList() { - return list; - } + public LinkedList<TaskInfo> getTaskList() { + return list; + } - public void addTask(TaskInfo newInfo) { - TaskExecuter exec = TaskExecuter.getInstance(); - TaskInfo nowTask = exec.getNowTask(); - if (nowTask == null) { // active task is nothing - add(newInfo); - } else { - long remainingTime = exec.getRemainingTime(); - if (remainingTime > newInfo.getSleepTime()) { - // active task is longer than newTask. - TaskInfo task = nowTask.clone(); - task.setSleepTime(remainingTime); - list.addFirst(task); - add(newInfo); - exec.ignore(); - } else { - // newTask is longer than active task. - newInfo.setSleepTime(newInfo.getSleepTime() - remainingTime); - add(newInfo); - } - } - show(); - } + public void addTask(TaskInfo newInfo) { + TaskExecuter exec = TaskExecuter.getInstance(); + TaskInfo nowTask = exec.getNowTask(); + if (nowTask == null) { // active task is nothing + add(newInfo); + } else { + long remainingTime = exec.getRemainingTime(); + if (remainingTime > newInfo.getSleepTime()) { + // active task is longer than newTask. + TaskInfo task = nowTask.clone(); + task.setSleepTime(remainingTime); + list.addFirst(task); + add(newInfo); + exec.ignore(); + } else { + // newTask is longer than active task. + newInfo.setSleepTime(newInfo.getSleepTime() - remainingTime); + add(newInfo); + } + } + show(); + } - private void add(TaskInfo newInfo){ - int cnt = 0; - for (TaskInfo info : list){ - if (info.getSleepTime() < newInfo.getSleepTime()){ - newInfo.setSleepTime(newInfo.getSleepTime() - info.getSleepTime()); - } else if (info.getSleepTime() == newInfo.getSleepTime()){ - // newInfo.getSleepTime() - info.getSleepTime() must be Zero - newInfo.setSleepTime(0); - cnt++; - break; - } else if (info.getSleepTime() > newInfo.getSleepTime()){ - info.setSleepTime(info.getSleepTime() - newInfo.getSleepTime()); - break; - } - cnt++; - } - list.add(cnt, newInfo); - } - - public boolean deleteTask(TaskInfo task){ - boolean matchFlag = false; - int cnt = 0; - for (TaskInfo t: list){ - if (t.getType().equals(task.getType())){ - matchFlag = true; - if (cnt+1 < list.size() ){ // next task exists. - TaskInfo next = list.get(cnt+1); - next.setSleepTime(next.getSleepTime()+task.getSleepTime()); - } - list.remove(cnt); - break; - } else { - cnt++; - } - } - return matchFlag; - } - - public void show(){ - if (TaskExecuter.getInstance().getNowTask()!=null){ - System.out.print("NOW | "); - System.out.print(TaskExecuter.getInstance().getNowTask().getSleepTime()); - System.out.print(" | "); - } - for (TaskInfo info : list){ - System.out.print(info.getSleepTime()); - System.out.print(" | "); - } - System.out.println(); - } + private void add(TaskInfo newInfo){ + int cnt = 0; + for (TaskInfo info : list){ + if (info.getSleepTime() < newInfo.getSleepTime()){ + newInfo.setSleepTime(newInfo.getSleepTime() - info.getSleepTime()); + } else if (info.getSleepTime() == newInfo.getSleepTime()){ + // newInfo.getSleepTime() - info.getSleepTime() must be Zero + newInfo.setSleepTime(0); + cnt++; + break; + } else if (info.getSleepTime() > newInfo.getSleepTime()){ + info.setSleepTime(info.getSleepTime() - newInfo.getSleepTime()); + break; + } + cnt++; + } + list.add(cnt, newInfo); + } + + public boolean deleteTask(TaskInfo task){ + boolean matchFlag = false; + int cnt = 0; + for (TaskInfo t: list){ + if (t.getType().equals(task.getType())){ + matchFlag = true; + if (cnt+1 < list.size() ){ // next task exists. + TaskInfo next = list.get(cnt+1); + next.setSleepTime(next.getSleepTime()+task.getSleepTime()); + } + list.remove(cnt); + break; + } else { + cnt++; + } + } + return matchFlag; + } + + public void show(){ + if (TaskExecuter.getInstance().getNowTask()!=null){ + System.out.print("NOW | "); + System.out.print(TaskExecuter.getInstance().getNowTask().getSleepTime()); + System.out.print(" | "); + } + for (TaskInfo info : list){ + System.out.print(info.getSleepTime()); + System.out.print(" | "); + } + System.out.println(); + } }
--- a/src/main/java/alice/topology/manager/keeparive/ListManagerTest.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/keeparive/ListManagerTest.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,44 +3,44 @@ import java.util.LinkedList; public class ListManagerTest { - public static void main(String args[]){ - TaskExecuter.getInstance().getNowTask(); - ListManager manager = new ListManager(); - LinkedList<String> nameList = new LinkedList<String>(); - nameList.add("nodeA"); - nameList.add("nodeB"); - nameList.add("nodeC"); - nameList.add("nodeD"); - - TaskInfo taskA = new TaskInfo(TaskType.PING); - taskA.setInfo("node0", "_TEST", 3 * 1000); - TaskExecuter.getInstance().setNowTask(taskA); - - int i = 5; - for (String name : nameList){ - TaskInfo task = new TaskInfo(TaskType.PING); - task.setInfo(name, "_TEST", i * 1000); - System.out.println(task.getSleepTime()); - manager.addTask(task); - manager.show(); - i +=1; - } - TaskExecuter.getInstance().skip(); - i = 11; - for (String name : nameList){ - TaskInfo task = new TaskInfo(TaskType.PING); - task.setInfo(name, "_TEST", i * 1000); - System.out.println(task.getSleepTime()); - manager.addTask(task); - manager.show(); - i +=1; - } - - manager = new ListManager(); - System.out.println(TaskExecuter.getInstance().getRemainingTime()); - TaskExecuter.getInstance().setNowTask(taskA); - TaskExecuter.getInstance().skip(); - System.out.println(TaskExecuter.getInstance().getRemainingTime()); + public static void main(String args[]){ + TaskExecuter.getInstance().getNowTask(); + ListManager manager = new ListManager(); + LinkedList<String> nameList = new LinkedList<String>(); + nameList.add("nodeA"); + nameList.add("nodeB"); + nameList.add("nodeC"); + nameList.add("nodeD"); + + TaskInfo taskA = new TaskInfo(TaskType.PING); + taskA.setInfo("node0", "_TEST", 3 * 1000); + TaskExecuter.getInstance().setNowTask(taskA); - } + int i = 5; + for (String name : nameList){ + TaskInfo task = new TaskInfo(TaskType.PING); + task.setInfo(name, "_TEST", i * 1000); + System.out.println(task.getSleepTime()); + manager.addTask(task); + manager.show(); + i +=1; + } + TaskExecuter.getInstance().skip(); + i = 11; + for (String name : nameList){ + TaskInfo task = new TaskInfo(TaskType.PING); + task.setInfo(name, "_TEST", i * 1000); + System.out.println(task.getSleepTime()); + manager.addTask(task); + manager.show(); + i +=1; + } + + manager = new ListManager(); + System.out.println(TaskExecuter.getInstance().getRemainingTime()); + TaskExecuter.getInstance().setNowTask(taskA); + TaskExecuter.getInstance().skip(); + System.out.println(TaskExecuter.getInstance().getRemainingTime()); + + } } \ No newline at end of file
--- a/src/main/java/alice/topology/manager/keeparive/RemoveTask.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/keeparive/RemoveTask.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,29 +5,29 @@ import alice.datasegment.Receiver; public class RemoveTask extends CodeSegment { - private Receiver info1 = ids.create(CommandType.TAKE); // list - private Receiver info2 = ids.create(CommandType.TAKE); // remove task + private Receiver info1 = ids.create(CommandType.TAKE); // list + private Receiver info2 = ids.create(CommandType.TAKE); // remove task - public RemoveTask(){ - info1.setKey("_WAITINGLIST"); - info2.setKey("_REMOVETASK"); - } + public RemoveTask(){ + info1.setKey("_WAITINGLIST"); + info2.setKey("_REMOVETASK"); + } - @Override - public void run() { - ListManager list = info1.asClass(ListManager.class); // explicit cast - TaskInfo task = info2.asClass(TaskInfo.class); - TaskExecuter exec = TaskExecuter.getInstance(); - if (exec.compareNowTask(task)){ - // case: remove task is state countdown. - exec.skip(); - } else { - // case: remove task is still in the waiting queue. - boolean removeFlag = list.deleteTask(task); - if (!removeFlag){ - ods.put("_REMOVETASK", task); - } - } - ods.update("_WAITINGLIST", list); - } + @Override + public void run() { + ListManager list = info1.asClass(ListManager.class); // explicit cast + TaskInfo task = info2.asClass(TaskInfo.class); + TaskExecuter exec = TaskExecuter.getInstance(); + if (exec.compareNowTask(task)){ + // case: remove task is state countdown. + exec.skip(); + } else { + // case: remove task is still in the waiting queue. + boolean removeFlag = list.deleteTask(task); + if (!removeFlag){ + ods.put("_REMOVETASK", task); + } + } + ods.update("_WAITINGLIST", list); + } }
--- a/src/main/java/alice/topology/manager/keeparive/RespondData.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/keeparive/RespondData.java Tue Jul 15 16:00:22 2014 +0900 @@ -1,11 +1,11 @@ package alice.topology.manager.keeparive; public class RespondData { - public String from; - public long time; - - public RespondData(String str, long t){ - from = str; - time = t; - } + public String from; + public long time; + + public RespondData(String str, long t){ + from = str; + time = t; + } }
--- a/src/main/java/alice/topology/manager/keeparive/RespondPing.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/keeparive/RespondPing.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,38 +6,38 @@ import alice.datasegment.Receiver; public class RespondPing extends CodeSegment{ - private Receiver respond = ids.create(CommandType.TAKE); - private long pingedTime = System.currentTimeMillis(); - - public RespondPing(String key) { - respond.setKey(key); - } + private Receiver respond = ids.create(CommandType.TAKE); + private long pingedTime = System.currentTimeMillis(); + + public RespondPing(String key) { + respond.setKey(key); + } - @Override - public void run() { - RespondData d = respond.asClass(RespondData.class); - System.out.print("ping from "+d.from); - System.out.println(" Recieved time "+(d.time - pingedTime)); - if (d.time - pingedTime > 60 * 1000){ - // need check, this connection is alive. may be close - DataSegment.get(d.from).shutdown(); - } else { - // if nowTask close d.from's socket cancel. - // if not remove close task in the Queue. - TaskExecuter exec = TaskExecuter.getInstance(); - TaskInfo task = new TaskInfo(TaskType.CLOSE); - task.setInfo(d.from, null, 0); - if (exec.compareNowTask(task)){ - // case: remove task is state countdown. - exec.skip(); // countdown - } else { - // case: remove task is still in the waiting queue. - ods.put("_REMOVETASK",task); - new RemoveTask(); - } - TaskInfo task2 = new TaskInfo(TaskType.PING); - task2.setInfo(d.from, "_FORM_"+d.from, 5 * 1000); - ods.put("_TASKINFO", task2); - } - } + @Override + public void run() { + RespondData d = respond.asClass(RespondData.class); + System.out.print("ping from "+d.from); + System.out.println(" Recieved time "+(d.time - pingedTime)); + if (d.time - pingedTime > 60 * 1000){ + // need check, this connection is alive. may be close + DataSegment.get(d.from).shutdown(); + } else { + // if nowTask close d.from's socket cancel. + // if not remove close task in the Queue. + TaskExecuter exec = TaskExecuter.getInstance(); + TaskInfo task = new TaskInfo(TaskType.CLOSE); + task.setInfo(d.from, null, 0); + if (exec.compareNowTask(task)){ + // case: remove task is state countdown. + exec.skip(); // countdown + } else { + // case: remove task is still in the waiting queue. + ods.put("_REMOVETASK",task); + new RemoveTask(); + } + TaskInfo task2 = new TaskInfo(TaskType.PING); + task2.setInfo(d.from, "_FORM_"+d.from, 5 * 1000); + ods.put("_TASKINFO", task2); + } + } }
--- a/src/main/java/alice/topology/manager/keeparive/StartKeepAlive.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/keeparive/StartKeepAlive.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,10 +4,10 @@ public class StartKeepAlive extends CodeSegment { - @Override - public void run() { - new CreateTask(); + @Override + public void run() { + new CreateTask(); - } + } }
--- a/src/main/java/alice/topology/manager/keeparive/TaskExecuter.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/keeparive/TaskExecuter.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,123 +6,123 @@ import alice.datasegment.Receiver; public class TaskExecuter extends CodeSegment { - private Receiver info = ids.create(CommandType.TAKE); - private TaskInfo nowTask; - private boolean sleepFlag = false; - private boolean skipFlag = false; - private long startTime = 0; - private long remainingTime = 0; - private static TaskExecuter instance = new TaskExecuter(); + private Receiver info = ids.create(CommandType.TAKE); + private TaskInfo nowTask; + private boolean sleepFlag = false; + private boolean skipFlag = false; + private long startTime = 0; + private long remainingTime = 0; + private static TaskExecuter instance = new TaskExecuter(); + + private TaskExecuter() {} + public static TaskExecuter getInstance() { + return instance; + } + + public void setKey() { + ids.init(); + info.setKey("_WAITINGLIST"); + } - private TaskExecuter() {} - public static TaskExecuter getInstance() { - return instance; - } + @Override + public synchronized void run() { + ListManager list = info.asClass(ListManager.class); + if (list.getTaskList().size() == 0){ + remainingTime = 0; + ods.update("_WAITINGLIST", list); + } else { + nowTask = list.getTaskList().poll(); + ods.update("_WAITINGLIST", list); - public void setKey() { - ids.init(); - info.setKey("_WAITINGLIST"); - } + if (skipFlag) { + skipFlag = false; + nowTask.setSleepTime(remainingTime + nowTask.getSleepTime()); + remainingTime = 0; + } + + startTime = System.currentTimeMillis(); + System.out.println(nowTask.getSleepTime()+" "+nowTask.getType()); + if (nowTask.getSleepTime() != 0){ + sleepFlag = true; + try { + wait(nowTask.getSleepTime()); + } catch (InterruptedException e) { + e.printStackTrace(); + } + sleepFlag = false; + } - @Override - public synchronized void run() { - ListManager list = info.asClass(ListManager.class); - if (list.getTaskList().size() == 0){ - remainingTime = 0; - ods.update("_WAITINGLIST", list); - } else { - nowTask = list.getTaskList().poll(); - ods.update("_WAITINGLIST", list); - - if (skipFlag) { - skipFlag = false; - nowTask.setSleepTime(remainingTime + nowTask.getSleepTime()); - remainingTime = 0; - } - - startTime = System.currentTimeMillis(); - System.out.println(nowTask.getSleepTime()+" "+nowTask.getType()); - if (nowTask.getSleepTime() != 0){ - sleepFlag = true; - try { - wait(nowTask.getSleepTime()); - } catch (InterruptedException e) { - e.printStackTrace(); - } - sleepFlag = false; - } - - if (!skipFlag){ - // ping or close - if (nowTask.getType() == TaskType.PING) { - ods.ping(nowTask.getManagerKey(), nowTask.getReturnKey()); - TaskInfo task = new TaskInfo(TaskType.CLOSE); - task.setInfo(nowTask.getManagerKey(), 10 * 1000); - ods.put("_TASKINFO", task); - new RespondPing(nowTask.getReturnKey()); - } else if (nowTask.getType() == TaskType.CLOSE) { - // no response from the Remote DataSegment. So close this connection. - System.out.println("SHOTDOWN"); - DataSegment.get(nowTask.getManagerKey()).shutdown(); - } - } - nowTask = null; - startTime = 0; - } - setKey(); - } - - public synchronized void skip() { - if (sleepFlag){ - skipFlag = true; - if (startTime == 0){ - remainingTime = nowTask.getSleepTime(); - } else { - remainingTime = nowTask.getSleepTime() - (System.currentTimeMillis() - startTime); - } - nowTask = null; - notify(); - } - } + if (!skipFlag){ + // ping or close + if (nowTask.getType() == TaskType.PING) { + ods.ping(nowTask.getManagerKey(), nowTask.getReturnKey()); + TaskInfo task = new TaskInfo(TaskType.CLOSE); + task.setInfo(nowTask.getManagerKey(), 10 * 1000); + ods.put("_TASKINFO", task); + new RespondPing(nowTask.getReturnKey()); + } else if (nowTask.getType() == TaskType.CLOSE) { + // no response from the Remote DataSegment. So close this connection. + System.out.println("SHOTDOWN"); + DataSegment.get(nowTask.getManagerKey()).shutdown(); + } + } + nowTask = null; + startTime = 0; + } + setKey(); + } + + public synchronized void skip() { + if (sleepFlag){ + skipFlag = true; + if (startTime == 0){ + remainingTime = nowTask.getSleepTime(); + } else { + remainingTime = nowTask.getSleepTime() - (System.currentTimeMillis() - startTime); + } + nowTask = null; + notify(); + } + } - public synchronized void ignore() { - if (sleepFlag){ - skipFlag = true; - remainingTime = 0; - nowTask = null; - notify(); - } - } + public synchronized void ignore() { + if (sleepFlag){ + skipFlag = true; + remainingTime = 0; + nowTask = null; + notify(); + } + } - public synchronized TaskInfo getNowTask() { - return nowTask; - } + public synchronized TaskInfo getNowTask() { + return nowTask; + } - // only use in ListManagerTest - public synchronized void setNowTask(TaskInfo info) { - nowTask = info; - } + // only use in ListManagerTest + public synchronized void setNowTask(TaskInfo info) { + nowTask = info; + } - public synchronized long getRemainingTime() { - if (sleepFlag) { - if (startTime !=0) { - return nowTask.getSleepTime() - (System.currentTimeMillis() - startTime); - } else { - return nowTask.getSleepTime(); - } - } else { - return remainingTime; - } - } + public synchronized long getRemainingTime() { + if (sleepFlag) { + if (startTime !=0) { + return nowTask.getSleepTime() - (System.currentTimeMillis() - startTime); + } else { + return nowTask.getSleepTime(); + } + } else { + return remainingTime; + } + } - public boolean compareNowTask(TaskInfo task) { - if (nowTask != null){ - if (nowTask.getType().equals(task.getType()) - && nowTask.getManagerKey().equals(task.getManagerKey())){ - return true; - } - } - return false; - } + public boolean compareNowTask(TaskInfo task) { + if (nowTask != null){ + if (nowTask.getType().equals(task.getType()) + && nowTask.getManagerKey().equals(task.getManagerKey())){ + return true; + } + } + return false; + } } \ No newline at end of file
--- a/src/main/java/alice/topology/manager/keeparive/TaskInfo.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/keeparive/TaskInfo.java Tue Jul 15 16:00:22 2014 +0900 @@ -1,56 +1,56 @@ package alice.topology.manager.keeparive; public class TaskInfo { - private TaskType type; - private long sleepTime; - private String managerKey; - private String returnKey; - - public TaskInfo(TaskType t){ - type = t; - } - - public void setInfo(String managerKey, long time){ - this.managerKey = managerKey; - sleepTime = time; - } - - public void setInfo(String managerKey, String returnKey, long time){ - this.managerKey = managerKey; - this.returnKey = returnKey; - sleepTime = time; - } - - public TaskType getType(){ - return type; - } - - public long getSleepTime(){ - return sleepTime; - } - - public void setSleepTime(long time){ - sleepTime = time; - } + private TaskType type; + private long sleepTime; + private String managerKey; + private String returnKey; + + public TaskInfo(TaskType t){ + type = t; + } + + public void setInfo(String managerKey, long time){ + this.managerKey = managerKey; + sleepTime = time; + } + + public void setInfo(String managerKey, String returnKey, long time){ + this.managerKey = managerKey; + this.returnKey = returnKey; + sleepTime = time; + } + + public TaskType getType(){ + return type; + } - public String getManagerKey(){ - return managerKey; - } - - public String getReturnKey(){ - return returnKey; - } - - public TaskInfo clone(){ - TaskInfo task = new TaskInfo(type); - task.setInfo(managerKey, returnKey, sleepTime); - return task; - } - - public void show(){ - System.out.print(type); - System.out.print(" "+ this.sleepTime); - System.out.print(" "+ this.managerKey); - System.out.println(" "+ this.returnKey); - } + public long getSleepTime(){ + return sleepTime; + } + + public void setSleepTime(long time){ + sleepTime = time; + } + + public String getManagerKey(){ + return managerKey; + } + + public String getReturnKey(){ + return returnKey; + } + + public TaskInfo clone(){ + TaskInfo task = new TaskInfo(type); + task.setInfo(managerKey, returnKey, sleepTime); + return task; + } + + public void show(){ + System.out.print(type); + System.out.print(" "+ this.sleepTime); + System.out.print(" "+ this.managerKey); + System.out.println(" "+ this.returnKey); + } }
--- a/src/main/java/alice/topology/manager/keeparive/TaskType.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/manager/keeparive/TaskType.java Tue Jul 15 16:00:22 2014 +0900 @@ -1,6 +1,6 @@ package alice.topology.manager.keeparive; public enum TaskType { - PING, - CLOSE, + PING, + CLOSE, }
--- a/src/main/java/alice/topology/node/ConfigurationFinish.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/node/ConfigurationFinish.java Tue Jul 15 16:00:22 2014 +0900 @@ -8,28 +8,28 @@ public class ConfigurationFinish extends CodeSegment { - public Receiver reverseCount = ids.create(CommandType.PEEK); - public Receiver configNodeNum = ids.create(CommandType.PEEK); - private CodeSegment startCS; - - public ConfigurationFinish(CodeSegment startCS) { - this.startCS = startCS; - } - - @Override - public void run() { - if (reverseCount.getVal().equals(configNodeNum.getVal())) { - - ods.put("manager", "done", ValueFactory.createNilValue()); - Start cs = new Start(startCS); - cs.runningFlag.setKey("local", "running"); - cs.done.setKey("manager", "start"); - return; - } - - ConfigurationFinish cs3 = new ConfigurationFinish(startCS); - cs3.reverseCount.setKey("local", "reverseCount", this.reverseCount.index); - cs3.configNodeNum.setKey("local", "configNodeNum"); - } + public Receiver reverseCount = ids.create(CommandType.PEEK); + public Receiver configNodeNum = ids.create(CommandType.PEEK); + private CodeSegment startCS; + + public ConfigurationFinish(CodeSegment startCS) { + this.startCS = startCS; + } + + @Override + public void run() { + if (reverseCount.getVal().equals(configNodeNum.getVal())) { + + ods.put("manager", "done", ValueFactory.createNilValue()); + Start cs = new Start(startCS); + cs.runningFlag.setKey("local", "running"); + cs.done.setKey("manager", "start"); + return; + } + + ConfigurationFinish cs3 = new ConfigurationFinish(startCS); + cs3.reverseCount.setKey("local", "reverseCount", this.reverseCount.index); + cs3.configNodeNum.setKey("local", "configNodeNum"); + } }
--- a/src/main/java/alice/topology/node/CreateConnectionList.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/node/CreateConnectionList.java Tue Jul 15 16:00:22 2014 +0900 @@ -7,22 +7,22 @@ import alice.datasegment.Receiver; public class CreateConnectionList extends CodeSegment { - private Receiver info = ids.create(CommandType.TAKE); // connection List - private Receiver info1 = ids.create(CommandType.TAKE); // connection names - - public CreateConnectionList() { - info.setKey("_CLIST"); - info1.setKey("cMember"); - } + private Receiver info = ids.create(CommandType.TAKE); // connection List + private Receiver info1 = ids.create(CommandType.TAKE); // connection names + + public CreateConnectionList() { + info.setKey("_CLIST"); + info1.setKey("cMember"); + } - @Override - public void run() { - @SuppressWarnings("unchecked") - List<String> cList = info.asClass(List.class); - String name = info1.asString(); - cList.add(name); - ods.update(info.key, cList); - - } + @Override + public void run() { + @SuppressWarnings("unchecked") + List<String> cList = info.asClass(List.class); + String name = info1.asString(); + cList.add(name); + ods.update(info.key, cList); + + } }
--- a/src/main/java/alice/topology/node/IncomingAbstractHostName.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/node/IncomingAbstractHostName.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,13 +6,13 @@ public class IncomingAbstractHostName extends CodeSegment { - public Receiver absName = ids.create(CommandType.PEEK); - - @Override - public void run() { - String absName = this.absName.asString(); - IncomingConnectionInfo cs = new IncomingConnectionInfo(absName, 0); - cs.hostInfo.setKey("manager", absName); - } + public Receiver absName = ids.create(CommandType.PEEK); + + @Override + public void run() { + String absName = this.absName.asString(); + IncomingConnectionInfo cs = new IncomingConnectionInfo(absName, 0); + cs.hostInfo.setKey("manager", absName); + } }
--- a/src/main/java/alice/topology/node/IncomingConnectionInfo.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/node/IncomingConnectionInfo.java Tue Jul 15 16:00:22 2014 +0900 @@ -10,34 +10,34 @@ public class IncomingConnectionInfo extends CodeSegment { - public Receiver hostInfo = ids.create(CommandType.TAKE); - private String absName; - private int count; + public Receiver hostInfo = ids.create(CommandType.TAKE); + private String absName; + private int count; - public IncomingConnectionInfo(String absName, int count) { - this.absName = absName; - this.count = count; - } + public IncomingConnectionInfo(String absName, int count) { + this.absName = absName; + this.count = count; + } - @Override - public void run() { - if (this.hostInfo.getVal() == null) { - ods.put("local", "configNodeNum", count); - } else { - if (count == 0) - ods.put("_CLIST", new ArrayList<String>()); - - HostMessage hostInfo = this.hostInfo.asClass(HostMessage.class); - DataSegment.connect(hostInfo.connectionName, hostInfo.reverseName, hostInfo.name, hostInfo.port); - ods.put(hostInfo.connectionName, "reverseKey", hostInfo.reverseName); - ods.put("cMember", hostInfo.connectionName); - count++; - - new CreateConnectionList(); - } - IncomingConnectionInfo cs = new IncomingConnectionInfo(absName, count); - cs.hostInfo.setKey("manager", absName); - } + @Override + public void run() { + if (this.hostInfo.getVal() == null) { + ods.put("local", "configNodeNum", count); + } else { + if (count == 0) + ods.put("_CLIST", new ArrayList<String>()); + + HostMessage hostInfo = this.hostInfo.asClass(HostMessage.class); + DataSegment.connect(hostInfo.connectionName, hostInfo.reverseName, hostInfo.name, hostInfo.port); + ods.put(hostInfo.connectionName, "reverseKey", hostInfo.reverseName); + ods.put("cMember", hostInfo.connectionName); + count++; + + new CreateConnectionList(); + } + IncomingConnectionInfo cs = new IncomingConnectionInfo(absName, count); + cs.hostInfo.setKey("manager", absName); + } }
--- a/src/main/java/alice/topology/node/IncomingReverseKey.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/node/IncomingReverseKey.java Tue Jul 15 16:00:22 2014 +0900 @@ -7,22 +7,22 @@ public class IncomingReverseKey extends CodeSegment { - public Receiver reverseKey = ids.create(CommandType.TAKE); - public Receiver reverseCount = ids.create(CommandType.PEEK); - - @Override - public void run() { - String reverseKey = this.reverseKey.asString(); - String from = this.reverseKey.from; - DataSegment.getAccept(from).reverseKey = reverseKey; - - int reverseCount = this.reverseCount.asInteger(); - reverseCount++; - ods.update("local", "reverseCount", reverseCount); - - IncomingReverseKey cs = new IncomingReverseKey(); - cs.reverseKey.setKey("local", "reverseKey"); - cs.reverseCount.setKey("local", "reverseCount"); - } + public Receiver reverseKey = ids.create(CommandType.TAKE); + public Receiver reverseCount = ids.create(CommandType.PEEK); + + @Override + public void run() { + String reverseKey = this.reverseKey.asString(); + String from = this.reverseKey.from; + DataSegment.getAccept(from).reverseKey = reverseKey; + + int reverseCount = this.reverseCount.asInteger(); + reverseCount++; + ods.update("local", "reverseCount", reverseCount); + + IncomingReverseKey cs = new IncomingReverseKey(); + cs.reverseKey.setKey("local", "reverseKey"); + cs.reverseCount.setKey("local", "reverseCount"); + } }
--- a/src/main/java/alice/topology/node/Start.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/node/Start.java Tue Jul 15 16:00:22 2014 +0900 @@ -7,27 +7,27 @@ import alice.datasegment.Receiver; public class Start extends CodeSegment { - - public Receiver done = ids.create(CommandType.PEEK); - public Receiver runningFlag = ids.create(CommandType.TAKE); - - private Logger logger = Logger.getLogger(Start.class); - private CodeSegment startCS; + + public Receiver done = ids.create(CommandType.PEEK); + public Receiver runningFlag = ids.create(CommandType.TAKE); + + private Logger logger = Logger.getLogger(Start.class); + private CodeSegment startCS; + - - public Start(CodeSegment startCS) { - this.startCS = startCS; - } - - @Override - public void run() { - logger.info("Configuration finished."); - - if (startCS == null) - return; - ods.update(runningFlag.key, true); - startCS.execute(); - - } + public Start(CodeSegment startCS) { + this.startCS = startCS; + } + + @Override + public void run() { + logger.info("Configuration finished."); + + if (startCS == null) + return; + ods.update(runningFlag.key, true); + startCS.execute(); + + } }
--- a/src/main/java/alice/topology/node/StartTopologyNode.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/node/StartTopologyNode.java Tue Jul 15 16:00:22 2014 +0900 @@ -8,41 +8,41 @@ public class StartTopologyNode extends CodeSegment { - private TopologyNodeConfig conf; - private CodeSegment startCS; - - public StartTopologyNode(TopologyNodeConfig conf, CodeSegment startCS) { - this.conf = conf; - this.startCS = startCS; - } - - @Override - public void run() { - ods.put("running", false); - DataSegment.connect("manager", "", conf.getManagerHostName(), conf.getManagerPort()); - String localHostName = null; - try { - localHostName = InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException e) { - e.printStackTrace(); - } - - HostMessage host = new HostMessage(localHostName, conf.localPort); - ods.put("manager", "host", host); - - IncomingAbstractHostName cs = new IncomingAbstractHostName(); - cs.absName.setKey("local", "host"); - - IncomingReverseKey cs2 = new IncomingReverseKey(); - cs2.reverseKey.setKey("local", "reverseKey"); - cs2.reverseCount.setKey("local", "reverseCount"); - - ods.put("local", "reverseCount", 0); - - ConfigurationFinish cs3 = new ConfigurationFinish(startCS); - cs3.reverseCount.setKey("local", "reverseCount"); - cs3.configNodeNum.setKey("local", "configNodeNum"); - - } - + private TopologyNodeConfig conf; + private CodeSegment startCS; + + public StartTopologyNode(TopologyNodeConfig conf, CodeSegment startCS) { + this.conf = conf; + this.startCS = startCS; + } + + @Override + public void run() { + ods.put("running", false); + DataSegment.connect("manager", "", conf.getManagerHostName(), conf.getManagerPort()); + String localHostName = null; + try { + localHostName = InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + + HostMessage host = new HostMessage(localHostName, conf.localPort); + ods.put("manager", "host", host); + + IncomingAbstractHostName cs = new IncomingAbstractHostName(); + cs.absName.setKey("local", "host"); + + IncomingReverseKey cs2 = new IncomingReverseKey(); + cs2.reverseKey.setKey("local", "reverseKey"); + cs2.reverseCount.setKey("local", "reverseCount"); + + ods.put("local", "reverseCount", 0); + + ConfigurationFinish cs3 = new ConfigurationFinish(startCS); + cs3.reverseCount.setKey("local", "reverseCount"); + cs3.configNodeNum.setKey("local", "configNodeNum"); + + } + }
--- a/src/main/java/alice/topology/node/TopologyNode.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/node/TopologyNode.java Tue Jul 15 16:00:22 2014 +0900 @@ -5,14 +5,14 @@ public class TopologyNode { - public TopologyNode(TopologyNodeConfig conf, CodeSegment startCS) { - new AliceDaemon(conf).listen(); - new StartTopologyNode(conf, startCS).execute(); - } - - public static void main(String[] args) { - TopologyNodeConfig conf = new TopologyNodeConfig(args); - new TopologyNode(conf, null); - } + public TopologyNode(TopologyNodeConfig conf, CodeSegment startCS) { + new AliceDaemon(conf).listen(); + new StartTopologyNode(conf, startCS).execute(); + } + + public static void main(String[] args) { + TopologyNodeConfig conf = new TopologyNodeConfig(args); + new TopologyNode(conf, null); + } }
--- a/src/main/java/alice/topology/node/TopologyNodeConfig.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/topology/node/TopologyNodeConfig.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,35 +3,35 @@ import alice.daemon.Config; public class TopologyNodeConfig extends Config { - - private String managerHostName; - private int managerPort; - - public TopologyNodeConfig(String[] args) { - super(args); - for (int i = 0; i< args.length; i++) { - if ("-host".equals(args[i])) { - setManagerHostName(args[++i]); - } else if ("-port".equals(args[i])) { - setManagerPort(Integer.parseInt(args[++i])); - } - } - } + + private String managerHostName; + private int managerPort; + + public TopologyNodeConfig(String[] args) { + super(args); + for (int i = 0; i< args.length; i++) { + if ("-host".equals(args[i])) { + setManagerHostName(args[++i]); + } else if ("-port".equals(args[i])) { + setManagerPort(Integer.parseInt(args[++i])); + } + } + } - public String getManagerHostName() { - return managerHostName; - } + public String getManagerHostName() { + return managerHostName; + } - public void setManagerHostName(String managerHostName) { - this.managerHostName = managerHostName; - } + public void setManagerHostName(String managerHostName) { + this.managerHostName = managerHostName; + } - public int getManagerPort() { - return managerPort; - } + public int getManagerPort() { + return managerPort; + } - public void setManagerPort(int managerPort) { - this.managerPort = managerPort; - } + public void setManagerPort(int managerPort) { + this.managerPort = managerPort; + } }
--- a/src/test/java/alice/daemon/MulticastIncrement.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/test/java/alice/daemon/MulticastIncrement.java Tue Jul 15 16:00:22 2014 +0900 @@ -6,18 +6,18 @@ public class MulticastIncrement extends CodeSegment { - public Receiver num = ids.create(CommandType.TAKE); + public Receiver num = ids.create(CommandType.TAKE); - @Override - public void run() { - int num = this.num.asInteger(); - System.out.println("[CodeSegment] " + num++); - if (num == 10) System.exit(0); - MulticastIncrement cs = new MulticastIncrement(); - cs.num.setKey("multicast", "num"); - - ods.put("multicast", "num", num); - - } + @Override + public void run() { + int num = this.num.asInteger(); + System.out.println("[CodeSegment] " + num++); + if (num == 10) System.exit(0); + MulticastIncrement cs = new MulticastIncrement(); + cs.num.setKey("multicast", "num"); + + ods.put("multicast", "num", num); + + } }
--- a/src/test/java/alice/daemon/MulticastStartCodeSegment.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/test/java/alice/daemon/MulticastStartCodeSegment.java Tue Jul 15 16:00:22 2014 +0900 @@ -4,12 +4,12 @@ public class MulticastStartCodeSegment extends CodeSegment { - @Override - public void run() { - MulticastIncrement cs = new MulticastIncrement(); - cs.num.setKey("multicast","num"); - - ods.put("multicast", "num", 0); - } + @Override + public void run() { + MulticastIncrement cs = new MulticastIncrement(); + cs.num.setKey("multicast","num"); + + ods.put("multicast", "num", 0); + } }
--- a/src/test/java/alice/daemon/UdpTest.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/test/java/alice/daemon/UdpTest.java Tue Jul 15 16:00:22 2014 +0900 @@ -3,10 +3,10 @@ import alice.datasegment.DataSegment; public class UdpTest { - public static void main(String[] args){ - Config conf = new Config(args); - DataSegment.connectMulticast("multicast",conf.MCSTADDR, conf.localPort, conf.nis); - new MulticastStartCodeSegment().execute(); - } + public static void main(String[] args){ + Config conf = new Config(args); + DataSegment.connectMulticast("multicast",conf.MCSTADDR, conf.localPort, conf.nis); + new MulticastStartCodeSegment().execute(); + } }