public abstract class AbstractBatchGetRequest<RecordType extends ChannelRecord> extends java.lang.Object implements BatchConnectionRequestListener
Constructor and Description |
---|
AbstractBatchGetRequest(java.util.Collection<Channel> channels)
Primary Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addBatchGetRequestListener(BatchGetRequestListener<RecordType> listener)
add the specified listener as a receiver of batch get request events from this instance
|
void |
addChannel(Channel channel)
add a new channel to the batch request
|
boolean |
await(double timeout)
Synonym for waitForCompletion.
|
void |
batchConnectionRequestCompleted(BatchConnectionRequest connectionRequest,
int connectedCount,
int disconnectedCount,
int exceptionCount)
event indicating that the batch request is complete
|
void |
connectionChangeInBatch(BatchConnectionRequest connectionRequest,
Channel channel,
boolean connected)
event indicating that a connection change has occurred for a channel
|
void |
connectionExceptionInBatch(BatchConnectionRequest connectionRequest,
Channel channel,
java.lang.Exception exception)
event indicating that an exception has been thrown for a channel
|
protected void |
finalize()
dispose of the executors
|
java.util.Collection<Channel> |
getChannels()
get the collection of channels to process
|
java.lang.Exception |
getException(Channel channel)
Get the exception if any for the specified channel
|
int |
getExceptionCount()
Get the number of exceptions
|
java.util.Set<Channel> |
getFailedChannels()
Get the failed channels for which exceptions were thrown during the request
|
RecordType |
getRecord(Channel channel)
Get the record if any for the specified channel
|
int |
getRecordCount()
get the number of records
|
java.util.Set<Channel> |
getResultChannels()
Get the channels which produced a result
|
boolean |
hasExceptions()
determine if there were any exceptions
|
boolean |
isComplete()
determine if there are any channels pending for either an exception or a completed get request
|
protected void |
processCurrentStatus()
check for the current status and post notifications if necessary
|
protected void |
processRecordEvent(Channel channel,
RecordType record)
Process the receipt of a new record event
|
protected void |
processRequest(Channel channel)
Process the get request for a single channel
|
void |
removeBatchGetRequestListener(BatchGetRequestListener<RecordType> listener)
remove the specified listener from receiving batch get request events from this instance
|
protected abstract void |
requestChannelData(Channel channel)
Request to get the data for the channel
|
void |
submit()
submit as a batch the get requests for each channel
|
boolean |
submitAndWait(double timeout)
Submit a batch of get requests and wait for the requests to be completed or timeout.
|
boolean |
waitForCompletion(double timeout)
Wait up to the specified timeout for completion.
|
public AbstractBatchGetRequest(java.util.Collection<Channel> channels)
channels
- the channels for which get requests will be handledprotected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public void addBatchGetRequestListener(BatchGetRequestListener<RecordType> listener)
listener
- a receiver which will receive eventspublic void removeBatchGetRequestListener(BatchGetRequestListener<RecordType> listener)
listener
- receiver to remove from receiving eventspublic void addChannel(Channel channel)
channel
- a channel to add to the batch requestpublic java.util.Collection<Channel> getChannels()
public void submit()
public boolean submitAndWait(double timeout)
timeout
- the maximum time in seconds to wait for completionpublic boolean await(double timeout)
timeout
- the maximum time in seconds to wait for completionpublic boolean waitForCompletion(double timeout)
timeout
- the maximum time in seconds to wait for completionprotected abstract void requestChannelData(Channel channel) throws java.lang.Exception
channel
- the channel for which to request datajava.lang.Exception
- when the request failsprotected void processRequest(Channel channel)
channel
- the channel for which to process the requestpublic boolean isComplete()
public boolean hasExceptions()
public int getRecordCount()
public int getExceptionCount()
public RecordType getRecord(Channel channel)
channel
- the channel for which the record is fetchedpublic java.lang.Exception getException(Channel channel)
channel
- the channel for which the exception is fetchedpublic java.util.Set<Channel> getFailedChannels()
public java.util.Set<Channel> getResultChannels()
protected void processRecordEvent(Channel channel, RecordType record)
channel
- the channel for which the event will be processedrecord
- the fetched recordprotected void processCurrentStatus()
public void batchConnectionRequestCompleted(BatchConnectionRequest connectionRequest, int connectedCount, int disconnectedCount, int exceptionCount)
batchConnectionRequestCompleted
in interface BatchConnectionRequestListener
connectionRequest
- request for which the connection completedconnectedCount
- number of channels connecteddisconnectedCount
- number of channels disconnectedexceptionCount
- number of channels for which there were connection exceptionspublic void connectionExceptionInBatch(BatchConnectionRequest connectionRequest, Channel channel, java.lang.Exception exception)
connectionExceptionInBatch
in interface BatchConnectionRequestListener
connectionRequest
- in which the exception occuredchannel
- for which the exception occuredexception
- the exception thrown while attempting to connectpublic void connectionChangeInBatch(BatchConnectionRequest connectionRequest, Channel channel, boolean connected)
connectionChangeInBatch
in interface BatchConnectionRequestListener
connectionRequest
- in which the connection changedchannel
- for which the connection changedconnected
- status of the connection (true for connected and false for disconnected)