use of actor4j.core.actors.Actor in project actor4j-core by relvaner.
the class ActorSystemImpl method addActor.
public UUID addActor(Class<? extends Actor> clazz, Object... args) throws ActorInitializationException {
ActorCell cell = generateCell(clazz);
container.registerConstructorInjector(cell.id, clazz, args);
Actor actor = null;
try {
actor = (Actor) container.getInstance(cell.id);
cell.actor = actor;
} catch (Exception e) {
e.printStackTrace();
executerService.safetyManager.notifyErrorHandler(new ActorInitializationException(), "initialization", null);
}
return (actor != null) ? user_addCell(cell) : UUID_ZERO;
}
use of actor4j.core.actors.Actor in project actor4j-core by relvaner.
the class ActorBalancingOnCreation method balance.
public void balance(Map<UUID, Long> cellsMap, List<ActorThread> actorThreads, Map<UUID, Long> groupsMap, Map<UUID, Integer> groupsDistributedMap, Map<UUID, ActorCell> cells) {
List<UUID> buffer = new LinkedList<>();
for (UUID id : cells.keySet()) buffer.add(id);
int i = 0, j = 0;
for (ActorCell cell : cells.values()) {
Actor actor = cell.getActor();
if (actor instanceof ActorGroupMember) {
Long id = groupsMap.get(((ActorGroupMember) actor).getGroupId());
if (id == null) {
id = actorThreads.get(i).getId();
groupsMap.put(((ActorGroupMember) actor).getGroupId(), id);
i++;
if (i == actorThreads.size())
i = 0;
}
if (buffer.remove(cell.getId()))
cellsMap.put(cell.getId(), id);
} else if (actor instanceof ActorDistributedGroupMember) {
Integer threadIndex = groupsDistributedMap.get(((ActorDistributedGroupMember) actor).getGroupId());
Long id = null;
if (threadIndex == null) {
id = actorThreads.get(j).getId();
groupsDistributedMap.put(((ActorDistributedGroupMember) actor).getGroupId(), j);
} else {
threadIndex++;
if (threadIndex == actorThreads.size())
threadIndex = 0;
id = actorThreads.get(threadIndex).getId();
groupsDistributedMap.put(((ActorDistributedGroupMember) actor).getGroupId(), threadIndex);
}
if (buffer.remove(cell.getId()))
cellsMap.put(cell.getId(), id);
j++;
if (j == actorThreads.size())
j = 0;
}
}
i = 0;
for (UUID id : buffer) {
cellsMap.put(id, actorThreads.get(i).getId());
i++;
if (i == actorThreads.size())
i = 0;
}
/*
int i=0;
for (UUID id : system.cells.keySet()) {
cellsMap.put(id, actorThreads.get(i).getId());
i++;
if (i==actorThreads.size())
i = 0;
}
*/
}
use of actor4j.core.actors.Actor in project actor4j-core by relvaner.
the class RestartProtocol method postRestart.
protected void postRestart(Exception reason) {
cell.postStop();
try {
Actor newActor = (Actor) cell.getSystem().getContainer().getInstance(cell.getId());
newActor.setCell(cell);
cell.setActor(newActor);
cell.postRestart(reason);
logger().info(String.format("%s - System: actor (%s) restarted", cell.getSystem().getName(), actorLabel(cell.getActor())));
} catch (Exception e) {
// never must occur
throw new ActorInitializationException();
}
}
use of actor4j.core.actors.Actor in project actor4j-core by relvaner.
the class ActorCell method addChild.
public UUID addChild(Class<? extends Actor> clazz, Object... args) throws ActorInitializationException {
ActorCell cell = system.generateCell(clazz);
system.container.registerConstructorInjector(cell.id, clazz, args);
try {
Actor child = (Actor) system.container.getInstance(cell.id);
cell.actor = child;
} catch (Exception e) {
throw new ActorInitializationException();
}
return internal_addChild(cell);
}
use of actor4j.core.actors.Actor in project actor4j-core by relvaner.
the class ActorSystemImpl method internal_addCell.
protected UUID internal_addCell(ActorCell cell) {
Actor actor = cell.actor;
if (actor instanceof PseudoActor)
pseudoCells.put(cell.id, cell);
else {
actor.setCell(cell);
cells.put(cell.id, cell);
if (actor instanceof ResourceActor)
resourceCells.put(cell.id, false);
if (executerService.isStarted()) {
messageDispatcher.registerCell(cell);
/* preStart */
cell.preStart();
}
}
return cell.id;
}
Aggregations