Version 3

    JBoss EJB 3.0 and Extensions

     

    &12488;&12524;&12452;&12523;&65300;&65306;JMX&12469;&12540;&12499;&12473;&12458;&12502;&12472;&12455;&12463;&12488;&65288;JMX Service Objects&65289;

     

    &12399;&12376;&12417;&12395;&65288;Introduction&65289;

     

    JMX MBean services are the core building blocks of the JBoss Application Server. Developers can specify dependency between MBean services so that they are started in a particular order when the server starts, which makes them especially suitable for implementing the server's internal infrastructure services. A lot of JBoss internal services are implemented as MBeans. They communicate with each other via the internal JMX bus (i.e., the JBoss JMX Microkernel). MBeans also provide a unified management interface for JBoss administrators to manage the JBoss internal services.

     

    JMX MBean&12469;&12540;&12499;&12473;&12399;JBoss&12450;&12503;&12522;&12465;&12540;&12471;&12519;&12531;&12469;&12540;&12496;&12434;&24418;&25104;&12377;&12427;&37325;&35201;&12394;&12469;&12540;&12499;&12473;&12391;&12377;&12290;&38283;&30330;&32773;&12399;&12289;MBean&12469;&12540;&12499;&12473;&21516;&22763;&12398;&20381;&23384;&38306;&20418;&12434;&25351;&23450;&12375;&12289;&12469;&12540;&12496;&36215;&21205;&26178;&12395;&27491;&12375;&12356;&38918;&30058;&12391;&12469;&12540;&12499;&12473;&12364;&36215;&21205;&12377;&12427;&12424;&12358;&12395;&25351;&23450;&12391;&12365;&12414;&12377;&12290;&12414;&12383;&12289;&12371;&12428;&12399;&12469;&12540;&12496;&12398;&20869;&37096;&12469;&12540;&12499;&12473;&12434;&23455;&35013;&12377;&12427;&12398;&12395;&29305;&12395;&26368;&36969;&12391;&12377;&12290;JBoss&12398;&20869;&37096;&12469;&12540;&12499;&12473;&12398;&22810;&12367;&12399;MBean&12392;&12375;&12390;&23455;&35013;&12373;&12428;&12390;&12356;&12414;&12377;&12290;&12469;&12540;&12499;&12473;&21516;&22763;&12399;&20869;&37096;JMX&12496;&12473;&65288;&12388;&12414;&12426;JBoss JMX&12510;&12452;&12463;&12525;&12459;&12540;&12493;&12523;&65289;&12434;&36890;&12375;&12390;&12362;&20114;&12356;&12395;&36890;&20449;&12375;&12414;&12377;&12290;MBean&12399;&12289;JBoss&12398;&20869;&37096;&12469;&12540;&12499;&12473;&12434;&31649;&29702;&12377;&12427;JBoss&31649;&29702;&32773;&12398;&12383;&12417;&12398;&32113;&19968;&12373;&12428;&12383;&31649;&29702;&12452;&12531;&12479;&12501;&12455;&12540;&12473;&12418;&25552;&20379;&12375;&12414;&12377;&12290;

     

    Different from EJB services, which are provided by a pool of managed objects, a JMX MBean service is provided by a singleton object in the server JVM. This service object is stateful and has an application-wide scope.

     

    &31649;&29702;&12458;&12502;&12472;&12455;&12463;&12488;&12398;&12503;&12540;&12523;&12363;&12425;&25552;&20379;&12373;&12428;&12427;EJB&12469;&12540;&12499;&12473;&12392;&30064;&12394;&12426;&12289;JMX MBean&12399;&12469;&12540;&12496;&12398;JVM&12391;&21336;&29420;&65288;singleton&65289;&12458;&12502;&12472;&12455;&12463;&12488;&12392;&12375;&12390;&25552;&20379;&12373;&12428;&12414;&12377;&12290;&12469;&12540;&12499;&12473;&12458;&12502;&12472;&12455;&12463;&12488;&12399;&12473;&12486;&12540;&12488;&12501;&12523;&12391;&12289;&12450;&12503;&12522;&12465;&12540;&12471;&12519;&12531;&20840;&20307;&12391;&26377;&21177;&12391;&12377;&12290;

     

    While MBean services are very useful, developing them is not trivial. In a regular JMX server environment, you need to extend numerous framework classes and work with reflection-like APIs. However, in the JBoss EJB 3.0 server, you can use simple annotations to configure POJOs and make them available as MBean services. In this trail, you will learn how to develop EJB 3.0 style MBean services. The annotations covered in this trail are JBoss-specific. They are beyond the scope of the official EJB 3.0 specification.

     

    MBean&12469;&12540;&12499;&12473;&12399;&12392;&12390;&12418;&26377;&29992;&12391;&12377;&12364;&12289;&38283;&30330;&12399;&31777;&21336;&12391;&12399;&12354;&12426;&12414;&12379;&12435;&12290;&36890;&24120;&12398;JMX&12469;&12540;&12496;&29872;&22659;&12391;&12399;&12289;&12383;&12367;&12373;&12435;&12398;&12501;&12524;&12540;&12512;&12527;&12540;&12463;&12463;&12521;&12473;&12434;&25313;&24373;&12375;&12289;&12522;&12501;&12524;&12463;&12471;&12519;&12531;&12398;&12424;&12358;&12394;API&12434;&20351;&29992;&12375;&12394;&12369;&12428;&12400;&12394;&12426;&12414;&12379;&12435;&12290;&19968;&26041;&12289;JBoss EJB 3.0&12469;&12540;&12496;&12391;&12399;&31777;&21336;&12394;&12450;&12494;&12486;&12540;&12471;&12519;&12531;&12434;&20351;&12387;&12390;&12289;POJO&12434;MBean&12469;&12540;&12499;&12473;&12395;&12377;&12427;&12371;&12392;&12364;&12391;&12365;&12414;&12377;&12290;&12371;&12398;&12488;&12524;&12452;&12523;&12391;&12399;&12289;EJB 3.0&12473;&12479;&12452;&12523;&12398;MBean&12469;&12540;&12499;&12473;&12398;&38283;&30330;&12395;&12388;&12356;&12390;&23398;&12403;&12414;&12377;&12290;&12371;&12398;&12488;&12524;&12452;&12523;&12391;&23398;&12406;&12450;&12494;&12486;&12540;&12471;&12519;&12531;&12399;JBoss&22266;&26377;&12391;&12377;&12290;&27491;&24335;&12394;EJB 3.0&20181;&27096;&12398;&31684;&22258;&12395;&12399;&21547;&12414;&12428;&12390;&12356;&12414;&12379;&12435;&12290;

     

    &12469;&12531;&12503;&12523;&12450;&12503;&12522;&12465;&12540;&12471;&12519;&12531;&65288;The Sample Application&65289;

     

    In this trail, we create a MBean service to perform the investment calculation. To illustrate the manageability aspect of the service, the calculator has a fixed investment growth rate. The growth rate can be changed by an administrator via the JMX management server.

     

    &12371;&12398;&12488;&12524;&12452;&12523;&12391;&12399;&12289;&25237;&36039;&35336;&31639;&12434;&34892;&12358;MBean&12469;&12540;&12499;&12473;&12434;&20316;&25104;&12375;&12414;&12377;&12290;&12469;&12540;&12499;&12473;&12398;&31649;&29702;&30340;&12394;&20596;&38754;&12434;&32057;&20171;&12377;&12427;&12383;&12417;&12395;&12289;&35336;&31639;&12503;&12525;&12464;&12521;&12512;&12391;&12399;&25104;&38263;&29575;&12399;&22266;&23450;&12395;&12375;&12390;&12356;&12414;&12377;&12290;&25104;&38263;&29575;&12399;&12289;&31649;&29702;&32773;&12364;JMX&31649;&29702;&12469;&12540;&12496;&12434;&36890;&12375;&12390;&22793;&26356;&12375;&12414;&12377;&12290;

     

    The client application obtains a reference of the MBean singleton object from the container via the JMX API and makes use of its calculation services. Click on the following button to open calculator application in a new window, the JSP page connects to the session bean and uses it to calculate the investment.

     

    &12463;&12521;&12452;&12450;&12531;&12488;&12450;&12503;&12522;&12465;&12540;&12471;&12519;&12531;&12399;&12289;JMX API&12434;&20351;&12387;&12390;&12467;&12531;&12486;&12490;&12363;&12425;MBean&12398;&21336;&29420;&12458;&12502;&12472;&12455;&12463;&12488;&12398;&21442;&29031;&12434;&21462;&24471;&12375;&12289;&35336;&31639;&12469;&12540;&12499;&12473;&12434;&21033;&29992;&12375;&12414;&12377;&12290;&19979;&12398;&12508;&12479;&12531;&12434;&12463;&12522;&12483;&12463;&12375;&12390;&12289;&21029;&12454;&12451;&12531;&12489;&12454;&12391;&35336;&31639;&12503;&12525;&12464;&12521;&12512;&12434;&36215;&21205;&12375;&12390;&12415;&12390;&12367;&12384;&12373;&12356;&12290;JSP&12506;&12540;&12472;&12364;&12475;&12483;&12471;&12519;&12531;Bean&12395;&12450;&12463;&12475;&12473;&12375;&12289;&25237;&36039;&35336;&31639;&12434;&34892;&12356;&12414;&12377;&12290;

     

    &12300;JMX&29256;&12398;&35336;&31639;&12503;&12525;&12464;&12521;&12512;&12434;&36215;&21205;&12375;&12390;&12415;&12427;&12301;

     

    To change the growth rate of the calculator (i.e., manage the service), you need to use the JMX management console. Since most server's JMX console is secured, it is difficult to demonstrate this feature on a hosted server. Instead, I made a flash movie to show how to use the JMX console to manage the calculator application and change the growth rate (or interest rate). Please click on the button below to view the movie.

     

    &35336;&31639;&12503;&12525;&12464;&12521;&12512;&12398;&25104;&38263;&29575;&12434;&22793;&26356;&12377;&12427;&12395;&12399;&65288;&12388;&12414;&12426;&12289;&12469;&12540;&12499;&12473;&12434;&31649;&29702;&12377;&12427;&12395;&12399;&65289;&12289;JMX&31649;&29702;&12467;&12531;&12477;&12540;&12523;&12434;&20351;&29992;&12375;&12414;&12377;&12290;&36890;&24120;&12289;JMX&12467;&12531;&12477;&12540;&12523;&12399;&12450;&12463;&12475;&12473;&21046;&38480;&12373;&12428;&12390;&12356;&12427;&12383;&12417;&12289;&36939;&29992;&20013;&12398;&12469;&12540;&12496;&12391;&12371;&12398;&27231;&33021;&12434;&12362;&35211;&12379;&12377;&12427;&12398;&12399;&22256;&38627;&12391;&12377;&12290;&12381;&12371;&12391;&12289;&12501;&12521;&12483;&12471;&12517;&12512;&12540;&12499;&12540;&12434;&20351;&12387;&12390;&12289;&31649;&29702;&12467;&12531;&12477;&12540;&12523;&12391;&35336;&31639;&12450;&12503;&12522;&12465;&12540;&12471;&12519;&12531;&12434;&31649;&29702;&12375;&12289;&25104;&38263;&29575;&65288;&21033;&29575;&65289;&12434;&22793;&26356;&12377;&12427;&12392;&12371;&12429;&12434;&12372;&35239;&12356;&12383;&12384;&12365;&12414;&12377;&12290;&19979;&12398;&12508;&12479;&12531;&12434;&12463;&12522;&12483;&12463;&12375;&12390;&12512;&12540;&12499;&12540;&12434;&12372;&35239;&12367;&12384;&12373;&12356;&12290;

     

    &12300;JMX&12391;&35336;&31639;&12503;&12525;&12464;&12521;&12512;&12434;&31649;&29702;&12377;&12427;&12301;

     

    If you deploy the TrailBlazer application on your own server and have access to the JMX console, you can find the calculator MBean at the bottom of the page http://localhost:8080/jmx-console/ and scroll all the way down to the bottom. You can also perform the investment calculation directly from the JMX interface by invoking the calculate() method with appropriate parameters.

     

    &12372;&33258;&20998;&12398;&12469;&12540;&12496;&12395;TrailBlazer&12450;&12503;&12522;&12465;&12540;&12471;&12519;&12531;&12434;&12487;&12503;&12525;&12452;&12375;&12289;JMX&12467;&12531;&12477;&12540;&12523;&12395;&12450;&12463;&12475;&12473;&12391;&12365;&12427;&22580;&21512;&12399;&12289;http://localhost:8080/jmx-console/&12506;&12540;&12472;&12398;&19979;&12398;&12411;&12358;&12395;calculator MBean&12364;&35211;&12360;&12427;&12399;&12378;&12391;&12377;&12290;&12506;&12540;&12472;&12398;&26368;&19979;&37096;&12414;&12391;&12473;&12463;&12525;&12540;&12523;&12375;&12390;&12367;&12384;&12373;&12356;&12290;&12414;&12383;&12289;calculate()&12513;&12477;&12483;&12489;&12395;&36969;&20999;&12394;&24341;&25968;&12434;&25351;&23450;&12377;&12427;&12371;&12392;&12395;&12424;&12387;&12390;&12289;JMX&12467;&12531;&12477;&12540;&12523;&12363;&12425;&30452;&25509;&25237;&36039;&35336;&31639;&12434;&34892;&12358;&12371;&12392;&12418;&12391;&12365;&12414;&12377;&12290;

     

    MBean&31649;&29702;&12452;&12531;&12479;&12501;&12455;&12540;&12473;&65288;The MBean management interface&65289;

     

    The MBeans management interface is the outward interface of the MBean service. It exposes all the attributes and methods that can be accessed by the MBean service client as well as the JMX management console. Under the EJB 3.0 programming model, an MBean management interface is just a plain old Java interface similiar to a session bean interface. The following code snippet shows that the Calculator interface defines a Growthrate MBean attribute and a calculate() MBean method.

     

    MBean&31649;&29702;&12452;&12531;&12479;&12501;&12455;&12540;&12473;&12399;&12289;MBean&12469;&12540;&12499;&12473;&12398;&22806;&21521;&12365;&12398;&12452;&12531;&12479;&12501;&12455;&12540;&12473;&12391;&12377;&12290;MBean&12469;&12540;&12499;&12473;&12398;&12463;&12521;&12452;&12450;&12531;&12488;&12420;JMX&31649;&29702;&12467;&12531;&12477;&12540;&12523;&12363;&12425;&12450;&12463;&12475;&12473;&21487;&33021;&12394;&23646;&24615;&12420;&12513;&12477;&12483;&12489;&12434;&20844;&38283;&12375;&12414;&12377;&12290;EJB 3.0&12503;&12525;&12464;&12521;&12511;&12531;&12464;&12514;&12487;&12523;&12395;&12362;&12356;&12390;&12399;&12289;MBean&31649;&29702;&12452;&12531;&12479;&12501;&12455;&12540;&12473;&12399;&12475;&12483;&12471;&12519;&12531;Bean&12452;&12531;&12479;&12501;&12455;&12540;&12473;&12392;&21516;&12376;&12424;&12358;&12395;&12289;&21336;&12394;&12427;Java&12452;&12531;&12479;&12501;&12455;&12540;&12473;&12391;&12377;&12290;&20197;&19979;&12398;&12467;&12540;&12489;&12398;&25244;&31883;&12391;&12399;&12289;Calculator&12452;&12531;&12479;&12501;&12455;&12540;&12473;&12391;&12289;Growthrate&23646;&24615;&12392;calculate()&12513;&12477;&12483;&12489;&12434;&23450;&32681;&12375;&12390;&12356;&12414;&12377;&12290;

     

     public interface Calculator {
     
       // Attribute
       public void setGrowthrate (double g);
       public double getGrowthrate ();
     
       // The management method
       public double calculate (int start, int end, double saving);
     
       // Life cycle method
       public void create () throws Exception;
       public void destroy () throws Exception;
     }
    

     

    The management interface also defines MBean life cycle methods. You can define any combination of the following methods.

     

    &31649;&29702;&12452;&12531;&12479;&12501;&12455;&12540;&12473;&12399;MBean&12398;&12521;&12452;&12501;&12469;&12452;&12463;&12523;&12513;&12477;&12483;&12489;&12418;&23450;&32681;&12375;&12414;&12377;&12290;&20197;&19979;&12398;&12513;&12477;&12483;&12489;&12434;&32068;&12415;&21512;&12431;&12379;&12390;&23450;&32681;&12375;&12414;&12377;&12290;

     

    • create() -- called by the server when the service is created and all the services it depends upon have been created too. At this point the service (and all the services it depends on) is installed in the JMX server, but is not yet fully functional.

     

    • create() -- &12469;&12540;&12499;&12473;&12392;&12289;&20381;&23384;&12375;&12390;&12356;&12427;&12377;&12409;&12390;&12398;&12469;&12540;&12499;&12473;&12364;&29983;&25104;&12373;&12428;&12383;&12392;&12365;&12395;&12469;&12540;&12496;&12363;&12425;&21628;&12400;&12428;&12414;&12377;&12290;&12371;&12398;&26178;&28857;&12391;&12399;&12289;&12469;&12540;&12499;&12473;&65288;&12362;&12424;&12403;&20381;&23384;&12375;&12390;&12356;&12427;&12377;&12409;&12390;&12398;&12469;&12540;&12499;&12473;&65289;&12399;JMX&12469;&12540;&12496;&12395;&12452;&12531;&12473;&12488;&12540;&12523;&12373;&12428;&12390;&12356;&12414;&12377;&12364;&12289;&12414;&12384;&27231;&33021;&12375;&12414;&12379;&12435;&12290;

     

    • start() -- called by the server when the service is started and all the services it depends upon have been started too. At this point the service (and all the services it depends on) is fully functional.

     

    • start() -- &12469;&12540;&12499;&12473;&12392;&12289;&20381;&23384;&12375;&12390;&12356;&12427;&12377;&12409;&12390;&12398;&12469;&12540;&12499;&12473;&12364;&36215;&21205;&12373;&12428;&12383;&12392;&12365;&12395;&12469;&12540;&12496;&12363;&12425;&21628;&12400;&12428;&12414;&12377;&12290;&12371;&12398;&26178;&28857;&12391;&12399;&12289;&12469;&12540;&12499;&12473;&65288;&12362;&12424;&12403;&20381;&23384;&12375;&12390;&12356;&12427;&12377;&12409;&12390;&12398;&12469;&12540;&12499;&12473;&65289;&12399;&20840;&27231;&33021;&12364;&20351;&29992;&21487;&33021;&12391;&12377;&12290;

     

    • stop() -- called by the server when the service is stopped. At this point the service (and all the services that depend on it) is no longer fully operational.

     

    • stop() -- &12469;&12540;&12499;&12473;&12364;&20572;&27490;&12375;&12383;&12392;&12365;&12395;&12469;&12540;&12496;&12363;&12425;&21628;&12400;&12428;&12414;&12377;&12290;&12371;&12398;&26178;&28857;&12391;&12399;&12289;&12469;&12540;&12499;&12473;&65288;&12362;&12424;&12403;&20381;&23384;&12375;&12390;&12356;&12427;&12377;&12409;&12390;&12398;&12469;&12540;&12499;&12473;{FOOTNOTE DEF 1 1}&65289;&12399;&12418;&12399;&12420;&27231;&33021;&12375;&12414;&12379;&12435;&12290;

     

    {FOOTNOTE RED #1 1} &12300;&12362;&12424;&12403;&12381;&12398;&12469;&12540;&12499;&12473;&12395;&20381;&23384;&12375;&12390;&12356;&12427;&12377;&12409;&12390;&12398;&12469;&12540;&12499;&12473;&12301;&12371;&12371;&12384;&12369;&24847;&21619;&12364;&36949;&12358;&12435;&12391;&12377;&12424;&12397; -tokobayashi

     

    • destroy() -- called by the server when the service is destroyed and removed from the MBean server.

     

    • destroy() -- &12469;&12540;&12499;&12473;&12364;&30772;&26820;&12373;&12428;&12289;MBean&12469;&12540;&12496;&12363;&12425;&21066;&38500;&12373;&12428;&12427;&12392;&12365;&12395;&12469;&12540;&12496;&12363;&12425;&21628;&12400;&12428;&12414;&12377;&12290;

     

    MBean&12398;&23455;&35013;&65288;The MBean implementation&65289;

     

    The MBean implementation class simply implements the MBean management interface. It has to be annotated with the @Service tag, so that JBoss knows to register it with the JMX server. The objectName annotation attribute specifies the service name under which this MBean service registers. The @Management annotation specifies which interface is the management interface. This way, you can have multiple local, remote, and management interfaces for the same bean class. So, from the JMX console, you can find this MBean via the name trail:service=calculator.

     

    MBean&23455;&35013;&12463;&12521;&12473;&12399;MBean&31649;&29702;&12452;&12531;&12479;&12501;&12455;&12540;&12473;&12434;&23455;&35013;&12377;&12427;&12384;&12369;&12391;&12377;&12290;JBoss&12399;@Service&12479;&12464;&12391;&12450;&12494;&12486;&12540;&12471;&12519;&12531;&12373;&12428;&12383;&12463;&12521;&12473;&12434;JMX&12469;&12540;&12496;&12395;&30331;&37682;&12375;&12414;&12377;&12290;&12450;&12494;&12486;&12540;&12471;&12519;&12531;&12398;objectName&23646;&24615;&12391;&12289;&12371;&12398;MBean&12469;&12540;&12499;&12473;&12364;&30331;&37682;&12377;&12427;&12469;&12540;&12499;&12473;&21517;&12434;&25351;&23450;&12375;&12414;&12377;&12290;@Management&12450;&12494;&12486;&12540;&12471;&12519;&12531;&12391;&31649;&29702;&12452;&12531;&12479;&12501;&12455;&12540;&12473;&12434;&25351;&23450;&12375;&12414;&12377;&12290;&12388;&12414;&12426;&12289;&21516;&12376;Bean&12463;&12521;&12473;&12395;&23550;&12375;&12390;&12289;&12525;&12540;&12459;&12523;&12452;&12531;&12479;&12501;&12455;&12540;&12473;&12289;&12522;&12514;&12540;&12488;&12452;&12531;&12479;&12501;&12455;&12540;&12473;&12289;&31649;&29702;&12452;&12531;&12479;&12501;&12455;&12540;&12473;&12398;&35079;&25968;&12398;&12452;&12531;&12479;&12501;&12455;&12540;&12473;&12434;&23450;&32681;&12391;&12365;&12427;&12398;&12391;&12377;&12290;JMX&12467;&12531;&12477;&12540;&12523;&12391;&12399;&12289;trail:service=calculator&12398;&21517;&21069;&12391;&12371;&12398;MBean&12434;&21442;&29031;&12391;&12365;&12414;&12377;&12290;

     

     @Service (objectName="trail:service=calculator")
     @Management(Calculator.class)
     public class CalculatorMBean implements Calculator {
     
       double growthrate;
     
       public void setGrowthrate (double growthrate) {
         this.growthrate = growthrate;
       }
     
       public double getGrowthrate () {
         return growthrate;
       }
     
       public double calculate (int start, int end, double saving) {
         double tmp =
             Math.pow(1. + growthrate / 12., 12. * (end - start) + 1);
         return saving * 12. * (tmp - 1) / growthrate;
       }
     
       // Lifecycle methods
       public void create() throws Exception {
         growthrate = 0.08;
         System.out.println("Calculator - Creating");
       }
     
       public void destroy() {
         System.out.println("Calculator - Destroying");
       }
     }
    

     

    The create() method is called by the JMX server to set the initial values of the Growthrate attribute when the MBean service singleton is created.

     

    MBean&12469;&12540;&12499;&12473;&12398;&21336;&29420;&12458;&12502;&12472;&12455;&12463;&12488;&12364;&29983;&25104;&12373;&12428;&12427;&12392;&12289;JMX&12469;&12540;&12496;&12363;&12425;create()&12513;&12477;&12483;&12489;&12364;&21628;&12400;&12428;&12289;Growthrate&23646;&24615;&12395;&21021;&26399;&20516;&12364;&35373;&23450;&12373;&12428;&12414;&12377;&12290;

     

    MBean&12469;&12540;&12499;&12473;&12434;&20351;&12358;&65288;Use the MBean service&65289;

     

    To use the MBean service, you first need to find its service singleton stub (or "proxy") via the service name. JBoss JMX provides several convenient methods to do that as shown below.

     

    MBean&12469;&12540;&12499;&12473;&12434;&21033;&29992;&12377;&12427;&12395;&12399;&12289;&12414;&12378;&12469;&12540;&12499;&12473;&21517;&12391;&12469;&12540;&12499;&12473;&12398;&21336;&29420;&12458;&12502;&12472;&12455;&12463;&12488;&65288;&12414;&12383;&12399;&12503;&12525;&12461;&12471;&65289;&12434;&26908;&32034;&12375;&12414;&12377;&12290;JBoss JMX&12391;&12399;&12371;&12398;&12424;&12358;&12394;&20966;&29702;&12434;&34892;&12358;&20197;&19979;&12398;&12424;&12358;&12394;&20415;&21033;&12394;&12513;&12477;&12483;&12489;&12434;&29992;&24847;&12375;&12390;&12356;&12414;&12377;&12290;

     

     private Calculator cal = null;
     
     public void jspInit () {
         try {
             MBeanServer server = MBeanServerLocator.locate();
     
             cal = (Calculator) MBeanProxyExt.create(
                 Calculator.class,
                 "trail:service=calculator",
                 server);
         } catch (Exception e) {
             e.printStackTrace ();
         }
     }
    

     

    Now, you can simply invoke the MBean's service and management methods.

     

    &12371;&12371;&12391;&12289;MBean&12469;&12540;&12499;&12473;&12392;&31649;&29702;&12513;&12477;&12483;&12489;&12434;&21628;&12403;&20986;&12377;&12371;&12392;&12364;&12391;&12365;&12414;&12377;&12290;

     

     result = nf.format(cal.calculate(start, end, saving));
    

     

    MBean&38291;&12398;&20381;&23384;&38306;&20418;&65288;Dependency between MBeans&65289;

     

    An important feature of MBean services is that you can specify the dependency between MBeans so that certain services are only started after other services have already successfully started. You can use the @Depends annotation to declare that an MBean is dependent on another MBean.

     

    MBean&12469;&12540;&12499;&12473;&12398;&37325;&35201;&12394;&27231;&33021;&12398;&12402;&12392;&12388;&12399;&12289;MBean&38291;&12398;&20381;&23384;&38306;&20418;&12434;&25351;&23450;&12375;&12390;&12289;&20182;&12398;&12469;&12540;&12499;&12473;&12364;&27491;&12375;&12367;&36215;&21205;&12373;&12428;&12390;&12356;&12427;&22580;&21512;&12395;&12398;&12415;&12289;&12354;&12427;&12469;&12540;&12499;&12473;&12434;&36215;&21205;&12377;&12427;&12424;&12358;&12395;&12391;&12365;&12427;&12371;&12392;&12391;&12377;&12290;@Depends&12450;&12494;&12486;&12540;&12471;&12519;&12531;&12391;&12289;&20381;&23384;&12375;&12390;&12356;&12427;MBean&12434;&25351;&23450;&12375;&12414;&12377;&12290;

     

     @Service (objectName="trail:service=investmentAdvisor")
     @Depends ("trail:service=calculator")
     public class InvestmentAdvisorMBean implements InvestmentAdvisor {
         // ... ...
     }
    

     

    Or, an MBean can be dependent on a list of other MBeans.

     

    &12354;&12427;&12356;&12399;&12289;MBean&12364;&20381;&23384;&12377;&12427;MBean&12398;&19968;&35239;&12434;&25351;&23450;&12377;&12427;&12371;&12392;&12418;&12391;&12365;&12414;&12377;&12290;

     

     @Service (objectName="trail:service=investmentAdvisor")
     @Depends ({"trail:service=calculator",
                "trail:service=riskAnalysis"})
     public class InvestmentAdvisorMBean implements InvestmentAdvisor {
         // ... ...
     }
    

     

    If an attribute of an MBean itself is another MBean, the @Depends annotation on the attribute setter method would cause the container to automatically inject the dependent MBean object (setter dependency injection). In the following example, the container calls the setCalculator() method with the right parameter once the trail:service=calculator MBean is started. The Calculator attribute in the InvestmentAdvisor MBean automatically has the correct value without any explicit lookup code.

     

    MBean&12364;&25345;&12388;&23646;&24615;&12364;&21029;&12398;MBean&12398;&22580;&21512;&12289;&12381;&12398;&23646;&24615;&12398;&12475;&12483;&12479;&12540;&12513;&12477;&12483;&12489;&12395;@Depends&12450;&12494;&12486;&12540;&12471;&12519;&12531;&12434;&20351;&29992;&12377;&12427;&12371;&12392;&12391;&12289;&12467;&12531;&12486;&12490;&12399;&33258;&21205;&30340;&12395;&20381;&23384;&12377;&12427;MBean&12458;&12502;&12472;&12455;&12463;&12488;&12395;&20381;&23384;&24615;&12434;&27880;&20837;&12375;&12414;&12377;&65288;&35373;&23450;&20381;&23384;&12398;&27880;&20837;&65289;&12290;&19979;&12398;&20363;&12391;&12399;&12289;trail:service=calculator&12398;MBean&12364;&36215;&21205;&12373;&12428;&12427;&12392;&12289;&12467;&12531;&12486;&12490;&12399;&36969;&20999;&12394;&24341;&25968;&12391;setCalculator()&12513;&12477;&12483;&12489;&12434;&21628;&12403;&12414;&12377;&12290;InvestmentAdvisor&12398;MBean&12398;Calculator&23646;&24615;&12399;&12289;&26126;&31034;&30340;&12394;&12523;&12483;&12463;&12450;&12483;&12503;&12434;&34892;&12431;&12394;&12367;&12390;&12418;&33258;&21205;&30340;&12395;&27491;&12375;&12356;&20516;&12364;&35373;&23450;&12373;&12428;&12414;&12377;&12290;

     

     @Service (objectName="trail:service=investmentAdvisor")
     public class InvestmentAdvisorMBean implements InvestmentAdvisor {
     
         @Depends ("trail:service=calculator")
         public void setCalculator (Calculator calculator) {
           this.calculator = calculator;
         }
     
         // ... ...
     }
    

     

    &12477;&12540;&12473;&12467;&12540;&12489;&21442;&29031;&65288;Complete code reference&65289;

     

    JMX&12469;&12540;&12496;&65288;JMX server&65289;

     

    • Calculator.java: The MBean management interface

    • CalculatorMBean.java: The MBean implementation

     

    • Calculator.java: MBean&31649;&29702;&12452;&12531;&12479;&12501;&12455;&12540;&12473;

    • CalculatorMBean.java: MBean&23455;&35013;

     

    JMX&12463;&12521;&12452;&12450;&12531;&12488;&65288;JMX client&65289;

     

    • calculator.jsp: The client of the calculator MBean

     

    • calculator.jsp: &35336;&31639;&12503;&12525;&12464;&12521;&12512;MBean&12398;&12463;&12521;&12452;&12450;&12531;&12488;

     

    &12414;&12392;&12417;&65288;Summary&65289;

     

    In this trail, you learned how to develop JMX MBean services using simple EJB 3.0 style annotations. MBean services are very useful when you need to provide manageable services to other components or services inside the JBoss application server. In the next trail, we discuss another type services: message driven services.

     

    &12371;&12398;&12488;&12524;&12452;&12523;&12391;&12399;&12289;&31777;&21336;&12394;EJB 3.0&12473;&12479;&12452;&12523;&12398;&12450;&12494;&12486;&12540;&12471;&12519;&12531;&12434;&20351;&12387;&12390;JMX MBean&12469;&12540;&12499;&12473;&12434;&38283;&30330;&12377;&12427;&26041;&27861;&12434;&23398;&12403;&12414;&12375;&12383;&12290;JBoss&12450;&12503;&12522;&12465;&12540;&12471;&12519;&12531;&12469;&12540;&12496;&12398;&20869;&37096;&12469;&12540;&12499;&12473;&12420;&20182;&12398;&12467;&12531;&12509;&12540;&12493;&12531;&12488;&12395;&23550;&12375;&12390;&31649;&29702;&21487;&33021;&12394;&12469;&12540;&12499;&12473;&12434;&25552;&20379;&12377;&12427;&12395;&12399;MBean&12469;&12540;&12499;&12473;&12399;&12392;&12390;&12418;&26377;&21177;&12391;&12377;&12290;&27425;&12398;&12488;&12524;&12452;&12523;&12391;&12399;&12289;&12418;&12358;&19968;&12388;&12398;&12479;&12452;&12503;&12398;&12469;&12540;&12499;&12473;&12391;&12354;&12427;&12513;&12483;&12475;&12540;&12472;&39366;&21205;&22411;&12469;&12540;&12499;&12473;&12395;&12388;&12356;&12390;&35696;&35542;&12375;&12414;&12377;&12290;

     

    (c) 2005 JBoss, Inc. All Rights Reserved