Search in sources :

Example 1 with ContainerServiceProvider

use of com.alipay.sofa.ark.container.registry.ContainerServiceProvider in project sofa-ark by alipay.

the class RegisterServiceStage method registryDefaultService.

/**
 * Registry some default service
 */
private void registryDefaultService() {
    /**
     * some basic container service is not allowed to be override,  they are only published
     * to be referenced by plugin and biz, even depended by other container service.
     */
    registryService.publishService(BizManagerService.class, ArkServiceContainerHolder.getContainer().getService(BizManagerService.class), new ContainerServiceProvider(PriorityOrdered.HIGHEST_PRECEDENCE));
    registryService.publishService(BizFactoryService.class, ArkServiceContainerHolder.getContainer().getService(BizFactoryService.class), new ContainerServiceProvider(PriorityOrdered.HIGHEST_PRECEDENCE));
    registryService.publishService(PluginManagerService.class, ArkServiceContainerHolder.getContainer().getService(PluginManagerService.class), new ContainerServiceProvider(PriorityOrdered.HIGHEST_PRECEDENCE));
    registryService.publishService(PluginFactoryService.class, ArkServiceContainerHolder.getContainer().getService(PluginFactoryService.class), new ContainerServiceProvider(PriorityOrdered.HIGHEST_PRECEDENCE));
    registryService.publishService(EventAdminService.class, ArkServiceContainerHolder.getContainer().getService(EventAdminService.class), new ContainerServiceProvider(PriorityOrdered.HIGHEST_PRECEDENCE));
    registryService.publishService(RegistryService.class, ArkServiceContainerHolder.getContainer().getService(RegistryService.class), new ContainerServiceProvider(PriorityOrdered.HIGHEST_PRECEDENCE));
    /**
     * some container service which may depends on other basic container service.
     */
    registryService.publishService(BizDeployer.class, new DefaultBizDeployer(), new ContainerServiceProvider());
    registryService.publishService(CommandProvider.class, new PluginCommandProvider(), PLUGIN_COMMAND_UNIQUE_ID, new ContainerServiceProvider());
    registryService.publishService(CommandProvider.class, new BizCommandProvider(), BIZ_COMMAND_UNIQUE_ID, new ContainerServiceProvider());
}
Also used : PluginManagerService(com.alipay.sofa.ark.spi.service.plugin.PluginManagerService) PluginFactoryService(com.alipay.sofa.ark.spi.service.plugin.PluginFactoryService) DefaultBizDeployer(com.alipay.sofa.ark.container.service.biz.DefaultBizDeployer) BizFactoryService(com.alipay.sofa.ark.spi.service.biz.BizFactoryService) EventAdminService(com.alipay.sofa.ark.spi.service.event.EventAdminService) ContainerServiceProvider(com.alipay.sofa.ark.container.registry.ContainerServiceProvider) PluginCommandProvider(com.alipay.sofa.ark.container.service.plugin.PluginCommandProvider) BizCommandProvider(com.alipay.sofa.ark.container.service.biz.BizCommandProvider) RegistryService(com.alipay.sofa.ark.spi.service.registry.RegistryService) BizManagerService(com.alipay.sofa.ark.spi.service.biz.BizManagerService)

Example 2 with ContainerServiceProvider

use of com.alipay.sofa.ark.container.registry.ContainerServiceProvider in project sofa-ark by alipay.

the class InjectionServiceTest method test.

@Test
public void test() {
    RegistryService registryService = ArkServiceContainerHolder.getContainer().getService(RegistryService.class);
    PluginMockService pluginMockService = new PluginMockService();
    registryService.publishService(PluginMockService.class, pluginMockService, new ContainerServiceProvider());
    Assert.assertNotNull(pluginMockService.getBizFactoryService());
    Assert.assertNotNull(pluginMockService.getBizManagerService());
    Assert.assertNull(pluginMockService.getClassLoaderService());
}
Also used : ContainerServiceProvider(com.alipay.sofa.ark.container.registry.ContainerServiceProvider) RegistryService(com.alipay.sofa.ark.spi.service.registry.RegistryService) BaseTest(com.alipay.sofa.ark.container.BaseTest) Test(org.junit.Test)

Example 3 with ContainerServiceProvider

use of com.alipay.sofa.ark.container.registry.ContainerServiceProvider in project sofa-ark by alipay.

the class CommandHandlerTest method test.

@Test
public void test() {
    ArkCommandHandler arkCommandHandler = new ArkCommandHandler();
    RegistryService registryService = ArkServiceContainerHolder.getContainer().getService(RegistryService.class);
    registryService.publishService(CommandProvider.class, new MockCommandProvider(), new ContainerServiceProvider());
    Assert.assertTrue(arkCommandHandler.handleCommand("any").contains("mock help"));
    Assert.assertTrue("mock command provider".equals(arkCommandHandler.handleCommand("mock")));
}
Also used : ArkCommandHandler(com.alipay.sofa.ark.container.session.handler.ArkCommandHandler) ContainerServiceProvider(com.alipay.sofa.ark.container.registry.ContainerServiceProvider) RegistryService(com.alipay.sofa.ark.spi.service.registry.RegistryService) BaseTest(com.alipay.sofa.ark.container.BaseTest) Test(org.junit.Test)

Example 4 with ContainerServiceProvider

use of com.alipay.sofa.ark.container.registry.ContainerServiceProvider in project sofa-ark by alipay.

the class ServiceRegistrationTest method testFilter.

@Test
@SuppressWarnings("unchecked")
public void testFilter() {
    final PluginModel pluginA = new PluginModel();
    pluginA.setPluginName("plugin A").setPriority("10");
    PluginModel pluginB = new PluginModel();
    pluginB.setPluginName("plugin B").setPriority("1");
    pluginManagerService.registerPlugin(pluginA);
    pluginManagerService.registerPlugin(pluginB);
    registryService.publishService(ITest.class, new TestObjectA(), new PluginServiceProvider(pluginA));
    registryService.publishService(ITest.class, new TestObjectB(), new PluginServiceProvider(pluginB));
    registryService.publishService(ITest.class, new TestObjectC(), new ContainerServiceProvider());
    List<ServiceReference> references = registryService.referenceServices(new DefaultServiceFilter().setServiceInterface(ITest.class).setProviderType(ServiceProviderType.ARK_PLUGIN));
    Assert.assertTrue(2 == references.size());
    PluginServiceProvider provider = (PluginServiceProvider) references.get(0).getServiceMetadata().getServiceProvider();
    Assert.assertEquals(pluginB.getPluginName(), provider.getPluginName());
    references = registryService.referenceServices(new ServiceFilter() {

        @Override
        public boolean match(ServiceReference serviceReference) {
            ServiceProvider serviceProvider = serviceReference.getServiceMetadata().getServiceProvider();
            if (serviceProvider instanceof PluginServiceProvider) {
                if (((PluginServiceProvider) serviceProvider).getPluginName().equals(pluginA.getPluginName())) {
                    return true;
                }
            }
            return false;
        }
    });
    Assert.assertTrue(1 == references.size());
    provider = (PluginServiceProvider) references.get(0).getServiceMetadata().getServiceProvider();
    Assert.assertEquals(pluginA.getPluginName(), provider.getPluginName());
    references = registryService.referenceServices(new DefaultServiceFilter().setServiceInterface(ITest.class));
    Assert.assertTrue(3 == references.size());
    references = registryService.referenceServices(new DefaultServiceFilter().setProviderType(ServiceProviderType.ARK_CONTAINER).setServiceInterface(ITest.class));
    Assert.assertTrue(1 == references.size());
    Assert.assertEquals("TestObject C", ((TestObjectC) references.get(0).getService()).test());
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) DefaultServiceFilter(com.alipay.sofa.ark.container.registry.DefaultServiceFilter) ServiceFilter(com.alipay.sofa.ark.spi.registry.ServiceFilter) TestObjectC(com.alipay.sofa.ark.container.testdata.impl.TestObjectC) DefaultServiceFilter(com.alipay.sofa.ark.container.registry.DefaultServiceFilter) TestObjectA(com.alipay.sofa.ark.container.testdata.impl.TestObjectA) TestObjectB(com.alipay.sofa.ark.container.testdata.impl.TestObjectB) ServiceProvider(com.alipay.sofa.ark.spi.registry.ServiceProvider) ContainerServiceProvider(com.alipay.sofa.ark.container.registry.ContainerServiceProvider) PluginServiceProvider(com.alipay.sofa.ark.container.registry.PluginServiceProvider) ContainerServiceProvider(com.alipay.sofa.ark.container.registry.ContainerServiceProvider) PluginServiceProvider(com.alipay.sofa.ark.container.registry.PluginServiceProvider) ServiceReference(com.alipay.sofa.ark.spi.registry.ServiceReference) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest) Test(org.junit.Test)

Example 5 with ContainerServiceProvider

use of com.alipay.sofa.ark.container.registry.ContainerServiceProvider in project sofa-ark by alipay.

the class ServiceRegistrationTest method testPublishService.

@Test
@SuppressWarnings("unchecked")
public void testPublishService() {
    ServiceReference<ITest> iTestServiceReference = registryService.publishService(ITest.class, new TestObjectA(), new ContainerServiceProvider());
    Assert.assertNotNull(iTestServiceReference);
    Assert.assertEquals(TestObjectA.OUTPUT, iTestServiceReference.getService().test());
    int c = registryService.unPublishServices(new DefaultServiceFilter().setServiceInterface(ITest.class).setProviderType(ServiceProviderType.ARK_CONTAINER));
    Assert.assertTrue(c == 1);
    iTestServiceReference = registryService.referenceService(ITest.class);
    Assert.assertNull(iTestServiceReference);
}
Also used : DefaultServiceFilter(com.alipay.sofa.ark.container.registry.DefaultServiceFilter) TestObjectA(com.alipay.sofa.ark.container.testdata.impl.TestObjectA) ITest(com.alipay.sofa.ark.container.testdata.ITest) ContainerServiceProvider(com.alipay.sofa.ark.container.registry.ContainerServiceProvider) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest) Test(org.junit.Test)

Aggregations

ContainerServiceProvider (com.alipay.sofa.ark.container.registry.ContainerServiceProvider)9 BaseTest (com.alipay.sofa.ark.container.BaseTest)8 Test (org.junit.Test)8 ITest (com.alipay.sofa.ark.container.testdata.ITest)6 TestObjectA (com.alipay.sofa.ark.container.testdata.impl.TestObjectA)6 DefaultServiceFilter (com.alipay.sofa.ark.container.registry.DefaultServiceFilter)4 TestObjectB (com.alipay.sofa.ark.container.testdata.impl.TestObjectB)3 RegistryService (com.alipay.sofa.ark.spi.service.registry.RegistryService)3 PluginModel (com.alipay.sofa.ark.container.model.PluginModel)2 PluginServiceProvider (com.alipay.sofa.ark.container.registry.PluginServiceProvider)2 TestObjectC (com.alipay.sofa.ark.container.testdata.impl.TestObjectC)2 ServiceReference (com.alipay.sofa.ark.spi.registry.ServiceReference)2 PluginContextImpl (com.alipay.sofa.ark.container.model.PluginContextImpl)1 BizCommandProvider (com.alipay.sofa.ark.container.service.biz.BizCommandProvider)1 DefaultBizDeployer (com.alipay.sofa.ark.container.service.biz.DefaultBizDeployer)1 PluginClassLoader (com.alipay.sofa.ark.container.service.classloader.PluginClassLoader)1 PluginCommandProvider (com.alipay.sofa.ark.container.service.plugin.PluginCommandProvider)1 ArkCommandHandler (com.alipay.sofa.ark.container.session.handler.ArkCommandHandler)1 PluginActivatorA (com.alipay.sofa.ark.container.testdata.activator.PluginActivatorA)1 PluginActivatorB (com.alipay.sofa.ark.container.testdata.activator.PluginActivatorB)1