ignite-nio - Removing message clone
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/f1d41941 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/f1d41941 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/f1d41941 Branch: refs/heads/sprint-1 Commit: f1d419418b9d429634658af38ac47c9f156f0931 Parents: d674a08 Author: Valentin Kulichenko <vkuliche...@gridgain.com> Authored: Sat Feb 14 18:25:40 2015 -0800 Committer: Valentin Kulichenko <vkuliche...@gridgain.com> Committed: Sat Feb 14 18:25:40 2015 -0800 ---------------------------------------------------------------------- .../CommunicationMessageCodeGenerator.java | 71 ++++++++++-- .../internal/direct/DirectByteBufferStream.java | 116 ++----------------- .../communication/MessageAdapter.java | 47 ++++++++ 3 files changed, 116 insertions(+), 118 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f1d41941/modules/codegen/src/main/java/org/apache/ignite/codegen/CommunicationMessageCodeGenerator.java ---------------------------------------------------------------------- diff --git a/modules/codegen/src/main/java/org/apache/ignite/codegen/CommunicationMessageCodeGenerator.java b/modules/codegen/src/main/java/org/apache/ignite/codegen/CommunicationMessageCodeGenerator.java index c163684..80cf53e 100644 --- a/modules/codegen/src/main/java/org/apache/ignite/codegen/CommunicationMessageCodeGenerator.java +++ b/modules/codegen/src/main/java/org/apache/ignite/codegen/CommunicationMessageCodeGenerator.java @@ -63,6 +63,56 @@ public class CommunicationMessageCodeGenerator { private static final String BUF_VAR = "buf"; /** */ + private static final Map<Class<?>, MessageAdapter.Type> TYPES = U.newHashMap(30); + + static { + TYPES.put(byte.class, MessageAdapter.Type.BYTE); + TYPES.put(Byte.class, MessageAdapter.Type.BYTE); + TYPES.put(short.class, MessageAdapter.Type.SHORT); + TYPES.put(Short.class, MessageAdapter.Type.SHORT); + TYPES.put(int.class, MessageAdapter.Type.INT); + TYPES.put(Integer.class, MessageAdapter.Type.INT); + TYPES.put(long.class, MessageAdapter.Type.LONG); + TYPES.put(Long.class, MessageAdapter.Type.LONG); + TYPES.put(float.class, MessageAdapter.Type.FLOAT); + TYPES.put(Float.class, MessageAdapter.Type.FLOAT); + TYPES.put(double.class, MessageAdapter.Type.DOUBLE); + TYPES.put(Double.class, MessageAdapter.Type.DOUBLE); + TYPES.put(char.class, MessageAdapter.Type.CHAR); + TYPES.put(Character.class, MessageAdapter.Type.CHAR); + TYPES.put(boolean.class, MessageAdapter.Type.BOOLEAN); + TYPES.put(Boolean.class, MessageAdapter.Type.BOOLEAN); + TYPES.put(byte[].class, MessageAdapter.Type.BYTE_ARR); + TYPES.put(short[].class, MessageAdapter.Type.SHORT_ARR); + TYPES.put(int[].class, MessageAdapter.Type.INT_ARR); + TYPES.put(long[].class, MessageAdapter.Type.LONG_ARR); + TYPES.put(float[].class, MessageAdapter.Type.FLOAT_ARR); + TYPES.put(double[].class, MessageAdapter.Type.DOUBLE_ARR); + TYPES.put(char[].class, MessageAdapter.Type.CHAR_ARR); + TYPES.put(boolean[].class, MessageAdapter.Type.BOOLEAN_ARR); + TYPES.put(String.class, MessageAdapter.Type.STRING); + TYPES.put(BitSet.class, MessageAdapter.Type.BIT_SET); + TYPES.put(UUID.class, MessageAdapter.Type.UUID); + TYPES.put(IgniteUuid.class, MessageAdapter.Type.IGNITE_UUID); + } + + /** + * @param cls Class. + * @return Type enum value. + */ + private static MessageAdapter.Type typeEnum(Class<?> cls) { + MessageAdapter.Type type = TYPES.get(cls); + + if (type == null) { + assert MessageAdapter.class.isAssignableFrom(cls) : cls; + + type = MessageAdapter.Type.MSG; + } + + return type; + } + + /** */ private final Collection<String> write = new ArrayList<>(); /** */ @@ -540,19 +590,19 @@ public class CommunicationMessageCodeGenerator { returnFalseIfFailed(write, "writer.writeMessage", field, name); else if (type.isArray()) { returnFalseIfFailed(write, "writer.writeObjectArray", field, name, - type.getComponentType().getSimpleName() + ".class"); + "Type." + typeEnum(type.getComponentType())); } else if (Collection.class.isAssignableFrom(type) && !Set.class.isAssignableFrom(type)) { assert colItemType != null; - returnFalseIfFailed(write, "writer.writeCollection", field, name, colItemType.getSimpleName() + ".class"); + returnFalseIfFailed(write, "writer.writeCollection", field, name, "Type." + typeEnum(colItemType)); } else if (Map.class.isAssignableFrom(type)) { assert mapKeyType != null; assert mapValType != null; - returnFalseIfFailed(write, "writer.writeMap", field, name, mapKeyType.getSimpleName() + ".class", - mapValType.getSimpleName() + ".class"); + returnFalseIfFailed(write, "writer.writeMap", field, name, "Type." + typeEnum(mapKeyType), + "Type." + typeEnum(mapKeyType)); } else throw new IllegalStateException("Unsupported type: " + type); @@ -624,15 +674,12 @@ public class CommunicationMessageCodeGenerator { } else if (BASE_CLS.isAssignableFrom(type)) returnFalseIfReadFailed(name, "reader.readMessage", field); - else if (type.isArray()) { - returnFalseIfReadFailed(name, "reader.readObjectArray", field, - type.getComponentType().getSimpleName() + ".class"); - } + else if (type.isArray()) + returnFalseIfReadFailed(name, "reader.readObjectArray", field, "Type." + typeEnum(type.getComponentType())); else if (Collection.class.isAssignableFrom(type) && !Set.class.isAssignableFrom(type)) { assert colItemType != null; - returnFalseIfReadFailed(name, "reader.readCollection", field, - colItemType.getSimpleName() + ".class"); + returnFalseIfReadFailed(name, "reader.readCollection", field, "Type." + typeEnum(colItemType)); } else if (Map.class.isAssignableFrom(type)) { assert mapKeyType != null; @@ -640,8 +687,8 @@ public class CommunicationMessageCodeGenerator { boolean linked = type.equals(LinkedHashMap.class); - returnFalseIfReadFailed(name, "reader.readMap", field, mapKeyType.getSimpleName() + ".class", - mapValType.getSimpleName() + ".class", linked ? "true" : "false"); + returnFalseIfReadFailed(name, "reader.readMap", field, "Type." + typeEnum(mapKeyType), + "Type." + typeEnum(mapValType), linked ? "true" : "false"); } else throw new IllegalStateException("Unsupported type: " + type); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f1d41941/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java index df969b1..4b5dc3a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java @@ -207,56 +207,6 @@ public class DirectByteBufferStream { private static final Object NULL = new Object(); /** */ - private static final Map<Class<?>, Type> TYPES = U.newHashMap(30); - - static { - TYPES.put(byte.class, Type.BYTE); - TYPES.put(Byte.class, Type.BYTE); - TYPES.put(short.class, Type.SHORT); - TYPES.put(Short.class, Type.SHORT); - TYPES.put(int.class, Type.INT); - TYPES.put(Integer.class, Type.INT); - TYPES.put(long.class, Type.LONG); - TYPES.put(Long.class, Type.LONG); - TYPES.put(float.class, Type.FLOAT); - TYPES.put(Float.class, Type.FLOAT); - TYPES.put(double.class, Type.DOUBLE); - TYPES.put(Double.class, Type.DOUBLE); - TYPES.put(char.class, Type.CHAR); - TYPES.put(Character.class, Type.CHAR); - TYPES.put(boolean.class, Type.BOOLEAN); - TYPES.put(Boolean.class, Type.BOOLEAN); - TYPES.put(byte[].class, Type.BYTE_ARR); - TYPES.put(short[].class, Type.SHORT_ARR); - TYPES.put(int[].class, Type.INT_ARR); - TYPES.put(long[].class, Type.LONG_ARR); - TYPES.put(float[].class, Type.FLOAT_ARR); - TYPES.put(double[].class, Type.DOUBLE_ARR); - TYPES.put(char[].class, Type.CHAR_ARR); - TYPES.put(boolean[].class, Type.BOOLEAN_ARR); - TYPES.put(String.class, Type.STRING); - TYPES.put(BitSet.class, Type.BIT_SET); - TYPES.put(UUID.class, Type.UUID); - TYPES.put(IgniteUuid.class, Type.IGNITE_UUID); - } - - /** - * @param cls Class. - * @return Type enum value. - */ - private static Type type(Class<?> cls) { - Type type = TYPES.get(cls); - - if (type == null) { - assert MessageAdapter.class.isAssignableFrom(cls) : cls; - - type = Type.MSG; - } - - return type; - } - - /** */ private final MessageFactory msgFactory; /** */ @@ -614,7 +564,7 @@ public class DirectByteBufferStream { it = arrayIterator(arr); } - Type itemType = type(itemCls); + MessageAdapter.Type itemType = null;//type(itemCls); while (it.hasNext() || cur != NULL) { if (cur == NULL) { @@ -657,7 +607,7 @@ public class DirectByteBufferStream { it = col.iterator(); } - Type itemType = type(itemCls); + MessageAdapter.Type itemType = null;//type(itemCls); while (it.hasNext() || cur != NULL) { if (cur == NULL) { @@ -702,8 +652,8 @@ public class DirectByteBufferStream { it = map.entrySet().iterator(); } - Type keyType = type(keyCls); - Type valType = type(valCls); + MessageAdapter.Type keyType = null;//type(keyCls); + MessageAdapter.Type valType = null;//type(valCls); while (it.hasNext() || cur != NULL) { Map.Entry<K, V> e; @@ -1044,7 +994,7 @@ public class DirectByteBufferStream { if (objArr == null) objArr = (Object[])Array.newInstance(itemCls, readSize); - Type itemType = type(itemCls); + MessageAdapter.Type itemType = null;//type(itemCls); for (int i = readItems; i < readSize; i++) { Object item = read(itemType, reader); @@ -1089,7 +1039,7 @@ public class DirectByteBufferStream { if (col == null) col = new ArrayList<>(readSize); - Type itemType = type(itemCls); + MessageAdapter.Type itemType = null;//type(itemCls); for (int i = readItems; i < readSize; i++) { Object item = read(itemType, reader); @@ -1137,8 +1087,8 @@ public class DirectByteBufferStream { if (map == null) map = linked ? U.newLinkedHashMap(readSize) : U.newHashMap(readSize); - Type keyType = type(keyCls); - Type valType = type(valCls); + MessageAdapter.Type keyType = null;//type(keyCls); + MessageAdapter.Type valType = null;//type(valCls); for (int i = readItems; i < readSize; i++) { if (!keyDone) { @@ -1324,7 +1274,7 @@ public class DirectByteBufferStream { * @param type Type. * @param val Value. */ - private void write(Type type, Object val, MessageWriteState state) { + private void write(MessageAdapter.Type type, Object val, MessageWriteState state) { switch (type) { case BYTE: writeByte((Byte)val); @@ -1450,7 +1400,7 @@ public class DirectByteBufferStream { * @param reader Reader. * @return Value. */ - private Object read(Type type, MessageReader reader) { + private Object read(MessageAdapter.Type type, MessageReader reader) { switch (type) { case BYTE: return readByte(); @@ -1555,50 +1505,4 @@ public class DirectByteBufferStream { */ public T create(int len); } - - /** - */ - private enum Type { - BYTE, - - SHORT, - - INT, - - LONG, - - FLOAT, - - DOUBLE, - - CHAR, - - BOOLEAN, - - BYTE_ARR, - - SHORT_ARR, - - INT_ARR, - - LONG_ARR, - - FLOAT_ARR, - - DOUBLE_ARR, - - CHAR_ARR, - - BOOLEAN_ARR, - - STRING, - - BIT_SET, - - UUID, - - IGNITE_UUID, - - MSG - } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f1d41941/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageAdapter.java b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageAdapter.java index 2f960a7..9cb8945 100644 --- a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageAdapter.java @@ -83,4 +83,51 @@ public abstract class MessageAdapter implements Serializable, Cloneable { public boolean skipRecovery() { return false; } + + /** + * TODO + */ + public enum Type { + BYTE, + + SHORT, + + INT, + + LONG, + + FLOAT, + + DOUBLE, + + CHAR, + + BOOLEAN, + + BYTE_ARR, + + SHORT_ARR, + + INT_ARR, + + LONG_ARR, + + FLOAT_ARR, + + DOUBLE_ARR, + + CHAR_ARR, + + BOOLEAN_ARR, + + STRING, + + BIT_SET, + + UUID, + + IGNITE_UUID, + + MSG + } }