use of org.osgi.service.component.annotations.Activate in project smarthome by eclipse.
the class SampleExtensionService method activate.
@Activate
protected void activate() {
types.add(new ExtensionType("binding", "Bindings"));
types.add(new ExtensionType("ui", "User Interfaces"));
types.add(new ExtensionType("persistence", "Persistence Services"));
for (ExtensionType type : types) {
for (int i = 0; i < 10; i++) {
String id = type.getId() + Integer.toString(i);
boolean installed = Math.random() > 0.5;
String name = RandomStringUtils.randomAlphabetic(5);
String label = name + " " + StringUtils.capitalize(type.getId());
String typeId = type.getId();
String version = "1.0";
String link = (Math.random() < 0.5) ? null : "http://lmgtfy.com/?q=" + name;
String description = createDescription();
String imageLink = null;
String backgroundColor = createRandomColor();
Extension extension = new Extension(id, typeId, label, version, link, installed, description, backgroundColor, imageLink);
extensions.put(extension.getId(), extension);
}
}
}
use of org.osgi.service.component.annotations.Activate in project APM by Cognifide.
the class ActionMapperRegistryImpl method activate.
@Activate
public void activate(ComponentContext componentContext) {
registry = new AnnotatedClassRegistry(componentContext.getBundleContext(), BUNDLE_HEADER, Mapper.class);
registry.addChangeListener(this);
registry.open();
}
use of org.osgi.service.component.annotations.Activate in project sling by apache.
the class JobManagerImpl method activate.
/**
* Activate this component.
* @param props Configuration properties
*/
@Activate
protected void activate(final BundleContext ctx, final Map<String, Object> props) throws LoginException {
this.jobScheduler = new org.apache.sling.event.impl.jobs.scheduling.JobSchedulerImpl(this.configuration, this.scheduler, this);
this.maintenanceTask = new CleanUpTask(this.configuration, this.jobScheduler);
final Dictionary<String, Object> regProps = new Hashtable<>();
regProps.put(ResourceChangeListener.PATHS, this.configuration.getScheduledJobsPath(false));
regProps.put(ResourceChangeListener.CHANGES, new String[] { ResourceChange.ChangeType.ADDED.name(), ResourceChange.ChangeType.CHANGED.name(), ResourceChange.ChangeType.REMOVED.name() });
regProps.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
regProps.put(Constants.SERVICE_DESCRIPTION, "Resource change listener for scheduled jobs");
this.changeListenerReg = ctx.registerService(ResourceChangeListener.class, this.jobScheduler, regProps);
logger.info("Apache Sling Job Manager started on instance {}", Environment.APPLICATION_ID);
}
use of org.osgi.service.component.annotations.Activate in project sling by apache.
the class SlingServletResolver method activate.
// ---------- SCR Integration ----------------------------------------------
/**
* Activate this component.
*/
@Activate
protected void activate(final BundleContext context, final Config config) throws LoginException {
final Collection<PendingServlet> refs;
synchronized (this.pendingServlets) {
refs = new ArrayList<>(pendingServlets);
pendingServlets.clear();
this.sharedScriptResolver = resourceResolverFactory.getServiceResourceResolver(Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, (Object) "scripts"));
this.searchPaths = this.sharedScriptResolver.getSearchPath();
servletResourceProviderFactory = new ServletResourceProviderFactory(config.servletresolver_servletRoot(), this.searchPaths);
// register servlets immediately from now on
this.context = context;
}
createAllServlets(refs);
// execution paths
this.executionPaths = config.servletresolver_paths();
if (this.executionPaths != null) {
// we simply set the array to null
if (this.executionPaths.length == 0) {
this.executionPaths = null;
} else {
boolean hasRoot = false;
for (int i = 0; i < this.executionPaths.length; i++) {
final String path = this.executionPaths[i];
if (path == null || path.length() == 0 || path.equals("/")) {
hasRoot = true;
break;
}
}
if (hasRoot) {
this.executionPaths = null;
}
}
}
this.defaultExtensions = config.servletresolver_defaultExtensions();
// create cache - if a cache size is configured
this.cacheSize = config.servletresolver_cacheSize();
if (this.cacheSize > 5) {
this.cache = new ConcurrentHashMap<>(cacheSize);
this.logCacheSizeWarning = true;
} else {
this.cacheSize = 0;
}
// setup default servlet
this.getDefaultServlet();
// and finally register as event listener if we need to flush the cache
if (this.cache != null) {
final Dictionary<String, Object> props = new Hashtable<>();
props.put("event.topics", new String[] { "javax/script/ScriptEngineFactory/*", "org/apache/sling/api/adapter/AdapterFactory/*", "org/apache/sling/scripting/core/BindingsValuesProvider/*" });
props.put(ResourceChangeListener.PATHS, "/");
props.put("service.description", "Apache Sling Servlet Resolver and Error Handler");
props.put("service.vendor", "The Apache Software Foundation");
this.eventHandlerReg = context.registerService(new String[] { ResourceChangeListener.class.getName(), EventHandler.class.getName() }, this, props);
}
this.plugin = new ServletResolverWebConsolePlugin(context);
if (this.cacheSize > 0) {
try {
Dictionary<String, String> mbeanProps = new Hashtable<>();
mbeanProps.put("jmx.objectname", "org.apache.sling:type=servletResolver,service=SlingServletResolverCache");
ServletResolverCacheMBeanImpl mbean = new ServletResolverCacheMBeanImpl();
mbeanRegistration = context.registerService(SlingServletResolverCacheMBean.class, mbean, mbeanProps);
} catch (Throwable t) {
LOGGER.debug("Unable to register mbean");
}
}
}
use of org.osgi.service.component.annotations.Activate in project sling by apache.
the class ResourcePresenter method activate.
@Activate
public void activate(final ResourcePresenterConfiguration configuration, final BundleContext bundleContext) {
logger.info("activating resource presenter for {}", configuration.path());
path = configuration.path();
this.bundleContext = bundleContext;
try (final ResourceResolver resourceResolver = getServiceResourceResolver()) {
final Resource resource = resourceResolver.getResource(path);
if (resource != null) {
registerResourcePresence();
}
registerResourceChangeListener();
} catch (LoginException e) {
logger.error(e.getMessage(), e);
}
}
Aggregations