public class MuxServerSocketChannel extends DelegatingServerSocketChannel<MuxingServerSocketChannel>
ServerSocketChannel
which is capable of sharing its
listening endpoint with multiple others like it.Modifier and Type | Field and Description |
---|---|
private Queue<Timestamped<SocketChannel>> |
acceptQ
The (ordered) list (i.e.
|
protected DatagramPacketFilter |
filter
The
DatagramPacketFilter which demultiplexes
SocketChannel s accepted by the associated
MuxingServerSocketChannel . |
private Object |
syncRoot
The Object which synchronizes the access to the state of this
MuxServerSocketChannel such as
acceptQ . |
delegateAsSelChImpl
delegate
Modifier | Constructor and Description |
---|---|
protected |
MuxServerSocketChannel(MuxingServerSocketChannel delegate,
DatagramPacketFilter filter)
Initializes a new
MuxServerSocketChannel instance which is to
demultiplex SocketChannel s accepted by a specific
MuxingServerSocketChannel using a specific
DatagramPacketFilter . |
Modifier and Type | Method and Description |
---|---|
SocketChannel |
accept()
Forwards to
BaseDelegatingServerSocketChannel.delegate . |
(package private) void |
closeAbandonedSocketChannels(long now)
Weeds out abandoned
SocketChannels from acceptQ i.e. |
protected boolean |
filterAccept(DatagramPacket p,
SocketChannel channel)
Determines whether the
filter of this instance accepts a
specific SocketChannel from which a specific
DatagramPacket has been read and, if it does, queues the
channel to be accepted through this instance. |
protected void |
implConfigureBlocking(boolean block)
Forwards to
BaseDelegatingServerSocketChannel.delegate . |
protected MuxServerSocket |
implSocket(ServerSocket socket)
Allows extenders to optionally configure (e.g.
|
static MuxServerSocketChannel |
openAndBind(Map<String,Object> properties,
SocketAddress endpoint,
int backlog,
DatagramPacketFilter filter)
Opens and binds a new
MuxServerSocketChannel instance. |
(package private) boolean |
qAccept(SocketChannel channel)
Queues a
SocketChannel for acceptance through this instance. |
getFD, getFDVal, kill, translateAndSetInterestOps, translateAndSetReadyOps, translateAndUpdateReadyOps
bind, getLocalAddress, getOption, implAccept, implCloseSelectableChannel, isBound, setOption, socket, supportedOptions
bind, open, validOps
blockingLock, configureBlocking, implCloseChannel, isBlocking, isRegistered, keyFor, provider, register
register
begin, close, end, isOpen
private final Queue<Timestamped<SocketChannel>> acceptQ
accept()
.protected final DatagramPacketFilter filter
DatagramPacketFilter
which demultiplexes
SocketChannel
s accepted by the associated
MuxingServerSocketChannel
.protected MuxServerSocketChannel(MuxingServerSocketChannel delegate, DatagramPacketFilter filter)
MuxServerSocketChannel
instance which is to
demultiplex SocketChannel
s accepted by a specific
MuxingServerSocketChannel
using a specific
DatagramPacketFilter
. The new instance shares the listening
endpoint of delegate
with any other associated
MuxServerSocketChannel
s.delegate
- the MuxingServerSocketChannel
which is actually
open and bound to a listening endpoint and accepts SocketChannel
s
to be filtered by associated
MuxServerSocketChannel
sfilter
- the DatagramPacketFilter
which is to demultiplex
SocketChannel
s accepted by delegate
public static MuxServerSocketChannel openAndBind(Map<String,Object> properties, SocketAddress endpoint, int backlog, DatagramPacketFilter filter) throws IOException
MuxServerSocketChannel
instance. If there
are other (existing) MuxServerSocketChannel
open and bound on the
specified listening endpoint
, the new instance will share it with
them.properties
- a Map
of the values to be assigned to
properties of the underlying ServerSocketChannel
which is to
actually listen on the specified endpoint
. If the new instance is
not the first to open and bind the specified endpoint
, the
properties
and their respective values may not be used.endpoint
- the IP and port the new instance is to bind tobacklog
- the requested maximum number of pending incoming
connections to be queued. If the new instance is not the first to open
and bind the specified endpoint
, the value may not be used.filter
- the DatagramPacketFilter
to demultiplex (i.e.
recognize) the content meant for the new instanceMuxServerSocketChannel
instance open and bound on
the specified listening endpoint
IOException
- if an I/O error occurspublic SocketChannel accept() throws IOException
BaseDelegatingServerSocketChannel.delegate
.accept
in class BaseDelegatingServerSocketChannel<MuxingServerSocketChannel>
IOException
void closeAbandonedSocketChannels(long now)
SocketChannels
from acceptQ
i.e.
which were classified/filtered into this MuxServerSocketChannel
but were not accepted (out of it) for a long time.now
- the (system) time in milliseconds at which the method is
invokedprotected boolean filterAccept(DatagramPacket p, SocketChannel channel)
filter
of this instance accepts a
specific SocketChannel
from which a specific
DatagramPacket
has been read and, if it does, queues the
channel
to be accepted through this instance.p
- the DatagramPacket
which has been read from
channel
and which is to be analyzed by the filter
of this
instancechannel
- the SocketChannel
from which p
has been
read and which is to be queued for acceptance through this instance if
the filter
accepts p
true
if the filter
of this instance accepts
p
and channel
was queued for acceptance through this
instance; otherwise, false
protected void implConfigureBlocking(boolean block) throws IOException
BaseDelegatingServerSocketChannel.delegate
.
Adjusts the blocking mode of BaseDelegatingServerSocketChannel.delegate
.implConfigureBlocking
in class BaseDelegatingServerSocketChannel<MuxingServerSocketChannel>
IOException
protected MuxServerSocket implSocket(ServerSocket socket) throws IOException
ServerSocket
of BaseDelegatingServerSocketChannel.delegate
and before it is returned by
BaseDelegatingServerSocketChannel.socket()
.
Associates a MuxServerSocket
with this
MuxServerSocketChannel
.implSocket
in class BaseDelegatingServerSocketChannel<MuxingServerSocketChannel>
socket
- the ServerSocket
of delegate
ServerSocket
to be returned by BaseDelegatingServerSocketChannel.socket()
(in
place of socket
)IOException
- if an I/O error occursboolean qAccept(SocketChannel channel)
SocketChannel
for acceptance through this instance.channel
- the SocketChannel
to queue for acceptance through
this instancetrue
if channel
was queued for acceptance through
this instance; otherwise, false
Copyright © 2018. All rights reserved.