com.paritytrading.nassau.soupbintcp.SoupBinTCPClient Java Examples

The following examples show how to use com.paritytrading.nassau.soupbintcp.SoupBinTCPClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Recorder.java    From nassau with Apache License 2.0 6 votes vote down vote up
private static void receive(SoupBinTCPClient client) throws IOException {
    try (Selector selector = Selector.open()) {

        client.getChannel().register(selector, SelectionKey.OP_READ);

        while (receive) {
            int numKeys = selector.select(TIMEOUT_MILLIS);
            if (numKeys > 0) {
                if (client.receive() < 0)
                    break;

                selector.selectedKeys().clear();
            }

            client.keepAlive();
        }
    }
}
 
Example #2
Source File: Recorder.java    From nassau with Apache License 2.0 6 votes vote down vote up
private static void main(Config config, File file) throws IOException {
    addShutdownHook();

    try (final BinaryFILEWriter writer = BinaryFILEWriter.open(file)) {

        MessageListener listener = new MessageListener() {

            @Override
            public void message(ByteBuffer buffer) throws IOException {
                writer.write(buffer);
            }

        };

        if (config.hasPath("session.multicast-interface")) {
            try (MoldUDP64Client client = join(config, listener)) {
                receive(client);
            }
        } else {
            try (SoupBinTCPClient client = connect(config, listener)) {
                receive(client);
            }
        }
    }
}
 
Example #3
Source File: OrderEntry.java    From parity-extras with Apache License 2.0 5 votes vote down vote up
public static OrderEntry open(InetSocketAddress address) throws IOException {
    SocketChannel channel = SocketChannel.open();

    channel.setOption(StandardSocketOptions.TCP_NODELAY, true);
    channel.connect(address);
    channel.configureBlocking(false);

    MessageListener listener = new POEClientParser(new Listener());

    SoupBinTCPClient transport = new SoupBinTCPClient(channel, POE.MAX_OUTBOUND_MESSAGE_LENGTH,
            listener, new StatusListener());

    return new OrderEntry(transport);
}
 
Example #4
Source File: OrderEntryFactory.java    From parity with Apache License 2.0 5 votes vote down vote up
SoupBinTCPClient create(POEClientListener listener,
        SoupBinTCPClientStatusListener statusListener) throws IOException {
    SocketChannel channel = SocketChannel.open();

    channel.connect(address);

    channel.setOption(StandardSocketOptions.TCP_NODELAY, true);
    channel.configureBlocking(false);

    return new SoupBinTCPClient(channel, POE.MAX_OUTBOUND_MESSAGE_LENGTH,
            new POEClientParser(listener), statusListener);
}
 
Example #5
Source File: Session.java    From parity with Apache License 2.0 5 votes vote down vote up
@Override
public void loginRejected(SoupBinTCPClient session, SoupBinTCP.LoginRejected payload) throws IOException {
    switch (payload.rejectReasonCode) {
    case SoupBinTCP.LOGIN_REJECT_CODE_NOT_AUTHORIZED:
        fix.sendLogout("Not authorized");
        break;
    case SoupBinTCP.LOGIN_REJECT_CODE_SESSION_NOT_AVAILABLE:
        fix.sendLogout("Session not available");
        break;
    }
}
 
Example #6
Source File: SoupBinTCP.java    From nassau with Apache License 2.0 5 votes vote down vote up
/**
 * Receive messages. Invoke the message listener on each message. Continue
 * until an End of Session packet is received or the end-of-stream is
 * reached.
 *
 * @param address the address
 * @param username the username
 * @param password the password
 * @param listener a message listener
 * @throws IOException if an I/O error occurs
 */
public static void receive(InetSocketAddress address, String username,
        String password, MessageListener listener) throws IOException {
    SocketChannel channel = SocketChannel.open();

    channel.connect(address);
    channel.configureBlocking(false);

    StatusListener statusListener = new StatusListener();

    try (Selector selector = Selector.open();
            SoupBinTCPClient client = new SoupBinTCPClient(channel, listener, statusListener)) {
        channel.register(selector, SelectionKey.OP_READ);

        LoginRequest message = new LoginRequest();

        message.setUsername(username);
        message.setPassword(password);
        message.setRequestedSession("");
        message.setRequestedSequenceNumber(1);

        client.login(message);

        while (statusListener.receive) {
            int numKeys = selector.select(TIMEOUT_MILLIS);

            if (numKeys > 0) {
                if (client.receive() < 0)
                    break;

                selector.selectedKeys().clear();
            }

            client.keepAlive();
        }
    }
}
 
Example #7
Source File: OrderEntry.java    From parity with Apache License 2.0 4 votes vote down vote up
@Override
public void heartbeatTimeout(SoupBinTCPClient session) {
    close();
}
 
Example #8
Source File: OrderEntry.java    From parity-extras with Apache License 2.0 4 votes vote down vote up
private OrderEntry(SoupBinTCPClient transport) {
    this.transport = transport;

    this.txBuffer = ByteBuffer.allocateDirect(POE.MAX_INBOUND_MESSAGE_LENGTH);
}
 
Example #9
Source File: Session.java    From parity with Apache License 2.0 4 votes vote down vote up
@Override
public void endOfSession(SoupBinTCPClient session) throws IOException {
    fix.sendLogout();
}
 
Example #10
Source File: OrderEntry.java    From parity-extras with Apache License 2.0 4 votes vote down vote up
public SoupBinTCPClient getTransport() {
    return transport;
}
 
Example #11
Source File: Session.java    From parity with Apache License 2.0 4 votes vote down vote up
@Override
public void loginAccepted(SoupBinTCPClient session, SoupBinTCP.LoginAccepted payload) throws IOException {
    fix.sendLogon(false);
}
 
Example #12
Source File: Session.java    From parity with Apache License 2.0 4 votes vote down vote up
@Override
public void heartbeatTimeout(SoupBinTCPClient session) throws IOException {
    fix.sendLogout("Trading system not available");
}
 
Example #13
Source File: Session.java    From parity with Apache License 2.0 4 votes vote down vote up
SoupBinTCPClient getOrderEntry() {
    return orderEntry;
}
 
Example #14
Source File: OrderEntry.java    From parity with Apache License 2.0 4 votes vote down vote up
@Override
public void endOfSession(SoupBinTCPClient session) {
}
 
Example #15
Source File: OrderEntry.java    From parity with Apache License 2.0 4 votes vote down vote up
@Override
public void loginRejected(SoupBinTCPClient session, SoupBinTCP.LoginRejected payload) {
    close();
}
 
Example #16
Source File: OrderEntry.java    From parity with Apache License 2.0 4 votes vote down vote up
@Override
public void loginAccepted(SoupBinTCPClient session, SoupBinTCP.LoginAccepted payload) {
}
 
Example #17
Source File: OrderEntry.java    From parity-extras with Apache License 2.0 4 votes vote down vote up
@Override
public void loginRejected(SoupBinTCPClient session, SoupBinTCP.LoginRejected payload) {
    error("Login rejected");
}
 
Example #18
Source File: OrderEntry.java    From parity with Apache License 2.0 4 votes vote down vote up
SoupBinTCPClient getTransport() {
    return transport;
}
 
Example #19
Source File: OrderEntry.java    From parity with Apache License 2.0 4 votes vote down vote up
private OrderEntry(Selector selector, SocketChannel channel, POEClientListener listener) {
    this.txBuffer = ByteBuffer.allocateDirect(POE.MAX_INBOUND_MESSAGE_LENGTH);

    this.selector = selector;

    this.transport = new SoupBinTCPClient(channel, POE.MAX_OUTBOUND_MESSAGE_LENGTH,
            new POEClientParser(listener), new StatusListener());

    this.closed = false;

    this.txLock = new Object();

    Thread receiver = new Thread(new Receiver());

    receiver.setDaemon(true);
    receiver.start();
}
 
Example #20
Source File: SoupBinTCP.java    From nassau with Apache License 2.0 4 votes vote down vote up
@Override
public void endOfSession(SoupBinTCPClient session) {
    receive = false;
}
 
Example #21
Source File: SoupBinTCP.java    From nassau with Apache License 2.0 4 votes vote down vote up
@Override
public void loginRejected(SoupBinTCPClient session, LoginRejected payload) throws IOException {
    throw new IOException("Login rejected");
}
 
Example #22
Source File: SoupBinTCP.java    From nassau with Apache License 2.0 4 votes vote down vote up
@Override
public void loginAccepted(SoupBinTCPClient session, LoginAccepted payload) {
}
 
Example #23
Source File: SoupBinTCP.java    From nassau with Apache License 2.0 4 votes vote down vote up
@Override
public void heartbeatTimeout(SoupBinTCPClient session) throws IOException {
    throw new IOException("Heartbeat timeout");
}
 
Example #24
Source File: OrderEntry.java    From parity-extras with Apache License 2.0 4 votes vote down vote up
@Override
public void heartbeatTimeout(SoupBinTCPClient session) {
    error("Heartbeat timeout");
}
 
Example #25
Source File: OrderEntry.java    From parity-extras with Apache License 2.0 4 votes vote down vote up
@Override
public void endOfSession(SoupBinTCPClient session) {
}
 
Example #26
Source File: OrderEntry.java    From parity-extras with Apache License 2.0 4 votes vote down vote up
@Override
public void loginAccepted(SoupBinTCPClient session, SoupBinTCP.LoginAccepted payload) {
}