All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opendaylight.jsonrpc.bus.spi.ChannelGroupHandler Maven / Gradle / Ivy

/*
 * Copyright (c) 2018 Lumina Networks, Inc. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.jsonrpc.bus.spi;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.group.ChannelGroup;
import java.util.Objects;

/**
 * Client connection tracker. Allows bulk operation on child channels like
 * broadcasting or channel closing.
 *
 * @author Richard Kosegi
 * @since Mar 6, 2018
 */
public class ChannelGroupHandler extends ChannelInboundHandlerAdapter {
    private final ChannelGroup channelGroup;

    public ChannelGroupHandler(final ChannelGroup channelGroup) {
        this.channelGroup = Objects.requireNonNull(channelGroup);
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        channelGroup.add(ctx.channel());
        super.channelActive(ctx);
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        channelGroup.remove(ctx.channel());
        super.channelInactive(ctx);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy