void start(String id) { this.id = id; this.running.set(true); String name = (this.connection.getOptions().getConnectionName() != null) ? this.connection.getOptions().getConnectionName() : "Nats Connection"; this.thread = new Thread(this, name + " Dispatcher"); this.thread.start(); }
void start(Future<DataPort> dataPortFuture) { this.dataPortFuture = dataPortFuture; this.running.set(true); this.stopped = new CompletableFuture<>(); // New future String name = (this.connection.getOptions().getConnectionName() != null) ? this.connection.getOptions().getConnectionName() : "Nats Connection"; this.thread = new Thread(this, name + " Reader"); this.thread.start(); }
void start(Future<DataPort> dataPortFuture) { this.dataPortFuture = dataPortFuture; this.running.set(true); this.stopped = new CompletableFuture<>(); // New future String name = (this.connection.getOptions().getConnectionName() != null) ? this.connection.getOptions().getConnectionName() : "Nats Connection"; this.thread = new Thread(this, name + " Writer"); this.thread.start(); }
void start(String id) { this.id = id; this.running.set(true); String name = (this.connection.getOptions().getConnectionName() != null) ? this.connection.getOptions().getConnectionName() : "Nats Connection"; this.thread = new Thread(this, name + " Dispatcher"); this.thread.start(); }
void start(Future<DataPort> dataPortFuture) { this.dataPortFuture = dataPortFuture; this.running.set(true); this.stopped = new CompletableFuture<>(); // New future String name = (this.connection.getOptions().getConnectionName() != null) ? this.connection.getOptions().getConnectionName() : "Nats Connection"; this.thread = new Thread(this, name + " Reader"); this.thread.start(); }
void start(Future<DataPort> dataPortFuture) { this.dataPortFuture = dataPortFuture; this.running.set(true); this.stopped = new CompletableFuture<>(); // New future String name = (this.connection.getOptions().getConnectionName() != null) ? this.connection.getOptions().getConnectionName() : "Nats Connection"; this.thread = new Thread(this, name + " Writer"); this.thread.start(); }
void handleCommunicationIssue(Exception io) { // If we are connecting or disconnecting, note exception and leave statusLock.lock(); try { if (this.connecting || this.disconnecting || this.status == Status.CLOSED) { this.exceptionDuringConnectChange = io; return; } } finally { statusLock.unlock(); } processException(io); // Spawn a thread so we don't have timing issues with // waiting on read/write threads String name = (this.getOptions().getConnectionName() != null) ? this.getOptions().getConnectionName() : "Nats Connection"; Thread t = new Thread(() -> { try { this.closeSocket(true); } catch (InterruptedException e) { processException(e); } }, name + " Reconnect"); t.start(); }
void handleCommunicationIssue(Exception io) { // If we are connecting or disconnecting, note exception and leave statusLock.lock(); try { if (this.connecting || this.disconnecting || this.status == Status.CLOSED) { this.exceptionDuringConnectChange = io; return; } } finally { statusLock.unlock(); } processException(io); // Spawn a thread so we don't have timing issues with // waiting on read/write threads String name = (this.getOptions().getConnectionName() != null) ? this.getOptions().getConnectionName() : "Nats Connection"; Thread t = new Thread(() -> { try { this.closeSocket(true); } catch (InterruptedException e) { processException(e); } }, name + " Reconnect"); t.start(); }
@Test public void testPropertiesStringOptions() throws NoSuchAlgorithmException { Properties props = new Properties(); props.setProperty(Options.PROP_USERNAME, "hello"); props.setProperty(Options.PROP_PASSWORD, "world"); props.setProperty(Options.PROP_CONNECTION_NAME, "name"); Options o = new Options.Builder(props).build(); assertEquals("default verbose", false, o.isVerbose()); // One from a different type assertEquals("property username", "hello", o.getUsername()); assertEquals("property password", "world", o.getPassword()); assertEquals("property connection name", "name", o.getConnectionName()); }
@Test public void testChainOverridesProperties() throws NoSuchAlgorithmException { Properties props = new Properties(); props.setProperty(Options.PROP_TOKEN, "token"); props.setProperty(Options.PROP_CONNECTION_NAME, "name"); Options o = new Options.Builder(props).connectionName("newname").build(); assertEquals("default verbose", false, o.isVerbose()); // One from a different type assertEquals("property token", "token", o.getToken()); assertEquals("property connection name", "newname", o.getConnectionName()); }
@Test public void testNatsConnectionName() throws Exception { try (NatsStreamingTestServer srv = new NatsStreamingTestServer(clusterName, false)) { Options opts = new Options.Builder().natsUrl(srv.getURI()).build(); try (StreamingConnection sc = NatsStreaming.connect(clusterName, clientName, opts)) { Connection nc = sc.getNatsConnection(); assertEquals(clientName, nc.getOptions().getConnectionName()); } } }
@Test public void testChainedStringOptions() throws NoSuchAlgorithmException { Options o = new Options.Builder().userInfo("hello", "world").connectionName("name").build(); assertEquals("default verbose", false, o.isVerbose()); // One from a different type assertEquals("chained username", "hello", o.getUsername()); assertEquals("chained password", "world", o.getPassword()); assertEquals("chained connection name", "name", o.getConnectionName()); }
@Test public void testDefaultOptions() { Options o = new Options.Builder().build(); assertEquals("default one server", 1, o.getServers().size()); assertEquals("default url", Options.DEFAULT_URL, o.getServers().toArray()[0].toString()); assertEquals("default data port type", Options.DEFAULT_DATA_PORT_TYPE, o.getDataPortType()); assertEquals("default verbose", false, o.isVerbose()); assertEquals("default pedantic", false, o.isPedantic()); assertEquals("default norandomize", false, o.isNoRandomize()); assertEquals("default oldstyle", false, o.isOldRequestStyle()); assertEquals("default noEcho", false, o.isNoEcho()); assertEquals("default UTF8 Support", false, o.supportUTF8Subjects()); assertNull("default username", o.getUsername()); assertNull("default password", o.getPassword()); assertNull("default token", o.getToken()); assertNull("default connection name", o.getConnectionName()); assertNull("default ssl context", o.getSslContext()); assertEquals("default max reconnect", Options.DEFAULT_MAX_RECONNECT, o.getMaxReconnect()); assertEquals("default ping max", Options.DEFAULT_MAX_PINGS_OUT, o.getMaxPingsOut()); assertEquals("default reconnect buffer size", Options.DEFAULT_RECONNECT_BUF_SIZE, o.getReconnectBufferSize()); assertEquals("default reconnect wait", Options.DEFAULT_RECONNECT_WAIT, o.getReconnectWait()); assertEquals("default connection timeout", Options.DEFAULT_CONNECTION_TIMEOUT, o.getConnectionTimeout()); assertEquals("default ping interval", Options.DEFAULT_PING_INTERVAL, o.getPingInterval()); assertEquals("default cleanup interval", Options.DEFAULT_REQUEST_CLEANUP_INTERVAL, o.getRequestCleanupInterval()); assertNull("error handler", o.getErrorListener()); assertNull("disconnect handler", o.getConnectionListener()); }