public class Backend extends Object implements com.yahoo.io.ConnectionFactory
Modifier and Type | Class and Description |
---|---|
static class |
Backend.BackendStatistics |
Modifier and Type | Field and Description |
---|---|
private Map<Integer,FS4Channel> |
activeChannels |
private InetSocketAddress |
address |
private boolean |
areInSocketNotConnectableState
Whether we are currently in the state of not being able to connect, to avoid repeated logging
|
private int |
channelId |
private AtomicInteger |
connectionCount |
private ConnectionPool |
connectionPool |
private String |
host |
private ListenerPool |
listeners |
private static Logger |
log |
private PacketDumper |
packetDumper |
private PacketListener |
packetListener |
private LinkedList<FS4Channel> |
pingChannels |
private int |
port |
private boolean |
shutdownInitiated |
Modifier | Constructor and Description |
---|---|
protected |
Backend()
For unit testing.
|
|
Backend(String host,
int port,
String serverDiscriminator,
ListenerPool listenerPool,
ConnectionPool connectionPool) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
private void |
connectSocket(SocketChannel socket) |
private FS4Connection |
createConnection()
Create a new connection to the target for this backend.
|
void |
dumpPackets(PacketDumper.PacketType packetType,
boolean on) |
(package private) InetSocketAddress |
getAddress()
Get the remote address for this Backend.
|
FS4Channel |
getChannel(int id)
Get an active channel by id.
|
FS4Channel |
getChannel(Integer id)
Get an active channel by id.
|
private FS4Connection |
getConnection()
Fetch a connection from the connection pool.
|
String |
getHost() |
FS4Channel |
getPingChannel()
Return the first channel in the queue waiting for pings or
null if none. |
int |
getPort() |
Backend.BackendStatistics |
getStatistics() |
private void |
logInfo(String attemptDescription,
Exception e) |
private void |
logWarning(String attemptDescription,
Exception e) |
com.yahoo.io.Connection |
newConnection(SocketChannel channel,
com.yahoo.io.Listener listener)
Connection factory used by the Listener class.
|
FS4Channel |
openChannel()
Open a new channel to fdispatch.
|
FS4Channel |
openPingChannel() |
protected void |
receivePacket(BasicPacket packet)
When a connection receives a packet, it uses this method to
dispatch the packet to the right FS4Channel.
|
protected FS4Channel |
removeChannel(Integer id)
Remove a channel.
|
protected FS4Channel |
removePingChannel()
Remove a ping channel.
|
void |
returnConnection(FS4Connection connection)
Return a connection to the connection pool.
|
protected boolean |
sendPacket(BasicPacket packet,
Integer channelId) |
void |
shutdown()
This method should be used to ensure graceful shutdown of the backend.
|
String |
toString() |
private static final Logger log
private final ListenerPool listeners
private final InetSocketAddress address
private final String host
private final int port
private final Map<Integer,FS4Channel> activeChannels
private int channelId
private boolean shutdownInitiated
private boolean areInSocketNotConnectableState
private final LinkedList<FS4Channel> pingChannels
private final PacketListener packetListener
private final ConnectionPool connectionPool
private final PacketDumper packetDumper
private final AtomicInteger connectionCount
protected Backend()
public Backend(String host, int port, String serverDiscriminator, ListenerPool listenerPool, ConnectionPool connectionPool)
private FS4Connection getConnection() throws IOException
IOException
public void returnConnection(FS4Connection connection)
private FS4Connection createConnection() throws IOException
IOException
private void connectSocket(SocketChannel socket) throws IOException
IOException
public FS4Channel openChannel()
public FS4Channel openPingChannel()
InetSocketAddress getAddress()
public FS4Channel getChannel(Integer id)
id
- the (fs4) channel idnull
if the channel is not in the
set of active channels.public FS4Channel getPingChannel()
null
if none.public FS4Channel getChannel(int id)
id
- The (fs4) channel idnull
if the channel is not in the
set of active channels.protected FS4Channel removeChannel(Integer id)
id
- The (fs4) channel idnull
if the channel is
not in the set of active channels.protected FS4Channel removePingChannel()
null
if there are no active ping channels.protected boolean sendPacket(BasicPacket packet, Integer channelId) throws IOException
IOException
protected void receivePacket(BasicPacket packet)
public void shutdown()
public void close()
public com.yahoo.io.Connection newConnection(SocketChannel channel, com.yahoo.io.Listener listener)
newConnection
in interface com.yahoo.io.ConnectionFactory
public Backend.BackendStatistics getStatistics()
public void dumpPackets(PacketDumper.PacketType packetType, boolean on) throws IOException
IOException
public String getHost()
public int getPort()
Copyright © 2018. All rights reserved.