Package org.jgroups.nio
Class MockSocketChannel
- java.lang.Object
-
- java.nio.channels.spi.AbstractInterruptibleChannel
-
- java.nio.channels.SelectableChannel
-
- java.nio.channels.spi.AbstractSelectableChannel
-
- java.nio.channels.SocketChannel
-
- org.jgroups.nio.MockSocketChannel
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.nio.channels.ByteChannel
,java.nio.channels.Channel
,java.nio.channels.GatheringByteChannel
,java.nio.channels.InterruptibleChannel
,java.nio.channels.NetworkChannel
,java.nio.channels.ReadableByteChannel
,java.nio.channels.ScatteringByteChannel
,java.nio.channels.WritableByteChannel
public class MockSocketChannel extends java.nio.channels.SocketChannel
A mockSocketChannel
for testing- Since:
- 3.6.5
- Author:
- Bela Ban
-
-
Field Summary
Fields Modifier and Type Field Description protected java.nio.ByteBuffer
bytes_to_read
protected int
bytes_to_write
protected boolean
closed
protected java.nio.ByteBuffer
recorder
-
Constructor Summary
Constructors Constructor Description MockSocketChannel()
MockSocketChannel(java.nio.channels.spi.SelectorProvider provider)
Initializes a new instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.nio.channels.SocketChannel
bind(java.net.SocketAddress local)
java.nio.ByteBuffer
bytesToRead()
MockSocketChannel
bytesToRead(byte[] buf)
MockSocketChannel
bytesToRead(java.nio.ByteBuffer buf)
MockSocketChannel
bytesToWrite(int num)
boolean
connect(java.net.SocketAddress remote)
void
doClose()
boolean
finishConnect()
java.net.SocketAddress
getLocalAddress()
<T> T
getOption(java.net.SocketOption<T> name)
java.net.SocketAddress
getRemoteAddress()
protected void
implCloseSelectableChannel()
protected void
implConfigureBlocking(boolean block)
boolean
isConnected()
boolean
isConnectionPending()
int
read(java.nio.ByteBuffer dst)
long
read(java.nio.ByteBuffer[] dsts, int offset, int length)
java.nio.ByteBuffer
recorder()
MockSocketChannel
recorder(java.nio.ByteBuffer buf)
<T> java.nio.channels.SocketChannel
setOption(java.net.SocketOption<T> name, T value)
java.nio.channels.SocketChannel
shutdownInput()
java.nio.channels.SocketChannel
shutdownOutput()
java.net.Socket
socket()
java.util.Set<java.net.SocketOption<?>>
supportedOptions()
int
write(java.nio.ByteBuffer buf)
long
write(java.nio.ByteBuffer[] srcs, int offset, int length)
-
Methods inherited from class java.nio.channels.spi.AbstractSelectableChannel
blockingLock, configureBlocking, implCloseChannel, isBlocking, isRegistered, keyFor, provider, register
-
Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
begin, close, end, isOpen
-
-
-
-
Method Detail
-
bytesToWrite
public MockSocketChannel bytesToWrite(int num)
-
bytesToRead
public MockSocketChannel bytesToRead(byte[] buf)
-
bytesToRead
public MockSocketChannel bytesToRead(java.nio.ByteBuffer buf)
-
bytesToRead
public java.nio.ByteBuffer bytesToRead()
-
recorder
public MockSocketChannel recorder(java.nio.ByteBuffer buf)
-
recorder
public java.nio.ByteBuffer recorder()
-
bind
public java.nio.channels.SocketChannel bind(java.net.SocketAddress local) throws java.io.IOException
- Specified by:
bind
in interfacejava.nio.channels.NetworkChannel
- Specified by:
bind
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
doClose
public void doClose()
-
setOption
public <T> java.nio.channels.SocketChannel setOption(java.net.SocketOption<T> name, T value) throws java.io.IOException
- Specified by:
setOption
in interfacejava.nio.channels.NetworkChannel
- Specified by:
setOption
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
getOption
public <T> T getOption(java.net.SocketOption<T> name) throws java.io.IOException
- Throws:
java.io.IOException
-
supportedOptions
public java.util.Set<java.net.SocketOption<?>> supportedOptions()
-
shutdownInput
public java.nio.channels.SocketChannel shutdownInput() throws java.io.IOException
- Specified by:
shutdownInput
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
shutdownOutput
public java.nio.channels.SocketChannel shutdownOutput() throws java.io.IOException
- Specified by:
shutdownOutput
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
socket
public java.net.Socket socket()
- Specified by:
socket
in classjava.nio.channels.SocketChannel
-
isConnected
public boolean isConnected()
- Specified by:
isConnected
in classjava.nio.channels.SocketChannel
-
isConnectionPending
public boolean isConnectionPending()
- Specified by:
isConnectionPending
in classjava.nio.channels.SocketChannel
-
connect
public boolean connect(java.net.SocketAddress remote) throws java.io.IOException
- Specified by:
connect
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
finishConnect
public boolean finishConnect() throws java.io.IOException
- Specified by:
finishConnect
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
getRemoteAddress
public java.net.SocketAddress getRemoteAddress() throws java.io.IOException
- Specified by:
getRemoteAddress
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
read
public int read(java.nio.ByteBuffer dst) throws java.io.IOException
- Specified by:
read
in interfacejava.nio.channels.ReadableByteChannel
- Specified by:
read
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
read
public long read(java.nio.ByteBuffer[] dsts, int offset, int length) throws java.io.IOException
- Specified by:
read
in interfacejava.nio.channels.ScatteringByteChannel
- Specified by:
read
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
write
public int write(java.nio.ByteBuffer buf) throws java.io.IOException
- Specified by:
write
in interfacejava.nio.channels.WritableByteChannel
- Specified by:
write
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
write
public long write(java.nio.ByteBuffer[] srcs, int offset, int length) throws java.io.IOException
- Specified by:
write
in interfacejava.nio.channels.GatheringByteChannel
- Specified by:
write
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
getLocalAddress
public java.net.SocketAddress getLocalAddress() throws java.io.IOException
- Specified by:
getLocalAddress
in interfacejava.nio.channels.NetworkChannel
- Specified by:
getLocalAddress
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
implCloseSelectableChannel
protected void implCloseSelectableChannel() throws java.io.IOException
- Specified by:
implCloseSelectableChannel
in classjava.nio.channels.spi.AbstractSelectableChannel
- Throws:
java.io.IOException
-
implConfigureBlocking
protected void implConfigureBlocking(boolean block) throws java.io.IOException
- Specified by:
implConfigureBlocking
in classjava.nio.channels.spi.AbstractSelectableChannel
- Throws:
java.io.IOException
-
-