apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chandni Singh <chan...@datatorrent.com>
Subject Re: Regarding logging and exception handling framework
Date Wed, 04 Nov 2015 18:25:47 GMT
Hi Venkatesh,

I am not very familiar with AOP but here is some information I found and I
guess you may have seen this as well.
http://stackoverflow.com/questions/13461985/classcastexception-proxy-cannot-be-cast-to-using-aop

This says that target object needs to implement an interface. However it
refers to the link below if the target is a class.

http://docs.spring.io/spring/docs/3.0.0.M3/reference/html/ch08s06.html

Can you please follow the steps in the above doc and let me know how it
goes.

Thanks,
Chandni


On Tue, Nov 3, 2015 at 3:44 PM, Kottapalli, Venkatesh <
VKottapalli@directv.com> wrote:

> I am trying to log exceptions, some entry and exit parameters for certain
> function calls in my implementation, hence I have defined beans to
> intercept in the following way. Please let me know if you need more inputs
> on this.
>
> I have used spring core jars :
> =====================
>                 <dependency>
>                         <groupId>org.springframework</groupId>
>                         <artifactId>spring-core</artifactId>
>                         <version>${spring.version}</version>
>                 </dependency>
>                 <dependency>
>                         <groupId>org.springframework</groupId>
>                         <artifactId>spring-context</artifactId>
>                         <version>${spring.version}</version>
>                 </dependency>
>
>
> ApplicationContext definitions :
> ===========================
>
>         <bean id=" fileSplitter" class="com.package.SimpleService"/>
>         <bean id="secondServiceBean" class="com.package.SecondService"/>
>
>         <bean id="logEntryBean" class="com.package.LogEntry" />
>         <bean id="logExitBean" class="com.package.LogReturn" />
>         <bean id="logExceptionBean" class
> ="com.package.logging.ExceptionLogger"/>
>
>
>                 <bean id="secondServiceProxy"
> class="org.springframework.aop.framework.ProxyFactoryBean">
>                 <property name="target" ref="secondServiceBean" />
>                 <property name="interceptorNames">
>                         <list>
>                                 <value>logEntryBean</value>
>                                 <value>logExitBean</value>
>                                 <value>logExceptionBean</value>
>                         </list>
>                 </property>
>         </bean>
>
>
> Application.java
> ===============
>
>         ConfigurableApplicationContext context = new
> ClassPathXmlApplicationContext("ApplicationContext.xml");
>          FileSplitter call =(FileSplitter) context.getBean("fileSplitter");
>          SecondService secondService =(SecondService)
> context.getBean("secondServiceProxy");
>
>         FileSplitter fileSplitter = dag.addOperator("FileSplitter", call);
>         SecondService reader=dag.addOperator("reader", secondService);
>
>         ConsoleOutputOperator cons = dag.addOperator("console", new
> ConsoleOutputOperator());
>         dag.addStream("blockin", fileSplitter.blocksMetadataOutput,
> reader.blocksMetadataInput);
>         dag.addStream("randomData", reader.batchData, cons.input);
>
>
> LogEntry :
> =========
>
> package com.package.logging;
>
> import java.lang.reflect.Method;
>
> import org.apache.log4j.Logger;
> import org.springframework.aop.MethodBeforeAdvice;
>
> public class LogEntry implements MethodBeforeAdvice {
>         private final static Logger logger =
> Logger.getLogger(LogEntry.class);
>
>         public void before(Method method, Object[] args, Object target)
> throws Throwable {
>
>                 if(logger.isDebugEnabled())
>                 logger.info("logged entry for method : " +
> method.getName());
>         }
>
> }
>
>
> SecondService does not implement any interface, it extends CSVBlockReader
> class which again extends AbstractBlockReader class.
> =========================================================================
>
> Exception while running Junit :
> ===========================
>
> java.lang.ClassCastException: com.sun.proxy.$Proxy11 cannot be cast to
> com.package.filesplitterimpl.SecondService
>         at
> com.package.filesplitterimpl.Application.populateDAG(Application.java:28)
>         at
> com.datatorrent.stram.plan.logical.LogicalPlanConfiguration.prepareDAG(LogicalPlanConfiguration.java:1191)
>         at
> com.datatorrent.stram.LocalModeImpl.prepareDAG(LocalModeImpl.java:57)
>         at
> com.dtv.myapexapp.ApplicationTest.testApplication(ApplicationTest.java:28)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:606)
>         at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
>         at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>         at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
>         at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
>         at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
>         at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
>         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
>         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
>         at
> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
>         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
>         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
>         at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
>         at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
>         at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
>
> regards,
> Venkatesh.
>
> -----Original Message-----
> From: Chandni Singh [mailto:chandni@datatorrent.com]
> Sent: Tuesday, November 03, 2015 2:46 PM
> To: dev@apex.incubator.apache.org
> Subject: Re: Regarding logging and exception handling framework
>
> Hi Venkatesh,
>
> Can you please provide a small code snippet or example which shows what
> you want to do?
>
> If you want to find out any validation exception during preparation of
> logical plan, then you can take a look at the LogicalPlanTest in Apache
> Apex repository.
>
> Thanks,
> Chandni
>
>
> On Tue, Nov 3, 2015 at 2:37 PM, Kottapalli, Venkatesh <
> VKottapalli@directv.com> wrote:
>
> > Hi,
> >
> >                 With the framework malhar has, Can we use AOP
> > interception technique for logging and exception handling?  I have
> > tried but unable to proxy Operator classes to intercept during DAG
> preparation. Please suggest.
> >
> > Regards,
> > Venkatesh.
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message