All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vlingo.actors.ActorProxyBase Maven / Gradle / Ivy

Go to download

Type safe Actor Model toolkit for reactive concurrency and resiliency using Java and other JVM languages.

There is a newer version: 1.7.5
Show newest version
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();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy