|
||||||||||
| 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.OTConnectionSpec, org.otfeed.event.IConnectionStateListener) method, one have to set
username/password
and at least one host in the hosts.
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.OTConnectionSpec, 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.Set<OTHost> hostList)
Creates new OTConnectionFactory and initializes all its properties. |
|
| Method Summary | |
|---|---|
IConnection |
connect(IConnectionStateListener listener)
Deprecated. |
IConnection |
connect(OTConnectionSpec spec,
IConnectionStateListener list)
Starts asynchronous connection process. |
long |
getConnectTimeoutMillis()
Gets connection timeout (in milliseconds). |
java.util.concurrent.Executor |
getExecutor()
Executor service (factory of threads). |
long |
getHeartbeatIntervalMillis()
Gets heartbeat interval value (in milliseconds). |
java.util.List<OTHost> |
getHostList()
Deprecated. |
java.util.Set<OTHost> |
getHosts()
Returns set of addresses. |
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 |
setExecutor(java.util.concurrent.Executor val)
Sets executor service. |
void |
setHeartbeatIntervalMillis(long val)
Sets heartbeat interval value (in milliseconds). |
void |
setHostList(java.util.List<OTHost> val)
Deprecated. |
void |
setHosts(java.util.Set<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.Set<OTHost> hostList)
username - username.password - password.hostList - list of hosts.| Method Detail |
|---|
public void setUsername(java.lang.String val)
connect(org.otfeed.OTConnectionSpec, org.otfeed.event.IConnectionStateListener)
val - login name.public java.lang.String getUsername()
public void setPassword(java.lang.String val)
connect(org.otfeed.OTConnectionSpec, org.otfeed.event.IConnectionStateListener)
val - login password.public java.lang.String getPassword()
@Deprecated public java.util.List<OTHost> getHostList()
getHosts() instead.
@Deprecated public void setHostList(java.util.List<OTHost> val)
setHosts(java.util.Set) instead.
val - collection of addresses.public java.util.Set<OTHost> getHosts()
session.getHosts().add(new OTHost("feed1.opentick.com", 10015));
session.getHosts().add(new OTHost("feed2.opentick.com", 10015));
Client must configure at least one server address before calling
connect(org.otfeed.OTConnectionSpec, org.otfeed.event.IConnectionStateListener) method. Initially, this list is empty (but not null).
public void setHosts(java.util.Set<OTHost> val)
Set hosts = new HashSet();
hosts.add(new OTHost("feed1.opentick.com", 10015));
hosts.add(new OTHost("feed2.opentick.com", 10015));
session.setHosts(hosts);
Client must configure at least one server address before calling
connect(org.otfeed.OTConnectionSpec, 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 - streamer factory.public java.util.concurrent.Executor getExecutor()
public void setExecutor(java.util.concurrent.Executor val)
val - executor service to use. Default is Executors.newCachedThreadPool().
public IConnection connect(OTConnectionSpec spec,
IConnectionStateListener list)
IConnection object
immediately.
Pass OTConnectionSpec instance as first parameter to
specify connection destination, username/password, and other
connection properties. This parameter is optional. If not used
(meaning user passes null),
values set on the factory instance are used instead.
Note that username, password, and
hosts properties are required.
Use list parameter 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.
connect in interface IConnectionFactoryspec - connection specification. Optional.list - connection state listener. Optional.
java.lang.IllegalStateException - if username/password pair is not set,
or if hostList is empty.@Deprecated public IConnection connect(IConnectionStateListener listener)
IConnectionFactory.connect(OTConnectionSpec, IConnectionStateListener)
method.
connect in interface IConnectionFactory
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||