Commit 0b13fa2f0e74e5de26afe9fb0fc1874660fd4342
1 parent
d8ac3883
Hotfix for actor restarts during creation failure
Showing
3 changed files
with
25 additions
and
3 deletions
... | ... | @@ -114,7 +114,7 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso |
114 | 114 | private String deviceType; |
115 | 115 | private TbMsgMetaData defaultMetaData; |
116 | 116 | |
117 | - public DeviceActorMessageProcessor(ActorSystemContext systemContext, LoggingAdapter logger, TenantId tenantId, DeviceId deviceId) { | |
117 | + DeviceActorMessageProcessor(ActorSystemContext systemContext, LoggingAdapter logger, TenantId tenantId, DeviceId deviceId) { | |
118 | 118 | super(systemContext, logger); |
119 | 119 | this.tenantId = tenantId; |
120 | 120 | this.deviceId = deviceId; | ... | ... |
... | ... | @@ -15,13 +15,17 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.actors.session; |
17 | 17 | |
18 | +import akka.actor.ActorInitializationException; | |
18 | 19 | import akka.actor.ActorRef; |
19 | 20 | import akka.actor.InvalidActorNameException; |
20 | 21 | import akka.actor.LocalActorRef; |
22 | +import akka.actor.OneForOneStrategy; | |
21 | 23 | import akka.actor.Props; |
24 | +import akka.actor.SupervisorStrategy; | |
22 | 25 | import akka.actor.Terminated; |
23 | 26 | import akka.event.Logging; |
24 | 27 | import akka.event.LoggingAdapter; |
28 | +import akka.japi.Function; | |
25 | 29 | import org.thingsboard.server.actors.ActorSystemContext; |
26 | 30 | import org.thingsboard.server.actors.service.ContextAwareActor; |
27 | 31 | import org.thingsboard.server.actors.service.ContextBasedCreator; |
... | ... | @@ -34,6 +38,7 @@ import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
34 | 38 | import org.thingsboard.server.common.msg.core.ActorSystemToDeviceSessionActorMsg; |
35 | 39 | import org.thingsboard.server.common.msg.core.SessionCloseMsg; |
36 | 40 | import org.thingsboard.server.common.msg.session.SessionCtrlMsg; |
41 | +import scala.concurrent.duration.Duration; | |
37 | 42 | |
38 | 43 | import java.util.HashMap; |
39 | 44 | import java.util.Map; |
... | ... | @@ -46,12 +51,17 @@ public class SessionManagerActor extends ContextAwareActor { |
46 | 51 | |
47 | 52 | private final Map<String, ActorRef> sessionActors; |
48 | 53 | |
49 | - public SessionManagerActor(ActorSystemContext systemContext) { | |
54 | + SessionManagerActor(ActorSystemContext systemContext) { | |
50 | 55 | super(systemContext); |
51 | 56 | this.sessionActors = new HashMap<>(INITIAL_SESSION_MAP_SIZE); |
52 | 57 | } |
53 | 58 | |
54 | 59 | @Override |
60 | + public SupervisorStrategy supervisorStrategy() { | |
61 | + return strategy; | |
62 | + } | |
63 | + | |
64 | + @Override | |
55 | 65 | protected boolean process(TbActorMsg msg) { |
56 | 66 | //TODO Move everything here, to work with TbActorMsg |
57 | 67 | return false; |
... | ... | @@ -160,4 +170,11 @@ public class SessionManagerActor extends ContextAwareActor { |
160 | 170 | } |
161 | 171 | } |
162 | 172 | |
173 | + private final SupervisorStrategy strategy = new OneForOneStrategy(3, Duration.create("1 minute"), new Function<Throwable, SupervisorStrategy.Directive>() { | |
174 | + @Override | |
175 | + public SupervisorStrategy.Directive apply(Throwable t) { | |
176 | + logger.error(t, "Unknown failure"); | |
177 | + return SupervisorStrategy.stop(); | |
178 | + } | |
179 | + }); | |
163 | 180 | } | ... | ... |
... | ... | @@ -15,6 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.actors.tenant; |
17 | 17 | |
18 | +import akka.actor.ActorInitializationException; | |
18 | 19 | import akka.actor.ActorRef; |
19 | 20 | import akka.actor.OneForOneStrategy; |
20 | 21 | import akka.actor.Props; |
... | ... | @@ -170,7 +171,11 @@ public class TenantActor extends RuleChainManagerActor { |
170 | 171 | @Override |
171 | 172 | public SupervisorStrategy.Directive apply(Throwable t) { |
172 | 173 | logger.error(t, "Unknown failure"); |
173 | - return SupervisorStrategy.resume(); | |
174 | + if(t instanceof ActorInitializationException){ | |
175 | + return SupervisorStrategy.stop(); | |
176 | + } else { | |
177 | + return SupervisorStrategy.resume(); | |
178 | + } | |
174 | 179 | } |
175 | 180 | }); |
176 | 181 | ... | ... |