Package com.mongodb.internal.connection
Class SocketChannelStream
- java.lang.Object
-
- com.mongodb.internal.connection.SocketChannelStream
-
- All Implemented Interfaces:
BufferProvider
,Stream
- Direct Known Subclasses:
UnixSocketChannelStream
public class SocketChannelStream extends java.lang.Object implements Stream
-
-
Constructor Summary
Constructors Constructor Description SocketChannelStream(ServerAddress address, SocketSettings settings, SslSettings sslSettings, BufferProvider bufferProvider)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the connection.ServerAddress
getAddress()
The address that this stream is connected to.ByteBuf
getBuffer(int size)
Gets a buffer with the givens capacity.boolean
isClosed()
Returns the closed state of the connectionvoid
open()
Open the stream.void
openAsync(AsyncCompletionHandler<java.lang.Void> handler)
Open the stream asynchronously.ByteBuf
read(int numBytes)
Read from the stream, blocking until the requested number of bytes have been read.void
readAsync(int numBytes, AsyncCompletionHandler<ByteBuf> handler)
Read from the stream, asynchronously.void
write(java.util.List<ByteBuf> buffers)
Write each buffer in the list to the stream in order, blocking until all are completely written.void
writeAsync(java.util.List<ByteBuf> buffers, AsyncCompletionHandler<java.lang.Void> handler)
Write each buffer in the list to the stream in order, asynchronously.
-
-
-
Constructor Detail
-
SocketChannelStream
public SocketChannelStream(ServerAddress address, SocketSettings settings, SslSettings sslSettings, BufferProvider bufferProvider)
-
-
Method Detail
-
open
public void open() throws java.io.IOException
Description copied from interface:Stream
Open the stream.
-
getBuffer
public ByteBuf getBuffer(int size)
Description copied from interface:BufferProvider
Gets a buffer with the givens capacity.- Specified by:
getBuffer
in interfaceBufferProvider
- Parameters:
size
- the size required for the buffer- Returns:
- a ByteBuf with the given size, which is now owned by the caller and must be released.
-
write
public void write(java.util.List<ByteBuf> buffers) throws java.io.IOException
Description copied from interface:Stream
Write each buffer in the list to the stream in order, blocking until all are completely written.
-
read
public ByteBuf read(int numBytes) throws java.io.IOException
Description copied from interface:Stream
Read from the stream, blocking until the requested number of bytes have been read.
-
openAsync
public void openAsync(AsyncCompletionHandler<java.lang.Void> handler)
Description copied from interface:Stream
Open the stream asynchronously.
-
writeAsync
public void writeAsync(java.util.List<ByteBuf> buffers, AsyncCompletionHandler<java.lang.Void> handler)
Description copied from interface:Stream
Write each buffer in the list to the stream in order, asynchronously. This method should return immediately, and invoke the given callback on completion.- Specified by:
writeAsync
in interfaceStream
- Parameters:
buffers
- the buffers to writehandler
- invoked when the read operation has completed
-
readAsync
public void readAsync(int numBytes, AsyncCompletionHandler<ByteBuf> handler)
Description copied from interface:Stream
Read from the stream, asynchronously. This method should return immediately, and invoke the given callback when the number of requested bytes have been read.
-
getAddress
public ServerAddress getAddress()
Description copied from interface:Stream
The address that this stream is connected to.- Specified by:
getAddress
in interfaceStream
- Returns:
- the address
-
close
public void close()
Description copied from interface:Stream
Closes the connection.
-
-