Counter.java
01 /**
02  *
03  * All content copyright (c) 2003-2008 Terracotta, Inc.,
04  * except as may otherwise be noted in a separate copyright notice.
05  * All rights reserved.
06  *
07  */
08 package demo.jmx;
09 
10 import org.springframework.beans.factory.BeanNameAware;
11 
12 /**
13  *  Simple service bean
14  *
15  *@author    Terracotta, Inc.
16  */
17 public class Counter
18        implements BeanNameAware, ICounter {
19    private volatile int counter = 0;
20    private String name;
21 
22    public void setBeanName(String name) {
23       this.name = name;
24    }
25 
26    public int getCurrent() {
27       return counter;
28    }
29 
30    public String getName() {
31       return this.name;
32    }
33 
34    public int next() {
35       synchronized (this) {
36          return counter++;
37       }
38    }
39 }