Package org.rioproject.deploy

Examples of org.rioproject.deploy.ServiceBeanInstantiationException


        }
        if(abortThrowable != null) {
            for(PlatformCapability pCap : installedPlatformCapabilities) {
                pCap.decrementUsage();
            }
            ServiceBeanInstantiationException toThrow;
            if(abortThrowable instanceof ServiceBeanInstantiationException) {
                toThrow = (ServiceBeanInstantiationException) abortThrowable;
            } else {
                toThrow = new ServiceBeanInstantiationException(String.format("ServiceBean [%s] instantiation failed",
                                                                              ServiceLogUtil.logName(sElem)),
                                                                abortThrowable,
                                                                true);
            }
            stagedDataManager.removeInstalledPlatformCapabilities();
View Full Code Here


    public ServiceBeanInstance instantiate(final ServiceElement sElem,
                                           final OperationalStringManager opStringMgr)
        throws ServiceBeanInstantiationException {
        logger.info("Instantiating {}, service counter={}", sElem.getName(), container.getServiceCounter());
        if (container.getServiceCounter() > 0)
            throw new ServiceBeanInstantiationException("ServiceBeanExecutor has already instantiated a service");

        OperationalStringManager opMgr = opStringMgr;
        try {
            opMgr = OpStringManagerProxy.getProxy(sElem.getOperationalStringName(),
                                                  opStringMgr,
View Full Code Here

            started = true;
            /* notification to shutdown may have come in the middle of
             * service creation, if it did, terminate */
            if(shutdownSequence.get()) {
                delegate.terminate();
                throw new ServiceBeanInstantiationException("Resource unavailable, shutting down");
            }
            if(sElem.getAutoAdvertise()) {
                delegate.advertise();
            }

        } catch(ServiceBeanInstantiationException e) {
            if(started) {
                discarded(identifier);
                delegate.terminate();
            }
            /* rethrow ServiceBeanInstantiationException */
            throw e;
        } catch(Throwable t) {
            if(started) {
                discarded(identifier);
                delegate.terminate();
            }
            logger.error("Could not activate service {}", ServiceLogUtil.logName(sElem), t);
            throw new ServiceBeanInstantiationException(String.format("Service %s load failed", ServiceLogUtil.logName(sElem)),
                                                        t, true);
        } finally {
            activationInProcessCount.decrementAndGet();
        }
        return (loadedInstance);
View Full Code Here

                } else {
                    exports = dlPR.getJars();
                }
                implJARs = implPR.getJars();
            } catch(Exception e) {
                throw new ServiceBeanInstantiationException("Unable to provision JARs for " +
                                                            "service "+ ServiceLogUtil.logName(sElem), e);
            }
        }

        final Thread currentThread = Thread.currentThread();
        ClassLoader currentClassLoader = currentThread.getContextClassLoader();
        Uuid serviceIDToUse = serviceID;
        try {
            ClassBundle jsbBundle = sElem.getComponentBundle();
            List<URL> urlList = new ArrayList<URL>();
            /*
            URL[] implJARs;
            if(jsbBundle!=null && jsbBundle.getCodebase()!=null)
                implJARs = jsbBundle.getJARs();
            else
                implJARs = new URL[0];
            */
            urlList.addAll(Arrays.asList(implJARs));

            /* Get matched PlatformCapability jars to load */
            PlatformCapability[] pCaps = computeResource.getPlatformCapabilities();
            PlatformCapability[] matched = ServiceElementUtil.getMatchedPlatformCapabilities(sElem, pCaps);
            for (PlatformCapability pCap : matched) {
                URL[] urls = PlatformCapabilityLoader.getLoadableClassPath(pCap);
                for(URL url : urls) {
                    if(!urlList.contains(url))
                        urlList.add(url);
                }
            }

            URL[] classpath = urlList.toArray(new URL[urlList.size()]);
            Properties metaData = new Properties();
            metaData.setProperty("opStringName", sElem.getOperationalStringName());
            metaData.setProperty("serviceName", sElem.getName());
            ServiceClassLoader jsbCL = new ServiceClassLoader(ServiceClassLoader.getURIs(classpath),
                                                              new ClassAnnotator(exports),
                                                              commonCL,
                                                              metaData);

            /*
            ServiceClassLoader jsbCL =
                new ServiceClassLoader(classpath, annotator, commonCL);
                */
            currentThread.setContextClassLoader(jsbCL);
            if(logger.isDebugEnabled()) {
                StringBuilder buffer = new StringBuilder();
                if(implJARs.length==0) {
                    buffer.append("<empty>");
                } else {
                    for(int i=0; i<implJARs.length; i++) {
                        if(i>0)
                            buffer.append(", ");
                        buffer.append(implJARs[i].toExternalForm());
                    }
                }
                String className = (jsbBundle==null?"<not defined>": jsbBundle.getClassName());
                if(logger.isDebugEnabled()) {
                    logger.debug("Create ServiceClassLoader for {}, classpath {}, codebase {}",
                                 className, buffer.toString(), jsbCL.getClassAnnotation());
                }
            }

            /* Get the servicePolicyFile from the environment. If the
             * property has not been set use the policy set for the VM */
            String servicePolicyFile = System.getProperty("rio.service.security.policy",
                                                          System.getProperty("java.security.policy"));
            if(logger.isTraceEnabled()) {
                logger.trace("{} Service security policy file {}",
                             ServiceLogUtil.logName(sElem), servicePolicyFile);
            }
            if(servicePolicyFile!=null) {
                if(logger.isTraceEnabled()) {
                    logger.trace("Set {} service security to LoaderSplitPolicyProvider", ServiceLogUtil.logName(sElem));
                }
                DynamicPolicyProvider service_policy = new DynamicPolicyProvider(new PolicyFileProvider(servicePolicyFile));
                LoaderSplitPolicyProvider splitServicePolicy = new LoaderSplitPolicyProvider(jsbCL,
                                                                                             service_policy,
                                                                                             new DynamicPolicyProvider(initialGlobalPolicy));
                globalPolicy.setPolicy(jsbCL, splitServicePolicy);
            }

            /* Reload the shared configuration using the service's classloader */
            //String[] configFiles = container.getSharedConfigurationFiles().toArray(new String[sharedConfigurationFiles.size()]);
            Configuration sharedConfiguration = container.getSharedConfiguration();

            /* Get the ServiceBeanContextFactory */
            ServiceBeanContextFactory serviceBeanContextFactory =
                (ServiceBeanContextFactory)Config.getNonNullEntry(sharedConfiguration,
                                                                  CONFIG_COMPONENT,
                                                                  "serviceBeanContextFactory",
                                                                  ServiceBeanContextFactory.class,
                                                                  new ServiceContextFactory());
            /* Create the ServiceBeanContext */
            context = serviceBeanContextFactory.create(sElem,
                                                       jsbManager,
                                                       computeResource,
                                                       sharedConfiguration);
            /* Add a temporary startup value, used to check when issuing
             * lifecycle notification (RIO-141) */
            Map<String, Object> configParms = context.getServiceBeanConfig().getConfigurationParameters();
            configParms.put(Constants.STARTING, true);
            context.getServiceBeanConfig().setConfigurationParameters(configParms);
           
            /*
             * Initialize any configured Logger instances. If there are any
             * exceptions loading the configurations, log the appropriate
             * message and continue
             */
            LoggerConfig[] loggerConfigs = context.getServiceBeanConfig().getLoggerConfigs();
            if(loggerConfigs != null) {
                for (LoggerConfig loggerConfig : loggerConfigs) {
                    try {
                        loggerConfig.getLogger();
                    } catch (Throwable t) {
                        logger.warn("Loading LoggerConfig", t);
                    }
                }
            }
           
            /* Get the ServiceBeanFactory */
            ServiceBeanFactory serviceBeanFactory =
                (ServiceBeanFactory)Config.getNonNullEntry(context.getConfiguration(),
                                                           CONFIG_COMPONENT,
                                                           "serviceBeanFactory",
                                                           ServiceBeanFactory.class,
                                                           new DefaultServiceBeanFactory());
            if(logger.isTraceEnabled()) {
                logger.trace("service = {}, serviceBeanFactory = {}",
                             ServiceLogUtil.logName(sElem), serviceBeanFactory);
            }
            created = serviceBeanFactory.create(context);
            logger.trace("Created ServiceBeanFactory.Created {}", created);
            Object impl = created.getImpl();
            logger.trace("Obtained implementation {}", impl);
           
            if(context.getServiceElement().getComponentBundle()==null) {
                String compName = impl.getClass().getName();
                if(compName.indexOf(".")>0) {
                    int index = compName.lastIndexOf(".");
                    compName = compName.substring(0, index);
                }
                context.getServiceBeanConfig().addInitParameter(ServiceBeanActivation.BOOT_CONFIG_COMPONENT, compName);
            }

            /* Get the ProxyPreparer */
            if(logger.isTraceEnabled()) {
                logger.trace("Get the ProxyPreparer for {}", ServiceLogUtil.logName(sElem));
            }
           
            ProxyPreparer servicePreparer = (ProxyPreparer)Config.getNonNullEntry(context.getConfiguration(),
                                                                                  CONFIG_COMPONENT,
                                                                                  "servicePreparer",
                                                                                  ProxyPreparer.class,
                                                                                  new BasicProxyPreparer());
            if(logger.isTraceEnabled()) {
                logger.trace("Getting the proxy");
            }
            Object proxy = created.getProxy();
            if(logger.isTraceEnabled()) {
                logger.trace("Obtained the proxy %s", proxy);
            }
            if(proxy != null) {
                proxy = servicePreparer.prepareProxy(proxy);
            }
            if(logger.isTraceEnabled()) {
                logger.trace("Proxy {}, prepared? {}", proxy, (proxy==null?"not prepared, returned proxy was null": "yes"));
            }
            /*
             * Set the MarshalledInstance into the ServiceBeanManager
             */
            if(logger.isTraceEnabled()) {
                logger.trace("Set the MarshalledInstance into the ServiceBeanManager");
            }
            marshalledProxy = new MarshalledInstance(proxy);
            ((DefaultServiceBeanManager)context.getServiceBeanManager()).setMarshalledInstance(marshalledProxy);
            /*
             * The service may have created it's own serviceID
             */
            if(proxy instanceof ReferentUuid) {
                serviceIDToUse = ((ReferentUuid)proxy).getReferentUuid();
                if(logger.isDebugEnabled()) {
                    logger.debug("Service has provided Uuid: {}", serviceIDToUse);
                }
                ((DefaultServiceBeanManager)context.getServiceBeanManager()).setServiceID(serviceIDToUse);
            }
           
            /*
             * If the proxy is Administrable and an instanceof
             * ServiceBeanControl, set the ServiceBeanControl in the
             * DefaultAssociationManagement object
             */
            if(proxy instanceof Administrable) {
                Object adminObject = ((Administrable)proxy).getAdmin();              
                if(adminObject instanceof ServiceBeanControl) {
                    context.getAssociationManagement().setServiceBeanControl((ServiceBeanControl)adminObject);
                }                   
            }
            if(logger.isTraceEnabled()) {
                logger.trace("Proxy =  {}", proxy);
            }
        } catch(Exception e) {
            ServiceBeanInstantiationException sbe;
            if(logger.isTraceEnabled()) {
                logger.trace("Loading ServiceBean", e);
            }
            if(e instanceof ServiceBeanInstantiationException)
                sbe = (ServiceBeanInstantiationException)e;
            else
                sbe = new ServiceBeanInstantiationException(e.getClass().getName()+ ": "+ e.getLocalizedMessage(), e);
            throw sbe;
        } finally {               
            currentThread.setContextClassLoader(currentClassLoader);
        }
        return(new ServiceBeanLoaderResult(context, created.getImpl(), created.getBeanAdapter(), marshalledProxy, serviceIDToUse));
View Full Code Here

            implPR = new ProvisionedResources(implArtifact);
            if(elem.getComponentBundle()!=null) {
                if(System.getProperty("StaticCybernode")==null) {
                    if(elem.getComponentBundle().getArtifact()!=null && resolver!=null) {
                        if(!supportsInstallation)
                            throw new ServiceBeanInstantiationException("Service ["+elem.getName()+"] " +
                                                                        "cannot be instantiated, the Cybernode " +
                                                                        "does not support persistent provisioning, " +
                                                                        "and the service requires artifact resolution " +
                                                                        "for "+implArtifact);
                        URL[] jars;
                        try {
                            StringBuilder builder = new StringBuilder();
                            for(RemoteRepository repository: elem.getRemoteRepositories()) {
                                if(builder.length()>0){
                                    builder.append(", ");
                                }
                                builder.append(repository.getUrl());
                            }
                            if(logger.isInfoEnabled()) {
                                logger.info("Resolve {} using these repositories [{}]",
                                            elem.getComponentBundle().getArtifact(), builder.toString());
                            }
                            jars = ResolverHelper.resolve(elem.getComponentBundle().getArtifact(),
                                                          resolver,
                                                          elem.getRemoteRepositories());
                        } catch (ResolverException e) {
                            Throwable thrown = e;
                            if(e.getCause()!=null)
                                thrown = e.getCause();
                            throw new ServiceBeanInstantiationException("Could not resolve implementation artifact", thrown);
                        }
                        implJARs = jars;
                    } else {
                        /* RIO-228 */
                        if(System.getProperty("StaticCybernode")!=null)
View Full Code Here

TOP

Related Classes of org.rioproject.deploy.ServiceBeanInstantiationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.