KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.text.MessageFormat JavaDoc;
23
24 import com.maverick.multiplex.Channel;
25 import com.maverick.multiplex.ChannelListener;
26 import com.sslexplorer.agent.client.Agent;
27 import com.sslexplorer.agent.client.PortMonitor;
28
29 public class RemoteTunnelChannelListener implements ChannelListener {
30
31     private Agent agent;
32     private PortMonitor portMonitor;
33
34     public RemoteTunnelChannelListener(Agent agent) {
35         this.agent = agent;
36         portMonitor = this.agent.getGUI().getPortMonitor();
37     }
38
39     public void onChannelClose(Channel channel) {
40         RemoteTunnelChannel rfc = (RemoteTunnelChannel) channel;
41         if(agent.getConfiguration().isDisplayInformationPopups()) {
42             agent.getGUI()
43                             .popup(null,
44                                 MessageFormat.format(Messages.getString("RemoteForwardingChannelListener.closingRemoteTunnel"), new Object JavaDoc[] { rfc.getConfiguration().getName(),//$NON-NLS-1$
45
String.valueOf(rfc.getConfiguration().getSourcePort()),
46                                         rfc.getConfiguration().getDestinationHost() + ":" + rfc.getConfiguration().getDestinationPort() }), //$NON-NLS-1$
47
Messages.getString("Agent.title"), //$NON-NLS-1$
48
"popup-tunnel", -1); //$NON-NLS-1$PortMonitor pm = WebForwardManager.getPortMonitor();
49
}
50         synchronized (portMonitor) {
51             int idx = portMonitor.getIndexForId(rfc.getConfiguration().getId());
52             AbstractPortItem portItem = idx == -1 ? null : portMonitor.getItemAt(idx);
53             if (portItem != null) {
54                 portItem.decreaseActive();
55                 portMonitor.updateItemAt(idx);
56             }
57         }
58     }
59
60     public void onChannelData(Channel channel, byte[] buf, int off, int len) {
61         RemoteTunnelChannel rfc = (RemoteTunnelChannel) channel;
62         synchronized (portMonitor) {
63             int idx = portMonitor.getIndexForId(rfc.getConfiguration().getId());
64             if (idx != -1) {
65                 portMonitor.updateItemAt(idx);
66             }
67         }
68     }
69
70     public void onChannelOpen(Channel channel) {
71         final RemoteTunnelChannel rfc = (RemoteTunnelChannel) channel;
72         if(agent.getConfiguration().isDisplayInformationPopups()) {
73             agent.getGUI()
74                             .popup(null,
75                                 MessageFormat.format(Messages.getString("RemoteForwardingChannelListener.openedRemoteTunnel"), new Object JavaDoc[] { rfc.getConfiguration().getName(), String.valueOf(rfc.getConfiguration().getSourcePort()), //$NON-NLS-1$$
76
rfc.getConfiguration().getDestinationHost() + ":" + rfc.getConfiguration().getDestinationPort() }), //$NON-NLS-1$$
77
Messages.getString("Agent.title"), //$NON-NLS-1$
78
"popup-tunnel", -1); //$NON-NLS-1$
79
}
80         
81         synchronized (portMonitor) {
82             int idx = portMonitor.getIndexForId(rfc.getConfiguration().getId());
83             RemotePortItem portItem = idx == -1 ? null : (RemotePortItem)portMonitor.getItemAt(idx);
84             if (portItem == null) {
85                 portItem = new RemotePortItem(rfc.getConfiguration());
86                 portItem.addChannel(rfc);
87                 portMonitor.addPortItem(portItem);
88             } else {
89                 portItem.addChannel(rfc);
90                 portMonitor.updateItemAt(idx);
91             }
92         }
93     }
94
95 }
96
Popular Tags