Chinaunix首页 | 论坛 | 博客
  • 博客访问: 754215
  • 博文数量: 160
  • 博客积分: 2516
  • 博客等级: 大尉
  • 技术积分: 1511
  • 用 户 组: 普通用户
  • 注册时间: 2004-10-24 17:58
文章分类

全部博文(160)

文章存档

2019年(2)

2018年(3)

2017年(15)

2016年(3)

2015年(11)

2014年(3)

2013年(1)

2012年(3)

2011年(17)

2010年(25)

2009年(17)

2008年(13)

2007年(14)

2006年(21)

2005年(10)

2004年(2)

分类: Java

2005-10-09 14:16:06

任务由JBOSS服务器启动而启动,停止而停止. (jboss-4.0.1sp1)

jboss-4.0.1sp1serverdefaultdeploy

----jmxtest.sar

        ----com.example.mbeans.*      //all classes file

        ----META-INF

             ----jboss-service.xml 


HelloMBean.java

package com.example.mbeans;
 
 
public interface HelloMBean {
 
    public void sayHello();
    public int add(int x, int y);
 
    public String getName();
 
    public int getCacheSize();
    public void setCacheSize(int size);
   
    public void start() throws Exception;
    public void stop() throws Exception;
}


Hello.java

package com.example.mbeans;
import javax.management.*;

public class Hello
        extends NotificationBroadcasterSupport implements HelloMBean {
 
 public void start() throws Exception{
  System.out.println("-------------------------------------start()");
 }
 
 public void stop() throws Exception{
  System.out.println("-------------------------------------stop()");
 }
 
    public void sayHello() {
        System.out.println("hello, world");
    }
 
    public int add(int x, int y) {
        return x + y;
    }
 
    public String getName() {
        return this.name;
    }
 
    public int getCacheSize() {
        return this.cacheSize;
    }
 
    public synchronized void setCacheSize(int size) {
//        int oldSize = this.cacheSize;
        this.cacheSize = size;
 
        System.out.println("Cache size now " + this.cacheSize);
 
//        Notification n =
//            new AttributeChangeNotification(this,
//         sequenceNumber++,
//         System.currentTimeMillis(),
//         "CacheSize changed",
//         "CacheSize",
//         "int",
//         oldSize,
//         this.cacheSize);
//
// sendNotification(n);
    }
 
    public MBeanNotificationInfo[] getNotificationInfo() {
        String[] types = new String[] {
            AttributeChangeNotification.ATTRIBUTE_CHANGE
        };
        String name = AttributeChangeNotification.class.getName();
        String description = "An attribute of this MBean has changed";
        MBeanNotificationInfo info =
            new MBeanNotificationInfo(types, name, description);
        return new MBeanNotificationInfo[] {info};
    }

 
    private final String name = "Reginald";
    private int cacheSize = DEFAULT_CACHE_SIZE;
    private static final int DEFAULT_CACHE_SIZE = 200;
 
//    private long sequenceNumber = 1;
}


jboss-service.xml


 
  Hello Service Jason
 


阅读(2377) | 评论(0) | 转发(0) |
0

上一篇:WEB 计划任务

下一篇:网吧CMD

给主人留下些什么吧!~~