use of org.apache.sling.hc.util.HealthCheckMetadata in project sling by apache.
the class HealthCheckExecutorImpl method getHealthCheckMetadata.
/**
* Create the health check meta data
*/
private List<HealthCheckMetadata> getHealthCheckMetadata(final ServiceReference... healthCheckReferences) {
final List<HealthCheckMetadata> descriptors = new LinkedList<HealthCheckMetadata>();
for (final ServiceReference serviceReference : healthCheckReferences) {
final HealthCheckMetadata descriptor = getHealthCheckMetadata(serviceReference);
descriptors.add(descriptor);
}
return descriptors;
}
use of org.apache.sling.hc.util.HealthCheckMetadata in project sling by apache.
the class HealthCheckResultCache method useValidCacheResults.
/**
* Get the valid cache results
*/
public void useValidCacheResults(final List<HealthCheckMetadata> metadatas, final Collection<HealthCheckExecutionResult> results, final long resultCacheTtlInMs) {
final Set<HealthCheckExecutionResult> cachedResults = new TreeSet<HealthCheckExecutionResult>();
final Iterator<HealthCheckMetadata> checksIt = metadatas.iterator();
while (checksIt.hasNext()) {
final HealthCheckMetadata md = checksIt.next();
final HealthCheckExecutionResult result = getValidCacheResult(md, resultCacheTtlInMs);
if (result != null) {
cachedResults.add(result);
checksIt.remove();
}
}
logger.debug("Adding {} results from cache", cachedResults.size());
results.addAll(cachedResults);
}
use of org.apache.sling.hc.util.HealthCheckMetadata in project sling by apache.
the class AsyncHealthCheckExecutor method activate.
@Activate
protected final void activate(final ComponentContext componentContext) {
this.bundleContext = componentContext.getBundleContext();
this.bundleContext.addServiceListener(this);
int count = 0;
HealthCheckFilter healthCheckFilter = new HealthCheckFilter(bundleContext);
final ServiceReference[] healthCheckReferences = healthCheckFilter.getHealthCheckServiceReferences(HealthCheckSelector.empty());
for (ServiceReference serviceReference : healthCheckReferences) {
HealthCheckMetadata healthCheckMetadata = new HealthCheckMetadata(serviceReference);
if (isAsync(healthCheckMetadata)) {
if (scheduleHealthCheck(healthCheckMetadata)) {
count++;
}
}
}
LOG.debug("Scheduled {} jobs for asynchronous health checks", count);
}
use of org.apache.sling.hc.util.HealthCheckMetadata in project sling by apache.
the class AsyncHealthCheckExecutor method serviceChanged.
@Override
public void serviceChanged(ServiceEvent event) {
if (bundleContext == null) {
// already deactivated?
return;
}
ServiceReference serviceReference = event.getServiceReference();
final boolean isHealthCheck = serviceReference.isAssignableTo(bundleContext.getBundle(), HealthCheck.class.getName());
if (isHealthCheck) {
HealthCheckMetadata healthCheckMetadata = new HealthCheckMetadata(serviceReference);
int eventType = event.getType();
LOG.debug("Received service event of type {} for health check {}", eventType, healthCheckMetadata);
if (eventType == ServiceEvent.REGISTERED) {
scheduleHealthCheck(healthCheckMetadata);
} else if (eventType == ServiceEvent.UNREGISTERING) {
unscheduleHealthCheck(healthCheckMetadata);
} else if (eventType == ServiceEvent.MODIFIED) {
unscheduleHealthCheck(healthCheckMetadata);
scheduleHealthCheck(healthCheckMetadata);
}
}
}
use of org.apache.sling.hc.util.HealthCheckMetadata in project sling by apache.
the class HealthCheckExecutorImpl method execute.
/**
* Execute a set of health checks
*/
private List<HealthCheckExecutionResult> execute(final ServiceReference[] healthCheckReferences, HealthCheckExecutionOptions options) {
final StopWatch stopWatch = new StopWatch();
stopWatch.start();
final List<HealthCheckExecutionResult> results = new ArrayList<HealthCheckExecutionResult>();
final List<HealthCheckMetadata> healthCheckDescriptors = getHealthCheckMetadata(healthCheckReferences);
createResultsForDescriptors(healthCheckDescriptors, results, options);
stopWatch.stop();
if (logger.isDebugEnabled()) {
logger.debug("Time consumed for all checks: {}", msHumanReadable(stopWatch.getTime()));
}
// sort result
Collections.sort(results, new Comparator<HealthCheckExecutionResult>() {
@Override
public int compare(final HealthCheckExecutionResult arg0, final HealthCheckExecutionResult arg1) {
return ((ExecutionResult) arg0).compareTo((ExecutionResult) arg1);
}
});
return results;
}
Aggregations