Mercurial > hg > Database > Christie
changeset 111:671246274719
fix file dir
author | akahori |
---|---|
date | Tue, 20 Nov 2018 18:29:13 +0900 |
parents | eab161e557bd |
children | 20f7270e997d |
files | src/main/java/christie/daemon/IncomingTcpConnection.java src/main/java/christie/datagear/Command/ReplyCommand.java src/main/java/christie/datagear/Command/TakeCommand.java src/main/java/christie/datagear/command/Command.java src/main/java/christie/datagear/command/CommandType.java src/main/java/christie/datagear/command/PeekCommand.java src/main/java/christie/datagear/command/PutCommand.java src/main/java/christie/datagear/command/RemotePeekCommand.java src/main/java/christie/datagear/command/RemoteTakeCommand.java src/main/java/christie/datagear/command/ReplyCommand.java src/main/java/christie/datagear/command/TakeCommand.java src/main/java/christie/topology/manager/StartTopologyManager.java src/main/java/christie/topology/node/StartTopologyNode.java |
diffstat | 13 files changed, 253 insertions(+), 50 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/christie/daemon/IncomingTcpConnection.java Mon Nov 19 12:31:36 2018 +0900 +++ b/src/main/java/christie/daemon/IncomingTcpConnection.java Tue Nov 20 18:29:13 2018 +0900 @@ -4,7 +4,6 @@ import christie.codegear.CodeGearManager; import christie.datagear.*; -import christie.datagear.command.Command; import christie.datagear.command.CommandType; import christie.datagear.RemoteMessage; import christie.datagear.command.RemotePeekCommand;
--- a/src/main/java/christie/datagear/Command/ReplyCommand.java Mon Nov 19 12:31:36 2018 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -package christie.datagear.command; - -import christie.daemon.Connection; -import christie.datagear.dg.DataGear; - -public class ReplyCommand extends PutCommand { - - public ReplyCommand(Command cm){ - super(0, null, cm.key, cm.dg); - this.fromDgmName = cm.fromDgmName; - this.type = CommandType.REPLY; - this.connection = cm.connection; - } - - public void setData(Object data){ - this.dg.setData(data); - } - -}
--- a/src/main/java/christie/datagear/Command/TakeCommand.java Mon Nov 19 12:31:36 2018 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -package christie.datagear.command; - -import christie.codegear.CodeGear; -import christie.datagear.dg.DataGear; - -import java.nio.ByteBuffer; - -public class TakeCommand extends Command { - - public TakeCommand(CodeGear cg, int cgmID, String toDgmName, String key, DataGear dg){ - this.type = CommandType.TAKE; - this.cgmID = cgmID; - this.toDgmName = toDgmName; - this.key = key; - this.dg = dg; - this.clazz = dg.getClazz(); - this.cg = cg; - } - - @Override - public ByteBuffer convert() { - return null; - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/datagear/command/Command.java Tue Nov 20 18:29:13 2018 +0900 @@ -0,0 +1,38 @@ +package christie.datagear.command; + +import christie.codegear.CodeGear; +import christie.daemon.Connection; +import christie.datagear.RemoteMessage; +import christie.datagear.command.CommandType; +import christie.datagear.dg.DataGear; + +import java.nio.ByteBuffer; + +public abstract class Command { + public CommandType type; + public String key; + public String toDgmName;// for take + public String fromDgmName = "local";//for remotetake/reply + public int cgmID = 0;// for local meta + public CodeGear cg = null;//for localtake + public DataGear dg = null;//for put/localtake/reply + public Class clazz = null;// for remote + public Connection connection = null;//for reply + + //for remote + public abstract ByteBuffer convert(); + + //for remote + public RemoteMessage createRemoteMessage(){ + return new RemoteMessage(type.id, fromDgmName, key, clazz.getName()); + } + + public void setInputs(){ + cg.getIdg().setInputs(key, dg); + } + + public void setDg(Object obj){ + this.dg.setData(obj); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/datagear/command/CommandType.java Tue Nov 20 18:29:13 2018 +0900 @@ -0,0 +1,36 @@ +package christie.datagear.command; + +import java.util.HashMap; + +public enum CommandType { + PUT, + TAKE, + PEEK, + REMOTETAKE, + REMOTEPEEK, + REPLY, + CLOSE, + FINISH; + + public int id;//コマンドのid + public static HashMap<Integer, CommandType> hash = new HashMap<Integer, CommandType>();//コマンド対応表 + private static int lastId = 0;//コマンドの総数 + + private CommandType() { + this.id = incrementLastId(); + }//for init + + 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); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/datagear/command/PeekCommand.java Tue Nov 20 18:29:13 2018 +0900 @@ -0,0 +1,11 @@ +package christie.datagear.command; + +import christie.codegear.CodeGear; +import christie.datagear.dg.DataGear; + +public class PeekCommand extends TakeCommand{ + public PeekCommand(CodeGear cg, int cgmID, String toDgmName, String key, DataGear dg) { + super(cg, cgmID, toDgmName, key, dg); + this.type = CommandType.PEEK; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/datagear/command/PutCommand.java Tue Nov 20 18:29:13 2018 +0900 @@ -0,0 +1,45 @@ +package christie.datagear.command; + +import christie.datagear.command.Command; +import christie.datagear.command.CommandType; +import christie.datagear.dg.DataGear; +import christie.datagear.dg.MessagePackDataGear; +import org.msgpack.MessagePack; + +import java.io.IOException; +import java.nio.ByteBuffer; + +public class PutCommand extends Command { + + public PutCommand(int cgmID, String toDgmName, String key, DataGear dg){ + this.type = CommandType.PUT; + this.cgmID = cgmID; + this.toDgmName = toDgmName; + this.key = key; + this.dg = dg; + this.clazz = dg.getClazz(); + } + + @Override + public ByteBuffer convert() { + ByteBuffer buf = null; + MessagePack packer = new MessagePack(); + + try { + byte[] command = packer.write(createRemoteMessage()); + byte[] data = new MessagePackDataGear(dg.getData()).getMessagePack(); + byte[] dataSize = packer.write(data.length); + + buf = ByteBuffer.allocate(command.length+dataSize.length+data.length); + buf.put(command); + buf.put(dataSize); + buf.put(data); + + buf.flip(); + } catch (IOException e) { + e.printStackTrace(); + } + + return buf; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/datagear/command/RemotePeekCommand.java Tue Nov 20 18:29:13 2018 +0900 @@ -0,0 +1,16 @@ +package christie.datagear.command; + +import christie.daemon.Connection; +import christie.datagear.RemoteMessage; + +public class RemotePeekCommand extends RemoteTakeCommand { + public RemotePeekCommand(RemoteMessage msg, Connection cn) { + super(msg, cn); + this.type = CommandType.REMOTEPEEK; + } + + public RemotePeekCommand(String fromDgmName, Command cm, Connection cn) { + super(fromDgmName, cm, cn); + this.type = CommandType.REMOTEPEEK; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/datagear/command/RemoteTakeCommand.java Tue Nov 20 18:29:13 2018 +0900 @@ -0,0 +1,54 @@ +package christie.datagear.command; + +import christie.daemon.Connection; +import christie.datagear.RemoteMessage; +import christie.datagear.command.Command; +import christie.datagear.command.CommandType; +import christie.datagear.dg.MessagePackDataGear; +import org.msgpack.MessagePack; + +import java.io.IOException; +import java.nio.ByteBuffer; + +public class RemoteTakeCommand extends Command { + + public RemoteTakeCommand(RemoteMessage msg, Connection cn) { + this.type = CommandType.REMOTETAKE; + this.fromDgmName = msg.fromDgmName; + this.key = msg.key; + try { + this.clazz = Class.forName(msg.clazz); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + this.dg = new MessagePackDataGear(this.clazz); + this.connection = cn; + } + + public RemoteTakeCommand(String fromDgmName, Command cm, Connection cn) { + this.type = CommandType.REMOTETAKE; + this.fromDgmName = fromDgmName; + this.key = cm.key; + this.clazz = cm.clazz; + this.dg = new MessagePackDataGear(clazz); + this.connection = cn; + } + + @Override + public ByteBuffer convert() { + ByteBuffer buf = null; + MessagePack packer = new MessagePack(); + + try { + byte[] command = packer.write(createRemoteMessage()); + buf = ByteBuffer.allocate(command.length); + buf.put(command); + + buf.flip(); + } catch (IOException e) { + e.printStackTrace(); + } + + return buf; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/datagear/command/ReplyCommand.java Tue Nov 20 18:29:13 2018 +0900 @@ -0,0 +1,16 @@ +package christie.datagear.command; + +public class ReplyCommand extends PutCommand { + + public ReplyCommand(Command cm){ + super(0, null, cm.key, cm.dg); + this.fromDgmName = cm.fromDgmName; + this.type = CommandType.REPLY; + this.connection = cm.connection; + } + + public void setData(Object data){ + this.dg.setData(data); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/datagear/command/TakeCommand.java Tue Nov 20 18:29:13 2018 +0900 @@ -0,0 +1,26 @@ +package christie.datagear.command; + +import christie.codegear.CodeGear; +import christie.datagear.command.Command; +import christie.datagear.command.CommandType; +import christie.datagear.dg.DataGear; + +import java.nio.ByteBuffer; + +public class TakeCommand extends Command { + + public TakeCommand(CodeGear cg, int cgmID, String toDgmName, String key, DataGear dg){ + this.type = CommandType.TAKE; + this.cgmID = cgmID; + this.toDgmName = toDgmName; + this.key = key; + this.dg = dg; + this.clazz = dg.getClazz(); + this.cg = cg; + } + + @Override + public ByteBuffer convert() { + return null; + } +}
--- a/src/main/java/christie/topology/manager/StartTopologyManager.java Mon Nov 19 12:31:36 2018 +0900 +++ b/src/main/java/christie/topology/manager/StartTopologyManager.java Tue Nov 20 18:29:13 2018 +0900 @@ -5,10 +5,14 @@ public class StartTopologyManager extends StartCodeGear{ + public StartTopologyManager(String[] args){ + super(createCGM(new TopologyManagerConfig(args).localPort)); + getLocalDGM().put("topologyManagerConfig", new TopologyManagerConfig(args)); + } public StartTopologyManager(CodeGearManager cgm, TopologyManagerConfig topologyManagerConfig){ super(cgm); - cgm.getLocalDGM().put("topologyManagerConfig", topologyManagerConfig); + getLocalDGM().put("topologyManagerConfig", topologyManagerConfig); } @@ -17,10 +21,14 @@ getLocalDGM().put("topologyManagerConfig", topologyManagerConfig); } + public static void main(String[] args) { + TopologyManagerConfig topologyManagerConfig = new TopologyManagerConfig(args); + new StartTopologyManager(topologyManagerConfig); + } + @Override protected void run(CodeGearManager cgm){ cgm.setup(new TopologyManager()); - } }
--- a/src/main/java/christie/topology/node/StartTopologyNode.java Mon Nov 19 12:31:36 2018 +0900 +++ b/src/main/java/christie/topology/node/StartTopologyNode.java Tue Nov 20 18:29:13 2018 +0900 @@ -20,10 +20,7 @@ } - public static void main(String[] args) { - TopologyNodeConfig conf = new TopologyNodeConfig(args); - //new TopologyNode(conf, null); - } + @Override protected void run(CodeGearManager cgm) {