Handle the command send from my client peer.
@param in The (optional) Inputstream to get the params from.
@param out The stream to write the results.
357950
public void doProcess(InputStream in, PrintWriter out, Map<String, Object> properties)
        throws RemoteException
    {
        String strCommand = this.getProperty(REMOTE_COMMAND, properties);
        if (GET_REMOTE_TABLE.equals(strCommand))
        {
            String strName = this.getNextStringParam(in, NAME, properties);
            RemoteTable remoteTable = ((RemoteSession)m_remoteObject).getRemoteTable(strName);
            // First, see if this is in my list already?
            String strID = this.find(remoteTable);
            if (strID == null)
                strID = this.add(new TableHolder(this, remoteTable));
            this.setReturnString(out, strID);
        }
        else if (SETUP_REMOTE_SESSION_FILTER.equals(strCommand))
        {
            org.jbundle.thin.base.message.BaseMessageFilter filter = (org.jbundle.thin.base.message.BaseMessageFilter)this.getNextObjectParam(in, FILTER, properties);
            filter = ((RemoteSession)m_remoteObject).setupRemoteSessionFilter(filter);
            this.setReturnObject(out, filter);
        }
        else
            super.doProcess(in, out, properties);
    }
1250127
static void crossStreams(final InputStream in, final OutputStream out) throws IOException {
        final byte[] buffer = new byte[bufferSize];
        int len;
        while ((len = in.read(buffer)) != -1) {
            out.write(buffer, 0, len);
        }
    }
309372
static void write(Command cmd, OutputStream out) throws UnsupportedEncodingException, IOException {
        encode(cmd.getCommand(), out);
        for (Parameter param : cmd.getParameters()) {
            encode(String.format("=%s=%s", param.getName(), param.hasValue() ? param.getValue() : ""), out);
        }
        String tag = cmd.getTag();
        if ((tag != null) && !tag.equals("")) {
            encode(String.format(".tag=%s", tag), out);
        }
        List<String> props = cmd.getProperties();
        if (!props.isEmpty()) {
            StringBuilder buf = new StringBuilder("=.proplist=");
            for (int i = 0; i < props.size(); ++i) {
                if (i > 0) {
                    buf.append(",");
                }
                buf.append(props.get(i));
            }
            encode(buf.toString(), out);
        }
        for (String query : cmd.getQueries()) {
            encode(query, out);
        }
        out.write(0);
    }
591192
@Override
    public void handle(CommandContext ctx, String commandLine) {
        String[] commands = commandLine.split(" ");
        if (commands.length != 1) {
            ctx.printLine("Invalid command.");
            return;
        }

        ctx.terminateSession();
    }
630750
public static void copyThread(InputStream in, OutputStream out)
    {
        try{
            instance().run(new Job(in,out));
        }
        catch(InterruptedException e)
        {
            log.warn(LogSupport.EXCEPTION,e);
        }
    }
95924
@Override
  public void dispatch()
  {
    Result<InputStreamClient> result = _result;
    
    if (result != null) {
      result.ok(_is);
    }
  }
639399
public void send(final Command msg) throws HandlerSocketException {
		Session session = this.selectSession();
		session.write(msg);
	}
762388
@Override
	public void invoke(IN value) {
		try {
			byte[] msg = schema.serialize(value);

			if (publishOptions == null) {
				channel.basicPublish("", queueName, null, msg);
			} else {
				boolean mandatory = publishOptions.computeMandatory(value);
				boolean immediate = publishOptions.computeImmediate(value);

				Preconditions.checkState(!(returnListener == null && (mandatory || immediate)),
					"Setting mandatory and/or immediate flags to true requires a ReturnListener.");

				String rk = publishOptions.computeRoutingKey(value);
				String exchange = publishOptions.computeExchange(value);

				channel.basicPublish(exchange, rk, mandatory, immediate,
					publishOptions.computeProperties(value), msg);
			}
		} catch (IOException e) {
			if (logFailuresOnly) {
				LOG.error("Cannot send RMQ message {} at {}", queueName, rmqConnectionConfig.getHost(), e);
			} else {
				throw new RuntimeException("Cannot send RMQ message " + queueName + " at " + rmqConnectionConfig.getHost(), e);
			}
		}

	}
686681
public static void write(HttpServletResponse response, InputStream in, int bufferSize) {
		ServletOutputStream out = null;
		try {
			out = response.getOutputStream();
			IoUtil.copy(in, out, bufferSize);
		} catch (IOException e) {
			throw new UtilException(e);
		} finally {
			IoUtil.close(out);
			IoUtil.close(in);
		}
	}
1016377
@Override
  public void deliver(WriteStream os, OutHttp2 outHttp)
    throws IOException
  {
    outHttp.writeFlow(_streamId, _credit);
  }
1291386
@Override
  public void deliver(WriteStream os, OutHttp2 out)
    throws IOException
  {
    _stream.writeCont(out);
  }
452039
@Override
    InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException {
        assert args.length <= 3;                // includes null

        // first check that we are still attached
        int door;
        synchronized (this) {
            if (fd == -1) {
                throw new IOException("Detached from target VM");
            }
            door = fd;
        }

        // enqueue the command via a door call
        int s = enqueue(door, cmd, args);
        assert s >= 0;                          // valid file descriptor

        // The door call returns a file descriptor (one end of a socket pair).
        // Create an input stream around it.
        SocketInputStream sis = new SocketInputStream(s);

        // Read the command completion status
        int completionStatus;
        try {
            completionStatus = readInt(sis);
        } catch (IOException ioe) {
            sis.close();
            throw ioe;
        }

        // If non-0 it means an error but we need to special-case the
        // "load" command to ensure that the right exception is thrown.
        if (completionStatus != 0) {
            sis.close();
            if (cmd.equals("load")) {
                throw new AgentLoadException("Failed to load agent library");
            } else {
                throw new IOException("Command failed in target VM");
            }
        }

        // Return the input stream so that the command output can be read
        return sis;
    }
1370025
@Handler
    public void onOutput(Output<ByteBuffer> event,
            PlainChannel plainChannel)
            throws InterruptedException, SSLException, ExecutionException {
        if (plainChannel.hub() != this) {
            return;
        }
        plainChannel.sendUpstream(event);
    }
108969
public void sendData(InputStream in) throws ResponseException {
        if(con.isClosed()) return;

        Socket socket = null;
        try {
            socket = conHandler.createDataSocket();
            dataConnections.add(socket);
            OutputStream out = socket.getOutputStream();

            byte[] buffer = new byte[bufferSize];
            int len;
            while((len = in.read(buffer)) != -1) {
                Utils.write(out, buffer, len, conHandler.isAsciiMode());
                bytesTransferred += len;
            }

            out.flush();
            Utils.closeQuietly(out);
            Utils.closeQuietly(in);
            Utils.closeQuietly(socket);
        } catch(SocketException ex) {
            throw new ResponseException(426, "Transfer aborted");
        } catch(IOException ex) {
            throw new ResponseException(425, "An error occurred while transferring the data");
        } finally {
            onUpdate();
            if(socket != null) dataConnections.remove(socket);
        }
    }
763817
public void doProcess(InputStream in, PrintWriter out, Map<String, Object> properties)
        throws RemoteException
    {
        String strCommand = this.getProperty(REMOTE_COMMAND, properties);
        if (RECEIVE_REMOTE_MESSAGE.equals(strCommand))
        {
            Message message = ((RemoteReceiveQueue)m_remoteObject).receiveRemoteMessage();
            if (message != null)	// If the client quits, this is freed and I get a null message (which I don't need to return)
            	this.setReturnObject(out, message);
        }
        else if (ADD_REMOTE_MESSAGE_FILTER.equals(strCommand))
        {
            BaseMessageFilter messageFilter = (BaseMessageFilter)this.getNextObjectParam(in, FILTER, properties);
            String strSessionPathID = this.getNextStringParam(in, SESSION, properties);
            BaseHolder sessionHolder = this.getSessionFromPath(strSessionPathID);
            BaseMessageFilter objReturn = null;
            if (sessionHolder instanceof SessionHolder)
            {       // Always
                RemoteSession remoteSession = (RemoteSession)sessionHolder.getRemoteObject();
                objReturn = ((RemoteReceiveQueue)m_remoteObject).addRemoteMessageFilter(messageFilter, remoteSession);
            }
            else if (sessionHolder == null)
            {   // Session may be null.
                objReturn = ((RemoteReceiveQueue)m_remoteObject).addRemoteMessageFilter(messageFilter, null);
            }
            else
                Utility.getLogger().warning("Remote session not found");
            this.setReturnObject(out, objReturn);
        }
        else if (REMOVE_REMOTE_MESSAGE_FILTER.equals(strCommand))
        {
            BaseMessageFilter messageFilter = (BaseMessageFilter)this.getNextObjectParam(in, FILTER, properties);
            boolean bFreeFilter = this.getNextBooleanParam(in, FREE, properties);
            boolean bSuccess = ((RemoteReceiveQueue)m_remoteObject).removeRemoteMessageFilter(messageFilter, bFreeFilter);
            this.setReturnObject(out, new Boolean(bSuccess));
        }
        else if (UPDATE_REMOTE_FILTER_PROPERTIES.equals(strCommand))
        {
            BaseMessageFilter messageFilter = (BaseMessageFilter)this.getNextObjectParam(in, FILTER, properties);
            Object[][] propIn = (Object[][])this.getNextObjectParam(in, PROPERTIES, properties);
            Map<String,Object> propFilter = this.getNextPropertiesParam(in, MAP, properties);
            ((RemoteReceiveQueue)m_remoteObject).updateRemoteFilterProperties(messageFilter, propIn, propFilter);
        }
        else
            super.doProcess(in, out, properties);
    }
306040
protected void handleConnection(Socket connection) throws IOException
    {
        if (log.isDebugEnabled()) log.debug("Handle " + connection);
        InputStream in = connection.getInputStream();
        OutputStream out = connection.getOutputStream();

        handleConnection(in, out);
        out.flush();

        in = null;
        out = null;
        connection.close();
    }
962335
public void sendRequest (
        int invOid, int invCode, int methodId, Object[] args, Transport transport)
    {
        if (_clobj == null) {
            log.warning("Dropping invocation request on shutdown director", "code", invCode,
                        "methodId", methodId);
            return;
        }

        // configure any invocation listener marshallers among the arguments
        int acount = args.length;
        for (int ii = 0; ii < acount; ii++) {
            Object arg = args[ii];
            if (arg instanceof ListenerMarshaller) {
                ListenerMarshaller lm = (ListenerMarshaller)arg;
                lm.requestId = nextRequestId();
                lm.mapStamp = System.currentTimeMillis();
                // create a mapping for this marshaller so that we can properly dispatch responses
                // sent to it
                _listeners.put(lm.requestId, lm);
            }
        }

        // create an invocation request event
        InvocationRequestEvent event = new InvocationRequestEvent(invOid, invCode, methodId, args);
        event.setTransport(transport);

        // because invocation directors are used on the server, we set the source oid here so that
        // invocation requests are properly attributed to the right client object when created by
        // server-side entities only sort of pretending to be a client
        event.setSourceOid(_clobj.getOid());

//         Log.info("Sending invreq " + event + ".");

        // now dispatch the event
        _omgr.postEvent(event);
    }