use of org.osgi.service.component.ComponentContext in project sling by apache.
the class OakVirtualInstanceBuilder method createViewChecker.
@Override
protected ViewChecker createViewChecker() throws Exception {
getOakViewChecker();
return new ViewChecker() {
private final Logger logger = LoggerFactory.getLogger(getClass());
private SimulatedLease lease = new SimulatedLease(getResourceResolverFactory(), leaseCollection, getSlingId());
protected void activate(ComponentContext c) throws Throwable {
OakViewChecker pinger = getOakViewChecker();
PrivateAccessor.invoke(pinger, "activate", new Class[] { ComponentContext.class }, new Object[] { c });
}
@Override
public void checkView() {
try {
lease.updateDescriptor(getConfig());
} catch (Exception e) {
logger.error("run: could not update lease: " + e);
}
}
public void run() {
heartbeatAndCheckView();
}
@Override
public void heartbeatAndCheckView() {
// as soon as I see others the descriptor is updated
try {
lease.updateLeaseAndDescriptor(getConfig());
} catch (Exception e) {
logger.error("run: could not update lease: " + e, e);
}
try {
getOakViewChecker().run();
} catch (Exception e) {
logger.error("run: could not ping: " + e, e);
}
if (!getIdMapService().isInitialized()) {
if (!getIdMapService().waitForInit(1500)) {
fail("init didnt work");
}
}
}
};
}
use of org.osgi.service.component.ComponentContext 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.service.component.ComponentContext in project sling by apache.
the class HealthCheckTestsProviderTest method setup.
@Before
public void setup() throws InvalidSyntaxException {
setupTimestamp = System.currentTimeMillis();
final ComponentContext ctx = Mockito.mock(ComponentContext.class);
// context properties
final Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(HealthCheckTestsProvider.PROP_TAG_GROUPS, TAG_GROUPS);
props.put(Constants.SERVICE_PID, getClass().getName());
Mockito.when(ctx.getProperties()).thenReturn(props);
// bundle context
final BundleContext bc = Mockito.mock(BundleContext.class);
Mockito.when(ctx.getBundleContext()).thenReturn(bc);
// HealthCheck ServiceReferences mocks
Mockito.when(bc.getServiceReferences(Mockito.anyString(), Mockito.anyString())).thenAnswer(new Answer<ServiceReference[]>() {
@Override
public ServiceReference[] answer(InvocationOnMock invocation) throws Throwable {
return getMockReferences(bc, (String) invocation.getArguments()[1]);
}
});
provider = new HealthCheckTestsProvider() {
{
activate(ctx);
}
};
}
use of org.osgi.service.component.ComponentContext in project sling by apache.
the class RhinoJavaScriptEngineFactory method activate.
// ---------- SCR integration
@Activate
protected void activate(final ComponentContext context, final RhinoJavaScriptEngineFactoryConfiguration configuration) {
Dictionary<?, ?> props = context.getProperties();
boolean debugging = getProperty("org.apache.sling.scripting.javascript.debug", props, context.getBundleContext(), false);
optimizationLevel = readOptimizationLevel(configuration);
// setup the wrap factory
wrapFactory = new SlingWrapFactory();
// initialize the Rhino Context Factory
SlingContextFactory.setup(this);
Context cx = Context.enter();
setEngineName(getEngineName() + " (" + cx.getImplementationVersion() + ")");
languageVersion = String.valueOf(cx.getLanguageVersion());
Context.exit();
setExtensions(ECMA_SCRIPT_EXTENSION, ESP_SCRIPT_EXTENSION);
setMimeTypes("text/javascript", "application/ecmascript", "application/javascript");
setNames("javascript", ECMA_SCRIPT_EXTENSION, ESP_SCRIPT_EXTENSION);
final ContextFactory contextFactory = ContextFactory.getGlobal();
if (contextFactory instanceof SlingContextFactory) {
((SlingContextFactory) contextFactory).setDebugging(debugging);
}
// set the dynamic class loader as the application class loader
final DynamicClassLoaderManager dclm = this.dynamicClassLoaderManager;
if (dclm != null) {
contextFactory.initApplicationClassLoader(dynamicClassLoaderManager.getDynamicClassLoader());
}
log.info("Activated with optimization level {}", optimizationLevel);
}
use of org.osgi.service.component.ComponentContext in project stanbol by apache.
the class LanguageDetectionEngineTest method testNonTextContent.
@Test
public void testNonTextContent() throws EngineException, ConfigurationException, LangDetectException, IOException {
LanguageDetectionEnhancementEngine langIdEngine = new LanguageDetectionEnhancementEngine();
ComponentContext context = new MockComponentContext();
context.getProperties().put(EnhancementEngine.PROPERTY_NAME, "langdetect");
langIdEngine.activate(context);
ContentItem ci = ciFactory.createContentItem(new StringSource("123"));
langIdEngine.computeEnhancements(ci);
}
Aggregations