# HG changeset patch # User sugi # Date 1397640367 -32400 # Node ID 8f71c3e6f11dd87bee99b66e1193a092973271b2 # Parent 9f97ec18f8c568b4ce5c225110c75a31045238f7 Change directory structure Maven standard diff -r 9f97ec18f8c5 -r 8f71c3e6f11d .classpath --- a/.classpath Wed Apr 16 17:37:48 2014 +0900 +++ b/.classpath Wed Apr 16 18:26:07 2014 +0900 @@ -1,13 +1,11 @@ - - - - - - - - - + + + + + + + diff -r 9f97ec18f8c5 -r 8f71c3e6f11d .project --- a/.project Wed Apr 16 17:37:48 2014 +0900 +++ b/.project Wed Apr 16 18:26:07 2014 +0900 @@ -1,6 +1,6 @@ - Alice + Alice-Gradle @@ -12,6 +12,7 @@ + org.springsource.ide.eclipse.gradle.core.nature org.eclipse.jdt.core.javanature diff -r 9f97ec18f8c5 -r 8f71c3e6f11d .settings/org.eclipse.core.resources.prefs --- a/.settings/org.eclipse.core.resources.prefs Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -eclipse.preferences.version=1 -encoding//src/alice/test/codesegment/local/bitonicsort/SortTest.java=UTF-8 -encoding//src/alice/test/codesegment/local/wordcount/SeparateArray.java=UTF-8 -encoding//src/alice/test/codesegment/local/wordcount/WordCount.java=UTF-8 -encoding//src/alice/topology/manager/IncomingHosts.java=UTF-8 -encoding//src/alice/topology/manager/createABSIPList.java=UTF-8 -encoding//src/alice/topology/manager/keeparive/RemoveTask.java=UTF-8 -encoding//src/alice/topology/manager/keeparive/TaskExecuter.java=UTF-8 diff -r 9f97ec18f8c5 -r 8f71c3e6f11d .settings/org.eclipse.jdt.core.prefs --- a/.settings/org.eclipse.jdt.core.prefs Wed Apr 16 17:37:48 2014 +0900 +++ b/.settings/org.eclipse.jdt.core.prefs Wed Apr 16 18:26:07 2014 +0900 @@ -1,9 +1,4 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore -org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull -org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault -org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable -org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve @@ -11,99 +6,6 @@ org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.doc.comment.support=enabled -org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.autoboxing=ignore -org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning -org.eclipse.jdt.core.compiler.problem.deadCode=warning -org.eclipse.jdt.core.compiler.problem.deprecation=warning -org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled -org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled -org.eclipse.jdt.core.compiler.problem.discouragedReference=warning -org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore -org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore -org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled -org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore -org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning -org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning -org.eclipse.jdt.core.compiler.problem.forbiddenReference=ignore -org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning -org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled -org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning -org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore -org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore -org.eclipse.jdt.core.compiler.problem.invalidJavadoc=ignore -org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=disabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=disabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=disabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public -org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore -org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning -org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore -org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled -org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore -org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore -org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public -org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag -org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled -org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled -org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning -org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore -org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning -org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning -org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore -org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error -org.eclipse.jdt.core.compiler.problem.nullReference=warning -org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error -org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning -org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning -org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore -org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore -org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore -org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore -org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning -org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning -org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore -org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore -org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore -org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore -org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore -org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled -org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning -org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled -org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled -org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore -org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning -org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled -org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning -org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning -org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore -org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore -org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore -org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled -org.eclipse.jdt.core.compiler.problem.unusedImport=warning -org.eclipse.jdt.core.compiler.problem.unusedLabel=warning -org.eclipse.jdt.core.compiler.problem.unusedLocal=warning -org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled -org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning -org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning -org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.source=1.6 diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/codesegment/CodeSegment.java --- a/src/alice/codesegment/CodeSegment.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -package alice.codesegment; - -import java.util.ArrayList; - -import alice.codesegment.InputDataSegment; -import alice.datasegment.Receiver; - -public abstract class CodeSegment implements Runnable { - - public InputDataSegment ids = new InputDataSegment(this); - public OutputDataSegment ods = new OutputDataSegment(); - public ArrayList list = new ArrayList(); - - public void execute() { - ids.receive(); - } - - public void recycle(){ - ids.init(); - ids.setCounter(list.size()); - for (Receiver receiver : list) { - ids.recommand(receiver); - } - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/codesegment/CodeSegmentManager.java --- a/src/alice/codesegment/CodeSegmentManager.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -package alice.codesegment; - -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -import org.apache.log4j.Logger; - -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()); - private Logger logger = Logger.getLogger(CodeSegmentManager.class); - - 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()); - } - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/codesegment/InputDataSegment.java --- a/src/alice/codesegment/InputDataSegment.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -package alice.codesegment; - -import java.util.concurrent.atomic.AtomicInteger; - -import alice.datasegment.Command; -import alice.datasegment.CommandType; -import alice.datasegment.DataSegment; -import alice.datasegment.ReceiveLocalData; -import alice.datasegment.ReceiveRemoteData; -import alice.datasegment.Receiver; - -/** - * InputDataSegment Manager - * keep tracking unbound/bound count - * @author kazz - * - */ -public class InputDataSegment { - - public CodeSegment cs; - private AtomicInteger count = new AtomicInteger(1); // 1 for no input data segments - private AtomicInteger keyCount = new AtomicInteger(0); // number of DataSegments - public InputDataSegment(CodeSegment cs) { - this.cs = cs; - } - - public void init(){ - count = new AtomicInteger(1); - keyCount = new AtomicInteger(0); - } - - public void quickPeek(Receiver receiver) { - cs.list.add(receiver); - if (receiver.managerKey==null){ - DataSegment.getLocal().peek(receiver, cs); - } else { - DataSegment.get(receiver.managerKey).quickPeek(receiver ,cs); - } - } - - public void quickTake(Receiver receiver) { - cs.list.add(receiver); - if (receiver.managerKey==null){ - DataSegment.getLocal().quickTake(receiver, cs); - } else { - DataSegment.get(receiver.managerKey).quickTake(receiver ,cs); - } - } - - public void peek(Receiver receiver) { - cs.list.add(receiver); - if (receiver.managerKey==null){ - DataSegment.getLocal().peek(receiver, cs); - } else { - DataSegment.get(receiver.managerKey).peek(receiver, cs); - } - } - - - public void take(Receiver receiver) { - cs.list.add(receiver); - if (receiver.managerKey==null){ - DataSegment.getLocal().take(receiver, cs); - } else { - DataSegment.get(receiver.managerKey).take(receiver, cs); - } - } - - public void reply(Receiver receiver, Command reply) { - receiver.index = reply.index; - receiver.from = reply.reverseKey; - if (reply.reverseKey==null){ - receiver.setData(new ReceiveRemoteData(reply.val)); - } else if (!reply.reverseKey.equals("local")) { - receiver.setData(new ReceiveRemoteData(reply.val)); - } else { - receiver.setData(new ReceiveLocalData(reply.obj)); - } - receive(); - } - - public void register() { - count.getAndIncrement(); - keyCount.getAndIncrement(); - } - - public void setKey() { - if (keyCount.decrementAndGet() == 0) { - receive(); - } - } - - public void receive() { - if (count.decrementAndGet() == 0) { - CodeSegmentManager.submit(cs); - } - } - - /** - * InputDataSegment factory - * @param type PEEK or TAKE - * @return Receiver of DataSegment reply - */ - public Receiver create(CommandType type) { - return new Receiver(this, type); - } - - public void recommand(Receiver receiver) { - // TODO why only local? - DataSegment.getLocal().recommand(receiver, cs); - } - - public void setCounter(int cnt){ - count.set(cnt); - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/codesegment/OutputDataSegment.java --- a/src/alice/codesegment/OutputDataSegment.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ -package alice.codesegment; - -import alice.datasegment.DataSegment; -import alice.datasegment.Receiver; - -public class OutputDataSegment { - - /** - * for local - */ - - public void flip(Receiver receiver) { - receiver.managerKey=null; - DataSegment.getLocal().put(receiver.key, receiver.getObj()); - } - - public void put(String key, Object val) { - DataSegment.getLocal().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 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); - } - } - - 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 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 - */ - - public void finish(String managerKey) { - DataSegment.get(managerKey).finish(); - } - - /** - * close socket for RemoteDataSegment after send other messages. - * - * @param managerKey - */ - - 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); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/codesegment/SingletonMessage.java --- a/src/alice/codesegment/SingletonMessage.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package alice.codesegment; - -import org.msgpack.MessagePack; - -public class SingletonMessage { - - private static final MessagePack instance = new MessagePack(); - - public static MessagePack getInstance(){ - return instance; - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/daemon/AcceptThread.java --- a/src/alice/daemon/AcceptThread.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -package alice.daemon; - -import java.io.IOException; -import java.net.ServerSocket; -import java.net.Socket; - -import org.apache.log4j.Logger; - -import alice.datasegment.DataSegment; - -public class AcceptThread extends Thread { - - 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; - } - - @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(); - } - } - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/daemon/AliceDaemon.java --- a/src/alice/daemon/AliceDaemon.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -package alice.daemon; - -import java.io.FileWriter; -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.ServerSocket; -import java.nio.channels.ServerSocketChannel; - -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -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); - - //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(); - } - - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/daemon/CommandMessage.java --- a/src/alice/daemon/CommandMessage.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -package alice.daemon; - -import org.msgpack.annotation.Message; -import org.msgpack.type.Value; - -@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; - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/daemon/Config.java --- a/src/alice/daemon/Config.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -package alice.daemon; - -import org.apache.log4j.Level; - -public class Config { - - public int localPort = 10000; - public String logFile = null; - public Level level = null; - - 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 ("-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; - } - } - } - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/daemon/Connection.java --- a/src/alice/daemon/Connection.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -package alice.daemon; - -import java.io.IOException; -import java.net.Socket; -import java.nio.ByteBuffer; -import java.util.concurrent.LinkedBlockingQueue; - -import alice.codesegment.SingletonMessage; -import alice.datasegment.Command; - -public class Connection { - - public Socket socket; - public LinkedBlockingQueue sendQueue = new LinkedBlockingQueue(); - - public Connection(Socket socket) { - this.socket = socket; - } - - public Connection() {} - - public void sendCommand(Command cmd) { - try { - sendQueue.put(cmd); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - 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 (IOException e) { - e.printStackTrace(); - } - } - - public void close(){ - try { - socket.shutdownOutput(); - socket.shutdownInput(); - socket.close(); - } catch (IOException e) { - e.printStackTrace(); - } - - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/daemon/IncomingTcpConnection.java --- a/src/alice/daemon/IncomingTcpConnection.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -package alice.daemon; - -import java.io.EOFException; -import java.io.IOException; -import java.nio.channels.ClosedChannelException; - -import org.msgpack.unpacker.Unpacker; - -import alice.codesegment.SingletonMessage; -import alice.datasegment.Command; -import alice.datasegment.CommandType; -import alice.datasegment.DataSegment; -import alice.datasegment.DataSegmentKey; -import alice.datasegment.DataSegmentManager; -import alice.datasegment.LocalDataSegmentManager; -import alice.topology.HostMessage; -import alice.topology.manager.keeparive.RespondData; -import alice.topology.manager.reconnection.SendError; - -public class IncomingTcpConnection extends Thread { - - public Connection connection; - public DataSegmentManager manager; - public String reverseKey; - private LocalDataSegmentManager lmanager = DataSegment.getLocal(); - - public IncomingTcpConnection(Connection connection, DataSegmentManager manager, String reverseKey) { - this.manager = manager; - this.connection = connection; - this.reverseKey = reverseKey; - } - - /** - * pipeline thread for receiving - */ - public void run() { - Unpacker unpacker = this.getUnpacker(); - if (unpacker == null) { - return; - } - while (true) { - try { - CommandMessage msg = unpacker.read(CommandMessage.class); - CommandType type = CommandType.getCommandTypeFromId(msg.type); - switch (type) { - case UPDATE: - getDataSegmentKey(msg).runCommand(new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey)); - break; - case PUT: - getDataSegmentKey(msg).runCommand(new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey)); - break; - case PEEK: - getDataSegmentKey(msg).runCommand(new Command(type, null, null, null, msg.index, msg.seq, connection, null, null, msg.flag)); - break; - case TAKE: - getDataSegmentKey(msg).runCommand(new Command(type, null, null, null, msg.index, msg.seq, connection, null, null, msg.flag)); - break; - case REMOVE: - getDataSegmentKey(msg).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.sendCommand(new Command(CommandType.CLOSE, null, null, null, 0, 0, null, null, null)); - return; - } catch (EOFException e) { - new SendError(new HostMessage(connection.socket.getInetAddress().getHostName(), connection.socket.getPort())).execute(); - connection.sendCommand(new Command(CommandType.CLOSE, null, null, null, 0, 0, null, null, null)); - return; - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - private Unpacker getUnpacker() { - Unpacker unpacker = null; - try { - unpacker = SingletonMessage.getInstance().createUnpacker(connection.socket.getInputStream()); - } catch (IOException e2) { - e2.printStackTrace(); - } - return unpacker; - } - - private DataSegmentKey getDataSegmentKey(CommandMessage msg) { - return lmanager.getDataSegmentKey(msg.key); - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/daemon/OutboundTcpConnection.java --- a/src/alice/daemon/OutboundTcpConnection.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -package alice.daemon; - -import java.io.IOException; -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.socket.close(); - return; - case FINISH: - System.exit(0); - return; - default: - break; - } - connection.write(cmd); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/datasegment/Command.java --- a/src/alice/datasegment/Command.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -package alice.datasegment; - -import java.io.IOException; -import java.util.concurrent.BlockingQueue; -import org.msgpack.type.Value; - -import alice.codesegment.CodeSegment; -import alice.codesegment.SingletonMessage; -import alice.daemon.CommandMessage; -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 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 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 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 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 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); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/datasegment/CommandType.java --- a/src/alice/datasegment/CommandType.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -package alice.datasegment; - -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 hash = new HashMap(); - 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); - } - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/datasegment/DataSegment.java --- a/src/alice/datasegment/DataSegment.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -package alice.datasegment; - -import java.util.concurrent.ConcurrentHashMap; - -import alice.daemon.IncomingTcpConnection; - -public class DataSegment { - - private static DataSegment dataSegment = new DataSegment(); - private LocalDataSegmentManager local = new LocalDataSegmentManager(); - private ConcurrentHashMap dataSegmentManagers = new ConcurrentHashMap(); //TODO Over Head - private ConcurrentHashMap acceptHash = new ConcurrentHashMap(); - - 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 RemoteDataSegmentManager connect(String connectionKey, String reverseKey, String hostName, int port, boolean rFlag) { - RemoteDataSegmentManager manager = new RemoteDataSegmentManager(connectionKey, reverseKey, hostName, port, rFlag); - register(connectionKey, 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); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/datasegment/DataSegmentKey.java --- a/src/alice/datasegment/DataSegmentKey.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +0,0 @@ -package alice.datasegment; - -import java.util.ArrayList; -import java.util.Iterator; - -import alice.datasegment.Command; - -/** - * Synchronized DataSegment for each DataSegment key - * @author kazz - * - */ -public class DataSegmentKey { - - private ArrayList dataList = new ArrayList(); - private ArrayList waitList = new ArrayList(); - 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 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 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(); - } - } - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/datasegment/DataSegmentManager.java --- a/src/alice/datasegment/DataSegmentManager.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -package alice.datasegment; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.atomic.AtomicInteger; - -import org.apache.log4j.Logger; - -import alice.codesegment.CodeSegment; - -public abstract class DataSegmentManager { - - protected ConcurrentHashMap seqHash = new ConcurrentHashMap(); - protected LinkedBlockingQueue replyQueue = new LinkedBlockingQueue(); - 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 take(Receiver receiver, CodeSegment cs); - public abstract void peek(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(String key); - public abstract void close(); - public abstract void finish(); - - public abstract void ping(String returnKey); - public abstract void response(String returnKey); - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/datasegment/DataSegmentValue.java --- a/src/alice/datasegment/DataSegmentValue.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -package alice.datasegment; - -import org.msgpack.type.Value; - -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; - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/datasegment/LocalDataSegmentManager.java --- a/src/alice/datasegment/LocalDataSegmentManager.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,172 +0,0 @@ -package alice.datasegment; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -import org.apache.log4j.Logger; - -import alice.codesegment.CodeSegment; - -public class LocalDataSegmentManager extends DataSegmentManager { - - private String reverseKey = "local"; - private ConcurrentHashMap dataSegments = new ConcurrentHashMap(); - 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()); - - public LocalDataSegmentManager() { - new Thread(replyThread, "LocalDataSegmentManager-replyCommand").start(); - } - - 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 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 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() { - - } - - 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 response(String returnKey) { - - } - - @Override - public void shutdown(String key) { - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/datasegment/ReceiveLocalData.java --- a/src/alice/datasegment/ReceiveLocalData.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -package alice.datasegment; - -import java.io.IOException; - -import org.msgpack.type.ArrayValue; -import org.msgpack.type.Value; - -import alice.codesegment.SingletonMessage; -import alice.datasegment.ReceiverData; - -public class ReceiveLocalData implements ReceiverData { - private Object obj; - - public ReceiveLocalData(Object obj2) { - this.obj = obj2; - } - - public String asString() { - return (String) obj; - } - - public int asInteger() { - return (Integer) obj; - } - - public Float asFloat() { - return (Float) obj; - } - - public ArrayValue asArray(){ - return (ArrayValue) obj; - } - - @SuppressWarnings("unchecked") - public T asClass(Class clazz) { - return (T) obj; - - } - - @Override - public Value getVal() { - try { - return SingletonMessage.getInstance().unconvert(obj); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } - - @Override - public Object getObj() { - return obj; - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/datasegment/ReceiveRemoteData.java --- a/src/alice/datasegment/ReceiveRemoteData.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -package alice.datasegment; - -import java.io.IOException; - -import org.msgpack.type.ArrayValue; -import org.msgpack.type.Value; -import org.msgpack.type.ValueType; - -import alice.codesegment.SingletonMessage; - -public class ReceiveRemoteData implements ReceiverData { - public Value val; - - public ReceiveRemoteData() { - } - - public ReceiveRemoteData(Value val2) { - this.val = val2; - } - - 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 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 T asClass(Class clazz) { - try { - return SingletonMessage.getInstance().convert(val, clazz); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - - } - - @Override - public Value getVal() { - return val; - } - - @Override - public Object getObj() { - return val; - } - -} \ No newline at end of file diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/datasegment/Receiver.java --- a/src/alice/datasegment/Receiver.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,112 +0,0 @@ -package alice.datasegment; - - -import alice.codesegment.InputDataSegment; - -/** - * MessagePack implementation and DataSegment Receiver - * @author kazz - * - */ -public class Receiver { - private ReceiverData data = new ReceiveRemoteData(); - public InputDataSegment ids; - public int index; - public String from; - public CommandType type; - public String managerKey; - public String key; - - public Receiver(InputDataSegment ids, CommandType type) { - this.ids = ids; - this.type = type; - ids.register(); - - } - - public void setQuickKey(String managerKey, String key){ - setQuickKey(managerKey, key, 0); - } - - public void setQuickKey(String managerKey, String key, int index) { - this.managerKey = managerKey; - this.key = key; - switch (type) { - case PEEK: - ids.quickPeek(this); - break; - case TAKE: - ids.quickTake(this); - break; - default: - break; - } - ids.setKey(); - } - - public void setKey(String managerKey, String key) { - setKey(managerKey, key, 0); - } - - public void setKey(String managerKey, String key, int index) { - this.managerKey = managerKey; - this.key = key; - this.index = index; - switch (type) { - case PEEK: - ids.peek(this); - break; - case TAKE: - ids.take(this); - break; - default: - break; - } - ids.setKey(); - } - - public void setKey(String key) { - setKey(key, 0); - } - - public void setKey(String key, int index) { - this.key = key; - this.index = index; - switch (type) { - case PEEK: - ids.peek(this); - break; - case TAKE: - ids.take(this); - break; - default: - break; - } - ids.setKey(); - } - - public void setData(ReceiverData r) { - data = r; - } - - public int asInteger() { - return data.asInteger(); - } - - public String asString() { - return data.asString(); - } - - public T asClass(Class clazz) { - return data.asClass(clazz); - } - - public Object getObj() { - return data.getObj(); - } - - public Object getVal() { - return data.getVal(); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/datasegment/ReceiverData.java --- a/src/alice/datasegment/ReceiverData.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -package alice.datasegment; - -import org.msgpack.type.ArrayValue; -import org.msgpack.type.Value; - -public interface ReceiverData { - - public String asString(); - public int asInteger(); - public Float asFloat() ; - public ArrayValue asArray(); - public T asClass(Class clazz); - public Value getVal(); - public Object getObj(); - -} \ No newline at end of file diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/datasegment/RemoteDataSegmentManager.java --- a/src/alice/datasegment/RemoteDataSegmentManager.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,166 +0,0 @@ -package alice.datasegment; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.nio.channels.SocketChannel; - -import org.apache.log4j.Logger; - -import alice.codesegment.CodeSegment; -import alice.daemon.Connection; -import alice.daemon.IncomingTcpConnection; -import alice.daemon.OutboundTcpConnection; -import alice.topology.HostMessage; -import alice.topology.manager.reconnection.SendError; - -public class RemoteDataSegmentManager extends DataSegmentManager { - - Connection connection; - Logger logger; - - public RemoteDataSegmentManager(String connectionKey, final String reverseKey, final String hostName, final int port, final boolean rFlag) { - 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&&!rFlag); - new IncomingTcpConnection(connection, manager, reverseKey).start(); - new OutboundTcpConnection(connection).start(); - // if connection failed need to stop these thread - if (connect){ - new SendError(new HostMessage(hostName, port)).execute(); - } - } - }.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 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 finish() { - Command cmd = new Command(CommandType.FINISH, null, null, null, 0, 0, null, null, null); - connection.sendCommand(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 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 shutdown(String key) { - connection.close(); - } - - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/api/FlipCodeSegment.java --- a/src/alice/test/codesegment/api/FlipCodeSegment.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -package alice.test.codesegment.api; - -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); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/api/FlipTest.java --- a/src/alice/test/codesegment/api/FlipTest.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -package alice.test.codesegment.api; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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); - } - - @Override - public void run() { - if(flag){ - System.out.println(System.currentTimeMillis() - t +" ms"); - System.exit(0); - } - t = System.currentTimeMillis(); - for (int i=0;i10000){ - 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); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/api/PutCodeSegment.java --- a/src/alice/test/codesegment/api/PutCodeSegment.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -package alice.test.codesegment.api; - -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(); - } - - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/api/StartCodeSegment.java --- a/src/alice/test/codesegment/api/StartCodeSegment.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -package alice.test.codesegment.api; - -import java.util.Random; - -import alice.codesegment.CodeSegment; -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; - } - - @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 ("-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); - } - } - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/api/TakeCodeSegment.java --- a/src/alice/test/codesegment/api/TakeCodeSegment.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -package alice.test.codesegment.api; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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); - - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/api/TestApiAlice.java --- a/src/alice/test/codesegment/api/TestApiAlice.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -package alice.test.codesegment.api; - -import alice.daemon.AliceDaemon; -import alice.daemon.Config; - -public class TestApiAlice { - - /** - * @param args - */ - public static void main(String[] args) { - new AliceDaemon(new Config(args)).listen(); - new StartCodeSegment(args).execute(); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/api/UpdateCodeSegment.java --- a/src/alice/test/codesegment/api/UpdateCodeSegment.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -package alice.test.codesegment.api; - -import org.msgpack.type.Value; -import org.msgpack.type.ValueFactory; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -public class UpdateCodeSegment extends CodeSegment { - 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); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/local/SingletonTestCodeSegment.java --- a/src/alice/test/codesegment/local/SingletonTestCodeSegment.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -package alice.test.codesegment.local; - -import org.msgpack.type.Value; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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"); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/local/StartCodeSegment.java --- a/src/alice/test/codesegment/local/StartCodeSegment.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package alice.test.codesegment.local; - -import alice.codesegment.CodeSegment; - -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. - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/local/TestCodeSegment.java --- a/src/alice/test/codesegment/local/TestCodeSegment.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -package alice.test.codesegment.local; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; -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"); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/local/TestLocalAlice.java --- a/src/alice/test/codesegment/local/TestLocalAlice.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -package alice.test.codesegment.local; - -import alice.daemon.AliceDaemon; -import alice.daemon.Config; - -public class TestLocalAlice { - public static void main(String args[]) { - new AliceDaemon(new Config(args)).listen(); // logger off - new StartCodeSegment().execute(); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/local/bitonicsort/DataInfo.java --- a/src/alice/test/codesegment/local/bitonicsort/DataInfo.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -package alice.test.codesegment.local.bitonicsort; - -import org.msgpack.annotation.Message; - -@Message -public class DataInfo { - public int index; - public int ptr; - - public DataInfo(){} - - public DataInfo(int _index, int _ptr){ - index = _index; - ptr = _ptr; - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/local/bitonicsort/DataList.java --- a/src/alice/test/codesegment/local/bitonicsort/DataList.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -package alice.test.codesegment.local.bitonicsort; - -import org.msgpack.annotation.Message; - -@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=t1.length) { // switch to the second list - t1 = t2; n = 0; - } - if (j>=t2.length || t0[i] < t2[j]) { - t1[n] = t0[i]; // including when j reaches end of t2 - i++; n++; - } else { - t1[n] = t2[j]; - j++; n++; - } - } - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/local/bitonicsort/LocalBitonicSort.java --- a/src/alice/test/codesegment/local/bitonicsort/LocalBitonicSort.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package alice.test.codesegment.local.bitonicsort; - -import alice.daemon.AliceDaemon; -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(); - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/local/bitonicsort/MakeData.java --- a/src/alice/test/codesegment/local/bitonicsort/MakeData.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -package alice.test.codesegment.local.bitonicsort; - -import java.util.Random; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -public class MakeData extends CodeSegment { - - private Receiver info1 = ids.create(CommandType.PEEK); - private Receiver info2 = ids.create(CommandType.TAKE); - - 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); - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/local/bitonicsort/RangeInfo.java --- a/src/alice/test/codesegment/local/bitonicsort/RangeInfo.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -package alice.test.codesegment.local.bitonicsort; - -import org.msgpack.annotation.Message; - -@Message -public class RangeInfo { - public int range; - public boolean lastFlag; - - public RangeInfo(){} - public RangeInfo(int i,boolean flag){ - range = i; - lastFlag = flag; - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/local/bitonicsort/SetInfo.java --- a/src/alice/test/codesegment/local/bitonicsort/SetInfo.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -package alice.test.codesegment.local.bitonicsort; - -import alice.codesegment.CodeSegment; - -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; - } - - @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(); - } - - 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; - } - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/local/bitonicsort/SetTask.java --- a/src/alice/test/codesegment/local/bitonicsort/SetTask.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -package alice.test.codesegment.local.bitonicsort; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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); - - } - - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/local/bitonicsort/ShowData.java --- a/src/alice/test/codesegment/local/bitonicsort/ShowData.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -package alice.test.codesegment.local.bitonicsort; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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); - } - - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/local/bitonicsort/Sort.java --- a/src/alice/test/codesegment/local/bitonicsort/Sort.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -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]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"); - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/codesegment/local/bitonicsort/SortConfig.java --- a/src/alice/test/codesegment/local/bitonicsort/SortConfig.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -package alice.test.codesegment.local.bitonicsort; - -import org.msgpack.annotation.Message; - -@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 clazz = tep.toClass(); // load Class - @SuppressWarnings("unused") - CSTemplate cs = (CSTemplate)clazz.newInstance(); // create instance - - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/AutoIncrement.java --- a/src/alice/test/topology/aquarium/AutoIncrement.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -package alice.test.topology.aquarium; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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); - } - - @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); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/CheckLocalIndex.java --- a/src/alice/test/topology/aquarium/CheckLocalIndex.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -package alice.test.topology.aquarium; - -import java.util.List; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -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 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); - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/CheckMyName.java --- a/src/alice/test/topology/aquarium/CheckMyName.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,97 +0,0 @@ -package alice.test.topology.aquarium; - -import java.util.Random; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - - -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); - } - - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/FishMovementConfig.java --- a/src/alice/test/topology/aquarium/FishMovementConfig.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -package alice.test.topology.aquarium; - -import alice.topology.node.TopologyNodeConfig; - -public class FishMovementConfig extends TopologyNodeConfig { - - public FishMovementConfig(String[] args){ - super(args); - } - - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/FishMovementTopology.java --- a/src/alice/test/topology/aquarium/FishMovementTopology.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -package alice.test.topology.aquarium; -import alice.topology.node.TopologyNode; - -public class FishMovementTopology { - public static void main(String[] args){ - FishMovementConfig conf = new FishMovementConfig(args); - new TopologyNode(conf, new StartFishMovement()); - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/FishPoint.java --- a/src/alice/test/topology/aquarium/FishPoint.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -package alice.test.topology.aquarium; - -import org.msgpack.annotation.Message; - -@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; - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/KeyInputCodeSegment.java --- a/src/alice/test/topology/aquarium/KeyInputCodeSegment.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -package alice.test.topology.aquarium; - -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; - -public class KeyInputCodeSegment implements KeyListener{ - - 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 keyReleased(KeyEvent event) { - - } - - @Override - public void keyTyped(KeyEvent event) { - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/MakeFrame.java --- a/src/alice/test/topology/aquarium/MakeFrame.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ -package alice.test.topology.aquarium; - -import java.awt.GraphicsConfiguration; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.net.URL; - -import javax.imageio.ImageIO; -import javax.media.j3d.Background; -import javax.media.j3d.BoundingSphere; -import javax.media.j3d.BranchGroup; -import javax.media.j3d.DirectionalLight; -import javax.media.j3d.ImageComponent2D; - -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.vecmath.Color3f; -import javax.vecmath.Point3d; -import javax.vecmath.Vector3f; - -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("image1.jpg"); - if (url!=null) { - img = ImageIO.read(url); - } else { - img = ImageIO.read(new File("image/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(); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/MakeObject.java --- a/src/alice/test/topology/aquarium/MakeObject.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,115 +0,0 @@ -package alice.test.topology.aquarium; - -import java.awt.Image; -import java.awt.MediaTracker; -import java.awt.Toolkit; -import java.io.FileNotFoundException; -import java.net.URL; - -import javax.media.j3d.Appearance; -import javax.media.j3d.BranchGroup; -import javax.media.j3d.Texture; -import javax.media.j3d.Transform3D; -import javax.media.j3d.TransformGroup; -import javax.vecmath.Matrix4d; - -import com.sun.j3d.loaders.IncorrectFormatException; -import com.sun.j3d.loaders.ParsingErrorException; -import com.sun.j3d.loaders.Scene; -import com.sun.j3d.loaders.objectfile.ObjectFile; - -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; - - - 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("TUNA"); - 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); - } - - -} - diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/MouseViewEvent.java --- a/src/alice/test/topology/aquarium/MouseViewEvent.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -package alice.test.topology.aquarium; - -import java.awt.event.MouseEvent; -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; - - } - - @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(); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/ObjectList.java --- a/src/alice/test/topology/aquarium/ObjectList.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -package alice.test.topology.aquarium; - -import java.util.ArrayList; -import java.util.List; - -public class ObjectList { - public List table = new ArrayList(); -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/RefreshWindow.java --- a/src/alice/test/topology/aquarium/RefreshWindow.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -package alice.test.topology.aquarium; -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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); - } - } - -} - diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/ResetFish.java --- a/src/alice/test/topology/aquarium/ResetFish.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -package alice.test.topology.aquarium; - -import alice.codesegment.CodeSegment; - -public class ResetFish extends CodeSegment { - - public ResetFish(){} - - @Override - public void run() { - FishPoint fp = new FishPoint(0.0f,0.0f,0.0f); - ods.update("fish", fp); - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/SendLocation.java --- a/src/alice/test/topology/aquarium/SendLocation.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -package alice.test.topology.aquarium; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - - -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); - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/SendMaxsize.java --- a/src/alice/test/topology/aquarium/SendMaxsize.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -package alice.test.topology.aquarium; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -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); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/SetLocation.java --- a/src/alice/test/topology/aquarium/SetLocation.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -package alice.test.topology.aquarium; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - - -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); - - } - - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/StartFishMovement.java --- a/src/alice/test/topology/aquarium/StartFishMovement.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -package alice.test.topology.aquarium; - -import alice.codesegment.CodeSegment; - -public class StartFishMovement extends CodeSegment{ - @Override - public void run(){ - new CheckMyName(); - } - - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/TakeMynum.java --- a/src/alice/test/topology/aquarium/TakeMynum.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -package alice.test.topology.aquarium; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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); - } - - @Override - public void run() { - new TakePnum(this.mynum); - ods.put("num", 0); - new TakeMynum(this.mynum.index+1); - } - -} - diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/TakePnum.java --- a/src/alice/test/topology/aquarium/TakePnum.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -package alice.test.topology.aquarium; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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; - } - - @Override - public void run() { - ods.update("parent", "num", - this.pnum.asInteger()+this.mynum.asInteger()); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/aquarium/ViewChange.java --- a/src/alice/test/topology/aquarium/ViewChange.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -package alice.test.topology.aquarium; - -import java.awt.*; - -import javax.media.j3d.*; -import javax.vecmath.*; -import com.sun.j3d.utils.universe.*; - -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(); - - 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.setTransform(Transform_camera_pos); - - addMouseMotionListener(new MouseViewEvent(this)); - - } - - - -} - diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/fish/AssignStartX.java --- a/src/alice/test/topology/fish/AssignStartX.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -package alice.test.topology.fish; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -public class AssignStartX extends CodeSegment { - - 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); - - 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); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/fish/CheckMyName.java --- a/src/alice/test/topology/fish/CheckMyName.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -package alice.test.topology.fish; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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"); - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/fish/DistributedFish.java --- a/src/alice/test/topology/fish/DistributedFish.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package alice.test.topology.fish; - -import alice.topology.node.TopologyNode; - -public class DistributedFish { - - public static void main(String[] args) { - FishConfig conf = new FishConfig(args); - new TopologyNode(conf, new StartFish()); - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/fish/FishConfig.java --- a/src/alice/test/topology/fish/FishConfig.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -package alice.test.topology.fish; - -import alice.topology.node.TopologyNodeConfig; - -public class FishConfig extends TopologyNodeConfig { - - public FishConfig(String[] args) { - super(args); - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/fish/GetStartX.java --- a/src/alice/test/topology/fish/GetStartX.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -package alice.test.topology.fish; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -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); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/fish/PeekStartX.java --- a/src/alice/test/topology/fish/PeekStartX.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -package alice.test.topology.fish; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -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); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/fish/Routing.java --- a/src/alice/test/topology/fish/Routing.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -package alice.test.topology.fish; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.msgpack.annotation.Message; -import org.msgpack.annotation.Optional; - -@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 Routing(String name, int id, int width, int startX) { - this.name = name; - this.id = id; - this.width = width; - this.startX = startX; - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/fish/RoutingTable.java --- a/src/alice/test/topology/fish/RoutingTable.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -package alice.test.topology.fish; - -import java.util.ArrayList; -import java.util.List; - -import org.msgpack.annotation.Message; - -@Message -public class RoutingTable { - - int sumWidth = 0; - List table = new ArrayList(); - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/fish/SendWidth.java --- a/src/alice/test/topology/fish/SendWidth.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -package alice.test.topology.fish; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -public class SendWidth extends CodeSegment { - - 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); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/fish/StartFish.java --- a/src/alice/test/topology/fish/StartFish.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package alice.test.topology.fish; - -import alice.codesegment.CodeSegment; - -public class StartFish extends CodeSegment { - - @Override - public void run() { - new CheckMyName(); // separate processing - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/fish/StartStartX.java --- a/src/alice/test/topology/fish/StartStartX.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package alice.test.topology.fish; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/fish/WidthReceiver.java --- a/src/alice/test/topology/fish/WidthReceiver.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -package alice.test.topology.fish; - -import java.util.Collections; -import java.util.Comparator; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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() { - @Override - public int compare(Routing o1, Routing o2) { - return o1.id - o2.id; - } - }); - 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); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/ring/CheckMyName.java --- a/src/alice/test/topology/ring/CheckMyName.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -package alice.test.topology.ring; - -import org.apache.log4j.Logger; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -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"); - } - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/ring/FirstRingMessagePassing.java --- a/src/alice/test/topology/ring/FirstRingMessagePassing.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -package alice.test.topology.ring; - -import org.msgpack.type.ValueFactory; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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"); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/ring/RingFinish.java --- a/src/alice/test/topology/ring/RingFinish.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -package alice.test.topology.ring; - -import org.msgpack.type.ValueFactory; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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; - } - - @Override - public void run() { - ods.put(sendKey, "finish", ValueFactory.createNilValue()); - ods.finish(sendKey); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/ring/RingMessagePassing.java --- a/src/alice/test/topology/ring/RingMessagePassing.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package alice.test.topology.ring; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -public class RingMessagePassing extends CodeSegment { - - 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"); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/ring/RingTopology.java --- a/src/alice/test/topology/ring/RingTopology.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -package alice.test.topology.ring; - -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)); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/ring/RingTopologyConfig.java --- a/src/alice/test/topology/ring/RingTopologyConfig.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -package alice.test.topology.ring; - -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]); - } - } - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/ring/StartRing.java --- a/src/alice/test/topology/ring/StartRing.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -package alice.test.topology.ring; - -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"); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/share/AutoIncrement.java --- a/src/alice/test/topology/share/AutoIncrement.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -package alice.test.topology.share; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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); - } - - @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); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/share/CheckLocalIndex.java --- a/src/alice/test/topology/share/CheckLocalIndex.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -package alice.test.topology.share; - -import java.util.List; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -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); - - - 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 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); - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/share/CheckMyName.java --- a/src/alice/test/topology/share/CheckMyName.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -package alice.test.topology.share; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - - -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); - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/share/DataInfo.java --- a/src/alice/test/topology/share/DataInfo.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -package alice.test.topology.share; - -import org.msgpack.annotation.Message; - -@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; - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/share/LookUpData.java --- a/src/alice/test/topology/share/LookUpData.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -package alice.test.topology.share; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -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); - } - - @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 diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/share/SendData.java --- a/src/alice/test/topology/share/SendData.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package alice.test.topology.share; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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()); - } - -} \ No newline at end of file diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/share/ShareConfig.java --- a/src/alice/test/topology/share/ShareConfig.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -package alice.test.topology.share; - -import alice.topology.node.TopologyNodeConfig; - -public class ShareConfig extends TopologyNodeConfig { - - public ShareConfig(String[] args){ - super(args); - } - - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/share/ShareTopology.java --- a/src/alice/test/topology/share/ShareTopology.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -package alice.test.topology.share; -import alice.topology.node.TopologyNode; - -public class ShareTopology { - public static void main(String[] args){ - ShareConfig conf = new ShareConfig(args); - new TopologyNode(conf, new StartFishMovement()); - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/test/topology/share/StartFishMovement.java --- a/src/alice/test/topology/share/StartFishMovement.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -package alice.test.topology.share; - -import alice.codesegment.CodeSegment; - -public class StartFishMovement extends CodeSegment{ - @Override - public void run(){ - new CheckMyName(); - } - - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/HostMessage.java --- a/src/alice/topology/HostMessage.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -package alice.topology; - -import org.msgpack.annotation.Message; - -@Message -public class HostMessage { - - public String name; - public int port; - public String connectionName; - public String reverseName; - public String absName; - public boolean reconnectFlag = false; - - 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; - } - - public void setABSName(String name){ - absName = name; - } - - public String getABSName(){ - return absName; - } - - public void setFlag(){ - this.reconnectFlag = true; - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/ConfigWaiter.java --- a/src/alice/topology/manager/ConfigWaiter.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -package alice.topology.manager; - -import org.msgpack.type.ValueFactory; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; -import alice.topology.manager.reconnection.ReceiveError; - -public class ConfigWaiter extends CodeSegment { - - 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()); - new ReceiveError(); - return; - } - ConfigWaiter cs3 = new ConfigWaiter(count); - cs3.done.setKey("local", "done"); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/IncomingHosts.java --- a/src/alice/topology/manager/IncomingHosts.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -package alice.topology.manager; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; - -import org.msgpack.type.ValueFactory; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.DataSegment; -import alice.datasegment.Receiver; -import alice.topology.HostMessage; - -public class IncomingHosts extends CodeSegment { - - HashMap> topology; - LinkedList nodeNames; - Receiver host = ids.create(CommandType.TAKE); - Receiver connection = ids.create(CommandType.TAKE); - - public IncomingHosts(HashMap> topology, LinkedList nodeNames) { - this.topology = topology; - this.nodeNames = nodeNames; - } - - @Override - public void run() { - HostMessage host = this.host.asClass(HostMessage.class); - @SuppressWarnings("unchecked") - HashMap> connectionList = this.connection.asClass(HashMap.class); - - String nodeName = nodeNames.poll(); - // Manager connect to Node - - DataSegment.connect(nodeName, "", host.name, host.port, host.reconnectFlag); - ods.put(nodeName, "host", nodeName); - LinkedList nodes = topology.get(nodeName); - ArrayList list; - for (NodeInfo nodeInfo : nodes) { - HostMessage newHost = new HostMessage(host.name, host.port, nodeInfo.connectionName, nodeInfo.reverseName); - ods.put("local", nodeInfo.sourceNodeName, newHost); - - if (connectionList.containsKey(nodeInfo.sourceNodeName)){ - list = connectionList.get(nodeInfo.sourceNodeName); - } else { - list = new ArrayList(); - connectionList.put(nodeInfo.sourceNodeName, list); - - } - list.add(newHost); - } - ods.update("local", "connection", connectionList); - - if (nodeNames.isEmpty()) { - // configuration finish - for (String key : topology.keySet()) { - ods.put("local", key, ValueFactory.createNilValue()); - } - } else { - IncomingHosts cs = new IncomingHosts(topology, nodeNames); - cs.host.setKey("local", "host"); - cs.connection.setKey("local", "connection"); - } - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/NodeInfo.java --- a/src/alice/topology/manager/NodeInfo.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -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; - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/StartTopologyManager.java --- a/src/alice/topology/manager/StartTopologyManager.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -package alice.topology.manager; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; - -import org.apache.log4j.Logger; - -import alice.codesegment.CodeSegment; -import alice.topology.HostMessage; - -import com.alexmerz.graphviz.ParseException; -import com.alexmerz.graphviz.Parser; -import com.alexmerz.graphviz.objects.Edge; -import com.alexmerz.graphviz.objects.Graph; -import com.alexmerz.graphviz.objects.Node; - -public class StartTopologyManager extends CodeSegment { - - TopologyManagerConfig conf; - Logger logger = Logger.getLogger(StartTopologyManager.class); - - public StartTopologyManager(TopologyManagerConfig conf) { - this.conf = conf; - } - - @Override - public void run() { - LinkedList nodeNames = new LinkedList(); - HashMap> topology = new HashMap>(); - int nodeNum = 0; - try { - FileReader reader = new FileReader(new File(conf.confFilePath)); - Parser parser = new Parser(); - parser.parse(reader); - ArrayList graphs = parser.getGraphs(); - for (Graph graph : graphs) { - ArrayList nodes = graph.getNodes(false); - nodeNum = nodes.size(); - for (Node node : nodes) { - String nodeName = node.getId().getId(); - nodeNames.add(nodeName); - topology.put(nodeName, new LinkedList()); - } - ArrayList edges = graph.getEdges(); - HashMap hash = new HashMap(); - for (Edge edge : edges) { - String connection = edge.getAttribute("label"); - String source = edge.getSource().getNode().getId().getId(); - String target = edge.getTarget().getNode().getId().getId(); - LinkedList 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(); - } - HashMap> connectionList = new HashMap>(); - ods.put("connection", connectionList); - ods.put("_ABSIPTABLE" ,new ArrayList()); - - new createABSIPList(); - - IncomingHosts cs1 = new IncomingHosts(topology, nodeNames); - cs1.host.setKey("host"); - cs1.connection.setKey("connection"); - - ConfigWaiter cs3 = new ConfigWaiter(nodeNum); - cs3.done.setKey("local", "done"); - - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/TopologyFinish.java --- a/src/alice/topology/manager/TopologyFinish.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -package alice.topology.manager; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -public class TopologyFinish extends CodeSegment { - public Receiver finish = ids.create(CommandType.TAKE); - @Override - public void run() { - System.exit(0); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/TopologyManager.java --- a/src/alice/topology/manager/TopologyManager.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package alice.topology.manager; - -import alice.daemon.AliceDaemon; - -public class TopologyManager { - - public static void main(String[] args) { - TopologyManagerConfig conf = new TopologyManagerConfig(args); - new AliceDaemon(conf).listen(); - new StartTopologyManager(conf).execute(); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/TopologyManagerConfig.java --- a/src/alice/topology/manager/TopologyManagerConfig.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package alice.topology.manager; - -import alice.daemon.Config; - -public class TopologyManagerConfig extends Config { - - public String confFilePath; - - public TopologyManagerConfig(String[] args) { - super(args); - for (int i = 0; i < args.length; i++) { - if ("-conf".equals(args[i])) { - confFilePath = args[++i]; - } - } - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/createABSIPList.java --- a/src/alice/topology/manager/createABSIPList.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -package alice.topology.manager; - -import java.util.List; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; -import alice.topology.HostMessage; - -public class createABSIPList extends CodeSegment{ - private Receiver rData = ids.create(CommandType.TAKE); - private Receiver hlist = ids.create(CommandType.PEEK); - - public createABSIPList(){ - rData.setKey("_ABS_IP"); - hlist.setKey("_ABSIPTABLE"); - } - - @Override - public void run() { - HostMessage host = rData.asClass(HostMessage.class); - @SuppressWarnings("unchecked") - List ABSIPList = hlist.asClass(List.class); - ABSIPList.add(host); - ods.update("_ABSIPTABLE", ABSIPList); - - new createABSIPList(); - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/keeparive/CheckExistTask.java --- a/src/alice/topology/manager/keeparive/CheckExistTask.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package alice.topology.manager.keeparive; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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(); - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/keeparive/CreateSchedule.java --- a/src/alice/topology/manager/keeparive/CreateSchedule.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -package alice.topology.manager.keeparive; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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"); - } - - @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(); - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/keeparive/CreateTask.java --- a/src/alice/topology/manager/keeparive/CreateTask.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -package alice.topology.manager.keeparive; - -import java.util.List; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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 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; - } - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/keeparive/KeepAlive.java --- a/src/alice/topology/manager/keeparive/KeepAlive.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -package alice.topology.manager.keeparive; - -import alice.topology.node.TopologyNode; -import alice.topology.node.TopologyNodeConfig; - -public class KeepAlive { - public static void main(String[] args) { - TopologyNodeConfig conf = new TopologyNodeConfig(args); - new TopologyNode(conf, new StartKeepAlive()); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/keeparive/ListManager.java --- a/src/alice/topology/manager/keeparive/ListManager.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -package alice.topology.manager.keeparive; - -import java.util.LinkedList; - -public class ListManager { - private LinkedList list = new LinkedList(); - - public LinkedList 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(); - } - - 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(); - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/keeparive/ListManagerTest.java --- a/src/alice/topology/manager/keeparive/ListManagerTest.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -package alice.topology.manager.keeparive; - -import java.util.LinkedList; - -public class ListManagerTest { - public static void main(String args[]){ - TaskExecuter.getInstance().getNowTask(); - ListManager manager = new ListManager(); - LinkedList nameList = new LinkedList(); - 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 diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/keeparive/RemoveTask.java --- a/src/alice/topology/manager/keeparive/RemoveTask.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -package alice.topology.manager.keeparive; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -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 - - 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); - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/keeparive/RespondData.java --- a/src/alice/topology/manager/keeparive/RespondData.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -package alice.topology.manager.keeparive; - -public class RespondData { - public String from; - public long time; - - public RespondData(String str, long t){ - from = str; - time = t; - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/keeparive/RespondPing.java --- a/src/alice/topology/manager/keeparive/RespondPing.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -package alice.topology.manager.keeparive; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.DataSegment; -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); - } - - @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).close(); - } 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); - } - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/keeparive/StartKeepAlive.java --- a/src/alice/topology/manager/keeparive/StartKeepAlive.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package alice.topology.manager.keeparive; - -import alice.codesegment.CodeSegment; - -public class StartKeepAlive extends CodeSegment { - - @Override - public void run() { - new CreateTask(); - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/keeparive/TaskExecuter.java --- a/src/alice/topology/manager/keeparive/TaskExecuter.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -package alice.topology.manager.keeparive; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.DataSegment; -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 TaskExecuter() {} - public static TaskExecuter getInstance() { - return instance; - } - - public void setKey() { - ids.init(); - info.setKey("_WAITINGLIST"); - } - - @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()).close(); - } - } - 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 TaskInfo getNowTask() { - return nowTask; - } - - // 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 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 diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/keeparive/TaskInfo.java --- a/src/alice/topology/manager/keeparive/TaskInfo.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -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; - } - - 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); - } -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/keeparive/TaskType.java --- a/src/alice/topology/manager/keeparive/TaskType.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -package alice.topology.manager.keeparive; - -public enum TaskType { - PING, - CLOSE, -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/reconnection/CheckABSName.java --- a/src/alice/topology/manager/reconnection/CheckABSName.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -package alice.topology.manager.reconnection; - -import java.util.List; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.DataSegment; -import alice.datasegment.Receiver; -import alice.topology.HostMessage; - -public class CheckABSName extends CodeSegment{ - private Receiver abs = ids.create(CommandType.PEEK); - private Receiver host = ids.create(CommandType.TAKE); - private HostMessage message; - - public CheckABSName(HostMessage mes) { - message = mes; - abs.setKey("_ABSIPTABLE"); - host.setKey("host"); - } - - @Override - public void run() { - System.out.println("CheckABSName"); - @SuppressWarnings("unchecked") - List ABSIPList = abs.asClass(List.class); - HostMessage hostInfo = host.asClass(HostMessage.class); - for (HostMessage mes : ABSIPList){ - if (mes.name.equals(message.name)&&mes.port == message.port){ - DataSegment.remove(mes.getABSName()); - DataSegment.connect(mes.getABSName(), "", hostInfo.name, hostInfo.port, hostInfo.reconnectFlag); - ods.put(mes.getABSName(), "host", mes.getABSName()); - ods.put("_RECABSNAME", mes.getABSName()); - ods.put("_HMCLONE", new HostMessage(mes.name, mes.port)); - mes.port = hostInfo.port; - mes.name = hostInfo.name; - ods.update("_ABSIPTABLE", ABSIPList); - new CheckConnectionList(); - return; - } - } - ods.put("host", hostInfo); - new ReceiveError(); - System.out.println("not match"); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/reconnection/CheckConnectionList.java --- a/src/alice/topology/manager/reconnection/CheckConnectionList.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -package alice.topology.manager.reconnection; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import org.msgpack.type.ValueFactory; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; -import alice.topology.HostMessage; - -public class CheckConnectionList extends CodeSegment { - - private Receiver name = ids.create(CommandType.TAKE); - private Receiver connection = ids.create(CommandType.TAKE); - private Receiver abs = ids.create(CommandType.PEEK); - private Receiver clone = ids.create(CommandType.TAKE); - - public CheckConnectionList(){ - name.setKey("_RECABSNAME"); - connection.setKey("connection"); - abs.setKey("_ABSIPTABLE"); - clone.setKey("_HMCLONE"); - } - - @Override - public void run() { - @SuppressWarnings("unchecked") - HashMap> connectionList = connection.asClass(HashMap.class); - @SuppressWarnings("unchecked") - List ABSIPList = abs.asClass(List.class); - String absName = name.asClass(String.class); - HostMessage oldInfo = clone.asClass(HostMessage.class); - HostMessage newInfo = null; - for (HostMessage mes : ABSIPList){ - if (mes.absName.equals(absName)){ - newInfo = mes; - break; - } - } - - List clist = connectionList.get(absName); - for (HostMessage mes : clist){ - mes.setFlag(); - ods.put(absName, mes); - for (HostMessage mes2 : ABSIPList){ - if (mes.name.equals(mes2.name)&&mes.port == mes2.port){ - String absName2 = mes2.getABSName(); - List clist2 = connectionList.get(absName2); - for (HostMessage mes3 : clist2){ - if (mes3.name.equals(oldInfo.name)&&mes3.port == oldInfo.port){ - mes3.name = newInfo.name; - mes3.port = newInfo.port; - mes3.setFlag(); - ods.put(absName2, "_RECODATA", mes3); - break; - } - } - break; - } - } - } - System.out.println("SendHost Data"); - ods.put(absName, ValueFactory.createNilValue()); - ods.update("connection", connectionList); - new ReceiveError(); - } -} \ No newline at end of file diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/reconnection/ReceiveError.java --- a/src/alice/topology/manager/reconnection/ReceiveError.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -package alice.topology.manager.reconnection; - -import java.io.IOException; -import java.net.Socket; -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; -import alice.topology.HostMessage; - -public class ReceiveError extends CodeSegment { - public Receiver reportInfo = ids.create(CommandType.TAKE); - - public ReceiveError(){ - reportInfo.setKey("_ERROR"); - } - - @Override - public void run() { - HostMessage message = reportInfo.asClass(HostMessage.class); - try { - System.out.println("Receive Error "+ message.port); - Socket socket = new Socket(message.name, message.port); - socket.close(); - System.out.println("alive "+message.port); - } catch (IOException e) { - System.out.println("Receive Error "+ message.port); - new CheckABSName(message); - return; - } - new ReceiveError(); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/reconnection/ReceiveReconnectData.java --- a/src/alice/topology/manager/reconnection/ReceiveReconnectData.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -package alice.topology.manager.reconnection; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.DataSegment; -import alice.datasegment.Receiver; -import alice.topology.HostMessage; - -public class ReceiveReconnectData extends CodeSegment{ - private Receiver hostData = ids.create(CommandType.TAKE); - - public ReceiveReconnectData(){ - hostData.setKey("_RECODATA"); - } - - @Override - public void run() { - HostMessage host = hostData.asClass(HostMessage.class); - DataSegment.remove(host.connectionName); - DataSegment.connect(host.connectionName, host.reverseName, host.name, host.port, host.reconnectFlag); - ods.put(host.connectionName, "reverseKey", host.reverseName); - new ReceiveReconnectData(); - } - - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/manager/reconnection/SendError.java --- a/src/alice/topology/manager/reconnection/SendError.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package alice.topology.manager.reconnection; - -import alice.codesegment.CodeSegment; -import alice.topology.HostMessage; - -public class SendError extends CodeSegment{ - private HostMessage message; - - public SendError(HostMessage mes){ - message = mes; - } - - @Override - public void run() { - ods.put("manager", "_ERROR", message); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/node/ConfigurationFinish.java --- a/src/alice/topology/node/ConfigurationFinish.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -package alice.topology.node; - -import org.msgpack.type.ValueFactory; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; -import alice.topology.manager.reconnection.ReceiveReconnectData; - -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())) { - new ReceiveReconnectData(); - - ods.put("manager", "done", ValueFactory.createNilValue()); - Start cs = new Start(startCS); - cs.done.setKey("manager", "start"); - return; - } - - ConfigurationFinish cs3 = new ConfigurationFinish(startCS); - cs3.reverseCount.setKey("local", "reverseCount", this.reverseCount.index); - cs3.configNodeNum.setKey("local", "configNodeNum"); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/node/IncomingAbstractHostName.java --- a/src/alice/topology/node/IncomingAbstractHostName.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -package alice.topology.node; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; -import alice.topology.HostMessage; - -public class IncomingAbstractHostName extends CodeSegment { - - public Receiver absName = ids.create(CommandType.PEEK); - private HostMessage host; // need CodeSegment - - public IncomingAbstractHostName(HostMessage _host){ - host = _host; - } - - @Override - public void run() { - String absName = this.absName.asString(); - IncomingConnectionInfo cs = new IncomingConnectionInfo(absName, 0); - cs.hostInfo.setKey("manager", absName); - host.setABSName(absName); - ods.put("manager","_ABS_IP", host); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/node/IncomingConnectionInfo.java --- a/src/alice/topology/node/IncomingConnectionInfo.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -package alice.topology.node; - -import java.util.ArrayList; -import java.util.List; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.DataSegment; -import alice.datasegment.Receiver; -import alice.topology.HostMessage; - -public class IncomingConnectionInfo extends CodeSegment { - - public Receiver hostInfo = ids.create(CommandType.TAKE); - private List connectionList; - private String absName; - private int count; - - public IncomingConnectionInfo(String absName, int count) { - this.absName = absName; - this.count = count; - this.connectionList = new ArrayList(); - } - - public IncomingConnectionInfo(String absName, int count, List connectionList) { - this.absName = absName; - this.count = count; - this.connectionList = connectionList; - } - - @Override - public void run() { - if (this.hostInfo.getVal() == null) { - ods.put("local", "configNodeNum", count); - return; - } - - HostMessage hostInfo = this.hostInfo.asClass(HostMessage.class); - //System.out.println(hostInfo.reconnectFlag); - DataSegment.connect(hostInfo.connectionName, hostInfo.reverseName, hostInfo.name, hostInfo.port, hostInfo.reconnectFlag); - ods.put(hostInfo.connectionName, "reverseKey", hostInfo.reverseName); - connectionList.add(hostInfo.connectionName); - ods.update("_CLIST", connectionList); - IncomingConnectionInfo cs = new IncomingConnectionInfo(absName, ++count, connectionList); - cs.hostInfo.setKey("manager", absName); - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/node/IncomingReverseKey.java --- a/src/alice/topology/node/IncomingReverseKey.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -package alice.topology.node; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.DataSegment; -import alice.datasegment.Receiver; -import org.msgpack.type.Value; - -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 = ((Value)this.reverseKey.getVal()).asRawValue().getString(); - 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"); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/node/Start.java --- a/src/alice/topology/node/Start.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -package alice.topology.node; - -import org.apache.log4j.Logger; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -public class Start extends CodeSegment { - - public Receiver done = ids.create(CommandType.PEEK); - 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; - startCS.execute(); - - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/node/StartTopologyNode.java --- a/src/alice/topology/node/StartTopologyNode.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -package alice.topology.node; - -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.net.UnknownHostException; -import java.util.Enumeration; - -import alice.codesegment.CodeSegment; -import alice.datasegment.DataSegment; -import alice.topology.HostMessage; - -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() { - DataSegment.connect("manager", "", conf.managerHostName, conf.managerPort, false); - 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(host); - 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"); - - } - - @SuppressWarnings("unused") - private String getIPAddress() throws SocketException { - Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); - - while(interfaces.hasMoreElements()){ - NetworkInterface network = interfaces.nextElement(); - Enumeration addresses = network.getInetAddresses(); - - while(addresses.hasMoreElements()){ - String address = addresses.nextElement().getHostAddress(); - if(!"127.0.0.1".equals(address) && !"0.0.0.0".equals(address)){ - return address; - } - } - } - return "127.0.0.1"; - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/node/TopologyNode.java --- a/src/alice/topology/node/TopologyNode.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package alice.topology.node; - -import alice.codesegment.CodeSegment; -import alice.daemon.AliceDaemon; - -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); - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/alice/topology/node/TopologyNodeConfig.java --- a/src/alice/topology/node/TopologyNodeConfig.java Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -package alice.topology.node; - -import alice.daemon.Config; - -public class TopologyNodeConfig extends Config { - - String managerHostName; - int managerPort; - - public TopologyNodeConfig(String[] args) { - super(args); - for (int i = 0; i< args.length; i++) { - if ("-host".equals(args[i])) { - managerHostName = args[++i]; - } else if ("-port".equals(args[i])) { - managerPort = Integer.parseInt(args[++i]); - } - } - } - -} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/log4j.xml --- a/src/log4j.xml Wed Apr 16 17:37:48 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/codesegment/CodeSegment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/codesegment/CodeSegment.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,26 @@ +package alice.codesegment; + +import java.util.ArrayList; + +import alice.codesegment.InputDataSegment; +import alice.datasegment.Receiver; + +public abstract class CodeSegment implements Runnable { + + public InputDataSegment ids = new InputDataSegment(this); + public OutputDataSegment ods = new OutputDataSegment(); + public ArrayList list = new ArrayList(); + + public void execute() { + ids.receive(); + } + + public void recycle(){ + ids.init(); + ids.setCounter(list.size()); + for (Receiver receiver : list) { + ids.recommand(receiver); + } + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/codesegment/CodeSegmentManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/codesegment/CodeSegmentManager.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,31 @@ +package alice.codesegment; + +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import org.apache.log4j.Logger; + +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()); + private Logger logger = Logger.getLogger(CodeSegmentManager.class); + + 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()); + } + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/codesegment/InputDataSegment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/codesegment/InputDataSegment.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,116 @@ +package alice.codesegment; + +import java.util.concurrent.atomic.AtomicInteger; + +import alice.datasegment.Command; +import alice.datasegment.CommandType; +import alice.datasegment.DataSegment; +import alice.datasegment.ReceiveLocalData; +import alice.datasegment.ReceiveRemoteData; +import alice.datasegment.Receiver; + +/** + * InputDataSegment Manager + * keep tracking unbound/bound count + * @author kazz + * + */ +public class InputDataSegment { + + public CodeSegment cs; + private AtomicInteger count = new AtomicInteger(1); // 1 for no input data segments + private AtomicInteger keyCount = new AtomicInteger(0); // number of DataSegments + public InputDataSegment(CodeSegment cs) { + this.cs = cs; + } + + public void init(){ + count = new AtomicInteger(1); + keyCount = new AtomicInteger(0); + } + + public void quickPeek(Receiver receiver) { + cs.list.add(receiver); + if (receiver.managerKey==null){ + DataSegment.getLocal().peek(receiver, cs); + } else { + DataSegment.get(receiver.managerKey).quickPeek(receiver ,cs); + } + } + + public void quickTake(Receiver receiver) { + cs.list.add(receiver); + if (receiver.managerKey==null){ + DataSegment.getLocal().quickTake(receiver, cs); + } else { + DataSegment.get(receiver.managerKey).quickTake(receiver ,cs); + } + } + + public void peek(Receiver receiver) { + cs.list.add(receiver); + if (receiver.managerKey==null){ + DataSegment.getLocal().peek(receiver, cs); + } else { + DataSegment.get(receiver.managerKey).peek(receiver, cs); + } + } + + + public void take(Receiver receiver) { + cs.list.add(receiver); + if (receiver.managerKey==null){ + DataSegment.getLocal().take(receiver, cs); + } else { + DataSegment.get(receiver.managerKey).take(receiver, cs); + } + } + + public void reply(Receiver receiver, Command reply) { + receiver.index = reply.index; + receiver.from = reply.reverseKey; + if (reply.reverseKey==null){ + receiver.setData(new ReceiveRemoteData(reply.val)); + } else if (!reply.reverseKey.equals("local")) { + receiver.setData(new ReceiveRemoteData(reply.val)); + } else { + receiver.setData(new ReceiveLocalData(reply.obj)); + } + receive(); + } + + public void register() { + count.getAndIncrement(); + keyCount.getAndIncrement(); + } + + public void setKey() { + if (keyCount.decrementAndGet() == 0) { + receive(); + } + } + + public void receive() { + if (count.decrementAndGet() == 0) { + CodeSegmentManager.submit(cs); + } + } + + /** + * InputDataSegment factory + * @param type PEEK or TAKE + * @return Receiver of DataSegment reply + */ + public Receiver create(CommandType type) { + return new Receiver(this, type); + } + + public void recommand(Receiver receiver) { + // TODO why only local? + DataSegment.getLocal().recommand(receiver, cs); + } + + public void setCounter(int cnt){ + count.set(cnt); + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/codesegment/OutputDataSegment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/codesegment/OutputDataSegment.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,99 @@ +package alice.codesegment; + +import alice.datasegment.DataSegment; +import alice.datasegment.Receiver; + +public class OutputDataSegment { + + /** + * for local + */ + + public void flip(Receiver receiver) { + receiver.managerKey=null; + DataSegment.getLocal().put(receiver.key, receiver.getObj()); + } + + public void put(String key, Object val) { + DataSegment.getLocal().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 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); + } + } + + 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 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 + */ + + public void finish(String managerKey) { + DataSegment.get(managerKey).finish(); + } + + /** + * close socket for RemoteDataSegment after send other messages. + * + * @param managerKey + */ + + 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); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/codesegment/SingletonMessage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/codesegment/SingletonMessage.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,13 @@ +package alice.codesegment; + +import org.msgpack.MessagePack; + +public class SingletonMessage { + + private static final MessagePack instance = new MessagePack(); + + public static MessagePack getInstance(){ + return instance; + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/daemon/AcceptThread.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/daemon/AcceptThread.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,43 @@ +package alice.daemon; + +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; + +import org.apache.log4j.Logger; + +import alice.datasegment.DataSegment; + +public class AcceptThread extends Thread { + + 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; + } + + @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(); + } + } + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/daemon/AliceDaemon.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/daemon/AliceDaemon.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,61 @@ +package alice.daemon; + +import java.io.FileWriter; +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.nio.channels.ServerSocketChannel; + +import org.apache.log4j.Logger; +import org.apache.log4j.PatternLayout; +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); + + //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(); + } + + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/daemon/CommandMessage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/daemon/CommandMessage.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,25 @@ +package alice.daemon; + +import org.msgpack.annotation.Message; +import org.msgpack.type.Value; + +@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; + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/daemon/Config.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/daemon/Config.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,35 @@ +package alice.daemon; + +import org.apache.log4j.Level; + +public class Config { + + public int localPort = 10000; + public String logFile = null; + public Level level = null; + + 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 ("-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; + } + } + } + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/daemon/Connection.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/daemon/Connection.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,58 @@ +package alice.daemon; + +import java.io.IOException; +import java.net.Socket; +import java.nio.ByteBuffer; +import java.util.concurrent.LinkedBlockingQueue; + +import alice.codesegment.SingletonMessage; +import alice.datasegment.Command; + +public class Connection { + + public Socket socket; + public LinkedBlockingQueue sendQueue = new LinkedBlockingQueue(); + + public Connection(Socket socket) { + this.socket = socket; + } + + public Connection() {} + + public void sendCommand(Command cmd) { + try { + sendQueue.put(cmd); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + 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 (IOException e) { + e.printStackTrace(); + } + } + + public void close(){ + try { + socket.shutdownOutput(); + socket.shutdownInput(); + socket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/daemon/IncomingTcpConnection.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/daemon/IncomingTcpConnection.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,101 @@ +package alice.daemon; + +import java.io.EOFException; +import java.io.IOException; +import java.nio.channels.ClosedChannelException; + +import org.msgpack.unpacker.Unpacker; + +import alice.codesegment.SingletonMessage; +import alice.datasegment.Command; +import alice.datasegment.CommandType; +import alice.datasegment.DataSegment; +import alice.datasegment.DataSegmentKey; +import alice.datasegment.DataSegmentManager; +import alice.datasegment.LocalDataSegmentManager; +import alice.topology.HostMessage; +import alice.topology.manager.keeparive.RespondData; +import alice.topology.manager.reconnection.SendError; + +public class IncomingTcpConnection extends Thread { + + public Connection connection; + public DataSegmentManager manager; + public String reverseKey; + private LocalDataSegmentManager lmanager = DataSegment.getLocal(); + + public IncomingTcpConnection(Connection connection, DataSegmentManager manager, String reverseKey) { + this.manager = manager; + this.connection = connection; + this.reverseKey = reverseKey; + } + + /** + * pipeline thread for receiving + */ + public void run() { + Unpacker unpacker = this.getUnpacker(); + if (unpacker == null) { + return; + } + while (true) { + try { + CommandMessage msg = unpacker.read(CommandMessage.class); + CommandType type = CommandType.getCommandTypeFromId(msg.type); + switch (type) { + case UPDATE: + getDataSegmentKey(msg).runCommand(new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey)); + break; + case PUT: + getDataSegmentKey(msg).runCommand(new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey)); + break; + case PEEK: + getDataSegmentKey(msg).runCommand(new Command(type, null, null, null, msg.index, msg.seq, connection, null, null, msg.flag)); + break; + case TAKE: + getDataSegmentKey(msg).runCommand(new Command(type, null, null, null, msg.index, msg.seq, connection, null, null, msg.flag)); + break; + case REMOVE: + getDataSegmentKey(msg).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.sendCommand(new Command(CommandType.CLOSE, null, null, null, 0, 0, null, null, null)); + return; + } catch (EOFException e) { + new SendError(new HostMessage(connection.socket.getInetAddress().getHostName(), connection.socket.getPort())).execute(); + connection.sendCommand(new Command(CommandType.CLOSE, null, null, null, 0, 0, null, null, null)); + return; + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + private Unpacker getUnpacker() { + Unpacker unpacker = null; + try { + unpacker = SingletonMessage.getInstance().createUnpacker(connection.socket.getInputStream()); + } catch (IOException e2) { + e2.printStackTrace(); + } + return unpacker; + } + + private DataSegmentKey getDataSegmentKey(CommandMessage msg) { + return lmanager.getDataSegmentKey(msg.key); + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/daemon/OutboundTcpConnection.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/daemon/OutboundTcpConnection.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,42 @@ +package alice.daemon; + +import java.io.IOException; +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.socket.close(); + return; + case FINISH: + System.exit(0); + return; + default: + break; + } + connection.write(cmd); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/datasegment/Command.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/datasegment/Command.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,110 @@ +package alice.datasegment; + +import java.io.IOException; +import java.util.concurrent.BlockingQueue; +import org.msgpack.type.Value; + +import alice.codesegment.CodeSegment; +import alice.codesegment.SingletonMessage; +import alice.daemon.CommandMessage; +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 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 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 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 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 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); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/datasegment/CommandType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/datasegment/CommandType.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,48 @@ +package alice.datasegment; + +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 hash = new HashMap(); + 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); + } + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/datasegment/DataSegment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/datasegment/DataSegment.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,48 @@ +package alice.datasegment; + +import java.util.concurrent.ConcurrentHashMap; + +import alice.daemon.IncomingTcpConnection; + +public class DataSegment { + + private static DataSegment dataSegment = new DataSegment(); + private LocalDataSegmentManager local = new LocalDataSegmentManager(); + private ConcurrentHashMap dataSegmentManagers = new ConcurrentHashMap(); //TODO Over Head + private ConcurrentHashMap acceptHash = new ConcurrentHashMap(); + + 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 RemoteDataSegmentManager connect(String connectionKey, String reverseKey, String hostName, int port, boolean rFlag) { + RemoteDataSegmentManager manager = new RemoteDataSegmentManager(connectionKey, reverseKey, hostName, port, rFlag); + register(connectionKey, 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); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/datasegment/DataSegmentKey.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/datasegment/DataSegmentKey.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,103 @@ +package alice.datasegment; + +import java.util.ArrayList; +import java.util.Iterator; + +import alice.datasegment.Command; + +/** + * Synchronized DataSegment for each DataSegment key + * @author kazz + * + */ +public class DataSegmentKey { + + private ArrayList dataList = new ArrayList(); + private ArrayList waitList = new ArrayList(); + 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 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 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(); + } + } + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/datasegment/DataSegmentManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/datasegment/DataSegmentManager.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,71 @@ +package alice.datasegment; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.log4j.Logger; + +import alice.codesegment.CodeSegment; + +public abstract class DataSegmentManager { + + protected ConcurrentHashMap seqHash = new ConcurrentHashMap(); + protected LinkedBlockingQueue replyQueue = new LinkedBlockingQueue(); + 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 take(Receiver receiver, CodeSegment cs); + public abstract void peek(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(String key); + public abstract void close(); + public abstract void finish(); + + public abstract void ping(String returnKey); + public abstract void response(String returnKey); + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/datasegment/DataSegmentValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/datasegment/DataSegmentValue.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,25 @@ +package alice.datasegment; + +import org.msgpack.type.Value; + +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; + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/datasegment/LocalDataSegmentManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/datasegment/LocalDataSegmentManager.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,172 @@ +package alice.datasegment; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import org.apache.log4j.Logger; + +import alice.codesegment.CodeSegment; + +public class LocalDataSegmentManager extends DataSegmentManager { + + private String reverseKey = "local"; + private ConcurrentHashMap dataSegments = new ConcurrentHashMap(); + 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()); + + public LocalDataSegmentManager() { + new Thread(replyThread, "LocalDataSegmentManager-replyCommand").start(); + } + + 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 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 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() { + + } + + 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 response(String returnKey) { + + } + + @Override + public void shutdown(String key) { + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/datasegment/ReceiveLocalData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/datasegment/ReceiveLocalData.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,55 @@ +package alice.datasegment; + +import java.io.IOException; + +import org.msgpack.type.ArrayValue; +import org.msgpack.type.Value; + +import alice.codesegment.SingletonMessage; +import alice.datasegment.ReceiverData; + +public class ReceiveLocalData implements ReceiverData { + private Object obj; + + public ReceiveLocalData(Object obj2) { + this.obj = obj2; + } + + public String asString() { + return (String) obj; + } + + public int asInteger() { + return (Integer) obj; + } + + public Float asFloat() { + return (Float) obj; + } + + public ArrayValue asArray(){ + return (ArrayValue) obj; + } + + @SuppressWarnings("unchecked") + public T asClass(Class clazz) { + return (T) obj; + + } + + @Override + public Value getVal() { + try { + return SingletonMessage.getInstance().unconvert(obj); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public Object getObj() { + return obj; + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/datasegment/ReceiveRemoteData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/datasegment/ReceiveRemoteData.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,69 @@ +package alice.datasegment; + +import java.io.IOException; + +import org.msgpack.type.ArrayValue; +import org.msgpack.type.Value; +import org.msgpack.type.ValueType; + +import alice.codesegment.SingletonMessage; + +public class ReceiveRemoteData implements ReceiverData { + public Value val; + + public ReceiveRemoteData() { + } + + public ReceiveRemoteData(Value val2) { + this.val = val2; + } + + 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 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 T asClass(Class clazz) { + try { + return SingletonMessage.getInstance().convert(val, clazz); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + + } + + @Override + public Value getVal() { + return val; + } + + @Override + public Object getObj() { + return val; + } + +} \ No newline at end of file diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/datasegment/Receiver.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/datasegment/Receiver.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,112 @@ +package alice.datasegment; + + +import alice.codesegment.InputDataSegment; + +/** + * MessagePack implementation and DataSegment Receiver + * @author kazz + * + */ +public class Receiver { + private ReceiverData data = new ReceiveRemoteData(); + public InputDataSegment ids; + public int index; + public String from; + public CommandType type; + public String managerKey; + public String key; + + public Receiver(InputDataSegment ids, CommandType type) { + this.ids = ids; + this.type = type; + ids.register(); + + } + + public void setQuickKey(String managerKey, String key){ + setQuickKey(managerKey, key, 0); + } + + public void setQuickKey(String managerKey, String key, int index) { + this.managerKey = managerKey; + this.key = key; + switch (type) { + case PEEK: + ids.quickPeek(this); + break; + case TAKE: + ids.quickTake(this); + break; + default: + break; + } + ids.setKey(); + } + + public void setKey(String managerKey, String key) { + setKey(managerKey, key, 0); + } + + public void setKey(String managerKey, String key, int index) { + this.managerKey = managerKey; + this.key = key; + this.index = index; + switch (type) { + case PEEK: + ids.peek(this); + break; + case TAKE: + ids.take(this); + break; + default: + break; + } + ids.setKey(); + } + + public void setKey(String key) { + setKey(key, 0); + } + + public void setKey(String key, int index) { + this.key = key; + this.index = index; + switch (type) { + case PEEK: + ids.peek(this); + break; + case TAKE: + ids.take(this); + break; + default: + break; + } + ids.setKey(); + } + + public void setData(ReceiverData r) { + data = r; + } + + public int asInteger() { + return data.asInteger(); + } + + public String asString() { + return data.asString(); + } + + public T asClass(Class clazz) { + return data.asClass(clazz); + } + + public Object getObj() { + return data.getObj(); + } + + public Object getVal() { + return data.getVal(); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/datasegment/ReceiverData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/datasegment/ReceiverData.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,16 @@ +package alice.datasegment; + +import org.msgpack.type.ArrayValue; +import org.msgpack.type.Value; + +public interface ReceiverData { + + public String asString(); + public int asInteger(); + public Float asFloat() ; + public ArrayValue asArray(); + public T asClass(Class clazz); + public Value getVal(); + public Object getObj(); + +} \ No newline at end of file diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/datasegment/RemoteDataSegmentManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/datasegment/RemoteDataSegmentManager.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,166 @@ +package alice.datasegment; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.channels.SocketChannel; + +import org.apache.log4j.Logger; + +import alice.codesegment.CodeSegment; +import alice.daemon.Connection; +import alice.daemon.IncomingTcpConnection; +import alice.daemon.OutboundTcpConnection; +import alice.topology.HostMessage; +import alice.topology.manager.reconnection.SendError; + +public class RemoteDataSegmentManager extends DataSegmentManager { + + Connection connection; + Logger logger; + + public RemoteDataSegmentManager(String connectionKey, final String reverseKey, final String hostName, final int port, final boolean rFlag) { + 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&&!rFlag); + new IncomingTcpConnection(connection, manager, reverseKey).start(); + new OutboundTcpConnection(connection).start(); + // if connection failed need to stop these thread + if (connect){ + new SendError(new HostMessage(hostName, port)).execute(); + } + } + }.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 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 finish() { + Command cmd = new Command(CommandType.FINISH, null, null, null, 0, 0, null, null, null); + connection.sendCommand(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 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 shutdown(String key) { + connection.close(); + } + + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/api/FlipCodeSegment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/api/FlipCodeSegment.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,21 @@ +package alice.test.codesegment.api; + +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); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/api/FlipTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/api/FlipTest.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,38 @@ +package alice.test.codesegment.api; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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); + } + + @Override + public void run() { + if(flag){ + System.out.println(System.currentTimeMillis() - t +" ms"); + System.exit(0); + } + t = System.currentTimeMillis(); + for (int i=0;i10000){ + 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); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/api/PutCodeSegment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/api/PutCodeSegment.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,32 @@ +package alice.test.codesegment.api; + +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(); + } + + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/api/StartCodeSegment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/api/StartCodeSegment.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,54 @@ +package alice.test.codesegment.api; + +import java.util.Random; + +import alice.codesegment.CodeSegment; +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; + } + + @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 ("-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); + } + } + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/api/TakeCodeSegment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/api/TakeCodeSegment.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,19 @@ +package alice.test.codesegment.api; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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); + + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/api/TestApiAlice.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/api/TestApiAlice.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,16 @@ +package alice.test.codesegment.api; + +import alice.daemon.AliceDaemon; +import alice.daemon.Config; + +public class TestApiAlice { + + /** + * @param args + */ + public static void main(String[] args) { + new AliceDaemon(new Config(args)).listen(); + new StartCodeSegment(args).execute(); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/api/UpdateCodeSegment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/api/UpdateCodeSegment.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,28 @@ +package alice.test.codesegment.api; + +import org.msgpack.type.Value; +import org.msgpack.type.ValueFactory; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class UpdateCodeSegment extends CodeSegment { + 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); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/local/SingletonTestCodeSegment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/local/SingletonTestCodeSegment.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,34 @@ +package alice.test.codesegment.local; + +import org.msgpack.type.Value; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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"); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/local/StartCodeSegment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/local/StartCodeSegment.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,20 @@ +package alice.test.codesegment.local; + +import alice.codesegment.CodeSegment; + +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. + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/local/TestCodeSegment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/local/TestCodeSegment.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,32 @@ +package alice.test.codesegment.local; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +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"); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/local/TestLocalAlice.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/local/TestLocalAlice.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,12 @@ +package alice.test.codesegment.local; + +import alice.daemon.AliceDaemon; +import alice.daemon.Config; + +public class TestLocalAlice { + public static void main(String args[]) { + new AliceDaemon(new Config(args)).listen(); // logger off + new StartCodeSegment().execute(); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/local/bitonicsort/DataInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/DataInfo.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,16 @@ +package alice.test.codesegment.local.bitonicsort; + +import org.msgpack.annotation.Message; + +@Message +public class DataInfo { + public int index; + public int ptr; + + public DataInfo(){} + + public DataInfo(int _index, int _ptr){ + index = _index; + ptr = _ptr; + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/local/bitonicsort/DataList.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/DataList.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,75 @@ +package alice.test.codesegment.local.bitonicsort; + +import org.msgpack.annotation.Message; + +@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=t1.length) { // switch to the second list + t1 = t2; n = 0; + } + if (j>=t2.length || t0[i] < t2[j]) { + t1[n] = t0[i]; // including when j reaches end of t2 + i++; n++; + } else { + t1[n] = t2[j]; + j++; n++; + } + } + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/local/bitonicsort/LocalBitonicSort.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/LocalBitonicSort.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,13 @@ +package alice.test.codesegment.local.bitonicsort; + +import alice.daemon.AliceDaemon; +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(); + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/local/bitonicsort/MakeData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/MakeData.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,31 @@ +package alice.test.codesegment.local.bitonicsort; + +import java.util.Random; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class MakeData extends CodeSegment { + + private Receiver info1 = ids.create(CommandType.PEEK); + private Receiver info2 = ids.create(CommandType.TAKE); + + 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); + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/local/bitonicsort/RangeInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/RangeInfo.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,16 @@ +package alice.test.codesegment.local.bitonicsort; + +import org.msgpack.annotation.Message; + +@Message +public class RangeInfo { + public int range; + public boolean lastFlag; + + public RangeInfo(){} + public RangeInfo(int i,boolean flag){ + range = i; + lastFlag = flag; + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/local/bitonicsort/SetInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/SetInfo.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,40 @@ +package alice.test.codesegment.local.bitonicsort; + +import alice.codesegment.CodeSegment; + +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; + } + + @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(); + } + + 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; + } + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/local/bitonicsort/SetTask.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/SetTask.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,48 @@ +package alice.test.codesegment.local.bitonicsort; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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); + + } + + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/local/bitonicsort/ShowData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/ShowData.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,43 @@ +package alice.test.codesegment.local.bitonicsort; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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); + } + + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/local/bitonicsort/Sort.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/Sort.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +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]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"); + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/codesegment/local/bitonicsort/SortConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/codesegment/local/bitonicsort/SortConfig.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,39 @@ +package alice.test.codesegment.local.bitonicsort; + +import org.msgpack.annotation.Message; + +@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 clazz = tep.toClass(); // load Class + @SuppressWarnings("unused") + CSTemplate cs = (CSTemplate)clazz.newInstance(); // create instance + + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/AutoIncrement.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/AutoIncrement.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,47 @@ +package alice.test.topology.aquarium; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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); + } + + @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); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/CheckLocalIndex.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/CheckLocalIndex.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,33 @@ +package alice.test.topology.aquarium; + +import java.util.List; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +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 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); + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/CheckMyName.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/CheckMyName.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,97 @@ +package alice.test.topology.aquarium; + +import java.util.Random; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + + +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); + } + + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/FishMovementConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/FishMovementConfig.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,12 @@ +package alice.test.topology.aquarium; + +import alice.topology.node.TopologyNodeConfig; + +public class FishMovementConfig extends TopologyNodeConfig { + + public FishMovementConfig(String[] args){ + super(args); + } + + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/FishMovementTopology.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/FishMovementTopology.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,11 @@ +package alice.test.topology.aquarium; +import alice.topology.node.TopologyNode; + +public class FishMovementTopology { + public static void main(String[] args){ + FishMovementConfig conf = new FishMovementConfig(args); + new TopologyNode(conf, new StartFishMovement()); + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/FishPoint.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/FishPoint.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,48 @@ +package alice.test.topology.aquarium; + +import org.msgpack.annotation.Message; + +@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; + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/KeyInputCodeSegment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/KeyInputCodeSegment.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,55 @@ +package alice.test.topology.aquarium; + +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +public class KeyInputCodeSegment implements KeyListener{ + + 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 keyReleased(KeyEvent event) { + + } + + @Override + public void keyTyped(KeyEvent event) { + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/MakeFrame.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/MakeFrame.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,114 @@ +package alice.test.topology.aquarium; + +import java.awt.GraphicsConfiguration; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.net.URL; + +import javax.imageio.ImageIO; +import javax.media.j3d.Background; +import javax.media.j3d.BoundingSphere; +import javax.media.j3d.BranchGroup; +import javax.media.j3d.DirectionalLight; +import javax.media.j3d.ImageComponent2D; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.vecmath.Color3f; +import javax.vecmath.Point3d; +import javax.vecmath.Vector3f; + +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("image1.jpg"); + if (url!=null) { + img = ImageIO.read(url); + } else { + img = ImageIO.read(new File("image/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(); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/MakeObject.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/MakeObject.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,115 @@ +package alice.test.topology.aquarium; + +import java.awt.Image; +import java.awt.MediaTracker; +import java.awt.Toolkit; +import java.io.FileNotFoundException; +import java.net.URL; + +import javax.media.j3d.Appearance; +import javax.media.j3d.BranchGroup; +import javax.media.j3d.Texture; +import javax.media.j3d.Transform3D; +import javax.media.j3d.TransformGroup; +import javax.vecmath.Matrix4d; + +import com.sun.j3d.loaders.IncorrectFormatException; +import com.sun.j3d.loaders.ParsingErrorException; +import com.sun.j3d.loaders.Scene; +import com.sun.j3d.loaders.objectfile.ObjectFile; + +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; + + + 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("TUNA"); + 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); + } + + +} + diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/MouseViewEvent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/MouseViewEvent.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,52 @@ +package alice.test.topology.aquarium; + +import java.awt.event.MouseEvent; +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; + + } + + @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(); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/ObjectList.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/ObjectList.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,8 @@ +package alice.test.topology.aquarium; + +import java.util.ArrayList; +import java.util.List; + +public class ObjectList { + public List table = new ArrayList(); +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/RefreshWindow.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/RefreshWindow.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,28 @@ +package alice.test.topology.aquarium; +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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); + } + } + +} + diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/ResetFish.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/ResetFish.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,16 @@ +package alice.test.topology.aquarium; + +import alice.codesegment.CodeSegment; + +public class ResetFish extends CodeSegment { + + public ResetFish(){} + + @Override + public void run() { + FishPoint fp = new FishPoint(0.0f,0.0f,0.0f); + ods.update("fish", fp); + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/SendLocation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/SendLocation.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,30 @@ +package alice.test.topology.aquarium; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + + +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); + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/SendMaxsize.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/SendMaxsize.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,22 @@ +package alice.test.topology.aquarium; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +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); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/SetLocation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/SetLocation.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,27 @@ +package alice.test.topology.aquarium; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + + +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); + + } + + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/StartFishMovement.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/StartFishMovement.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,12 @@ +package alice.test.topology.aquarium; + +import alice.codesegment.CodeSegment; + +public class StartFishMovement extends CodeSegment{ + @Override + public void run(){ + new CheckMyName(); + } + + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/TakeMynum.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/TakeMynum.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,27 @@ +package alice.test.topology.aquarium; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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); + } + + @Override + public void run() { + new TakePnum(this.mynum); + ods.put("num", 0); + new TakeMynum(this.mynum.index+1); + } + +} + diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/TakePnum.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/TakePnum.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,24 @@ +package alice.test.topology.aquarium; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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; + } + + @Override + public void run() { + ods.update("parent", "num", + this.pnum.asInteger()+this.mynum.asInteger()); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/aquarium/ViewChange.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/ViewChange.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,58 @@ +package alice.test.topology.aquarium; + +import java.awt.*; + +import javax.media.j3d.*; +import javax.vecmath.*; +import com.sun.j3d.utils.universe.*; + +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(); + + 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.setTransform(Transform_camera_pos); + + addMouseMotionListener(new MouseViewEvent(this)); + + } + + + +} + diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/fish/AssignStartX.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/fish/AssignStartX.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,40 @@ +package alice.test.topology.fish; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class AssignStartX extends CodeSegment { + + 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); + + 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); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/fish/CheckMyName.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/fish/CheckMyName.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,58 @@ +package alice.test.topology.fish; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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"); + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/fish/DistributedFish.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/fish/DistributedFish.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,13 @@ +package alice.test.topology.fish; + +import alice.topology.node.TopologyNode; + +public class DistributedFish { + + public static void main(String[] args) { + FishConfig conf = new FishConfig(args); + new TopologyNode(conf, new StartFish()); + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/fish/FishConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/fish/FishConfig.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,12 @@ +package alice.test.topology.fish; + +import alice.topology.node.TopologyNodeConfig; + +public class FishConfig extends TopologyNodeConfig { + + public FishConfig(String[] args) { + super(args); + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/fish/GetStartX.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/fish/GetStartX.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,21 @@ +package alice.test.topology.fish; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +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); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/fish/PeekStartX.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/fish/PeekStartX.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,23 @@ +package alice.test.topology.fish; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +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); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/fish/Routing.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/fish/Routing.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,35 @@ +package alice.test.topology.fish; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.msgpack.annotation.Message; +import org.msgpack.annotation.Optional; + +@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 Routing(String name, int id, int width, int startX) { + this.name = name; + this.id = id; + this.width = width; + this.startX = startX; + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/fish/RoutingTable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/fish/RoutingTable.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,14 @@ +package alice.test.topology.fish; + +import java.util.ArrayList; +import java.util.List; + +import org.msgpack.annotation.Message; + +@Message +public class RoutingTable { + + int sumWidth = 0; + List table = new ArrayList(); + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/fish/SendWidth.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/fish/SendWidth.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,22 @@ +package alice.test.topology.fish; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class SendWidth extends CodeSegment { + + 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); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/fish/StartFish.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/fish/StartFish.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,13 @@ +package alice.test.topology.fish; + +import alice.codesegment.CodeSegment; + +public class StartFish extends CodeSegment { + + @Override + public void run() { + new CheckMyName(); // separate processing + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/fish/StartStartX.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/fish/StartStartX.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,18 @@ +package alice.test.topology.fish; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/fish/WidthReceiver.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/fish/WidthReceiver.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,55 @@ +package alice.test.topology.fish; + +import java.util.Collections; +import java.util.Comparator; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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() { + @Override + public int compare(Routing o1, Routing o2) { + return o1.id - o2.id; + } + }); + 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); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/ring/CheckMyName.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/ring/CheckMyName.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,39 @@ +package alice.test.topology.ring; + +import org.apache.log4j.Logger; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +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"); + } + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/ring/FirstRingMessagePassing.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/ring/FirstRingMessagePassing.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,43 @@ +package alice.test.topology.ring; + +import org.msgpack.type.ValueFactory; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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"); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/ring/RingFinish.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/ring/RingFinish.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,24 @@ +package alice.test.topology.ring; + +import org.msgpack.type.ValueFactory; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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; + } + + @Override + public void run() { + ods.put(sendKey, "finish", ValueFactory.createNilValue()); + ods.finish(sendKey); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/ring/RingMessagePassing.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/ring/RingMessagePassing.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,18 @@ +package alice.test.topology.ring; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class RingMessagePassing extends CodeSegment { + + 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"); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/ring/RingTopology.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/ring/RingTopology.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,12 @@ +package alice.test.topology.ring; + +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)); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/ring/RingTopologyConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/ring/RingTopologyConfig.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,24 @@ +package alice.test.topology.ring; + +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]); + } + } + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/ring/StartRing.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/ring/StartRing.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,16 @@ +package alice.test.topology.ring; + +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"); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/share/AutoIncrement.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/share/AutoIncrement.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,28 @@ +package alice.test.topology.share; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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); + } + + @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); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/share/CheckLocalIndex.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/share/CheckLocalIndex.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,44 @@ +package alice.test.topology.share; + +import java.util.List; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +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); + + + 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 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); + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/share/CheckMyName.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/share/CheckMyName.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,48 @@ +package alice.test.topology.share; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + + +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); + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/share/DataInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/share/DataInfo.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,22 @@ +package alice.test.topology.share; + +import org.msgpack.annotation.Message; + +@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; + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/share/LookUpData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/share/LookUpData.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,32 @@ +package alice.test.topology.share; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +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); + } + + @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 diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/share/SendData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/share/SendData.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,20 @@ +package alice.test.topology.share; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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()); + } + +} \ No newline at end of file diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/share/ShareConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/share/ShareConfig.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,12 @@ +package alice.test.topology.share; + +import alice.topology.node.TopologyNodeConfig; + +public class ShareConfig extends TopologyNodeConfig { + + public ShareConfig(String[] args){ + super(args); + } + + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/share/ShareTopology.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/share/ShareTopology.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,11 @@ +package alice.test.topology.share; +import alice.topology.node.TopologyNode; + +public class ShareTopology { + public static void main(String[] args){ + ShareConfig conf = new ShareConfig(args); + new TopologyNode(conf, new StartFishMovement()); + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/test/topology/share/StartFishMovement.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/share/StartFishMovement.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,12 @@ +package alice.test.topology.share; + +import alice.codesegment.CodeSegment; + +public class StartFishMovement extends CodeSegment{ + @Override + public void run(){ + new CheckMyName(); + } + + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/HostMessage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/HostMessage.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,40 @@ +package alice.topology; + +import org.msgpack.annotation.Message; + +@Message +public class HostMessage { + + public String name; + public int port; + public String connectionName; + public String reverseName; + public String absName; + public boolean reconnectFlag = false; + + 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; + } + + public void setABSName(String name){ + absName = name; + } + + public String getABSName(){ + return absName; + } + + public void setFlag(){ + this.reconnectFlag = true; + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/ConfigWaiter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/ConfigWaiter.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,31 @@ +package alice.topology.manager; + +import org.msgpack.type.ValueFactory; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +import alice.topology.manager.reconnection.ReceiveError; + +public class ConfigWaiter extends CodeSegment { + + 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()); + new ReceiveError(); + return; + } + ConfigWaiter cs3 = new ConfigWaiter(count); + cs3.done.setKey("local", "done"); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/IncomingHosts.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/IncomingHosts.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,67 @@ +package alice.topology.manager; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; + +import org.msgpack.type.ValueFactory; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.DataSegment; +import alice.datasegment.Receiver; +import alice.topology.HostMessage; + +public class IncomingHosts extends CodeSegment { + + HashMap> topology; + LinkedList nodeNames; + Receiver host = ids.create(CommandType.TAKE); + Receiver connection = ids.create(CommandType.TAKE); + + public IncomingHosts(HashMap> topology, LinkedList nodeNames) { + this.topology = topology; + this.nodeNames = nodeNames; + } + + @Override + public void run() { + HostMessage host = this.host.asClass(HostMessage.class); + @SuppressWarnings("unchecked") + HashMap> connectionList = this.connection.asClass(HashMap.class); + + String nodeName = nodeNames.poll(); + // Manager connect to Node + + DataSegment.connect(nodeName, "", host.name, host.port, host.reconnectFlag); + ods.put(nodeName, "host", nodeName); + LinkedList nodes = topology.get(nodeName); + ArrayList list; + for (NodeInfo nodeInfo : nodes) { + HostMessage newHost = new HostMessage(host.name, host.port, nodeInfo.connectionName, nodeInfo.reverseName); + ods.put("local", nodeInfo.sourceNodeName, newHost); + + if (connectionList.containsKey(nodeInfo.sourceNodeName)){ + list = connectionList.get(nodeInfo.sourceNodeName); + } else { + list = new ArrayList(); + connectionList.put(nodeInfo.sourceNodeName, list); + + } + list.add(newHost); + } + ods.update("local", "connection", connectionList); + + if (nodeNames.isEmpty()) { + // configuration finish + for (String key : topology.keySet()) { + ods.put("local", key, ValueFactory.createNilValue()); + } + } else { + IncomingHosts cs = new IncomingHosts(topology, nodeNames); + cs.host.setKey("local", "host"); + cs.connection.setKey("local", "connection"); + } + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/NodeInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/NodeInfo.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +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; + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/StartTopologyManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/StartTopologyManager.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,93 @@ +package alice.topology.manager; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; + +import org.apache.log4j.Logger; + +import alice.codesegment.CodeSegment; +import alice.topology.HostMessage; + +import com.alexmerz.graphviz.ParseException; +import com.alexmerz.graphviz.Parser; +import com.alexmerz.graphviz.objects.Edge; +import com.alexmerz.graphviz.objects.Graph; +import com.alexmerz.graphviz.objects.Node; + +public class StartTopologyManager extends CodeSegment { + + TopologyManagerConfig conf; + Logger logger = Logger.getLogger(StartTopologyManager.class); + + public StartTopologyManager(TopologyManagerConfig conf) { + this.conf = conf; + } + + @Override + public void run() { + LinkedList nodeNames = new LinkedList(); + HashMap> topology = new HashMap>(); + int nodeNum = 0; + try { + FileReader reader = new FileReader(new File(conf.confFilePath)); + Parser parser = new Parser(); + parser.parse(reader); + ArrayList graphs = parser.getGraphs(); + for (Graph graph : graphs) { + ArrayList nodes = graph.getNodes(false); + nodeNum = nodes.size(); + for (Node node : nodes) { + String nodeName = node.getId().getId(); + nodeNames.add(nodeName); + topology.put(nodeName, new LinkedList()); + } + ArrayList edges = graph.getEdges(); + HashMap hash = new HashMap(); + for (Edge edge : edges) { + String connection = edge.getAttribute("label"); + String source = edge.getSource().getNode().getId().getId(); + String target = edge.getTarget().getNode().getId().getId(); + LinkedList 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(); + } + HashMap> connectionList = new HashMap>(); + ods.put("connection", connectionList); + ods.put("_ABSIPTABLE" ,new ArrayList()); + + new createABSIPList(); + + IncomingHosts cs1 = new IncomingHosts(topology, nodeNames); + cs1.host.setKey("host"); + cs1.connection.setKey("connection"); + + ConfigWaiter cs3 = new ConfigWaiter(nodeNum); + cs3.done.setKey("local", "done"); + + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/TopologyFinish.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/TopologyFinish.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,14 @@ +package alice.topology.manager; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class TopologyFinish extends CodeSegment { + public Receiver finish = ids.create(CommandType.TAKE); + @Override + public void run() { + System.exit(0); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/TopologyManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/TopologyManager.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,13 @@ +package alice.topology.manager; + +import alice.daemon.AliceDaemon; + +public class TopologyManager { + + public static void main(String[] args) { + TopologyManagerConfig conf = new TopologyManagerConfig(args); + new AliceDaemon(conf).listen(); + new StartTopologyManager(conf).execute(); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/TopologyManagerConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/TopologyManagerConfig.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,18 @@ +package alice.topology.manager; + +import alice.daemon.Config; + +public class TopologyManagerConfig extends Config { + + public String confFilePath; + + public TopologyManagerConfig(String[] args) { + super(args); + for (int i = 0; i < args.length; i++) { + if ("-conf".equals(args[i])) { + confFilePath = args[++i]; + } + } + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/createABSIPList.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/createABSIPList.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,31 @@ +package alice.topology.manager; + +import java.util.List; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +import alice.topology.HostMessage; + +public class createABSIPList extends CodeSegment{ + private Receiver rData = ids.create(CommandType.TAKE); + private Receiver hlist = ids.create(CommandType.PEEK); + + public createABSIPList(){ + rData.setKey("_ABS_IP"); + hlist.setKey("_ABSIPTABLE"); + } + + @Override + public void run() { + HostMessage host = rData.asClass(HostMessage.class); + @SuppressWarnings("unchecked") + List ABSIPList = hlist.asClass(List.class); + ABSIPList.add(host); + ods.update("_ABSIPTABLE", ABSIPList); + + new createABSIPList(); + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/keeparive/CheckExistTask.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/keeparive/CheckExistTask.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,20 @@ +package alice.topology.manager.keeparive; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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(); + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/keeparive/CreateSchedule.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/keeparive/CreateSchedule.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,24 @@ +package alice.topology.manager.keeparive; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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"); + } + + @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(); + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/keeparive/CreateTask.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/keeparive/CreateTask.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,34 @@ +package alice.topology.manager.keeparive; + +import java.util.List; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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 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; + } + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/keeparive/KeepAlive.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/keeparive/KeepAlive.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,12 @@ +package alice.topology.manager.keeparive; + +import alice.topology.node.TopologyNode; +import alice.topology.node.TopologyNodeConfig; + +public class KeepAlive { + public static void main(String[] args) { + TopologyNodeConfig conf = new TopologyNodeConfig(args); + new TopologyNode(conf, new StartKeepAlive()); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/keeparive/ListManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/keeparive/ListManager.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,85 @@ +package alice.topology.manager.keeparive; + +import java.util.LinkedList; + +public class ListManager { + private LinkedList list = new LinkedList(); + + public LinkedList 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(); + } + + 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(); + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/keeparive/ListManagerTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/keeparive/ListManagerTest.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,46 @@ +package alice.topology.manager.keeparive; + +import java.util.LinkedList; + +public class ListManagerTest { + public static void main(String args[]){ + TaskExecuter.getInstance().getNowTask(); + ListManager manager = new ListManager(); + LinkedList nameList = new LinkedList(); + 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 diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/keeparive/RemoveTask.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/keeparive/RemoveTask.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,33 @@ +package alice.topology.manager.keeparive; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +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 + + 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); + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/keeparive/RespondData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/keeparive/RespondData.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +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; + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/keeparive/RespondPing.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/keeparive/RespondPing.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,43 @@ +package alice.topology.manager.keeparive; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.DataSegment; +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); + } + + @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).close(); + } 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); + } + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/keeparive/StartKeepAlive.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/keeparive/StartKeepAlive.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,13 @@ +package alice.topology.manager.keeparive; + +import alice.codesegment.CodeSegment; + +public class StartKeepAlive extends CodeSegment { + + @Override + public void run() { + new CreateTask(); + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/keeparive/TaskExecuter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/keeparive/TaskExecuter.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,128 @@ +package alice.topology.manager.keeparive; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.DataSegment; +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 TaskExecuter() {} + public static TaskExecuter getInstance() { + return instance; + } + + public void setKey() { + ids.init(); + info.setKey("_WAITINGLIST"); + } + + @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()).close(); + } + } + 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 TaskInfo getNowTask() { + return nowTask; + } + + // 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 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 diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/keeparive/TaskInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/keeparive/TaskInfo.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +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; + } + + 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); + } +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/keeparive/TaskType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/keeparive/TaskType.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,6 @@ +package alice.topology.manager.keeparive; + +public enum TaskType { + PING, + CLOSE, +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/reconnection/CheckABSName.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/reconnection/CheckABSName.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,47 @@ +package alice.topology.manager.reconnection; + +import java.util.List; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.DataSegment; +import alice.datasegment.Receiver; +import alice.topology.HostMessage; + +public class CheckABSName extends CodeSegment{ + private Receiver abs = ids.create(CommandType.PEEK); + private Receiver host = ids.create(CommandType.TAKE); + private HostMessage message; + + public CheckABSName(HostMessage mes) { + message = mes; + abs.setKey("_ABSIPTABLE"); + host.setKey("host"); + } + + @Override + public void run() { + System.out.println("CheckABSName"); + @SuppressWarnings("unchecked") + List ABSIPList = abs.asClass(List.class); + HostMessage hostInfo = host.asClass(HostMessage.class); + for (HostMessage mes : ABSIPList){ + if (mes.name.equals(message.name)&&mes.port == message.port){ + DataSegment.remove(mes.getABSName()); + DataSegment.connect(mes.getABSName(), "", hostInfo.name, hostInfo.port, hostInfo.reconnectFlag); + ods.put(mes.getABSName(), "host", mes.getABSName()); + ods.put("_RECABSNAME", mes.getABSName()); + ods.put("_HMCLONE", new HostMessage(mes.name, mes.port)); + mes.port = hostInfo.port; + mes.name = hostInfo.name; + ods.update("_ABSIPTABLE", ABSIPList); + new CheckConnectionList(); + return; + } + } + ods.put("host", hostInfo); + new ReceiveError(); + System.out.println("not match"); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/reconnection/CheckConnectionList.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/reconnection/CheckConnectionList.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,70 @@ +package alice.topology.manager.reconnection; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.msgpack.type.ValueFactory; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +import alice.topology.HostMessage; + +public class CheckConnectionList extends CodeSegment { + + private Receiver name = ids.create(CommandType.TAKE); + private Receiver connection = ids.create(CommandType.TAKE); + private Receiver abs = ids.create(CommandType.PEEK); + private Receiver clone = ids.create(CommandType.TAKE); + + public CheckConnectionList(){ + name.setKey("_RECABSNAME"); + connection.setKey("connection"); + abs.setKey("_ABSIPTABLE"); + clone.setKey("_HMCLONE"); + } + + @Override + public void run() { + @SuppressWarnings("unchecked") + HashMap> connectionList = connection.asClass(HashMap.class); + @SuppressWarnings("unchecked") + List ABSIPList = abs.asClass(List.class); + String absName = name.asClass(String.class); + HostMessage oldInfo = clone.asClass(HostMessage.class); + HostMessage newInfo = null; + for (HostMessage mes : ABSIPList){ + if (mes.absName.equals(absName)){ + newInfo = mes; + break; + } + } + + List clist = connectionList.get(absName); + for (HostMessage mes : clist){ + mes.setFlag(); + ods.put(absName, mes); + for (HostMessage mes2 : ABSIPList){ + if (mes.name.equals(mes2.name)&&mes.port == mes2.port){ + String absName2 = mes2.getABSName(); + List clist2 = connectionList.get(absName2); + for (HostMessage mes3 : clist2){ + if (mes3.name.equals(oldInfo.name)&&mes3.port == oldInfo.port){ + mes3.name = newInfo.name; + mes3.port = newInfo.port; + mes3.setFlag(); + ods.put(absName2, "_RECODATA", mes3); + break; + } + } + break; + } + } + } + System.out.println("SendHost Data"); + ods.put(absName, ValueFactory.createNilValue()); + ods.update("connection", connectionList); + new ReceiveError(); + } +} \ No newline at end of file diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/reconnection/ReceiveError.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/reconnection/ReceiveError.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,33 @@ +package alice.topology.manager.reconnection; + +import java.io.IOException; +import java.net.Socket; +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +import alice.topology.HostMessage; + +public class ReceiveError extends CodeSegment { + public Receiver reportInfo = ids.create(CommandType.TAKE); + + public ReceiveError(){ + reportInfo.setKey("_ERROR"); + } + + @Override + public void run() { + HostMessage message = reportInfo.asClass(HostMessage.class); + try { + System.out.println("Receive Error "+ message.port); + Socket socket = new Socket(message.name, message.port); + socket.close(); + System.out.println("alive "+message.port); + } catch (IOException e) { + System.out.println("Receive Error "+ message.port); + new CheckABSName(message); + return; + } + new ReceiveError(); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/reconnection/ReceiveReconnectData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/reconnection/ReceiveReconnectData.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,26 @@ +package alice.topology.manager.reconnection; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.DataSegment; +import alice.datasegment.Receiver; +import alice.topology.HostMessage; + +public class ReceiveReconnectData extends CodeSegment{ + private Receiver hostData = ids.create(CommandType.TAKE); + + public ReceiveReconnectData(){ + hostData.setKey("_RECODATA"); + } + + @Override + public void run() { + HostMessage host = hostData.asClass(HostMessage.class); + DataSegment.remove(host.connectionName); + DataSegment.connect(host.connectionName, host.reverseName, host.name, host.port, host.reconnectFlag); + ods.put(host.connectionName, "reverseKey", host.reverseName); + new ReceiveReconnectData(); + } + + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/manager/reconnection/SendError.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/reconnection/SendError.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,18 @@ +package alice.topology.manager.reconnection; + +import alice.codesegment.CodeSegment; +import alice.topology.HostMessage; + +public class SendError extends CodeSegment{ + private HostMessage message; + + public SendError(HostMessage mes){ + message = mes; + } + + @Override + public void run() { + ods.put("manager", "_ERROR", message); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/node/ConfigurationFinish.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/node/ConfigurationFinish.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,36 @@ +package alice.topology.node; + +import org.msgpack.type.ValueFactory; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +import alice.topology.manager.reconnection.ReceiveReconnectData; + +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())) { + new ReceiveReconnectData(); + + ods.put("manager", "done", ValueFactory.createNilValue()); + Start cs = new Start(startCS); + cs.done.setKey("manager", "start"); + return; + } + + ConfigurationFinish cs3 = new ConfigurationFinish(startCS); + cs3.reverseCount.setKey("local", "reverseCount", this.reverseCount.index); + cs3.configNodeNum.setKey("local", "configNodeNum"); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/node/IncomingAbstractHostName.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/node/IncomingAbstractHostName.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,26 @@ +package alice.topology.node; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +import alice.topology.HostMessage; + +public class IncomingAbstractHostName extends CodeSegment { + + public Receiver absName = ids.create(CommandType.PEEK); + private HostMessage host; // need CodeSegment + + public IncomingAbstractHostName(HostMessage _host){ + host = _host; + } + + @Override + public void run() { + String absName = this.absName.asString(); + IncomingConnectionInfo cs = new IncomingConnectionInfo(absName, 0); + cs.hostInfo.setKey("manager", absName); + host.setABSName(absName); + ods.put("manager","_ABS_IP", host); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/node/IncomingConnectionInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/node/IncomingConnectionInfo.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,49 @@ +package alice.topology.node; + +import java.util.ArrayList; +import java.util.List; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.DataSegment; +import alice.datasegment.Receiver; +import alice.topology.HostMessage; + +public class IncomingConnectionInfo extends CodeSegment { + + public Receiver hostInfo = ids.create(CommandType.TAKE); + private List connectionList; + private String absName; + private int count; + + public IncomingConnectionInfo(String absName, int count) { + this.absName = absName; + this.count = count; + this.connectionList = new ArrayList(); + } + + public IncomingConnectionInfo(String absName, int count, List connectionList) { + this.absName = absName; + this.count = count; + this.connectionList = connectionList; + } + + @Override + public void run() { + if (this.hostInfo.getVal() == null) { + ods.put("local", "configNodeNum", count); + return; + } + + HostMessage hostInfo = this.hostInfo.asClass(HostMessage.class); + //System.out.println(hostInfo.reconnectFlag); + DataSegment.connect(hostInfo.connectionName, hostInfo.reverseName, hostInfo.name, hostInfo.port, hostInfo.reconnectFlag); + ods.put(hostInfo.connectionName, "reverseKey", hostInfo.reverseName); + connectionList.add(hostInfo.connectionName); + ods.update("_CLIST", connectionList); + IncomingConnectionInfo cs = new IncomingConnectionInfo(absName, ++count, connectionList); + cs.hostInfo.setKey("manager", absName); + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/node/IncomingReverseKey.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/node/IncomingReverseKey.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,30 @@ +package alice.topology.node; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.DataSegment; +import alice.datasegment.Receiver; +import org.msgpack.type.Value; + +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 = ((Value)this.reverseKey.getVal()).asRawValue().getString(); + 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"); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/node/Start.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/node/Start.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,28 @@ +package alice.topology.node; + +import org.apache.log4j.Logger; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class Start extends CodeSegment { + + public Receiver done = ids.create(CommandType.PEEK); + 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; + startCS.execute(); + + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/node/StartTopologyNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/node/StartTopologyNode.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,69 @@ +package alice.topology.node; + +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.Enumeration; + +import alice.codesegment.CodeSegment; +import alice.datasegment.DataSegment; +import alice.topology.HostMessage; + +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() { + DataSegment.connect("manager", "", conf.managerHostName, conf.managerPort, false); + 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(host); + 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"); + + } + + @SuppressWarnings("unused") + private String getIPAddress() throws SocketException { + Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); + + while(interfaces.hasMoreElements()){ + NetworkInterface network = interfaces.nextElement(); + Enumeration addresses = network.getInetAddresses(); + + while(addresses.hasMoreElements()){ + String address = addresses.nextElement().getHostAddress(); + if(!"127.0.0.1".equals(address) && !"0.0.0.0".equals(address)){ + return address; + } + } + } + return "127.0.0.1"; + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/node/TopologyNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/node/TopologyNode.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,18 @@ +package alice.topology.node; + +import alice.codesegment.CodeSegment; +import alice.daemon.AliceDaemon; + +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); + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/alice/topology/node/TopologyNodeConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/node/TopologyNodeConfig.java Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,21 @@ +package alice.topology.node; + +import alice.daemon.Config; + +public class TopologyNodeConfig extends Config { + + String managerHostName; + int managerPort; + + public TopologyNodeConfig(String[] args) { + super(args); + for (int i = 0; i< args.length; i++) { + if ("-host".equals(args[i])) { + managerHostName = args[++i]; + } else if ("-port".equals(args[i])) { + managerPort = Integer.parseInt(args[++i]); + } + } + } + +} diff -r 9f97ec18f8c5 -r 8f71c3e6f11d src/main/java/log4j.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/log4j.xml Wed Apr 16 18:26:07 2014 +0900 @@ -0,0 +1,13 @@ + + + + + + + + + + + + +