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.networkhandler; 22 23 import java.util.HashSet; 24 25 /** 26 * Client NetworkChannel attached to one HostId. 27 * 28 * 29 * 30 * This class is used to keep information for one HostID when it connects as client 31 * to the current Host. As one Id can be shared or one can use direct send, so having 32 * a connection by request, this class is useful when one wants to know who is connected 33 * and how many times. 34 * 35 * 36 * @author Frederic Bregier 37 * 38 */ 39 public class ClientNetworkChannels { 40 41 private final String hostId; 42 private final HashSet<NetworkChannel> networkChannels = new HashSet<NetworkChannel>(); 43 44 public ClientNetworkChannels(String hostId) { 45 this.hostId = hostId; 46 } 47 48 public void add(NetworkChannel networkChannel) { 49 networkChannels.add(networkChannel); 50 } 51 52 public void remove(NetworkChannel networkChannel) { 53 networkChannels.remove(networkChannel); 54 } 55 56 public boolean isEmpty() { 57 return networkChannels.isEmpty(); 58 } 59 60 public int size() { 61 return networkChannels.size(); 62 } 63 64 public boolean shutdownAll() { 65 boolean status = false; 66 for (NetworkChannel networkChannel : networkChannels) { 67 NetworkTransaction.shuttingdownNetworkChannel(networkChannel.channel); 68 status = true; 69 } 70 networkChannels.clear(); 71 return status; 72 } 73 74 public String getHostId() { 75 return hostId; 76 } 77 }