/** * Converts the header of this message into a <code>byte</code> array using a {@link ByteBuffer}. */ protected void getDSCODEsForWrite() { final ByteBuffer cb = getCommBuffer(); cb.clear(); cb.putInt(this.messageType); cb.putInt(this.numberOfParts); cb.putInt(this.transactionId); } }
/** * Reads a chunk of this message. */ public void receiveChunk() throws IOException { if (this.socket != null) { synchronized (getCommBuffer()) { readChunk(); } } else { throw new IOException("Dead Connection"); } }
@Override protected void packHeaderInfoForSending(int msgLen, boolean isSecurityHeader) { final ByteBuffer cb = getCommBuffer(); cb.putInt(msgLen); byte isLastChunk = 0x00; if (isLastChunk()) { // isLastChunk = (byte) 0x01 ; isLastChunk = this.lastChunk; if (isSecurityHeader) { isLastChunk |= 0x02; } } // cb.put(isLastChunk() ? (byte) 0x01 : (byte) 0x00); cb.put(isLastChunk); }
/** * Populates the header with information received via socket */ public void readHeader() throws IOException { if (this.socket != null) { final ByteBuffer cb = getCommBuffer(); synchronized (cb) { fetchHeader(); final int type = cb.getInt(); final int numParts = cb.getInt(); final int txid = cb.getInt(); cb.clear(); if (!MessageType.validate(type)) { throw new IOException( String.format("Invalid message type %s while reading header", Integer.valueOf(type))); } // Set the header and payload fields only after receiving all the // socket data, providing better message consistency in the face // of exceptional conditions (e.g. IO problems, timeouts etc.) this.messageType = type; this.numberOfParts = numParts; // Already set in setPayloadFields via setNumberOfParts this.transactionId = txid; } } else { throw new IOException("Dead Connection"); } }
/** * Sends the header of this message. */ public void sendHeader() throws IOException { if (this.socket != null) { synchronized (getCommBuffer()) { getDSCODEsForWrite(); flushBuffer(); // Darrel says: I see no need for the following os.flush() call // so I've deadcoded it for performance. // this.os.flush(); } this.currentPart = 0; this.headerSent = true; } else { throw new IOException("Dead Connection"); } }
final ByteBuffer cb = getCommBuffer(); clearParts(); cb.clear();
public ServerToClientFunctionResultSender(ChunkedMessage msg, int messageType, ServerConnection sc, Function function, ExecuteFunctionOperationContext authzContext) { this.msg = msg; this.msg.setVersion(sc.getClientVersion()); this.messageType = messageType; this.sc = sc; this.fn = function; this.authContext = authzContext; this.isSelector = sc.getAcceptor().isSelector(); if (this.isSelector) { this.commBuffer = msg.getCommBuffer(); } }