Skip to content

Commit

Permalink
ignite-nio - Removing message clone
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Kulichenko committed Feb 15, 2015
1 parent f1d4194 commit ca27b58
Show file tree
Hide file tree
Showing 47 changed files with 235 additions and 232 deletions.
Expand Up @@ -602,7 +602,7 @@ else if (Map.class.isAssignableFrom(type)) {
assert mapValType != null;

returnFalseIfFailed(write, "writer.writeMap", field, name, "Type." + typeEnum(mapKeyType),
"Type." + typeEnum(mapKeyType));
"Type." + typeEnum(mapValType));
}
else
throw new IllegalStateException("Unsupported type: " + type);
Expand Down
Expand Up @@ -519,7 +519,7 @@ public UUID getSubjectId() {
state.increment();

case 9:
if (!writer.writeMap("ldrParticipants", ldrParticipants, UUID.class, IgniteUuid.class))
if (!writer.writeMap("ldrParticipants", ldrParticipants, Type.UUID, Type.IGNITE_UUID))
return false;

state.increment();
Expand Down Expand Up @@ -579,7 +579,7 @@ public UUID getSubjectId() {
state.increment();

case 19:
if (!writer.writeCollection("top", top, UUID.class))
if (!writer.writeCollection("top", top, Type.UUID))
return false;

state.increment();
Expand Down Expand Up @@ -678,7 +678,7 @@ public UUID getSubjectId() {
readState++;

case 9:
ldrParticipants = reader.readMap("ldrParticipants", UUID.class, IgniteUuid.class, false);
ldrParticipants = reader.readMap("ldrParticipants", Type.UUID, Type.IGNITE_UUID, false);

if (!reader.isLastRead())
return false;
Expand Down Expand Up @@ -758,7 +758,7 @@ public UUID getSubjectId() {
readState++;

case 19:
top = reader.readCollection("top", UUID.class);
top = reader.readCollection("top", Type.UUID);

if (!reader.isLastRead())
return false;
Expand Down
Expand Up @@ -550,10 +550,10 @@ public void writeMessage(MessageAdapter msg, MessageWriteState state) {

/**
* @param arr Array.
* @param itemCls Component type.
* @param writer Writer.
* @param itemType Component type.
* @param state Current state.
*/
public <T> void writeObjectArray(T[] arr, Class<T> itemCls, MessageWriteState state) {
public <T> void writeObjectArray(T[] arr, MessageAdapter.Type itemType, MessageWriteState state) {
if (arr != null) {
if (it == null) {
writeInt(arr.length);
Expand All @@ -564,8 +564,6 @@ public <T> void writeObjectArray(T[] arr, Class<T> itemCls, MessageWriteState st
it = arrayIterator(arr);
}

MessageAdapter.Type itemType = null;//type(itemCls);

while (it.hasNext() || cur != NULL) {
if (cur == NULL) {
cur = it.next();
Expand Down Expand Up @@ -593,10 +591,10 @@ public <T> void writeObjectArray(T[] arr, Class<T> itemCls, MessageWriteState st

/**
* @param col Collection.
* @param itemCls Item type.
* @param writer Writer.
* @param itemType Item type.
* @param state Current state.
*/
public <T> void writeCollection(Collection<T> col, Class<T> itemCls, MessageWriteState state) {
public <T> void writeCollection(Collection<T> col, MessageAdapter.Type itemType, MessageWriteState state) {
if (col != null) {
if (it == null) {
writeInt(col.size());
Expand All @@ -607,8 +605,6 @@ public <T> void writeCollection(Collection<T> col, Class<T> itemCls, MessageWrit
it = col.iterator();
}

MessageAdapter.Type itemType = null;//type(itemCls);

while (it.hasNext() || cur != NULL) {
if (cur == NULL) {
cur = it.next();
Expand Down Expand Up @@ -636,12 +632,13 @@ public <T> void writeCollection(Collection<T> col, Class<T> itemCls, MessageWrit

/**
* @param map Map.
* @param keyCls Key type.
* @param valCls Value type.
* @param writer Writer.
* @param keyType Key type.
* @param valType Value type.
* @param state Current state.
*/
@SuppressWarnings("unchecked")
public <K, V> void writeMap(Map<K, V> map, Class<K> keyCls, Class<V> valCls, MessageWriteState state) {
public <K, V> void writeMap(Map<K, V> map, MessageAdapter.Type keyType, MessageAdapter.Type valType,
MessageWriteState state) {
if (map != null) {
if (it == null) {
writeInt(map.size());
Expand All @@ -652,9 +649,6 @@ public <K, V> void writeMap(Map<K, V> map, Class<K> keyCls, Class<V> valCls, Mes
it = map.entrySet().iterator();
}

MessageAdapter.Type keyType = null;//type(keyCls);
MessageAdapter.Type valType = null;//type(valCls);

while (it.hasNext() || cur != NULL) {
Map.Entry<K, V> e;

Expand Down Expand Up @@ -975,12 +969,12 @@ public <T extends MessageAdapter> T readMessage(MessageReader reader) {
}

/**
* @param itemCls Component type.
* @param itemType Component type.
* @param reader Reader.
* @return Array.
*/
@SuppressWarnings("unchecked")
public <T> T[] readObjectArray(Class<?> itemCls, MessageReader reader) {
public <T> T[] readObjectArray(MessageAdapter.Type itemType, MessageReader reader) {
if (readSize == -1) {
int size = readInt();

Expand All @@ -992,9 +986,7 @@ public <T> T[] readObjectArray(Class<?> itemCls, MessageReader reader) {

if (readSize >= 0) {
if (objArr == null)
objArr = (Object[])Array.newInstance(itemCls, readSize);

MessageAdapter.Type itemType = null;//type(itemCls);
objArr = (Object[])Array.newInstance(itemType.clazz(), readSize);

for (int i = readItems; i < readSize; i++) {
Object item = read(itemType, reader);
Expand All @@ -1020,12 +1012,12 @@ public <T> T[] readObjectArray(Class<?> itemCls, MessageReader reader) {
}

/**
* @param itemCls Item type.
* @param itemType Item type.
* @param reader Reader.
* @return Collection.
*/
@SuppressWarnings("unchecked")
public <C extends Collection<T>, T> C readCollection(Class<T> itemCls, MessageReader reader) {
public <C extends Collection<?>> C readCollection(MessageAdapter.Type itemType, MessageReader reader) {
if (readSize == -1) {
int size = readInt();

Expand All @@ -1039,8 +1031,6 @@ public <C extends Collection<T>, T> C readCollection(Class<T> itemCls, MessageRe
if (col == null)
col = new ArrayList<>(readSize);

MessageAdapter.Type itemType = null;//type(itemCls);

for (int i = readItems; i < readSize; i++) {
Object item = read(itemType, reader);

Expand All @@ -1057,23 +1047,23 @@ public <C extends Collection<T>, T> C readCollection(Class<T> itemCls, MessageRe
readItems = 0;
cur = null;

Collection<T> col0 = (Collection<T>)col;
C col0 = (C)col;

col = null;

return (C)col0;
return col0;
}

/**
* @param keyCls Key type.
* @param valCls Value type.
* @param keyType Key type.
* @param valType Value type.
* @param reader Reader.
* @param linked Whether linked map should be created.
* @return Map.
*/
@SuppressWarnings("unchecked")
public <M extends Map<K, V>, K, V> M readMap(Class<K> keyCls, Class<V> valCls, MessageReader reader,
boolean linked) {
public <M extends Map<?, ?>> M readMap(MessageAdapter.Type keyType, MessageAdapter.Type valType,
MessageReader reader, boolean linked) {
if (readSize == -1) {
int size = readInt();

Expand All @@ -1087,9 +1077,6 @@ public <M extends Map<K, V>, K, V> M readMap(Class<K> keyCls, Class<V> valCls, M
if (map == null)
map = linked ? U.newLinkedHashMap(readSize) : U.newHashMap(readSize);

MessageAdapter.Type keyType = null;//type(keyCls);
MessageAdapter.Type valType = null;//type(valCls);

for (int i = readItems; i < readSize; i++) {
if (!keyDone) {
Object key = read(keyType, reader);
Expand Down Expand Up @@ -1118,11 +1105,11 @@ public <M extends Map<K, V>, K, V> M readMap(Class<K> keyCls, Class<V> valCls, M
readItems = 0;
cur = null;

Map<K, V> map0 = (Map<K, V>)map;
M map0 = (M)map;

map = null;

return (M)map0;
return map0;
}

/**
Expand Down
Expand Up @@ -236,27 +236,27 @@ public DirectMessageReader(MessageFactory msgFactory) {
}

/** {@inheritDoc} */
@Override public <T> T[] readObjectArray(String name, Class<T> itemCls) {
T[] msg = stream.readObjectArray(itemCls, this);
@Override public <T> T[] readObjectArray(String name, MessageAdapter.Type itemType) {
T[] msg = stream.readObjectArray(itemType, this);

lastRead = stream.lastFinished();

return msg;
}

/** {@inheritDoc} */
@Override public <C extends Collection<T>, T> C readCollection(String name, Class<T> itemCls) {
C col = stream.readCollection(itemCls, this);
@Override public <C extends Collection<?>> C readCollection(String name, MessageAdapter.Type itemType) {
C col = stream.readCollection(itemType, this);

lastRead = stream.lastFinished();

return col;
}

/** {@inheritDoc} */
@Override public <M extends Map<K, V>, K, V> M readMap(String name, Class<K> keyCls, Class<V> valCls,
boolean linked) {
M map = stream.readMap(keyCls, valCls, this, linked);
@Override public <M extends Map<?, ?>> M readMap(String name, MessageAdapter.Type keyType,
MessageAdapter.Type valType, boolean linked) {
M map = stream.readMap(keyType, valType, this, linked);

lastRead = stream.lastFinished();

Expand Down
Expand Up @@ -193,22 +193,23 @@ public void state(MessageWriteState state) {
}

/** {@inheritDoc} */
@Override public <T> boolean writeObjectArray(String name, T[] arr, Class<T> itemCls) {
stream.writeObjectArray(arr, itemCls, state);
@Override public <T> boolean writeObjectArray(String name, T[] arr, MessageAdapter.Type itemType) {
stream.writeObjectArray(arr, itemType, state);

return stream.lastFinished();
}

/** {@inheritDoc} */
@Override public <T> boolean writeCollection(String name, Collection<T> col, Class<T> itemCls) {
stream.writeCollection(col, itemCls, state);
@Override public <T> boolean writeCollection(String name, Collection<T> col, MessageAdapter.Type itemType) {
stream.writeCollection(col, itemType, state);

return stream.lastFinished();
}

/** {@inheritDoc} */
@Override public <K, V> boolean writeMap(String name, Map<K, V> map, Class<K> keyCls, Class<V> valCls) {
stream.writeMap(map, keyCls, valCls, state);
@Override public <K, V> boolean writeMap(String name, Map<K, V> map, MessageAdapter.Type keyType,
MessageAdapter.Type valType) {
stream.writeMap(map, keyType, valType, state);

return stream.lastFinished();
}
Expand Down
Expand Up @@ -264,7 +264,7 @@ public void deployment(GridDeployment dep) {
state.increment();

case 4:
if (!writer.writeMap("ldrParties", ldrParties, UUID.class, IgniteUuid.class))
if (!writer.writeMap("ldrParties", ldrParties, Type.UUID, Type.IGNITE_UUID))
return false;

state.increment();
Expand Down Expand Up @@ -329,7 +329,7 @@ public void deployment(GridDeployment dep) {
readState++;

case 4:
ldrParties = reader.readMap("ldrParties", UUID.class, IgniteUuid.class, false);
ldrParties = reader.readMap("ldrParties", Type.UUID, Type.IGNITE_UUID, false);

if (!reader.isLastRead())
return false;
Expand Down
Expand Up @@ -188,7 +188,7 @@ public void localDeploymentOwner(boolean locDepOwner) {
state.increment();

case 3:
if (!writer.writeMap("participants", participants, UUID.class, IgniteUuid.class))
if (!writer.writeMap("participants", participants, Type.UUID, Type.IGNITE_UUID))
return false;

state.increment();
Expand Down Expand Up @@ -239,7 +239,7 @@ public void localDeploymentOwner(boolean locDepOwner) {
readState++;

case 3:
participants = reader.readMap("participants", UUID.class, IgniteUuid.class, false);
participants = reader.readMap("participants", Type.UUID, Type.IGNITE_UUID, false);

if (!reader.isLastRead())
return false;
Expand Down
Expand Up @@ -201,7 +201,7 @@ public void nodeIds(Collection<UUID> nodeIds) {
state.increment();

case 2:
if (!writer.writeCollection("nodeIds", nodeIds, UUID.class))
if (!writer.writeCollection("nodeIds", nodeIds, Type.UUID))
return false;

state.increment();
Expand Down Expand Up @@ -246,7 +246,7 @@ public void nodeIds(Collection<UUID> nodeIds) {
readState++;

case 2:
nodeIds = reader.readCollection("nodeIds", UUID.class);
nodeIds = reader.readCollection("nodeIds", Type.UUID);

if (!reader.isLastRead())
return false;
Expand Down
Expand Up @@ -336,7 +336,7 @@ void exceptionBytes(byte[] exBytes) {
state.increment();

case 6:
if (!writer.writeMap("ldrParties", ldrParties, UUID.class, IgniteUuid.class))
if (!writer.writeMap("ldrParties", ldrParties, Type.UUID, Type.IGNITE_UUID))
return false;

state.increment();
Expand Down Expand Up @@ -417,7 +417,7 @@ void exceptionBytes(byte[] exBytes) {
readState++;

case 6:
ldrParties = reader.readMap("ldrParties", UUID.class, IgniteUuid.class, false);
ldrParties = reader.readMap("ldrParties", Type.UUID, Type.IGNITE_UUID, false);

if (!reader.isLastRead())
return false;
Expand Down
Expand Up @@ -177,7 +177,7 @@ boolean error() {
state.increment();

case 5:
if (!writer.writeCollection("rejectedKeyBytes", rejectedKeyBytes, byte[].class))
if (!writer.writeCollection("rejectedKeyBytes", rejectedKeyBytes, Type.BYTE_ARR))
return false;

state.increment();
Expand Down Expand Up @@ -213,7 +213,7 @@ boolean error() {
readState++;

case 5:
rejectedKeyBytes = reader.readCollection("rejectedKeyBytes", byte[].class);
rejectedKeyBytes = reader.readCollection("rejectedKeyBytes", Type.BYTE_ARR);

if (!reader.isLastRead())
return false;
Expand Down

0 comments on commit ca27b58

Please sign in to comment.