public class Server extends Object implements AutoCloseable
Socket
-based Server
that can
handle, using OperationHandler
s, Operation
s invoked by
Client
s.Client
,
Operation
,
OperationHandler
Modifier and Type | Field and Description |
---|---|
static Operation<Void> |
CLOSE_OPERATION
Special operation to signal the server that the client has been closed.
|
static Logger |
LOG
Logger
|
Constructor and Description |
---|
Server(int port)
|
Modifier and Type | Method and Description |
---|---|
void |
addOperationHandler(OperationHandler handler)
Registers the specified
OperationHandler for an operation. |
void |
clientConnectedDirectly() |
void |
close()
Stops the
Server . |
void |
closeWasCalledOnClient() |
void |
executeOperation(String operation,
ObjectInputStream ois,
ObjectOutputStream oos) |
InetAddress |
getInetAddress()
Obtains the
InetAddress on which the Server is listening. |
int |
getPort()
Obtains the port on which the
Server is listening. |
static Server |
lookupServerAtLocalMachine(int port)
Returns the server for this port, if running in the local machine.
|
InetAddress |
open()
Opens and starts the
Server . |
public static final Logger LOG
public Server(int port)
port
- the port on which to accept Client
connections and requestspublic static Server lookupServerAtLocalMachine(int port)
public void addOperationHandler(OperationHandler handler)
OperationHandler
for an operation.handler
- the OperationHandler
public InetAddress open() throws IOException
InetAddress
on which the Server
is accepting requests from Client
s.IOException
- if not able to create ServerSocketpublic InetAddress getInetAddress()
InetAddress
on which the Server
is listening.InetAddress
public int getPort()
Server
is listening.public void clientConnectedDirectly()
public void closeWasCalledOnClient()
public void close()
close
in interface AutoCloseable
public void executeOperation(String operation, ObjectInputStream ois, ObjectOutputStream oos) throws ClassNotFoundException, IOException
ClassNotFoundException
IOException
cache2k API documentation. Copyright © 2000–2018 headissue GmbH, Munich.