alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Spring Framework example source code file (UsageLogAspect.java)

This example Spring Framework source code file (UsageLogAspect.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Spring Framework tags/keywords

arraylist, arraylist, aspect, aspect, before, before, list, list, usagelogaspect, util

The Spring Framework UsageLogAspect.java source code

package org.springframework.samples.petclinic.aspects;

import java.util.ArrayList;
import java.util.Collections;
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
 * @author Juergen Hoeller
 * @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(this.historySize);


	public synchronized 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) {
			this.namesRequested.remove(0);
		}
		this.namesRequested.add(name);
	}

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

}

Other Spring Framework examples (source code examples)

Here is a short list of links related to this Spring Framework UsageLogAspect.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.