zoukankan      html  css  js  c++  java
  • Shows how to create and run composites dynamically

    tuscany-domain-node/DynamicTestCase.java
    /**
    * Shows how to create and run composites dynamically */ public class DynamicTestCase { @Test public void testInstalledContribution() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException, MalformedURLException, ClassNotFoundException, IntrospectionException, IllegalArgumentException, InvocationTargetException, IllegalAccessException { // get the various factories that will be needed TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance(); ExtensionPointRegistry extensionPoints = tuscanyRuntime.getExtensionPointRegistry(); FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); // Create a contribution ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class); Contribution contribution = contributionFactory.createContribution(); contribution.setURI("testContribution"); ModelResolverExtensionPoint modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories); contribution.setModelResolver(modelResolver); contribution.setClassLoader(new URLClassLoader(new URL[] {new File("src/test/resources/sample-helloworld.jar").toURI().toURL()})); // Create a composite AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); Composite composite = assemblyFactory.createComposite(); composite.setURI("testComposite"); composite.setName(new QName("testComposite")); // create a component Component component = assemblyFactory.createComponent(); component.setName("testComponent"); JavaImplementationFactory javaImplementationFactory = modelFactories.getFactory(JavaImplementationFactory.class); JavaImplementation javaImplementation = javaImplementationFactory.createJavaImplementation(contribution.getClassLoader().loadClass("sample.HelloworldImpl")); javaImplementation.setJavaClass(contribution.getClassLoader().loadClass("sample.HelloworldImpl")); component.setImplementation(javaImplementation); // add the component to the composite composite.getComponents().add(component); // add the composite to the contribution contribution.addComposite(composite); // Now run the composite with a Tuscany Node Node node = tuscanyRuntime.createNode(); node.installContribution(contribution, null); node.startComposite(contribution.getURI(), composite.getURI()); // test that the service has started and can be invoked testService(node, contribution.getClassLoader()); node.stop(); tuscanyRuntime.stop(); } private void testService(Node node, ClassLoader classLoader) throws ClassNotFoundException, NoSuchServiceException, NoSuchDomainException, IllegalArgumentException, InvocationTargetException, IllegalAccessException { Class<?> interfaze = classLoader.loadClass("sample.Helloworld"); Object clientProxy = node.getService(interfaze, "testComponent/Helloworld"); Method m = interfaze.getMethods()[0]; // the helloworld interface just has a single method "sayHello" Object response = m.invoke(clientProxy, new Object[] {"Ariana"}); Assert.assertEquals("Hello Ariana", response); } }
  • 相关阅读:
    linux服务器网络配置
    全面了解linux服务器
    centos selinux学习记录
    centos7使用samba共享文件
    centos7修改yum下载源为阿里源
    ubuntu14.04使用samba共享文件
    计算两个经纬度之间的距离(python算法)
    awk中的冒泡排序
    linux awk时间计算脚本
    linux shell中FS、OFS、RS、ORS图解
  • 原文地址:https://www.cnblogs.com/feiling/p/2782026.html
Copyright © 2011-2022 走看看