1 /** 2 This file is part of GoldenGate Project (named also GoldenGate or GG). 3 4 Copyright 2009, Frederic Bregier, and individual contributors by the @author 5 tags. See the COPYRIGHT.txt in the distribution for a full listing of 6 individual contributors. 7 8 All GoldenGate Project is free software: you can redistribute it and/or 9 modify it under the terms of the GNU General Public License as published 10 by the Free Software Foundation, either version 3 of the License, or 11 (at your option) any later version. 12 13 GoldenGate is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with GoldenGate . If not, see <http://www.gnu.org/licenses/>. 20 */ 21 package openr66.protocol.utils; 22 23 import java.util.concurrent.TimeUnit; 24 25 import openr66.protocol.configuration.Configuration; 26 27 import org.jboss.netty.channel.Channel; 28 import org.jboss.netty.channel.Channels; 29 import org.jboss.netty.util.Timeout; 30 import org.jboss.netty.util.TimerTask; 31 32 /** 33 * TimerTask to Close a Channel in the future 34 * @author Frederic Bregier 35 * 36 */ 37 public class ChannelCloseTimer implements TimerTask { 38 39 private Channel channel; 40 41 public ChannelCloseTimer(Channel channel) { 42 this.channel = channel; 43 } 44 45 @Override 46 public void run(Timeout timeout) throws Exception { 47 Channels.close(channel); 48 } 49 50 /** 51 * Close in the future this channel 52 * @param channel 53 */ 54 public static void closeFutureChannel(Channel channel) { 55 Configuration.configuration.getTimerClose().newTimeout( 56 new ChannelCloseTimer(channel), 57 Configuration.WAITFORNETOP, TimeUnit.MILLISECONDS); 58 } 59 }