Example usage for io.netty.channel.group ChannelGroupFuture group

List of usage examples for io.netty.channel.group ChannelGroupFuture group

Introduction

In this page you can find the example usage for io.netty.channel.group ChannelGroupFuture group.

Prototype

ChannelGroup group();

Source Link

Document

Returns the ChannelGroup which is associated with this future.

Usage

From source file:org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor.java

License:Apache License

public synchronized void stop() {
    if (channelClazz == null) {
        return;/*from   w w  w.  j a  v a2  s.co  m*/
    }

    if (protocolHandler != null) {
        protocolHandler.close();
    }

    if (batchFlusherFuture != null) {
        batchFlusherFuture.cancel(false);

        flusher.cancel();

        flusher = null;

        batchFlusherFuture = null;
    }

    // serverChannelGroup has been unbound in pause()
    if (serverChannelGroup != null) {
        serverChannelGroup.close().awaitUninterruptibly();
    }

    if (channelGroup != null) {
        ChannelGroupFuture future = channelGroup.close().awaitUninterruptibly();

        if (!future.isSuccess()) {
            ActiveMQServerLogger.LOGGER.nettyChannelGroupError();
            Iterator<Channel> iterator = future.group().iterator();
            while (iterator.hasNext()) {
                Channel channel = iterator.next();
                if (channel.isActive()) {
                    ActiveMQServerLogger.LOGGER.nettyChannelStillOpen(channel, channel.remoteAddress());
                }
            }
        }
    }

    // Shutdown the EventLoopGroup if no new task was added for 100ms or if
    // 3000ms elapsed.
    eventLoopGroup.shutdownGracefully(100, 3000, TimeUnit.MILLISECONDS);
    eventLoopGroup = null;

    channelClazz = null;

    for (Connection connection : connections.values()) {
        listener.connectionDestroyed(connection.getID());
    }

    connections.clear();

    if (notificationService != null) {
        TypedProperties props = new TypedProperties();
        props.putSimpleStringProperty(new SimpleString("factory"),
                new SimpleString(NettyAcceptorFactory.class.getName()));
        props.putSimpleStringProperty(new SimpleString("host"), new SimpleString(host));
        props.putIntProperty(new SimpleString("port"), port);
        Notification notification = new Notification(null, CoreNotificationType.ACCEPTOR_STOPPED, props);
        try {
            notificationService.sendNotification(notification);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    paused = false;
}

From source file:org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor.java

License:Apache License

public synchronized void pause() {
    if (paused) {
        return;/*w w w . ja  va 2s . co m*/
    }

    if (channelClazz == null) {
        return;
    }

    // We *pause* the acceptor so no new connections are made
    if (serverChannelGroup != null) {
        ChannelGroupFuture future = serverChannelGroup.close().awaitUninterruptibly();
        if (!future.isSuccess()) {
            ActiveMQServerLogger.LOGGER.nettyChannelGroupBindError();
            Iterator<Channel> iterator = future.group().iterator();
            while (iterator.hasNext()) {
                Channel channel = iterator.next();
                if (channel.isActive()) {
                    ActiveMQServerLogger.LOGGER.nettyChannelStillBound(channel, channel.remoteAddress());
                }
            }
        }
    }
    paused = true;
}

From source file:org.apache.activemq.core.remoting.impl.netty.NettyAcceptor.java

License:Apache License

public synchronized void stop() {
    if (channelClazz == null) {
        return;//from w w  w .j  a v  a  2s. c  o  m
    }

    if (protocolHandler != null) {
        protocolHandler.close();
    }

    if (batchFlusherFuture != null) {
        batchFlusherFuture.cancel(false);

        flusher.cancel();

        flusher = null;

        batchFlusherFuture = null;
    }

    // serverChannelGroup has been unbound in pause()
    serverChannelGroup.close().awaitUninterruptibly();
    ChannelGroupFuture future = channelGroup.close().awaitUninterruptibly();

    if (!future.isSuccess()) {
        ActiveMQServerLogger.LOGGER.nettyChannelGroupError();
        Iterator<Channel> iterator = future.group().iterator();
        while (iterator.hasNext()) {
            Channel channel = iterator.next();
            if (channel.isActive()) {
                ActiveMQServerLogger.LOGGER.nettyChannelStillOpen(channel, channel.remoteAddress());
            }
        }
    }

    // Shutdown the EventLoopGroup if no new task was added for 100ms or if
    // 3000ms elapsed.
    eventLoopGroup.shutdownGracefully(100, 3000, TimeUnit.MILLISECONDS);
    eventLoopGroup = null;

    channelClazz = null;

    for (Connection connection : connections.values()) {
        listener.connectionDestroyed(connection.getID());
    }

    connections.clear();

    if (notificationService != null) {
        TypedProperties props = new TypedProperties();
        props.putSimpleStringProperty(new SimpleString("factory"),
                new SimpleString(NettyAcceptorFactory.class.getName()));
        props.putSimpleStringProperty(new SimpleString("host"), new SimpleString(host));
        props.putIntProperty(new SimpleString("port"), port);
        Notification notification = new Notification(null, CoreNotificationType.ACCEPTOR_STOPPED, props);
        try {
            notificationService.sendNotification(notification);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    paused = false;
}

From source file:org.apache.activemq.core.remoting.impl.netty.NettyAcceptor.java

License:Apache License

public synchronized void pause() {
    if (paused) {
        return;// w ww  .  j  a v a 2s  .c  om
    }

    if (channelClazz == null) {
        return;
    }

    // We *pause* the acceptor so no new connections are made
    ChannelGroupFuture future = serverChannelGroup.close().awaitUninterruptibly();
    if (!future.isSuccess()) {
        ActiveMQServerLogger.LOGGER.nettyChannelGroupBindError();
        Iterator<Channel> iterator = future.group().iterator();
        while (iterator.hasNext()) {
            Channel channel = iterator.next();
            if (channel.isActive()) {
                ActiveMQServerLogger.LOGGER.nettyChannelStillBound(channel, channel.remoteAddress());
            }
        }
    }
    paused = true;
}

From source file:org.hornetq.core.remoting.impl.netty.NettyAcceptor.java

License:Apache License

public synchronized void stop() {
    if (channelClazz == null) {
        return;//from w  ww . j  a va2  s  . c  o  m
    }

    if (protocolHandler != null) {
        protocolHandler.close();
    }

    if (batchFlusherFuture != null) {
        batchFlusherFuture.cancel(false);

        flusher.cancel();

        flusher = null;

        batchFlusherFuture = null;
    }

    // serverChannelGroup has been unbound in pause()
    serverChannelGroup.close().awaitUninterruptibly();
    ChannelGroupFuture future = channelGroup.close().awaitUninterruptibly();

    if (!future.isSuccess()) {
        HornetQServerLogger.LOGGER.nettyChannelGroupError();
        Iterator<Channel> iterator = future.group().iterator();
        while (iterator.hasNext()) {
            Channel channel = iterator.next();
            if (channel.isActive()) {
                HornetQServerLogger.LOGGER.nettyChannelStillOpen(channel, channel.remoteAddress());
            }
        }
    }

    // Shutdown the EventLoopGroup if no new task was added for 100ms or if
    // 3000ms elapsed.
    eventLoopGroup.shutdownGracefully(100, 3000, TimeUnit.MILLISECONDS);
    eventLoopGroup = null;

    channelClazz = null;

    for (Connection connection : connections.values()) {
        listener.connectionDestroyed(connection.getID());
    }

    connections.clear();

    if (notificationService != null) {
        TypedProperties props = new TypedProperties();
        props.putSimpleStringProperty(new SimpleString("factory"),
                new SimpleString(NettyAcceptorFactory.class.getName()));
        props.putSimpleStringProperty(new SimpleString("host"), new SimpleString(host));
        props.putIntProperty(new SimpleString("port"), port);
        Notification notification = new Notification(null, CoreNotificationType.ACCEPTOR_STOPPED, props);
        try {
            notificationService.sendNotification(notification);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    paused = false;
}

From source file:org.hornetq.core.remoting.impl.netty.NettyAcceptor.java

License:Apache License

public synchronized void pause() {
    if (paused) {
        return;// ww  w  .ja  v  a2  s  .  co  m
    }

    if (channelClazz == null) {
        return;
    }

    // We *pause* the acceptor so no new connections are made
    ChannelGroupFuture future = serverChannelGroup.close().awaitUninterruptibly();
    if (!future.isSuccess()) {
        HornetQServerLogger.LOGGER.nettyChannelGroupBindError();
        Iterator<Channel> iterator = future.group().iterator();
        while (iterator.hasNext()) {
            Channel channel = iterator.next();
            if (channel.isActive()) {
                HornetQServerLogger.LOGGER.nettyChannelStillBound(channel, channel.remoteAddress());
            }
        }
    }
    paused = true;
}