Package org.jgroups.blocks.cs
Class NioConnection
- java.lang.Object
-
- org.jgroups.blocks.cs.Connection
-
- org.jgroups.blocks.cs.NioConnection
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class NioConnection extends Connection
An NIO based impl ofConnection- Since:
- 3.6.5
- Author:
- Bela Ban
-
-
Field Summary
Fields Modifier and Type Field Description protected java.nio.channels.SocketChannelchannelprotected booleancopy_on_partial_writeprotected java.nio.channels.SelectionKeykeyprotected java.nio.ByteBufferlength_bufprotected intpartial_writesprotected Buffersrecv_bufprotected Bufferssend_buf-
Fields inherited from class org.jgroups.blocks.cs.Connection
cookie, last_access, peer_addr, send_lock, server
-
-
Constructor Summary
Constructors Constructor Description NioConnection(java.nio.channels.SocketChannel channel, NioBaseServer server)NioConnection(Address peer_addr, NioBaseServer server)Creates a connection stub and binds it, useconnect(Address)to connect
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean_read()voidclearSelectionKey(int interest_ops)voidclose()voidconnect(Address dest)protected voidconnect(Address dest, boolean send_local_addr)booleancopyOnPartialWrite()NioConnectioncopyOnPartialWrite(boolean b)voidflush()protected static byte[]getBuffer(java.nio.ByteBuffer buf)booleanisClosed()booleanisConnected()booleanisConnectionPending()java.nio.channels.SelectionKeykey()NioConnectionkey(java.nio.channels.SelectionKey k)AddresslocalAddress()protected java.nio.ByteBuffermakeLengthBuffer(int length)intnumPartialWrites()voidread()Read the length first, then the actual data.protected AddressreadPeerAddress()voidregisterSelectionKey(int interest_ops)voidsend()voidsend(byte[] buf, int offset, int length)voidsend(java.nio.ByteBuffer buf)Sends a message.protected voidsend(java.nio.ByteBuffer buf, boolean send_length)protected voidsendLocalAddress(Address local_addr)protected voidsetSocketParameters(java.net.Socket client_sock)voidstart()java.lang.Stringstatus()java.lang.StringtoString()-
Methods inherited from class org.jgroups.blocks.cs.Connection
getTimestamp, isExpired, peerAddress, updateLastAccessed
-
-
-
-
Field Detail
-
channel
protected java.nio.channels.SocketChannel channel
-
key
protected java.nio.channels.SelectionKey key
-
send_buf
protected final Buffers send_buf
-
length_buf
protected final java.nio.ByteBuffer length_buf
-
copy_on_partial_write
protected boolean copy_on_partial_write
-
partial_writes
protected int partial_writes
-
recv_buf
protected Buffers recv_buf
-
-
Constructor Detail
-
NioConnection
public NioConnection(Address peer_addr, NioBaseServer server) throws java.lang.Exception
Creates a connection stub and binds it, useconnect(Address)to connect- Throws:
java.lang.Exception
-
NioConnection
public NioConnection(java.nio.channels.SocketChannel channel, NioBaseServer server) throws java.lang.Exception- Throws:
java.lang.Exception
-
-
Method Detail
-
isConnected
public boolean isConnected()
- Specified by:
isConnectedin classConnection
-
isConnectionPending
public boolean isConnectionPending()
- Specified by:
isConnectionPendingin classConnection
-
isClosed
public boolean isClosed()
- Specified by:
isClosedin classConnection
-
localAddress
public Address localAddress()
- Specified by:
localAddressin classConnection
-
key
public java.nio.channels.SelectionKey key()
-
key
public NioConnection key(java.nio.channels.SelectionKey k)
-
copyOnPartialWrite
public NioConnection copyOnPartialWrite(boolean b)
-
copyOnPartialWrite
public boolean copyOnPartialWrite()
-
numPartialWrites
public int numPartialWrites()
-
registerSelectionKey
public void registerSelectionKey(int interest_ops)
-
clearSelectionKey
public void clearSelectionKey(int interest_ops)
-
connect
public void connect(Address dest) throws java.lang.Exception
- Specified by:
connectin classConnection- Throws:
java.lang.Exception
-
connect
protected void connect(Address dest, boolean send_local_addr) throws java.lang.Exception
- Throws:
java.lang.Exception
-
start
public void start() throws java.lang.Exception- Specified by:
startin classConnection- Throws:
java.lang.Exception
-
send
public void send(byte[] buf, int offset, int length) throws java.lang.Exception- Specified by:
sendin classConnection- Throws:
java.lang.Exception
-
send
public void send(java.nio.ByteBuffer buf) throws java.lang.ExceptionSends a message. If the previous write didn't complete, tries to complete it. If this still doesn't complete, the message is dropped (needs to be retransmitted, e.g. by UNICAST3 or NAKACK2).- Specified by:
sendin classConnection- Throws:
java.lang.Exception
-
send
protected void send(java.nio.ByteBuffer buf, boolean send_length) throws java.lang.Exception- Throws:
java.lang.Exception
-
send
public void send() throws java.lang.Exception- Throws:
java.lang.Exception
-
read
public void read() throws java.lang.ExceptionRead the length first, then the actual data. This method is not reentrant and access must be synchronized- Throws:
java.lang.Exception
-
_read
protected boolean _read() throws java.lang.Exception- Throws:
java.lang.Exception
-
close
public void close() throws java.io.IOException- Throws:
java.io.IOException
-
flush
public void flush()
- Specified by:
flushin classConnection
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
status
public java.lang.String status()
- Specified by:
statusin classConnection
-
setSocketParameters
protected void setSocketParameters(java.net.Socket client_sock) throws java.net.SocketException- Throws:
java.net.SocketException
-
sendLocalAddress
protected void sendLocalAddress(Address local_addr) throws java.lang.Exception
- Throws:
java.lang.Exception
-
readPeerAddress
protected Address readPeerAddress() throws java.lang.Exception
- Throws:
java.lang.Exception
-
getBuffer
protected static byte[] getBuffer(java.nio.ByteBuffer buf)
-
makeLengthBuffer
protected java.nio.ByteBuffer makeLengthBuffer(int length)
-
-