Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions apgas/src/apgas/Constructs.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,44 @@ public static Place place(int id) {
public static List<? extends Place> 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);
}
}
55 changes: 55 additions & 0 deletions apgas/src/apgas/impl/GlobalRuntimeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends Place> 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<? extends Place> 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;
}
}