Improvements to Tenant Actor initialization
This commit is contained in:
parent
9be5c367ce
commit
25db0b73fd
@ -78,11 +78,13 @@ public class AppActor extends ContextAwareActor {
|
|||||||
ruleManager.init(this.context());
|
ruleManager.init(this.context());
|
||||||
pluginManager.init(this.context());
|
pluginManager.init(this.context());
|
||||||
|
|
||||||
PageDataIterable<Tenant> tenantIterator = new PageDataIterable<>(link -> tenantService.findTenants(link), ENTITY_PACK_LIMIT);
|
if (systemContext.isTenantComponentsInitEnabled()) {
|
||||||
for (Tenant tenant : tenantIterator) {
|
PageDataIterable<Tenant> tenantIterator = new PageDataIterable<>(tenantService::findTenants, ENTITY_PACK_LIMIT);
|
||||||
logger.debug("[{}] Creating tenant actor", tenant.getId());
|
for (Tenant tenant : tenantIterator) {
|
||||||
getOrCreateTenantActor(tenant.getId());
|
logger.debug("[{}] Creating tenant actor", tenant.getId());
|
||||||
logger.debug("Tenant actor created.");
|
getOrCreateTenantActor(tenant.getId());
|
||||||
|
logger.debug("Tenant actor created.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Main system actor started.");
|
logger.info("Main system actor started.");
|
||||||
@ -181,13 +183,8 @@ public class AppActor extends ContextAwareActor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ActorRef getOrCreateTenantActor(TenantId tenantId) {
|
private ActorRef getOrCreateTenantActor(TenantId tenantId) {
|
||||||
ActorRef tenantActor = tenantActors.get(tenantId);
|
return tenantActors.computeIfAbsent(tenantId, k -> context().actorOf(Props.create(new TenantActor.ActorCreator(systemContext, tenantId))
|
||||||
if (tenantActor == null) {
|
.withDispatcher(DefaultActorService.CORE_DISPATCHER_NAME), tenantId.toString()));
|
||||||
tenantActor = context().actorOf(Props.create(new TenantActor.ActorCreator(systemContext, tenantId))
|
|
||||||
.withDispatcher(DefaultActorService.CORE_DISPATCHER_NAME), tenantId.toString());
|
|
||||||
tenantActors.put(tenantId, tenantActor);
|
|
||||||
}
|
|
||||||
return tenantActor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processTermination(Terminated message) {
|
private void processTermination(Terminated message) {
|
||||||
|
|||||||
@ -44,7 +44,7 @@ public abstract class RuleManager {
|
|||||||
protected final Map<RuleId, ActorRef> ruleActors;
|
protected final Map<RuleId, ActorRef> ruleActors;
|
||||||
protected final TenantId tenantId;
|
protected final TenantId tenantId;
|
||||||
|
|
||||||
Map<RuleMetaData, RuleActorMetaData> ruleMap = new HashMap<>();
|
private Map<RuleMetaData, RuleActorMetaData> ruleMap;
|
||||||
private RuleActorChain ruleChain;
|
private RuleActorChain ruleChain;
|
||||||
|
|
||||||
public RuleManager(ActorSystemContext systemContext, TenantId tenantId) {
|
public RuleManager(ActorSystemContext systemContext, TenantId tenantId) {
|
||||||
@ -55,6 +55,10 @@ public abstract class RuleManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void init(ActorContext context) {
|
public void init(ActorContext context) {
|
||||||
|
doInit(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doInit(ActorContext context) {
|
||||||
PageDataIterable<RuleMetaData> ruleIterator = new PageDataIterable<>(getFetchRulesFunction(),
|
PageDataIterable<RuleMetaData> ruleIterator = new PageDataIterable<>(getFetchRulesFunction(),
|
||||||
ContextAwareActor.ENTITY_PACK_LIMIT);
|
ContextAwareActor.ENTITY_PACK_LIMIT);
|
||||||
ruleMap = new HashMap<>();
|
ruleMap = new HashMap<>();
|
||||||
@ -62,8 +66,7 @@ public abstract class RuleManager {
|
|||||||
for (RuleMetaData rule : ruleIterator) {
|
for (RuleMetaData rule : ruleIterator) {
|
||||||
log.debug("[{}] Creating rule actor {}", rule.getId(), rule);
|
log.debug("[{}] Creating rule actor {}", rule.getId(), rule);
|
||||||
ActorRef ref = getOrCreateRuleActor(context, rule.getId());
|
ActorRef ref = getOrCreateRuleActor(context, rule.getId());
|
||||||
RuleActorMetaData actorMd = RuleActorMetaData.systemRule(rule.getId(), rule.getWeight(), ref);
|
ruleMap.put(rule, RuleActorMetaData.systemRule(rule.getId(), rule.getWeight(), ref));
|
||||||
ruleMap.put(rule, actorMd);
|
|
||||||
log.debug("[{}] Rule actor created.", rule.getId());
|
log.debug("[{}] Rule actor created.", rule.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +75,7 @@ public abstract class RuleManager {
|
|||||||
|
|
||||||
public Optional<ActorRef> update(ActorContext context, RuleId ruleId, ComponentLifecycleEvent event) {
|
public Optional<ActorRef> update(ActorContext context, RuleId ruleId, ComponentLifecycleEvent event) {
|
||||||
if (ruleMap == null) {
|
if (ruleMap == null) {
|
||||||
init(context);
|
doInit(context);
|
||||||
}
|
}
|
||||||
RuleMetaData rule;
|
RuleMetaData rule;
|
||||||
if (event != ComponentLifecycleEvent.DELETED) {
|
if (event != ComponentLifecycleEvent.DELETED) {
|
||||||
@ -114,8 +117,8 @@ public abstract class RuleManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RuleActorChain getRuleChain(ActorContext context) {
|
public RuleActorChain getRuleChain(ActorContext context) {
|
||||||
if (ruleMap == null) {
|
if (ruleChain == null) {
|
||||||
init(context);
|
doInit(context);
|
||||||
}
|
}
|
||||||
return ruleChain;
|
return ruleChain;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,7 @@ public class TenantRuleManager extends RuleManager {
|
|||||||
super(systemContext, tenantId);
|
super(systemContext, tenantId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void init(ActorContext context) {
|
public void init(ActorContext context) {
|
||||||
if (systemContext.isTenantComponentsInitEnabled()) {
|
if (systemContext.isTenantComponentsInitEnabled()) {
|
||||||
super.init(context);
|
super.init(context);
|
||||||
|
|||||||
@ -151,7 +151,8 @@ public class TenantActor extends ContextAwareActor {
|
|||||||
private void process(RuleChainDeviceMsg msg) {
|
private void process(RuleChainDeviceMsg msg) {
|
||||||
ToDeviceActorMsg toDeviceActorMsg = msg.getToDeviceActorMsg();
|
ToDeviceActorMsg toDeviceActorMsg = msg.getToDeviceActorMsg();
|
||||||
ActorRef deviceActor = getOrCreateDeviceActor(toDeviceActorMsg.getDeviceId());
|
ActorRef deviceActor = getOrCreateDeviceActor(toDeviceActorMsg.getDeviceId());
|
||||||
RuleActorChain chain = new ComplexRuleActorChain(msg.getRuleChain(), ruleManager.getRuleChain(this.context()));
|
RuleActorChain tenantChain = ruleManager.getRuleChain(this.context());
|
||||||
|
RuleActorChain chain = new ComplexRuleActorChain(msg.getRuleChain(), tenantChain);
|
||||||
deviceActor.tell(new RuleChainDeviceMsg(toDeviceActorMsg, chain), context().self());
|
deviceActor.tell(new RuleChainDeviceMsg(toDeviceActorMsg, chain), context().self());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user