public class NioConnection extends java.lang.Object implements Connection<Address>
Connection
Modifier and Type | Field and Description |
---|---|
protected java.nio.channels.SocketChannel |
channel |
protected java.nio.channels.SelectionKey |
key |
protected long |
last_access |
protected Address |
peer_addr |
protected Buffers |
recv_buf |
protected java.util.concurrent.locks.Lock |
recv_lock |
protected Buffers |
send_buf |
protected java.util.concurrent.locks.Lock |
send_lock |
protected NioServer |
server |
protected boolean |
write_interest_set |
Constructor and Description |
---|
NioConnection(Address peer_addr,
NioServer server)
Creates a connection stub and binds it, use
connect(Address) to connect |
NioConnection(java.nio.channels.SocketChannel channel,
NioServer server) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
connect(Address dest) |
protected long |
getTimestamp() |
boolean |
isConnected() |
boolean |
isExpired(long now) |
boolean |
isOpen() |
java.nio.channels.SelectionKey |
key() |
NioConnection |
key(java.nio.channels.SelectionKey k) |
Address |
peerAddress() |
protected Address |
readPeerAddress(java.nio.ByteBuffer buf) |
void |
receive()
Read the length first, then the actual data
|
void |
receive(int max_num_msgs_to_receive)
Tries to receive up to max_num_msgs_to_receive messages in one go
|
void |
send() |
void |
send(byte[] buf,
int offset,
int length) |
void |
send(java.nio.ByteBuffer buf)
Sends a message.
|
protected void |
sendLocalAddress(Address local_addr) |
protected void |
setSocketParameters(java.net.Socket client_sock) |
void |
start() |
java.lang.String |
toString() |
protected void |
updateLastAccessed() |
protected void |
writeInterest(boolean register) |
protected java.nio.channels.SocketChannel channel
protected java.nio.channels.SelectionKey key
protected Address peer_addr
protected long last_access
protected final NioServer server
protected final Buffers send_buf
protected boolean write_interest_set
protected final java.util.concurrent.locks.Lock send_lock
protected Buffers recv_buf
protected final java.util.concurrent.locks.Lock recv_lock
public NioConnection(Address peer_addr, NioServer server) throws java.lang.Exception
connect(Address)
to connectjava.lang.Exception
public NioConnection(java.nio.channels.SocketChannel channel, NioServer server) throws java.lang.Exception
java.lang.Exception
public boolean isOpen()
isOpen
in interface Connection<Address>
public boolean isConnected()
isConnected
in interface Connection<Address>
public boolean isExpired(long now)
isExpired
in interface Connection<Address>
protected void updateLastAccessed()
public Address peerAddress()
public java.nio.channels.SelectionKey key()
public NioConnection key(java.nio.channels.SelectionKey k)
public void connect(Address dest) throws java.lang.Exception
connect
in interface Connection<Address>
java.lang.Exception
public void start() throws java.lang.Exception
start
in interface Connection<Address>
java.lang.Exception
public void send(byte[] buf, int offset, int length) throws java.lang.Exception
send
in interface Connection<Address>
java.lang.Exception
public void send(java.nio.ByteBuffer buf) throws java.lang.Exception
send
in interface Connection<Address>
buf
- java.lang.Exception
public void send() throws java.lang.Exception
java.lang.Exception
public void receive() throws java.lang.Exception
java.lang.Exception
public void receive(int max_num_msgs_to_receive) throws java.lang.Exception
max_num_msgs_to_receive
- java.lang.Exception
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object
protected long getTimestamp()
protected void writeInterest(boolean register)
protected void setSocketParameters(java.net.Socket client_sock) throws java.net.SocketException
java.net.SocketException
protected void sendLocalAddress(Address local_addr) throws java.lang.Exception
java.lang.Exception
protected Address readPeerAddress(java.nio.ByteBuffer buf) throws java.lang.Exception
java.lang.Exception
Copyright © 1998-2020 Red Hat. All Rights Reserved.