本文整理汇总了Java中se.sics.kompics.network.netty.serialization.Serializers类的典型用法代码示例。如果您正苦于以下问题:Java Serializers类的具体用法?Java Serializers怎么用?Java Serializers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Serializers类属于se.sics.kompics.network.netty.serialization包,在下文中一共展示了Serializers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: register
import se.sics.kompics.network.netty.serialization.Serializers; //导入依赖的package包/类
public static void register() {
MessageRegistrator.register();
Serializers.register(ServerSerializer.FD.instance, "fdS");
Serializers.register(FDMsg.class, "fdS");
//
Serializers.register(ServerSerializer.GLOBAL.instance, "globalS");
Serializers.register(MaintenanceMsg.class, "globalS");
Serializers.register(Maintenance.class, "globalS");
//
Serializers.register(ServerSerializer.XNGIN.instance, "xnginS");
Serializers.register(SMROp.class, "xnginS");
Serializers.register(SyncedUp.class, "xnginS");
Serializers.register(Scan.class, "xnginS");
//
Serializers.register(ServerSerializer.BOOT.instance, "bootS");
Serializers.register(BootstrapMsg.class, "bootS");
}
示例2: fromBinary
import se.sics.kompics.network.netty.serialization.Serializers; //导入依赖的package包/类
@Override
public Object fromBinary(ByteBuf buf, Optional<Object> hint) {
byte[] ipBytes = new byte[4];
buf.readBytes(ipBytes);
if ((ipBytes[0] == 0) && (ipBytes[1] == 0) && (ipBytes[2] == 0) && (ipBytes[3] == 0)) {
return null; // IP 0.0.0.0 is not valid but null Address encoding
}
InetAddress ip;
try {
ip = InetAddress.getByAddress(ipBytes);
} catch (UnknownHostException ex) {
Serializers.LOG.error("AddressSerializer: Could not create InetAddress.", ex);
return null;
}
byte portUpper = buf.readByte();
byte portLower = buf.readByte();
int port = Ints.fromBytes((byte) 0, (byte) 0, portUpper, portLower);
return new TestAddress(ip, port);
}
示例3: 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);
}
示例4: register
import se.sics.kompics.network.netty.serialization.Serializers; //导入依赖的package包/类
public static void register() {
Serializers.register(CoreSerializer.SYSTEM.instance, "systemS");
Serializers.register(StartVNode.class, "systemS");
Serializers.register(StopVNode.class, "systemS");
//
Serializers.register(CoreSerializer.OP.instance, "opS");
Serializers.register(CaracalMsg.class, "opS");
Serializers.register(CaracalOp.class, "opS");
//
Serializers.register(CoreSerializer.LOOKUP.instance, "lookupS");
Serializers.register(ForwardMessage.class, "lookupS");
Serializers.register(LookupMessage.class, "lookupS");
Serializers.register(Schema.Req.class, "lookupS");
Serializers.register(Schema.Response.class, "lookupS");
//
Serializers.register(CoreSerializer.COND.instance, "condS");
Serializers.register(MultiOp.Condition.class, "condS");
//
Serializers.register(CoreSerializer.DTS.instance, "transferS");
Serializers.register(TransferMessage.class, "transferS");
//
Serializers.register(CoreSerializer.CDS.instance, "collectorS");
Serializers.register(CollectorDescriptor.class, "collectorS");
}
示例5: sendUdpMessage
import se.sics.kompics.network.netty.serialization.Serializers; //导入依赖的package包/类
ChannelFuture sendUdpMessage(MessageWrapper msgw) {
ByteBuf buf = udpChannel.alloc().ioBuffer(INITIAL_BUFFER_SIZE, SEND_BUFFER_SIZE);
try {
if (msgw.notify.isPresent() && msgw.notify.get().notifyOfDelivery) {
MessageNotify.Req msgr = msgw.notify.get();
AckRequestMsg arm = new AckRequestMsg(msgw.msg, msgr.getMsgId());
Serializers.toBinary(arm, buf);
} else {
Serializers.toBinary(msgw.msg, buf);
}
msgw.injectSize(buf.readableBytes(), System.nanoTime());
DatagramPacket pack = new DatagramPacket(buf, msgw.msg.getDestination().asSocket());
logger.debug("Sending Datagram message {} ({}bytes)", msgw.msg, buf.readableBytes());
return udpChannel.writeAndFlush(pack);
} catch (Exception e) { // serialization might fail horribly with size bounded buff
logger.warn("Could not send Datagram message {}, error was: {}", msgw, e);
return null;
}
}
示例6: toBinary
import se.sics.kompics.network.netty.serialization.Serializers; //导入依赖的package包/类
@Override
public void toBinary(Object o, ByteBuf buf) {
NodeMsg nodeMsg = (NodeMsg) o;
Serializers.toBinary(nodeMsg.header, buf); // write THeader
buf.writeLong(nodeMsg.rid); // write long
buf.writeByte(nodeMsg.comp); // write byte
buf.writeByte(nodeMsg.cmd); // write byte
buf.writeInt(nodeMsg.inst); // write int
byte[] data = SerializationUtils.serialize(nodeMsg.body);
buf.writeInt(data.length); // write int
buf.writeBytes(data); // write x * byte
}
示例7: 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));
}
示例8: toBinary
import se.sics.kompics.network.netty.serialization.Serializers; //导入依赖的package包/类
@Override
public void toBinary(Object o, ByteBuf buf) {
if (o instanceof Ping) {
Ping ping = (Ping) o;
buf.writeByte(PING); // 1 byte
Serializers.toBinary(ping.header, buf); // 1 byte serialiser id + 16 bytes THeader
// total 18 bytes
} else if (o instanceof Pong) {
Pong pong = (Pong) o;
buf.writeByte(PONG); // 1 byte
Serializers.toBinary(pong.header, buf); // 1 byte serialiser id + 16 bytes THeader
// total 18 bytes
}
}
示例9: main
import se.sics.kompics.network.netty.serialization.Serializers; //导入依赖的package包/类
public static void main(String[] args) throws UnknownHostException {
Serializers.register(new TestSerializer(), "testS");
Serializers.register(TestMessage.class, "testS");
InetAddress ip = InetAddress.getLocalHost();
senderAddr = new TestAddress(ip, 45454);
receiverAddr = new TestAddress(ip, 45455);
Kompics.createAndStart(Parent.class);
}
示例10: 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;
}
}
示例11: initToBinary
import se.sics.kompics.network.netty.serialization.Serializers; //导入依赖的package包/类
private void initToBinary(InitiateTransfer init, ByteBuf buf) {
MessageSerializationUtil.msgToBinary(init, buf, INIT, false);
SpecialSerializers.UUIDSerializer.INSTANCE.toBinary(init.id, buf);
buf.writeInt(init.metadata.size());
if (!init.metadata.isEmpty()) {
for (Entry<String, Object> e : init.metadata.entrySet()) {
byte[] keyB = e.getKey().getBytes(UTF8);
buf.writeInt(keyB.length);
buf.writeBytes(keyB);
Serializers.toBinary(e.getValue(), buf);
}
}
}
示例12: 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());
}
示例13: 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();
}
}
示例14: encode
import se.sics.kompics.network.netty.serialization.Serializers; //导入依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, MessageWrapper msgw, List<Object> outL) throws Exception {
component.setCustomMDC();
try {
long startTS = System.nanoTime(); // start measuring here to avoid overestimating the throuhgput
Msg msg = msgw.msg;
ByteBuf out = ctx.alloc().buffer(NettyNetwork.INITIAL_BUFFER_SIZE, NettyNetwork.SEND_BUFFER_SIZE);
component.extLog.trace("Trying to encode outgoing data to {} from {}: {}.", ctx.channel().remoteAddress(), ctx.channel().localAddress(), msgw.msg.getClass());
int startIdx = out.writerIndex();
out.writeBytes(LENGTH_PLACEHOLDER);
try {
if (msgw.notify.isPresent() && msgw.notify.get().notifyOfDelivery) {
MessageNotify.Req msgr = msgw.notify.get();
component.extLog.trace("Serialising message with AckRequest: {}", msgr.getMsgId());
AckRequestMsg arm = new AckRequestMsg(msgw.msg, msgr.getMsgId());
Serializers.toBinary(arm, out);
} else {
Serializers.toBinary(msgw.msg, out);
}
} catch (Throwable e) {
component.extLog.warn("There was a problem serialising {}: \n --> {}", msgw, e);
e.printStackTrace(System.err);
throw e;
}
int endIdx = out.writerIndex();
int diff = endIdx - startIdx - LENGTH_PLACEHOLDER.length;
if (diff > 65532) { //2^16 - 2bytes for the length header (snappy wants no more than 65536 bytes uncompressed)
throw new Exception("Can't encode message longer than 65532 bytes!");
}
out.setShort(startIdx, diff);
//component.LOG.trace("Encoded outgoing {} bytes of data to {}: {}.", new Object[]{diff, ctx.channel().remoteAddress(), ByteBufUtil.hexDump(out)});
msgw.injectSize(diff, startTS);
outL.add(out);
} finally {
MDC.clear();
}
}
示例15: 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();
}
}