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

Commit

Permalink
Merge pull request #27 from hawkular/pinger-update2
Browse files Browse the repository at this point in the history
When a destination is added, immediately ping it, so first result is in quicker
  • Loading branch information
jmazzitelli committed Feb 25, 2015
2 parents 50515ce + 02dcc07 commit aeb61b2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import org.hawkular.component.pinger.PingManager;
import org.hawkular.component.pinger.PingStatus;
import org.hawkular.component.pinger.Pinger;
import org.hawkular.metrics.client.common.SingleMetric;
import org.junit.Test;

import java.util.List;
import java.util.Map;

/**
* Simple test for the pinger
Expand All @@ -49,6 +51,7 @@ public void testPingManagerSimple() throws Exception {

PingManager manager = new PingManager();
manager.pinger = new Pinger();
manager.metricPublisher = new NoOpMetricPublisher();
PingDestination destination = new PingDestination("123","http://hawkular.github.io");
manager.addDestination(destination);
manager.metricPublisher = new MetricPublisher();
Expand All @@ -65,14 +68,31 @@ public void testPingManagerSimple() throws Exception {
* running inventory instance
* @throws Exception
*/
// @Test
@Test
public void testPingManagerStartup() throws Exception {

PingManager manager = new PingManager();
manager.startUp();
try {
manager.startUp();
} catch (javax.ws.rs.ProcessingException e) {
// It's ok, as we may not have the full Jax-RS client stack available
}
List<PingDestination> destinations = manager.getDestinations();
manager.pinger = new Pinger();
manager.scheduleWork();

}


private class NoOpMetricPublisher extends MetricPublisher {
@Override
public void sendToMetricsViaRest(String tenantId, List<Map<String, Object>> metrics) {

}

@Override
public void publishToTopic(String tenantId, List<SingleMetric> metrics) {

}
}
}

0 comments on commit aeb61b2

Please sign in to comment.