1 /***
2 *
3 * Copyright RAJD Consultancy Ltd
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of 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 distributed under the License is distributed on
11 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 * specific language governing permissions and limitations under the License.
13 *
14 */
15 package org.logicblaze.lingo.jmx.remote;
16
17 import javax.management.MBeanAttributeInfo;
18 import javax.management.MBeanOperationInfo;
19 import javax.management.MBeanParameterInfo;
20 import mx4j.AbstractDynamicMBean;
21 /***
22 * This is based haviliy on the DynamicService example from the mx4j project
23 *
24 * @version $Revision: 1.3 $
25 */
26 public class SimpleService extends AbstractDynamicMBean implements Runnable{
27 private boolean running;
28 private int simpleCounter=0;
29 private int simpleValue = 0;
30
31 public void start(){
32 if(!running){
33 running=true;
34 Thread thread=new Thread(this);
35 thread.start();
36 }
37 }
38
39 public void stop(){
40 running=false;
41 }
42
43 public void run(){
44 while(running){
45 simpleCounter++;
46 try{
47 Thread.sleep(250);
48 }catch(InterruptedException e){
49 e.printStackTrace();
50 }
51 }
52 }
53
54 /***
55 * @param simpleCounter
56 * The simpleCounter to set.
57 */
58 public void setSimpleCounter(int simpleCounter){
59 this.simpleCounter=simpleCounter;
60 }
61
62 /***
63 * @return Returns the simpleCounter.
64 */
65 public int getSimpleCounter(){
66 return simpleCounter;
67 }
68
69 /***
70 * @return Returns the simpleValue.
71 */
72 public int getSimpleValue(){
73 return simpleValue;
74 }
75
76 /***
77 * @param simpleValue The simpleValue to set.
78 */
79 public void setSimpleValue(int simpleValue){
80 this.simpleValue=simpleValue;
81 }
82
83
84 protected MBeanAttributeInfo[] createMBeanAttributeInfo(){
85 return new MBeanAttributeInfo[] {
86 new MBeanAttributeInfo("SimpleCounter","int","test simpleCounter",true,false,false),
87 new MBeanAttributeInfo("SimpleValue","int","test simpleValue",true,true,false) };
88 }
89
90 protected MBeanOperationInfo[] createMBeanOperationInfo(){
91 return new MBeanOperationInfo[] {
92 new MBeanOperationInfo("start","Starts the SimpleService",new MBeanParameterInfo[0],"void",
93 MBeanOperationInfo.ACTION),
94 new MBeanOperationInfo("stop","Stops the SimpleService",new MBeanParameterInfo[0],"void",
95 MBeanOperationInfo.ACTION) };
96 }
97
98
99 }