use of actor4j.core.utils.ActorGroupSet in project actor4j-core by relvaner.
the class StatelessActorFeature method test.
@Test(timeout = 10000)
public void test() {
ActorSystem system = new ActorSystem();
system.setParallelismFactor(2);
CountDownLatch testDone = new CountDownLatch(system.getParallelismMin() * system.getParallelismFactor());
ActorGroup group = new ActorGroupSet();
system.setAlias(system.addActor(() -> new StatelessActor(group) {
protected boolean first = true;
@Override
public void receive(ActorMessage<?> message) {
logger().debug(String.format("from thread %s of actor %s%n", Thread.currentThread().getName(), self()));
if (first) {
testDone.countDown();
first = false;
}
}
}, system.getParallelismMin() * system.getParallelismFactor()), "instances");
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
system.sendViaAlias(new ActorMessage<Object>(null, 0, system.SYSTEM_ID, null), "instances");
}
}, 0, 50);
system.start();
try {
testDone.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
timer.cancel();
system.shutdownWithActors(true);
}
use of actor4j.core.utils.ActorGroupSet in project actor4j-core by relvaner.
the class PrimaryActor method preStart.
@Override
public void preStart() {
List<UUID> ids = null;
if (secondary != null)
// creating secondary actors
ids = addChild(secondary.apply(self()), instances);
else
ids = new LinkedList<>();
ActorGroupSet secondaryGroup = new ActorGroupSet(ids);
hub = new HubPattern(this, secondaryGroup);
ids.add(self());
// registering alias
getSystem().setAlias(ids, alias);
}
Aggregations