Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   *
  *   http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
  */
 
 package org.apache.tuscany.sca.node.impl;
 
 import java.util.List;
 
 
An SCA Node that is managed by the NodeManager
 
 public class NodeImpl implements Node {
     private static final Logger logger = Logger.getLogger(NodeImpl.class.getName());
     private ProxyFactory proxyFactory;
     private Composite domainComposite;
     private NodeConfiguration configuration;
     private NodeFactoryImpl nodeFactory;
     private List<Contributioncontributions;
     // private NodeManager mbean;
 
    
Create a node from the configuration

Parameters:
manager
configuration
 
     public NodeImpl(NodeFactoryImpl nodeFactoryNodeConfiguration configuration) {
         super();
         this. = configuration;
         this. = nodeFactory;
     }
    
    
Create a node from the configuration and loaded contributions

Parameters:
manager
configuration
contributions
 
     public NodeImpl(NodeFactoryImpl managerNodeConfiguration configurationList<Contributioncontributions) {
         super();
         this. = configuration;
         this. = manager;
         this. = new ArrayList<Contribution>(contributions);
     }
 
     public String getURI() {
        return getConfiguration().getURI();
    }
    public Node start() {
        .log(."Starting node: " + .getURI() + " domain: " + .getDomainURI());
        .init();
        .addNode(this);
        this. = .;
        
        DomainRegistryFactory domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(.);
        EndpointRegistry endpointRegistry =
            domainRegistryFactory.getEndpointRegistry(.getDomainRegistryURI(), 
                .getDomainURI());
        
        this. = utilities.getUtility(CompositeActivator.class);
        try {
            Monitor monitor = ..createMonitor();
            ProcessorContext context = new ProcessorContext(monitor);
            
            // Set up the thead context monitor
            Monitor tcm = ..setContextMonitor(monitor);
            try {
                if ( == null) {
                     = .loadContributions(context);
                }
                 = .configureNode(context);
                this. =
                    new CompositeContext(.
                                         endpointRegistry
                                         
                                         .getDomainURI(), 
                                         .getURI(),
                                         .getDeployer().getSystemDefinitions());
                
            } finally {
                // Reset the thread context monitor
                ..setContextMonitor(tcm);
            }
            
            // Activate the composite
            // Start the composite
            // FIXME: [rfeng] We should turn the management capability into a system utility.
            // In certain environment such as Google App Engine, the JMX API is not allowed
            try {
                /*
                MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
                mbean = new NodeManager(this);
                mBeanServer.registerMBean(mbean, mbean.getName());
                */
                /*
                LocateRegistry.createRegistry(9999);
                JMXServiceURL url =
                    new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/server");
                JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mBeanServer);
                connectorServer.start();
                */
            } catch (Throwable e) {
                // Ignore the error for now
                // mbean = null;
                .log(.e.getMessage(), e);
            }
            return this;
        } catch (Throwable e) {
            throw new IllegalStateException(e);
        }
    }
    public void stop() {
        .log(."Stopping node: " + .getURI());
        try {
            if ( == null) {
                return;
            }
            /*
            if (mbean != null) {
                try {
                    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
                    mBeanServer.unregisterMBean(mbean.getName());
                } catch (Throwable e) {
                    logger.log(Level.SEVERE, e.getMessage(), e);
                } finally {
                    mbean = null;
                }
            }
            */
            if != null ) {
                // Stop the composite
                .stop();
                // Deactivate the composite
                .deactivate();
            } // end if
            .removeNode();
            this. = null;
            this. = null;
            this. = null;
            this. = null;
            
            ThreadMessageContext.removeMessageContext();
        } catch (ActivationException e) {
            throw new IllegalStateException(e);
        }
    }
    @SuppressWarnings("unchecked")
    public <B, R extends ServiceReference<B>> R cast(B targetthrows IllegalArgumentException {
        return (R).cast(target);
    }
    public <B> B getService(Class<B> businessInterfaceString serviceName) {
        ServiceReference<B> serviceReference = getServiceReference(businessInterfaceserviceName);
        if (serviceReference == null) {
            throw new ServiceRuntimeException("Service not found: " + serviceName);
        }
        return serviceReference.getService();
    }
    public <B> ServiceReference<B> getServiceReference(Class<B> businessInterfaceString name) {
        // Extract the component name
        String componentName;
        String serviceName;
        int i = name.indexOf('/');
        if (i != -1) {
            componentName = name.substring(0, i);
            serviceName = name.substring(i + 1);
        } else {
            componentName = name;
            serviceName = null;
        }
        // Lookup the component
        Component component = null;
        for (Component compositeComponent : .getComponents()) {
            if (compositeComponent.getName().equals(componentName)) {
                component = compositeComponent;
                break;
            }
        }
        if (component == null) {
            throw new ServiceUnavailableException("The service " + name + " has not been contributed to the domain");
        }
        RuntimeComponentContext componentContext = null;
        // If the component is a composite, then we need to find the
        // non-composite component that provides the requested service
        if (component.getImplementation() instanceof Composite) {
            for (ComponentService componentService : component.getServices()) {
                String bindingName = null;
                if (serviceName != null) {
                    int index = serviceName.indexOf('/');
                    if (index != -1) {
                        bindingName = serviceName.substring(index + 1);
                        serviceName = serviceName.substring(0, index);
                    }
                }
                if (serviceName == null || serviceName.equals(componentService.getName())) {
                    CompositeService compositeService = (CompositeService)componentService.getService();
                    if (compositeService != null) {
                        componentContext =
                            ((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
                        serviceName = compositeService.getPromotedService().getName();
                        if (bindingName != null) {
                            serviceName = serviceName + "/" + bindingName;
                        }
                        return componentContext.createSelfReference(businessInterfaceserviceName);
                    }
                    break;
                }
            }
            // No matching service found
            throw new ServiceRuntimeException("Composite service not found: " + name);
        } else {
            componentContext = ((RuntimeComponent)component).getComponentContext();
            if (serviceName != null) {
                return componentContext.createSelfReference(businessInterfaceserviceName);
            } else {
                return componentContext.createSelfReference(businessInterface);
            }
        }
    }
        return ;
    }
        return .getExtensionPointRegistry();
    }

    
Get the service endpoints in this Node TODO: needs review, works for the very simple testcase but i expect there are other endpoints to be included
    public List<EndpointgetServiceEndpoints() {
        List<Endpointendpoints = new ArrayList<Endpoint>();
        if ( != null) {
            if ( != null) {
                for (Component component : .getComponents()) {
                    for (Service service : component.getServices()) {
                           // MJE 28/05/2009 - changed to RuntimeComponentService from RuntimeComponentServiceImpl
                           // - no need to access the Impl directly here
                        if (service instanceof RuntimeComponentService) {
                            endpoints.addAll(((RuntimeComponentService)service).getEndpoints());
                        }
                    }
                }
            }
        }
        return endpoints;
    }
    
    public Composite getDomainComposite() {
        return ;
    }   
    
    public String dumpDomainComposite() {
        
        StAXArtifactProcessorExtensionPoint xmlProcessors = 
        StAXArtifactProcessor<Composite>  compositeProcessor = 
            xmlProcessors.getProcessor(Composite.class);   
     
        return writeComposite(getDomainComposite(), compositeProcessor);
    }
       
    private String writeComposite(Composite compositeStAXArtifactProcessor<CompositecompositeProcessor){
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        XMLOutputFactory outputFactory =
                .getFactory(XMLOutputFactory.class);
        
        try {
            compositeProcessor.write(compositeoutputFactory.createXMLStreamWriter(bos), new ProcessorContext(.));
        } catch(Exception ex) {
            return ex.toString();
        }
        
        String result = bos.toString();
        
        // write out and nested composites
        for (Component component : composite.getComponents()) {
            if (component.getImplementation() instanceof Composite) {
                result +=
                    "\n<!-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -->\n" + writeComposite((Composite)component
                                                                                                          .getImplementation(),
                                                                                                      compositeProcessor);
            }
        }
        
        return result;
    }
    
    public List<ContributiongetContributions() {
        return ;
    }
New to GrepCode? Check out our FAQ X