Package org.apache.tuscany.sca.node

Examples of org.apache.tuscany.sca.node.NodeException


                    stopComposite(composite);
                }
            }
                           
        } catch (Exception ex) {
            throw new NodeException(ex);
        }             
    }
View Full Code Here


        // find the composite that will be updated
        Composite composite = composites.get(compositeQName);
       
        if (composite == null) {
            throw new NodeException("trying to update composite " + compositeQName.toString() +
                                    " which can't be found in node " + nodeURI);
        }
       
        // parse the XML into an composite object
        Composite newComposite = null;
       
        ExtensionPointRegistry registry = nodeRuntime.getExtensionPointRegistry();
        StAXArtifactProcessorExtensionPoint staxProcessors =
            registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
       
        StAXArtifactProcessor<Composite> processor = staxProcessors.getProcessor(Composite.class);
             
        try {
            XMLInputFactory inputFactory = XMLInputFactory.newInstance();
            XMLStreamReader reader = inputFactory.createXMLStreamReader(bais);
            newComposite = processor.read(reader);
            reader.close();
        } catch (Exception ex) {
            throw new NodeException(ex);
        }      

       
        // for each component in the composite compare it against the live component
        for (Component newComponent : newComposite.getComponents()){
            for (Component component : composite.getComponents()){        
                if (component.getName().equals(newComponent.getName())){
                    // compare the component references
                    for (Reference newReference : newComponent.getReferences()){
                        for (Reference reference : component.getReferences()) {          
                            if (reference.getName().equals(newReference.getName())) {
                                boolean referenceChanged = false;
                                List<Binding> removeCandidates = new ArrayList<Binding>();
                                List<Binding> addCandidates = new ArrayList<Binding>();
                               
                                removeCandidates.addAll(reference.getBindings());
                               
                                for (Binding newBinding : newReference.getBindings()){
                                    boolean bindingFound = false;
                                    for (Binding binding : reference.getBindings()){
                                        // find the matching target service binding      
                                        if (binding.getName().equals(newBinding.getName())){
                                            if ((binding.getURI() != null) &&
                                                (newBinding.getURI() != null) &&
                                                !binding.getURI().equals(newBinding.getURI())){
                                                binding.setURI(newBinding.getURI());
                                                referenceChanged = true;
                                               
                                                logger.log(Level.INFO, "Updating binding " +
                                                                       component.getName() +
                                                                       " reference " +
                                                                       reference.getName() +
                                                                       " binding " +
                                                                       binding.getClass().getName() +
                                                                       " URI " +
                                                                       binding.getURI());
                                            }
                                            bindingFound = true;
                                            removeCandidates.remove(binding);
                                        }
                                    }
                                   
                                    if (bindingFound == false){
                                        addCandidates.add(newBinding);
                                    }

                                }
                               
                                for (Binding addBinding : addCandidates){
                                    reference.getBindings().add(addBinding);
                                    referenceChanged = true;
                                    logger.log(Level.INFO, "Adding binding " +
                                            component.getName() +
                                            " reference " +
                                            reference.getName() +
                                            " binding " +
                                            addBinding.getClass().getName() +
                                            " URI " +
                                            addBinding.getURI());                                       
                                }
                               
                                // remove all of the old bindings
                                for (Binding removeBinding : removeCandidates){
                                    reference.getBindings().remove(removeBinding);
                                    referenceChanged = true;
                                    logger.log(Level.INFO, "Removing binding " +
                                            component.getName() +
                                            " reference " +
                                            reference.getName() +
                                            " binding " +
                                            removeBinding.getClass().getName() +
                                            " URI " +
                                            removeBinding.getURI());
                                }
                               
                                // if the node is running restart the reference and the component that holds it
                                if (referenceChanged && nodeStarted){
                                    try {
                                        nodeRuntime.getCompositeActivator().stop((RuntimeComponent)component);
                                        nodeRuntime.getCompositeActivator().deactivate((RuntimeComponent)component,
                                                (RuntimeComponentReference)reference);
                                        nodeRuntime.getCompositeActivator().start((RuntimeComponent)component,
                                                (RuntimeComponentReference)reference);
                                        nodeRuntime.getCompositeActivator().start((RuntimeComponent)component);
                                      
                                    } catch (Exception ex) {
                                        throw new NodeException(ex);
                                    }
                                   
                                }                               
                            }
                        }
View Full Code Here

   
    public void destroy() throws NodeException {
        try {
            nodeRuntime.stop();
        } catch(Exception ex) {
            throw new NodeException(ex);
        }
    }
View Full Code Here

            // check whether node uri is an absolute url, 
            try {
                URI tmpURI = new URI(nodeURI);
                nodeURL = tmpURI.toURL();
            } catch(Exception ex) {
                throw new NodeException("node uri " +
                                        nodeURI +
                                        " must be a valid url");
            }
           
            // create a node runtime for the domain contributions to run on
            nodeRuntime = new ReallySmallRuntime(nodeClassLoader);
            nodeRuntime.start();
           
            // get the domain builder
            domainBuilder = nodeRuntime.getDomainBuilder();           
           
            // configure the default port and path for this runtime
            int port = URI.create(nodeURI).getPort();
            String path = nodeURL.getPath();
            ServletHostExtensionPoint servletHosts = nodeRuntime.getExtensionPointRegistry().getExtensionPoint(ServletHostExtensionPoint.class);
            for (ServletHost servletHost: servletHosts.getServletHosts()) {
                servletHost.setDefaultPort(port);
                if (path != null && path.length() > 0 && !path.equals("/")) {
                    servletHost.setContextPath(path);
                }
            }           
           
            // make the node available to the model
            // this causes the runtime to start registering binding-sca service endpoints
            // with the domain proxy
            // TODO - This code is due to be pulled out and combined with the register and
            //       resolution code that appears in this class
            ModelFactoryExtensionPoint factories = nodeRuntime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class);
            nodeFactory = new NodeFactoryImpl(this);
            factories.addFactory(nodeFactory);
           
            // Create an in-memory domain level composite
            AssemblyFactory assemblyFactory = nodeRuntime.getAssemblyFactory();
            nodeComposite = assemblyFactory.createComposite();
            nodeComposite.setName(new QName(Constants.SCA10_NS, "node"));
            nodeComposite.setURI(nodeURI);
           
            // add the top level composite into the composite activator
            nodeRuntime.getCompositeActivator().setDomainComposite(nodeComposite);            
           
            // create a link to the domain
            scaDomain = new SCADomainProxyImpl(domainURI, nodeClassLoader);
           
            // add the node URI to the domain
            scaDomain.addNode(this)
           
        } catch(NodeException ex) {
            throw ex;
        } catch(Exception ex) {
            throw new NodeException(ex);
        }
    }
View Full Code Here

   
   
    public void addContributionFromDomain(String contributionURI, URL contributionURL, ClassLoader contributionClassLoader ) throws NodeException {
       
        if (nodeStarted){
            throw new NodeException("Can't add contribution " + contributionURI + " when the node is running. Call stop() on the node first");
        }
      
        if (contributionURI == null){
            throw new NodeException("Contribution URI cannot be null");
        }
       
        if (contributionURL == null){
            throw new NodeException("Contribution URL cannot be null");
        }
       
        if (contributions.containsKey(contributionURI)) {
            throw new NodeException("Contribution " + contributionURI + " has already been added");
        }
       
        try {         

          //FIXME What to do when a contribution uses a separate class loader ? (e.g contributionClassLoader != null)
           
            // Add the contribution to the node
            ContributionService contributionService = nodeRuntime.getContributionService();
            Contribution contribution = contributionService.contribute(contributionURI,
                                                                       contributionURL,
                                                                       false);
           
            // remember the contribution
            contributions.put(contributionURI, contribution);
               
            // remember all the composites that have been found
            for (Artifact artifact : contribution.getArtifacts()) {
                if (artifact.getModel() instanceof Composite) {
                    Composite composite = (Composite)artifact.getModel();
                    composites.put(composite.getName(), composite);
                    compositeFiles.put(composite.getURI(), composite);
                }
            }
                   
        } catch (Exception ex) {
            throw new NodeException(ex);
        }       
    }  
View Full Code Here

    }  
   
    public void removeContributionFromDomain(String contributionURI) throws NodeException {
       
        if (nodeStarted){
            throw new NodeException("Can't remove contribution " + contributionURI + " when the node is running. Call stop() on the node first");
        }
      
        if (contributionURI == null){
            throw new NodeException("Contribution URI cannot be null");
        }
       
        if (!contributions.containsKey(contributionURI)) {
            throw new NodeException("Contribution " + contributionURI + " has not been added");
        }       
       
        try {

            Contribution contribution = contributions.get(contributionURI);
           
            // remove the local record of composites associated with this contribution
            for (Artifact artifact : contribution.getArtifacts()) {
                if (artifact.getModel() instanceof Composite) {
                    Composite composite = (Composite)artifact.getModel();
                    composites.remove(composite.getName());
                    compositeFiles.remove(composite.getURI());
                }
            }           
       
            // remove the contribution from the contribution service
            nodeRuntime.getContributionService().remove(contributionURI);
           
            // remove any deployed composites from the node level composite
            for (Composite composite : contribution.getDeployables()) {
                if (nodeComposite.getIncludes().contains(composite)){
                    // deactivate it
                    deactivateComposite(composite);
                   
                    // remove it
                    nodeComposite.getIncludes().remove(composite);
                }
            }
           
            // remove the local record of the contribution
            contributions.remove(contributionURI);               
           
        } catch (Exception ex) {
            throw new NodeException(ex);
       
    }  
View Full Code Here

  
    public void addContribution(String contributionURI, String contributionURL) throws NodeException {
        try {
            node.addContributionFromDomain(contributionURI, new URL(contributionURL), null);
        } catch (MalformedURLException ex){
            throw new NodeException(ex);
        }           
    }
View Full Code Here

            // check whether node uri is an absolute url, 
            try {
                URI tmpURI = new URI(nodeURI);
                nodeURL = tmpURI.toURL();
            } catch(Exception ex) {
                throw new NodeException("node uri " +
                                        nodeURI +
                                        " must be a valid url");
            }
           
            // create a node runtime for the domain contributions to run on
            nodeRuntime = new ReallySmallRuntime(nodeClassLoader);
            nodeRuntime.start();
           
            // get the domain builder
            domainBuilder = nodeRuntime.getDomainBuilder();           
           
            // configure the default port and path for this runtime
            int port = URI.create(nodeURI).getPort();
            String path = nodeURL.getPath();
            ServletHostExtensionPoint servletHosts = nodeRuntime.getExtensionPointRegistry().getExtensionPoint(ServletHostExtensionPoint.class);
            for (ServletHost servletHost: servletHosts.getServletHosts()) {
                servletHost.setDefaultPort(port);
                if (path != null && path.length() > 0 && !path.equals("/")) {
                    servletHost.setContextPath(path);
                }
            }           
           
            // make the node available to the model
            // this causes the runtime to start registering binding-sca service endpoints
            // with the domain proxy
            // TODO - This code is due to be pulled out and combined with the register and
            //       resolution code that appears in this class
            ModelFactoryExtensionPoint factories = nodeRuntime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class);
            nodeFactory = new NodeFactoryImpl(this);
            factories.addFactory(nodeFactory);
           
            // Create an in-memory domain level composite
            AssemblyFactory assemblyFactory = nodeRuntime.getAssemblyFactory();
            nodeComposite = assemblyFactory.createComposite();
            nodeComposite.setName(new QName(Constants.SCA10_NS, "node"));
            nodeComposite.setURI(nodeURI);
           
            // add the top level composite into the composite activator
            nodeRuntime.getCompositeActivator().setDomainComposite(nodeComposite);            
           
            // create a link to the domain
            scaDomain = new SCADomainProxyImpl(domainURI, nodeClassLoader);
           
            // add the node URI to the domain
            scaDomain.addNode(this)
           
        } catch(NodeException ex) {
            throw ex;
        } catch(Exception ex) {
            throw new NodeException(ex);
        }
    }
View Full Code Here

   
   
    public void addContributionFromDomain(String contributionURI, URL contributionURL, ClassLoader contributionClassLoader ) throws NodeException {
       
        if (nodeStarted){
            throw new NodeException("Can't add contribution " + contributionURI + " when the node is running. Call stop() on the node first");
        }
      
        if (contributionURI == null){
            throw new NodeException("Contribution URI cannot be null");
        }
       
        if (contributionURL == null){
            throw new NodeException("Contribution URL cannot be null");
        }
       
        if (contributions.containsKey(contributionURI)) {
            throw new NodeException("Contribution " + contributionURI + " has already been added");
        }
       
        try {         
            ModelResolver modelResolver = null;
           
            // if the contribution is to be resolved using a separate class loader
            // then create a new model resolver
            if (contributionClassLoader != null)  {
                modelResolver = new ModelResolverImpl(contributionClassLoader);
            }
           
            // Add the contribution to the node
            ContributionService contributionService = nodeRuntime.getContributionService();
            Contribution contribution = contributionService.contribute(contributionURI,
                                                                       contributionURL,
                                                                       modelResolver,
                                                                       false);
           
            // remember the contribution
            contributions.put(contributionURI, contribution);
               
            // remember all the composites that have been found
            for (DeployedArtifact artifact : contribution.getArtifacts()) {
                if (artifact.getModel() instanceof Composite) {
                    Composite composite = (Composite)artifact.getModel();
                    composites.put(composite.getName(), composite);
                    compositeFiles.put(composite.getURI(), composite);
                }
            }
                   
        } catch (Exception ex) {
            throw new NodeException(ex);
        }       
    }  
View Full Code Here

    }  
   
    public void removeContributionFromDomain(String contributionURI) throws NodeException {
       
        if (nodeStarted){
            throw new NodeException("Can't remove contribution " + contributionURI + " when the node is running. Call stop() on the node first");
        }
      
        if (contributionURI == null){
            throw new NodeException("Contribution URI cannot be null");
        }
       
        if (!contributions.containsKey(contributionURI)) {
            throw new NodeException("Contribution " + contributionURI + " has not been added");
        }       
       
        try {

            Contribution contribution = contributions.get(contributionURI);
           
            // remove the local record of composites associated with this contribution
            for (DeployedArtifact artifact : contribution.getArtifacts()) {
                if (artifact.getModel() instanceof Composite) {
                    Composite composite = (Composite)artifact.getModel();
                    composites.remove(composite.getName());
                    compositeFiles.remove(composite.getURI());
                }
            }           
       
            // remove the contribution from the contribution service
            nodeRuntime.getContributionService().remove(contributionURI);
           
            // remove any deployed composites from the node level composite
            for (Composite composite : contribution.getDeployables()) {
                if (nodeComposite.getIncludes().contains(composite)){
                    // deactivate it
                    deactivateComposite(composite);
                   
                    // remove it
                    nodeComposite.getIncludes().remove(composite);
                }
            }
           
            // remove the local record of the contribution
            contributions.remove(contributionURI);               
           
        } catch (Exception ex) {
            throw new NodeException(ex);
       
    }  
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.node.NodeException

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.