Mercurial > hg > Database > Christie
changeset 31:e29900328fff
remove RemoteTake annotation
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 13 Feb 2018 18:29:37 +0900 |
parents | 250ae646db7f |
children | 307ac87ddcf7 |
files | src/main/java/christie/annotation/RemotePeek.java src/main/java/christie/annotation/RemoteTake.java src/main/java/christie/codegear/CodeGear.java src/main/java/christie/codegear/InputDataGear.java src/main/java/christie/datagear/Command/Command.java src/main/java/christie/datagear/LocalDataGearManager.java src/main/java/christie/datagear/WrapperClass.java src/main/java/christie/datagear/dg/DataGear.java src/main/java/christie/datagear/dg/MessagePackDataGear.java src/main/java/christie/test/Remote/RemotePutTest.java src/main/java/christie/test/RemoteTake/RemoteTakeTest.java src/main/java/christie/test/TestLocal/StartTest.java src/main/java/christie/test/TestLocal/TestCodeGear.java |
diffstat | 13 files changed, 73 insertions(+), 104 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/christie/annotation/RemotePeek.java Sat Feb 03 19:23:24 2018 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -package christie.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface RemotePeek { - String dgmName(); - String key(); -}
--- a/src/main/java/christie/annotation/RemoteTake.java Sat Feb 03 19:23:24 2018 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -package christie.annotation; - - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Created by e125769 on 12/7/17. - */ -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface RemoteTake { - String dgmName(); - String key(); -} \ No newline at end of file
--- a/src/main/java/christie/codegear/CodeGear.java Sat Feb 03 19:23:24 2018 +0900 +++ b/src/main/java/christie/codegear/CodeGear.java Tue Feb 13 18:29:37 2018 +0900 @@ -1,7 +1,6 @@ package christie.codegear; import christie.annotation.Peek; -import christie.annotation.RemoteTake; import christie.annotation.Take; import christie.datagear.*; import christie.datagear.command.Command; @@ -33,13 +32,10 @@ for (Field field : this.getClass().getDeclaredFields()) {//AnnotationからInputDataGearをセット if (field.isAnnotationPresent(Take.class)) { Take ano = field.getAnnotation(Take.class); - setTakeCommand("local", ano.value(), initDataGear(field, ano.value())); + setTakeCommand(ano.value(), field.getName(), new DataGear(field.getType())); } else if (field.isAnnotationPresent(Peek.class)) { Peek ano = field.getAnnotation(Peek.class); - setPeekCommand("local", ano.value(), initDataGear(field, ano.value())); - } else if (field.isAnnotationPresent(RemoteTake.class)) { - RemoteTake ano = field.getAnnotation(RemoteTake.class); - setTakeCommand(ano.dgmName(), ano.key(), initDataGear(field, ano.key())); + setPeekCommand(ano.value(), field.getName(), new DataGear(field.getType())); } //ToDo:add remote peek } @@ -47,25 +43,6 @@ idg.finishInput(cgm, commandList); } - public DataGear initDataGear(Field field, String key){ - if (!field.getName().equals(key)){ - throw new IllegalArgumentException("key and DataGearName do not match"); - } - - DataGear dg = null; - try { - dg = (DataGear) field.get(this); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - - if (dg.getClazz() == null){ - throw new NullPointerException("please initialize DataGear"); - } - - return dg; - } - public void setTakeCommand(String toDgmName, String key, DataGear dg){ commandList.add(new TakeCommand(this, cgm.cgmID, toDgmName, key, dg)); }
--- a/src/main/java/christie/codegear/InputDataGear.java Sat Feb 03 19:23:24 2018 +0900 +++ b/src/main/java/christie/codegear/InputDataGear.java Tue Feb 13 18:29:37 2018 +0900 @@ -1,7 +1,6 @@ package christie.codegear; import christie.annotation.Peek; -import christie.annotation.RemoteTake; import christie.annotation.Take; import christie.datagear.command.Command; import christie.datagear.dg.DataGear; @@ -60,20 +59,17 @@ field.setAccessible(true); if (field.isAnnotationPresent(Take.class)){ Take ano = field.getAnnotation(Take.class); - setField(field, ano.value()); + setField(field); } else if (field.isAnnotationPresent(Peek.class)){ Peek ano = field.getAnnotation(Peek.class); - setField(field, ano.value()); - } else if (field.isAnnotationPresent(RemoteTake.class)){ - RemoteTake ano = field.getAnnotation(RemoteTake.class); - setField(field, ano.key()); - }//ToDo:implements RemotePut + setField(field); + } //ToDo:implements RemotePut } } - public void setField(Field field, String key){ + public void setField(Field field){ try { - field.set(cg, typeCheck(key)); + field.set(cg, typeCheck(field.getName())); } catch (IllegalAccessException e) { e.printStackTrace(); } @@ -81,7 +77,7 @@ public Object typeCheck(String key){ if (inputValue.get(key).getData() != null){ - return inputValue.get(key); + return inputValue.get(key).getData(); } else { throw new IllegalArgumentException("'" + key + "' is null! this DataGear required type of " + inputValue.get(key).getClazz()); }
--- a/src/main/java/christie/datagear/Command/Command.java Sat Feb 03 19:23:24 2018 +0900 +++ b/src/main/java/christie/datagear/Command/Command.java Tue Feb 13 18:29:37 2018 +0900 @@ -25,4 +25,9 @@ public RemoteMessage createRemoteMessage(){ return new RemoteMessage(type.id, fromDgmName, key, clazz.getName()); } + + public void setInputs(){ + cg.getIdg().setInputs(key, dg); + } + }
--- a/src/main/java/christie/datagear/LocalDataGearManager.java Sat Feb 03 19:23:24 2018 +0900 +++ b/src/main/java/christie/datagear/LocalDataGearManager.java Tue Feb 13 18:29:37 2018 +0900 @@ -36,14 +36,14 @@ case PUT: dataGears.put(cm.key, cm.dg); - if (waitList.containsKey(cm.key)){ + if (waitList.containsKey(cm.key)){//ここもsyncronized? runCommand(waitList.getAndRemoveCommand(cm.key)); } break; case TAKE: takeAndSetData(cm); - setInputToCG(cm); + cm.setInputs(); break; case REMOTETAKE: @@ -53,7 +53,7 @@ break; case PEEK: peekAndSetData(cm); - setInputToCG(cm); + cm.setInputs(); break; case REMOTEPEEK://ToDo:implement @@ -74,8 +74,4 @@ cm.dg.setData(dataGears.peek(cm.key)); } - private void setInputToCG(Command cm){ - cm.cg.getIdg().setInputs(cm.key, cm.dg); - } - }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/datagear/WrapperClass.java Tue Feb 13 18:29:37 2018 +0900 @@ -0,0 +1,23 @@ +package christie.datagear; + +import java.util.HashMap; +import java.util.Map; + +public class WrapperClass { + public static <T> Class<T> getWrapperClass(Class<T> c) { + return c.isPrimitive() ? (Class<T>) map.get(c) : c; + } + + public final static Map<Class<?>, Class<?>> map = new HashMap<Class<?>, Class<?>>(); + + static { + map.put(boolean.class, Boolean.class); + map.put(byte.class, Byte.class); + map.put(short.class, Short.class); + map.put(char.class, Character.class); + map.put(int.class, Integer.class); + map.put(long.class, Long.class); + map.put(float.class, Float.class); + map.put(double.class, Double.class); + } +}
--- a/src/main/java/christie/datagear/dg/DataGear.java Sat Feb 03 19:23:24 2018 +0900 +++ b/src/main/java/christie/datagear/dg/DataGear.java Tue Feb 13 18:29:37 2018 +0900 @@ -1,8 +1,6 @@ package christie.datagear.dg; -import org.msgpack.MessagePack; - -import java.io.IOException; +import christie.datagear.WrapperClass; public class DataGear<T>{ protected T data = null; @@ -13,12 +11,17 @@ setData(data); } - public DataGear(T... dg) {//for input DataGear init + /*public DataGear(T... dg) {//for input DataGear init @SuppressWarnings("unchecked") Class<T> type = (Class<T>) dg.getClass().getComponentType(); this.clazz = type; + }*/ + + public DataGear(Class clazz){ + setClazz(clazz); } + public void setData(T data) { if (data.getClass() == this.clazz){ this.data = data; @@ -26,7 +29,7 @@ } public void setClazz(Class clazz){ - this.clazz = clazz; + this.clazz = WrapperClass.getWrapperClass(clazz); }; public Class getClazz(){ @@ -37,5 +40,4 @@ return data; } - }
--- a/src/main/java/christie/datagear/dg/MessagePackDataGear.java Sat Feb 03 19:23:24 2018 +0900 +++ b/src/main/java/christie/datagear/dg/MessagePackDataGear.java Tue Feb 13 18:29:37 2018 +0900 @@ -10,17 +10,16 @@ private MessagePack packer = new MessagePack(); public MessagePackDataGear(T data, Class clazz){ - setClazz(clazz); - setData(data); + super(data, clazz); getMessagePack(); } public MessagePackDataGear(Class clazz){ - setClazz(clazz); + super(clazz); } public MessagePackDataGear(byte[] messagePack, Class clazz){ - setClazz(clazz); + super(clazz); this.messagePack = messagePack; }
--- a/src/main/java/christie/test/Remote/RemotePutTest.java Sat Feb 03 19:23:24 2018 +0900 +++ b/src/main/java/christie/test/Remote/RemotePutTest.java Tue Feb 13 18:29:37 2018 +0900 @@ -7,18 +7,18 @@ public class RemotePutTest extends CodeGear { - @Take("hoge") - public DataGear<Integer> hoge = new DataGear<>(); + @Take("local") + public int hoge; - @Take("cgmID") - public DataGear<Integer> cgmID = new DataGear<>(); + @Take("local") + public int cgmID; @Override protected void run(CodeGearManager cgm) { - if (hoge.getData() != 10){ - System.out.println(cgmID.getData() + " : " +hoge.getData()); + if (hoge != 10){ + System.out.println(cgmID + " : " + hoge); cgm.setup(new RemotePutTest()); - getDGM("remote").put("hoge", hoge.getData() + 1); + getDGM("remote").put("hoge", hoge + 1); getDGM("remote").put("cgmID", cgm.cgmID); } }
--- a/src/main/java/christie/test/RemoteTake/RemoteTakeTest.java Sat Feb 03 19:23:24 2018 +0900 +++ b/src/main/java/christie/test/RemoteTake/RemoteTakeTest.java Tue Feb 13 18:29:37 2018 +0900 @@ -1,25 +1,27 @@ package christie.test.RemoteTake; -import christie.annotation.RemoteTake; +import christie.annotation.Take; import christie.codegear.CodeGear; import christie.codegear.CodeGearManager; import christie.datagear.dg.DataGear; public class RemoteTakeTest extends CodeGear{ - @RemoteTake(dgmName = "remote",key = "hoge") - public DataGear<Integer> hoge = new DataGear<>(); + @Take("remote") + public int hoge; - @RemoteTake(dgmName = "remote",key = "cgmID") - public DataGear<Integer> cgmID = new DataGear<>(); + @Take("remote") + public int cgmID; @Override protected void run(CodeGearManager cgm) { - if (hoge.getData() != 10){ - System.out.println(cgmID.getData() + " : " +hoge.getData()); + + if (hoge <= 10){ + System.out.println(cgmID + " : " +hoge); cgm.setup(new RemoteTakeTest()); - getLocalDGM().put("hoge", hoge.getData() + 1); - getLocalDGM().put("cgmID", cgm.cgmID); } + + getLocalDGM().put("hoge", hoge + 1); + getLocalDGM().put("cgmID", cgm.cgmID); } }
--- a/src/main/java/christie/test/TestLocal/StartTest.java Sat Feb 03 19:23:24 2018 +0900 +++ b/src/main/java/christie/test/TestLocal/StartTest.java Tue Feb 13 18:29:37 2018 +0900 @@ -16,7 +16,6 @@ @Override protected void run(CodeGearManager cgm) { cgm.setup(new TestCodeGear()); - getLocalDGM().put("hoge", 1); } }
--- a/src/main/java/christie/test/TestLocal/TestCodeGear.java Sat Feb 03 19:23:24 2018 +0900 +++ b/src/main/java/christie/test/TestLocal/TestCodeGear.java Tue Feb 13 18:29:37 2018 +0900 @@ -11,15 +11,15 @@ */ public class TestCodeGear extends CodeGear { - @Take("hoge") - public DataGear<Integer> hoge = new DataGear<>();//必ずこの書き方でないとエラー + @Take("local") + int hoge; public void run(CodeGearManager cgm){ - System.out.println(hoge.getData()); + System.out.println(hoge); - if (hoge.getData()!= 10){ + if (hoge != 10){ cgm.setup(new TestCodeGear()); - getLocalDGM().put("hoge", hoge.getData() + 1); + getLocalDGM().put("hoge", hoge + 1); } }