Adds a new IConnection object to this ConnectionManager's connection list. The connection list specifies the connections that should be attempted, in the order they were added, when connecting to Union Server. To connect to Union Server, use the Orbiter.connect method or the ConnectionManager.connect method.
Attempts to connect to Union Server using the currently specified list of connection objects. If any of the connections in the list succeeds, ConnectionManager dispatches the ConnectionManagerEvent.READY event, and the Orbiter object dispatches a OrbiterEvent.READY event. If, however, all of the connections in the list fail, ConnectionManager dispatches the ConnectionManagerEvent.CONNECT_FAILURE event, and the Orbiter object dispatches a OrbiterEvent.CLOSE event.
Applications that use ConnectionManager's connect() method directly must first add at least one Connection object to the ConnectionManager.
Connections are attempted in the order they were added to the connection list.
Each time the ConnectionManager moves to the next connection in its list, it triggers the ConnectionManagerEvent.SELECT_CONNECTION event.
Note, however, that the ConnectionManager class's connect() method is not used directly by most applications. Instead, to connect to the server, applications typically use the Orbiter class's more convenient connect() method, which delegates its work to the ConnectionManager class's connect() method.
However, note that while the Orbiter class's version of connect() is less verbose than ConnectionManager's connect() method, it cannot specify multiple hosts for multiple connections.
Terminates any open connection to the server. If the disconnection attempt succeeds, ConnectionManager dispatches the ConnectionManagerEvent.CLIENT_KILL_CONNECT and ConnectionManagerEvent.DISCONNECT events, and the Orbiter object dispatches an OrbiterEvent.CLOSE event.
Permanently disables this object and releases all of its resources. Once dispose() is called, the object can never be used again. Use dispose() only when purging an object from memory.
To simply disconnect from Union Server, use disconnect, not dispose().
If a connection is currently connected, getActiveConnection() returns that connection; otherwise, getActiveConnection() returns null.
Returns the actual server address that will be used when a connection to the specified host is requested. When the current client connects to a Union Server cluster, and the specified host is a DNS server that forwards connection requests to a server node in the cluster, getAffinity() returns the address (public name or IP) of that server node. Similarly, when the current client connects to a DNS server that redirects to a Union Server instance, getAffinity() returns the address (public name or IP) of that instance. When the current client connects to a Union Server instance directly, the address returned by getAffinity() is always identical to the supplied host.
Returns an integer indicating the number of times this ConnectionManager object has aborted an in-progress connection attempt since the last successful connection was made.
Returns an integer indicating the number of times this ConnectionManager object has attempted to connect to the server since the last successful connection was established.
Returns an integer indicating the number of failed connection attempts this ConnectionManager object has made since the last successful connection was established. Whenever a successful connection is established, the connect-failed count returns to zero.
Returns the ConnectionManager's current state. For a list of possible states, see the ConnectionState class.
Returns a one-time snapshot of the ConnectionManager's connection list, as an Array. Each element of the array is an Connection object.
Returns the connection that would be opened next if connect were called.
If a connection is currently in progress, getInProgressConnection() returns that connection; otherwise, getInProgressConnection() returns null.
Returns an integer indicating the number of times this ConnectionManager object has successfully established a valid connection to the server. The count is increased when the ConnectionEvent.READY event occurs.
The maximum time each Connection object allows for its setup phase to complete when attempting to connect to Union Server.
Returns a Boolean indicating whether the ConnectionManager currently has an active connection to Union Server.
Returns true if Orbiter is currently connected to the server; false otherwise.
Removes all Connection objects from this ConnectionManager's connection list. Any connection that is currently open will be disconnected. Until new connections are added via addConnection, subsequent calls to connect or disconnect will fail.
Removes the specified Connection object from this ConnectionManager's connection list. If the connection is currently open, it is disconnected before removal.
Sets the ConnectionManager's current state.
Specifies whether the current client's ConnectionManager will use global server affinity or local server affinity. When enabled is true (default), server affinity is set to global, and the ConnectionManager uses the affinity value shared by all clients in the current environment. When enabled is false, server affinity is set to local, and the ConnectionManager for the current client maintains its own, individual server affinity.
For example, imagine a client application with two Orbiter instances, both of which connect to a Union Server cluster. The cluster is accessed via a round-robin DNS server, pool.example.com, and server affinity is global. The first Orbiter instance connects to pool.example.com, and is redirected to slave1.example.com. Upon connection, the affinity address slave1.example.com is assigned for host pool.example.com. Then the second Orbiter instance connects. Because affinity is global, the second Orbiter instance finds affinity address slave1.example.com for host pool.example.com, and connects directly to slave1.example.com, bypassing pool.example.com entirely.
Now imagine the same application with server affinity set to local. The first Orbiter instance connects to pool.example.com, and is redirected to slave1.example.com as before. Upon connection, the affinity address slave1.example.com is assigned for host pool.example.com. Then the second Orbiter instance connects. Because affinity is local, the second Orbiter instance has no affinity established for pool.example.com, and therefore connects to pool.example.com, not slave1.example.com. The pool.example.com DNS server redirects the second Orbiter instance to slave2.example.com. Upon connection, the affinity address slave2.example.com is assigned for host pool.example.com in the second Orbiter instance's affinity map. For the duration specified by the server's affinity configuration, the first Orbiter instance communicates with slave1.example.com and the second Orbiter instance communicates with slave2.example.com. Compare with the preceding global affinity example, where the first Orbiter instance and the second Orbiter instance both communicate with slave1.example.com.
Sets the maximum time each Connection object allows for its setup phase to complete when attempting to connect to Union Server.
When an Connection object attempts to connect to Union Server, it starts a "handshake" process during which client setup tasks (such as issuing a client ID) are performed. If the setup tasks are not completed within an allowed limit known as the "ready timeout," then the Connection object considers the setup process a failure and automatically aborts the connection attempt. If, on the other hand, the client setup process completes within the ready-timeout limit, then the Connection object considers the setup process a success and triggers a ConnectionEvent.READY event indicating that the connection is ready for use. The ready timeout defaults to 10 seconds, but can be changed via the setReadyTimeout() method.
Once an Connection object achieves a ready state,Orbiter continues to monitor the connection to the server by sending regular heartbeat messages. By default, one heartbeat message is sent every 10 seconds, but the heartbeat message frequency is configurable via ConnectionMonitor.setHeartbeatFrequency method. If Union Server takes longer than 60 seconds (by default) to respond to single heartbeat, Orbiter will automatically disconnect. To change the duration that Orbiter will tolerate for a heartbeat response, use ConnectionMonitor.setConnectionTimeout method.
The time within which a connection must achieve a ready state, in milliseconds.
The following code lengthens the default ready timeout to 20 seconds. As a result, Orbiter will automatically disconnect from Union Server when the client-setup process does not complete within 20 seconds.
const orbiter = new Orbiter();
orbiter.getConnectionManager().setReadyTimeout(20000);
The ConnectionManager class manages all connections made by an application to Union Server. In most applications, the ConnectionManager class is not used directly. Instead, connections to Union Server are made via the Orbiter.connect method, and disconnections are requested via the Orbiter.disconnect method. However, ConnectionManager provides more control over the connection process than the Orbiter class offers. Specifically, the ConnectionManager provides the following services:
Note, however, that when socket connections are configured manually via addConnection(), any desired backup HTTP connections must also be configured manually.var connectionManager = orbiter.getConnectionManager(); connectionManager.addConnection(new XMLSocketConnection("example.com", 80)); connectionManager.addConnection(new XMLSocketConnection("tryunion.com", 80)); connectionManager.connect();
To access the ConnectionManager, use Orbiter.getConnectionManager method.