KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > agent > client > tunneling > AbstractPortItem


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.agent.client.tunneling;
21
22 import com.sslexplorer.agent.client.util.TunnelConfiguration;
23
24
25 /**
26  * Encapsulate a single listener socket that can tunnel
27  * multiple connections of data in either direction.
28  * This is used in the {@link AWTPortMonitorWindow}.
29  *
30  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
31  * @see PortModel
32  * @see AWTPortMonitorWindow
33  */

34 public abstract class AbstractPortItem {
35     
36     // Private instance variables
37

38     private TunnelConfiguration listeningSocketConfiguration;
39     private RemoteTunnelChannel remoteForwardingChannel;
40     private int totalConnections, activeConnections;
41
42     /**
43      * Constructor for local tunnels
44      *
45      * @param listeningSocketConfiguration local tunnel
46      * @param localListener local tunnel listener
47      */

48     public AbstractPortItem(TunnelConfiguration listeningSocketConfiguration) {
49         super();
50         this.listeningSocketConfiguration = listeningSocketConfiguration;
51     }
52     
53     /**
54      * Get port type description.
55      *
56      * @return tunnel type
57      */

58     public String JavaDoc getType() {
59         return listeningSocketConfiguration.getType() == TunnelConfiguration.LOCAL_TUNNEL ? Messages.getString("PortItem.local") : Messages.getString("PortItem.remote"); //$NON-NLS-1$ //$NON-NLS-2$
60
}
61     
62     /**
63      * Get the tunnel configuration
64      *
65      * @return configuration
66      */

67     public TunnelConfiguration getConfiguration() {
68         return listeningSocketConfiguration;
69     }
70
71     /**
72      * Get the port name
73      *
74      * @return port name
75      */

76     public String JavaDoc getName() {
77         return listeningSocketConfiguration.getName();
78     }
79     
80     /**
81      * Get the number of active tunnels on this port.
82      *
83      * @return active tunnels on port
84      */

85     public int getActiveTunnelCount() {
86         return activeConnections;
87     }
88
89     
90     /**
91      * Get the total number of tunnels that have ever been
92      * open on this port.
93      *
94      * @return total tunnels on port
95      */

96     public int getTotalTunnelCount() {
97         return totalConnections;
98     }
99
100     /**
101      * If this is a remote port, then get the channel otherwise
102      * return <code>null</code>
103      *
104      * @return remote forwarding channel
105      */

106     public RemoteTunnelChannel getRemoteForwardingChannel() {
107         return remoteForwardingChannel;
108     }
109     
110     /**
111      * Increate the number of active connections by 1
112      */

113     public void increaseActive() {
114         activeConnections++;
115         totalConnections++;
116     }
117     
118     /**
119      * Decrease the number of active connections by 1
120      */

121     public void decreaseActive() {
122         activeConnections--;
123     }
124
125     public abstract void stop();
126
127     /**
128      * Get the local IP port numberon which the port is running.
129      *
130      * @return local port number
131      */

132     public abstract int getLocalPort();
133
134     /**
135      * Get when data was last transferred
136      *
137      * @return data last transferred
138      */

139     public abstract long getDataLastTransferred();
140 }
Popular Tags