public void getResources(int resourceType, String menu) { try { ByteArrayWriter baw = new ByteArrayWriter(); baw.writeInt(resourceType); Request request = new Request("getResources", baw.toByteArray()); if (agent.getConnection().sendRequest(request, true)) { if (request.getRequestData() != null) { ByteArrayReader reader = new ByteArrayReader(request.getRequestData()); int count = (int) reader.readInt(); if (count > 0) { if (agent.getGUI().isMenuExists(menu)) agent.getGUI().clearMenu(menu); else agent.getGUI().addMenu(menu); for (int i = 0; i < count; i++) { int resourceId = (int) reader.readInt(); agent .getGUI() .addMenuItem(menu, new ResourceLaunchAction(resourceId, reader.readString())); } } else { if (agent.getGUI().isMenuExists(menu)) agent.getGUI().removeMenu(menu); } } } } catch (IOException e) { // #ifdef DEBUG log.error("Failed to get resources.", e); // #endif } }
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; } }