Search in sources :

Example 1 with Result

use of com.sun.enterprise.util.Result in project Payara by payara.

the class AppServerStartup method postStartupJob.

/**
 * @return True if started successfully, false otherwise
 */
private boolean postStartupJob() {
    LinkedList<Future<Result<Thread>>> futures = appInstanceListener.getFutures();
    env.setStatus(ServerEnvironment.Status.starting);
    events.send(new Event(EventTypes.SERVER_STARTUP), false);
    // finally let's calculate our starting times
    long nowTime = System.currentTimeMillis();
    logger.log(Level.INFO, KernelLoggerInfo.startupEndMessage, new Object[] { Version.getVersion(), Version.getBuildVersion(), platform, (platformInitTime - context.getCreationTime()), (nowTime - platformInitTime), nowTime - context.getCreationTime() });
    printModuleStatus(systemRegistry, level);
    String wallClockStart = System.getProperty("WALL_CLOCK_START");
    if (wallClockStart != null) {
        try {
            // it will only be set when called from AsadminMain and the env. variable AS_DEBUG is set to true
            long realstart = Long.parseLong(wallClockStart);
            logger.log(Level.INFO, KernelLoggerInfo.startupTotalTime, (System.currentTimeMillis() - realstart));
        } catch (Exception e) {
        // do nothing.
        }
    }
    for (Future<Result<Thread>> future : futures) {
        try {
            try {
                // wait for an eventual status, otherwise ignore
                if (future.get(3, TimeUnit.SECONDS).isFailure()) {
                    final Throwable t = future.get().exception();
                    logger.log(Level.SEVERE, KernelLoggerInfo.startupFatalException, t);
                    shutdown();
                    return false;
                }
            } catch (TimeoutException e) {
                logger.log(Level.WARNING, KernelLoggerInfo.startupWaitTimeout, e);
            }
        } catch (Throwable t) {
            logger.log(Level.SEVERE, KernelLoggerInfo.startupException, t);
        }
    }
    env.setStatus(ServerEnvironment.Status.started);
    events.send(new Event(EventTypes.SERVER_READY), false);
    pidWriter.writePidFile();
    return true;
}
Also used : RunLevelFuture(org.glassfish.hk2.runlevel.RunLevelFuture) Future(java.util.concurrent.Future) ChangeableRunLevelFuture(org.glassfish.hk2.runlevel.ChangeableRunLevelFuture) Event(org.glassfish.api.event.EventListener.Event) InstanceLifecycleEvent(org.glassfish.hk2.api.InstanceLifecycleEvent) TimeoutException(java.util.concurrent.TimeoutException) GlassFishException(org.glassfish.embeddable.GlassFishException) Result(com.sun.enterprise.util.Result) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with Result

use of com.sun.enterprise.util.Result in project Payara by payara.

the class WebContainer method loadWebModule.

/**
 * Creates and configures a web module for each virtual server that the web module is hosted under.
 * <p/>
 * If no virtual servers have been specified, then the web module will not be loaded.
 *
 * @param webModuleConfig
 * @param j2eeApplication
 * @param deploymentProperties
 * @return
 */
public List<Result<WebModule>> loadWebModule(WebModuleConfig webModuleConfig, String j2eeApplication, Properties deploymentProperties) {
    List<Result<WebModule>> results = new ArrayList<>();
    String virtualServerIds = webModuleConfig.getVirtualServers();
    List<String> virtualServers = parseStringList(virtualServerIds, " ,");
    if (virtualServers == null || virtualServers.isEmpty()) {
        if (logger.isLoggable(INFO)) {
            logger.log(INFO, WEB_MODULE_NOT_LOADED_NO_VIRTUAL_SERVERS, webModuleConfig.getName());
        }
        return results;
    }
    logger.log(FINE, LOADING_WEB_MODULE, virtualServerIds);
    List<String> nonProcessedVirtualServers = new ArrayList<>(virtualServers);
    Container[] containers = getEngine().findChildren();
    List<VirtualServer> virtualServersToDeploy = new ArrayList<>(containers.length);
    for (Container container : containers) {
        if (container instanceof VirtualServer) {
            VirtualServer virtualServer = (VirtualServer) container;
            boolean eqVS = virtualServers.contains(virtualServer.getID());
            if (eqVS) {
                nonProcessedVirtualServers.remove(virtualServer.getID());
            }
            Set<String> matchedAliases = matchAlias(virtualServers, virtualServer);
            boolean hasMatchedAlias = matchedAliases.size() > 0;
            if (hasMatchedAlias) {
                nonProcessedVirtualServers.removeAll(matchedAliases);
            }
            if (eqVS || hasMatchedAlias) {
                virtualServersToDeploy.add(virtualServer);
            }
        }
    }
    boolean moreThanOneVirtualServer = virtualServersToDeploy.size() > 1;
    for (VirtualServer virtualServerToDeploy : virtualServersToDeploy) {
        WebModule webModule = null;
        ClassLoader appClassLoader = webModuleConfig.getAppClassLoader();
        try {
            if (moreThanOneVirtualServer) {
                WebappClassLoader virtualServerClassLoader = new WebappClassLoader(appClassLoader, webModuleConfig.getDeploymentContext().getModuleMetaData(Application.class));
                virtualServerClassLoader.start();
                // For every virtual server, JSF and other extensions expect a separate class loader
                webModuleConfig.setAppClassLoader(virtualServerClassLoader);
            }
            webModule = loadWebModule(virtualServerToDeploy, webModuleConfig, j2eeApplication, deploymentProperties);
            results.add(new Result<>(webModule));
        } catch (Throwable t) {
            if (webModule != null) {
                webModule.setAvailable(false);
            }
            results.add(new Result<>(t));
        } finally {
            if (moreThanOneVirtualServer) {
                webModuleConfig.setAppClassLoader(appClassLoader);
            }
        }
    }
    if (nonProcessedVirtualServers.size() > 0) {
        StringBuilder sb = new StringBuilder();
        boolean follow = false;
        for (String alias : nonProcessedVirtualServers) {
            if (follow) {
                sb.append(",");
            }
            sb.append(alias);
            follow = true;
        }
        logger.log(SEVERE, WEB_MODULE_NOT_LOADED_TO_VS, new Object[] { webModuleConfig.getName(), sb.toString() });
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) Result(com.sun.enterprise.util.Result) Container(org.apache.catalina.Container) WebappClassLoader(org.glassfish.web.loader.WebappClassLoader) WebappClassLoader(org.glassfish.web.loader.WebappClassLoader) Application(com.sun.enterprise.deployment.Application)

Example 3 with Result

use of com.sun.enterprise.util.Result in project Payara by payara.

the class ActiveJmsResourceAdapter method initializeLazyListener.

/**
 * Start Grizzly based JMS lazy listener, which is going to initialize
 * JMS container on first request.
 * @param jmsService
 * @throws com.sun.enterprise.connectors.jms.system.JmsInitialisationException
 */
public void initializeLazyListener(JmsService jmsService) throws JmsInitialisationException {
    if (jmsService != null && jmsService.getType().equals("DISABLED")) {
        return;
    }
    if (jmsService != null) {
        if (EMBEDDED.equalsIgnoreCase(jmsService.getType()) && !grizzlyListenerInit) {
            GrizzlyService grizzlyService = Globals.get(GrizzlyService.class);
            if (grizzlyService != null) {
                List<JmsHost> jmsHosts = jmsService.getJmsHost();
                for (JmsHost oneHost : jmsHosts) {
                    if (Boolean.valueOf(oneHost.getLazyInit()) && !doBind) {
                        String jmsHost = null;
                        if (oneHost.getHost() != null && "localhost".equals(oneHost.getHost())) {
                            jmsHost = "0.0.0.0";
                        } else {
                            jmsHost = oneHost.getHost();
                        }
                        NetworkListener dummy = new DummyNetworkListener();
                        dummy.setPort(oneHost.getPort());
                        dummy.setAddress(jmsHost);
                        dummy.setType("proxy");
                        dummy.setProtocol(JMS_SERVICE);
                        dummy.setTransport("tcp");
                        String name = GRIZZLY_PROXY_PREFIX + oneHost.getName();
                        dummy.setName(name);
                        synchronized (grizzlyListeners) {
                            Future<Result<Thread>> createNetworkProxy = grizzlyService.createNetworkProxy(dummy);
                            try {
                                Result<Thread> result = createNetworkProxy.get();
                                if (result.exception() != null) {
                                    throw new JmsInitialisationException(MessageFormat.format("Cannot initialise JMS broker listener on {0}:{1}", oneHost.getHost(), oneHost.getPort()), result.exception());
                                }
                            } catch (InterruptedException | ExecutionException ex) {
                                Logger.getLogger(ActiveJmsResourceAdapter.class.getName()).log(Level.SEVERE, null, ex);
                            }
                            grizzlyListeners.add(name);
                        }
                        grizzlyListenerInit = true;
                    }
                }
            }
        }
    }
}
Also used : DummyNetworkListener(com.sun.enterprise.v3.services.impl.DummyNetworkListener) Result(com.sun.enterprise.util.Result) GrizzlyService(com.sun.enterprise.v3.services.impl.GrizzlyService) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost) ExecutionException(java.util.concurrent.ExecutionException) DummyNetworkListener(com.sun.enterprise.v3.services.impl.DummyNetworkListener) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 4 with Result

use of com.sun.enterprise.util.Result in project Payara by payara.

the class WebApplication method start.

@Override
public boolean start(ApplicationContext appContext) throws Exception {
    webModules.clear();
    Properties props = null;
    if (appContext != null) {
        wmInfo.setAppClassLoader(appContext.getClassLoader());
        if (appContext instanceof DeploymentContext) {
            DeploymentContext deployContext = (DeploymentContext) appContext;
            wmInfo.setDeploymentContext(deployContext);
            if (isKeepState(deployContext, true)) {
                props = deployContext.getAppProps();
            }
        }
        applyApplicationConfig(appContext);
    }
    List<Result<WebModule>> results = container.loadWebModule(wmInfo, "null", props);
    // release DeploymentContext in memory
    wmInfo.setDeploymentContext(null);
    if (results.isEmpty()) {
        logger.log(Level.SEVERE, "webApplication.unknownError");
        return false;
    }
    boolean isFailure = false;
    StringBuilder sb = null;
    for (Result<WebModule> result : results) {
        if (result.isFailure()) {
            if (sb == null) {
                sb = new StringBuilder(result.exception().toString());
            } else {
                sb.append(result.exception().toString());
            }
            logger.log(Level.WARNING, result.exception().toString(), result.exception());
            isFailure = true;
        } else {
            webModules.add(result.result());
        }
    }
    if (isFailure) {
        webModules.clear();
        throw new Exception(sb.toString());
    }
    if (logger.isLoggable(Level.INFO)) {
        logger.log(Level.INFO, LogFacade.LOADING_APP, new Object[] { wmInfo.getDescriptor().getName(), wmInfo.getDescriptor().getContextRoot() });
    }
    return true;
}
Also used : ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) Result(com.sun.enterprise.util.Result)

Example 5 with Result

use of com.sun.enterprise.util.Result in project Payara by payara.

the class DomainXmlVerifier method checkDuplicate.

private void checkDuplicate(Collection<? extends Dom> beans) {
    if (beans == null || beans.size() <= 1) {
        return;
    }
    WeakHashMap keyBeanMap = new WeakHashMap();
    ArrayList<String> keys = new ArrayList<String>(beans.size());
    for (Dom b : beans) {
        String key = b.getKey();
        keyBeanMap.put(key, b);
        keys.add(key);
    }
    WeakHashMap<String, Class<ConfigBeanProxy>> errorKeyBeanMap = new WeakHashMap<String, Class<ConfigBeanProxy>>();
    String[] strKeys = keys.toArray(new String[beans.size()]);
    for (int i = 0; i < strKeys.length; i++) {
        for (int j = i + 1; j < strKeys.length; j++) {
            // we have a duplicate. So output that error
            if ((strKeys[i].equals(strKeys[j]))) {
                errorKeyBeanMap.put(strKeys[i], ((Dom) keyBeanMap.get(strKeys[i])).getProxyType());
                error = true;
                break;
            }
        }
    }
    for (Map.Entry e : errorKeyBeanMap.entrySet()) {
        Result result = new Result(STRINGS.get("VerifyDupKey", e.getKey(), e.getValue()));
        output(result);
    }
}
Also used : Dom(org.jvnet.hk2.config.Dom) ArrayList(java.util.ArrayList) Result(com.sun.enterprise.util.Result) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) WeakHashMap(java.util.WeakHashMap)

Aggregations

Result (com.sun.enterprise.util.Result)6 ArrayList (java.util.ArrayList)2 Future (java.util.concurrent.Future)2 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)1 JmsHost (com.sun.enterprise.connectors.jms.config.JmsHost)1 Application (com.sun.enterprise.deployment.Application)1 DummyNetworkListener (com.sun.enterprise.v3.services.impl.DummyNetworkListener)1 GrizzlyService (com.sun.enterprise.v3.services.impl.GrizzlyService)1 Map (java.util.Map)1 WeakHashMap (java.util.WeakHashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Container (org.apache.catalina.Container)1 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)1 Event (org.glassfish.api.event.EventListener.Event)1 DeploymentProperties (org.glassfish.deployment.common.DeploymentProperties)1 GlassFishException (org.glassfish.embeddable.GlassFishException)1 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)1 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)1 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)1