Hello, 

We did.....,

        public static class ServantLogger implements Loggable, 
Serializable {

                private static final long serialVersionUID = 
7527959720796724806L;
 
                private Class<? extends Object> clazz = null;
                private transient Logger log = null;

                public ServantLogger(Class<? extends Object> clazz) {
                        this.clazz = clazz;
                }

                @Override
                public Logger getLog() {
                        if (log == null) {
                                log = LoggerFactory.getLogger(clazz);
                        }
 
                        return log;
                }
        }


Jean ANDRÉ





De :    Jean Andre <jean.an...@intact.net>
A :     aspectj-users@eclipse.org, 
Date :  2013-05-08 12:00
Objet : [aspectj-users] Aspect  under clustering env. - serialization
Envoyé par :    aspectj-users-boun...@eclipse.org



Hello, 

We got a NPE on logger under clustering env, It is like the transient 
logger is not recreate automatically even if the class seem to be 
reconstruct. What do we need to do or know in addition to allow aspect 
working under clustering env. 

        1)  Making the aspect Serializable ? 
        2) How do we recreate automatically the logger in aspect  ? 
        3) Making the logger serializable ? 
        4) Something else ? 

Here is our aspect that performs a log on every method prefixed by do 
backing bean. 

>>>> NPE here one the class is reconstruct after a serialization 
        >>>>        if (log.getLog().isDebugEnabled()) { 

Thank a lot for your answer 


==================================================================================
 

                                                                     THE 
BASE CLASS  - Fragment
==================================================================================
 

@Aspect 
public abstract class LoggingBaseBehavior { 
        /* 
         * The interface and the implementation of Loggable class. 
         */ 
        public interface Loggable { 
                Logger getLog(); 
        }; 

        public static class ServantLogger implements Loggable, 
Serializable { 

                private static final long serialVersionUID = 
7527959720796724806L; 
 
                private transient Logger log = null; 

                public ServantLogger(Class<? extends Object> clazz) { 
                        this.log = LoggerFactory.getLogger(clazz); 
                } 

                @Override 
                public Logger getLog() { 
                        return log; 
                } 
        } 
} 

==================================================================================
 

                                                                     THE 
LOGGER ASPECT ON Controller
==================================================================================
 

@Aspect 
public class LoggingControllerBehavior extends LoggingBaseBehavior { 

        @DeclareMixin("com.xyz.crm.web.common.controller.BaseController") 
        public static Loggable createLoggerDelegate(Object o) { 
                return new ServantLogger(o.getClass()); 
        } 

        @Pointcut("execution(* com.xyz.crm.web..*Controller*.do*(..))") 
        public void controllerLogger() {}; 

        @Pointcut("execution(protected void 
com.xyz.crm.web..BaseTabController.initialize(..)) && 
!within(com.xyz.crm.web..BaseClientController)") 
        public void initializerLogger() {}; 

        @Pointcut("execution(* com.xyz.crm.web..*Controller.validate(..))"
) 
        public void validateLogger() {}; 


        @Before(value = "controllerLogger() && this(log)") 
        public void loggerController(JoinPoint jp, JoinPoint.StaticPart 
jps, Loggable log) { 
                if (log.getLog().isDebugEnabled() && jps != null) { 
                        final String args = buildParameters(jp.getArgs()); 

                        log.getLog().debug(jps.getSignature().getName() + 
" - Entering..." + (args.isEmpty() ? "" : " - " + args)); 
                        log.getLog().debug(jps.getSignature().getName() + 
" - Object dump - " + jp.getTarget()); 
                } 
        } 

        @Before(value = "initializerLogger() && this(log) && 
target(controller)") 
        public void loggerInitializer(JoinPoint jp, JoinPoint.StaticPart 
jps, Loggable log, Object controller) { 
                if (log.getLog().isDebugEnabled()) { 
                        if 
(controller.getClass().isAssignableFrom(BaseTabController.class)) { 
                                if 
(!((BaseTabController)controller).getTabId().equals(jp.getArgs()[0])) { 
 log.getLog().debug(jps.getSignature().getName() + " - Entering 
initializer... - " + buildParameters(jp.getArgs())); 
                                } 
                        } else { 
 log.getLog().debug(jps.getSignature().getName() + " - Entering 
initializer... - " + buildParameters(jp.getArgs())); 
                        } 
                } 
        } 

        @Around(value= "validateLogger() && this(log)") 
        public boolean loggerValidate(ProceedingJoinPoint pjp, JoinPoint 
jp, JoinPoint.StaticPart jps, Loggable log) throws Throwable { 
                Boolean result = (Boolean)pjp.proceed(); 
                if (log.getLog().isDebugEnabled()) { 
                        String param1 = (jp.getArgs() != null && 
jp.getArgs().length > 0) ? (" - param1: " + jp.getArgs()[0]) : ""; 
 log.getLog().debug(jps.getSignature().toShortString() + " - VALIDATE" + 
param1 + " - return: " + result); 
                } 
                return result; 
        } 
} 

Jean ANDRÉ 
_______________________________________________
aspectj-users mailing list
aspectj-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/aspectj-users

_______________________________________________
aspectj-users mailing list
aspectj-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to