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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classNioConnection.Readerprotected static classNioConnection.State
-
Field Summary
Fields Modifier and Type Field Description protected java.nio.channels.SocketChannelchannelprotected booleanconnectedprotected booleancopy_on_partial_writeprotected java.nio.channels.SelectionKeykeyprotected intpartial_writesprotected NioConnection.Readerreaderprotected longreader_idle_timeprotected Buffersrecv_bufprotected Bufferssend_bufprotected java.util.concurrent.locks.Locksend_lockprotected NioBaseServerserverprotected booleanwrite_interest_set-
Fields inherited from class org.jgroups.blocks.cs.Connection
cookie, last_access, peer_addr
-
-
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_receive(boolean update)voidclearSelectionKey(int interest_ops)voidclose()voidconnect(Address dest)protected voidconnect(Address dest, boolean send_local_addr)NioConnectionconnected(boolean c)booleancopyOnPartialWrite()NioConnectioncopyOnPartialWrite(boolean b)protected static byte[]getBuffer(java.nio.ByteBuffer buf)protected longgetTimestamp()booleanisConnected()booleanisConnectionPending()booleanisExpired(long now)booleanisOpen()java.nio.channels.SelectionKeykey()NioConnectionkey(java.nio.channels.SelectionKey k)AddresslocalAddress()protected static java.nio.ByteBuffermakeLengthBuffer(java.nio.ByteBuffer buf)intnumPartialWrites()AddresspeerAddress()longreaderIdleTime()NioConnectionreaderIdleTime(long t)booleanreaderRunning()protected AddressreadPeerAddress()voidreceive()Read the length first, then the actual data.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()protected voidupdateLastAccessed()protected voidwriteInterest(boolean register)
-
-
-
Field Detail
-
channel
protected java.nio.channels.SocketChannel channel
-
key
protected java.nio.channels.SelectionKey key
-
server
protected final NioBaseServer server
-
send_buf
protected final Buffers send_buf
-
write_interest_set
protected boolean write_interest_set
-
copy_on_partial_write
protected boolean copy_on_partial_write
-
partial_writes
protected int partial_writes
-
send_lock
protected final java.util.concurrent.locks.Lock send_lock
-
recv_buf
protected Buffers recv_buf
-
reader
protected NioConnection.Reader reader
-
reader_idle_time
protected long reader_idle_time
-
connected
protected boolean connected
-
-
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
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin classConnection
-
isConnected
public boolean isConnected()
- Specified by:
isConnectedin classConnection
-
isConnectionPending
public boolean isConnectionPending()
- Specified by:
isConnectionPendingin classConnection
-
isExpired
public boolean isExpired(long now)
- Specified by:
isExpiredin classConnection
-
updateLastAccessed
protected void updateLastAccessed()
-
localAddress
public Address localAddress()
- Specified by:
localAddressin classConnection
-
peerAddress
public Address peerAddress()
- Specified by:
peerAddressin 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()
-
readerIdleTime
public long readerIdleTime()
-
readerIdleTime
public NioConnection readerIdleTime(long t)
-
readerRunning
public boolean readerRunning()
-
connected
public NioConnection connected(boolean c)
-
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- Parameters:
buf-- Throws:
java.lang.Exception
-
send
public void send() throws java.lang.Exception- Throws:
java.lang.Exception
-
receive
public void receive() 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
-
send
protected void send(java.nio.ByteBuffer buf, boolean send_length) throws java.lang.Exception- Throws:
java.lang.Exception
-
_receive
protected boolean _receive(boolean update) throws java.lang.Exception- Throws:
java.lang.Exception
-
close
public void close() throws java.io.IOException- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
status
public java.lang.String status()
- Specified by:
statusin classConnection
-
getTimestamp
protected long getTimestamp()
-
writeInterest
protected void writeInterest(boolean register)
-
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 static java.nio.ByteBuffer makeLengthBuffer(java.nio.ByteBuffer buf)
-
-