juglr.net
Class TCPServerActor
java.lang.Object
juglr.Actor
juglr.net.TCPServerActor
public class TCPServerActor
- extends Actor
A TCP server that accepts connections in a designated thread and dispatches
control to a TCPChannelActor
obtained from a
TCPChannelStrategy
. The accept
-loop is very tight and is able
to handle a massive number of concurrent connections (mainly limited by the
multiplexing capabilities of Java's ServerSocketChannel
).
To stop the server send it the SHUTDOWN
message.
Constructor Summary |
TCPServerActor(int port,
TCPChannelStrategy strategy)
Create a server listening on port handling connection with
actor obtained from strategy |
TCPServerActor(int port,
TCPChannelStrategy strategy,
MessageBus bus)
|
TCPServerActor(java.net.SocketAddress socketAddress,
TCPChannelStrategy strategy,
MessageBus bus)
|
TCPServerActor(java.lang.String hostname,
int port,
TCPChannelStrategy strategy)
|
TCPServerActor(java.lang.String hostname,
int port,
TCPChannelStrategy strategy,
MessageBus bus)
|
Method Summary |
void |
react(Message msg)
Primary method for handling incoming messages, override it with
your message handling logic. |
void |
start()
Initiate the actor life cycle, you may start sending messages from
within this method. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
SHUTDOWN
public static final Message SHUTDOWN
TCPServerActor
public TCPServerActor(java.net.SocketAddress socketAddress,
TCPChannelStrategy strategy,
MessageBus bus)
throws java.io.IOException
- Throws:
java.io.IOException
TCPServerActor
public TCPServerActor(int port,
TCPChannelStrategy strategy)
throws java.io.IOException
- Create a server listening on
port
handling connection with
actor obtained from strategy
- Parameters:
port
- strategy
-
- Throws:
java.io.IOException
TCPServerActor
public TCPServerActor(java.lang.String hostname,
int port,
TCPChannelStrategy strategy)
throws java.io.IOException
- Throws:
java.io.IOException
TCPServerActor
public TCPServerActor(int port,
TCPChannelStrategy strategy,
MessageBus bus)
throws java.io.IOException
- Throws:
java.io.IOException
TCPServerActor
public TCPServerActor(java.lang.String hostname,
int port,
TCPChannelStrategy strategy,
MessageBus bus)
throws java.io.IOException
- Throws:
java.io.IOException
react
public void react(Message msg)
- Description copied from class:
Actor
- Primary method for handling incoming messages, override it with
your message handling logic. This method is guaranteed to be run
in a calling context synchronized on this actor. In effect this means
that actors only handle one message at a time. For a discussion on how
to parallelize message processing see the section in the class
documentation.
Blocking operations, such as IO, should be done within an
Actor.await(Callable)
call.
- Specified by:
react
in class Actor
- Parameters:
msg
- the incoming message
start
public void start()
- Description copied from class:
Actor
- Initiate the actor life cycle, you may start sending messages from
within this method. This method is guaranteed to be run
in a calling context synchronized on this actor.
- Overrides:
start
in class Actor