Search in sources :

Example 36 with ServiceName

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

the class ExceptionHandlerMappingService method startService.

@Override
public void startService() throws Exception {
    final ClassLoader loader = NimbusClassLoader.getInstance();
    if (exceptionAndHandlerMapping != null) {
        exceptionMapForHandler = new ClassMappingTree();
        final ServiceNameEditor editor = new ServiceNameEditor();
        editor.setServiceManagerName(getServiceManagerName());
        final Iterator exNames = exceptionAndHandlerMapping.keySet().iterator();
        while (exNames.hasNext()) {
            final String exName = (String) exNames.next();
            final Class clazz = Class.forName(exName, true, loader);
            final String name = (String) exceptionAndHandlerMapping.get(exName);
            editor.setAsText(name);
            final ServiceName serviceName = (ServiceName) editor.getValue();
            exceptionMapForHandler.add(clazz, ServiceManagerFactory.getServiceObject(serviceName));
        }
    }
    if (defaultExceptionHandlerServiceName != null) {
        defaultExceptionHandler = (ExceptionHandler) ServiceManagerFactory.getServiceObject(defaultExceptionHandlerServiceName);
    }
}
Also used : ServiceNameEditor(jp.ossc.nimbus.beans.ServiceNameEditor) ServiceName(jp.ossc.nimbus.core.ServiceName) Iterator(java.util.Iterator) NimbusClassLoader(jp.ossc.nimbus.core.NimbusClassLoader) ClassMappingTree(jp.ossc.nimbus.util.ClassMappingTree)

Example 37 with ServiceName

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

the class WsServiceMetricsHandlerService method startService.

/**
 * サービスの開始処理を行う。<p>
 *
 * @exception Exception 開始処理に失敗した場合
 */
public void startService() throws Exception {
    metricsInfos.clear();
    if (keyAndCategoryServiceNameMapping != null && keyAndCategoryServiceNameMapping.size() != 0) {
        final ServiceNameEditor nameEditor = new ServiceNameEditor();
        nameEditor.setServiceManagerName(getServiceManagerName());
        final Iterator keys = keyAndCategoryServiceNameMapping.keySet().iterator();
        while (keys.hasNext()) {
            final String key = (String) keys.next();
            final String nameStr = keyAndCategoryServiceNameMapping.getProperty(key);
            nameEditor.setAsText(nameStr);
            final ServiceName name = (ServiceName) nameEditor.getValue();
            final Category category = (Category) ServiceManagerFactory.getServiceObject(name);
            keyAndCategoryMap.put(key, category);
        }
    }
    if (categoryServiceName != null) {
        metricsCategory = (Category) ServiceManagerFactory.getServiceObject(categoryServiceName);
    }
    if ((keyAndCategoryMap != null && keyAndCategoryMap.size() != 0) || metricsCategory != null) {
        writerDaemon = new Daemon(this);
        writerDaemon.setName("Nimbus MetricsWriteDaemon " + getServiceNameObject());
        writerDaemon.start();
    }
}
Also used : ServiceNameEditor(jp.ossc.nimbus.beans.ServiceNameEditor) Category(jp.ossc.nimbus.service.writer.Category) Daemon(jp.ossc.nimbus.daemon.Daemon) ServiceName(jp.ossc.nimbus.core.ServiceName) Iterator(java.util.Iterator)

Example 38 with ServiceName

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

the class MethodMetricsInterceptorServiceTest method test5.

public void test5() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    MethodMetricsInterceptorService interceptor = new MethodMetricsInterceptorService();
    ServiceManagerFactory.registerService("Test", "MethodMetricsInterceptor", interceptor);
    class TestCategory implements Category {

        public Object elements;

        public boolean isEnabled() {
            return true;
        }

        public void setEnabled(boolean enable) {
        }

        public void write(Object elements) {
            this.elements = elements;
            synchronized (this) {
                this.notify();
            }
        }
    }
    ;
    TestCategory category = new TestCategory();
    ServiceManagerFactory.registerService("Test", "Category", category);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        interceptor.setCategoryServiceName(new ServiceName("Test", "Category"));
        interceptor.setOutputInterval(1000L);
        interceptor.setOutputCount(true);
        interceptor.setOutputExceptionCount(true);
        interceptor.setOutputErrorCount(true);
        interceptor.setOutputLastTime(true);
        interceptor.setOutputLastExceptionTime(true);
        interceptor.setOutputLastErrorTime(true);
        interceptor.setOutputBestPerformance(true);
        interceptor.setOutputBestPerformanceTime(true);
        interceptor.setOutputWorstPerformance(true);
        interceptor.setOutputWorstPerformanceTime(true);
        interceptor.setOutputAveragePerformance(true);
        ServiceManagerFactory.findManager("Test").startAllService();
        assertEquals("test", new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {

            public Object invoke(InvocationContext context) throws Throwable {
                Thread.sleep(new Random().nextInt(400) + 100);
                return "test";
            }
        }).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("get", new Class[] { Object.class }), null)));
        synchronized (category) {
            if (category.elements == null) {
                category.wait(2000);
            }
        }
        assertNotNull(category.elements);
        assertTrue(category.elements instanceof Map);
        Map record = (Map) category.elements;
        assertEquals(13, record.size());
        assertEquals(new Integer(1), record.get(MethodMetricsInterceptorService.RECORD_KEY_ORDER));
        assertEquals("java.util.HashMap#get(java.lang.Object)", record.get(MethodMetricsInterceptorService.RECORD_KEY_METHOD));
        assertEquals(new Long(1), record.get(MethodMetricsInterceptorService.RECORD_KEY_COUNT));
        assertEquals(new Long(0), record.get(MethodMetricsInterceptorService.RECORD_KEY_EXCEPTION_COUNT));
        assertEquals(new Long(0), record.get(MethodMetricsInterceptorService.RECORD_KEY_ERROR_COUNT));
        assertNotNull(record.get(MethodMetricsInterceptorService.RECORD_KEY_LAST_TIME));
        assertTrue(new Date().compareTo((Date) record.get(MethodMetricsInterceptorService.RECORD_KEY_LAST_TIME)) > 0);
        assertNull(record.get(MethodMetricsInterceptorService.RECORD_KEY_LAST_EXCEPTION_TIME));
        assertNull(record.get(MethodMetricsInterceptorService.RECORD_KEY_LAST_ERROR_TIME));
        assertNotNull(record.get(MethodMetricsInterceptorService.RECORD_KEY_BEST_PERFORMANCE));
        assertTrue(new Long(0).compareTo((Long) record.get(MethodMetricsInterceptorService.RECORD_KEY_BEST_PERFORMANCE)) < 0);
        assertNotNull(record.get(MethodMetricsInterceptorService.RECORD_KEY_BEST_PERFORMANCE_TIME));
        assertTrue(new Date().compareTo((Date) record.get(MethodMetricsInterceptorService.RECORD_KEY_BEST_PERFORMANCE_TIME)) > 0);
        assertNotNull(record.get(MethodMetricsInterceptorService.RECORD_KEY_WORST_PERFORMANCE));
        assertTrue(new Long(0).compareTo((Long) record.get(MethodMetricsInterceptorService.RECORD_KEY_WORST_PERFORMANCE)) < 0);
        assertNotNull(record.get(MethodMetricsInterceptorService.RECORD_KEY_WORST_PERFORMANCE_TIME));
        assertTrue(new Date().compareTo((Date) record.get(MethodMetricsInterceptorService.RECORD_KEY_WORST_PERFORMANCE_TIME)) > 0);
        assertNotNull(record.get(MethodMetricsInterceptorService.RECORD_KEY_AVERAGE_PERFORMANCE));
        assertTrue(new Long(0).compareTo((Long) record.get(MethodMetricsInterceptorService.RECORD_KEY_AVERAGE_PERFORMANCE)) < 0);
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) Category(jp.ossc.nimbus.service.writer.Category) HashMap(java.util.HashMap) Date(java.util.Date) Invoker(jp.ossc.nimbus.service.aop.Invoker) Random(java.util.Random) 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) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) HashMap(java.util.HashMap) Map(java.util.Map) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Example 39 with ServiceName

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

the class MockInterceptorServiceTest method test1.

public void test1() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    MockInterceptorService interceptor = new MockInterceptorService();
    ServiceManagerFactory.registerService("Test", "MockInterceptor", interceptor);
    final Method targetMethod = String.class.getMethod("toString", (Class[]) null);
    MockFactory mockFactory = new MockFactory() {

        public Object createMock(InvocationContext context) {
            assertNotNull(context);
            assertTrue(context instanceof MethodInvocationContext);
            MethodInvocationContext ctx = (MethodInvocationContext) context;
            assertEquals("Real", ctx.getTargetObject());
            assertEquals(targetMethod, ctx.getTargetMethod());
            return "Mock";
        }
    };
    ServiceManagerFactory.registerService("Test", "MockFactory", mockFactory);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        interceptor.setMockFactoryServiceName(new ServiceName("Test", "MockFactory"));
        ServiceManagerFactory.findManager("Test").startAllService();
        final InterceptorChain chain = new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new MethodReflectionCallInvokerService());
        assertEquals("Mock", chain.invokeNext(new DefaultMethodInvocationContext("Real", targetMethod, null)));
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) MethodInvocationContext(jp.ossc.nimbus.service.aop.MethodInvocationContext) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) Method(java.lang.reflect.Method) MethodReflectionCallInvokerService(jp.ossc.nimbus.service.aop.invoker.MethodReflectionCallInvokerService) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain) InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) ServiceName(jp.ossc.nimbus.core.ServiceName) MockFactory(jp.ossc.nimbus.service.aop.MockFactory) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) MethodInvocationContext(jp.ossc.nimbus.service.aop.MethodInvocationContext) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Example 40 with ServiceName

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

the class MockInterceptorServiceTest method test3.

public void test3() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    MockInterceptorService interceptor = new MockInterceptorService();
    ServiceManagerFactory.registerService("Test", "MockInterceptor", interceptor);
    final Method targetMethod = String.class.getMethod("toString", (Class[]) null);
    ServiceManagerFactory.registerService("Test", "Mock", "Mock");
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        interceptor.setMockServiceName(new ServiceName("Test", "Mock"));
        ServiceManagerFactory.findManager("Test").startAllService();
        final InterceptorChain chain = new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new MethodReflectionCallInvokerService());
        assertEquals("Mock", chain.invokeNext(new DefaultMethodInvocationContext("Real", targetMethod, null)));
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain) InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) ServiceName(jp.ossc.nimbus.core.ServiceName) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) Method(java.lang.reflect.Method) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) MethodReflectionCallInvokerService(jp.ossc.nimbus.service.aop.invoker.MethodReflectionCallInvokerService) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Aggregations

ServiceName (jp.ossc.nimbus.core.ServiceName)66 ServiceNameRef (jp.ossc.nimbus.core.ServiceNameRef)13 ServiceNameEditor (jp.ossc.nimbus.beans.ServiceNameEditor)12 DefaultInterceptorChainList (jp.ossc.nimbus.service.aop.DefaultInterceptorChainList)9 DefaultMethodInvocationContext (jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext)8 Interceptor (jp.ossc.nimbus.service.aop.Interceptor)8 InvocationContext (jp.ossc.nimbus.service.aop.InvocationContext)8 FilterChain (javax.servlet.FilterChain)7 InterceptorChain (jp.ossc.nimbus.service.aop.InterceptorChain)7 Map (java.util.Map)6 Properties (java.util.Properties)6 DefaultInterceptorChain (jp.ossc.nimbus.service.aop.DefaultInterceptorChain)6 HashMap (java.util.HashMap)5 ServiceMetaData (jp.ossc.nimbus.core.ServiceMetaData)5 Invoker (jp.ossc.nimbus.service.aop.Invoker)5 Iterator (java.util.Iterator)4 Method (java.lang.reflect.Method)3 ServletConfig (javax.servlet.ServletConfig)3 DefaultThreadLocalInterceptorChain (jp.ossc.nimbus.service.aop.DefaultThreadLocalInterceptorChain)3 DefaultSemaphoreService (jp.ossc.nimbus.service.semaphore.DefaultSemaphoreService)3