/** * Request an asynchronous close of a connection. * * @param conn the connection to close **/ void closeConnection(Connection conn) { postCommand(new CloseConnectionCmd(conn)); }
/** * Perform the given command in such a way that it does not run * concurrently with the transport thread or other commands * performed by invoking this method. This method will continue to * work even after the transport thread has been shut down. * * @param cmd the command to perform **/ public void perform(Runnable cmd) { if (Thread.currentThread() == thread) { cmd.run(); return; } if (!postCommand(cmd)) { join(); synchronized (thread) { cmd.run(); } } }
/** * Request an asynchronous enabling of write events for a * connection. * * @param conn the connection to enable write events for **/ void enableWrite(Connection conn) { if (Thread.currentThread() == thread) { handleEnableWrite(conn); } else { postCommand(new EnableWriteCmd(conn)); } }
/** * Add a connection to the set of connections handled by this * Transport. Invoked by the {@link Connector} class. * * @param conn the connection to add **/ void addConnection(Connection conn) { if (!postCommand(new AddConnectionCmd(conn))) { perform(new CloseConnectionCmd(conn)); } }
/** * Synchronize with the transport thread. This method will block * until all commands issued before this method was invoked has * completed. If the transport thread has been shut down (or is in * the progress of being shut down) this method will instead wait * for the transport thread to complete, since no more commands * will be performed, and waiting would be forever. Invoking this * method from the transport thread is not a good idea. * * @return this object, to enable chaining **/ public Transport sync() { SyncCmd cmd = new SyncCmd(); if (postCommand(cmd)) { cmd.waitDone(); } else { join(); } return this; }