private long send( final long result, final int messageType, final int sequenceIndex, final Encoder encoder, final int msgSeqNo) { if (!libraryConnected) { return LIBRARY_DISCONNECTED; } final int length = Encoder.length(result); final int offset = Encoder.offset(result); final long position = gatewayPublication.saveMessage( buffer, offset, length, libraryId, messageType, sessionId, sequenceIndex, connectionId, OK, msgSeqNo); encoder.resetMessage(); return position; }
private void assertEncodesTo(final Encoder encoder, final String expectedValue) { final long result = encoder.encode(buffer, 1); final int length = Encoder.length(result); final int offset = Encoder.offset(result); assertEquals(expectedValue, buffer.getAscii(offset, expectedValue.length())); assertEquals(expectedValue.length(), length); }
private void onMessageWithSession( final int messageType, final long result, final Action expectedAction, final long sessionId, final long connectionId) { final int length = Encoder.length(result); final int offset = Encoder.offset(result); final Action action = replayer.onMessage( buffer, offset, length, LIBRARY_ID, connectionId, sessionId, SEQUENCE_INDEX, messageType, 0L, OK, 0, 0L); assertEquals(expectedAction, action); }
final int encodedLength = Encoder.length(result); final int encodedOffset = Encoder.offset(result); gapFiller.onMessage(
void send(final Encoder encoder) { try { final long result = encoder.encode(writeAsciiBuffer, OFFSET); final int offset = Encoder.offset(result); final int length = Encoder.length(result); encoder.reset(); writeBuffer.position(offset).limit(offset + length); final int written = socket.write(writeBuffer); assertEquals(length, written); DebugLogger.log(FIX_TEST, "> [" + writeAsciiBuffer.getAscii(offset, length) + "]"); writeBuffer.clear(); } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } }
private void initiateConnection() throws IOException { socket = SocketChannel.open(new InetSocketAddress("localhost", port)); final UtcTimestampEncoder timestamp = new UtcTimestampEncoder(); timestamp.encode(System.currentTimeMillis()); logon .heartBtInt(10) .encryptMethod(0) .header() .sendingTime(timestamp.buffer()) .msgSeqNum(1) .senderCompID(INITIATOR_ID) .targetCompID(ACCEPTOR_ID); final long result = logon.encode(buffer, 0); final int offset = Encoder.offset(result); final int length = Encoder.length(result); byteBuffer.position(offset); byteBuffer.limit(offset + length); assertEquals(length, socket.write(byteBuffer)); }
encoder.setupMessage(reqHeader); final long result = encoder.encode(gapFillMsgSeqNum, newSeqNo); final int encodedLength = Encoder.length(result); final int encodedOffset = Encoder.offset(result); final long sentPosition = publication.saveMessage(
/** * Send a message on this session. * * @param encoder the encoder of the message to be sent * @return the position in the stream that corresponds to the end of this message or a negative * number indicating an error status. * @throws IndexOutOfBoundsException if the encoded message is too large, if this happens consider * increasing {@link CommonConfiguration#sessionBufferSize(int)} */ public long send(final Encoder encoder) { validateCanSendMessage(); final int sentSeqNum = newSentSeqNum(); final HeaderEncoder header = (HeaderEncoder)encoder.header(); header .msgSeqNum(sentSeqNum) .sendingTime(timestampEncoder.buffer(), timestampEncoder.encode(time())); if (enableLastMsgSeqNumProcessed) { header.lastMsgSeqNumProcessed(lastMsgSeqNumProcessed); } if (!header.hasSenderCompID()) { sessionIdStrategy.setupSession(sessionKey, header); } final long result = encoder.encode(asciiBuffer, 0); final int length = Encoder.length(result); final int offset = Encoder.offset(result); return send(asciiBuffer, offset, length, sentSeqNum, encoder.messageType()); }
private Action sendGapFill(final int msgSeqNo, final int newSeqNo) { final long result = gapFillEncoder.encode(msgSeqNo, newSeqNo); final int gapFillLength = Encoder.length(result); final int gapFillOffset = Encoder.offset(result); if (claimBuffer(MESSAGE_FRAME_BLOCK_LENGTH + gapFillLength)) { final int destOffset = bufferClaim.offset(); final MutableDirectBuffer destBuffer = bufferClaim.buffer(); FIX_MESSAGE_ENCODER .wrapAndApplyHeader(destBuffer, destOffset, MESSAGE_HEADER_ENCODER) .libraryId(ENGINE_LIBRARY_ID) .messageType(SequenceResetDecoder.MESSAGE_TYPE) .session(this.sessionId) .sequenceIndex(this.sequenceIndex) .connection(this.connectionId) .timestamp(0) .status(MessageStatus.OK) .putBody(gapFillEncoder.buffer(), gapFillOffset, gapFillLength); bufferClaim.commit(); this.beginGapFillSeqNum = NONE; return CONTINUE; } else { return ABORT; } }
@Test public void doesNotReuseExistingSessionIdsForDistinctCompositeKeys() { final SessionContext aContext = sessionContexts.onLogon(aSession); final SessionContext bContext = sessionContexts.onLogon(bSession); // bump counter final long result = logonWithSenderAndTarget(aSession.localCompId(), aSession.remoteCompId()); sessionContexts.onSentFollowerMessage( aContext.sessionId(), aContext.sequenceIndex(), LogonDecoder.MESSAGE_TYPE, asciiBuffer, Encoder.offset(result), Encoder.length(result)); final SessionContext cContext = sessionContexts.onLogon(cSession); assertNotEquals(DUPLICATE_SESSION, cContext); assertEquals(3, cContext.sessionId()); }
private void bufferContainsMessage( final long sessionId, final int sequenceNumber, final int sequenceIndex, final Encoder exampleMessage, final HeaderEncoder header, final int messageType) { final UtcTimestampEncoder timestampEncoder = new UtcTimestampEncoder(); final int timestampLength = timestampEncoder.encode(ORIGINAL_SENDING_EPOCH_MS); MutableAsciiBuffer asciiBuffer = new MutableAsciiBuffer(new byte[BIG_BUFFER_LENGTH]); header .sendingTime(timestampEncoder.buffer(), timestampLength) .senderCompID(BUFFER_SENDER) .targetCompID(BUFFER_TARGET) .msgSeqNum(sequenceNumber); final long result = exampleMessage.encode(asciiBuffer, 0); logEntryLength = Encoder.length(result); final int encodedOffset = Encoder.offset(result); asciiBuffer = new MutableAsciiBuffer(asciiBuffer, encodedOffset, logEntryLength); bufferContainsMessage(sessionId, sequenceIndex, asciiBuffer, messageType); }
final int encodedLength = Encoder.length(result); final int encodedOffset = Encoder.offset(result); final boolean sent = inboundPublication.saveMessage(