Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import apgas.Configuration;
- import apgas.GlobalRuntime;
- import apgas.Place;
- import apgas.impl.Config;
- import java.io.Serializable;
- import static apgas.Constructs.*;
- /**
- * Created by jposner on 07.10.16.
- */
- public class HandlerTest implements Serializable {
- public static void main(String[] args) {
- System.setProperty(Configuration.APGAS_PLACES, "4");
- System.setProperty(Configuration.APGAS_RESILIENT, "true");
- System.setProperty(Config.APGAS_SERIALIZATION, "java");
- System.setProperty(Configuration.APGAS_THREADS, "16");
- HandlerTest handlerTest = new HandlerTest();
- handlerTest.go();
- }
- private void go() {
- for (Place p : places()) {
- at (p, () -> {
- GlobalRuntime.getRuntime().setPlaceFailureHandler(this::placeFailureHandler);
- System.out.println(here() + " started...");
- });
- }
- finish(() -> {
- for (Place p : places()) {
- try {
- asyncAt(p, () -> {
- int count = 0;
- while (true) {
- count++;
- System.out.println(here() + " works...");
- Thread.sleep(1000);
- if (here().id == 3 && count >= 5) {
- System.out.println(here() + " shutdown!!!!");
- System.exit(42);
- }
- }
- });
- } catch (Throwable throwable) {
- System.out.println(here() + " caught a Exception");
- throwable.printStackTrace();
- }
- }
- });
- }
- private void placeFailureHandler(Place deadPlace) {
- System.out.println(here() + " detected deadPlace: " + deadPlace);
- final Place h = here();
- for (Place p : places()) {
- try {
- at (p, () -> {
- System.out.println("From " + h + " to " + here() + " beeeep");
- });
- } catch (Throwable throwable) {
- System.out.println(here() + " to p caught a Exception");
- throwable.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment