I'm no expert, but here's some code to get you started if you'd like to
create an MBean called Foo:

1) Create an interface called FooMBean. It can be empty, but it will contain
method declarations for your accessor/mutator methods if you have any.


package com.example.FooMBean;

public interface FooMBean
{            
    public static final String OBJECT_NAME = ":service=FooExample";

    public void setFileName(String fileName);
    public String getFileName();
}

2) Next create a class named Foo that extends ServiceMBeanSupport and
implements MBeanRegistration and FooMBean and minimally implement the
following methods: getName, getObjectName, initService. The
ServiceMBeanSupport is an adaptor class that provides bare bones
implementations of methods like startService or stopServices that are called
as various stages of the MBeanlife cycle. You can override these methods to
add more functionality.

package com.example.Foo;

import org.jboss.util.ServiceMBeanSupport;
import javax.management.*;

public class Foo extends ServiceMBeanSupport implements MBeanRegistration,
FooMBean
{          
    ObjectName name;
    MBeanServer server;
    String fileName;
     
    public Foo(){ )

    public Foo(String fileName)
    {
        this.fileName = fileName;
    )
   
    // ServiceMBeanSupport implementation ----------------------------
    public ObjectName getObjectName(MBeanServer server, ObjectName name)
throws javax.management.MalformedObjectNameException
    {
        return name == null ? new ObjectName(OBJECT_NAME) : name;
    }
 
    public String getName()
    {
        return "Foo Exmaple";
    }
    
    public void initService() throws java.lang.Exception
    {
        System.out.println("FileName = " + fileName);
    }

    public void setFileName(String fileName)
    {
        this.fileName = fileName;
    }

    public String getFileName() { return this.fileName; }    
}

3) To use the MBean make the following entry in the jboss.conf file

<MLET CODE="com.example.Foo" ARCHIVE="foo.jar" CODEBASE="../../lib/ext/">
    <ARG TYPE="java.lang.String" VALUE="example.txt">
</MLET>

This form passes the file name into the constructor. You could also omit the
parameter:

<MLET CODE="com.example.Foo" ARCHIVE="foo.jar" CODEBASE="../../lib/ext/">
</MLET>

in which case you must also make an entry int he jboss.jcml file:

     <mbean code="com.example.Foo" name="DefaultDomain:service=FooExample">
       <attribute name="FileName">exmaple.file</attribute>
     </mbean>

4) Make sure you'r using the latest version of JBoss. The 2.0 version i used
seemed to overwrite the changes I made to the jboss.jcml file.

Hope this helps.

Jim

-----Original Message-----
From: Penn [mailto:[EMAIL PROTECTED]]
Sent: Friday, March 30, 2001 12:42 AM
To: [EMAIL PROTECTED]
Subject: RE: [JBoss-user] Custom MBeans


Hi,

i'm learning to create a MBean, may i know where/how to start....

thanks

Penn

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of joel
cordonnier
Sent: Friday, March 30, 2001 4:11 PM
To: [EMAIL PROTECTED]
Subject: Re: [JBoss-user] Custom MBeans


Do you use the 'Default' configuration or your own ?

Joel


--- James Kiryakoza <[EMAIL PROTECTED]> a écrit :
> I created a custom MBean to set up my Log4J
> configuration. The bean works
> fine, but when I try to pass it a parameter by
> including a reference to it
> in the Jboss.jcml file, the jcml file is always
> overwritten and my entry is
> deleted. Does anyone have any ideas as to why this
> is happening.
>
> Here is the entry I'm trying to place in the jcml
> file:
>
> <mbean name="Log4J:service=LogInitializer">
>        <attribute
> name="PropertyFile">EngageApps.log</attribute>
> </mbean>
>
>
>
> James Kiryakoza
> Engage Media
> 415-615-2752
> [EMAIL PROTECTED] <mailto:>
>
>
>
>

> ATTACHMENT part 2 image/jpeg name=Glacier Bkgrd.jpg



___________________________________________________________
Do You Yahoo!? -- Pour dialoguer en direct avec vos amis,
Yahoo! Messenger : http://fr.messenger.yahoo.com

_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user


_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to