public class FS4Channel extends Object
Modifier and Type | Field and Description |
---|---|
private Backend |
backend |
private Integer |
channelId |
private boolean |
isPingChannel |
private static Logger |
log |
private Query |
query |
private BlockingQueue<BasicPacket> |
responseQueue |
Modifier | Constructor and Description |
---|---|
protected |
FS4Channel()
for unit testing.
|
protected |
FS4Channel(Backend backend,
Integer channelId) |
Modifier and Type | Method and Description |
---|---|
protected void |
addPacket(BasicPacket packet)
Add incoming packet to the response queue.
|
void |
close()
Closes the channel
|
static FS4Channel |
createPingChannel(Backend backend) |
Optional<Integer> |
distributionKey()
Returns the distribution key of the content node this represents, or empty if it is a dispatch node
|
private void |
ensureValid()
This method is called whenever we want to perform an operation
which assumes that the FS4Channel object is valid.
|
private BlockingQueue<BasicPacket> |
ensureValidQ()
This method is called whenever we want to perform an operation
which assumes that the FS4Channel object is valid.
|
Integer |
getChannelId()
Returns the (fs4) channel id
|
Query |
getQuery()
Get the query currently associated with this channel
|
private static boolean |
hasEnoughPackets(int packetCount,
List<BasicPacket> packets) |
private static boolean |
isLastPacket(BasicPacket packet)
Returns true if we will definitely receive more packets on this stream
Shouldn't that be "_not_ receive more packets"?
|
boolean |
isValid()
A valid FS4Channel is one that has not yet been closed.
|
BasicPacket |
nextPacket(long timeout)
Return the next available packet from the response queue.
|
BasicPacket[] |
receivePackets(long timeout,
int packetCount)
Receives the given number of packets and returns them, OR
Returns a smaller number of packets if an error or eol packet is received
Throws a ChannelTimeoutException if timeout occurs before all packets
are received.
|
boolean |
sendPacket(BasicPacket packet)
Legacy interface.
|
void |
setQuery(Query query)
Set the query currently associated with this channel
|
String |
toString() |
private static Logger log
private Integer channelId
private Backend backend
private volatile BlockingQueue<BasicPacket> responseQueue
private Query query
private boolean isPingChannel
public static FS4Channel createPingChannel(Backend backend)
public void setQuery(Query query)
public Query getQuery()
public Integer getChannelId()
public Optional<Integer> distributionKey()
public void close()
public boolean sendPacket(BasicPacket packet) throws InvalidChannelException, IOException
InvalidChannelException
IOException
public BasicPacket[] receivePackets(long timeout, int packetCount) throws InvalidChannelException, ChannelTimeoutException
timeout
- the number of ms to attempt to get packets before throwing an exceptionpacketCount
- the number of packets to receive, or -1 to receive any number up to eol/errorInvalidChannelException
ChannelTimeoutException
private static boolean hasEnoughPackets(int packetCount, List<BasicPacket> packets)
private static boolean isLastPacket(BasicPacket packet)
public BasicPacket nextPacket(long timeout) throws InterruptedException, InvalidChannelException
timeout
milliseconds before returning a null
timeout
- Number of milliseconds to wait for a packet
to become available.BasicPacket
or
null
if we timed out.InterruptedException
InvalidChannelException
protected void addPacket(BasicPacket packet) throws InterruptedException, InvalidChannelException
packet
- BasicPacket to be placed in the response queue.InterruptedException
InvalidChannelException
public boolean isValid()
true
if the FS4Channel is valid.private void ensureValid() throws InvalidChannelException
InvalidChannelException
- if the channel is no longer valid.private BlockingQueue<BasicPacket> ensureValidQ() throws InvalidChannelException
InvalidChannelException
- if the channel is no longer valid.Copyright © 2018. All rights reserved.