Search in sources :

Example 1 with AttributeMetaData

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

the class MethodJournalInterceptorServiceTest method test3.

public void test3() throws Throwable {
    AttributeMetaData attr = new AttributeMetaData(interceptorServiceData);
    attr.setName("Enabled");
    attr.setValue("false");
    interceptorServiceData.addAttribute(attr);
    ServiceManagerFactory.registerService("Test", interceptorServiceData);
    interceptor = (MethodJournalInterceptorService) ServiceManagerFactory.getService("Test", "MethodJournalInterceptor");
    ServiceManagerFactory.findManager("Test").createAllService();
    ServiceManagerFactory.findManager("Test").startAllService();
    final Context context = (Context) ServiceManagerFactory.getServiceObject("Test", "Context");
    context.put(ThreadContextKey.REQUEST_ID, "001");
    Map target = new HashMap();
    target.put("A", new Integer(100));
    Object ret = new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {

        public Object invoke(InvocationContext context) throws Throwable {
            MethodInvocationContext ctx = (MethodInvocationContext) context;
            return ctx.getTargetMethod().invoke(ctx.getTargetObject(), ctx.getParameters());
        }
    }).invokeNext(new DefaultMethodInvocationContext(target, HashMap.class.getMethod("get", new Class[] { Object.class }), new Object[] { "A" }));
    assertEquals(ret, new Integer(100));
    synchronized (writer) {
        if (writer.record == null) {
            writer.wait(1000);
        }
    }
    assertNull(writer.record);
}
Also used : InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) MethodInvocationContext(jp.ossc.nimbus.service.aop.MethodInvocationContext) Context(jp.ossc.nimbus.service.context.Context) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) MethodInvocationContext(jp.ossc.nimbus.service.aop.MethodInvocationContext) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) Invoker(jp.ossc.nimbus.service.aop.Invoker) AttributeMetaData(jp.ossc.nimbus.core.AttributeMetaData) HashMap(java.util.HashMap) 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) HashMap(java.util.HashMap) Map(java.util.Map) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Example 2 with AttributeMetaData

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

the class MethodJournalInterceptorServiceTest method setUp.

protected void setUp() throws Exception {
    ServiceManagerFactory.registerManager("Test");
    ServiceMetaData serviceData = new ServiceMetaData();
    serviceData.setCode(ThreadManagedJournalService.class.getName());
    serviceData.setName("Journal");
    AttributeMetaData attr = new AttributeMetaData(serviceData);
    attr.setName("EditorFinderName");
    attr.setValue("#JournalEditorFinder");
    serviceData.addAttribute(attr);
    attr = new AttributeMetaData(serviceData);
    attr.setName("WritableElementKey");
    attr.setValue("MethodJournal");
    serviceData.addAttribute(attr);
    attr = new AttributeMetaData(serviceData);
    attr.setName("CategoryServiceNames");
    attr.setValue("#JournalCategory");
    serviceData.addAttribute(attr);
    serviceData.addDepends(serviceData.createDependsMetaData("Test", "JournalEditorFinder"));
    serviceData.addDepends(serviceData.createDependsMetaData("Test", "JournalCategory"));
    ServiceManagerFactory.registerService("Test", serviceData);
    serviceData = new ServiceMetaData();
    serviceData.setCode(SimpleCategoryService.class.getName());
    serviceData.setName("JournalCategory");
    attr = new AttributeMetaData(serviceData);
    attr.setName("MessageWriterServiceName");
    attr.setValue("#JournalWriter");
    serviceData.addAttribute(attr);
    attr = new AttributeMetaData(serviceData);
    attr.setName("WritableRecordFactoryServiceName");
    attr.setValue("#JournalWritableRecordFactory");
    serviceData.addAttribute(attr);
    serviceData.addDepends(serviceData.createDependsMetaData("Test", "JournalWriter"));
    serviceData.addDepends(serviceData.createDependsMetaData("Test", "JournalWritableRecordFactory"));
    ServiceManagerFactory.registerService("Test", serviceData);
    serviceData = new ServiceMetaData();
    serviceData.setCode(PropertyWritableRecordFactoryService.class.getName());
    serviceData.setName("JournalWritableRecordFactory");
    attr = new AttributeMetaData(serviceData);
    attr.setName("FormatKeyMapping");
    attr.setValue("REQUEST_ID=MethodJournal.RequestID\n" + "CALL=MethodJournal.JournalRecords.MethodCall[0]\n" + "RETURN=MethodJournal.JournalRecords.MethodReturn[0]\n");
    serviceData.addAttribute(attr);
    attr = new AttributeMetaData(serviceData);
    attr.setName("Format");
    attr.setValue("%REQUEST_ID%%CALL%%RETURN%");
    serviceData.addAttribute(attr);
    ServiceManagerFactory.registerService("Test", serviceData);
    writer = new TestMessageWriter();
    ServiceManagerFactory.registerService("Test", "JournalWriter", writer);
    serviceData = new ServiceMetaData();
    serviceData.setCode(ObjectMappedEditorFinderService.class.getName());
    serviceData.setName("JournalEditorFinder");
    attr = new AttributeMetaData(serviceData);
    attr.setName("EditorProperties");
    attr.setValue("java.lang.Object=#ObjectJournalEditor\n" + "jp.ossc.nimbus.service.journal.RequestJournal=#RequestJournalEditor\n");
    serviceData.addAttribute(attr);
    serviceData.addDepends(serviceData.createDependsMetaData("Test", "ObjectJournalEditor"));
    serviceData.addDepends(serviceData.createDependsMetaData("Test", "RequestJournalEditor"));
    ServiceManagerFactory.registerService("Test", serviceData);
    serviceData = new ServiceMetaData();
    serviceData.setCode(SimpleRequestMapJournalEditorService.class.getName());
    serviceData.setName("RequestJournalEditor");
    ServiceManagerFactory.registerService("Test", serviceData);
    serviceData = new ServiceMetaData();
    serviceData.setCode(ThreadContextService.class.getName());
    serviceData.setName("Context");
    ServiceManagerFactory.registerService("Test", serviceData);
    serviceData = new ServiceMetaData();
    serviceData.setCode(MutableObjectJournalEditorService.class.getName());
    serviceData.setName("ObjectJournalEditor");
    ServiceManagerFactory.registerService("Test", serviceData);
    interceptorServiceData = new ServiceMetaData();
    interceptorServiceData.setCode(MethodJournalInterceptorService.class.getName());
    interceptorServiceData.setName("MethodJournalInterceptor");
    attr = new AttributeMetaData(interceptorServiceData);
    attr.setName("JournalServiceName");
    attr.setValue("#Journal");
    interceptorServiceData.addAttribute(attr);
    attr = new AttributeMetaData(interceptorServiceData);
    attr.setName("ThreadContextServiceName");
    attr.setValue("#Context");
    interceptorServiceData.addAttribute(attr);
    interceptorServiceData.addDepends(serviceData.createDependsMetaData("Test", "Journal"));
    interceptorServiceData.addDepends(serviceData.createDependsMetaData("Test", "Context"));
}
Also used : SimpleRequestMapJournalEditorService(jp.ossc.nimbus.service.journal.editor.SimpleRequestMapJournalEditorService) ThreadManagedJournalService(jp.ossc.nimbus.service.journal.ThreadManagedJournalService) MutableObjectJournalEditorService(jp.ossc.nimbus.service.journal.editor.MutableObjectJournalEditorService) AttributeMetaData(jp.ossc.nimbus.core.AttributeMetaData) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) PropertyWritableRecordFactoryService(jp.ossc.nimbus.service.writer.PropertyWritableRecordFactoryService) ThreadContextService(jp.ossc.nimbus.service.context.ThreadContextService) SimpleCategoryService(jp.ossc.nimbus.service.writer.SimpleCategoryService) ObjectMappedEditorFinderService(jp.ossc.nimbus.service.journal.editorfinder.ObjectMappedEditorFinderService)

Example 3 with AttributeMetaData

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

the class MethodMappingInterceptorServiceTest method test2.

public void test2() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    ServiceMetaData serviceData = new ServiceMetaData();
    serviceData.setCode(MethodMappingInterceptorService.class.getName());
    serviceData.setName("MethodMappingInterceptor");
    AttributeMetaData attr = new AttributeMetaData(serviceData);
    attr.setName("TargetMethodMapping");
    attr.setValue("java\\.util\\..*#get(java.lang.Object)=#Interceptor2\n" + "java\\.util\\..*#put(java.lang.Object, java.lang.Object)=#Interceptor3");
    serviceData.addAttribute(attr);
    ServiceManagerFactory.registerService("Test", serviceData);
    Interceptor interceptor1 = (Interceptor) ServiceManagerFactory.getServiceObject("Test", "MethodMappingInterceptor");
    Interceptor interceptor2 = new Interceptor() {

        public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
            return this;
        }
    };
    ServiceManagerFactory.registerService("Test", "Interceptor2", interceptor2);
    Interceptor interceptor3 = new Interceptor() {

        public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
            return this;
        }
    };
    ServiceManagerFactory.registerService("Test", "Interceptor3", interceptor3);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        ServiceManagerFactory.findManager("Test").startAllService();
        assertEquals(interceptor2, new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("get", new Class[] { Object.class }), null)));
        assertEquals(interceptor3, new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("put", new Class[] { Object.class, Object.class }), 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) AttributeMetaData(jp.ossc.nimbus.core.AttributeMetaData) HashMap(java.util.HashMap) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) 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) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Example 4 with AttributeMetaData

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

the class MethodJournalInterceptorServiceTest method test4.

public void test4() throws Throwable {
    AttributeMetaData attr = new AttributeMetaData(interceptorServiceData);
    attr.setName("BushingCallBlock");
    attr.setValue("true");
    interceptorServiceData.addAttribute(attr);
    ServiceManagerFactory.registerService("Test", interceptorServiceData);
    interceptor = (MethodJournalInterceptorService) ServiceManagerFactory.getService("Test", "MethodJournalInterceptor");
    ServiceManagerFactory.findManager("Test").createAllService();
    ServiceManagerFactory.findManager("Test").startAllService();
    final Context context = (Context) ServiceManagerFactory.getServiceObject("Test", "Context");
    context.put(ThreadContextKey.REQUEST_ID, "001");
    Map target = new HashMap();
    target.put("A", new Integer(100));
    Object ret = new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor, new Interceptor() {

        public Object invoke(InvocationContext ctx, InterceptorChain chain) throws Throwable {
            ctx.setAttribute("chain", chain);
            return chain.invokeNext(ctx);
        }
    } }), new Invoker() {

        public Object invoke(InvocationContext ctx) throws Throwable {
            String reqId = (String) context.get(ThreadContextKey.REQUEST_ID);
            if ("001".equals(reqId)) {
                context.put(ThreadContextKey.REQUEST_ID, "002");
                final InterceptorChain chain = (InterceptorChain) ctx.getAttribute("chain");
                final InterceptorChain newChain = chain.cloneChain();
                newChain.setCurrentInterceptorIndex(0);
                return newChain.invokeNext(ctx);
            } else {
                MethodInvocationContext mctx = (MethodInvocationContext) ctx;
                return mctx.getTargetMethod().invoke(mctx.getTargetObject(), mctx.getParameters());
            }
        }
    }).invokeNext(new DefaultMethodInvocationContext(target, HashMap.class.getMethod("get", new Class[] { Object.class }), new Object[] { "A" }));
    assertEquals(ret, new Integer(100));
    synchronized (writer) {
        if (writer.record == null) {
            writer.wait(1000);
        }
    }
    assertNotNull(writer.record);
    assertEquals(3, writer.record.getElementMap().size());
    WritableElement element = (WritableElement) writer.record.getElementMap().get("REQUEST_ID");
    assertNotNull(element);
    assertEquals("001", element.toObject());
    element = (WritableElement) writer.record.getElementMap().get("CALL");
    assertNotNull(element);
    MethodCallJournalData callData = (MethodCallJournalData) element.toObject();
    assertNotNull(callData);
    assertEquals(HashMap.class, callData.getOwnerClass());
    assertEquals("get", callData.getName());
    assertNotNull(callData.getParameterTypes());
    assertEquals(1, callData.getParameterTypes().length);
    assertEquals(Object.class, callData.getParameterTypes()[0]);
    assertNotNull(callData.getParameters());
    assertEquals(1, callData.getParameters().length);
    assertEquals("A", callData.getParameters()[0]);
    element = (WritableElement) writer.record.getElementMap().get("RETURN");
    assertNotNull(element);
    MethodReturnJournalData retData = (MethodReturnJournalData) element.toObject();
    assertNotNull(retData);
    assertEquals(HashMap.class, retData.getOwnerClass());
    assertEquals("get", retData.getName());
    assertNotNull(retData.getParameterTypes());
    assertEquals(1, retData.getParameterTypes().length);
    assertEquals(Object.class, retData.getParameterTypes()[0]);
    assertEquals(new Integer(100), retData.getReturnValue());
}
Also used : InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) MethodInvocationContext(jp.ossc.nimbus.service.aop.MethodInvocationContext) Context(jp.ossc.nimbus.service.context.Context) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) MethodInvocationContext(jp.ossc.nimbus.service.aop.MethodInvocationContext) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) AttributeMetaData(jp.ossc.nimbus.core.AttributeMetaData) HashMap(java.util.HashMap) MethodCallJournalData(jp.ossc.nimbus.service.journal.editor.MethodCallJournalData) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain) InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) Invoker(jp.ossc.nimbus.service.aop.Invoker) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) WritableElement(jp.ossc.nimbus.service.writer.WritableElement) MethodReturnJournalData(jp.ossc.nimbus.service.journal.editor.MethodReturnJournalData) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) MethodInvocationContext(jp.ossc.nimbus.service.aop.MethodInvocationContext) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) HashMap(java.util.HashMap) Map(java.util.Map) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Example 5 with AttributeMetaData

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

the class MethodMappingInterceptorServiceTest method test3.

public void test3() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    ServiceMetaData serviceData = new ServiceMetaData();
    serviceData.setCode(MethodMappingInterceptorService.class.getName());
    serviceData.setName("MethodMappingInterceptor");
    AttributeMetaData attr = new AttributeMetaData(serviceData);
    attr.setName("TargetMethodMapping");
    attr.setValue("java\\.util\\..*#get(*)=#Interceptor2\n" + "java\\.util\\..*#.*(java.lang.Object, java.lang.Object)=#Interceptor3");
    serviceData.addAttribute(attr);
    ServiceManagerFactory.registerService("Test", serviceData);
    Interceptor interceptor1 = (Interceptor) ServiceManagerFactory.getServiceObject("Test", "MethodMappingInterceptor");
    Interceptor interceptor2 = new Interceptor() {

        public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
            return this;
        }
    };
    ServiceManagerFactory.registerService("Test", "Interceptor2", interceptor2);
    Interceptor interceptor3 = new Interceptor() {

        public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
            return this;
        }
    };
    ServiceManagerFactory.registerService("Test", "Interceptor3", interceptor3);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        ServiceManagerFactory.findManager("Test").startAllService();
        assertEquals(interceptor2, new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("get", new Class[] { Object.class }), null)));
        assertEquals(interceptor2, new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, ArrayList.class.getMethod("get", new Class[] { Integer.TYPE }), null)));
        assertEquals(interceptor3, new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("put", new Class[] { Object.class, Object.class }), null)));
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) AttributeMetaData(jp.ossc.nimbus.core.AttributeMetaData) HashMap(java.util.HashMap) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) ArrayList(java.util.ArrayList) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain) InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) 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) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Aggregations

AttributeMetaData (jp.ossc.nimbus.core.AttributeMetaData)7 HashMap (java.util.HashMap)6 DefaultInterceptorChain (jp.ossc.nimbus.service.aop.DefaultInterceptorChain)6 DefaultInterceptorChainList (jp.ossc.nimbus.service.aop.DefaultInterceptorChainList)6 DefaultMethodInvocationContext (jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext)6 InvocationContext (jp.ossc.nimbus.service.aop.InvocationContext)6 ServiceMetaData (jp.ossc.nimbus.core.ServiceMetaData)5 Interceptor (jp.ossc.nimbus.service.aop.Interceptor)5 InterceptorChain (jp.ossc.nimbus.service.aop.InterceptorChain)4 Context (jp.ossc.nimbus.service.context.Context)3 Map (java.util.Map)2 Invoker (jp.ossc.nimbus.service.aop.Invoker)2 MethodInvocationContext (jp.ossc.nimbus.service.aop.MethodInvocationContext)2 ArrayList (java.util.ArrayList)1 DefaultContextService (jp.ossc.nimbus.service.context.DefaultContextService)1 ThreadContextService (jp.ossc.nimbus.service.context.ThreadContextService)1 ThreadManagedJournalService (jp.ossc.nimbus.service.journal.ThreadManagedJournalService)1 MethodCallJournalData (jp.ossc.nimbus.service.journal.editor.MethodCallJournalData)1 MethodReturnJournalData (jp.ossc.nimbus.service.journal.editor.MethodReturnJournalData)1 MutableObjectJournalEditorService (jp.ossc.nimbus.service.journal.editor.MutableObjectJournalEditorService)1