本文整理汇总了Java中se.sics.kompics.network.netty.serialization.Serializers.fromBinary方法的典型用法代码示例。如果您正苦于以下问题:Java Serializers.fromBinary方法的具体用法?Java Serializers.fromBinary怎么用?Java Serializers.fromBinary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类se.sics.kompics.network.netty.serialization.Serializers
的用法示例。
在下文中一共展示了Serializers.fromBinary方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: chunkFromBinary
import se.sics.kompics.network.netty.serialization.Serializers; //导入方法依赖的package包/类
private Chunk chunkFromBinary(ByteBuf buf, MessageFields fields) {
UUID flowId = (UUID) SpecialSerializers.UUIDSerializer.INSTANCE.fromBinary(buf, Optional.absent());
int clearId = buf.readInt();
long chunkNo = buf.readLong();
long bytes = buf.readLong();
int length = FlowManager.CHUNK_SIZE;
boolean isFinal = false;
if (!fields.flag2) {
length = buf.readInt();
isFinal = buf.readBoolean();
}
ClearFlowId id = new ClearFlowId(flowId, clearId);
CollectorDescriptor cd = (CollectorDescriptor) Serializers.fromBinary(buf, Optional.absent());
ChunkCollector coll = ChunkCollector.getOrCreate(id, cd);
if (buf.readableBytes() < length) {
FlowManager.LOG.error("Expected to read {}, but only have {} in buffer. Chunk#{}",
new Object[]{length, buf.readableBytes(), chunkNo});
System.exit(1); // no point in continuing from here
}
DataRef data = coll.readChunk(chunkNo, length, buf);
return new Chunk(fields.src, fields.dst, fields.proto, flowId, clearId, chunkNo, bytes, data, isFinal, cd);
}
示例2: fromBinary
import se.sics.kompics.network.netty.serialization.Serializers; //导入方法依赖的package包/类
@Override
public Object fromBinary(ByteBuf buf, Optional<Object> hint) {
THeader header = (THeader) Serializers.fromBinary(buf, Optional.absent()); // read THeader
long rid = buf.readLong(); // read long
byte comp = buf.readByte(); // read byte
byte cmd = buf.readByte(); // read byte
int inst = buf.readInt(); // read int
byte[] data = new byte[buf.readInt()]; // read int
for (int i = 0; i < data.length; i++) {
data[i] = buf.readByte(); // read x * byte
}
return new NodeMsg(header.src, header.dst, rid, comp, cmd, inst, SerializationUtils.deserialize(data));
}
示例3: otherFromBinary
import se.sics.kompics.network.netty.serialization.Serializers; //导入方法依赖的package包/类
private BaseMessage otherFromBinary(MessageFields fields, ByteBuf buf) {
byte type = buf.readByte();
Value val;
switch (type) {
case FORWARD:
val = (Value) Serializers.fromBinary(buf, Optional.absent());
return new Forward(fields.src, fields.dst, fields.orig, val);
default:
LOG.error("Unknown Msg type: {}", type);
return null;
}
}
示例4: initFromBinary
import se.sics.kompics.network.netty.serialization.Serializers; //导入方法依赖的package包/类
private InitiateTransfer initFromBinary(MessageSerializationUtil.MessageFields fields, ByteBuf buf) {
UUID id = (UUID) SpecialSerializers.UUIDSerializer.INSTANCE.fromBinary(buf, Optional.absent());
int size = buf.readInt();
ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
for (int i = 0; i < size; i++) {
int keySize = buf.readInt();
byte[] keyB = new byte[keySize];
buf.readBytes(keyB);
String key = new String(keyB, UTF8);
Object value = Serializers.fromBinary(buf, Optional.absent());
builder.put(key, value);
}
return new InitiateTransfer(fields.src, fields.dst, id, builder.build());
}
示例5: decode
import se.sics.kompics.network.netty.serialization.Serializers; //导入方法依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
ByteBuf frame = (ByteBuf) super.decode(ctx, in);
if (frame == null) {
return null;
}
component.setCustomMDC();
try {
component.extLog.trace("Trying to decode incoming {} bytes of data from {} to {}.", new Object[]{frame.readableBytes(), ctx.channel().remoteAddress(), ctx.channel().localAddress()});
Object o = Serializers.fromBinary(frame, Optional.absent());
component.extLog.trace("Decoded incoming data from {}: {}", ctx.channel().remoteAddress(), o);
if (o instanceof AckRequestMsg) {
AckRequestMsg arm = (AckRequestMsg) o;
component.extLog.trace("Got AckRequest for {}. Replying...", arm.id);
NotifyAck an = arm.reply();
ctx.channel().writeAndFlush(new MessageWrapper(an));
return arm.content;
} else if (o instanceof Msg) {
return o;
} else {
component.extLog.warn("Got unexpected Stream message type: {} -> {}", o.getClass().getCanonicalName(), o);
}
return o;
} finally {
MDC.clear();
}
}
示例6: messageReceived
import se.sics.kompics.network.netty.serialization.Serializers; //导入方法依赖的package包/类
@Override
protected void messageReceived(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
component.setCustomMDC();
try {
Object o = Serializers.fromBinary(msg.content(), msg);
if (o instanceof AckRequestMsg) {
AckRequestMsg arm = (AckRequestMsg) o;
ByteBuf buf = ctx.alloc().ioBuffer(NettyNetwork.INITIAL_BUFFER_SIZE, NettyNetwork.SEND_BUFFER_SIZE);
component.deliverMessage(arm.content, ctx.channel());
component.extLog.trace("Got AckRequest for {}. Replying...", arm.id);
NotifyAck ack = arm.reply();
Serializers.toBinary(ack, buf);
DatagramPacket pack = new DatagramPacket(buf, ack.getDestination().asSocket());
component.extLog.trace("Sending Datagram ACK {} ({}bytes)", ack, buf.readableBytes());
ctx.writeAndFlush(pack);
} else if (o instanceof Msg) {
Msg m = (Msg) o;
component.deliverMessage(m, ctx.channel());
} else {
component.extLog.warn("Got unexpected Datagram message type: {} -> {}", o.getClass().getCanonicalName(), o);
}
} catch (Exception e) { // Catch anything...the Serializer could throw any kind of weird exception if you get message that were send by someone else
component.extLog.warn("Got weird Datagram message, ignoring it: {}", ByteBufUtil.hexDump(msg.content()));
component.extLog.trace("Exception was: \n{}", e);
} finally {
MDC.clear();
}
}
示例7: instanceFromBinary
import se.sics.kompics.network.netty.serialization.Serializers; //导入方法依赖的package包/类
private Instance instanceFromBinary(ByteBuf buf) {
long id = buf.readLong();
int ballot = buf.readInt();
Value v = (Value) Serializers.fromBinary(buf, Optional.absent());
return new Instance(id, ballot, v);
}
示例8: paxosFromBinary
import se.sics.kompics.network.netty.serialization.Serializers; //导入方法依赖的package包/类
private PaxosMsg paxosFromBinary(MessageFields fields, ByteBuf buf) {
int ballot = buf.readInt();
byte type = buf.readByte();
View v;
Instance ins;
int size;
switch (type) {
case PREPARE:
return new Prepare(fields.src, fields.dst, ballot);
case PROMISE:
size = buf.readInt();
ImmutableSet.Builder<Instance> builder = ImmutableSet.builder();
for (int i = 0; i < size; i++) {
builder.add(instanceFromBinary(buf));
}
v = CustomSerialisers.deserialiseView(buf);
return new Promise(fields.src, fields.dst, ballot, builder.build(), v);
case NO_PROMISE:
return new NoPromise(fields.src, fields.dst, ballot);
case ACCEPT:
ins = instanceFromBinary(buf);
return new Accept(fields.src, fields.dst, ballot, ins);
case ACCEPTED:
ins = instanceFromBinary(buf);
v = CustomSerialisers.deserialiseView(buf);
return new Accepted(fields.src, fields.dst, ballot, ins, v);
case REJECTED:
ins = instanceFromBinary(buf);
return new Rejected(fields.src, fields.dst, ballot, ins);
case INSTALL:
Reconfigure rec = (Reconfigure) Serializers.fromBinary(buf, Optional.absent());
long highestDecided = buf.readLong();
size = buf.readInt();
ImmutableSortedMap.Builder<Long, Value> mBuilder = ImmutableSortedMap.naturalOrder();
for (int i = 0; i < size; i++) {
long k = buf.readLong();
Value val = (Value) Serializers.fromBinary(buf, Optional.absent());
mBuilder.put(k, val);
}
return new Install(fields.src, fields.dst, ballot, rec, highestDecided, mBuilder.build());
default:
LOG.error("Unknown PaxosMsg type: {}", type);
return null;
}
}