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


Java Serializers.toBinary方法代码示例

本文整理汇总了Java中se.sics.kompics.network.netty.serialization.Serializers.toBinary方法的典型用法代码示例。如果您正苦于以下问题:Java Serializers.toBinary方法的具体用法?Java Serializers.toBinary怎么用?Java Serializers.toBinary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在se.sics.kompics.network.netty.serialization.Serializers的用法示例。


在下文中一共展示了Serializers.toBinary方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

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

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

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

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

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

import se.sics.kompics.network.netty.serialization.Serializers; //导入方法依赖的package包/类
private void instanceToBinary(Instance i, ByteBuf buf) {
    buf.writeLong(i.id);
    buf.writeInt(i.ballot);
    Serializers.toBinary(i.value, buf);
}
 
开发者ID:CaracalDB,项目名称:CaracalDB,代码行数:6,代码来源:PaxosSerializer.java


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