public EJBContainer createEJBContainer()

in tomee/apache-tomee/src/main/java/org/apache/tomee/RemoteTomEEEJBContainer.java [69:180]


        public EJBContainer createEJBContainer(final Map<?, ?> rawProperties) {
            final Map<?, ?> properties = rawProperties == null ? new HashMap<>() : rawProperties;
            final Object provider = properties.get(EJBContainer.PROVIDER);
            int ejbContainerProviders = 1;
            try {
                ejbContainerProviders = ProviderLocator.getServices(EJBContainerProvider.class.getName(), EJBContainer.class, Thread.currentThread().getContextClassLoader()).size();
            } catch (final Exception e) {
                // no-op
            }

            if ((provider == null && ejbContainerProviders > 1)
                    || (!RemoteTomEEEJBContainer.class.equals(provider)
                    && !CONTAINER_NAMES.contains(String.valueOf(provider)))) {
                return null;
            }

            if (instance != null) {
                return instance;
            }

            final Object modules = properties.get(EJBContainer.MODULES);

            System.getProperties().putAll(properties);
            final File home = new File(System.getProperty("openejb.home", "doesn't exist"));
            if (!home.exists()) {
                throw new IllegalArgumentException("You need to set openejb.home");
            }

            final QuickServerXmlParser parser = QuickServerXmlParser.parse(new File(home, "conf/server.xml"));
            final String remoteEjb = System.getProperty(Context.PROVIDER_URL, "http://" + parser.host() + ":" + parser.http() + "/tomee/ejb");
            System.setProperty(RemoteServer.SERVER_SHUTDOWN_PORT, parser.stop());

            final String blacklist = System.getProperty("tomee.serialization.class.blacklist");
            if (blacklist == null) {
                System.setProperty("tomee.serialization.class.blacklist", "-");
                EjbObjectInputStream.reloadResolverConfig();
            }
            try {
                instance = new RemoteTomEEEJBContainer();
                instance.container = new RemoteServer();
                instance.container.setDebug("true".equalsIgnoreCase(String.valueOf(properties.get("debug"))));
                instance.container.setPortStartup(Integer.parseInt(parser.http()));

                try {
                    instance.container.start(Arrays.asList(
                        "-Dtomee.serialization.class.blacklist=" + System.getProperty("tomee.serialization.class.blacklist"),
                        "-Dopenejb.system.apps=true", "-Dtomee.remote.support=true"),
                        "start", true);
                } catch (final Exception e) {
                    instance.container.destroy();
                    throw e;
                }

                instance.context = new InitialContext(new Properties() {{
                    setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
                    setProperty(Context.PROVIDER_URL, String.valueOf(properties.containsKey(Context.PROVIDER_URL) ? properties.get(Context.PROVIDER_URL) : remoteEjb));
                }});

                Deployer deployer = null;
                for (int i = 0; i < (properties.containsKey("retries") ? Integer.parseInt(String.class.cast(properties.get("retries"))) : 4); i++) {
                    try {
                        deployer = Deployer.class.cast(instance.context.lookup("openejb/DeployerBusinessRemote"));
                        if (deployer != null) {
                            break;
                        }
                    } catch (final NamingException ne) {
                        try {
                            sleep(250);
                        } catch (final InterruptedException ie) {
                            Thread.interrupted();
                            break;
                        }
                    }
                }
                if (deployer == null) {
                    throw new TomEERemoteEJBContainerException("Can't lookup deployer, eother increse retries or setup it correctly", new IllegalStateException());
                }

                if (modules instanceof File) {
                    final File file = File.class.cast(modules);
                    deployFile(deployer, file);
                } else if (modules instanceof String) {
                    final String path = String.class.cast(modules);
                    final File file = new File(path);
                    deployFile(deployer, file);
                } else if (modules instanceof String[]) {
                    for (final String path : (String[]) modules) {
                        deployFile(deployer, new File(path));
                    }
                } else if (modules instanceof File[]) {
                    for (final File file : (File[]) modules) {
                        deployFile(deployer, file);
                    }
                } // else suppose already deployed

                return instance;
            } catch (final OpenEJBException | MalformedURLException e) {
                throw new EJBException(e);
            } catch (final ValidationException ve) {
                throw ve;
            } catch (final Exception e) {
                if (e instanceof EJBException) {
                    throw (EJBException) e;
                }
                throw new TomEERemoteEJBContainerException("initialization exception", e);
            } finally {
                if (blacklist == null) {
                    System.clearProperty("tomee.serialization.class.blacklist");
                    EjbObjectInputStream.reloadResolverConfig();
                }
            }
        }