diff --git a/apgas/src/apgas/Constructs.java b/apgas/src/apgas/Constructs.java index e4f66ab..b8335bd 100644 --- a/apgas/src/apgas/Constructs.java +++ b/apgas/src/apgas/Constructs.java @@ -160,4 +160,44 @@ public static Place place(int id) { public static List places() { return GlobalRuntime.getRuntimeImpl().places(); } + + /** + * Returns the aliveness status of the passed place + * + * @param p + * the place to check + * + * @return the aliveness status of the passed places + */ + public static boolean isDead(Place p) { + return GlobalRuntime.getRuntimeImpl().isDead(p); + } + + /** + * Returns the closest {@link Place} alive in the ring of places that comes + * behind the passed place. + * + * @param p + * the base place + * + * @return the closest {@link Place} alive in the ring of places that comes + * behind the passed place. + */ + public static Place nextPlace(Place p) { + return GlobalRuntime.getRuntimeImpl().nextPlace(p); + } + + /** + * Returns the closest {@link Place} alive in the ring of places that comes + * before the passed place. + * + * @param p + * the base place + * + * @return the closest {@link Place} alive in the ring of places that comes + * before the passed place. + */ + public static Place prevPlace(Place p) { + return GlobalRuntime.getRuntimeImpl().prevPlace(p); + } } diff --git a/apgas/src/apgas/impl/GlobalRuntimeImpl.java b/apgas/src/apgas/impl/GlobalRuntimeImpl.java index 121a8b2..614460c 100644 --- a/apgas/src/apgas/impl/GlobalRuntimeImpl.java +++ b/apgas/src/apgas/impl/GlobalRuntimeImpl.java @@ -683,4 +683,59 @@ void execute(ForkJoinTask task) { public Long lastfailureTime() { return failureTime; } + + /** + * Returns the aliveness status of the passed place + * + * @param p + * the place to check + * + * @return the aliveness status of the passed places + */ + public boolean isDead(Place p) { + return !this.places.contains(p); + } + + /** + * Returns the closest {@link Place} alive in the ring of places that comes + * behind the passed place. + * + * @param p + * the base place + * + * @return the closest {@link Place} alive in the ring of places that comes + * behind the passed place. + */ + public Place nextPlace(Place p) { + final List tmpPlaces = new ArrayList<>(places()); + for (final Place tmp : tmpPlaces) { + if (tmp.id > p.id) { + return tmp; + } + } + return tmpPlaces.get(0); + } + + /** + * Returns the closest {@link Place} alive in the ring of places that comes + * before the passed place. + * + * @param p + * the base place + * + * @return the closest {@link Place} alive in the ring of places that comes + * before the passed place. + */ + public Place prevPlace(Place p) { + final List tmpPlaces = new ArrayList<>(places()); + Place prev = tmpPlaces.get(tmpPlaces.size() - 1); + for (final Place tmp : tmpPlaces) { + if (tmp.id < p.id) { + prev = tmp; + } else { + return prev; + } + } + return prev; + } }