Search in sources :

Example 1 with ServiceMetaData

use of jp.ossc.nimbus.core.ServiceMetaData in project nimbus by nimbus-org.

the class WsServiceFactoryService method startService.

public void startService() throws Exception {
    if (wsdlPath == null || "".equals(wsdlPath)) {
        throw new IllegalArgumentException("WsdlPath must be specified.");
    }
    if (nameSpace == null || "".equals(nameSpace)) {
        throw new IllegalArgumentException("NameSpace must be specified.");
    }
    if (localPart == null || "".equals(localPart)) {
        throw new IllegalArgumentException("LocalPart must be specified.");
    }
    if (webServiceClassName == null || "".equals(webServiceClassName)) {
        throw new IllegalArgumentException("WebServiceClassName must be specified.");
    }
    if (wsdlPath != null) {
        URL url = null;
        File localFile = new File(wsdlPath);
        if (localFile.exists()) {
            if (!localFile.isFile()) {
                throw new IllegalArgumentException("WsdlPath must be file : " + localFile);
            }
            try {
                wsdlURL = localFile.toURI().toURL();
            } catch (MalformedURLException e) {
            // この例外は発生しないはず
            }
        } else {
            File serviceDefDir = null;
            if (getServiceNameObject() != null) {
                ServiceMetaData metaData = ServiceManagerFactory.getServiceMetaData(getServiceNameObject());
                if (metaData != null) {
                    jp.ossc.nimbus.core.ServiceLoader loader = metaData.getServiceLoader();
                    if (loader != null) {
                        String filePath = loader.getServiceURL().getFile();
                        if (filePath != null) {
                            serviceDefDir = new File(filePath).getParentFile();
                        }
                    }
                }
            }
            localFile = new File(serviceDefDir, wsdlPath);
            if (localFile.exists()) {
                if (!localFile.isFile()) {
                    throw new IllegalArgumentException("WsdlPath must be file : " + localFile);
                }
                try {
                    wsdlURL = localFile.toURI().toURL();
                } catch (MalformedURLException e) {
                // この例外は発生しないはず
                }
            } else {
                final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
                final URL resource = classLoader.getResource(wsdlPath);
                if (resource != null) {
                    wsdlURL = resource;
                }
            }
        }
    }
    try {
        webServiceClass = Class.forName(webServiceClassName);
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException("WebServiceClassName Illegal. " + webServiceClassName);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) File(java.io.File) URL(java.net.URL)

Example 2 with ServiceMetaData

use of jp.ossc.nimbus.core.ServiceMetaData in project nimbus by nimbus-org.

the class FlowControlInterceptorServiceTest method test2.

public void test2() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    final ServiceMetaData interceptorServiceData = new ServiceMetaData();
    interceptorServiceData.setCode(FlowControlInterceptorService.class.getName());
    interceptorServiceData.setName("FlowControlInterceptor");
    interceptorServiceData.addDepends(interceptorServiceData.createDependsMetaData("Test", "Semaphore"));
    ServiceManagerFactory.registerService("Test", interceptorServiceData);
    FlowControlInterceptorService interceptor = (FlowControlInterceptorService) ServiceManagerFactory.getService("Test", "FlowControlInterceptor");
    final DefaultSemaphoreService semaphore = new DefaultSemaphoreService();
    ServiceManagerFactory.registerService("Test", "Semaphore", semaphore);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        interceptor.setSemaphoreServiceName(new ServiceName("Test", "Semaphore"));
        interceptor.setTimeout(200l);
        semaphore.setResourceCapacity(1);
        ServiceManagerFactory.findManager("Test").startAllService();
        final InterceptorChain chain = new DefaultThreadLocalInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {

            public Object invoke(InvocationContext context) throws Throwable {
                Thread.sleep(500);
                return "test";
            }
        });
        Runnable runner = new Runnable() {

            public void run() {
                try {
                    chain.invokeNext(new DefaultMethodInvocationContext());
                } catch (Throwable th) {
                }
            }
        };
        Thread thread = new Thread(runner);
        thread.start();
        Thread.sleep(100);
        try {
            chain.invokeNext(new DefaultMethodInvocationContext());
            fail();
        } catch (FailToObtainSemaphoreException e) {
        }
        thread.join();
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) DefaultThreadLocalInterceptorChain(jp.ossc.nimbus.service.aop.DefaultThreadLocalInterceptorChain) DefaultThreadLocalInterceptorChain(jp.ossc.nimbus.service.aop.DefaultThreadLocalInterceptorChain) InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) Invoker(jp.ossc.nimbus.service.aop.Invoker) ServiceName(jp.ossc.nimbus.core.ServiceName) DefaultSemaphoreService(jp.ossc.nimbus.service.semaphore.DefaultSemaphoreService) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) Interceptor(jp.ossc.nimbus.service.aop.Interceptor)

Example 3 with ServiceMetaData

use of jp.ossc.nimbus.core.ServiceMetaData in project nimbus by nimbus-org.

the class FlowControlInterceptorServiceTest method test1.

public void test1() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    final ServiceMetaData interceptorServiceData = new ServiceMetaData();
    interceptorServiceData.setCode(FlowControlInterceptorService.class.getName());
    interceptorServiceData.setName("FlowControlInterceptor");
    interceptorServiceData.addDepends(interceptorServiceData.createDependsMetaData("Test", "Semaphore"));
    ServiceManagerFactory.registerService("Test", interceptorServiceData);
    FlowControlInterceptorService interceptor = (FlowControlInterceptorService) ServiceManagerFactory.getService("Test", "FlowControlInterceptor");
    final DefaultSemaphoreService semaphore = new DefaultSemaphoreService();
    ServiceManagerFactory.registerService("Test", "Semaphore", semaphore);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        interceptor.setSemaphoreServiceName(new ServiceName("Test", "Semaphore"));
        semaphore.setResourceCapacity(2);
        ServiceManagerFactory.findManager("Test").startAllService();
        class Counter {

            public volatile int count;

            public boolean isAssertFail;
        }
        final Counter counter = new Counter();
        final InterceptorChain chain = new DefaultThreadLocalInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {

            public Object invoke(InvocationContext context) throws Throwable {
                try {
                    synchronized (counter) {
                        counter.count++;
                    }
                    Thread.sleep(new Random().nextInt(100));
                    return "test";
                } finally {
                    synchronized (counter) {
                        counter.count--;
                    }
                }
            }
        });
        Runnable runner = new Runnable() {

            public void run() {
                for (int i = 0; i < 10; i++) {
                    counter.isAssertFail |= counter.count > semaphore.getResourceCapacity();
                    try {
                        chain.invokeNext(new DefaultMethodInvocationContext());
                    } catch (Throwable th) {
                    }
                    counter.isAssertFail |= counter.count > semaphore.getResourceCapacity();
                }
            }
        };
        Thread[] threads = new Thread[10];
        for (int i = 0; i < threads.length; i++) {
            threads[i] = new Thread(runner);
        }
        Random random = new Random();
        for (int i = 0; i < threads.length; i++) {
            threads[i].start();
            Thread.sleep(random.nextInt(100));
        }
        for (int i = 0; i < threads.length; i++) {
            threads[i].join();
        }
        assertFalse(counter.isAssertFail);
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) DefaultThreadLocalInterceptorChain(jp.ossc.nimbus.service.aop.DefaultThreadLocalInterceptorChain) DefaultThreadLocalInterceptorChain(jp.ossc.nimbus.service.aop.DefaultThreadLocalInterceptorChain) InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) Invoker(jp.ossc.nimbus.service.aop.Invoker) Random(java.util.Random) ServiceName(jp.ossc.nimbus.core.ServiceName) DefaultSemaphoreService(jp.ossc.nimbus.service.semaphore.DefaultSemaphoreService) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) Interceptor(jp.ossc.nimbus.service.aop.Interceptor)

Example 4 with ServiceMetaData

use of jp.ossc.nimbus.core.ServiceMetaData in project nimbus by nimbus-org.

the class FlowControlInterceptorServiceTest method test3.

public void test3() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    final ServiceMetaData interceptorServiceData = new ServiceMetaData();
    interceptorServiceData.setCode(FlowControlInterceptorService.class.getName());
    interceptorServiceData.setName("FlowControlInterceptor");
    interceptorServiceData.addDepends(interceptorServiceData.createDependsMetaData("Test", "Semaphore"));
    ServiceManagerFactory.registerService("Test", interceptorServiceData);
    FlowControlInterceptorService interceptor = (FlowControlInterceptorService) ServiceManagerFactory.getService("Test", "FlowControlInterceptor");
    final DefaultSemaphoreService semaphore = new DefaultSemaphoreService();
    ServiceManagerFactory.registerService("Test", "Semaphore", semaphore);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        interceptor.setSemaphoreServiceName(new ServiceName("Test", "Semaphore"));
        interceptor.setTimeout(200l);
        interceptor.setFailToObtainSemaphore(false);
        semaphore.setResourceCapacity(1);
        ServiceManagerFactory.findManager("Test").startAllService();
        final InterceptorChain chain = new DefaultThreadLocalInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {

            public Object invoke(InvocationContext context) throws Throwable {
                Thread.sleep(500);
                return "test";
            }
        });
        Runnable runner = new Runnable() {

            public void run() {
                try {
                    chain.invokeNext(new DefaultMethodInvocationContext());
                } catch (Throwable th) {
                }
            }
        };
        Thread thread = new Thread(runner);
        thread.start();
        Thread.sleep(100);
        assertNull(chain.invokeNext(new DefaultMethodInvocationContext()));
        thread.join();
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) DefaultThreadLocalInterceptorChain(jp.ossc.nimbus.service.aop.DefaultThreadLocalInterceptorChain) DefaultThreadLocalInterceptorChain(jp.ossc.nimbus.service.aop.DefaultThreadLocalInterceptorChain) InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) Invoker(jp.ossc.nimbus.service.aop.Invoker) ServiceName(jp.ossc.nimbus.core.ServiceName) DefaultSemaphoreService(jp.ossc.nimbus.service.semaphore.DefaultSemaphoreService) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) Interceptor(jp.ossc.nimbus.service.aop.Interceptor)

Example 5 with ServiceMetaData

use of jp.ossc.nimbus.core.ServiceMetaData in project nimbus by nimbus-org.

the class MethodAsynchronousInterceptorServiceTest method test4.

public void test4() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    final ServiceMetaData interceptorServiceData = new ServiceMetaData();
    interceptorServiceData.setCode(MethodAsynchronousInterceptorService.class.getName());
    interceptorServiceData.setName("MethodAsynchronousInterceptor");
    interceptorServiceData.addDepends(interceptorServiceData.createDependsMetaData("Test", "Queue"));
    ServiceManagerFactory.registerService("Test", interceptorServiceData);
    MethodAsynchronousInterceptorService interceptor = (MethodAsynchronousInterceptorService) ServiceManagerFactory.getService("Test", "MethodAsynchronousInterceptor");
    final ServiceMetaData queueServiceData = new ServiceMetaData();
    queueServiceData.setCode(DefaultQueueService.class.getName());
    queueServiceData.setName("Queue");
    queueServiceData.setInstance(ServiceMetaData.INSTANCE_TYPE_THREADLOCAL);
    ServiceManagerFactory.registerService("Test", queueServiceData);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        interceptor.setResponseQueueServiceName(new ServiceName("Test", "Queue"));
        interceptor.setInvokerThreadSize(3);
        interceptor.setReturnResponse(false);
        ServiceManagerFactory.findManager("Test").startAllService();
        for (int i = 0; i < 3; i++) {
            Object ret = new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {

                public Object invoke(InvocationContext context) throws Throwable {
                    Thread.sleep(500);
                    return "test";
                }
            }).invokeNext(new DefaultMethodInvocationContext(new Integer(i), Integer.class.getMethod("toString", (Class[]) null), null));
            assertNull(ret);
        }
        Queue queue = (Queue) ServiceManagerFactory.getServiceObject("Test", "Queue");
        for (int i = 0; i < 3; i++) {
            AsynchronousResponse response = (AsynchronousResponse) queue.get();
            assertNotNull(response);
            assertEquals("test", response.getReturnObject());
        }
        assertNull(queue.get(500));
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) Invoker(jp.ossc.nimbus.service.aop.Invoker) ServiceName(jp.ossc.nimbus.core.ServiceName) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) Queue(jp.ossc.nimbus.service.queue.Queue) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Aggregations

ServiceMetaData (jp.ossc.nimbus.core.ServiceMetaData)14 DefaultInterceptorChainList (jp.ossc.nimbus.service.aop.DefaultInterceptorChainList)8 DefaultMethodInvocationContext (jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext)8 InvocationContext (jp.ossc.nimbus.service.aop.InvocationContext)8 Interceptor (jp.ossc.nimbus.service.aop.Interceptor)7 InterceptorChain (jp.ossc.nimbus.service.aop.InterceptorChain)6 AttributeMetaData (jp.ossc.nimbus.core.AttributeMetaData)5 ServiceName (jp.ossc.nimbus.core.ServiceName)5 DefaultInterceptorChain (jp.ossc.nimbus.service.aop.DefaultInterceptorChain)5 File (java.io.File)4 HashMap (java.util.HashMap)4 Invoker (jp.ossc.nimbus.service.aop.Invoker)4 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 DefaultThreadLocalInterceptorChain (jp.ossc.nimbus.service.aop.DefaultThreadLocalInterceptorChain)3 DefaultSemaphoreService (jp.ossc.nimbus.service.semaphore.DefaultSemaphoreService)3 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1