Search in sources :

Example 1 with MessageType

use of edu.iu.dsc.tws.comms.api.MessageType in project twister2 by DSC-SPIDAL.

the class MPIMessageDeSerializer method getDataBuffers.

@Override
@SuppressWarnings("unchecked")
public Object getDataBuffers(Object partialObject, int edge) {
    MPIMessage message = (MPIMessage) partialObject;
    MessageType type = message.getType();
    // Used when handling multi messages
    List<ImmutablePair<byte[], byte[]>> results;
    if (!keyed) {
        return DataDeserializer.getAsByteBuffer(message.getBuffers(), message.getHeader().getLength(), type);
    } else {
        Pair<Integer, Object> keyPair = KeyDeserializer.getKeyAsByteBuffer(message.getKeyType(), message.getBuffers());
        MessageType keyType = message.getKeyType();
        Object data;
        if (MessageTypeUtils.isMultiMessageType(keyType)) {
            data = DataDeserializer.getAsByteBuffer(message.getBuffers(), message.getHeader().getLength() - keyPair.getKey() - 4 - 4, type, ((List) keyPair.getValue()).size());
            results = new ArrayList<>();
            List<byte[]> keyList = (List<byte[]>) keyPair.getValue();
            List<byte[]> dataList = (List<byte[]>) data;
            for (int i = 0; i < keyList.size(); i++) {
                results.add(new ImmutablePair<>(keyList.get(i), dataList.get(i)));
            }
            return results;
        } else if (!MessageTypeUtils.isPrimitiveType(keyType)) {
            data = DataDeserializer.getAsByteBuffer(message.getBuffers(), message.getHeader().getLength() - keyPair.getKey() - 4, type);
        } else {
            data = DataDeserializer.getAsByteBuffer(message.getBuffers(), message.getHeader().getLength() - keyPair.getKey(), type);
        }
        return new ImmutablePair<>(keyPair.getValue(), data);
    }
}
Also used : MPIMessage(edu.iu.dsc.tws.comms.mpi.MPIMessage) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ArrayList(java.util.ArrayList) List(java.util.List) MessageType(edu.iu.dsc.tws.comms.api.MessageType)

Example 2 with MessageType

use of edu.iu.dsc.tws.comms.api.MessageType in project twister2 by DSC-SPIDAL.

the class MPIMultiMessageDeserializer method getSingleDataBuffers.

public Object getSingleDataBuffers(MPIMessage mpiMessage, List<MPIBuffer> message, int length) {
    MessageType type = mpiMessage.getType();
    if (!keyed) {
        return DataDeserializer.getAsByteBuffer(message, length, type);
    } else {
        Pair<Integer, Object> keyPair = KeyDeserializer.getKeyAsByteBuffer(mpiMessage.getKeyType(), message);
        byte[] data = DataDeserializer.getAsByteBuffer(message, length - keyPair.getKey(), type);
        return new ImmutablePair<>(keyPair.getValue(), data);
    }
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) MessageType(edu.iu.dsc.tws.comms.api.MessageType)

Example 3 with MessageType

use of edu.iu.dsc.tws.comms.api.MessageType in project twister2 by DSC-SPIDAL.

the class MPIMessageDeSerializer method buildMessage.

private Object buildMessage(MPIMessage message) {
    MessageType type = message.getType();
    if (!keyed) {
        return DataDeserializer.deserializeData(message.getBuffers(), message.getHeader().getLength(), serializer, type);
    } else {
        Pair<Integer, Object> keyPair = KeyDeserializer.deserializeKey(message.getKeyType(), message.getBuffers(), serializer);
        MessageType keyType = message.getKeyType();
        if (MessageTypeUtils.isMultiMessageType(keyType)) {
            return DataDeserializer.deserializeData(message.getBuffers(), message.getHeader().getLength() - keyPair.getKey() - 4 - 4, serializer, type, ((List) keyPair.getValue()).size());
        } else if (!MessageTypeUtils.isPrimitiveType(keyType)) {
            return DataDeserializer.deserializeData(message.getBuffers(), message.getHeader().getLength() - keyPair.getKey() - 4, serializer, type);
        } else {
            return DataDeserializer.deserializeData(message.getBuffers(), message.getHeader().getLength() - keyPair.getKey(), serializer, type);
        }
    }
}
Also used : MessageType(edu.iu.dsc.tws.comms.api.MessageType)

Aggregations

MessageType (edu.iu.dsc.tws.comms.api.MessageType)3 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)2 MPIMessage (edu.iu.dsc.tws.comms.mpi.MPIMessage)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1