Java Code Examples for org.apache.openejb.loader.SystemInstance#setComponent()

The following examples show how to use org.apache.openejb.loader.SystemInstance#setComponent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpEjbServer.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public void init(final Properties props) throws Exception {
    name = props.getProperty("name");
    final EjbServer ejbServer = new EjbServer();
    final ServerServiceAdapter adapter = new ServerServiceAdapter(ejbServer);

    final SystemInstance systemInstance = SystemInstance.get();
    HttpListenerRegistry registry = systemInstance.getComponent(HttpListenerRegistry.class);
    if (registry == null) {
        registry = new HttpListenerRegistry();
        systemInstance.setComponent(HttpListenerRegistry.class, registry);
    }

    registry.addHttpListener(adapter, "/ejb/?.*");

    // register the http server
    systemInstance.setComponent(HttpServer.class, httpServer);

    httpServer.init(props);
    ejbServer.init(props);
}
 
Example 2
Source File: LightweightWebAppBuilder.java    From tomee with Apache License 2.0 6 votes vote down vote up
private void switchServletContextIfNeeded(final ServletContext sc, final Runnable runnable) {
    if (sc == null) {
        runnable.run();
        return;
    }
    final SystemInstance systemInstance = SystemInstance.get();
    final ServletContext old = systemInstance.getComponent(ServletContext.class);
    systemInstance.setComponent(ServletContext.class, sc);
    try {
        runnable.run();
    } finally {
        if (old == null) {
            systemInstance.removeComponent(ServletContext.class);
        } else {
            systemInstance.setComponent(ServletContext.class, old);
        }
    }
}
 
Example 3
Source File: TomeeJaxWsService.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void init(final Properties props) throws Exception {
    // Install the Tomcat webservice registry
    final SystemInstance system = SystemInstance.get();

    TomcatWsRegistry tomcatSoapHandler = (TomcatWsRegistry) system.getComponent(WsRegistry.class);
    if (tomcatSoapHandler == null) {
        tomcatSoapHandler = new TomcatWsRegistry();
        system.setComponent(WsRegistry.class, tomcatSoapHandler);
    }

    system.addObserver(this);
}
 
Example 4
Source File: TomcatWebAppBuilder.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void setComponentsUsedByCDI() {
    final SystemInstance systemInstance = SystemInstance.get();
    if (systemInstance.getComponent(HttpServletRequest.class) == null) {
        systemInstance.setComponent(HttpServletRequest.class, Proxys.threadLocalProxy(HttpServletRequest.class, OpenEJBSecurityListener.requests, null));
    }
    if (systemInstance.getComponent(HttpSession.class) == null) {
        systemInstance.setComponent(javax.servlet.http.HttpSession.class, Proxys.threadLocalRequestSessionProxy(OpenEJBSecurityListener.requests, null));
    }
    if (systemInstance.getComponent(ServletContext.class) == null) {
        systemInstance.setComponent(ServletContext.class, Proxys.handlerProxy(servletContextHandler, ServletContext.class, CdiAppContextsService.FiredManually.class));
    }
}
 
Example 5
Source File: TomeeJaxRsService.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void init(final Properties props) throws Exception {
    final SystemInstance system = SystemInstance.get();

    TomcatRsRegistry tomcatRestHandler = (TomcatRsRegistry) system.getComponent(RsRegistry.class);
    if (tomcatRestHandler == null) {
        tomcatRestHandler = new TomcatRsRegistry();
        system.setComponent(RsRegistry.class, tomcatRestHandler);
    }

    system.addObserver(this);
}
 
Example 6
Source File: OpenEJBHttpServer.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static HttpListenerRegistry getHttpListenerRegistry() {
    final SystemInstance systemInstance = SystemInstance.get();
    HttpListenerRegistry registry = systemInstance.getComponent(HttpListenerRegistry.class);
    if (registry == null) {
        registry = new HttpListenerRegistry();
        systemInstance.setComponent(HttpListenerRegistry.class, registry);
    }
    return registry;
}
 
Example 7
Source File: Main.java    From tomee with Apache License 2.0 5 votes vote down vote up
private static void initServer(final SystemInstance system) throws Exception {
    Server server = Server.getInstance();
    server.init(system.getProperties());

    system.setComponent(Server.class, server);
    server.start();
}
 
Example 8
Source File: EjbTimerServiceImpl.java    From tomee with Apache License 2.0 4 votes vote down vote up
public static synchronized Scheduler getDefaultScheduler(final BeanContext deployment) {
    Scheduler scheduler = deployment.get(Scheduler.class);
    if (scheduler != null) {
        boolean valid;
        try {
            valid = !scheduler.isShutdown();
        } catch (final Exception ignored) {
            valid = false;
        }
        if (valid) {
            return scheduler;
        }
    }

    Scheduler thisScheduler;
    synchronized (deployment.getId()) { // should be done only once so no perf issues
        scheduler = deployment.get(Scheduler.class);
        if (scheduler != null) {
            return scheduler;
        }

        final Properties properties = new Properties();
        int quartzProps = 0;
        quartzProps += putAll(properties, SystemInstance.get().getProperties());
        quartzProps += putAll(properties, deployment.getModuleContext().getAppContext().getProperties());
        quartzProps += putAll(properties, deployment.getModuleContext().getProperties());
        quartzProps += putAll(properties, deployment.getProperties());

        // custom config -> don't use default/global scheduler
        // if one day we want to keep a global config for a global scheduler (SystemInstance.get().getProperties()) we'll need to manage resume/pause etc correctly by app
        // since we have a scheduler by ejb today in such a case we don't need
        final boolean newInstance = quartzProps > 0;

        final SystemInstance systemInstance = SystemInstance.get();

        scheduler = systemInstance.getComponent(Scheduler.class);

        if (scheduler == null || newInstance) {
            final boolean useTccl = "true".equalsIgnoreCase(properties.getProperty(OPENEJB_QUARTZ_USE_TCCL, "false"));

            defaultQuartzConfiguration(properties, deployment, newInstance, useTccl);

            try {
                // start in container context to avoid thread leaks
                final ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
                if (useTccl) {
                    Thread.currentThread().setContextClassLoader(deployment.getClassLoader());
                } else {
                    Thread.currentThread().setContextClassLoader(EjbTimerServiceImpl.class.getClassLoader());
                }
                try {
                    thisScheduler = new StdSchedulerFactory(properties).getScheduler();
                    thisScheduler.start();
                } finally {
                    Thread.currentThread().setContextClassLoader(oldCl);
                }

                //durability is configured with true, which means that the job will be kept in the store even if no trigger is attached to it.
                //Currently, all the EJB beans share with the same job instance
                final JobDetail job = JobBuilder.newJob(EjbTimeoutJob.class)
                    .withIdentity(OPENEJB_TIMEOUT_JOB_NAME, OPENEJB_TIMEOUT_JOB_GROUP_NAME)
                    .storeDurably(true)
                    .requestRecovery(false)
                    .build();
                thisScheduler.addJob(job, true);
            } catch (final SchedulerException e) {
                throw new OpenEJBRuntimeException("Fail to initialize the default scheduler", e);
            }

            if (!newInstance) {
                systemInstance.setComponent(Scheduler.class, thisScheduler);
            }
        } else {
            thisScheduler = scheduler;
        }

        deployment.set(Scheduler.class, thisScheduler);
    }

    return thisScheduler;
}
 
Example 9
Source File: Assembler.java    From tomee with Apache License 2.0 3 votes vote down vote up
public Assembler(final JndiFactory jndiFactory) {
    logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP, Assembler.class);
    skipLoaderIfPossible = "true".equalsIgnoreCase(SystemInstance.get().getProperty("openejb.classloader.skip-app-loader-if-possible", "true"));
    resourceDestroyTimeout = SystemInstance.get().getProperty("openejb.resources.destroy.timeout");
    threadStackOnTimeout = "true".equals(SystemInstance.get().getProperty("openejb.resources.destroy.stack-on-timeout", "false"));
    persistenceClassLoaderHandler = new PersistenceClassLoaderHandlerImpl();

    installNaming();

    final SystemInstance system = SystemInstance.get();

    system.setComponent(org.apache.openejb.spi.Assembler.class, this);
    system.setComponent(Assembler.class, this);

    containerSystem = new CoreContainerSystem(jndiFactory);
    system.setComponent(ContainerSystem.class, containerSystem);

    jndiBuilder = new JndiBuilder(containerSystem.getJNDIContext());

    setConfiguration(new OpenEjbConfiguration());

    final ApplicationServer appServer = system.getComponent(ApplicationServer.class);
    if (appServer == null) {
        system.setComponent(ApplicationServer.class, new ServerFederation());
    }

    system.setComponent(EjbResolver.class, new EjbResolver(null, EjbResolver.Scope.GLOBAL));

    installExtensions();

    system.fireEvent(new AssemblerCreated());

    initBValFiltering();
}