|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.otfeed.OTConnectionFactory
public class OTConnectionFactory
Factory of connections to the OpenTick service. This is the root object of the OpenTick client API. It is used to establish a connection to the OpenTick service.
Before calling the connect(org.otfeed.event.IConnectionStateListener)
method, one have to set
username
/password
and at least one host in the hostList
.
OTConnectionFactory factory = new OTConnectionFactory(); factory.setUsername("super-trooper"); factory.setPassword("kick-me"); factory.getHostList().add(new OTHost("feed1.opentick.com", 10015)); IConnection connection = factory.connect(null); ListExchangesCommand command = new ListExchangesCommand(new IDataDelegate{ public void onData(OTExchange exchange) { System.out.println(exchange); } }); IRequest request = connection.prepareRequest(command); request.submit(); request.waitForCompletion(); connection.shutdown(); connection.waitForCompletion();
connect(org.otfeed.event.IConnectionStateListener)
method multiple times. However, this is not
recommended. The reasons are: the avoidance of synchronization issues, and
conservation of resources.
Synchronization is a concern, because listener methods are called by a separate event-dispatching thread. Every connection starts its own event-displatching thread.
Resources are a concern, because each connection takes a significant amount of resources. For example, current implementation creates three threads and one client socket per connection.
Therefore, the recommentded practice is to limit number of connections
(e.g. work with a single connection per whole application). Each connection
can handle unlimited number of simultaneous requests very efficiently.
Another benefit of having just a single connection per application is
that one can avoid need for synchronization by assuming that all business
logic is done by the event-dispatching thread. When needed, calls from
outside can be translated to the event-dispatching thread by calling
IConnection.runInEventThread(java.lang.Runnable)
method on the connection object.
OTPooledConnectionFactory
class can be used to simulate "simultaneous"
connections while keeping only a single actual connection to the Opentick server.
Constructor Summary | |
---|---|
OTConnectionFactory()
Creates new OTConnectionFactory. |
|
OTConnectionFactory(java.lang.String username,
java.lang.String password,
java.util.List<OTHost> hostList)
Creates new OTConnectionFactory and initializes all its properties. |
Method Summary | |
---|---|
IConnection |
connect(IConnectionStateListener list)
Starts asynchronous connection process. |
long |
getConnectTimeoutMillis()
Gets connection timeout (in milliseconds). |
long |
getHeartbeatIntervalMillis()
Gets heartbeat interval value (in milliseconds). |
java.util.List<OTHost> |
getHostList()
Returns list of servers. |
java.lang.String |
getPassword()
Gets login password. |
IStreamerFactory |
getStreamerFactory()
Low-level IO object, responsible for connecting and delivering/receiving raw frames. |
java.lang.String |
getUsername()
Gets login name. |
void |
setConnectTimeoutMillis(long val)
Sets connection timeout (in milliseconds). |
void |
setHeartbeatIntervalMillis(long val)
Sets heartbeat interval value (in milliseconds). |
void |
setHostList(java.util.List<OTHost> val)
Sets list of servers. |
void |
setPassword(java.lang.String val)
Sets login password. |
void |
setStreamerFactory(IStreamerFactory val)
Sets streamer factory. |
void |
setUsername(java.lang.String val)
Sets login name. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public OTConnectionFactory()
public OTConnectionFactory(java.lang.String username, java.lang.String password, java.util.List<OTHost> hostList)
username
- username.password
- password.hostList
- list of hosts.Method Detail |
---|
public void setUsername(java.lang.String val)
connect(org.otfeed.event.IConnectionStateListener)
val
- login name.public java.lang.String getUsername()
public void setPassword(java.lang.String val)
connect(org.otfeed.event.IConnectionStateListener)
val
- login password.public java.lang.String getPassword()
public java.util.List<OTHost> getHostList()
session.getHostList().add(new OTHost("feed1.opentick.com", 10015)); session.getHostList().add(new OTHost("feed2.opentick.com", 10015));Client must configure at least one server address before calling
connect(org.otfeed.event.IConnectionStateListener)
method. Initially, this list is empty (but not null).
public void setHostList(java.util.List<OTHost> val)
ListClient must configure at least one server address before callinghosts = new LinkedList (); hosts.add(new OTHost("feed1.opentick.com", 10015)); hosts.add(new OTHost("feed2.opentick.com", 10015)); session.setHostList(hosts);
connect(org.otfeed.event.IConnectionStateListener)
method.
val
- list of server addresses.public void setConnectTimeoutMillis(long val)
val
- connection timeout value.public long getConnectTimeoutMillis()
public void setHeartbeatIntervalMillis(long val)
val
- heartbeat interval value.public long getHeartbeatIntervalMillis()
public IStreamerFactory getStreamerFactory()
LoginStreamerFactory.getStreamerFactory()
.
You may want to change this only for the puproses of
testing, debugging, or mocking.
public void setStreamerFactory(IStreamerFactory val)
val
- stremaer factory.public IConnection connect(IConnectionStateListener list)
IConnection
object
immediately.
Use list
paramater to monitor the connection progress.
For more details, see IConnectionStateListener
.
If caller is not interested in monitoring connection progress,
it can pass null as list
paramater.
Valid username
and password
,
and non-empty hostList
must be set before
calling this method.
connect
in interface IConnectionFactory
list
- connection state listener.
java.lang.IllegalStateException
- if username/password pair is not set,
or if hostList is empty.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |