use of akka.AkkaException in project transporter by wang4ever.
the class ActorManager method run.
@Override
public void run(ApplicationArguments args) throws Exception {
if (this.started) {
logger.warn("Actor system initialized.");
return;
}
// 1.1 Creating a local actor system.
try {
this._system = ActorSystem.create(conf.getActorSystemName(), conf.getConfig());
// 1.2 Create a local default actor.
this.actorCreate(ActorPath.DEFAULT_ACTOR_NAME);
this.started = true;
if (logger.isInfoEnabled())
logger.info("Actor system initialization successfully.");
} catch (Throwable t) {
throw new AkkaException("Initialization of the actor system has failed.", t);
}
// 2.1 Save cluster node info.
try {
NodeInfo hap = new NodeInfo(conf.getHostname(), conf.getConfiguration().getRpcConfig().getPort(), conf.getConfiguration().getWsConfig().getPort(), conf.getRemote().getPort());
// 初始化加入集群
this.clusterService.initial(hap);
} catch (Exception e) {
throw new AkkaException("Failure to initial the cluster node information.", e);
}
}
use of akka.AkkaException in project flink by apache.
the class SupervisorActor method createStartAkkaRpcActorMessage.
private void createStartAkkaRpcActorMessage(StartAkkaRpcActor startAkkaRpcActor) {
final String endpointId = startAkkaRpcActor.getEndpointId();
final AkkaRpcActorRegistration akkaRpcActorRegistration = new AkkaRpcActorRegistration(endpointId);
final Props akkaRpcActorProps = startAkkaRpcActor.getPropsFactory().create(akkaRpcActorRegistration.getInternalTerminationFuture());
LOG.debug("Starting {} with name {}.", akkaRpcActorProps.actorClass().getSimpleName(), endpointId);
try {
final ActorRef actorRef = getContext().actorOf(akkaRpcActorProps, endpointId);
registeredAkkaRpcActors.put(actorRef, akkaRpcActorRegistration);
getSender().tell(StartAkkaRpcActorResponse.success(ActorRegistration.create(actorRef, akkaRpcActorRegistration.getExternalTerminationFuture())), getSelf());
} catch (AkkaException akkaException) {
getSender().tell(StartAkkaRpcActorResponse.failure(akkaException), getSelf());
}
}
use of akka.AkkaException in project transporter by wang4ever.
the class ActorManager method actorTell.
/**
* 通知消息给其他对应actor
*
* @param message
* 当前通知消息对象
* @param actorName
* 目标actor(待通知的用户号码)
* @return 当前被通知的用户bean
*/
public ActorBean actorTell(String actorName, Object message) {
if (StringUtils.isEmpty(actorName))
throw new AkkaException("Failed to send actor '" + actorName + "', because it does not exist or destroyed.");
// 目前推送用户(actor)
ActorBean ab = null;
try {
// 1.1 get actor user.
ab = this.repository.getActorBean(actorName);
if (ab == null)
return null;
// 获取actor用户地址
ActorSelection acti = this._system.actorSelection(ab.getRemoteActorAddr());
acti.tell(message, acti.anchor());
if (logger.isDebugEnabled())
logger.debug("It has been sent to actor: '{}'", ab.getRemoteActorAddr());
} catch (Exception e) {
logger.error("Failed to send to actor '" + ab.getRemoteActorAddr() + "'.", e);
}
return ab;
}
use of akka.AkkaException 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;
}
Aggregations