Guest User

Untitled

a guest
Oct 7th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.33 KB | None | 0 0
  1. import apgas.Configuration;
  2. import apgas.GlobalRuntime;
  3. import apgas.Place;
  4. import apgas.impl.Config;
  5.  
  6. import java.io.Serializable;
  7.  
  8. import static apgas.Constructs.*;
  9.  
  10. /**
  11.  * Created by jposner on 07.10.16.
  12.  */
  13. public class HandlerTest implements Serializable {
  14.  
  15.     public static void main(String[] args) {
  16.         System.setProperty(Configuration.APGAS_PLACES, "4");
  17.         System.setProperty(Configuration.APGAS_RESILIENT, "true");
  18.         System.setProperty(Config.APGAS_SERIALIZATION, "java");
  19.         System.setProperty(Configuration.APGAS_THREADS, "16");
  20.  
  21.         HandlerTest handlerTest = new HandlerTest();
  22.         handlerTest.go();
  23.     }
  24.  
  25.     private void go() {
  26.  
  27.         for (Place p : places()) {
  28.             at (p, () -> {
  29.                 GlobalRuntime.getRuntime().setPlaceFailureHandler(this::placeFailureHandler);
  30.                 System.out.println(here() + " started...");
  31.             });
  32.         }
  33.  
  34.  
  35.         finish(() -> {
  36.             for (Place p : places()) {
  37.                 try {
  38.                     asyncAt(p, () -> {
  39.                         int count = 0;
  40.                         while (true) {
  41.                             count++;
  42.                             System.out.println(here() + " works...");
  43.                             Thread.sleep(1000);
  44.                             if (here().id == 3 && count >= 5) {
  45.                                 System.out.println(here() + " shutdown!!!!");
  46.                                 System.exit(42);
  47.                             }
  48.                         }
  49.                     });
  50.                 } catch (Throwable throwable) {
  51.                     System.out.println(here() + " caught a Exception");
  52.                     throwable.printStackTrace();
  53.                 }
  54.             }
  55.         });
  56.     }
  57.  
  58.  
  59.     private void placeFailureHandler(Place deadPlace) {
  60.         System.out.println(here() + " detected deadPlace: " + deadPlace);
  61.         final Place h = here();
  62.         for (Place p : places()) {
  63.             try {
  64.                 at (p, () -> {
  65.                     System.out.println("From " + h + " to " + here() + " beeeep");
  66.                 });
  67.             } catch (Throwable throwable) {
  68.                 System.out.println(here() + " to p caught a Exception");
  69.                 throwable.printStackTrace();
  70.             }
  71.         }
  72.     }
  73.  
  74.  
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment