Search in sources :

Example 1 with ActorGroup

use of actor4j.core.utils.ActorGroup in project actor4j-core by relvaner.

the class ActorBalancingOnCreationManual method balanceGroups.

public void balanceGroups(Map<UUID, Long> cellsMap, List<ActorThread> actorThreads, Map<UUID, Long> groupsMap, List<ActorGroup> groups) {
    int i = 0;
    for (ActorGroup group : groups) {
        balanceGroup(cellsMap, groupsMap, actorThreads.get(i).getId(), group);
        i++;
        if (i == actorThreads.size())
            i = 0;
    }
}
Also used : ActorGroup(actor4j.core.utils.ActorGroup)

Example 2 with ActorGroup

use of actor4j.core.utils.ActorGroup 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);
}
Also used : ActorSystem(actor4j.core.ActorSystem) Timer(java.util.Timer) TimerTask(java.util.TimerTask) ActorGroup(actor4j.core.utils.ActorGroup) StatelessActor(actor4j.core.actors.StatelessActor) ActorGroupSet(actor4j.core.utils.ActorGroupSet) ActorMessage(actor4j.core.messages.ActorMessage) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

ActorGroup (actor4j.core.utils.ActorGroup)2 ActorSystem (actor4j.core.ActorSystem)1 StatelessActor (actor4j.core.actors.StatelessActor)1 ActorMessage (actor4j.core.messages.ActorMessage)1 ActorGroupSet (actor4j.core.utils.ActorGroupSet)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1