Search in sources :

Example 66 with Activate

use of org.osgi.service.component.annotations.Activate in project jackrabbit-oak by apache.

the class AtomicCounterEditorProvider method activate.

@Activate
public void activate(BundleContext context) {
    whiteboard.set(new OsgiWhiteboard(context));
    ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat("atomic-counter-%d").build();
    scheduler.set(Executors.newScheduledThreadPool(10, tf));
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) OsgiWhiteboard(org.apache.jackrabbit.oak.osgi.OsgiWhiteboard) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Activate(org.osgi.service.component.annotations.Activate)

Example 67 with Activate

use of org.osgi.service.component.annotations.Activate in project jackrabbit-oak by apache.

the class DataStoreTextProviderService method activate.

@Activate
private void activate(BundleContext context, Configuration config) throws IOException {
    String dirPath = config.dir();
    checkNotNull(dirPath, "Directory path not configured via 'dir'");
    File dir = new File(dirPath);
    checkArgument(dir.exists(), "Directory %s does not exist", dir.getAbsolutePath());
    textWriter = new DataStoreTextWriter(dir, true);
    reg = context.registerService(PreExtractedTextProvider.class.getName(), textWriter, null);
}
Also used : File(java.io.File) Activate(org.osgi.service.component.annotations.Activate)

Example 68 with Activate

use of org.osgi.service.component.annotations.Activate in project liferay-blade-samples by liferay.

the class AddTestData method addTestData.

@Activate
public void addTestData() {
    int entries = 2;
    while (entries > 0) {
        Foo foo = _fooLocalService.createFoo(0);
        foo.setField1("new field1 entry" + entries);
        foo.setField2(true);
        foo.setField3(10);
        foo.setField4(new Date());
        foo.setField5("new field5 entry" + entries);
        foo.isNew();
        _fooLocalService.addFooWithoutId(foo);
        entries--;
    }
}
Also used : Foo(com.liferay.blade.samples.servicebuilder.model.Foo) Date(java.util.Date) Activate(org.osgi.service.component.annotations.Activate)

Example 69 with Activate

use of org.osgi.service.component.annotations.Activate in project liferay-blade-samples by liferay.

the class BladeCustomJspBag method activate.

/**
 * Adds the URL paths for all custom core JSPs to a list when the module is
 * activated.
 *
 * @param bundleContext the bundle context from which to get the custom
 *        JSP's bundle
 */
@Activate
protected void activate(BundleContext bundleContext) {
    _bundle = bundleContext.getBundle();
    _customJsps = new ArrayList<>();
    Enumeration<URL> entries = _bundle.findEntries(getCustomJspDir(), "*.jsp", true);
    while (entries.hasMoreElements()) {
        URL url = entries.nextElement();
        _customJsps.add(url.getPath());
    }
}
Also used : URL(java.net.URL) Activate(org.osgi.service.component.annotations.Activate)

Example 70 with Activate

use of org.osgi.service.component.annotations.Activate in project adeptj-modules by AdeptJ.

the class EntityManagerFactoryProvider method start.

// ---------------- INTERNAL ----------------
@Activate
protected void start(BundleContext context, EntityManagerFactoryConfig config) {
    this.lock.lock();
    try {
        String unitName = config.unitName();
        Validate.isTrue(isNotEmpty(unitName), "unitName can't be null or empty!!");
        LOGGER.info("Creating EntityManagerFactory for PersistenceUnit: [{}]", unitName);
        DataSource ds = Validate.notNull(this.dataSourceProvider.getDataSource(config.dataSourceName()), DS_NOT_NULL_MSG);
        this.emf = new PersistenceProvider().createEntityManagerFactory(unitName, JpaProperties.create(config, ds, this.validatorService.getValidatorFactory()));
        if (this.emf == null) {
            throw new IllegalStateException(EMF_NULL_MSG);
        } else {
            LOGGER.info("EntityManagerFactory [{}] created for PersistenceUnit: [{}]", this.emf, unitName);
            this.jpaCrudRepository = JpaCrudRepositories.create(unitName, this.emf, context);
        }
    } catch (Exception ex) {
        // NOSONAR
        LOGGER.error("Exception occurred while creating EntityManagerFactory!!", ex);
        // Close the EntityManagerFactory if it was created earlier but exception occurred later.
        Optional.ofNullable(this.emf).ifPresent(EntityManagerFactory::close);
        // Throw exception so that SCR won't create the component instance.
        throw new JpaBootstrapException(ex);
    } finally {
        this.lock.unlock();
    }
}
Also used : PersistenceProvider(org.eclipse.persistence.jpa.PersistenceProvider) DataSource(javax.sql.DataSource) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

Activate (org.osgi.service.component.annotations.Activate)100 BundleContext (org.osgi.framework.BundleContext)13 File (java.io.File)8 OsgiWhiteboard (org.apache.jackrabbit.oak.osgi.OsgiWhiteboard)7 IOException (java.io.IOException)6 Hashtable (java.util.Hashtable)6 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)5 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)4 ArrayList (java.util.ArrayList)4 Properties (java.util.Properties)3 ServiceReference (org.osgi.framework.ServiceReference)3 PromiseFactory (org.osgi.util.promise.PromiseFactory)3 ServerStartupObserver (org.wso2.carbon.core.ServerStartupObserver)3 JsonObject (com.google.gson.JsonObject)2 Date (java.util.Date)2 Dictionary (java.util.Dictionary)2 ObjectName (javax.management.ObjectName)2 Whiteboard (org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard)2 WhiteboardExecutor (org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardExecutor)2 LoginException (org.apache.sling.api.resource.LoginException)2