Search in sources :

Example 1 with NSFComponentModule

use of com.ibm.domino.xsp.module.nsf.NSFComponentModule in project org.openntf.xsp.jakartaee by OpenNTF.

the class NSFBeanArchiveHandler method handle.

@Override
public BeanArchiveBuilder handle(String beanArchiveReference) {
    NotesContext context = NotesContext.getCurrentUnchecked();
    if (context != null) {
        NSFComponentModule module = context.getModule();
        try {
            if (LibraryUtil.usesLibrary(CDILibrary.LIBRARY_ID, module)) {
                // If it uses a CDI bundle ref, skip processing
                String bundleId = ContainerUtil.getApplicationCDIBundle(context.getNotesDatabase());
                if (StringUtil.isNotEmpty(bundleId)) {
                    return null;
                }
                // Slightly customize the builder to keep some extra metadata
                BeanArchiveBuilder builder = new BeanArchiveBuilder() {

                    {
                        super.setBeansXml(BeansXml.EMPTY_BEANS_XML);
                        super.setId(module.getDatabasePath());
                    }

                    @Override
                    public BeanArchiveBuilder setBeansXml(BeansXml beansXml) {
                        return this;
                    }
                };
                ModuleUtil.getClassNames(module).filter(className -> !ModuleUtil.GENERATED_CLASSNAMES.matcher(className).matches()).forEach(builder::addClass);
                return builder;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) BeanArchiveBuilder(org.jboss.weld.environment.deployment.discovery.BeanArchiveBuilder) StringUtil(com.ibm.commons.util.StringUtil) NotesContext(com.ibm.domino.xsp.module.nsf.NotesContext) ModuleUtil(org.openntf.xsp.jakartaee.util.ModuleUtil) BeanArchiveHandler(org.jboss.weld.environment.deployment.discovery.BeanArchiveHandler) NSFComponentModule(com.ibm.domino.xsp.module.nsf.NSFComponentModule) Priority(jakarta.annotation.Priority) CDILibrary(org.openntf.xsp.cdi.CDILibrary) ContainerUtil(org.openntf.xsp.cdi.util.ContainerUtil) LibraryUtil(org.openntf.xsp.jakartaee.util.LibraryUtil) NSFComponentModule(com.ibm.domino.xsp.module.nsf.NSFComponentModule) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) NotesContext(com.ibm.domino.xsp.module.nsf.NotesContext) BeanArchiveBuilder(org.jboss.weld.environment.deployment.discovery.BeanArchiveBuilder)

Example 2 with NSFComponentModule

use of com.ibm.domino.xsp.module.nsf.NSFComponentModule in project org.openntf.xsp.jakartaee by OpenNTF.

the class NSFJAXRSApplication method getProperties.

@Override
public Map<String, Object> getProperties() {
    Map<String, Object> result = new LinkedHashMap<>();
    // Read in xsp.properties
    NSFComponentModule module = NotesContext.getCurrent().getModule();
    Properties xspProperties = new Properties();
    try (InputStream is = module.getResourceAsStream("/WEB-INF/xsp.properties")) {
        // $NON-NLS-1$
        xspProperties.load(is);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    xspProperties.forEach((key, value) -> result.put(key.toString(), value));
    return result;
}
Also used : NSFComponentModule(com.ibm.domino.xsp.module.nsf.NSFComponentModule) InputStream(java.io.InputStream) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Properties(java.util.Properties) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with NSFComponentModule

use of com.ibm.domino.xsp.module.nsf.NSFComponentModule in project org.openntf.domino by OpenNTF.

the class XotsWrappedTask method invokeTasklet.

/**
 * Invokes the tasklet
 *
 * @param codeModule
 * @param bubbleException
 * @param sessionFactory
 * @param wrappedTask
 * @return
 * @throws Exception
 */
@SuppressWarnings({ "restriction" })
protected Object invokeTasklet(final NotesContext ctx, final NSFComponentModule module) throws Exception {
    ClassLoader mcl = null;
    ThreadLock readLock = null;
    NSFComponentModule codeModule = null;
    if (module == null) {
        mcl = getWrappedTask().getClass().getClassLoader();
    } else {
        // RPr: In my opinion, This is the proper way how to run runnables in a different thread
        codeModule = module.getTemplateModule();
        if (codeModule == null)
            codeModule = module;
        mcl = codeModule.getModuleClassLoader();
        if (ODAPlatform.isAppFlagSet("LOCKXOTS", codeModule.getNotesApplication())) {
            // $NON-NLS-1$
            readLock = XotsDominoExecutor.getLockManager(codeModule).getReadLock();
        }
    }
    if (sessionFactory != null) {
        Factory.setSessionFactory(sessionFactory, SessionType.CURRENT);
        @SuppressWarnings("unused") org.openntf.domino.Session current = Factory.getSession(SessionType.CURRENT);
    }
    try {
        if (readLock != null)
            // we want to read data from the module, so lock it!
            readLock.acquire();
        // set up the classloader
        ClassLoader oldCl = switchClassLoader(mcl);
        try {
            Object wrappedTask = getWrappedTask();
            XotsDominoExecutor.initModule(ctx, mcl, wrappedTask);
            XotsConfiguration config = null;
            if (mcl instanceof org.eclipse.osgi.internal.loader.ModuleClassLoader) {
                // Determine the bundle of mcl
                String bundle = ((org.eclipse.osgi.internal.loader.ModuleClassLoader) mcl).getBundle().getSymbolicName();
                config = Configuration.getXotsBundleConfiguration(bundle, wrappedTask.getClass().getName());
            } else {
                config = Configuration.getXotsNSFConfiguration(module.getDatabasePath(), wrappedTask.getClass().getName());
            }
            try {
                config.logStart();
                Object ret = invokeObject(wrappedTask);
                config.logSuccess();
                return ret;
            } catch (Exception e) {
                config.logError(e);
                throw e;
            }
        } finally {
            switchClassLoader(oldCl);
        }
    } finally {
        if (readLock != null)
            readLock.release();
    }
}
Also used : XotsConfiguration(org.openntf.domino.config.XotsConfiguration) NSFComponentModule(com.ibm.domino.xsp.module.nsf.NSFComponentModule) ThreadLock(com.ibm.commons.util.ThreadLock)

Example 4 with NSFComponentModule

use of com.ibm.domino.xsp.module.nsf.NSFComponentModule in project org.openntf.domino by OpenNTF.

the class XotsWrappedTask method callOrRun.

/**
 * Common code for the wrappers
 *
 * @param module
 * @param bubbleException
 * @param sessionFactory
 * @param callable
 * @param runnable
 * @return
 */
protected Object callOrRun(final NSFComponentModule module) throws Exception {
    NSFComponentModule codeModule = null;
    if (module != null) {
        codeModule = module.getTemplateModule() == null ? module : module.getTemplateModule();
        if (module.isDestroyed() || codeModule.isDestroyed()) {
            // $NON-NLS-1$
            throw new IllegalArgumentException("Module was destroyed in the meantime. Cannot run");
        }
        module.updateLastModuleAccess();
        codeModule.updateLastModuleAccess();
    }
    final NotesContext ctx = new NotesContext(module);
    NotesContext.initThread(ctx);
    try {
        // checkme: What should we use here?
        // Factory.initThread(ODAPlatform.getAppThreadConfig(module.getNotesApplication()));
        Factory.initThread(sourceThreadConfig);
        try {
            return invokeTasklet(ctx, codeModule);
        } catch (Exception e) {
            DominoUtils.handleException(e);
            return null;
        } finally {
            Factory.termThread();
        }
    } finally {
        NotesContext.termThread();
    }
}
Also used : NSFComponentModule(com.ibm.domino.xsp.module.nsf.NSFComponentModule) NotesContext(com.ibm.domino.xsp.module.nsf.NotesContext)

Example 5 with NSFComponentModule

use of com.ibm.domino.xsp.module.nsf.NSFComponentModule in project org.openntf.domino by OpenNTF.

the class XotsDominoExecutor method wrap.

@Override
protected <V> IWrappedCallable<V> wrap(final Callable<V> inner) {
    if (inner instanceof IWrappedCallable)
        return (IWrappedCallable<V>) inner;
    NSFComponentModule module = getCurrentModule();
    Tasklet annot = inner.getClass().getAnnotation(Tasklet.class);
    if (annot == null || annot.context() == Context.DEFAULT) {
        if (module == null) {
            return super.wrap(inner);
        } else {
            if (inner instanceof AbstractXotsCallable) {
                XotsContext ctx = new XotsContext();
                ctx.setOpenLogApiPath(ODAPlatform.getXspPropertyAsString("xsp.openlog.filepath"));
                ctx.setContextApiPath(module.getDatabasePath());
                ctx.setTaskletClass(inner.getClass().getName());
                ((AbstractXotsCallable) inner).setContext(ctx);
            }
            return new XotsWrappedCallable<V>(module, inner);
        }
    } else if (annot.context() == Context.PLUGIN) {
        return super.wrap(inner);
    } else if (annot.context() == Context.XSPSCOPED || annot.context() == Context.XSPBARE) {
        if (inner instanceof AbstractXotsXspCallable) {
            XotsXspContext ctx = new XotsXspContext();
            if (annot.context() == Context.XSPSCOPED) {
                ctx.initialiseXspContext(true);
            } else {
                ctx.initialiseXspContext(false);
            }
            if (module != null) {
                ctx.setOpenLogApiPath(ODAPlatform.getXspPropertyAsString("xsp.openlog.filepath"));
                ctx.setContextApiPath(module.getDatabasePath());
                ctx.setTaskletClass(inner.getClass().getName());
            }
            ((AbstractXotsXspCallable) inner).setContext(ctx);
        }
        if (module == null) {
            return super.wrap(inner);
        } else {
            return new XotsWrappedCallable<V>(module, inner);
        }
    } else {
        if (module == null) {
            throw new NullPointerException("No module is running");
        }
        return new XotsWrappedCallable<V>(module, inner);
    }
}
Also used : IWrappedCallable(org.openntf.domino.thread.IWrappedCallable) AbstractXotsCallable(org.openntf.domino.xots.AbstractXotsCallable) NSFComponentModule(com.ibm.domino.xsp.module.nsf.NSFComponentModule) XotsContext(org.openntf.domino.xots.XotsContext) Tasklet(org.openntf.domino.xots.Tasklet)

Aggregations

NSFComponentModule (com.ibm.domino.xsp.module.nsf.NSFComponentModule)7 NotesContext (com.ibm.domino.xsp.module.nsf.NotesContext)2 Tasklet (org.openntf.domino.xots.Tasklet)2 XotsContext (org.openntf.domino.xots.XotsContext)2 StringUtil (com.ibm.commons.util.StringUtil)1 ThreadLock (com.ibm.commons.util.ThreadLock)1 Priority (jakarta.annotation.Priority)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Properties (java.util.Properties)1 BeansXml (org.jboss.weld.bootstrap.spi.BeansXml)1 BeanArchiveBuilder (org.jboss.weld.environment.deployment.discovery.BeanArchiveBuilder)1 BeanArchiveHandler (org.jboss.weld.environment.deployment.discovery.BeanArchiveHandler)1 XotsConfiguration (org.openntf.domino.config.XotsConfiguration)1 IWrappedCallable (org.openntf.domino.thread.IWrappedCallable)1 IWrappedRunnable (org.openntf.domino.thread.IWrappedRunnable)1 AbstractXotsCallable (org.openntf.domino.xots.AbstractXotsCallable)1