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 stop()
      throws NodeException {
        try {
            nodeRuntime.stop();
        } catch(Exception ex) {
            throw new NodeException(ex);
        }
    }
View Full Code Here

                NodeFactoryImpl nodeFactory = new NodeFactoryImpl(this);
                factories.addFactory(nodeFactory);   
            }
        } catch(Exception ex) {
            throw new NodeException(ex);
        }
    }
View Full Code Here

    public void stop() throws NodeException {
        try {
            // remove contributions
            removeAllContributions();          
        } catch (Exception ex) {
            throw new NodeException(ex);
        }
    }   
View Full Code Here

               
            } else {
                    throw new ActivationException("Contribution " + contributionURL + " not found");
           
        } catch (Exception ex) {
            throw new NodeException(ex);
        }       
    }
View Full Code Here

            for (String contributionURI : contributions.keySet()){
                nodeRuntime.getContributionService().remove(contributionURI);
                contributions.remove(contributionURI);
            }
        } catch (Exception ex) {
            throw new NodeException(ex);
        }  
    }
View Full Code Here

                    }
                }
            }

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

    private void stopComposites() throws NodeException {
       
        try {
            if (compositesToStart.size() == 0 ){
                throw new NodeException("Stopping node " +
                                        nodeURI +
                                        " with no composite started");
            }
            for (QName compositeName : compositesToStart) {
                logger.log(Level.INFO, "Stopping composite: " + compositeName);
               
                Composite composite = composites.get(compositeName);  

                nodeRuntime.getCompositeActivator().stop(composite);
                nodeRuntime.getCompositeActivator().deactivate(composite);
               
                composites.remove(compositeName);              
            }
           
            compositesToStart.clear();
        } catch (NodeException ex) {
        throw ex;           
           
        } 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.