Example usage for io.netty.channel ChannelHandlerContext fireChannelRead

List of usage examples for io.netty.channel ChannelHandlerContext fireChannelRead

Introduction

In this page you can find the example usage for io.netty.channel ChannelHandlerContext fireChannelRead.

Prototype

@Override
    ChannelHandlerContext fireChannelRead(Object msg);

Source Link

Usage

From source file:org.onosproject.openflow.controller.impl.OFChannelHandler.java

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

    boolean release = true;
    try {/*from  w ww . j  av  a 2  s .  c o m*/
        if (msg instanceof OFMessage) {
            // channelRead0 inlined
            state.processOFMessage(this, (OFMessage) msg);
        } else {
            release = false;
            ctx.fireChannelRead(msg);
        }
    } finally {
        if (release) {
            ReferenceCountUtil.release(msg);
        }
    }
}

From source file:org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.AsyncSshHandler.java

License:Open Source License

private synchronized void handleSshChanelOpened(final ChannelHandlerContext ctx) {
    LOG.trace("SSH subsystem channel opened successfully on channel: {}", ctx.channel());

    connectPromise.setSuccess();/*from  w ww . j ava2 s .c om*/

    // TODO we should also read from error stream and at least log from that

    sshReadAsyncListener = new AsyncSshHandlerReader(new AutoCloseable() {
        @Override
        public void close() throws Exception {
            AsyncSshHandler.this.disconnect(ctx, ctx.newPromise());
        }
    }, new AsyncSshHandlerReader.ReadMsgHandler() {
        @Override
        public void onMessageRead(final ByteBuf msg) {
            ctx.fireChannelRead(msg);
        }
    }, channel.toString(), channel.getAsyncOut());

    // if readAsyncListener receives immediate close, it will close this handler and closing this handler sets channel variable to null
    if (channel != null) {
        sshWriteAsyncHandler = new AsyncSshHandlerWriter(channel.getAsyncIn());
        ctx.fireChannelActive();
    }
}

From source file:org.opendaylight.netconf.nettyutil.handler.ssh.client.AsyncSshHandler.java

License:Open Source License

private synchronized void handleSshChanelOpened(final ChannelHandlerContext ctx) {
    LOG.trace("SSH subsystem channel opened successfully on channel: {}", ctx.channel());

    if (negotiationFuture == null) {
        connectPromise.setSuccess();/*from w  ww. ja v a2 s.  c  o m*/
    }

    // TODO we should also read from error stream and at least log from that

    sshReadAsyncListener = new AsyncSshHandlerReader(new AutoCloseable() {
        @Override
        public void close() throws Exception {
            AsyncSshHandler.this.disconnect(ctx, ctx.newPromise());
        }
    }, new AsyncSshHandlerReader.ReadMsgHandler() {
        @Override
        public void onMessageRead(final ByteBuf msg) {
            ctx.fireChannelRead(msg);
        }
    }, channel.toString(), channel.getAsyncOut());

    // if readAsyncListener receives immediate close, it will close this handler and closing this handler sets channel variable to null
    if (channel != null) {
        sshWriteAsyncHandler = new AsyncSshHandlerWriter(channel.getAsyncIn());
        ctx.fireChannelActive();
    }
}

From source file:org.opendaylight.ocpjava.protocol.impl.core.IdleHandler.java

License:Open Source License

@Override
protected void readTimedOut(final ChannelHandlerContext ctx) throws Exception {
    if (first) {/*from ww  w.j ava 2  s  .c om*/
        LOG.debug("RadioHead idle");
        RadioHeadIdleEventBuilder builder = new RadioHeadIdleEventBuilder();
        builder.setInfo("RadioHead idle");
        ctx.fireChannelRead(builder.build());
        first = false;
    }
}

From source file:org.opendaylight.openflowjava.protocol.impl.core.IdleHandler.java

License:Open Source License

@Override
protected void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) throws Exception {
    if ((evt.state() == IdleState.READER_IDLE) && (evt.isFirst())) {
        LOGGER.debug("Switch idle");
        SwitchIdleEventBuilder builder = new SwitchIdleEventBuilder();
        builder.setInfo("Switch idle");
        ctx.fireChannelRead(builder.build());
    }/*from www . j  a va  2s  .  c om*/
}

From source file:org.opendaylight.sxp.core.handler.ConnectionDecoder.java

License:Open Source License

@Override
public void channelRead0(ChannelHandlerContext ctx, ByteBuf message)
        throws ErrorCodeDataLengthException, AttributeLengthException, TlvNotFoundException,
        AddressLengthException, UnknownNodeIdException, ErrorMessageException, UnknownSxpMessageTypeException,
        AttributeVariantException, UnknownHostException, UnknownPrefixException {
    InetSocketAddress address = getAddress(ctx);
    final SxpConnection connection = owner.getConnection(address);
    final SxpDomain domain = getTemplateDomain(address);

    if (address != null && connection == null && domain != null) {
        final SxpConnectionTemplateFields template = domain.getTemplate(address);
        Notification notification = MessageFactory.parse(null, message);
        Version version = getVersion(notification);
        ConnectionMode mode = getMode(notification);
        if ((template.getTemplateMode() == null || template.getTemplateMode().equals(mode))
                && (template.getTemplateVersion() == null || template.getTemplateVersion().equals(version))) {
            LOG.info("{} Adding new SxpConnection from template {}", owner, template);
            addConnection(domain.getName(),
                    new ConnectionBuilder().setMode(invertMode(mode)).setTcpPort(template.getTemplateTcpPort())
                            .setPeerAddress(new IpAddress(address.getAddress().getHostAddress().toCharArray()))
                            .setPassword(template.getTemplatePassword())
                            .setDescription("AutoGenerated connection.").setState(ConnectionState.Off)
                            .setConnectionTimers(new ConnectionTimersBuilder().build()).setVersion(version)
                            .setCapabilities(Configuration.getCapabilities(version)).build());
        }//from w  ww  . j a va  2 s.c  o m
        ctx.close();
    } else {
        ReferenceCountUtil.retain(message);
        ctx.fireChannelRead(message);
    }
}

From source file:org.opendaylight.usc.plugin.UscRemoteDeviceHandler.java

License:Open Source License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (isRemote(ctx)) {
        ByteBuf payload = (ByteBuf) msg;
        byte[] data = getPayloadFromByteBuf(payload);
        writeBuffer(data);/*from ww  w . j a v a 2 s. co  m*/
        return;
    }
    ReferenceCountUtil.retain(msg);
    // propagate the data to rest of handlers in pipeline
    ctx.fireChannelRead(msg);
}

From source file:org.opendaylight.usc.plugin.UscRemoteServerHandler.java

License:Open Source License

@Override
protected void channelRead0(ChannelHandlerContext ctx, Object data) throws Exception {
    UscRouteIdentifier localRouteId = null;

    // get local route identifier
    if (data instanceof UscFrame) {
        LOG.trace("Read data from Usc Agent: " + data);
        // communicate with agent
        final UscHeader header = ((UscFrame) data).getHeader();
        final UscChannelImpl connection = ctx.channel().attr(UscPlugin.CHANNEL).get();
        // for remote session
        localRouteId = new UscRouteIdentifier(connection.getDevice().getInetAddress(), connection.getType(),
                header.getSessionId(), header.getApplicationPort());
    } else {/*from www .j a  va 2 s  .  co m*/
        LOG.trace("Read data from None Usc Agent: " + data);
        // communicate directly with device
        localRouteId = ctx.channel().attr(UscPlugin.ROUTE_IDENTIFIER).get();
    }

    if (broker == null) {
        broker = UscServiceUtils.getService(UscRouteBrokerService.class);
    }
    if (broker == null) {
        LOG.error("Broker service is null!Can't check if it is response from remote channel.Route id is "
                + localRouteId);
    } else if (broker.isRemoteSession(localRouteId)) {
        byte[] payload = null;
        // get content, after reading the readable data become zero,can't
        // use again
        if (data instanceof UscFrame) {
            payload = getPayloadFromByteBuf(((UscFrame) data).getPayload());
        } else if (data instanceof DatagramPacket) {
            payload = getPayloadFromByteBuf(((DatagramPacket) data).content());
        } else {
            payload = getPayloadFromByteBuf((ByteBuf) data);
        }
        if (data instanceof UscError) {
            // propagate exception to the client channel
            UscSessionException ex = new UscSessionException(((UscError) data).getErrorCode());
            // send error message back to remote request controller
            broker.sendException(localRouteId, ex);
        } else {
            broker.sendResponse(localRouteId, payload);
        }
        LOG.trace("It is response from local remote channel.Sending message to route id (" + localRouteId
                + ").messsage is " + new String(payload));
        return;
    }

    ReferenceCountUtil.retain(data);
    // propagate the data to rest of handlers in pipeline
    ctx.fireChannelRead(data);
}

From source file:org.ow2.petals.bc.gateway.commons.handlers.LastLoggingHandler.java

License:Open Source License

@Override
public void channelRead(final @Nullable ChannelHandlerContext ctx, final @Nullable Object msg)
        throws Exception {
    assert ctx != null;
    logger.severe(String.format(//from www .j a  va  2  s. c  om
            "Discarded inbound message %s that reached the tail of the pipeline. There is something wrong!",
            msg));
    // let the last handler free resources and stuffs like this
    ctx.fireChannelRead(msg);
}

From source file:org.restcomm.media.network.netty.handler.NetworkFilter.java

License:Open Source License

@Override
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
    boolean secure = guard.isSecure(ctx.channel(), msg.sender());
    if (secure) {
        // Allow the packet to pass to next handler in pipeline for processing
        ctx.fireChannelRead(msg);
    } else {//w w  w.  j a v a2  s .c  o  m
        ReferenceCountUtil.release(msg);
    }
}