1 4 package com.tctest.spring.bean; 5 6 import org.aopalliance.intercept.MethodInvocation; 7 import org.springframework.aop.support.DelegatingIntroductionInterceptor; 8 9 10 public class CounterSaverMixin extends DelegatingIntroductionInterceptor implements CounterSaver { 11 12 private int savedCounter; 13 14 synchronized public void saveCounter() { 15 } 17 18 public int getSavedCounter() { 19 return savedCounter; 20 } 21 22 public Object invoke(MethodInvocation invocation) throws Throwable { 23 String name = invocation.getMethod().getName(); 24 if ("saveCounter".equals(name)) { 25 synchronized(this) { 26 savedCounter = ((ISingleton) invocation.getThis()).getCounter(); 27 } 28 return null; 29 } else { 30 return super.invoke(invocation); 31 } 32 } 33 34 } 35 36 | Popular Tags |