io.vlingo.actors.ActorProxyBase Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vlingo-actors Show documentation
Show all versions of vlingo-actors Show documentation
Type safe Actor Model toolkit for reactive concurrency and resiliency using Java and other JVM languages.
package io.vlingo.actors;
import io.vlingo.actors.Definition.SerializationProxy;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
public abstract class ActorProxyBase implements Externalizable {
private static final long serialVersionUID = -2047182900594333760L;
public static T thunk(ActorProxyBase> proxy, Actor actor, T arg) {
return proxy.isDistributable()
? thunk(actor.lifeCycle.environment.stage, arg)
: arg;
}
public static T thunk(Stage stage, T arg) {
if (arg instanceof ActorProxyBase) {
@SuppressWarnings("unchecked")
final ActorProxyBase base = (ActorProxyBase) arg;
return stage.lookupOrStartThunk(base.protocol,
Definition.from(stage, base.definition, stage.world().defaultLogger()),
base.address);
}
return arg;
}
public Class protocol;
public SerializationProxy definition;
public Address address;
public ActorProxyBase(Class protocol, SerializationProxy definition, Address address) {
this.protocol = protocol;
this.definition = definition;
this.address = address;
}
public ActorProxyBase() { }
public final boolean isDistributable() {
return address.isDistributable();
}
@Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(protocol);
out.writeObject(definition);
out.writeObject(address);
}
@Override
@SuppressWarnings("unchecked")
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { ;
this.protocol = (Class) in.readObject();
this.definition = (SerializationProxy) in.readObject();
this.address = (Address) in.readObject();
}
}