public final class EServer extends Object implements ServerSocketListener, EPublisher, StatusReporter
Only one EServer instance may be open at a
time.
Applications wanting to be notified when EServer
accepts a new remote eBus application connection need to
implement the ESubscriber interface and subscribe
for the message key
net.sf.eBus.client.ServerMessage:/eBus.
ServerMessage contains the remote address of the
newly accepted TCP connection. Note: this is
a local-only feed and cannot be remote accessed.
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_PORT
TCP ports must be <= 65,535.
|
static int |
MIN_PORT
TCP ports must be >= to 1.
|
static EMessageKey |
NEW_CONNECTION_KEY
Newly accepted eBus connections are reported using
ServerMessage and the subject
"/eBus". |
| Modifier and Type | Method and Description |
|---|---|
static void |
closeAllServers()
Closes are currently open eBus servers.
|
static void |
closeServer(int port)
Closes the specified service socket if open.
|
EConfigure.Service |
configuration()
Returns the eBus service configuration.
|
static void |
configure(EConfigure config)
Creates and opens an eBus service for this application as
per the
eBus configuration. |
void |
handleAccept(SocketChannel socket,
AsyncServerSocket aserver)
Create a
ERemoteApp to handle this new
connection if the connection passes the positive filter. |
void |
handleClose(Throwable jex,
AsyncServerSocket aserver)
The eBus service has unexpectedly closed.
|
boolean |
isOpen()
Returns
true if this server is open and
false otherwise. |
static boolean |
isServiceOpen(int port)
Returns
true if the singleton eBus service exists
and is open; otherwise, returns false. |
static EServer |
openServer(EConfigure.Service config)
Opens a service socket on the given port and accepting
connections of the given type and from the specified
hosts and ports.
|
int |
port()
Returns the TCP port on which this service is accepting
connections.
|
void |
publishStatus(EFeedState pubState,
IEPublishFeed feed)
Updates the feed state.
|
void |
reportStatus(PrintWriter report)
Adds the eBus server connection status to the status
report.
|
static EServer |
server(int port)
Returns the eBus server instance associated with the given
TCP serverPort.
|
static int |
serviceCount()
Returns the number of currently open eBus services.
|
static Collection<Integer> |
services()
Returns a copy of the existing eBus service ports.
|
public static final int MIN_PORT
public static final int MAX_PORT
public static final EMessageKey NEW_CONNECTION_KEY
ServerMessage and the subject
"/eBus".public void handleAccept(SocketChannel socket, AsyncServerSocket aserver)
ERemoteApp to handle this new
connection if the connection passes the positive filter.
If not, the accepted client connection is immediately
closed.handleAccept in interface ServerSocketListenersocket - a Socket connectionaserver - an
AsyncServerSocketpublic void handleClose(Throwable jex, AsyncServerSocket aserver)
handleClose in interface ServerSocketListenerjex - an Exception valueaserver - an
AsyncServerSocketpublic void reportStatus(PrintWriter report)
reportStatus in interface StatusReporterreport - the logged status report.public void publishStatus(EFeedState pubState, IEPublishFeed feed)
publishStatus in interface EPublisherpubState - the new publisher feed statefeed - the feed state applies to this feed.public int port()
public EConfigure.Service configuration()
public boolean isOpen()
true if this server is open and
false otherwise.true if this server is open.public static boolean isServiceOpen(int port)
true if the singleton eBus service exists
and is open; otherwise, returns false.port - check if this service port is open.true if this eBus application has an open
service.public static int serviceCount()
public static Collection<Integer> services()
public static EServer server(int port)
null if there is no eBus
server for serverPort.port - TCP service serverPort.public static EServer openServer(EConfigure.Service config)
EServer instance.
If
address filter
contains an entry with a socket address but a port set to
zero, that means the client connection may be bound to any
port. If the port is > zero, then the client connection
must be bound to the specific port. If the address filter
is null, then all connections are accepted.
Negative filters are not supported. A negative filter would accept all connections except those listed.
config - eBus service configuration.IllegalArgumentException - if any of the given
parameters is invalid.IllegalStateException - if service port is already open.public static void closeServer(int port)
port - close the service on this service port.public static void closeAllServers()
public static void configure(EConfigure config) throws IOException
eBus configuration.config - the eBus configuration.IOException - if the configured eBus service failed to open.Copyright © 2019. All rights reserved.