public static FixLibrary blockingConnect(final LibraryConfiguration configuration) { final FixLibrary library = FixLibrary.connect(configuration); while (!library.isConnected()) { library.poll(1); Thread.yield(); } return library; }
public void onDisconnect(final FixLibrary library) { if (shouldCloseOnDisconnect) { library.close(); } }
void internalClose() { closeAll(poller, () -> scheduler.close(libraryId()), super::close, this::deleteFiles); }
/** * Start connecting to an engine. This method returns a FixLibrary immediately even if it hasn't connected. * * You should call {@link #poll(int)} on a regular duty cycle until the connection completes. * {@link #isConnected()} can be polled in order to determine whether library is connected. Also the * {@link LibraryConnectHandler#onConnect(FixLibrary)} method will be invoked. * * @param configuration the configuration for this library instance. * @return the library instance. * @throws FixGatewayException * if there's an error connecting to the FIX Gateway. */ public static FixLibrary connect(final LibraryConfiguration configuration) { return new FixLibrary(configuration).connect(); }
while (library.isConnected()) library.poll(1); System.out.println("Disconnected: " + (!library.isConnected())); while (!library.isConnected()) library.poll(1);
@Override public int doWork() { return library.poll(FRAGMENT_LIMIT); }
@Override public void onStart() { final MessageValidationStrategy validationStrategy = MessageValidationStrategy.targetCompId(ACCEPTOR_COMP_ID) .and(MessageValidationStrategy.senderCompId(Collections.singletonList(INITIATOR_COMP_ID))); final AuthenticationStrategy authenticationStrategy = AuthenticationStrategy.of(validationStrategy); final LibraryConfiguration configuration = new LibraryConfiguration(); configuration.authenticationStrategy(authenticationStrategy); // You register the new session handler - which is your application hook // that receives messages for new sessions configuration .libraryConnectHandler(new LoggingLibraryConnectHandler()) .sessionAcquireHandler(this::onAcquire) .sessionExistsHandler(new AcquiringSessionExistsHandler(true)) .libraryAeronChannels(singletonList(IPC_CHANNEL)); library = FixLibrary.connect(configuration); System.out.println("Connecting library"); }
private void connectSession() { // Each outbound session with an Exchange or broker is represented by // a Session object. Each session object can be configured with connection // details and credentials. final SessionConfiguration sessionConfig = SessionConfiguration.builder() .address("localhost", 9999) .targetCompId(ACCEPTOR_COMP_ID) .senderCompId(INITIATOR_COMP_ID) .build(); initiateReply = library.initiate(sessionConfig); state = State.SESSION_CONNECTING; System.out.println("Attempting to connect to exchange"); }
public FixLibrary connect(final LibraryConfiguration configuration) { final FixLibrary library = FixLibrary.connect(configuration); add(library); assertEventuallyTrue( () -> "Unable to connect to engine", () -> { poll(); return library.isConnected(); }, DEFAULT_TIMEOUT_IN_MS, () -> close(library)); return library; }
@Test public void shouldEnableLibraryConnectionsOneAfterAnother() { for (int i = 0; i < 20; i++) { DebugLogger.log(LogTag.FIX_TEST, "Iteration: " + i); acceptingLibrary = testSystem.add(newAcceptingLibrary(acceptingHandler)); while (!acceptingLibrary.isConnected()) { testSystem.poll(); Thread.yield(); } acquireAcceptingSession(); final Reply<SessionReplyStatus> reply = testSystem.awaitReply(acceptingLibrary.releaseToGateway( acceptingSession, DEFAULT_REPLY_TIMEOUT_IN_MS)); assertEquals(SessionReplyStatus.OK, reply.resultIfPresent()); acceptingLibrary.close(); } }
private void awaitIsConnected(final boolean isConnected, final FixLibrary library) { assertEventuallyTrue( "isConnected never became: " + isConnected, () -> { testSystem.poll(); return library.isConnected() == isConnected; }); }
public void onSessionExists( final FixLibrary library, final long surrogateSessionId, final String localCompId, final String localSubId, final String localLocationId, final String remoteCompId, final String remoteSubId, final String remoteLocationId) { final Reply<SessionReplyStatus> reply = library.requestSession( surrogateSessionId, NO_MESSAGE_REPLAY, NO_MESSAGE_REPLAY, CommonConfiguration.DEFAULT_REPLY_TIMEOUT_IN_MS); final RequestInfo requestInfo = new RequestInfo( surrogateSessionId, reply, localCompId, localSubId, localLocationId, remoteCompId); if (printRequests) { System.out.println(requestInfo); } requests.add(requestInfo); }
static void awaitLibraryConnect(final FixLibrary library) { assertEventuallyTrue( () -> "Library hasn't seen Engine", () -> { library.poll(5); return library.isConnected(); }, AWAIT_TIMEOUT, () -> {} ); }
public int doWork() throws Exception { return fixLibrary.poll(1); }
private void shouldCleanupLibraryIfItCannotConnect(final LibraryConfiguration configuration) { configuration.aeronContext().driverTimeoutMs(50); try { FixLibrary.connect(configuration); } catch (final DriverTimeoutException e) { final File monitoringFile = new File(configuration.monitoringFile()); final File histogramLoggingFile = new File(configuration.histogramLoggingFile()); assertFalse(monitoringFile + " hasn't been deleted", monitoringFile.exists()); assertFalse(histogramLoggingFile + " hasn't been deleted", histogramLoggingFile.exists()); } }
static Reply<Session> initiate( final FixLibrary library, final int port, final String initiatorId, final String acceptorId) { final SessionConfiguration config = SessionConfiguration.builder() .address("localhost", port) .credentials(USERNAME, PASSWORD) .senderCompId(initiatorId) .targetCompId(acceptorId) .build(); return library.initiate(config); }
@Test public void libraryShouldRefuseConnectionWhenThereIsNoAcceptor() { launchEngine(); launchLibrary(); assertTrue("Library not connected", initiatingLibrary.isConnected()); initiateResultsInError(); }
static SessionReplyStatus requestSession( final FixLibrary library, final long sessionId, final int lastReceivedMsgSeqNum, final int sequenceIndex, final TestSystem testSystem) { final Reply<SessionReplyStatus> reply = testSystem.awaitReply(library.requestSession( sessionId, lastReceivedMsgSeqNum, sequenceIndex, DEFAULT_REPLY_TIMEOUT_IN_MS)); assertEquals(COMPLETED, reply.state()); return reply.resultIfPresent(); }