Mercurial > hg > Database > Christie
changeset 209:2ecb3a93b8ae
add Command abstract run
line wrap: on
line diff
--- a/src/main/java/christie/daemon/OutboundTcpConnection.java Sun Mar 10 16:25:52 2019 +0900 +++ b/src/main/java/christie/daemon/OutboundTcpConnection.java Mon Mar 11 16:21:30 2019 +0900 @@ -16,10 +16,8 @@ Command cmd = connection.sendQueue.take(); switch (cmd.type) { case CLOSE: - connection.close(); - return; case FINISH: - System.exit(0); + cmd.run(); return; default: break;
--- a/src/main/java/christie/datagear/DataGearManager.java Sun Mar 10 16:25:52 2019 +0900 +++ b/src/main/java/christie/datagear/DataGearManager.java Mon Mar 11 16:21:30 2019 +0900 @@ -1,5 +1,6 @@ package christie.datagear; +import christie.codegear.CodeGear; import christie.datagear.command.Command; import christie.datagear.dg.DataGear; @@ -17,6 +18,4 @@ public abstract void close(); public abstract void shutdown(); - - }
--- a/src/main/java/christie/datagear/DataGears.java Sun Mar 10 16:25:52 2019 +0900 +++ b/src/main/java/christie/datagear/DataGears.java Mon Mar 11 16:21:30 2019 +0900 @@ -1,5 +1,8 @@ package christie.datagear; +import christie.codegear.CodeGear; +import christie.datagear.command.Command; +import christie.datagear.command.CommandType; import christie.datagear.dg.DataGear; import java.util.TreeMap; @@ -19,7 +22,7 @@ } } - public synchronized Object take(String key){ + public Object take(String key){ Object data = dataGears.get(key).poll().getData(); if (dataGears.get(key).isEmpty()) { @@ -33,6 +36,23 @@ return dataGears.get(key).peek().getData(); } + public synchronized Object getData(Command cm){ + switch (cm.type) { + case TAKE: + case REMOTETAKE: + return take(cm.key); + case PEEK: + case REMOTEPEEK: + return peek(cm.key); + } + + return null; + } + + public synchronized void setData(Command cm){ + put(cm.key, cm.dg); + } + public synchronized boolean containsKey(String key){ return dataGears.containsKey(key); }
--- a/src/main/java/christie/datagear/LocalDataGearManager.java Sun Mar 10 16:25:52 2019 +0900 +++ b/src/main/java/christie/datagear/LocalDataGearManager.java Mon Mar 11 16:21:30 2019 +0900 @@ -20,7 +20,7 @@ public void runCommand(Command cm){ switch (cm.type) { case PUT: - dataGears.put(cm.key, cm.dg); + dataGears.setData(cm); if (waitList.containsKey(cm.key)){//ここもsyncronized? runCommand(waitList.getAndRemoveCommand(cm.key)); @@ -28,43 +28,18 @@ break; case TAKE: + case REMOTETAKE: + case PEEK: + case REMOTEPEEK: if (dataGears.containsKey(cm.key)) { - takeAndSetData(cm); - cm.setInputs(); - } else { - waitList.add(cm); - } - - break; - case REMOTETAKE: - if (dataGears.containsKey(cm.key)) { - takeAndSetData(cm); - runCommand(new ReplyCommand(cm)); + cm.setDg(dataGears.getData(cm)); + cm.run(); } else { waitList.add(cm); } - - break; - case PEEK: - if (dataGears.containsKey(cm.key)) { - peekAndSetData(cm); - cm.setInputs(); - } else { - waitList.add(cm); - } - - break; - case REMOTEPEEK: - if (dataGears.containsKey(cm.key)) { - peekAndSetData(cm); - runCommand(new ReplyCommand(cm)); - } else { - waitList.add(cm); - } - break; case REPLY: - cm.connection.write(cm); + cm.run(); break; } @@ -75,14 +50,6 @@ } - private void takeAndSetData(Command cm){ - cm.setDg(dataGears.take(cm.key)); - } - - private void peekAndSetData(Command cm){ - cm.setDg(dataGears.peek(cm.key)); - } - @Override public void finish() { System.exit(0);
--- a/src/main/java/christie/datagear/RemoteDataGearManager.java Sun Mar 10 16:25:52 2019 +0900 +++ b/src/main/java/christie/datagear/RemoteDataGearManager.java Mon Mar 11 16:21:30 2019 +0900 @@ -88,8 +88,8 @@ @Override public void resolveWaitCommand(String key, DataGear dg) { Command cm = waitList.getAndRemoveCommand(key); - cm.dg = dg; - cm.setInputs(); + cm.setDg(dg); + cm.run(); }
--- a/src/main/java/christie/datagear/command/CloseCommand.java Sun Mar 10 16:25:52 2019 +0900 +++ b/src/main/java/christie/datagear/command/CloseCommand.java Mon Mar 11 16:21:30 2019 +0900 @@ -9,8 +9,15 @@ CommandType type = CommandType.CLOSE; } + + @Override public ByteBuffer convert() { return null; } + + @Override + public void run() { + connection.close(); + } }
--- a/src/main/java/christie/datagear/command/Command.java Sun Mar 10 16:25:52 2019 +0900 +++ b/src/main/java/christie/datagear/command/Command.java Mon Mar 11 16:21:30 2019 +0900 @@ -2,6 +2,8 @@ import christie.codegear.CodeGear; import christie.daemon.Connection; +import christie.datagear.DataGearManager; +import christie.datagear.DataGears; import christie.datagear.RemoteMessage; import christie.datagear.command.CommandType; import christie.datagear.dg.DataGear; @@ -19,18 +21,18 @@ public Class clazz = null;// for remote public Connection connection = null;//for reply + public abstract void run(); + //public abstract void run(Object dataGear); + //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); }
--- a/src/main/java/christie/datagear/command/FinishCommand.java Sun Mar 10 16:25:52 2019 +0900 +++ b/src/main/java/christie/datagear/command/FinishCommand.java Mon Mar 11 16:21:30 2019 +0900 @@ -11,8 +11,14 @@ CommandType type = CommandType.FINISH; } + + @Override + public void run() { + System.exit(0); + } @Override public ByteBuffer convert() { return null; } + }
--- a/src/main/java/christie/datagear/command/PutCommand.java Sun Mar 10 16:25:52 2019 +0900 +++ b/src/main/java/christie/datagear/command/PutCommand.java Mon Mar 11 16:21:30 2019 +0900 @@ -21,6 +21,11 @@ } @Override + public void run() { + + } + + @Override public ByteBuffer convert() { ByteBuffer buf = null; MessagePack packer = new MessagePack();
--- a/src/main/java/christie/datagear/command/RemoteTakeCommand.java Sun Mar 10 16:25:52 2019 +0900 +++ b/src/main/java/christie/datagear/command/RemoteTakeCommand.java Mon Mar 11 16:21:30 2019 +0900 @@ -32,6 +32,11 @@ } @Override + public void run() { + new ReplyCommand(this).run(); + } + + @Override public ByteBuffer convert() { ByteBuffer buf = null; MessagePack packer = new MessagePack();
--- a/src/main/java/christie/datagear/command/ReplyCommand.java Sun Mar 10 16:25:52 2019 +0900 +++ b/src/main/java/christie/datagear/command/ReplyCommand.java Mon Mar 11 16:21:30 2019 +0900 @@ -9,6 +9,11 @@ this.connection = cm.connection; } + @Override + public void run() { + connection.write(this); + } + public void setData(Object data){ this.dg.setData(data); }
--- a/src/main/java/christie/datagear/command/TakeCommand.java Sun Mar 10 16:25:52 2019 +0900 +++ b/src/main/java/christie/datagear/command/TakeCommand.java Mon Mar 11 16:21:30 2019 +0900 @@ -1,6 +1,7 @@ package christie.datagear.command; import christie.codegear.CodeGear; +import christie.datagear.DataGears; import christie.datagear.command.Command; import christie.datagear.command.CommandType; import christie.datagear.dg.DataGear; @@ -23,4 +24,19 @@ public ByteBuffer convert() { return null; } + + @Override + public void run() { + setInputs(); + } + + /*@Override + public void run(Object dataGear) { + setDg(dataGear); + + }*/ + + public void setInputs(){ + cg.getIdg().setInputs(key, dg); + } }