public class Emulator extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
Emulator.MessageListener |
Constructor and Description |
---|
Emulator(TestUtility testUtility)
Constructs an Emulator instance with a reference to a TestUtility object.
|
Modifier and Type | Method and Description |
---|---|
void |
acceptConnection()
Accepts an incoming TCP connection.
|
void |
acceptConnection(TestAcceptorTask acceptorTask)
Accepts an incoming TCP connection and prepares the Emulator for communication.
|
IMessage |
acceptEstablishment()
Accepts an "Establish" message and automatically sends a corresponding establishment response.
|
IMessage |
acceptEstablishment(long outgoingSequenceNumber)
Accepts an "Establish" message and automatically sends a corresponding establishment response.
|
IMessage |
acceptEstablishment(long outgoingSequenceNumber,
long expectedIncomingSequenceNumber,
long previousUuid,
long previousSeqNo)
Accepts an "Establish" message, allows setting expected sequence numbers and previous UUID/SeqNo.
|
IMessage |
acceptEstablishmentWithoutResponse()
Accepts an "Establish" message, used to confirm session setup after negotiation.
|
IMessage |
acceptNegotiation()
Accepts a "Negotiate" message and automatically sends a corresponding negotiation response.
|
IMessage |
acceptNegotiationWithoutResponse()
Receives a "Negotiate" message, used at the start of a communication session.
|
IMessage |
acceptSequence(int keepAliveIntervalLapsed)
Accepts a sequence message, including checking the KeepAliveLapsed status.
|
IMessage |
acceptTerminate()
Accepts a "Terminate" message and sends a confirmation response.
|
IMessage |
acceptTerminateWithoutResponse()
Accepts a "Terminate" message without sending any response.
|
void |
closeServerSocket()
Closes the server socket.
|
IMessage |
createExecutionReportTradeOutright(long orderId,
boolean retransmission) |
IMessage |
createMassQuoteAck(boolean retransmission) |
void |
disconnect()
Closes the socket and associated input/output streams.
|
void |
disconnectImmediately()
Closes the socket immediately, using SO_LINGER with a timeout of 0.
|
int |
getPort()
Returns the port number the Emulator is listening on (default value is 11012).
|
long |
getTimeoutInMilliseconds()
Returns the timeout in milliseconds for sockets.
|
long |
getUuid()
Returns the UUID.
|
boolean |
isConnectionClosed()
Checks if the TCP connection associated with the Emulator is closed.
|
void |
receiveAll()
Receives all the data from the input stream.
|
IMessage |
receiveMessage()
Receives the next available message.
|
IMessage |
receiveMessage(int inSeqNum)
Receives a message, asserting that it has the expected sequence number.
|
IMessage |
receiveMessage(int inSeqNum,
int templateId)
Receives a message, asserting that it has the expected sequence number and template ID.
|
IMessage |
receiveOrder(int inSeqNum)
Receives a "NewOrderSingle" message and verifies its sequence number.
|
IMessage |
receiveRetransmitRequest(long fromSeqNo,
long msgCount)
Receives a "RetransmitRequest" message, verifying the provided sequence numbers.
|
IMessage |
receiveSequence(int nextSeqNo)
Receives a "Sequence" message and verifies its sequence number.
|
IMessage |
rejectEstablishment()
Accepts an "Establish" message and automatically sends a rejection response.
|
IMessage |
rejectNegotiation()
Accepts a "Negotiate" message and automatically sends a rejection response.
|
void |
send(ByteBuffer rawMsg)
Sends a raw message.
|
void |
send(IMessage msg)
Sends an IMessage object.
|
void |
send(IMessage msg,
long seqNum)
Sends an IMessage object with sequence number.
|
void |
sendNotApplied(long fromSeqNo,
int msgCount)
Sends a "Not Applied" message, indicating that some previous messages were not processed.
|
void |
sendRetransmission(IMessage request)
Sends a "Retransmission" message is sent in response to a valid Retransmit Request.
|
void |
sendSequence(long nextSeqNo)
Sends a "Sequence" message to maintain session synchronization.
|
void |
sendSequence(long nextSeqNo,
int keepAliveLapsed)
Sends a "Sequence" message with keep-alive status information.
|
void |
sendSequence(long nextSeqNo,
int keepAliveLapsed,
long uuid)
Sends a "Sequence" message with keep-alive information and a specified UUID.
|
void |
setPort(int port)
Sets the port number for the Emulator.
|
void |
setTimeoutInMilliseconds(int timeoutInMilliseconds)
Sets the timeout in milliseconds for sockets.
|
IMessage |
terminate()
Initiates a "Terminate" sequence and waits for the corresponding Terminate response.
|
IMessage |
terminateWithoutResponse(String text)
Initiates a "Terminate" sequence (with customizable text) without waiting for a response.
|
IMessage |
terminateWithoutResponse(String text,
int errorCode)
Initiates a "Terminate" sequence (with customizable text) without waiting for a response.
|
void |
testLink(int expectedOutgoingSequenceNumber,
int expectedIncomingSequenceNumber)
Tests the link by sending and receiving Sequence messages with expected sequence numbers.
|
IMessage |
waitUntilTerminate(Emulator.MessageListener listener)
Waits for a "Terminate" message and provides a way to process other incoming messages during the wait.
|
static void |
writeToLog(String message)
Static method for writing a message to a log, often used for test tracking.
|
public Emulator(TestUtility testUtility)
testUtility
- object used for message creation.public long getUuid()
public int getPort()
public void setPort(int port)
port
- The desired port number.public long getTimeoutInMilliseconds()
public void setTimeoutInMilliseconds(int timeoutInMilliseconds)
timeoutInMilliseconds
- The timeout in milliseconds.public boolean isConnectionClosed() throws IOException
IOException
- If an error occurs during the connection status check.public static void writeToLog(String message)
message
- message to be logged.public void acceptConnection(TestAcceptorTask acceptorTask) throws IOException
acceptorTask
- object is used to return automatically allocated port number.IOException
- If an error occurs during connection acceptance.public void acceptConnection() throws IOException
IOException
- If an error occurs during connection acceptance.public IMessage acceptNegotiationWithoutResponse() throws IOException
IOException
- If an error occurs during message reception.public IMessage acceptNegotiation() throws IOException
IOException
- If an error occurs during message reception or sending the response.public IMessage rejectNegotiation() throws IOException
IOException
- If an error occurs during message reception or sending the rejection.public IMessage acceptEstablishmentWithoutResponse() throws IOException
IOException
- If an error occurs during message reception.public IMessage acceptEstablishment(long outgoingSequenceNumber, long expectedIncomingSequenceNumber, long previousUuid, long previousSeqNo) throws IOException
outgoingSequenceNumber
- The expected next outgoing sequence number to send in the response.expectedIncomingSequenceNumber
- The expected incoming sequence number in the Establish message.previousUuid
- The UUID from a previous session (if resuming)previousSeqNo
- The sequence number from a previous session (if resuming)IOException
- If an error occurs during message reception or sending the response.public IMessage acceptEstablishment(long outgoingSequenceNumber) throws IOException
outgoingSequenceNumber
- The expected next outgoing sequence number to send in the response.IOException
- If an error occurs during message reception or sending the response.public IMessage acceptEstablishment() throws IOException
IOException
- If an error occurs during message reception or sending the response.public IMessage rejectEstablishment() throws IOException
IOException
- If an error occurs during message reception or sending the rejection.public IMessage acceptSequence(int keepAliveIntervalLapsed) throws IOException
keepAliveIntervalLapsed
- Indicates if the keep-alive mechanism has lapsed.IOException
- If an error occurs during message reception.public void sendNotApplied(long fromSeqNo, int msgCount) throws IOException
fromSeqNo
- The starting sequence number of the unprocessed messages.msgCount
- The number of unprocessed messages.IOException
- If an error occurs while sending the message.public void sendRetransmission(IMessage request) throws IOException
request
- The Retransmit Request.IOException
- If an error occurs while sending the message.public void sendSequence(long nextSeqNo, int keepAliveLapsed, long uuid) throws IOException
nextSeqNo
- The next expected sequence number.keepAliveLapsed
- Indicates if the keep-alive mechanism has lapsed.uuid
- UUID.IOException
- If an error occurs while sending the message.public void sendSequence(long nextSeqNo, int keepAliveLapsed) throws IOException
nextSeqNo
- The next expected sequence number.keepAliveLapsed
- Indicates if the keep-alive mechanism has lapsed.IOException
- If an error occurs while sending the message.public void sendSequence(long nextSeqNo) throws IOException
nextSeqNo
- The next expected sequence number.IOException
- If an error occurs while sending the message.public IMessage acceptTerminateWithoutResponse() throws IOException
IOException
- If an error occurs during message reception.public IMessage acceptTerminate() throws IOException
IOException
- If an error occurs during message reception.public IMessage terminateWithoutResponse(String text, int errorCode) throws IOException
text
- Customizable text to be included in the Terminate message.errorCode
- An error code to be included in the Terminate message.IOException
- If an error occurs during sending the Terminate message.public IMessage terminateWithoutResponse(String text) throws IOException
text
- Customizable text to be included in the Terminate message.IOException
- If an error occurs during sending the Terminate message.public IMessage terminate() throws IOException
IOException
- If an error occurs during sending or receiving Terminate messages.public void send(IMessage msg) throws IOException
msg
- The IMessage object to send.IOException
- If an error occurs while sending the message.public void send(IMessage msg, long seqNum) throws IOException
msg
- The IMessage object send.seqNum
- A sequence number to set.IOException
- If an error occurs while sending the message.public void send(ByteBuffer rawMsg) throws IOException
rawMsg
- The raw message buffer (ByteBuffer) to send.IOException
- If an error occurs while sending the message.public void receiveAll() throws IOException
IOException
- If an error occurs during message reception.public IMessage receiveMessage() throws IOException
IOException
- If an error occurs during message reception.public IMessage receiveMessage(int inSeqNum) throws IOException
inSeqNum
- The expected sequence number.IOException
- If an error occurs during message reception.public IMessage receiveMessage(int inSeqNum, int templateId) throws IOException
inSeqNum
- The expected sequence number.templateId
- The expected template ID of the message.IOException
- If an error occurs during message reception.public IMessage receiveOrder(int inSeqNum) throws IOException
inSeqNum
- The expected sequence number of the order message.IOException
- If an error occurs during message reception.public IMessage receiveSequence(int nextSeqNo) throws IOException
nextSeqNo
- The expected sequence number of the sequence message.IOException
- If an error occurs during message reception.public IMessage receiveRetransmitRequest(long fromSeqNo, long msgCount) throws IOException
fromSeqNo
- The expected starting sequence number of the retransmission request.msgCount
- The expected number of messages to be retransmitted.IOException
- If an error occurs during message reception.public void testLink(int expectedOutgoingSequenceNumber, int expectedIncomingSequenceNumber) throws IOException
expectedOutgoingSequenceNumber
- The expected next outgoing sequence number.expectedIncomingSequenceNumber
- The expected next incoming sequence number.IOException
- If an error occurs during communication.public IMessage waitUntilTerminate(Emulator.MessageListener listener) throws IOException
listener
- A MessageListener to handle incoming messages before the Terminate message.IOException
- If an error occurs during communication.public void disconnectImmediately()
public void disconnect()
public void closeServerSocket()
public IMessage createMassQuoteAck(boolean retransmission)
public IMessage createExecutionReportTradeOutright(long orderId, boolean retransmission)
Copyright © 2005–2024 Onix Solutions. All rights reserved.