use of org.osgi.framework.ServiceReference in project sling by apache.
the class JobConsumerManagerTest method testSubCategoryMappingExecutor.
@Test
public void testSubCategoryMappingExecutor() {
final BundleContext bc = Mockito.mock(BundleContext.class);
final JobConsumerManager jcs = new JobConsumerManager();
jcs.activate(bc, getDefaultConfig());
final JobExecutor jc1 = Mockito.mock(JobExecutor.class);
final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
Mockito.when(ref1.getProperty(JobExecutor.PROPERTY_TOPICS)).thenReturn("a/**");
Mockito.when(ref1.getProperty(Constants.SERVICE_RANKING)).thenReturn(1);
Mockito.when(ref1.getProperty(Constants.SERVICE_ID)).thenReturn(1L);
Mockito.when(bc.getService(ref1)).thenReturn(jc1);
jcs.bindJobExecutor(ref1);
assertNotNull(jcs.getExecutor("a/b"));
assertNull(jcs.getExecutor("a"));
assertNotNull(jcs.getExecutor("a/c"));
assertNotNull(jcs.getExecutor("a/b/a"));
}
use of org.osgi.framework.ServiceReference in project sling by apache.
the class HealthCheckExecutorImpl method execute.
@Override
public List<HealthCheckExecutionResult> execute(HealthCheckSelector selector, HealthCheckExecutionOptions options) {
logger.debug("Starting executing checks for filter selector {} and execution options {}", selector, options);
final HealthCheckFilter filter = new HealthCheckFilter(this.bundleContext);
try {
final ServiceReference[] healthCheckReferences = filter.getHealthCheckServiceReferences(selector, options.isCombineTagsWithOr());
return this.execute(healthCheckReferences, options);
} finally {
filter.dispose();
}
}
use of org.osgi.framework.ServiceReference in project sling by apache.
the class CompositeHealthCheck method execute.
@Override
public Result execute() {
final ComponentContext localCtx = this.componentContext;
final ServiceReference referenceToThis = localCtx == null ? null : localCtx.getServiceReference();
Result result = referenceToThis == null ? null : checkForRecursion(referenceToThis, new HashSet<String>());
if (result != null) {
// return recursion error
return result;
}
FormattingResultLog resultLog = new FormattingResultLog();
List<HealthCheckExecutionResult> executionResults = healthCheckExecutor.execute(HealthCheckSelector.tags(filterTags));
resultLog.debug("Executing {} HealthChecks selected by tags {}", executionResults.size(), Arrays.asList(filterTags));
result = new CompositeResult(resultLog, executionResults);
return result;
}
use of org.osgi.framework.ServiceReference in project sling by apache.
the class CompositeHealthCheck method checkForRecursion.
Result checkForRecursion(ServiceReference hcReference, Set<String> alreadyBannedTags) {
HealthCheckMetadata thisCheckMetadata = new HealthCheckMetadata(hcReference);
Set<String> bannedTagsForThisCompositeCheck = new HashSet<String>();
bannedTagsForThisCompositeCheck.addAll(alreadyBannedTags);
bannedTagsForThisCompositeCheck.addAll(thisCheckMetadata.getTags());
String[] tagsForIncludedChecksArr = PropertiesUtil.toStringArray(hcReference.getProperty(PROP_FILTER_TAGS), new String[0]);
Set<String> tagsForIncludedChecks = new HashSet<String>(Arrays.asList(tagsForIncludedChecksArr));
log.debug("HC {} has banned tags {}", thisCheckMetadata.getName(), bannedTagsForThisCompositeCheck);
log.debug("tagsForIncludedChecks {}", tagsForIncludedChecks);
// is this HC ok?
Set<String> intersection = new HashSet<String>();
intersection.addAll(bannedTagsForThisCompositeCheck);
intersection.retainAll(tagsForIncludedChecks);
if (!intersection.isEmpty()) {
return new Result(Status.HEALTH_CHECK_ERROR, "INVALID CONFIGURATION: Cycle detected in composite health check hierarchy. Health check '" + thisCheckMetadata.getName() + "' (" + hcReference.getProperty(Constants.SERVICE_ID) + ") must not have tag(s) " + intersection + " as a composite check in the hierarchy is itself already tagged alike (tags assigned to composite checks: " + bannedTagsForThisCompositeCheck + ")");
}
// check each sub composite check
ServiceReference[] hcRefsOfCompositeCheck = healthCheckFilter.getHealthCheckServiceReferences(HealthCheckSelector.tags(tagsForIncludedChecksArr));
for (ServiceReference hcRefOfCompositeCheck : hcRefsOfCompositeCheck) {
if (CompositeHealthCheck.class.getName().equals(hcRefOfCompositeCheck.getProperty(ComponentConstants.COMPONENT_NAME))) {
log.debug("Checking sub composite HC {}, {}", hcRefOfCompositeCheck, hcRefOfCompositeCheck.getProperty(ComponentConstants.COMPONENT_NAME));
Result result = checkForRecursion(hcRefOfCompositeCheck, bannedTagsForThisCompositeCheck);
if (result != null) {
// found recursion
return result;
}
}
}
// no recursion detected
return null;
}
use of org.osgi.framework.ServiceReference in project sling by apache.
the class HealthCheckMBeanCreator method unregisterHCMBean.
private synchronized void unregisterHCMBean(final BundleContext bundleContext, final ServiceReference ref) {
final Registration reg = registeredServices.remove(ref);
if (reg != null) {
final boolean registerFirst = reg.unregister();
final List<ServiceReference> registered = this.sortedRegistrations.get(reg.name);
registered.remove(ref);
if (registered.size() == 0) {
this.sortedRegistrations.remove(reg.name);
} else if (registerFirst) {
final ServiceReference newRef = registered.get(0);
final Registration newReg = this.registeredServices.get(newRef);
newReg.register(bundleContext);
}
bundleContext.ungetService(ref);
}
}
Aggregations