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 com.cloudhopper.smpp.impl.SmppSessionChannelListener; import com.cloudhopper.smpp.pdu.Pdu; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static io.netty.channel.ChannelHandler.Sharable; /** * * @author joelauer (twitter: @jjlauer or <a href="http://twitter.com/jjlauer" target=window>http://twitter.com/jjlauer</a>) */ @Sharable public class SmppSessionWrapper extends SimpleChannelInboundHandler<Pdu> { private static final Logger logger = LoggerFactory.getLogger(SmppSessionWrapper.class); private SmppSessionChannelListener listener; public SmppSessionWrapper(SmppSessionChannelListener listener) { this.listener = listener; } @Override protected void channelRead0(ChannelHandlerContext ctx, Pdu msg) throws Exception { this.listener.firePduReceived(msg); } /** * Invoked when a Channel was closed and all its related resources were released. */ @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { this.listener.fireChannelClosed(); super.channelInactive(ctx); } /** * Invoked when an exception was raised by an I/O thread or an upstream handler. */ @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { this.listener.fireExceptionThrown(cause.getCause()); } }