Fixed final issues in actor deep serialization; now Java and Protobuf support
This commit is contained in:
parent
ed6282393b
commit
306d017e7c
8 changed files with 425 additions and 33 deletions
|
|
@ -40,21 +40,25 @@ abstract class RemoteActor(hostname: String, port: Int) extends Actor {
|
||||||
*
|
*
|
||||||
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
||||||
*/
|
*/
|
||||||
trait SerializableActor[T] extends Actor {
|
trait SerializableActor extends Actor {
|
||||||
val serializer: Serializer
|
val serializer: Serializer
|
||||||
def toBinary: Array[Byte]
|
def toBinary: Array[Byte]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mix in this trait to create a serializable actor, serializable through
|
* Mix in this trait to create a serializable actor, serializable through
|
||||||
* Protobuf. This trait needs to be mixed in with a Protobuf
|
* Protobuf.
|
||||||
* 'com.google.protobuf.Message' generated class holding the state.
|
|
||||||
*
|
*
|
||||||
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
||||||
*/
|
*/
|
||||||
trait ProtobufSerializableActor[T] extends SerializableActor[T] { this: Message =>
|
trait ProtobufSerializableActor[T <: Message] extends SerializableActor {
|
||||||
val serializer = Serializer.Protobuf
|
val serializer = Serializer.Protobuf
|
||||||
def toBinary: Array[Byte] = this.toByteArray
|
def toBinary: Array[Byte] = toProtobuf.toByteArray
|
||||||
|
def fromBinary(bytes: Array[Byte]) = fromProtobuf(serializer.fromBinary(bytes, Some(clazz)).asInstanceOf[T])
|
||||||
|
|
||||||
|
val clazz: Class[T]
|
||||||
|
def toProtobuf: T
|
||||||
|
def fromProtobuf(message: T): Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -63,7 +67,7 @@ trait ProtobufSerializableActor[T] extends SerializableActor[T] { this: Message
|
||||||
*
|
*
|
||||||
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
||||||
*/
|
*/
|
||||||
trait JavaSerializableActor[T] extends SerializableActor[T] {
|
trait JavaSerializableActor extends SerializableActor {
|
||||||
@transient val serializer = Serializer.Java
|
@transient val serializer = Serializer.Java
|
||||||
def toBinary: Array[Byte] = serializer.toBinary(this)
|
def toBinary: Array[Byte] = serializer.toBinary(this)
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +78,7 @@ trait JavaSerializableActor[T] extends SerializableActor[T] {
|
||||||
*
|
*
|
||||||
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
||||||
*/
|
*/
|
||||||
trait JavaJSONSerializableActor[T] extends SerializableActor[T] {
|
trait JavaJSONSerializableActor extends SerializableActor {
|
||||||
val serializer = Serializer.JavaJSON
|
val serializer = Serializer.JavaJSON
|
||||||
def toBinary: Array[Byte] = serializer.toBinary(this)
|
def toBinary: Array[Byte] = serializer.toBinary(this)
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +89,7 @@ trait JavaJSONSerializableActor[T] extends SerializableActor[T] {
|
||||||
*
|
*
|
||||||
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
||||||
*/
|
*/
|
||||||
trait ScalaJSONSerializableActor[T] extends SerializableActor[T] {
|
trait ScalaJSONSerializableActor extends SerializableActor {
|
||||||
val serializer = Serializer.ScalaJSON
|
val serializer = Serializer.ScalaJSON
|
||||||
def toBinary: Array[Byte] = serializer.toBinary(this)
|
def toBinary: Array[Byte] = serializer.toBinary(this)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -334,7 +334,7 @@ trait ActorRef extends TransactionManagement {
|
||||||
/**
|
/**
|
||||||
* Is the actor is serializable?
|
* Is the actor is serializable?
|
||||||
*/
|
*/
|
||||||
def isSerializable: Boolean = actor.isInstanceOf[SerializableActor[_]]
|
def isSerializable: Boolean = actor.isInstanceOf[SerializableActor]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the 'Serializer' instance for the Actor as an Option.
|
* Returns the 'Serializer' instance for the Actor as an Option.
|
||||||
|
|
@ -342,7 +342,7 @@ trait ActorRef extends TransactionManagement {
|
||||||
* It returns 'Some(serializer)' if the Actor is serializable and 'None' if not.
|
* It returns 'Some(serializer)' if the Actor is serializable and 'None' if not.
|
||||||
*/
|
*/
|
||||||
def serializer: Option[Serializer] =
|
def serializer: Option[Serializer] =
|
||||||
if (isSerializable) Some(actor.asInstanceOf[SerializableActor[_]].serializer)
|
if (isSerializable) Some(actor.asInstanceOf[SerializableActor].serializer)
|
||||||
else None
|
else None
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -695,7 +695,15 @@ sealed class LocalActorRef private[akka](
|
||||||
__hotswap: Option[PartialFunction[Any, Unit]],
|
__hotswap: Option[PartialFunction[Any, Unit]],
|
||||||
__loader: ClassLoader,
|
__loader: ClassLoader,
|
||||||
__serializer: Serializer) = {
|
__serializer: Serializer) = {
|
||||||
this(() => __serializer.fromBinary(__actorBytes, Some(__loader.loadClass(__actorClassName))).asInstanceOf[Actor])
|
this(() => {
|
||||||
|
val actorClass = __loader.loadClass(__actorClassName)
|
||||||
|
val actorInstance = actorClass.newInstance
|
||||||
|
if (actorInstance.isInstanceOf[ProtobufSerializableActor[_]]) {
|
||||||
|
val instance = actorInstance.asInstanceOf[ProtobufSerializableActor[_]]
|
||||||
|
instance.fromBinary(__actorBytes)
|
||||||
|
instance
|
||||||
|
} else __serializer.fromBinary(__actorBytes, Some(actorClass)).asInstanceOf[Actor]
|
||||||
|
})
|
||||||
loader = Some(__loader)
|
loader = Some(__loader)
|
||||||
isDeserialized = true
|
isDeserialized = true
|
||||||
_uuid = __uuid
|
_uuid = __uuid
|
||||||
|
|
@ -783,7 +791,7 @@ sealed class LocalActorRef private[akka](
|
||||||
.setUuid(uuid)
|
.setUuid(uuid)
|
||||||
.setId(id)
|
.setId(id)
|
||||||
.setActorClassname(actorClass.getName)
|
.setActorClassname(actorClass.getName)
|
||||||
.setActorInstance(ByteString.copyFrom(actor.asInstanceOf[SerializableActor[_]].toBinary))
|
.setActorInstance(ByteString.copyFrom(actor.asInstanceOf[SerializableActor].toBinary))
|
||||||
.setSerializerClassname(serializerClassname)
|
.setSerializerClassname(serializerClassname)
|
||||||
.setOriginalAddress(originalAddress)
|
.setOriginalAddress(originalAddress)
|
||||||
.setIsTransactor(isTransactor)
|
.setIsTransactor(isTransactor)
|
||||||
|
|
|
||||||
|
|
@ -30,21 +30,22 @@ object Scheduler {
|
||||||
private var service = Executors.newSingleThreadScheduledExecutor(SchedulerThreadFactory)
|
private var service = Executors.newSingleThreadScheduledExecutor(SchedulerThreadFactory)
|
||||||
private val schedulers = new ConcurrentHashMap[ActorRef, ActorRef]
|
private val schedulers = new ConcurrentHashMap[ActorRef, ActorRef]
|
||||||
|
|
||||||
def schedule(receiver: ActorRef, message: AnyRef, initialDelay: Long, delay: Long, timeUnit: TimeUnit) = {
|
def schedule(receiver: ActorRef, message: AnyRef, initialDelay: Long, delay: Long, timeUnit: TimeUnit): ActorRef = {
|
||||||
try {
|
try {
|
||||||
val future = service.scheduleAtFixedRate(
|
val future = service.scheduleAtFixedRate(
|
||||||
new Runnable { def run = receiver ! message },
|
new Runnable { def run = receiver ! message },
|
||||||
initialDelay, delay, timeUnit).asInstanceOf[ScheduledFuture[AnyRef]]
|
initialDelay, delay, timeUnit).asInstanceOf[ScheduledFuture[AnyRef]]
|
||||||
val scheduler = actorOf(new ScheduleActor(future)).start
|
val scheduler = actorOf(new ScheduleActor(future)).start
|
||||||
schedulers.put(scheduler, scheduler)
|
schedulers.put(scheduler, scheduler)
|
||||||
|
scheduler
|
||||||
} catch {
|
} catch {
|
||||||
case e => throw SchedulerException(message + " could not be scheduled on " + receiver, e)
|
case e => throw SchedulerException(message + " could not be scheduled on " + receiver, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def unschedule(actorRef: ActorRef) = {
|
def unschedule(scheduleActor: ActorRef) = {
|
||||||
actorRef ! UnSchedule
|
scheduleActor ! UnSchedule
|
||||||
schedulers.remove(actorRef)
|
schedulers.remove(scheduleActor)
|
||||||
}
|
}
|
||||||
|
|
||||||
def shutdown = {
|
def shutdown = {
|
||||||
|
|
@ -79,5 +80,3 @@ private object SchedulerThreadFactory extends ThreadFactory {
|
||||||
thread
|
thread
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import java.net.UnknownHostException
|
||||||
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
||||||
*/
|
*/
|
||||||
trait Logging {
|
trait Logging {
|
||||||
@transient lazy val log = Logger.get(this.getClass.getName)
|
@sjson.json.JSONProperty(ignore = true) @transient lazy val log = Logger.get(this.getClass.getName)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -376,11 +376,301 @@ public final class ProtobufProtocol {
|
||||||
// @@protoc_insertion_point(class_scope:se.scalablesolutions.akka.actor.ProtobufPOJO)
|
// @@protoc_insertion_point(class_scope:se.scalablesolutions.akka.actor.ProtobufPOJO)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final class Counter extends
|
||||||
|
com.google.protobuf.GeneratedMessage {
|
||||||
|
// Use Counter.newBuilder() to construct.
|
||||||
|
private Counter() {
|
||||||
|
initFields();
|
||||||
|
}
|
||||||
|
private Counter(boolean noInit) {}
|
||||||
|
|
||||||
|
private static final Counter defaultInstance;
|
||||||
|
public static Counter getDefaultInstance() {
|
||||||
|
return defaultInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Counter getDefaultInstanceForType() {
|
||||||
|
return defaultInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final com.google.protobuf.Descriptors.Descriptor
|
||||||
|
getDescriptor() {
|
||||||
|
return se.scalablesolutions.akka.actor.ProtobufProtocol.internal_static_se_scalablesolutions_akka_actor_Counter_descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||||
|
internalGetFieldAccessorTable() {
|
||||||
|
return se.scalablesolutions.akka.actor.ProtobufProtocol.internal_static_se_scalablesolutions_akka_actor_Counter_fieldAccessorTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
// required uint32 count = 1;
|
||||||
|
public static final int COUNT_FIELD_NUMBER = 1;
|
||||||
|
private boolean hasCount;
|
||||||
|
private int count_ = 0;
|
||||||
|
public boolean hasCount() { return hasCount; }
|
||||||
|
public int getCount() { return count_; }
|
||||||
|
|
||||||
|
private void initFields() {
|
||||||
|
}
|
||||||
|
public final boolean isInitialized() {
|
||||||
|
if (!hasCount) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeTo(com.google.protobuf.CodedOutputStream output)
|
||||||
|
throws java.io.IOException {
|
||||||
|
getSerializedSize();
|
||||||
|
if (hasCount()) {
|
||||||
|
output.writeUInt32(1, getCount());
|
||||||
|
}
|
||||||
|
getUnknownFields().writeTo(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int memoizedSerializedSize = -1;
|
||||||
|
public int getSerializedSize() {
|
||||||
|
int size = memoizedSerializedSize;
|
||||||
|
if (size != -1) return size;
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
if (hasCount()) {
|
||||||
|
size += com.google.protobuf.CodedOutputStream
|
||||||
|
.computeUInt32Size(1, getCount());
|
||||||
|
}
|
||||||
|
size += getUnknownFields().getSerializedSize();
|
||||||
|
memoizedSerializedSize = size;
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static se.scalablesolutions.akka.actor.ProtobufProtocol.Counter parseFrom(
|
||||||
|
com.google.protobuf.ByteString data)
|
||||||
|
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||||
|
return newBuilder().mergeFrom(data).buildParsed();
|
||||||
|
}
|
||||||
|
public static se.scalablesolutions.akka.actor.ProtobufProtocol.Counter parseFrom(
|
||||||
|
com.google.protobuf.ByteString data,
|
||||||
|
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||||
|
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||||
|
return newBuilder().mergeFrom(data, extensionRegistry)
|
||||||
|
.buildParsed();
|
||||||
|
}
|
||||||
|
public static se.scalablesolutions.akka.actor.ProtobufProtocol.Counter parseFrom(byte[] data)
|
||||||
|
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||||
|
return newBuilder().mergeFrom(data).buildParsed();
|
||||||
|
}
|
||||||
|
public static se.scalablesolutions.akka.actor.ProtobufProtocol.Counter parseFrom(
|
||||||
|
byte[] data,
|
||||||
|
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||||
|
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||||
|
return newBuilder().mergeFrom(data, extensionRegistry)
|
||||||
|
.buildParsed();
|
||||||
|
}
|
||||||
|
public static se.scalablesolutions.akka.actor.ProtobufProtocol.Counter parseFrom(java.io.InputStream input)
|
||||||
|
throws java.io.IOException {
|
||||||
|
return newBuilder().mergeFrom(input).buildParsed();
|
||||||
|
}
|
||||||
|
public static se.scalablesolutions.akka.actor.ProtobufProtocol.Counter parseFrom(
|
||||||
|
java.io.InputStream input,
|
||||||
|
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||||
|
throws java.io.IOException {
|
||||||
|
return newBuilder().mergeFrom(input, extensionRegistry)
|
||||||
|
.buildParsed();
|
||||||
|
}
|
||||||
|
public static se.scalablesolutions.akka.actor.ProtobufProtocol.Counter parseDelimitedFrom(java.io.InputStream input)
|
||||||
|
throws java.io.IOException {
|
||||||
|
Builder builder = newBuilder();
|
||||||
|
if (builder.mergeDelimitedFrom(input)) {
|
||||||
|
return builder.buildParsed();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static se.scalablesolutions.akka.actor.ProtobufProtocol.Counter parseDelimitedFrom(
|
||||||
|
java.io.InputStream input,
|
||||||
|
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||||
|
throws java.io.IOException {
|
||||||
|
Builder builder = newBuilder();
|
||||||
|
if (builder.mergeDelimitedFrom(input, extensionRegistry)) {
|
||||||
|
return builder.buildParsed();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static se.scalablesolutions.akka.actor.ProtobufProtocol.Counter parseFrom(
|
||||||
|
com.google.protobuf.CodedInputStream input)
|
||||||
|
throws java.io.IOException {
|
||||||
|
return newBuilder().mergeFrom(input).buildParsed();
|
||||||
|
}
|
||||||
|
public static se.scalablesolutions.akka.actor.ProtobufProtocol.Counter parseFrom(
|
||||||
|
com.google.protobuf.CodedInputStream input,
|
||||||
|
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||||
|
throws java.io.IOException {
|
||||||
|
return newBuilder().mergeFrom(input, extensionRegistry)
|
||||||
|
.buildParsed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder newBuilder() { return Builder.create(); }
|
||||||
|
public Builder newBuilderForType() { return newBuilder(); }
|
||||||
|
public static Builder newBuilder(se.scalablesolutions.akka.actor.ProtobufProtocol.Counter prototype) {
|
||||||
|
return newBuilder().mergeFrom(prototype);
|
||||||
|
}
|
||||||
|
public Builder toBuilder() { return newBuilder(this); }
|
||||||
|
|
||||||
|
public static final class Builder extends
|
||||||
|
com.google.protobuf.GeneratedMessage.Builder<Builder> {
|
||||||
|
private se.scalablesolutions.akka.actor.ProtobufProtocol.Counter result;
|
||||||
|
|
||||||
|
// Construct using se.scalablesolutions.akka.actor.ProtobufProtocol.Counter.newBuilder()
|
||||||
|
private Builder() {}
|
||||||
|
|
||||||
|
private static Builder create() {
|
||||||
|
Builder builder = new Builder();
|
||||||
|
builder.result = new se.scalablesolutions.akka.actor.ProtobufProtocol.Counter();
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected se.scalablesolutions.akka.actor.ProtobufProtocol.Counter internalGetResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder clear() {
|
||||||
|
if (result == null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Cannot call clear() after build().");
|
||||||
|
}
|
||||||
|
result = new se.scalablesolutions.akka.actor.ProtobufProtocol.Counter();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder clone() {
|
||||||
|
return create().mergeFrom(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public com.google.protobuf.Descriptors.Descriptor
|
||||||
|
getDescriptorForType() {
|
||||||
|
return se.scalablesolutions.akka.actor.ProtobufProtocol.Counter.getDescriptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public se.scalablesolutions.akka.actor.ProtobufProtocol.Counter getDefaultInstanceForType() {
|
||||||
|
return se.scalablesolutions.akka.actor.ProtobufProtocol.Counter.getDefaultInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInitialized() {
|
||||||
|
return result.isInitialized();
|
||||||
|
}
|
||||||
|
public se.scalablesolutions.akka.actor.ProtobufProtocol.Counter build() {
|
||||||
|
if (result != null && !isInitialized()) {
|
||||||
|
throw newUninitializedMessageException(result);
|
||||||
|
}
|
||||||
|
return buildPartial();
|
||||||
|
}
|
||||||
|
|
||||||
|
private se.scalablesolutions.akka.actor.ProtobufProtocol.Counter buildParsed()
|
||||||
|
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||||
|
if (!isInitialized()) {
|
||||||
|
throw newUninitializedMessageException(
|
||||||
|
result).asInvalidProtocolBufferException();
|
||||||
|
}
|
||||||
|
return buildPartial();
|
||||||
|
}
|
||||||
|
|
||||||
|
public se.scalablesolutions.akka.actor.ProtobufProtocol.Counter buildPartial() {
|
||||||
|
if (result == null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"build() has already been called on this Builder.");
|
||||||
|
}
|
||||||
|
se.scalablesolutions.akka.actor.ProtobufProtocol.Counter returnMe = result;
|
||||||
|
result = null;
|
||||||
|
return returnMe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder mergeFrom(com.google.protobuf.Message other) {
|
||||||
|
if (other instanceof se.scalablesolutions.akka.actor.ProtobufProtocol.Counter) {
|
||||||
|
return mergeFrom((se.scalablesolutions.akka.actor.ProtobufProtocol.Counter)other);
|
||||||
|
} else {
|
||||||
|
super.mergeFrom(other);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder mergeFrom(se.scalablesolutions.akka.actor.ProtobufProtocol.Counter other) {
|
||||||
|
if (other == se.scalablesolutions.akka.actor.ProtobufProtocol.Counter.getDefaultInstance()) return this;
|
||||||
|
if (other.hasCount()) {
|
||||||
|
setCount(other.getCount());
|
||||||
|
}
|
||||||
|
this.mergeUnknownFields(other.getUnknownFields());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder mergeFrom(
|
||||||
|
com.google.protobuf.CodedInputStream input,
|
||||||
|
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||||
|
throws java.io.IOException {
|
||||||
|
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
|
||||||
|
com.google.protobuf.UnknownFieldSet.newBuilder(
|
||||||
|
this.getUnknownFields());
|
||||||
|
while (true) {
|
||||||
|
int tag = input.readTag();
|
||||||
|
switch (tag) {
|
||||||
|
case 0:
|
||||||
|
this.setUnknownFields(unknownFields.build());
|
||||||
|
return this;
|
||||||
|
default: {
|
||||||
|
if (!parseUnknownField(input, unknownFields,
|
||||||
|
extensionRegistry, tag)) {
|
||||||
|
this.setUnknownFields(unknownFields.build());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 8: {
|
||||||
|
setCount(input.readUInt32());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// required uint32 count = 1;
|
||||||
|
public boolean hasCount() {
|
||||||
|
return result.hasCount();
|
||||||
|
}
|
||||||
|
public int getCount() {
|
||||||
|
return result.getCount();
|
||||||
|
}
|
||||||
|
public Builder setCount(int value) {
|
||||||
|
result.hasCount = true;
|
||||||
|
result.count_ = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public Builder clearCount() {
|
||||||
|
result.hasCount = false;
|
||||||
|
result.count_ = 0;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @@protoc_insertion_point(builder_scope:se.scalablesolutions.akka.actor.Counter)
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
defaultInstance = new Counter(true);
|
||||||
|
se.scalablesolutions.akka.actor.ProtobufProtocol.internalForceInit();
|
||||||
|
defaultInstance.initFields();
|
||||||
|
}
|
||||||
|
|
||||||
|
// @@protoc_insertion_point(class_scope:se.scalablesolutions.akka.actor.Counter)
|
||||||
|
}
|
||||||
|
|
||||||
private static com.google.protobuf.Descriptors.Descriptor
|
private static com.google.protobuf.Descriptors.Descriptor
|
||||||
internal_static_se_scalablesolutions_akka_actor_ProtobufPOJO_descriptor;
|
internal_static_se_scalablesolutions_akka_actor_ProtobufPOJO_descriptor;
|
||||||
private static
|
private static
|
||||||
com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||||
internal_static_se_scalablesolutions_akka_actor_ProtobufPOJO_fieldAccessorTable;
|
internal_static_se_scalablesolutions_akka_actor_ProtobufPOJO_fieldAccessorTable;
|
||||||
|
private static com.google.protobuf.Descriptors.Descriptor
|
||||||
|
internal_static_se_scalablesolutions_akka_actor_Counter_descriptor;
|
||||||
|
private static
|
||||||
|
com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||||
|
internal_static_se_scalablesolutions_akka_actor_Counter_fieldAccessorTable;
|
||||||
|
|
||||||
public static com.google.protobuf.Descriptors.FileDescriptor
|
public static com.google.protobuf.Descriptors.FileDescriptor
|
||||||
getDescriptor() {
|
getDescriptor() {
|
||||||
|
|
@ -392,7 +682,8 @@ public final class ProtobufProtocol {
|
||||||
java.lang.String[] descriptorData = {
|
java.lang.String[] descriptorData = {
|
||||||
"\n\026ProtobufProtocol.proto\022\037se.scalablesol" +
|
"\n\026ProtobufProtocol.proto\022\037se.scalablesol" +
|
||||||
"utions.akka.actor\"8\n\014ProtobufPOJO\022\n\n\002id\030" +
|
"utions.akka.actor\"8\n\014ProtobufPOJO\022\n\n\002id\030" +
|
||||||
"\001 \002(\004\022\014\n\004name\030\002 \002(\t\022\016\n\006status\030\003 \002(\010"
|
"\001 \002(\004\022\014\n\004name\030\002 \002(\t\022\016\n\006status\030\003 \002(\010\"\030\n\007C" +
|
||||||
|
"ounter\022\r\n\005count\030\001 \002(\r"
|
||||||
};
|
};
|
||||||
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
||||||
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
|
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
|
||||||
|
|
@ -407,6 +698,14 @@ public final class ProtobufProtocol {
|
||||||
new java.lang.String[] { "Id", "Name", "Status", },
|
new java.lang.String[] { "Id", "Name", "Status", },
|
||||||
se.scalablesolutions.akka.actor.ProtobufProtocol.ProtobufPOJO.class,
|
se.scalablesolutions.akka.actor.ProtobufProtocol.ProtobufPOJO.class,
|
||||||
se.scalablesolutions.akka.actor.ProtobufProtocol.ProtobufPOJO.Builder.class);
|
se.scalablesolutions.akka.actor.ProtobufProtocol.ProtobufPOJO.Builder.class);
|
||||||
|
internal_static_se_scalablesolutions_akka_actor_Counter_descriptor =
|
||||||
|
getDescriptor().getMessageTypes().get(1);
|
||||||
|
internal_static_se_scalablesolutions_akka_actor_Counter_fieldAccessorTable = new
|
||||||
|
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
|
||||||
|
internal_static_se_scalablesolutions_akka_actor_Counter_descriptor,
|
||||||
|
new java.lang.String[] { "Count", },
|
||||||
|
se.scalablesolutions.akka.actor.ProtobufProtocol.Counter.class,
|
||||||
|
se.scalablesolutions.akka.actor.ProtobufProtocol.Counter.Builder.class);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -15,3 +15,7 @@ message ProtobufPOJO {
|
||||||
required string name = 2;
|
required string name = 2;
|
||||||
required bool status = 3;
|
required bool status = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message Counter {
|
||||||
|
required uint32 count = 1;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ import org.scalatest.BeforeAndAfterAll
|
||||||
import org.scalatest.junit.JUnitRunner
|
import org.scalatest.junit.JUnitRunner
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
|
import com.google.protobuf.Message
|
||||||
|
|
||||||
@RunWith(classOf[JUnitRunner])
|
@RunWith(classOf[JUnitRunner])
|
||||||
class SerializableActorSpec extends
|
class SerializableActorSpec extends
|
||||||
Spec with
|
Spec with
|
||||||
|
|
@ -19,19 +21,95 @@ class SerializableActorSpec extends
|
||||||
it("should be able to serialize and deserialize a JavaSerializableActor") {
|
it("should be able to serialize and deserialize a JavaSerializableActor") {
|
||||||
val actor1 = actorOf[JavaSerializableTestActor].start
|
val actor1 = actorOf[JavaSerializableTestActor].start
|
||||||
val serializer = actor1.serializer.getOrElse(fail("Serializer not defined"))
|
val serializer = actor1.serializer.getOrElse(fail("Serializer not defined"))
|
||||||
(actor1 !! "hello").getOrElse("_") should equal("world")
|
(actor1 !! "hello").getOrElse("_") should equal("world 1")
|
||||||
|
|
||||||
val bytes = actor1.toBinary
|
val bytes = actor1.toBinary
|
||||||
val actor2 = ActorRef.fromBinaryToLocalActorRef(bytes)
|
val actor2 = ActorRef.fromBinaryToLocalActorRef(bytes)
|
||||||
|
|
||||||
actor2.start
|
actor2.start
|
||||||
(actor2 !! "hello").getOrElse("_") should equal("world")
|
(actor2 !! "hello").getOrElse("_") should equal("world 2")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it("should be able to serialize and deserialize a ProtobufSerializableActor") {
|
||||||
|
val actor1 = actorOf[ProtobufSerializableTestActor].start
|
||||||
|
val serializer = actor1.serializer.getOrElse(fail("Serializer not defined"))
|
||||||
|
(actor1 !! "hello").getOrElse("_") should equal("world 1")
|
||||||
|
(actor1 !! "hello").getOrElse("_") should equal("world 2")
|
||||||
|
|
||||||
|
val bytes = actor1.toBinary
|
||||||
|
val actor2 = ActorRef.fromBinaryToLocalActorRef(bytes)
|
||||||
|
|
||||||
|
actor2.start
|
||||||
|
(actor2 !! "hello").getOrElse("_") should equal("world 3")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
it("should be able to serialize and deserialize a JavaJSONSerializableActor") {
|
||||||
|
val actor1 = actorOf[JavaJSONSerializableTestActor].start
|
||||||
|
val serializer = actor1.serializer.getOrElse(fail("Serializer not defined"))
|
||||||
|
(actor1 !! "hello").getOrElse("_") should equal("world 1")
|
||||||
|
(actor1 !! "hello").getOrElse("_") should equal("world 2")
|
||||||
|
|
||||||
|
val bytes = actor1.toBinary
|
||||||
|
val actor2 = ActorRef.fromBinaryToLocalActorRef(bytes)
|
||||||
|
|
||||||
|
actor2.start
|
||||||
|
(actor2 !! "hello").getOrElse("_") should equal("world 3")
|
||||||
|
}
|
||||||
|
|
||||||
|
it("should be able to serialize and deserialize a ScalaJSONSerializableActor") {
|
||||||
|
val actor1 = actorOf[ScalaJSONSerializableTestActor].start
|
||||||
|
val serializer = actor1.serializer.getOrElse(fail("Serializer not defined"))
|
||||||
|
(actor1 !! "hello").getOrElse("_") should equal("world 1")
|
||||||
|
|
||||||
|
val bytes = actor1.toBinary
|
||||||
|
val actor2 = ActorRef.fromBinaryToLocalActorRef(bytes)
|
||||||
|
|
||||||
|
actor2.start
|
||||||
|
(actor2 !! "hello").getOrElse("_") should equal("world 2")
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@serializable class JavaSerializableTestActor extends JavaSerializableActor[JavaSerializableTestActor] {
|
@serializable class JavaSerializableTestActor extends JavaSerializableActor {
|
||||||
|
private var count = 0
|
||||||
def receive = {
|
def receive = {
|
||||||
case "hello" => reply("world")
|
case "hello" =>
|
||||||
|
count = count + 1
|
||||||
|
self.reply("world " + count)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ProtobufSerializableTestActor extends ProtobufSerializableActor[ProtobufProtocol.Counter] {
|
||||||
|
val clazz = classOf[ProtobufProtocol.Counter]
|
||||||
|
private var count = 0
|
||||||
|
|
||||||
|
def toProtobuf = ProtobufProtocol.Counter.newBuilder.setCount(count).build
|
||||||
|
def fromProtobuf(message: ProtobufProtocol.Counter) = count = message.getCount
|
||||||
|
|
||||||
|
def receive = {
|
||||||
|
case "hello" =>
|
||||||
|
count = count + 1
|
||||||
|
self.reply("world " + count)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class JavaJSONSerializableTestActor extends JavaJSONSerializableActor {
|
||||||
|
private var count = 0
|
||||||
|
def receive = {
|
||||||
|
case "hello" =>
|
||||||
|
count = count + 1
|
||||||
|
self.reply("world " + count)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@scala.reflect.BeanInfo class ScalaJSONSerializableTestActor extends ScalaJSONSerializableActor {
|
||||||
|
private var count = 0
|
||||||
|
def receive = {
|
||||||
|
case "hello" =>
|
||||||
|
count = count + 1
|
||||||
|
self.reply("world " + count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -150,7 +150,7 @@ class CassandraPersistentActorSpec extends JUnitSuite {
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
import org.apache.cassandra.service.CassandraDaemon
|
import org.apache.cassandra.service.CassandraDaemon
|
||||||
object EmbeddedCassandraService {
|
object // EmbeddedCassandraService {
|
||||||
|
|
||||||
System.setProperty("storage-config", "src/test/resources");
|
System.setProperty("storage-config", "src/test/resources");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue