Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
When a destination is added, immediately ping it, so first result is …
Browse files Browse the repository at this point in the history
…in quicker.
  • Loading branch information
pilhuhn committed Feb 25, 2015
1 parent fcff8e0 commit f25e1d2
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public void scheduleWork() {
return;
}

doThePing(destinations);
}

/**
* Runs the pinging work on the provided list of destinations
* @param destinations Set of destinations to ping
*/
private void doThePing(Set<PingDestination> destinations) {
List<PingStatus> results = new ArrayList<>(destinations.size());
List<Future<PingStatus>> futures = new ArrayList<>(destinations.size());

Expand All @@ -109,7 +117,6 @@ public void scheduleWork() {
}



int round = 1;
while (!futures.isEmpty() && round < 20) {
Iterator<Future<PingStatus>> iterator = futures.iterator();
Expand Down Expand Up @@ -198,8 +205,16 @@ private void addDataItem(List<Map<String, Object>> mMetrics, PingStatus status,
mMetrics.add(outer);
}

public void addDestination(PingDestination s) {
destinations.add(s);
/**
* Add a new destination into the system. This triggers an immediate
* ping and then adding to the list of destinations.
* @param pd new Destination
*/
public void addDestination(PingDestination pd) {
Set<PingDestination> oneTimeDestinations = new HashSet<>(1);
oneTimeDestinations.add(pd);
doThePing(oneTimeDestinations);
destinations.add(pd);
}

public List<PingDestination> getDestinations() {
Expand Down

0 comments on commit f25e1d2

Please sign in to comment.