feat: define insideCluster in HandlerLocation

This commit is contained in:
tjq 2023-01-17 21:37:41 +08:00
parent 59121684a8
commit d6f3ae6c44
2 changed files with 13 additions and 9 deletions

View File

@ -15,6 +15,7 @@ import java.io.Serializable;
*/
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class HandlerLocation implements Serializable {
/**
@ -25,13 +26,12 @@ public class HandlerLocation implements Serializable {
* 方法路径
*/
private String methodPath;
/**
* 是否在本集群内用于兼容 AKKA 等除了IP还需要指定 system 访问的情况
*/
private boolean insideCluster;
public String toPath() {
return String.format("/%s/%s", rootPath, methodPath);
}
@Override
public String toString() {
return toPath();
}
}

View File

@ -8,6 +8,7 @@ import tech.powerjob.common.PowerSerializable;
import tech.powerjob.common.RemoteConstant;
import tech.powerjob.common.request.ServerScheduleJobReq;
import tech.powerjob.common.utils.CommonUtils;
import tech.powerjob.remote.framework.base.HandlerLocation;
import tech.powerjob.remote.framework.base.RemotingException;
import tech.powerjob.remote.framework.base.ServerType;
import tech.powerjob.remote.framework.base.URL;
@ -27,9 +28,9 @@ import java.util.concurrent.ExecutorService;
*/
public class AkkaTransporter implements Transporter {
private final ServerType serverType;
private final ActorSystem actorSystem;
private final String targetActorSystemName;
/**
* akka://<actor system>@<hostname>:<port>/<actor path>
@ -38,7 +39,7 @@ public class AkkaTransporter implements Transporter {
public AkkaTransporter(ServerType serverType, ActorSystem actorSystem) {
this.actorSystem = actorSystem;
this.targetActorSystemName = AkkaConstant.fetchActorSystemName(serverType, false);
this.serverType = serverType;
}
@Override
@ -61,9 +62,12 @@ public class AkkaTransporter implements Transporter {
private ActorSelection fetchActorSelection(URL url) {
String targetActorName = AkkaMappingService.parseActorName(url.getLocation().getRootPath()).getActorName();
HandlerLocation location = url.getLocation();
String targetActorSystemName = AkkaConstant.fetchActorSystemName(serverType, location.isInsideCluster());
CommonUtils.requireNonNull(targetActorName, "can't find actor by URL: " + url.getLocation());
String targetActorName = AkkaMappingService.parseActorName(location.getRootPath()).getActorName();
CommonUtils.requireNonNull(targetActorName, "can't find actor by URL: " + location);
String address = url.getAddress().toFullAddress();