25 lines
749 B
Java
25 lines
749 B
Java
package org.syndicate_lang.actors.example.example2;
|
|
|
|
import java.util.List;
|
|
|
|
public class Forwarder implements IForwarder {
|
|
private final int _index;
|
|
private final List<IForwarder> _actors;
|
|
private final IForwarder _main;
|
|
private final int _nRounds;
|
|
|
|
public Forwarder(int index, List<IForwarder> actors, IForwarder main, int nRounds) {
|
|
this._index = index;
|
|
this._actors = actors;
|
|
this._main = main;
|
|
this._nRounds = nRounds;
|
|
}
|
|
|
|
@Override
|
|
public void handleMessage(int hopCount) {
|
|
int index = (this._index + 1) % this._actors.size();
|
|
IForwarder target = hopCount >= this._nRounds - 1 ? _main : this._actors.get(index);
|
|
target.handleMessage(hopCount + 1);
|
|
}
|
|
}
|