public InvocationClient(Connection conn, Request req, double timeout, RequestWaiter waiter) { this.conn = conn; this.req = req; this.timeout = timeout; this.reqWaiter = waiter; req.clientHandler(this); this.replyKey = conn.allocateKey(); this.timeoutTask = conn.transport().createTask(this); }
public void closeLater(Connection c) { if (!closeQueue.enqueue(c)) { c.closeSocket(); } }
private void handshake() throws IOException { switch (socket.handshake()) { case DONE: if (socket.getMinimumReadBufferSize() > readSize) { readSize = socket.getMinimumReadBufferSize(); } setState(CONNECTED); while (socket.drain(input.getChannelWritable(readSize)) > 0) { handlePackets(); } break; case NEED_READ: enableRead(); disableWrite(); break; case NEED_WRITE: disableRead(); enableWrite(); break; } }
private void handleEnableWrite(Connection conn) { if (conn.isClosed()) { return; } conn.enableWrite(); }
enableRead(); if (pendingWrite) { enableWrite(); } else { disableWrite();
public boolean invokeVoid(Request req) { return postPacket(new RequestPacket(Packet.FLAG_NOREPLY, allocateKey(), req.methodName(), req.parameters())); }
/** * Connect to the given address. This method is called by a {@link * Supervisor} object. * * @return the new connection * @param owner the one calling this method * @param spec the address to connect to * @param context application context for the new connection * @param sync perform a synchronous connect in the calling thread * if this flag is set */ Connection connect(Supervisor owner, Spec spec, Object context, boolean sync) { Connection conn = new Connection(this, owner, spec, context); if (sync) { addConnection(conn.connect()); } else { connector.connectLater(conn); } return conn; }
public void returnRequest() { if (!conn.completeRequest(done)) { throw new IllegalStateException("Request already returned"); } if (noReply) { return; } if (!request.isError() && !method.checkReturnValues(request)) { request.setError(ErrorCode.WRONG_RETURN, "Return values in " + request + " does not match " + method); } if (request.isError()) { conn.postPacket(new ErrorPacket(0, replyKey, request.errorCode(), request.errorMessage())); } else { conn.postPacket(new ReplyPacket(0, replyKey, request.returnValues())); } } }
/** * Handle timeout. **/ public void run() { if (!conn.cancelReply(this)) { return; } req.setError(ErrorCode.TIMEOUT, "Request timed out after " + timeout + " seconds."); reqWaiter.handleRequestDone(req); } }
private void run() { try { while (true) { Connection conn = (Connection) connectQueue.dequeue(); parent.addConnection(conn.connect()); } } catch (EndOfQueueException e) {} synchronized (this) { done = true; notifyAll(); while (!exit) { try { wait(); } catch (InterruptedException x) {} } } }
private void run() { while (serverChannel.isOpen()) { try { parent.addConnection(new Connection(parent, owner, serverChannel.accept())); parent.sync(); } catch (ClosedChannelException ignore) { } catch (Exception e) { log.log(Level.WARNING, "Error accepting connection", e); } } while (true) { try { shutdownGate.await(); return; } catch (InterruptedException ignore) {} } }
/** * Handle user abort. **/ public void handleAbort() { if (!conn.cancelReply(this)) { return; } timeoutTask.kill(); req.setError(ErrorCode.ABORT, "Aborted by user"); reqWaiter.handleRequestDone(req); }
private void run() { try { while (true) { ((Connection)closeQueue.dequeue()).closeSocket(); } } catch (EndOfQueueException e) {} }