Skip to content

Commit 4c99f31

Browse files
committed
🚧 process actor module
1 parent 5f201b3 commit 4c99f31

File tree

11 files changed

+206
-7
lines changed

11 files changed

+206
-7
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package iot.technology.actor;
2+
3+
/**
4+
* @author mushuwei
5+
*/
6+
public abstract class AbstractActor implements Actor {
7+
8+
protected ActorCtx ctx;
9+
10+
@Override
11+
public void init() throws ActorException {
12+
this.ctx = ctx;
13+
}
14+
15+
public ActorRef getActorRef() {
16+
return ctx;
17+
}
18+
}

IOT-Guide-Actor/src/main/java/iot/technology/actor/Actor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package iot.technology.actor;
22

3+
import iot.technology.actor.message.ActorMsg;
4+
35
/**
46
* @author mushuwei
57
*/

IOT-Guide-Actor/src/main/java/iot/technology/actor/ActorCtx.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package iot.technology.actor;
22

3+
import iot.technology.actor.message.ActorMsg;
4+
35
import java.util.List;
46
import java.util.function.Predicate;
57
import java.util.function.Supplier;
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package iot.technology.actor;
2+
3+
import iot.technology.actor.message.ActorMsg;
4+
import lombok.Data;
5+
import lombok.extern.slf4j.Slf4j;
6+
7+
import java.util.List;
8+
import java.util.concurrent.ConcurrentLinkedQueue;
9+
import java.util.concurrent.atomic.AtomicBoolean;
10+
import java.util.function.Predicate;
11+
import java.util.function.Supplier;
12+
13+
/**
14+
* @author mushuwei
15+
*/
16+
@Slf4j
17+
@Data
18+
public final class ActorMailbox implements ActorCtx {
19+
20+
public static final boolean FREE = false;
21+
public static final boolean BUSY = true;
22+
23+
public static final boolean NOT_READY = false;
24+
public static final boolean READY = true;
25+
26+
private final ConcurrentLinkedQueue<ActorMsg> highPriorityMsgs = new ConcurrentLinkedQueue<>();
27+
private final ConcurrentLinkedQueue<ActorMsg> normalPriorityMsgs = new ConcurrentLinkedQueue<>();
28+
private final AtomicBoolean busy = new AtomicBoolean(FREE);
29+
private final AtomicBoolean ready = new AtomicBoolean(NOT_READY);
30+
private final AtomicBoolean destroyInProgress = new AtomicBoolean();
31+
32+
private void enqueue(ActorMsg msg, boolean highPriority) {
33+
if (!destroyInProgress.get()) {
34+
if (highPriority) {
35+
36+
}
37+
}
38+
}
39+
40+
@Override
41+
public ActorId getSelf() {
42+
return null;
43+
}
44+
45+
@Override
46+
public ActorRef getParentRef() {
47+
return null;
48+
}
49+
50+
@Override
51+
public void tell(ActorId target, ActorMsg msg) {
52+
53+
}
54+
55+
@Override
56+
public void stop(ActorId target) {
57+
58+
}
59+
60+
@Override
61+
public ActorRef getOrCreateChildActor(ActorId actorId, Supplier<String> dispatcher, Supplier<ActorCreator> creator) {
62+
return null;
63+
}
64+
65+
@Override
66+
public void broadcastToChildren(ActorMsg msg) {
67+
68+
}
69+
70+
@Override
71+
public void broadcastToChildren(ActorMsg msg, Predicate<ActorId> childFilter) {
72+
73+
}
74+
75+
@Override
76+
public List<ActorId> filterChildren(Predicate<ActorId> childFilter) {
77+
return null;
78+
}
79+
80+
@Override
81+
public ActorId getActorId() {
82+
return null;
83+
}
84+
85+
@Override
86+
public void tell(ActorMsg actorMsg) {
87+
88+
}
89+
90+
@Override
91+
public void tellWithHighPriority(ActorMsg actorMsg) {
92+
93+
}
94+
}

IOT-Guide-Actor/src/main/java/iot/technology/actor/ActorMsg.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

IOT-Guide-Actor/src/main/java/iot/technology/actor/ActorRef.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package iot.technology.actor;
22

3+
import iot.technology.actor.message.ActorMsg;
4+
35
/**
46
* @author mushuwei
57
*/
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,42 @@
11
package iot.technology.actor;
22

3+
import iot.technology.actor.message.ActorMsg;
4+
5+
import java.util.List;
6+
import java.util.concurrent.ExecutorService;
7+
import java.util.concurrent.ScheduledExecutorService;
8+
import java.util.function.Predicate;
9+
310
/**
411
* @author mushuwei
512
*/
613
public interface ActorSystem {
14+
15+
ScheduledExecutorService getScheduler();
16+
17+
void createDispatcher(String dispatcherId, ExecutorService executor);
18+
19+
void destroyDispatcher(String dispatcherId);
20+
21+
ActorRef getActor(ActorId actorId);
22+
23+
ActorRef createRootActor(String dispatcherId, ActorCreator creator);
24+
25+
ActorRef createChildActor(String dispatcherId, ActorCreator creator, ActorId actorId);
26+
27+
void tell(ActorId target, ActorMsg actorMsg);
28+
29+
void tellWithHighPriority(ActorId target, ActorMsg actorMsg);
30+
31+
void stop(ActorRef actorRef);
32+
33+
void stop(ActorId actorId);
34+
35+
void stop();
36+
37+
void broadcastToChildren(ActorId parent, ActorMsg msg);
38+
39+
void broadcastToChildren(ActorId parent, Predicate<ActorId> childFilter, ActorMsg msg);
40+
41+
List<ActorId> filterChildren(ActorId parent, Predicate<ActorId> childFilter);
742
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package iot.technology.actor;
2+
3+
import lombok.Data;
4+
5+
/**
6+
* @author mushuwei
7+
*/
8+
@Data
9+
public class ActorSystemSettings {
10+
11+
private final int actorThroughput;
12+
private final int schedulerPoolSize;
13+
private final int maxActorInitAttempts;
14+
15+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package iot.technology.actor.message;
2+
3+
/**
4+
* @author mushuwei
5+
*/
6+
public interface ActorMsg {
7+
8+
MsgType getMsgType();
9+
10+
/**
11+
* Executed when the target actor is stopped or destroyed.
12+
* For Example, rule node failed to initialize or removed from rule chain
13+
* Implementation should cleanup the resources.
14+
*
15+
* @param reason
16+
*/
17+
default void onActorStopped(ActorStopReason reason) {
18+
}
19+
20+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package iot.technology.actor.message;
2+
3+
/**
4+
* @author mushuwei
5+
*/
6+
public enum ActorStopReason {
7+
8+
INIT_FAILED, STOPPED
9+
10+
}

0 commit comments

Comments
 (0)