Example usage for io.netty.channel ChannelHandlerContext fireUserEventTriggered

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

Introduction

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

Prototype

@Override
    ChannelHandlerContext fireUserEventTriggered(Object evt);

Source Link

Usage

From source file:org.opendaylight.controller.netconf.nettyutil.handler.ssh.virtualsocket.ChannelInputStream.java

License:Open Source License

public void userEventTriggered(ChannelHandlerContext ctx, Object o) {
    ctx.fireUserEventTriggered(o);
}

From source file:org.opendaylight.controller.netconf.util.handler.ssh.virtualsocket.ChannelInputStream.java

License:Open Source License

public void userEventTriggered(ChannelHandlerContext ctx, Object o) throws Exception {
    ctx.fireUserEventTriggered(o);
}

From source file:org.scache.network.server.TransportChannelHandler.java

License:Apache License

/** Triggered based on events from an {@link io.netty.handler.timeout.IdleStateHandler}. */
@Override//  w ww. j a v a2  s  . co m
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent e = (IdleStateEvent) evt;
        // See class comment for timeout semantics. In addition to ensuring we only timeout while
        // there are outstanding requests, we also do a secondary consistency check to ensure
        // there's no race between the idle timeout and incrementing the numOutstandingRequests
        // (see SPARK-7003).
        //
        // To avoid a race between TransportClientFactory.createClient() and this code which could
        // result in an inactive client being returned, this needs to run in a synchronized block.
        synchronized (this) {
            boolean isActuallyOverdue = System.nanoTime()
                    - responseHandler.getTimeOfLastRequestNs() > requestTimeoutNs;
            if (e.state() == IdleState.ALL_IDLE && isActuallyOverdue) {
                if (responseHandler.numOutstandingRequests() > 0) {
                    String address = NettyUtils.getRemoteAddress(ctx.channel());
                    logger.error("Connection to {} has been quiet for {} ms while there are outstanding "
                            + "requests. Assuming connection is dead; please adjust scache.network.timeout if "
                            + "this is wrong.", address, requestTimeoutNs / 1000 / 1000);
                    client.timeOut();
                    ctx.close();
                } else if (closeIdleConnections) {
                    // While CloseIdleConnections is enable, we also close idle connection
                    client.timeOut();
                    ctx.close();
                }
            }
        }
    }
    ctx.fireUserEventTriggered(evt);
}

From source file:org.vertx.java.core.impl.FlowControlHandler.java

License:Apache License

@Override
public void flush(final ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
    boolean writable = state.isWritable();
    if (writable) {
        writable = !outboundBuf.isReadable(highMark);
    }/*from   ww  w.  java 2s.c  o m*/
    if (!writable) {
        if (state.isWritable()) {
            state.updateWritable(false);
            ctx.fireUserEventTriggered(state);
        }
        promise.addListener(listener);

    }
    ctx.flush(promise);
}

From source file:reactor.ipc.netty.channel.ChannelOperationsHandler.java

License:Open Source License

@Override
final public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (log.isTraceEnabled()) {
        log.trace("User event {}", evt);
    }// w  w  w  .  j av  a  2 s .c o m
    if (evt instanceof NettyPipeline.SendOptionsChangeEvent) {
        if (log.isDebugEnabled()) {
            log.debug("New sending options");
        }
        ((NettyPipeline.SendOptionsChangeEvent) evt).configurator().accept(this);
    } else {
        ctx.fireUserEventTriggered(evt);
    }
}

From source file:reactor.ipc.netty.http.server.HttpServerHandler.java

License:Open Source License

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt == NettyPipeline.handlerTerminatedEvent()) {
        if (mustRecycleEncoder) {
            mustRecycleEncoder = false;/*from w ww . j a v a 2 s .  c  om*/
            pendingResponses -= 1;

            ctx.pipeline().replace(NettyPipeline.HttpEncoder, NettyPipeline.HttpEncoder,
                    new HttpResponseEncoder());
        }

        if (pipelined != null && !pipelined.isEmpty()) {
            if (HttpServerOperations.log.isDebugEnabled()) {
                HttpServerOperations.log.debug("draining next pipelined " + "request,"
                        + " pending response count: {}, queued: " + "{}", pendingResponses, pipelined.size());
            }
            ctx.executor().execute(this);
        } else {
            ctx.read();
        }
    }

    ctx.fireUserEventTriggered(evt);
}

From source file:sailfish.remoting.handler.HeartbeatChannelHandler.java

License:Apache License

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        int maxIdleTimeout = ctx.channel().attr(ChannelAttrKeys.maxIdleTimeout).get();
        long expireTime = System.currentTimeMillis()
                - ctx.channel().attr(ChannelAttrKeys.lastReadTimeMillis).get();
        if (expireTime >= maxIdleTimeout * 1000) {
            logger.warn(//from   ww  w. j  a v a 2  s.c o  m
                    "readIdleTimeout exceed maxIdleTimeout, real timeout {}, this channel[{}] will be closed",
                    expireTime, ctx.channel().toString());
            ChannelUtil.closeChannel(ctx.channel());
        } else if (ChannelUtil.clientSide(ctx)) {
            // send heart beat to remote peer
            ctx.writeAndFlush(RequestProtocol.newHeartbeat());
        }
    } else {
        ctx.fireUserEventTriggered(evt);
    }
}

From source file:srebrinb.messagebroker.websocket.WebSocketFrameHandler.java

License:Apache License

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    super.userEventTriggered(ctx, evt);
    if (evt == WebSocketServerProtocolHandler.ServerHandshakeStateEvent.HANDSHAKE_COMPLETE) {
        String res = "channelId=\"" + ctx.channel().id().asLongText() + "\";";
        ChannelFuture f = ctx.channel().writeAndFlush(new TextWebSocketFrame(res));

        System.out.println("userEventTriggered ServerHandshakeStateEvent ");

    }/* ww w. j  a va  2  s .  c  o m*/
    ctx.fireUserEventTriggered(evt);

}

From source file:ws.wamp.jawampa.transport.netty.WampClientWebsocketHandler.java

License:Apache License

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt == WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE) {
        // Handshake is completed
        String actualProtocol = handshaker.actualSubprotocol();
        serialization = WampSerialization.fromString(actualProtocol);
        if (serialization == WampSerialization.Invalid) {
            throw new WampError("Invalid Websocket Protocol");
        }/* w  ww  .  ja va 2s.c o  m*/

        // Install the serializer and deserializer
        ctx.pipeline().addAfter(ctx.name(), "wamp-deserializer", new WampDeserializationHandler(serialization));
        ctx.pipeline().addAfter(ctx.name(), "wamp-serializer", new WampSerializationHandler(serialization));

        // Fire the connection established event
        ctx.fireUserEventTriggered(new ConnectionEstablishedEvent(serialization));

    } else {
        ctx.fireUserEventTriggered(evt);
    }
}

From source file:ws.wamp.jawampa.transport.WampClientWebsocketHandler.java

License:Apache License

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt == WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE) {
        // Handshake is completed
        String actualProtocol = handshaker.actualSubprotocol();
        if (actualProtocol.equals("wamp.2.json")) {
            serialization = Serialization.Json;
        }/*from   ww  w  . ja va 2 s  .  co  m*/
        //            else if (actualProtocol.equals("wamp.2.msgpack")) {
        //                serialization = Serialization.MessagePack;
        //            }
        else { // We don't want that protocol
            throw new WampError("Invalid Websocket Protocol");
        }

        // Install the serializer and deserializer
        ctx.pipeline().addAfter(ctx.name(), "wamp-deserializer",
                new WampDeserializationHandler(serialization, objectMapper));
        ctx.pipeline().addAfter(ctx.name(), "wamp-serializer",
                new WampSerializationHandler(serialization, objectMapper));

        // Fire the connection established event
        ctx.fireUserEventTriggered(WampChannelEvents.WEBSOCKET_CONN_ESTABLISHED);

    } else {
        ctx.fireUserEventTriggered(evt);
    }
}