@Override public void dispose(ClientConnection connection) { //we MUST open a new connection so we kill the oldest now. //logger.info("CLIENT SIDE BEGIN CONNECTION CLOSE"); connection.beginDisconnect(); //TODO: should we build a blocking write OR always keep some free. //connection.handShakeWrapIfNeeded(cc, target, buffer) connection.close(); if (true) { throw new UnsupportedOperationException("Can not close old connection without finishing handshake."); } }
private void abandonNow(ClientConnection abandonded) { Pipe<NetPayloadSchema> pipe = output[abandonded.getResponsePipeIdx()]; ///ensure that this will not cause any stall, better to skip this than be blocked. if (Pipe.hasRoomForWrite(pipe)) { long nowNS = System.nanoTime(); long callTime = abandonded.outstandingCallTime(nowNS); logger.warn("\nClient disconnected {} con:{} session:{} because call was taking too long. Estimated:{}", abandonded, abandonded.id, abandonded.sessionId,Appendables.appendNearestTimeUnit(new StringBuilder(), callTime)); abandonded.touchSentTime(nowNS);//rest the timeout so we do not attempt to close this again until the timeout has passed again. if (!abandonded.isDisconnecting()) { abandonded.beginDisconnect(); } int size = Pipe.addMsgIdx(pipe, NetPayloadSchema.MSG_DISCONNECT_203); Pipe.addLongValue(abandonded.getId(), pipe); Pipe.confirmLowLevelWrite(pipe, size); Pipe.publishWrites(pipe); //Do not set notification sent this message will trigger that one later once it makes it down the pipe. } }
public static void cleanCloseConnection(Pipe<ClientHTTPRequestSchema> requestPipe, ClientConnection connectionToKill, Pipe<NetPayloadSchema> pipe) { //must consume each field so we can move forward, this is required or the position will be off... //matches ClientHTTPRequestSchema.MSG_CLOSECONNECTION_104 int session = Pipe.takeInt(requestPipe); int port = Pipe.takeInt(requestPipe); int hostId = Pipe.takeInt(requestPipe); long conId = Pipe.takeLong(requestPipe); //do not close that will be done by last stage //must be done first before we send the message connectionToKill.beginDisconnect(); Pipe.presumeRoomForWrite(pipe); int size = Pipe.addMsgIdx(pipe, NetPayloadSchema.MSG_DISCONNECT_203); Pipe.addLongValue(connectionToKill.getId(), pipe);// NetPayloadSchema.MSG_DISCONNECT_203_FIELD_CONNECTIONID_201, connectionToKill.getId()); Pipe.confirmLowLevelWrite(pipe, size); Pipe.publishWrites(pipe); }
private boolean writeDisconnect(Pipe<NetPayloadSchema> pipe) { long chnl = Pipe.peekLong(pipe, 0xF&NetPayloadSchema.MSG_DISCONNECT_203_FIELD_CONNECTIONID_201); ClientConnection cc = (ClientConnection)ccm.lookupConnectionById(chnl); int msgIdx = Pipe.takeMsgIdx(pipe); long channelId = Pipe.takeLong(pipe); assert(chnl==channelId); if (cc!=null) { if (cc.isValid()) { //only begin disconnect if not already disconnected cc.beginDisconnect();//do not close or we will not get any response } else { //already closed so remove value ccm.removeConnection(channelId); } } else { //already closed so remove value ccm.removeConnection(channelId);//already closed so remove if possible } Pipe.confirmLowLevelRead(pipe, Pipe.sizeOf(pipe, msgIdx)); Pipe.releaseReadLock(pipe); return true; }
cc.beginDisconnect();//must be marked as disconnecting so it get re-connected if requests start up again.
if (null!=con) { if (con instanceof ClientConnection) { ((ClientConnection)con).beginDisconnect();