public final class RT_Consumer
extends java.lang.Object
The RT_Consumer
class is used to connect to a DataFeed server,
request message subscriptions, and dispatch messages from the internal
message queue.
Modifier and Type | Class and Description |
---|---|
class |
RT_Consumer.BulkSubscription
A bulk subscription to a message stream.
|
static class |
RT_Consumer.KeyCounter |
static interface |
RT_Consumer.Subscription
A subscription to a message stream.
|
Constructor and Description |
---|
RT_Consumer(java.lang.String connectionInfo)
Constructs an
RT_Consumer with a user name, password and
host specified by the given string. |
RT_Consumer(java.lang.String[] connectionInfoArray)
Constructs an
RT_Consumer with a set of user names,
passwords and hosts specified by the given string array. |
RT_Consumer(java.lang.String userName,
java.lang.String password,
java.lang.String host,
int port)
Constructs an
RT_Consumer with the given user name,
password, host and port for authenticating using basic auth. |
RT_Consumer(java.lang.String host,
java.lang.String user,
java.lang.String identifier,
java.lang.String key,
java.lang.String counter,
java.lang.String path,
boolean forceInput) |
RT_Consumer(java.lang.String host,
java.lang.String user,
java.lang.String identifier,
java.lang.String key,
java.lang.String counter,
java.lang.String path,
boolean forceInput,
boolean machineAccount) |
RT_Consumer(java.lang.String host,
java.lang.String user,
java.lang.String identifier,
java.lang.String key,
java.lang.String counter,
java.lang.String path,
boolean forceInput,
boolean machineAccount,
java.lang.String configFilepath)
Constructs an
RT_Consumer with the given user name, password,
host and port for authenticating with a machine account using OTP. |
Modifier and Type | Method and Description |
---|---|
void |
asyncConnect()
Asynchronously connects this consumer to a DataFeed server.
|
void |
clearControlHandler()
Cancels future incoming control messages.
|
void |
clearNotifyHandler()
Cancels future invocations of the associated
NotifyHandler
instance. |
void |
connect()
Synchronously connects this consumer to a DataFeed server.
|
boolean |
disable(RT_Feature feature) |
void |
disconnect()
Disconnects this consumer from the DataFeed server.
|
void |
disconnect(boolean keepSubscriptions)
Disconnects this consumer from the DataFeed server and queues the active
subscriptions if
keepSubscriptions is true . |
boolean |
dispatch()
Invokes the handlers associated with all messages received since this
method was last called.
|
boolean |
dispatch(int timeout)
Invokes the handlers associated with all messages received since this
method was last called, with a specified timeout value.
|
boolean |
enable(RT_Feature feature) |
java.lang.String |
getConnectionInfo()
Returns a string representation of the user name, password and host of
this connection.
|
java.lang.String[] |
getConnectionInfoArray()
Returns an array of connection strings used when connecting to a DataFeed
server.
|
RT_Consumer.KeyCounter |
getKeyAndCounter(java.lang.String user,
java.lang.String serial,
java.lang.String passcode) |
java.lang.String[] |
getServices()
Returns a string array containing all services available to this
consumer.
|
boolean |
isActive(RT_Feature feature) |
boolean |
isConnected()
Returns
true if this consumer is connected to a DataFeed
server. |
void |
loadConfig(java.lang.String filepath) |
int |
messageQueueSize() |
static RT_Consumer |
newWorkstationInstance(java.lang.String userName,
java.lang.String password)
Returns an
RT_Consumer for connecting to a FactSet
workstation on the current machine, using the given user name and
password. |
void |
registerDevice(java.lang.String userIps) |
RT_Consumer.Subscription |
request(RT_Request req,
MessageHandler handler)
Makes a request to the DataFeed server for a subscription to a real-time
data stream.
|
void |
requestPasscode(java.lang.String user,
java.lang.String serial) |
void |
setControlHandler(ControlHandler handler)
Sets the
ControlHandler instance to be notified when a
control event occurs. |
void |
setNotifyHandler(NotifyHandler handler)
Registers the
NotifyHandler instance to be invoked when
there are messages ready to be dispatched. |
void |
setSendUnchangedFields(java.lang.Boolean enable) |
java.lang.String |
toString()
Returns a brief description of this consumer.
|
public RT_Consumer(java.lang.String connectionInfo)
RT_Consumer
with a user name, password and
host specified by the given string.
connectionInfo
must be in the form of
"USER:PASSWORD@HOSTNAME:PORT". The only required parameter of the
connection string is the host name. The constructor does not check that
the host is valid or the IP address can be resolved.
connectionInfo
- a string containing a user name, password and host of a
DataFeed serverjava.lang.IllegalArgumentException
- if the specified port is outside the range of valid port
valuesjava.lang.NullPointerException
- if connectionInfo
is nullpublic RT_Consumer(java.lang.String userName, java.lang.String password, java.lang.String host, int port)
RT_Consumer
with the given user name,
password, host and port for authenticating using basic auth.
The constructor does not check that the host is valid or the
IP address can be resolved.userName
- a string containing the user name to login withpassword
- a string containing the password to login withhost
- a string containing the hostname of a DataFeed serverport
- a port of a DataDeed serverpublic RT_Consumer(java.lang.String host, java.lang.String user, java.lang.String identifier, java.lang.String key, java.lang.String counter, java.lang.String path, boolean forceInput, boolean machineAccount, java.lang.String configFilepath)
RT_Consumer
with the given user name, password,
host and port for authenticating with a machine account using OTP. The
constructor does not check that the host is valid or the IP address can be
resolved.host
- a string containing hostname of a DataFeed serveruser
- a string containing the user to login withidentifier
- a string containing the identifier for this user; for machine
accounts this must be the deviceId used during key generation, for
individual accounts this can be any stringkey
- a string containing the OTP key or null if using a filecounter
- a string containing the OTP counter or null if using a filepath
- a string containing the path to save the counter file and look for
an existing fileforceInput
- if true, will use the supplied key/counter instead of the contents
of an existing filemachineAccount
- true if the account authenticating is a machine account, false
otherwiseconfigFilepath
- path to the fdsrt config filepublic RT_Consumer(java.lang.String host, java.lang.String user, java.lang.String identifier, java.lang.String key, java.lang.String counter, java.lang.String path, boolean forceInput, boolean machineAccount)
public RT_Consumer(java.lang.String host, java.lang.String user, java.lang.String identifier, java.lang.String key, java.lang.String counter, java.lang.String path, boolean forceInput)
public RT_Consumer(java.lang.String[] connectionInfoArray)
RT_Consumer
with a set of user names,
passwords and hosts specified by the given string array. When a connect
method is called, this RT_Consumer
will attempt to connect
using each connection string in the given array until a valid connection
has been established.
Each connection string in the given array must be in the form of "USER:PASSWORD@HOSTNAME:PORT". The only required parameter of the connection string is the host name. The constructor does not check that the host is valid or the IP address can be resolved.
connectionInfoArray
- an array of strings, each containing a user name, password and
host of a DataFeed serverpublic static RT_Consumer newWorkstationInstance(java.lang.String userName, java.lang.String password)
RT_Consumer
for connecting to a FactSet
workstation on the current machine, using the given user name and
password. Note: This method is only supported in Windows environments.
userName
- a string containing the user name to login withpassword
- a string containing the password to login withRT_Consumer
instance.public void loadConfig(java.lang.String filepath) throws java.io.IOException
java.io.IOException
public void requestPasscode(java.lang.String user, java.lang.String serial) throws java.io.IOException
java.io.IOException
public RT_Consumer.KeyCounter getKeyAndCounter(java.lang.String user, java.lang.String serial, java.lang.String passcode) throws java.io.IOException
java.io.IOException
public void setControlHandler(ControlHandler handler)
ControlHandler
instance to be notified when a
control event occurs. Only one ControlHandler
can be
registered at a time.
Control messages typically indicate events such as a connection, a disconnection, a service attachment, etc.
handler
- the ControlHandler
that will receive control
messagesjava.lang.NullPointerException
- if handler
is nullControlHandler
public void clearControlHandler()
ControlHandler
will no longer be notified when control
events occur.public java.lang.String getConnectionInfo()
The returned string is of the form "USER:PASSWD@HOSTNAME:PORT".
public java.lang.String[] getConnectionInfoArray()
Each string in the returned array is of the form "USER:PASSWD@HOSTNAME:PORT".
public void connect() throws java.net.UnknownHostException, java.io.IOException, javax.security.auth.login.LoginException
This method will block until a valid connection to a DataFeed server is established or a connection error has been encountered.
This method or asyncConnect()
must be successfully invoked before
dispatching any messages.
If this instance of RT_Consumer
was created with
newWorkstationInstance(String, String)
, the FactSet workstation
program must be running when this method is called or an
UnknownHostException
will be thrown.
java.net.UnknownHostException
- if the host name cannot be resolved or this is a workstation
instance and communication could not be established with the
FactSet workstation programjava.io.IOException
- if an I/O error occurs while establishing a connection to the
DataFeed serverjavax.security.auth.login.LoginException
- if the username or password specified in the constructor are
incorrectpublic void asyncConnect() throws java.io.IOException
This method initiates a non-blocking connection and returns immediately.
If an exception is not thrown, the connection is in progress. The
registered ControlHandler
will be notified of the results of
the connection attempt.
If an exception is thrown, a connection will never be established. This
method or connect()
must be successfully invoked before
dispatching any messages.
java.io.IOException
- if an I/O error occurs while initiating a non-blocking
connection to the DataFeed serverpublic void disconnect()
public void disconnect(boolean keepSubscriptions)
keepSubscriptions
is true
.
If active subscriptions are queued, this method will generate "stale"
messages and the associated MessageHandler
instances are
invoked. If a valid connection is reestablished, the subscriptions will
become active again.
keepSubscriptions
- if true
, active subscriptions will be queuedpublic boolean isConnected()
true
if this consumer is connected to a DataFeed
server.
If this consumer loses the TCP connection to a DataFeed server, "stale"
messages will be generated and the associated MessageHandler
instances will be invoked. The API will periodically try to reestablish
the connection. When the connection is reestablished, the registered
ControlHandler
will be notified and the staled subscriptions
will become active.
true
if connected to a DataFeed server;
false
otherwisepublic RT_Consumer.Subscription request(RT_Request req, MessageHandler handler)
This method can be invoked at any time. If this consumer does not have a
valid connection or the requested service is not available at the time of
invocation, the request will be queued and the returned
Subscription
instance will have the isQueued
flag set to true
. When the connection is established or the
requested service is attached, the request will be sent to the DataFeed
server.
req
- the RT_Request
instance describing the properties
of the subscriptionhandler
- the MessageHandler
instance that will be invoked
when a message is received for the subscriptionRT_Consumer.Subscription
uniquely identifies the
resulting subscriptionjava.lang.NullPointerException
- if handler
is nullpublic boolean dispatch()
This method flushes the internal message queue. If there are no messages
to dispatch, it returns immediately. If there are subscription or control
messages in the queue, the associated ControlHandler
and/or
MessageHandler
instances are invoked. This method always returns
after the internal message queue has been flushed. It should be invoked
in a loop or when notified via the NotifyHandler
interface.
The connect()
method must be successfully invoked before this
method can be invoked. In addition, this method cannot be invoked from
within the NotifyHandler.onNotify()
method.
true
if this consumer is connected to a DataFeed
server; false
otherwisejava.lang.IllegalStateException
- if the connect
or asyncConnect
methods have not been invoked, if the dispatch
method has been called concurrently, or if the
dispatch
method has been invoked from the
onNotify
method of a NotifyHandler
instancepublic boolean dispatch(int timeout)
This method flushes the internal message queue. It will block for a
maximum time specified by timeout
or until a message there
are messages to dispatch. A negative timeout is interpreted as an
infinite timeout. If there are subscription or control messages in the
queue, the associated ControlHandler
and/or
MessageHandler
instances are invoked. This method always returns
after the internal message queue has been flushed. It should be invoked
in a loop or when notified via the NotifyHandler
interface.
The connect()
method must be successfully invoked before this
method can be invoked. In addition, this method cannot be invoked from
within the NotifyHandler.onNotify()
method or the
MessageHandler.onMessage(com.factset.rt.RT_Consumer.Subscription, com.factset.rt.RT_Message)
method.
timeout
- a timeout value to be used, in millisecondstrue
if this consumer is connected to a DataFeed
server; false
otherwisejava.lang.IllegalStateException
- if the connect
or asyncConnect
methods have not been invoked, if the dispatch
method has been called concurrently, or if the
dispatch
method has been invoked from the
onNotify
method of a NotifyHandler
instancepublic void setSendUnchangedFields(java.lang.Boolean enable)
public java.lang.String[] getServices()
public void setNotifyHandler(NotifyHandler handler)
NotifyHandler
instance to be invoked when
there are messages ready to be dispatched. Only one
NotifyHandler
can be registered at a time.handler
- the NotifyHandler
instance that will be invokedjava.lang.NullPointerException
- if handler
is nullpublic void clearNotifyHandler()
NotifyHandler
instance. The currently registered NotifyHandler
instance
will no longer be invoked when there are messages to dispatch.public boolean enable(RT_Feature feature)
public boolean disable(RT_Feature feature)
public boolean isActive(RT_Feature feature)
public void registerDevice(java.lang.String userIps)
public java.lang.String toString()
toString
in class java.lang.Object
public int messageQueueSize()