forked from IoT-Technology/IoT-Technical-Guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
581b440
commit 3d5cf49
Showing
11 changed files
with
299 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
IOT-Guide-Actor/src/main/java/iot/technology/actor/AbstractActor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
IOT-Guide-Actor/src/main/java/iot/technology/actor/ActorThreadFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package iot.technology.actor; | ||
|
||
import java.util.concurrent.ThreadFactory; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
/** | ||
* Copy of Executors.DefaultThreadFactory but with ability to set name of the pool | ||
* | ||
* @author mushuwei | ||
*/ | ||
public class ActorThreadFactory implements ThreadFactory { | ||
public static final AtomicInteger poolNumber = new AtomicInteger(1); | ||
private final ThreadGroup group; | ||
private static final AtomicInteger threadNumber = new AtomicInteger(1); | ||
private final String namePrefix; | ||
|
||
public static ActorThreadFactory forName(String name) { | ||
return new ActorThreadFactory(name); | ||
} | ||
|
||
public ActorThreadFactory(String name) { | ||
SecurityManager s = System.getSecurityManager(); | ||
group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup(); | ||
namePrefix = name + "-" + poolNumber.getAndIncrement() + "-thread-"; | ||
} | ||
|
||
@Override | ||
public Thread newThread(Runnable r) { | ||
Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0); | ||
if (t.isDaemon()) { | ||
t.setDaemon(false); | ||
} | ||
if (t.getPriority() != Thread.NORM_PRIORITY) { | ||
t.setPriority(Thread.NORM_PRIORITY); | ||
} | ||
return t; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
IOT-Guide-Actor/src/main/java/iot/technology/actor/DefaultActorSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package iot.technology.actor; | ||
|
||
import iot.technology.actor.message.ActorMsg; | ||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.*; | ||
import java.util.function.Predicate; | ||
|
||
/** | ||
* @author mushuwei | ||
*/ | ||
public class DefaultActorSystem implements ActorSystem { | ||
|
||
private final ConcurrentMap<String, Dispatcher> dispatchers = new ConcurrentHashMap<>(); | ||
|
||
@Getter | ||
private final ActorSystemSettings settings; | ||
@Getter | ||
private final ScheduledExecutorService scheduler; | ||
|
||
public DefaultActorSystem(ActorSystemSettings settings) { | ||
this.settings = settings; | ||
this.scheduler = | ||
Executors.newScheduledThreadPool(settings.getSchedulerPoolSize(), ActorThreadFactory.forName("actor-system-scheduler")); | ||
} | ||
|
||
|
||
@Override | ||
public void createDispatcher(String dispatcherId, ExecutorService executor) { | ||
|
||
} | ||
|
||
@Override | ||
public void destroyDispatcher(String dispatcherId) { | ||
|
||
} | ||
|
||
@Override | ||
public ActorRef getActor(ActorId actorId) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public ActorRef createRootActor(String dispatcherId, ActorCreator creator) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public ActorRef createChildActor(String dispatcherId, ActorCreator creator, ActorId actorId) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void tell(ActorId target, ActorMsg actorMsg) { | ||
|
||
} | ||
|
||
@Override | ||
public void tellWithHighPriority(ActorId target, ActorMsg actorMsg) { | ||
|
||
} | ||
|
||
@Override | ||
public void stop(ActorRef actorRef) { | ||
|
||
} | ||
|
||
@Override | ||
public void stop(ActorId actorId) { | ||
|
||
} | ||
|
||
@Override | ||
public void stop() { | ||
|
||
} | ||
|
||
@Override | ||
public void broadcastToChildren(ActorId parent, ActorMsg msg) { | ||
|
||
} | ||
|
||
@Override | ||
public void broadcastToChildren(ActorId parent, Predicate<ActorId> childFilter, ActorMsg msg) { | ||
|
||
} | ||
|
||
@Override | ||
public List<ActorId> filterChildren(ActorId parent, Predicate<ActorId> childFilter) { | ||
return null; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
IOT-Guide-Actor/src/main/java/iot/technology/actor/Dispatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package iot.technology.actor; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
|
||
/** | ||
* @author mushuwei | ||
*/ | ||
@Data | ||
public class Dispatcher { | ||
|
||
private final String dispatcherId; | ||
private final ExecutorService executor; | ||
} |
2 changes: 1 addition & 1 deletion
2
.../iot/technology/actor/ActorException.java → ...ology/actor/exception/ActorException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package iot.technology.actor; | ||
package iot.technology.actor.exception; | ||
|
||
/** | ||
* @author mushuwei | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,8 @@ | |
* @author mushuwei | ||
*/ | ||
public enum MsgType { | ||
|
||
/** | ||
* Special message to indicate update request | ||
*/ | ||
UPDATED_MSG, | ||
} |
15 changes: 15 additions & 0 deletions
15
IOT-Guide-Actor/src/test/java/iot/technology/actor/ActorSystemTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package iot.technology.actor; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
/** | ||
* @author mushuwei | ||
*/ | ||
@Slf4j | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class ActorSystemTest { | ||
|
||
private volatile ActorSystem actorSystem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters