Java tutorial
package com.cloudhopper.smpp.channel; /* * #%L * ch-smpp * %% * Copyright (C) 2009 - 2012 Cloudhopper by Twitter * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.group.ChannelGroup; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static io.netty.channel.ChannelHandler.Sharable; /** * The default handler used just during a "connect" for a Channel when attempting * to bind into an SMSC. The reason is that some handler must be added to create * a channel and then replaced before the actual "bind" is attempted. This * handler basically does nothing. Until a "bind" request is received by the SMSC, * nothing should actually be received so its safe to have a handler that does * nothing. * * @author joelauer (twitter: @jjlauer or <a href="http://twitter.com/jjlauer" target=window>http://twitter.com/jjlauer</a>) */ @Sharable public class SmppClientConnector extends ChannelInboundHandlerAdapter { private static final Logger logger = LoggerFactory.getLogger(SmppClientConnector.class); private ChannelGroup channels; public SmppClientConnector(ChannelGroup channels) { this.channels = channels; } @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { // called every time a new channel connects channels.add(ctx.channel()); super.channelActive(ctx); } @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { // called every time a channel disconnects channels.remove(ctx.channel()); super.channelInactive(ctx); } }