Beispiel #1
0
  public static void main(String args[]) {
    UAN uan = null;
    UAL ual = null;
    if (System.getProperty("uan") != null) {
      uan = new UAN(System.getProperty("uan"));
      ServiceFactory.getTheater();
      RunTime.receivedUniversalActor();
    }
    if (System.getProperty("ual") != null) {
      ual = new UAL(System.getProperty("ual"));

      if (uan == null) {
        System.err.println("Actor Creation Error:");
        System.err.println("	uan: " + uan);
        System.err.println("	ual: " + ual);
        System.err.println("	Identifier: " + System.getProperty("identifier"));
        System.err.println("	Cannot specify an actor to have a ual at runtime without a uan.");
        System.err.println(
            "	To give an actor a specific ual at runtime, use the identifier system property.");
        System.exit(0);
      }
      RunTime.receivedUniversalActor();
    }
    if (System.getProperty("identifier") != null) {
      if (ual != null) {
        System.err.println("Actor Creation Error:");
        System.err.println("	uan: " + uan);
        System.err.println("	ual: " + ual);
        System.err.println("	Identifier: " + System.getProperty("identifier"));
        System.err.println(
            "	Cannot specify an identifier and a ual with system properties when creating an actor.");
        System.exit(0);
      }
      ual = new UAL(ServiceFactory.getTheater().getLocation() + System.getProperty("identifier"));
    }
    RunTime.receivedMessage();
    CrazyMigration instance = (CrazyMigration) new CrazyMigration(uan, ual, null).construct();
    gc.WeakReference instanceRef = new gc.WeakReference(uan, ual);
    {
      Object[] _arguments = {args};

      // preAct() for local actor creation
      // act() for remote actor creation
      if (ual != null && !ual.getLocation().equals(ServiceFactory.getTheater().getLocation())) {
        instance.send(new Message(instanceRef, instanceRef, "act", _arguments, false));
      } else {
        instance.send(new Message(instanceRef, instanceRef, "preAct", _arguments, false));
      }
    }
    RunTime.finishedProcessingMessage();
  }
 public JoinDirector(UAN __uan, UAL __ual) {
   if (__ual != null && !__ual.getLocation().equals(ServiceFactory.getTheater().getLocation())) {
     createRemotely(__uan, __ual, "salsa.language.JoinDirector");
   } else {
     State state = new State(__uan, __ual);
     state.updateSelf(this);
     ServiceFactory.getNaming().setEntry(state.getUAN(), state.getUAL(), state);
     if (getUAN() != null) ServiceFactory.getNaming().update(state.getUAN(), state.getUAL());
   }
 }
Beispiel #3
0
  public CrazyMigration(UAN __uan, UAL __ual, Object obj) {
    // decide the type of sourceActor
    // if obj is null, the actor must be the startup actor.
    // if obj is an actorReference, this actor is created by a remote actor

    if (obj instanceof UniversalActor.State || obj == null) {
      UniversalActor.State sourceActor;
      if (obj != null) {
        sourceActor = (UniversalActor.State) obj;
      } else {
        sourceActor = null;
      }

      // remote creation message sent to a remote system service.
      if (__ual != null && !__ual.getLocation().equals(ServiceFactory.getTheater().getLocation())) {
        WeakReference sourceRef;
        if (sourceActor != null && sourceActor.getUAL() != null) {
          sourceRef = new WeakReference(sourceActor.getUAN(), sourceActor.getUAL());
        } else {
          sourceRef = null;
        }
        if (sourceActor != null) {
          if (__uan != null) {
            sourceActor.getActorMemory().getForwardList().putReference(__uan);
          } else if (__ual != null) {
            sourceActor.getActorMemory().getForwardList().putReference(__ual);
          }

          // update the source of this actor reference
          setSource(sourceActor.getUAN(), sourceActor.getUAL());
          activateGC();
        }
        createRemotely(__uan, __ual, "tests.distributed.CrazyMigration", sourceRef);
      }

      // local creation
      else {
        State state = new State(__uan, __ual);

        // assume the reference is weak
        muteGC();

        // the source actor is  the startup actor
        if (sourceActor == null) {
          state.getActorMemory().getInverseList().putInverseReference("rmsp://me");
        }

        // the souce actor is a normal actor
        else if (sourceActor instanceof UniversalActor.State) {

          // this reference is part of garbage collection
          activateGC();

          // update the source of this actor reference
          setSource(sourceActor.getUAN(), sourceActor.getUAL());

          /* Garbage collection registration:
           * register 'this reference' in sourceActor's forward list @
           * register 'this reference' in the forward acquaintance's inverse list
           */
          String inverseRefString = null;
          if (sourceActor.getUAN() != null) {
            inverseRefString = sourceActor.getUAN().toString();
          } else if (sourceActor.getUAL() != null) {
            inverseRefString = sourceActor.getUAL().toString();
          }
          if (__uan != null) {
            sourceActor.getActorMemory().getForwardList().putReference(__uan);
          } else if (__ual != null) {
            sourceActor.getActorMemory().getForwardList().putReference(__ual);
          } else {
            sourceActor.getActorMemory().getForwardList().putReference(state.getUAL());
          }

          // put the inverse reference information in the actormemory
          if (inverseRefString != null)
            state.getActorMemory().getInverseList().putInverseReference(inverseRefString);
        }
        state.updateSelf(this);
        ServiceFactory.getNaming().setEntry(state.getUAN(), state.getUAL(), state);
        if (getUAN() != null) ServiceFactory.getNaming().update(state.getUAN(), state.getUAL());
      }
    }

    // creation invoked by a remote message
    else if (obj instanceof ActorReference) {
      ActorReference sourceRef = (ActorReference) obj;
      State state = new State(__uan, __ual);
      muteGC();
      state.getActorMemory().getInverseList().putInverseReference("rmsp://me");
      if (sourceRef.getUAN() != null) {
        state.getActorMemory().getInverseList().putInverseReference(sourceRef.getUAN());
      } else if (sourceRef.getUAL() != null) {
        state.getActorMemory().getInverseList().putInverseReference(sourceRef.getUAL());
      }
      state.updateSelf(this);
      ServiceFactory.getNaming().setEntry(state.getUAN(), state.getUAL(), state);
      if (getUAN() != null) ServiceFactory.getNaming().update(state.getUAN(), state.getUAL());
    }
  }