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


Java Msg类代码示例

本文整理汇总了Java中se.sics.kompics.network.Msg的典型用法代码示例。如果您正苦于以下问题:Java Msg类的具体用法?Java Msg怎么用?Java Msg使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: executeKompicsEvent

import se.sics.kompics.network.Msg; //导入依赖的package包/类
private void executeKompicsEvent(KompicsEvent kompicsEvent) {
    // trigger Messages on the Network port
    if (kompicsEvent instanceof Msg) {
        Msg message = (Msg) kompicsEvent;
        LOG.debug("Delivered Message: {} from {} to {} ", new Object[]{
            message, message.getSource(), message.getDestination()});
        trigger(message, network);
        return;
    }

    // trigger Timeouts on the Timer port
    if (kompicsEvent instanceof Timeout) {
        Timeout timeout = (Timeout) kompicsEvent;
        LOG.debug("Triggered Timeout: {} {}", kompicsEvent, timeout
                .getTimeoutId());
        activeTimers.remove(timeout.getTimeoutId());
        trigger(timeout, timer);
        return;
    }

    // trigger other Kompics events on the simulation port
    trigger(kompicsEvent, simulationPort);
}
 
开发者ID:CaracalDB,项目名称:CaracalDB,代码行数:24,代码来源:VirtualSimulator.java

示例2: handle

import se.sics.kompics.network.Msg; //导入依赖的package包/类
@Override
public void handle(Msg event) {
    Header h = event.getHeader();
    if (h.getProtocol() == Transport.DATA) {
        InetSocketAddress target = h.getDestination().asSocket();
        ConnectionTracker ct = connections.get(target);
        if (ct == null) {
            ct = factory.findConnection(target);
            connections.put(target, ct);
        }
        ct.enqueue(event);
        tryToSend(ct);
    } else {
        throw new RuntimeException("Invalid protocol: " + h.getProtocol());
    }
}
 
开发者ID:kompics,项目名称:kompics,代码行数:17,代码来源:DataStreamInterceptor.java

示例3: handle

import se.sics.kompics.network.Msg; //导入依赖的package包/类
@Override
public void handle(Msg event) {
    if (event instanceof BaseMessage) {
        BaseMessage msg = (BaseMessage) event;
        if (msg instanceof Forwardable) {
            if (recentForwardsFirstGen.size() > MAX_RECENTS) {
                recentForwardsFirstGen.clear();
            }
            if (recentForwardsSecondGen.size() > MAX_RECENTS) {
                recentForwardsSecondGen.clear();
            }
            Forwardable f = (Forwardable) event;
            if (recentForwardsSecondGen.contains(f.getId())) {
                LOG.warn("{}: Not forwarding message anymore, due do possible endless loop: {}", self, event);
                return;
            }
            if (recentForwardsFirstGen.contains(f.getId())) {
                recentForwardsSecondGen.add(f.getId());
            }
            recentForwardsFirstGen.add(f.getId());
            Key dest = new Key(msg.getHeader().getDstId());
            trigger(new ForwardMessage(self, self, msg.getOrigin(), msg.getProtocol(), dest, f), net);
            LOG.trace("{}: Forwarded message to LUTManager: {}", self, msg);
            return;
        }
    }
    LOG.debug("{}: Dropping mis-addressed message: {}", self, event);
}
 
开发者ID:CaracalDB,项目名称:CaracalDB,代码行数:29,代码来源:DeadLetterBox.java

示例4: tryToSend

import se.sics.kompics.network.Msg; //导入依赖的package包/类
private void tryToSend(ConnectionTracker ct) {
    while (ct.canSend(maxQueueLength)) {
        Either<MessageNotify.Req, Msg> eMsg = ct.dequeue();
        Msg event;
        Optional<MessageNotify.Req> or;
        if (eMsg.isLeft()) {
            MessageNotify.Req mnr = eMsg.getLeft();
            event = mnr.msg;
            or = Optional.of(mnr);
        } else {
            event = eMsg.getRight();
            or = Optional.absent();
        }
        Header h = event.getHeader();
        Transport proto = ct.selectionPolicy.select(event);
        ct.stats.updateSelection(proto);
        logger.trace("Got DATA message over {} to track: {}", proto, event);
        long ts = System.currentTimeMillis();
        MessageNotify.Req req;
        if (h instanceof DataHeader) { // replace protocol
            DataHeader dh = (DataHeader) event.getHeader();
            dh.replaceProtocol(proto);
            req = MessageNotify.createWithDeliveryNotification(event);
        } else { // wrap message
            Msg wrapped = new DataMsgWrapper(event, proto);
            req = MessageNotify.createWithDeliveryNotification(wrapped);
        }
        TrackedMessage tm = new TrackedMessage(event, ts, or, ct);
        trigger(req, netDown);
        outstanding.put(req.getMsgId(), tm);
    }
}
 
开发者ID:kompics,项目名称:kompics,代码行数:33,代码来源:DataStreamInterceptor.java

示例5: select

import se.sics.kompics.network.Msg; //导入依赖的package包/类
@Override
public Transport select(Msg msg) {
    if (rand.nextDouble() < ratio) {
        return Transport.UDT;
    } else {
        return Transport.TCP;
    }
}
 
开发者ID:kompics,项目名称:kompics,代码行数:9,代码来源:RandomSelection.java

示例6: handle

import se.sics.kompics.network.Msg; //导入依赖的package包/类
@Override
public void handle(Msg event) {
    if (event.getDestination().sameHostAs(self)) {
        logger.trace("Delivering message {} locally.", event);
        trigger(event, net);
        return;
    }

    messages.send(event);
}
 
开发者ID:kompics,项目名称:kompics,代码行数:11,代码来源:NettyNetwork.java

示例7: trigger

import se.sics.kompics.network.Msg; //导入依赖的package包/类
void trigger(KompicsEvent event) {
    if (event instanceof Msg) {
        throw new RuntimeException("Not support anymore!");
        //trigger(event, net.getPair());
    } else {
        trigger(event, onSelf);
    }
}
 
开发者ID:kompics,项目名称:kompics,代码行数:9,代码来源:NettyNetwork.java

示例8: decode

import se.sics.kompics.network.Msg; //导入依赖的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

示例9: encode

import se.sics.kompics.network.Msg; //导入依赖的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

示例10: checkTCPChannel

import se.sics.kompics.network.Msg; //导入依赖的package包/类
void checkTCPChannel(Msg msg, SocketChannel c) {
    // Ignore some messages
    if (msg instanceof CheckChannelActive) {
        return;
    }
    if (msg instanceof CloseChannel) {
        return;
    }
    if (msg instanceof ChannelClosed) {
        return;
    }
    if (!c.equals(tcpActiveChannels.get(msg.getSource().asSocket()))) {
        synchronized (this) {
            component.setCustomMDC();
            try {
                SocketChannel activeC = tcpActiveChannels.get(msg.getSource().asSocket());
                tcpActiveChannels.put(msg.getSource().asSocket(), c);
                tcpChannels.put(msg.getSource().asSocket(), c);
                if (activeC != null && !activeC.equals(c)) {
                    component.extLog.warn("Duplicate TCP channel between {} and {}: local {}, remote {}",
                            new Object[]{msg.getSource(), msg.getDestination(), c.localAddress(), c.remoteAddress()});

                    SocketChannel minsc = minChannel(tcpChannels.get(msg.getSource().asSocket()));

                    minsc.writeAndFlush(new MessageNotify.Req(new CheckChannelActive(component.self, msg.getSource(), Transport.TCP)));

                }
            } finally {
                MDC.clear();
            }
        }
        component.trigger(new SendDelayed(msg.getSource(), Transport.TCP));
    }
}
 
开发者ID:kompics,项目名称:kompics,代码行数:35,代码来源:ChannelManager.java

示例11: checkUDTChannel

import se.sics.kompics.network.Msg; //导入依赖的package包/类
void checkUDTChannel(Msg msg, UdtChannel c) {
    // Ignore some messages
    if (msg instanceof CheckChannelActive) {
        return;
    }
    if (msg instanceof CloseChannel) {
        return;
    }
    if (msg instanceof ChannelClosed) {
        return;
    }
    if (!c.equals(udtActiveChannels.get(msg.getSource().asSocket()))) {
        synchronized (this) {
            component.setCustomMDC();
            try {
                UdtChannel activeC = udtActiveChannels.get(msg.getSource().asSocket());

                udtActiveChannels.put(msg.getSource().asSocket(), c);
                udtChannels.put(msg.getSource().asSocket(), c);
                if (activeC != null && !activeC.equals(c)) {
                    component.extLog.warn("Duplicate TCP channel between {} and {}: local {}, remote {}",
                            new Object[]{msg.getSource(), msg.getDestination(), c.localAddress(), c.remoteAddress()});

                    UdtChannel minsc = minChannel(udtChannels.get(msg.getSource().asSocket()));

                    minsc.writeAndFlush(new MessageNotify.Req(new CheckChannelActive(component.self, msg.getSource(), Transport.UDT)));

                }
            } finally {
                MDC.clear();
            }
        }
        component.trigger(new SendDelayed(msg.getSource(), Transport.UDT));
    }
}
 
开发者ID:kompics,项目名称:kompics,代码行数:36,代码来源:ChannelManager.java

示例12: messageReceived

import se.sics.kompics.network.Msg; //导入依赖的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

示例13: getLatencyMs

import se.sics.kompics.network.Msg; //导入依赖的package包/类
@Override
public long getLatencyMs(Msg message) {
    return min + (long)Math.floor(rand.nextDouble() * diff);
}
 
开发者ID:CaracalDB,项目名称:CaracalDB,代码行数:5,代码来源:UniformRandomModel.java

示例14: MessageDestinationSelector

import se.sics.kompics.network.Msg; //导入依赖的package包/类
public MessageDestinationSelector(Address self) {
    super(Msg.class, new HostAddress(self), true);
}
 
开发者ID:CaracalDB,项目名称:CaracalDB,代码行数:4,代码来源:MessageDestinationSelector.java

示例15: getValue

import se.sics.kompics.network.Msg; //导入依赖的package包/类
@Override
public HostAddress getValue(Msg event) {
    return new HostAddress(event.getDestination());
}
 
开发者ID:CaracalDB,项目名称:CaracalDB,代码行数:5,代码来源:MessageDestinationSelector.java


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