This commit is contained in:
parent
5b477e99e7
commit
24566c167c
9 changed files with 124 additions and 92 deletions
|
|
@ -16,7 +16,7 @@ import akka.zeromq.Subscribe;
|
|||
import akka.zeromq.Unsubscribe;
|
||||
//#import-unsub-topic-socket
|
||||
//#import-pub-topic
|
||||
import akka.zeromq.Frame;
|
||||
import akka.util.ByteString;
|
||||
import akka.zeromq.ZMQMessage;
|
||||
//#import-pub-topic
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ public class ZeromqDocTestBase {
|
|||
|
||||
byte[] payload = new byte[0];
|
||||
//#pub-topic
|
||||
pubSocket.tell(new ZMQMessage(new Frame("foo.bar"), new Frame(payload)), null);
|
||||
pubSocket.tell(ZMQMessage.withFrames(ByteString.fromString("foo.bar"), ByteString.fromArray(payload)), null);
|
||||
//#pub-topic
|
||||
|
||||
system.stop(subSocket);
|
||||
|
|
@ -136,7 +136,7 @@ public class ZeromqDocTestBase {
|
|||
private boolean checkZeroMQInstallation() {
|
||||
try {
|
||||
ZeroMQVersion v = ZeroMQExtension.get(system).version();
|
||||
return (v.major() == 2 && v.minor() == 1);
|
||||
return (v.major() >= 3 || (v.major() >= 2 && v.minor() >= 1));
|
||||
} catch (LinkageError e) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -213,18 +213,23 @@ public class ZeromqDocTestBase {
|
|||
long timestamp = System.currentTimeMillis();
|
||||
|
||||
// use akka SerializationExtension to convert to bytes
|
||||
byte[] heapPayload = ser.serializerFor(Heap.class).toBinary(
|
||||
new Heap(timestamp, currentHeap.getUsed(), currentHeap.getMax()));
|
||||
ByteString heapTopic = ByteString.fromString("health.heap", "UTF-8");
|
||||
ByteString heapPayload = ByteString.fromArray(
|
||||
ser.serialize(
|
||||
new Heap(timestamp,
|
||||
currentHeap.getUsed(),
|
||||
currentHeap.getMax())
|
||||
).get());
|
||||
// the first frame is the topic, second is the message
|
||||
pubSocket.tell(new ZMQMessage(new Frame("health.heap"),
|
||||
new Frame(heapPayload)), getSelf());
|
||||
pubSocket.tell(ZMQMessage.withFrames(heapTopic, heapPayload), getSelf());
|
||||
|
||||
// use akka SerializationExtension to convert to bytes
|
||||
byte[] loadPayload = ser.serializerFor(Load.class).toBinary(
|
||||
new Load(timestamp, os.getSystemLoadAverage()));
|
||||
ByteString loadTopic = ByteString.fromString("health.load", "UTF-8");
|
||||
ByteString loadPayload = ByteString.fromArray(
|
||||
ser.serialize(new Load(timestamp, os.getSystemLoadAverage())).get()
|
||||
);
|
||||
// the first frame is the topic, second is the message
|
||||
pubSocket.tell(new ZMQMessage(new Frame("health.load"),
|
||||
new Frame(loadPayload)), getSelf());
|
||||
pubSocket.tell(ZMQMessage.withFrames(loadTopic, loadPayload), getSelf());
|
||||
} else {
|
||||
unhandled(message);
|
||||
}
|
||||
|
|
@ -248,13 +253,14 @@ public class ZeromqDocTestBase {
|
|||
public void onReceive(Object message) {
|
||||
if (message instanceof ZMQMessage) {
|
||||
ZMQMessage m = (ZMQMessage) message;
|
||||
String topic = m.frame(0).utf8String();
|
||||
// the first frame is the topic, second is the message
|
||||
if (m.firstFrameAsString().equals("health.heap")) {
|
||||
Heap heap = (Heap) ser.serializerFor(Heap.class).fromBinary(m.payload(1));
|
||||
if ("health.heap".equals(topic)) {
|
||||
Heap heap = ser.deserialize(m.frame(1).toArray(), Heap.class).get();
|
||||
log.info("Used heap {} bytes, at {}", heap.used,
|
||||
timestampFormat.format(new Date(heap.timestamp)));
|
||||
} else if (m.firstFrameAsString().equals("health.load")) {
|
||||
Load load = (Load) ser.serializerFor(Load.class).fromBinary(m.payload(1));
|
||||
} else if ("health.load".equals(topic)) {
|
||||
Load load = ser.deserialize(m.frame(1).toArray(), Load.class).get();
|
||||
log.info("Load average {}, at {}", load.loadAverage,
|
||||
timestampFormat.format(new Date(load.timestamp)));
|
||||
}
|
||||
|
|
@ -282,9 +288,10 @@ public class ZeromqDocTestBase {
|
|||
public void onReceive(Object message) {
|
||||
if (message instanceof ZMQMessage) {
|
||||
ZMQMessage m = (ZMQMessage) message;
|
||||
String topic = m.frame(0).utf8String();
|
||||
// the first frame is the topic, second is the message
|
||||
if (m.firstFrameAsString().equals("health.heap")) {
|
||||
Heap heap = (Heap) ser.serializerFor(Heap.class).fromBinary(m.payload(1));
|
||||
if ("health.heap".equals(topic)) {
|
||||
Heap heap = ser.<Heap>deserialize(m.frame(1).toArray(), Heap.class).get();
|
||||
if (((double) heap.used / heap.max) > 0.9) {
|
||||
count += 1;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -32,10 +32,19 @@ The ``timerActive_?`` method has been deprecated in both the ``FSM`` trait and t
|
|||
class. You should now use the ``isTimerActive`` method instead. The old method will remain
|
||||
throughout 2.2.x. It will be removed in Akka 2.3.
|
||||
|
||||
|
||||
ThreadPoolConfigBuilder
|
||||
=======================
|
||||
|
||||
``akka.dispatch.ThreadPoolConfigBuilder`` companion object has been removed,
|
||||
and with it the ``conf_?`` method that was essentially only a type-inferencer aid for creation
|
||||
of optional transformations on ``ThreadPoolConfigBuilder``.
|
||||
Instead use: ``option.map(o => (t: ThreadPoolConfigBuilder) => t.op(o))``.
|
||||
Instead use: ``option.map(o => (t: ThreadPoolConfigBuilder) => t.op(o))``.
|
||||
|
||||
|
||||
ZeroMQ ByteString
|
||||
=================
|
||||
|
||||
``akka.zeromq.Frame`` and the use of ``Seq[Byte]`` in the API has been removed and is replaced by ``akka.util.ByteString``.
|
||||
|
||||
``ZMQMessage.firstFrameAsString`` has been removed, please use ``ZMQMessage.frames`` or ``ZMQMessage.frame(int)`` to access the frames.
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ package docs.zeromq
|
|||
import language.postfixOps
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import scala.collection.immutable
|
||||
import akka.actor.{ Actor, Props }
|
||||
import akka.util.ByteString
|
||||
import akka.testkit._
|
||||
import akka.zeromq.{ ZeroMQVersion, ZeroMQExtension, SocketType, Bind }
|
||||
import java.text.SimpleDateFormat
|
||||
|
|
@ -53,12 +53,12 @@ object ZeromqDocSpec {
|
|||
val heapPayload = ser.serialize(Heap(timestamp, currentHeap.getUsed,
|
||||
currentHeap.getMax)).get
|
||||
// the first frame is the topic, second is the message
|
||||
pubSocket ! ZMQMessage(immutable.Seq(Frame("health.heap"), Frame(heapPayload)))
|
||||
pubSocket ! ZMQMessage(ByteString("health.heap"), ByteString(heapPayload))
|
||||
|
||||
// use akka SerializationExtension to convert to bytes
|
||||
val loadPayload = ser.serialize(Load(timestamp, os.getSystemLoadAverage)).get
|
||||
// the first frame is the topic, second is the message
|
||||
pubSocket ! ZMQMessage(immutable.Seq(Frame("health.load"), Frame(loadPayload)))
|
||||
pubSocket ! ZMQMessage(ByteString("health.load"), ByteString(loadPayload))
|
||||
}
|
||||
}
|
||||
//#health
|
||||
|
|
@ -73,14 +73,14 @@ object ZeromqDocSpec {
|
|||
|
||||
def receive = {
|
||||
// the first frame is the topic, second is the message
|
||||
case m: ZMQMessage if m.firstFrameAsString == "health.heap" ⇒
|
||||
val Heap(timestamp, used, max) = ser.deserialize(m.payload(1),
|
||||
case m: ZMQMessage if m.frames(0).utf8String == "health.heap" ⇒
|
||||
val Heap(timestamp, used, max) = ser.deserialize(m.frames(1).toArray,
|
||||
classOf[Heap]).get
|
||||
log.info("Used heap {} bytes, at {}", used,
|
||||
timestampFormat.format(new Date(timestamp)))
|
||||
|
||||
case m: ZMQMessage if m.firstFrameAsString == "health.load" ⇒
|
||||
val Load(timestamp, loadAverage) = ser.deserialize(m.payload(1),
|
||||
case m: ZMQMessage if m.frames(0).utf8String == "health.load" ⇒
|
||||
val Load(timestamp, loadAverage) = ser.deserialize(m.frames(1).toArray,
|
||||
classOf[Load]).get
|
||||
log.info("Load average {}, at {}", loadAverage,
|
||||
timestampFormat.format(new Date(timestamp)))
|
||||
|
|
@ -98,9 +98,8 @@ object ZeromqDocSpec {
|
|||
|
||||
def receive = {
|
||||
// the first frame is the topic, second is the message
|
||||
case m: ZMQMessage if m.firstFrameAsString == "health.heap" ⇒
|
||||
val Heap(timestamp, used, max) = ser.deserialize(m.payload(1),
|
||||
classOf[Heap]).get
|
||||
case m: ZMQMessage if m.frames(0).utf8String == "health.heap" ⇒
|
||||
val Heap(timestamp, used, max) = ser.deserialize(m.frames(1).toArray, classOf[Heap]).get
|
||||
if ((used.toDouble / max) > 0.9) count += 1
|
||||
else count = 0
|
||||
if (count > 10) log.warning("Need more memory, using {} %",
|
||||
|
|
@ -147,7 +146,7 @@ class ZeromqDocSpec extends AkkaSpec("akka.loglevel=INFO") {
|
|||
|
||||
val payload = Array.empty[Byte]
|
||||
//#pub-topic
|
||||
pubSocket ! ZMQMessage(Frame("foo.bar"), Frame(payload))
|
||||
pubSocket ! ZMQMessage(ByteString("foo.bar"), ByteString(payload))
|
||||
//#pub-topic
|
||||
|
||||
system.stop(subSocket)
|
||||
|
|
@ -188,8 +187,9 @@ class ZeromqDocSpec extends AkkaSpec("akka.loglevel=INFO") {
|
|||
|
||||
def checkZeroMQInstallation() = try {
|
||||
ZeroMQExtension(system).version match {
|
||||
case ZeroMQVersion(2, 1, _) ⇒ Unit
|
||||
case version ⇒ pending
|
||||
case ZeroMQVersion(2, x, _) if x >= 1 ⇒ Unit
|
||||
case ZeroMQVersion(y, _, _) if y >= 3 ⇒ Unit
|
||||
case version ⇒ pending
|
||||
}
|
||||
} catch {
|
||||
case e: LinkageError ⇒ pending
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue