public class InstrumentProfileConnection extends Object
The key different between this class and InstrumentProfileReader
is that the later just reads
a snapshot of a set of instrument profiles, while this classes allows to track live updates, e.g.
addition and removal of instruments.
To use this class you need an address of the data source from you data provider. The name of the IPF file can also serve as an address for debugging purposes.
The recommended usage of this class to receive a live stream of instrument profile updates is:
String address = "<host>:<port>";InstrumentProfileCollector
collector = newInstrumentProfileCollector
();InstrumentProfileConnection
connection = InstrumentProfileConnection.createConnection
(address, collector); connection.start
(); collector.addUpdateListener
(newInstrumentProfileUpdateListener
() { public voidinstrumentProfilesUpdated
(Iterator<InstrumentProfile
> instruments) { while (instruments.hasNext()) {InstrumentProfile
instrument = instruments.next(); // do something with instrument here. } } });
If long-running processing of instrument profile is needed, then it is better to use
instrumentProfilesUpdated
notification
to schedule processing task in a separate thread.
This class is thread-safe.
Modifier and Type | Class and Description |
---|---|
static class |
InstrumentProfileConnection.State
Instrument profile connection state.
|
Modifier and Type | Method and Description |
---|---|
void |
addStateChangeListener(PropertyChangeListener listener)
Adds listener that is notified about changes in
state property. |
void |
close()
Closes this instrument profile connection.
|
static InstrumentProfileConnection |
createConnection(String address,
InstrumentProfileCollector collector)
Creates instrument profile connection with a specified address and collector.
|
String |
getAddress()
Returns the address of this instrument profile connection.
|
long |
getLastModified()
Returns last modification time (in milliseconds) of instrument profiles or zero if it is unknown.
|
InstrumentProfileConnection.State |
getState()
Returns state of this instrument profile connections.
|
long |
getUpdatePeriod()
Returns update period in milliseconds.
|
void |
removeStateChangeListener(PropertyChangeListener listener)
Removes listener that is notified about changes in
state property. |
void |
setUpdatePeriod(long updatePeriod)
Changes update period in milliseconds.
|
void |
start()
Starts this instrument profile connection.
|
String |
toString()
Returns a string representation of the object.
|
boolean |
waitUntilCompleted(long timeout,
TimeUnit unit)
Synchronously waits for full first snapshot read with the specified timeout.
|
public static InstrumentProfileConnection createConnection(String address, InstrumentProfileCollector collector)
update period
via an address string.
Default update period is 1 minute.
Connection needs to be started
to begin an actual operation.
address
- address.collector
- instrument profile collector to push updates into.public String getAddress()
public long getUpdatePeriod()
address string
.public void setUpdatePeriod(long updatePeriod)
updatePeriod
- update period in milliseconds.getUpdatePeriod()
public InstrumentProfileConnection.State getState()
public long getLastModified()
public void start()
CONNECTING
and the actual connection establishment proceeds in the background.public void close()
CLOSED
and the background update procedures are terminated.public void addStateChangeListener(PropertyChangeListener listener)
state
property.
Installed listener can be removed with
removeStateChangeListener
method.listener
- the listener to add.public void removeStateChangeListener(PropertyChangeListener listener)
state
property.
It removes the listener that was previously installed with
addStateChangeListener
method.listener
- the listener to remove.public boolean waitUntilCompleted(long timeout, TimeUnit unit)
timeout
- the maximum time to waitunit
- the time unit of the timeout
argumenttrue
if COMPLETED
state was reached and false
if the waiting time elapsed before snapshot was fully read.Copyright © 2002–2023 Devexperts LLC. All rights reserved.