当前位置: 首页>>代码示例>>Java>>正文


Java Serializers.fromBinary方法代码示例

本文整理汇总了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);
}
 
开发者ID:CaracalDB,项目名称:CaracalDB,代码行数:24,代码来源:FlowMessageSerializer.java

示例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));
}
 
开发者ID:tobiajo,项目名称:jbstore,代码行数:14,代码来源:NodeMsgSerializer.java

示例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;
    }
}
 
开发者ID:CaracalDB,项目名称:CaracalDB,代码行数:13,代码来源:PaxosSerializer.java

示例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());
}
 
开发者ID:CaracalDB,项目名称:CaracalDB,代码行数:15,代码来源:DataTransferSerializer.java

示例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();
    }
}
 
开发者ID:kompics,项目名称:kompics,代码行数:28,代码来源:MessageDecoder.java

示例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();
    }
}
 
开发者ID:kompics,项目名称:kompics,代码行数:30,代码来源:DatagramHandler.java

示例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);
}
 
开发者ID:CaracalDB,项目名称:CaracalDB,代码行数:7,代码来源:PaxosSerializer.java

示例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;
    }
}
 
开发者ID:CaracalDB,项目名称:CaracalDB,代码行数:46,代码来源:PaxosSerializer.java


注:本文中的se.sics.kompics.network.netty.serialization.Serializers.fromBinary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。