rename UdpFF->Udp and the other UdpConnected, see #3058

This commit is contained in:
Roland 2013-03-25 10:02:50 +01:00
parent 0d510ff031
commit 309f2c2f91
17 changed files with 267 additions and 274 deletions

View file

@ -16,13 +16,13 @@ import java.util.ArrayList;
import java.util.List;
import akka.actor.ActorRef;
import akka.io.Inet;
import akka.io.UdpConn;
import akka.io.UdpConnMessage;
import akka.io.UdpConnected;
import akka.io.UdpConnectedMessage;
import akka.io.UdpSO;
import akka.util.ByteString;
//#imports
public class UdpConnDocTest {
public class UdpConnectedDocTest {
static public class Demo extends UntypedActor {
ActorRef connectionActor = null;
@ -32,12 +32,12 @@ public class UdpConnDocTest {
public void onReceive(Object msg) {
if ("connect".equals(msg)) {
//#manager
final ActorRef udp = UdpConn.get(system).manager();
final ActorRef udp = UdpConnected.get(system).manager();
//#manager
//#connect
final InetSocketAddress remoteAddr =
new InetSocketAddress("127.0.0.1", 12345);
udp.tell(UdpConnMessage.connect(handler, remoteAddr), getSelf());
udp.tell(UdpConnectedMessage.connect(handler, remoteAddr), getSelf());
//#connect
//#connect-with-options
final InetSocketAddress localAddr =
@ -45,26 +45,26 @@ public class UdpConnDocTest {
final List<Inet.SocketOption> options =
new ArrayList<Inet.SocketOption>();
options.add(UdpSO.broadcast(true));
udp.tell(UdpConnMessage.connect(handler, remoteAddr, localAddr, options), getSelf());
udp.tell(UdpConnectedMessage.connect(handler, remoteAddr, localAddr, options), getSelf());
//#connect-with-options
} else
//#connected
if (msg instanceof UdpConn.Connected) {
final UdpConn.Connected conn = (UdpConn.Connected) msg;
if (msg instanceof UdpConnected.Connected) {
final UdpConnected.Connected conn = (UdpConnected.Connected) msg;
connectionActor = getSender(); // Save the worker ref for later use
}
//#connected
else
//#received
if (msg instanceof UdpConn.Received) {
final UdpConn.Received recv = (UdpConn.Received) msg;
if (msg instanceof UdpConnected.Received) {
final UdpConnected.Received recv = (UdpConnected.Received) msg;
final ByteString data = recv.data();
// and do something with the received data ...
} else if (msg instanceof UdpConn.CommandFailed) {
final UdpConn.CommandFailed failed = (UdpConn.CommandFailed) msg;
final UdpConn.Command command = failed.cmd();
} else if (msg instanceof UdpConnected.CommandFailed) {
final UdpConnected.CommandFailed failed = (UdpConnected.CommandFailed) msg;
final UdpConnected.Command command = failed.cmd();
// react to failed connect, etc.
} else if (msg instanceof UdpConn.Disconnected) {
} else if (msg instanceof UdpConnected.Disconnected) {
// do something on disconnect
}
//#received
@ -72,7 +72,7 @@ public class UdpConnDocTest {
if ("send".equals(msg)) {
ByteString data = ByteString.empty();
//#send
connectionActor.tell(UdpConnMessage.send(data), getSelf());
connectionActor.tell(UdpConnectedMessage.send(data), getSelf());
//#send
}
}
@ -82,7 +82,7 @@ public class UdpConnDocTest {
@BeforeClass
static public void setup() {
system = ActorSystem.create("UdpConnDocTest");
system = ActorSystem.create("UdpConnectedDocTest");
}
@AfterClass

View file

@ -9,8 +9,8 @@ import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.UntypedActor;
import akka.io.Inet;
import akka.io.UdpFF;
import akka.io.UdpFFMessage;
import akka.io.Udp;
import akka.io.UdpMessage;
import akka.io.UdpSO;
import akka.util.ByteString;
@ -24,26 +24,26 @@ import org.junit.BeforeClass;
import org.junit.Test;
public class IOUdpFFDocTest {
public class UdpDocTest {
static public class Demo extends UntypedActor {
public void onReceive(Object message) {
//#manager
final ActorRef udpFF = UdpFF.get(system).manager();
final ActorRef udp = Udp.get(system).manager();
//#manager
//#simplesend
udpFF.tell(UdpFFMessage.simpleSender(), getSelf());
udp.tell(UdpMessage.simpleSender(), getSelf());
// ... or with socket options:
final List<Inet.SocketOption> options = new ArrayList<Inet.SocketOption>();
options.add(UdpSO.broadcast(true));
udpFF.tell(UdpFFMessage.simpleSender(), getSelf());
udp.tell(UdpMessage.simpleSender(), getSelf());
//#simplesend
ActorRef simpleSender = null;
//#simplesend-finish
if (message instanceof UdpFF.SimpleSendReady) {
if (message instanceof Udp.SimpleSendReady) {
simpleSender = getSender();
}
//#simplesend-finish
@ -51,33 +51,33 @@ public class IOUdpFFDocTest {
final ByteString data = ByteString.empty();
//#simplesend-send
simpleSender.tell(UdpFFMessage.send(data, new InetSocketAddress("127.0.0.1", 7654)), getSelf());
simpleSender.tell(UdpMessage.send(data, new InetSocketAddress("127.0.0.1", 7654)), getSelf());
//#simplesend-send
final ActorRef handler = getSelf();
//#bind
udpFF.tell(UdpFFMessage.bind(handler, new InetSocketAddress("127.0.0.1", 9876)), getSelf());
udp.tell(UdpMessage.bind(handler, new InetSocketAddress("127.0.0.1", 9876)), getSelf());
//#bind
ActorRef udpWorker = null;
//#bind-finish
if (message instanceof UdpFF.Bound) {
if (message instanceof Udp.Bound) {
udpWorker = getSender();
}
//#bind-finish
//#bind-receive
if (message instanceof UdpFF.Received) {
final UdpFF.Received rcvd = (UdpFF.Received) message;
if (message instanceof Udp.Received) {
final Udp.Received rcvd = (Udp.Received) message;
final ByteString payload = rcvd.data();
final InetSocketAddress sender = rcvd.sender();
}
//#bind-receive
//#bind-send
udpWorker.tell(UdpFFMessage.send(data, new InetSocketAddress("127.0.0.1", 7654)), getSelf());
udpWorker.tell(UdpMessage.send(data, new InetSocketAddress("127.0.0.1", 7654)), getSelf());
//#bind-send
}
}

View file

@ -216,14 +216,14 @@ Using UDP
UDP support comes in two flavors: connectionless and connection-based. With connectionless UDP, workers can send datagrams
to any remote address. Connection-based UDP workers are linked to a single remote address.
The connectionless UDP manager is accessed through ``UdpFF``. ``UdpFF`` refers to the "fire-and-forget" style of sending
The connectionless UDP manager is accessed through ``Udp``. ``Udp`` refers to the "fire-and-forget" style of sending
UDP datagrams.
.. includecode:: code/docs/io/IOUdpFFDocTest.java#manager
.. includecode:: code/docs/io/UdpDocTest.java#manager
The connection-based UDP manager is accessed through ``UdpConn``.
The connection-based UDP manager is accessed through ``UdpConnected``.
.. includecode:: code/docs/io/UdpConnDocTest.java#manager
.. includecode:: code/docs/io/UdpConnectedDocTest.java#manager
UDP servers can be only implemented by the connectionless API, but clients can use both.
@ -232,24 +232,24 @@ Connectionless UDP
The following imports are assumed in the following sections:
.. includecode:: code/docs/io/IOUdpFFDocTest.java#imports
.. includecode:: code/docs/io/UdpDocTest.java#imports
Simple Send
............
To simply send a UDP datagram without listening to an answer one needs to send the ``SimpleSender`` command to the
``UdpFF`` manager:
``Udp`` manager:
.. includecode:: code/docs/io/IOUdpFFDocTest.java#simplesend
.. includecode:: code/docs/io/UdpDocTest.java#simplesend
The manager will create a worker for sending, and the worker will reply with a ``SimpleSendReady`` message:
.. includecode:: code/docs/io/IOUdpFFDocTest.java#simplesend-finish
.. includecode:: code/docs/io/UdpDocTest.java#simplesend-finish
After saving the sender of the ``SimpleSendReady`` message it is possible to send out UDP datagrams with a simple
message send:
.. includecode:: code/docs/io/IOUdpFFDocTest.java#simplesend-send
.. includecode:: code/docs/io/UdpDocTest.java#simplesend-send
Bind (and Send)
@ -258,22 +258,22 @@ Bind (and Send)
To listen for UDP datagrams arriving on a given port, the ``Bind`` command has to be sent to the connectionless UDP
manager
.. includecode:: code/docs/io/IOUdpFFDocTest.java#bind
.. includecode:: code/docs/io/UdpDocTest.java#bind
After the bind succeeds, the sender of the ``Bind`` command will be notified with a ``Bound`` message. The sender of
this message is the worker for the UDP channel bound to the local address.
.. includecode:: code/docs/io/IOUdpFFDocTest.java#bind-finish
.. includecode:: code/docs/io/UdpDocTest.java#bind-finish
The actor passed in the ``handler`` parameter will receive inbound UDP datagrams sent to the bound address:
.. includecode:: code/docs/io/IOUdpFFDocTest.java#bind-receive
.. includecode:: code/docs/io/UdpDocTest.java#bind-receive
The ``Received`` message contains the payload of the datagram and the address of the sender.
It is also possible to send UDP datagrams using the ``ActorRef`` of the worker:
.. includecode:: code/docs/io/IOUdpFFDocTest.java#bind-send
.. includecode:: code/docs/io/UdpDocTest.java#bind-send
.. note::
@ -290,27 +290,27 @@ receive datagrams only from that address.
Connecting is similar to what we have seen in the previous section:
.. includecode:: code/docs/io/UdpConnDocTest.java#connect
.. includecode:: code/docs/io/UdpConnectedDocTest.java#connect
Or, with more options:
.. includecode:: code/docs/io/UdpConnDocTest.java#connect-with-options
.. includecode:: code/docs/io/UdpConnectedDocTest.java#connect-with-options
After the connect succeeds, the sender of the ``Connect`` command will be notified with a ``Connected`` message. The sender of
this message is the worker for the UDP connection.
.. includecode:: code/docs/io/UdpConnDocTest.java#connected
.. includecode:: code/docs/io/UdpConnectedDocTest.java#connected
The actor passed in the ``handler`` parameter will receive inbound UDP datagrams sent to the bound address:
.. includecode:: code/docs/io/UdpConnDocTest.java#received
.. includecode:: code/docs/io/UdpConnectedDocTest.java#received
The ``Received`` message contains the payload of the datagram but unlike in the connectionless case, no sender address
is provided, as a UDP connection only receives messages from the endpoint it has been connected to.
It is also possible to send UDP datagrams using the ``ActorRef`` of the worker:
.. includecode:: code/docs/io/UdpConnDocTest.java#send
.. includecode:: code/docs/io/UdpConnectedDocTest.java#send
Again, like the ``Received`` message, the ``Send`` message does not contain a remote address. This is because the address
will always be the endpoint we originally connected to.