1 /*
2  * Copyright 2002-2008 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 
17 package org.springframework.jmx.export.annotation;
18 
19 import org.springframework.jmx.IJmxTestBean;
20 import org.springframework.jmx.support.MetricType;
21 import org.springframework.stereotype.Service;
22 
23 /**
24  * @author Rob Harrop
25  * @author Juergen Hoeller
26  */
27 @Service("testBean")
28 @ManagedResource(objectName = "bean:name=testBean4", description = "My Managed Bean", log = true,
29 		logFile = "jmx.log", currencyTimeLimit = 15, persistPolicy = "OnUpdate", persistPeriod = 200,
30 		persistLocation = "./foo", persistName = "bar.jmx")
31 @ManagedNotifications({@ManagedNotification(name="My Notification", notificationTypes={"type.foo", "type.bar"})})
32 public class AnnotationTestBean implements IJmxTestBean {
33 
34 	private String name;
35 
36 	private String nickName;
37 
38 	private int age;
39 
40 	private boolean isSuperman;
41 
42 
43 	@ManagedAttribute(description = "The Age Attribute", currencyTimeLimit = 15)
getAge()44 	public int getAge() {
45 		return age;
46 	}
47 
setAge(int age)48 	public void setAge(int age) {
49 		this.age = age;
50 	}
51 
52 	@ManagedOperation(currencyTimeLimit = 30)
myOperation()53 	public long myOperation() {
54 		return 1L;
55 	}
56 
57 	@ManagedAttribute(description = "The Name Attribute",
58 			currencyTimeLimit = 20,
59 			defaultValue = "bar",
60 			persistPolicy = "OnUpdate")
setName(String name)61 	public void setName(String name) {
62 		this.name = name;
63 	}
64 
65 	@ManagedAttribute(defaultValue = "foo", persistPeriod = 300)
getName()66 	public String getName() {
67 		return name;
68 	}
69 
70 	@ManagedAttribute(description = "The Nick Name Attribute")
setNickName(String nickName)71 	public void setNickName(String nickName) {
72 		this.nickName = nickName;
73 	}
74 
getNickName()75 	public String getNickName() {
76 		return this.nickName;
77 	}
78 
setSuperman(boolean superman)79 	public void setSuperman(boolean superman) {
80 		this.isSuperman = superman;
81 	}
82 
83 	@ManagedAttribute(description = "The Is Superman Attribute")
isSuperman()84 	public boolean isSuperman() {
85 		return isSuperman;
86 	}
87 
88 	@org.springframework.jmx.export.annotation.ManagedOperation(description = "Add Two Numbers Together")
89 	@ManagedOperationParameters({@ManagedOperationParameter(name="x", description="Left operand"),
90 	@ManagedOperationParameter(name="y", description="Right operand")})
add(int x, int y)91 	public int add(int x, int y) {
92 		return x + y;
93 	}
94 
95 	/**
96 	 * Test method that is not exposed by the MetadataAssembler.
97 	 */
dontExposeMe()98 	public void dontExposeMe() {
99 		throw new RuntimeException();
100 	}
101 
102 	@ManagedMetric(description="The QueueSize metric", currencyTimeLimit = 20, persistPolicy="OnUpdate", persistPeriod=300,
103 			category="utilization", metricType = MetricType.COUNTER, displayName="Queue Size", unit="messages")
getQueueSize()104 	public long getQueueSize() {
105 		return 100l;
106 	}
107 
108 	@ManagedMetric
getCacheEntries()109 	public int getCacheEntries() {
110 		return 3;
111 	}
112 
113 
114 
115 }
116