package org.springframework.samples.petclinic.aspects;

import java.util.ArrayList;
import java.util.List;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

/**
 * Sample AspectJ annotation-style aspect that saves
 * every owner name requested to the clinic.
 *
 * @author Rod Johnson
 * @since 2.0
 */
@Aspect
public class UsageLogAspect {

	private int historySize = 100;

	// Of course saving all names is not suitable for
	// production use, but this is a simple example.
	private List<String> namesRequested = new ArrayList<String>(this.historySize);


	public void setHistorySize(int historySize) {
		this.historySize = historySize;
		this.namesRequested = new ArrayList<String>(historySize);
	}


	@Before("execution(* *.findOwners(String)) && args(name)")
	public synchronized void logNameRequest(String name) {
		// Not the most efficient implementation,
		// but we're aiming to illustrate the power of
		// @AspectJ AOP, not write perfect code here :-)
		if (this.namesRequested.size() > this.historySize) {
			namesRequested.remove(0);
		}
		this.namesRequested.add(name);
	}

	public List<String> getNamesRequested() {
		return this.namesRequested;
	}

}

@@ -597,16 +597,29 @@
 %09public 
+synchronized 
 void set
@@ -747,17 +747,16 @@
 e);%0A%09%7D%0A%0A
-%0A
 %09@Before
@@ -1065,16 +1065,21 @@
 e) %7B%0A%09%09%09
+this.
 namesReq
@@ -1145,16 +1145,29 @@
 %09public 
+synchronized 
 List%3CStr

use full synchronization