27 lines
656 B
Java
27 lines
656 B
Java
package org.syndicate_lang.actors.example.example2;
|
|
|
|
import java.util.List;
|
|
// import java.util.Random;
|
|
|
|
public class Forwarder implements IForwarder {
|
|
private final IForwarder _main;
|
|
private final int _nRounds;
|
|
private IForwarder _peer = null;
|
|
|
|
public Forwarder(IForwarder main, int nRounds) {
|
|
this._main = main;
|
|
this._nRounds = nRounds;
|
|
}
|
|
|
|
@Override
|
|
public void setPeer(IForwarder peer) {
|
|
this._peer = peer;
|
|
}
|
|
|
|
@Override
|
|
public void handleMessage(int hopCount) {
|
|
IForwarder target = hopCount >= this._nRounds - 1 ? _main : _peer;
|
|
target.handleMessage(hopCount + 1);
|
|
}
|
|
}
|