void stopRemoteTunnels(MultiplexedConnection agent, Collection<Tunnel> tunnels) throws CoreException { CoreException e = null; for (Tunnel tunnel : tunnels) { try { RemoteTunnel rt = RemoteTunnelManagerFactory.getInstance().getRemoteTunnel(tunnel.getResourceId()); if (rt != null) { rt.stopListener(); } else { throw new Exception("No active with ID for " + tunnel.getResourceId()); } } catch (Exception ex) { throw new TunnelException(TunnelException.INTERNAL_ERROR, ex); } } if (e != null) { throw e; } }
Request buildLocalTunnel(Tunnel tunnel, LaunchSession launchSession) throws IOException { // Process destination host and port for replacement variables VariableReplacement r = new VariableReplacement(); r.setLaunchSession(launchSession); String destHost = r.replace(tunnel.getDestination().getHost()); ByteArrayWriter msg = new ByteArrayWriter(); msg.writeString(launchSession == null ? "" : launchSession.getId()); msg.writeInt(tunnel.getResourceId()); msg.writeString(tunnel.getResourceName()); msg.writeInt(tunnel.getType()); msg.writeString(tunnel.getTransport()); msg.writeString(tunnel.getSourceInterface()); msg.writeInt(tunnel.getSourcePort()); msg.writeInt(tunnel.getDestination().getPort()); msg.writeString(destHost); Request req = new Request(START_LOCAL_TUNNEL, msg.toByteArray()); return req; }
void stopLocalTunnels(MultiplexedConnection agent, Collection<Tunnel> tunnels) throws CoreException { CoreException e = null; for (Tunnel tunnel : tunnels) { try { ByteArrayWriter msg = new ByteArrayWriter(); msg.writeInt(tunnel.getResourceId()); if (!agent.sendRequest(new Request(STOP_LOCAL_TUNNEL, msg.toByteArray()), false) && e == null) { e = new TunnelException( TunnelException.AGENT_REFUSED_LOCAL_TUNNEL_STOP, (Throwable) null); } } catch (IOException ex) { throw new TunnelException(TunnelException.INTERNAL_ERROR, ex); } } if (e != null) { throw e; } }