Search in sources :

Example 1 with ActorPath

use of io.transport.cluster.config.ActorPath in project transporter by wang4ever.

the class ActorManager method actorCreate.

/**
 * 创建一个actor
 *
 * @param actorName
 *            actor名称
 * @return
 */
public ActorBean actorCreate(String actorName) {
    // 1.0 Check info.
    if (this._system == null)
        throw new AkkaException("Create actor failed('" + actorName + "'), actor system is unnitialized.");
    if (StringUtils.equalsIgnoreCase(actorName, ActorPath.DEFAULT_ACTOR_NAME) && this.defaultActorBean != null)
        throw new AkkaException("Create actor failed, because the name '" + actorName + "' is the guardian.");
    // 1.1 Create accpetActor.
    try {
        this._system.actorOf(Props.create(AccpetActor.class, actorName), actorName);
    } catch (InvalidActorNameException e) {
        if (logger.isInfoEnabled())
            logger.info("Create an existing actor '{}'", actorName);
    } catch (Throwable t) {
        logger.error("Creating actor '" + actorName + "' failed.", t);
        throw new AkkaException(t.getMessage(), t);
    }
    // 1.2 Selection actor info.
    String path = new ActorPath(conf.getActorSystemName(), conf.getHostname(), conf.getRemote().getPort(), actorName).asString();
    ActorSelection actorSel = this._system.actorSelection(path);
    ActorBean ab = new ActorBean(actorSel.anchor(), path);
    // Default actorBean.
    if (StringUtils.equalsIgnoreCase(actorName, ActorPath.DEFAULT_ACTOR_NAME))
        this.defaultActorBean = ab;
    // 1.3 Save actor info.
    this.repository.putActorBean(actorName, ab);
    return ab;
}
Also used : InvalidActorNameException(akka.actor.InvalidActorNameException) ActorSelection(akka.actor.ActorSelection) ActorPath(io.transport.cluster.config.ActorPath) AccpetActor(io.transport.cluster.actor.AccpetActor) AkkaException(akka.AkkaException)

Aggregations

AkkaException (akka.AkkaException)1 ActorSelection (akka.actor.ActorSelection)1 InvalidActorNameException (akka.actor.InvalidActorNameException)1 AccpetActor (io.transport.cluster.actor.AccpetActor)1 ActorPath (io.transport.cluster.config.ActorPath)1