use of akka.actor.ActorRef in project flink by apache.
the class ChaosMonkeyITCase method requestJobStatus.
private JobStatus requestJobStatus(JobID jobId, JobManagerProcess jobManager, ActorSystem actorSystem, FiniteDuration timeout) throws Exception {
ActorRef jobManagerRef = jobManager.getActorRef(actorSystem, timeout);
AkkaActorGateway jobManagerGateway = new AkkaActorGateway(jobManagerRef, null);
JobManagerMessages.JobStatusResponse resp = JobManagerActorTestUtils.requestJobStatus(jobId, jobManagerGateway, timeout);
if (resp instanceof JobManagerMessages.CurrentJobStatus) {
JobManagerMessages.CurrentJobStatus jobStatusResponse = (JobManagerMessages.CurrentJobStatus) resp;
return jobStatusResponse.status();
} else if (resp instanceof JobManagerMessages.JobNotFound) {
return JobStatus.RESTARTING;
}
throw new IllegalStateException("Unexpected response from JobManager");
}
use of akka.actor.ActorRef in project flink by apache.
the class TaskManagerFailureRecoveryITCase method testRestartWithFailingTaskManager.
@Test
public void testRestartWithFailingTaskManager() {
final int PARALLELISM = 4;
LocalFlinkMiniCluster cluster = null;
ActorSystem additionalSystem = null;
try {
Configuration config = new Configuration();
config.setInteger(ConfigConstants.LOCAL_NUMBER_TASK_MANAGER, 2);
config.setInteger(ConfigConstants.TASK_MANAGER_NUM_TASK_SLOTS, PARALLELISM);
config.setInteger(ConfigConstants.TASK_MANAGER_MEMORY_SIZE_KEY, 16);
config.setString(ConfigConstants.AKKA_WATCH_HEARTBEAT_INTERVAL, "500 ms");
config.setString(ConfigConstants.AKKA_WATCH_HEARTBEAT_PAUSE, "20 s");
config.setInteger(ConfigConstants.AKKA_WATCH_THRESHOLD, 20);
cluster = new LocalFlinkMiniCluster(config, false);
cluster.start();
// for the result
List<Long> resultCollection = new ArrayList<Long>();
final ExecutionEnvironment env = ExecutionEnvironment.createRemoteEnvironment("localhost", cluster.getLeaderRPCPort());
env.setParallelism(PARALLELISM);
env.setRestartStrategy(RestartStrategies.fixedDelayRestart(1, 1000));
env.getConfig().disableSysoutLogging();
env.generateSequence(1, 10).map(new FailingMapper<Long>()).reduce(new ReduceFunction<Long>() {
@Override
public Long reduce(Long value1, Long value2) {
return value1 + value2;
}
}).output(new LocalCollectionOutputFormat<Long>(resultCollection));
// simple reference (atomic does not matter) to pass back an exception from the trigger thread
final AtomicReference<Throwable> ref = new AtomicReference<Throwable>();
// trigger the execution from a separate thread, so we are available to temper with the
// cluster during the execution
Thread trigger = new Thread("program trigger") {
@Override
public void run() {
try {
env.execute();
} catch (Throwable t) {
ref.set(t);
}
}
};
trigger.setDaemon(true);
trigger.start();
// the mappers in turn are waiting
for (int i = 0; i < PARALLELISM; i++) {
FailingMapper.TASK_TO_COORD_QUEUE.take();
}
// bring up one more task manager and wait for it to appear
{
additionalSystem = cluster.startTaskManagerActorSystem(2);
ActorRef additionalTaskManager = cluster.startTaskManager(2, additionalSystem);
Object message = TaskManagerMessages.getNotifyWhenRegisteredAtJobManagerMessage();
Future<Object> future = Patterns.ask(additionalTaskManager, message, 30000);
try {
Await.result(future, new FiniteDuration(30000, TimeUnit.MILLISECONDS));
} catch (TimeoutException e) {
fail("The additional TaskManager did not come up within 30 seconds");
}
}
// kill the two other TaskManagers
for (ActorRef tm : cluster.getTaskManagersAsJava()) {
tm.tell(PoisonPill.getInstance(), null);
}
// wait for the next set of mappers (the recovery ones) to come online
for (int i = 0; i < PARALLELISM; i++) {
FailingMapper.TASK_TO_COORD_QUEUE.take();
}
// tell the mappers that they may continue this time
for (int i = 0; i < PARALLELISM; i++) {
FailingMapper.COORD_TO_TASK_QUEUE.add(new Object());
}
// wait for the program to finish
trigger.join();
if (ref.get() != null) {
Throwable t = ref.get();
t.printStackTrace();
fail("Program execution caused an exception: " + t.getMessage());
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
} finally {
if (additionalSystem != null) {
additionalSystem.shutdown();
}
if (cluster != null) {
cluster.stop();
}
}
}
use of akka.actor.ActorRef in project chuidiang-ejemplos by chuidiang.
the class HelloActorMain method main.
public static void main(String[] args) {
// an actor needs an ActorSystem
ActorSystem system = ActorSystem.create("HelloWorldSystem");
// create and start the actor
Props actor = Props.create(HelloActor.class);
ActorRef helloActor = system.actorOf(actor, "HelloActor");
// send the actor two messages
helloActor.tell("hello 1", helloActor);
helloActor.tell("hello 2", helloActor);
helloActor.tell("hello 3", helloActor);
// shut down the system
system.terminate();
}
use of akka.actor.ActorRef in project chuidiang-ejemplos by chuidiang.
the class Server2Main method main.
public static void main(String[] args) throws InterruptedException {
// Override the configuration of the port
// when specified as program argument
System.setProperty("akka.remote.netty.tcp.port", "5558");
// Create an Akka system
ActorSystem system = ActorSystem.create("ClusterSystem", ConfigFactory.defaultApplication());
// Create an actor that handles cluster domain events
ActorRef publisher = system.actorOf(Props.create(Publisher.class), "publisher");
while (true) {
publisher.tell("Hello", publisher);
Thread.sleep(1000);
}
}
Aggregations