Java Code Examples for org.jboss.netty.channel.ChannelStateEvent

The following examples show how to use org.jboss.netty.channel.ChannelStateEvent. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: onos   Source File: OspfInterfaceChannelHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent evt) {
    log.debug("OspfChannelHandler::channelDisconnected...!!!");

    for (Integer interfaceIndex : ospfInterfaceMap.keySet()) {
        OspfInterface anInterface = ospfInterfaceMap.get(interfaceIndex);
        if (anInterface != null) {
            anInterface.interfaceDown();
            anInterface.stopDelayedAckTimer();
        }
    }

    if (controller != null) {
        controller.connectPeer();
    }
}
 
Example 2
Source Project: onos   Source File: PcepChannelHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    channel = e.getChannel();
    log.info("PCC connected from {}", channel.getRemoteAddress());

    address = channel.getRemoteAddress();
    if (!(address instanceof InetSocketAddress)) {
        throw new IOException("Invalid peer connection.");
    }

    inetAddress = (InetSocketAddress) address;
    peerAddr = IpAddress.valueOf(inetAddress.getAddress()).toString();

    // Wait for open message from pcc client
    setState(ChannelState.OPENWAIT);
    controller.peerStatus(peerAddr, PcepCfg.State.OPENWAIT.toString(), sessionId);
}
 
Example 3
Source Project: onos   Source File: FpmSessionHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
        throws Exception {
    SocketAddress socketAddress = ctx.getChannel().getRemoteAddress();

    if (!(socketAddress instanceof InetSocketAddress)) {
        throw new IllegalStateException("Address type is not InetSocketAddress");
    }

    us = FpmPeer.fromSocketAddress((InetSocketAddress) socketAddress);

    if (!fpmListener.peerConnected(us)) {
        log.error("Received new FPM connection while already connected");
        ctx.getChannel().close();
        return;
    }

    channel = ctx.getChannel();
    fpmManager.addSessionChannel(e.getChannel());
    fpmManager.processStaticRoutes(e.getChannel());
}
 
Example 4
Source Project: canal   Source File: HandshakeInitializationHandler.java    License: Apache License 2.0 6 votes vote down vote up
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    // add new socket channel in channel container, used to manage sockets.
    if (childGroups != null) {
        childGroups.add(ctx.getChannel());
    }

    final byte[] seed = org.apache.commons.lang3.RandomUtils.nextBytes(8);
    byte[] body = Packet.newBuilder()
        .setType(CanalPacket.PacketType.HANDSHAKE)
        .setVersion(NettyUtils.VERSION)
        .setBody(Handshake.newBuilder().setSeeds(ByteString.copyFrom(seed)).build().toByteString())
        .build()
        .toByteArray();

    NettyUtils.write(ctx.getChannel(), body, new ChannelFutureListener() {

        public void operationComplete(ChannelFuture future) throws Exception {
            ctx.getPipeline().get(HandshakeInitializationHandler.class.getName());
            ClientAuthenticationHandler handler = (ClientAuthenticationHandler) ctx.getPipeline()
                .get(ClientAuthenticationHandler.class.getName());
            handler.setSeed(seed);
        }

    });
    logger.info("send handshake initialization packet to : {}", ctx.getChannel());
}
 
Example 5
Source Project: dubbo-2.6.5   Source File: NettyHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler);
    try {
        channels.remove(NetUtils.toAddressString((InetSocketAddress) ctx.getChannel().getRemoteAddress()));
        handler.disconnected(channel);
    } finally {
        NettyChannel.removeChannelIfDisconnected(ctx.getChannel());
    }
}
 
Example 6
Source Project: james-project   Source File: ChannelGroupHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    // Add all open channels to the global group so that they are
    // closed on shutdown.
    channels.add(e.getChannel());
    
    // call the next handler in the chain
    super.channelOpen(ctx, e);
}
 
Example 7
Source Project: pinpoint   Source File: PinpointServerAcceptor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    final Channel channel = e.getChannel();

    channelGroup.remove(channel);

    super.channelClosed(ctx, e);
}
 
Example 8
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    // add new socket channel in channel container, used to manage sockets.
    if (childGroups != null) {
        childGroups.add(ctx.getChannel());
    }

    byte[] body = Packet.newBuilder()
        .setType(CanalPacket.PacketType.HANDSHAKE)
        .setBody(Handshake.newBuilder().build().toByteString())
        .build()
        .toByteArray();
    NettyUtils.write(ctx.getChannel(), body, null);
    logger.info("send handshake initialization packet to : {}", ctx.getChannel());
}
 
Example 9
Source Project: pinpoint   Source File: PinpointServerAcceptor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    final Channel channel = e.getChannel();

    DefaultPinpointServer pinpointServer = (DefaultPinpointServer) channel.getAttachment();
    if (pinpointServer != null) {
        pinpointServer.stop(released);
    }

    super.channelDisconnected(ctx, e);
}
 
Example 10
@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    super.channelConnected(ctx, e);

    state = State.CONNECTED;
    inetAddress = ((InetSocketAddress) e.getChannel().getRemoteAddress()).getAddress();
    channel = ctx.getChannel();
    log.info("Channel connected Ip:" + inetAddress.getHostAddress());
}
 
Example 11
Source Project: jstorm   Source File: StormClientHandler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @see org.jboss.netty.channel.SimpleChannelUpstreamHandler#channelDisconnected(org.jboss.netty.channel.ChannelHandlerContext,
 * org.jboss.netty.channel.ChannelStateEvent)
 */
@Override
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    LOG.info("Receive channelDisconnected to {}, channel = {}", client.getRemoteAddr(), e.getChannel());
    // ctx.sendUpstream(e);
    super.channelDisconnected(ctx, e);

    client.disconnectChannel(e.getChannel());
}
 
Example 12
Source Project: voyage   Source File: NettyRpcServerHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
		throws Exception {
	if (null != channelGroups) {
		channelGroups.add(e.getChannel());
	}
}
 
Example 13
Source Project: dubbox   Source File: NettyHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler);
    try {
        if (channel != null) {
            channels.put(NetUtils.toAddressString((InetSocketAddress) ctx.getChannel().getRemoteAddress()), channel);
        }
        handler.connected(channel);
    } finally {
        NettyChannel.removeChannelIfDisconnected(ctx.getChannel());
    }
}
 
Example 14
Source Project: dubbox   Source File: NettyHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler);
    try {
        channels.remove(NetUtils.toAddressString((InetSocketAddress) ctx.getChannel().getRemoteAddress()));
        handler.disconnected(channel);
    } finally {
        NettyChannel.removeChannelIfDisconnected(ctx.getChannel());
    }
}
 
Example 15
Source Project: jstorm   Source File: StormClientHandler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sometime when connecting to a bad channel which isn't writable, this method will be called
 */
@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent event) {
    // register the newly established channel
    Channel channel = event.getChannel();
    LOG.info("connection established to :{}, local port:{}", client.getRemoteAddr(), channel.getLocalAddress());

    client.connectChannel(ctx.getChannel());
    client.handleResponse(ctx.getChannel(), null);
}
 
Example 16
Source Project: dubbox-hystrix   Source File: NettyHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler);
    try {
        if (channel != null) {
            channels.put(NetUtils.toAddressString((InetSocketAddress) ctx.getChannel().getRemoteAddress()), channel);
        }
        handler.connected(channel);
    } finally {
        NettyChannel.removeChannelIfDisconnected(ctx.getChannel());
    }
}
 
Example 17
Source Project: hadoop   Source File: SimpleTcpClientHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
  // Send the request
  if (LOG.isDebugEnabled()) {
    LOG.debug("sending PRC request");
  }
  ChannelBuffer outBuf = XDR.writeMessageTcp(request, true);
  e.getChannel().write(outBuf);
}
 
Example 18
Source Project: james-project   Source File: BasicChannelUpstreamHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelBound(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    try (Closeable closeable = mdcContextFactory.from(protocol, ctx)) {
        ctx.setAttachment(createSession(ctx));
        super.channelBound(ctx, e);
    }
}
 
Example 19
Source Project: tez   Source File: ShuffleHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent evt) 
    throws Exception {
  if ((maxShuffleConnections > 0) && (accepted.size() >= maxShuffleConnections)) {
    LOG.info(String.format("Current number of shuffle connections (%d) is " + 
        "greater than or equal to the max allowed shuffle connections (%d)", 
        accepted.size(), maxShuffleConnections));
    evt.getChannel().close();
    return;
  }
  accepted.add(evt.getChannel());
  super.channelOpen(ctx, evt);
 
}
 
Example 20
Source Project: pinpoint   Source File: DefaultPinpointClientHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelClosed(final ChannelHandlerContext ctx, final ChannelStateEvent e) throws Exception {
    logger.info("{} channelClosed() started.", objectUniqName);

    try {
        boolean factoryReleased = connectionFactory.isClosed();

        boolean needReconnect = false;
        SocketStateCode currentStateCode = state.getCurrentStateCode();
        if (currentStateCode == SocketStateCode.BEING_CLOSE_BY_CLIENT) {
            state.toClosed();
        } else if (currentStateCode == SocketStateCode.BEING_CLOSE_BY_SERVER) {
            needReconnect = state.toClosedByPeer().isChange();
        } else if (currentStateCode.isRun() && factoryReleased) {
            state.toUnexpectedClosed();
        } else if (currentStateCode.isRun()) {
            needReconnect = state.toUnexpectedClosedByPeer().isChange();
        } else if (currentStateCode.isBeforeConnected()) {
            state.toConnectFailed();
        } else {
            state.toErrorUnknown();
        }

        if (needReconnect) {
            reconnect();
        }
    } finally {
        closeResources();
        connectFuture.setResult(Result.FAIL);
    }
}
 
Example 21
Source Project: phoenix-omid   Source File: TSOClientRaw.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e)
        throws Exception {
    LOG.info("Disconnected");
    try {
        SettableFuture<Response> future = responseQueue.take();
        future.setException(new ConnectionException());
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
        LOG.warn("Interrupted handling exception", ie);
    }
}
 
Example 22
@Override
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e)
        throws Exception {
    if (timeout != null) {
        timeout.cancel();
        timeout = null;
    }
}
 
Example 23
Source Project: onos   Source File: PcepChannelHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    log.info("Pcc disconnected callback for pc:{}. Cleaning up ...", getClientInfoString());
    controller.peerStatus(peerAddr, PcepCfg.State.DOWN.toString(), sessionId);

    channel = e.getChannel();
    address = channel.getRemoteAddress();
    if (!(address instanceof InetSocketAddress)) {
        throw new IOException("Invalid peer connection.");
    }

    inetAddress = (InetSocketAddress) address;
    peerAddr = IpAddress.valueOf(inetAddress.getAddress()).toString();

    if (thispccId != null) {
        if (!duplicatePccIdFound) {
            // if the disconnected client (on this ChannelHandler)
            // was not one with a duplicate-dpid, it is safe to remove all
            // state for it at the controller. Notice that if the disconnected
            // client was a duplicate-ip, calling the method below would clear
            // all state for the original client (with the same ip),
            // which we obviously don't want.
            log.debug("{}:removal called", getClientInfoString());
            if (pc != null) {
                pc.removeConnectedClient();
            }
        } else {
            // A duplicate was disconnected on this ChannelHandler,
            // this is the same client reconnecting, but the original state was
            // not cleaned up - XXX check liveness of original ChannelHandler
            log.debug("{}:duplicate found", getClientInfoString());
            duplicatePccIdFound = Boolean.FALSE;
        }
    } else {
        log.warn("no pccip in channelHandler registered for " + "disconnected client {}", getClientInfoString());
    }
}
 
Example 24
Source Project: whiteboard   Source File: MyServerHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelDisconnected(ChannelHandlerContext ctx,
		ChannelStateEvent e) throws Exception {
	// String hostAddress = ((InetSocketAddress) e.getChannel()
	// .getRemoteAddress()).getAddress().getHostAddress();
	// MetadataRepositories.getInstance().getChannels().remove(hostAddress);

	// System.out.println("�ͻ�: " + hostAddress + " �˳���");
}
 
Example 25
Source Project: big-c   Source File: ShuffleHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent evt) 
    throws Exception {
  if ((maxShuffleConnections > 0) && (accepted.size() >= maxShuffleConnections)) {
    LOG.info(String.format("Current number of shuffle connections (%d) is " + 
        "greater than or equal to the max allowed shuffle connections (%d)", 
        accepted.size(), maxShuffleConnections));
    evt.getChannel().close();
    return;
  }
  accepted.add(evt.getChannel());
  super.channelOpen(ctx, evt);
 
}
 
Example 26
Source Project: big-c   Source File: SimpleTcpClientHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
  // Send the request
  if (LOG.isDebugEnabled()) {
    LOG.debug("sending PRC request");
  }
  ChannelBuffer outBuf = XDR.writeMessageTcp(request, true);
  e.getChannel().write(outBuf);
}
 
Example 27
Source Project: tez   Source File: ShuffleHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent evt)
    throws Exception {

  if ((maxShuffleConnections > 0) && (accepted.size() >= maxShuffleConnections)) {
    LOG.info(String.format("Current number of shuffle connections (%d) is " +
        "greater than or equal to the max allowed shuffle connections (%d)",
        accepted.size(), maxShuffleConnections));
    evt.getChannel().close();
    return;
  }
  accepted.add(evt.getChannel());
  super.channelOpen(ctx, evt);
}
 
Example 28
Source Project: dubbo3   Source File: NettyHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler);
    try {
        channels.remove(NetUtils.toAddressString((InetSocketAddress) ctx.getChannel().getRemoteAddress()));
        handler.disconnected(channel);
    } finally {
        NettyChannel.removeChannelIfDisconnected(ctx.getChannel());
    }
}
 
Example 29
Source Project: usergrid   Source File: MongoProxyInboundHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelOpen( ChannelHandlerContext ctx, ChannelStateEvent e ) throws Exception {
    // Suspend incoming traffic until connected to the remote host.
    final Channel inboundChannel = e.getChannel();
    inboundChannel.setReadable( false );

    // Start the connection attempt.
    ClientBootstrap cb = new ClientBootstrap( cf );
    cb.setOption( "bufferFactory", HeapChannelBufferFactory.getInstance( ByteOrder.LITTLE_ENDIAN ) );
    cb.getPipeline().addLast( "framer", new MongoMessageFrame() );
    cb.getPipeline().addLast( "handler", new OutboundHandler( e.getChannel() ) );
    ChannelFuture f = cb.connect( new InetSocketAddress( remoteHost, remotePort ) );

    outboundChannel = f.getChannel();
    f.addListener( new ChannelFutureListener() {
        @Override
        public void operationComplete( ChannelFuture future ) throws Exception {
            if ( future.isSuccess() ) {
                // Connection attempt succeeded:
                // Begin to accept incoming traffic.
                inboundChannel.setReadable( true );
            }
            else {
                // Close the connection if the connection attempt has
                // failed.
                inboundChannel.close();
            }
        }
    } );
}
 
Example 30
Source Project: Android-Airplay-Server   Source File: RaopAudioHandler.java    License: MIT License 5 votes vote down vote up
@Override
public void channelClosed(final ChannelHandlerContext ctx, final ChannelStateEvent evt)
	throws Exception {
	LOG.info("RTSP connection was shut down, closing RTP channels and audio output queue");

	synchronized(this) {
		reset();
	}

	super.channelClosed(ctx, evt);
}