geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Geronimo Knowledge Base > ¿Es posible obtener una referencia al MBeanServer desde un GBean?
Date Fri, 25 Jan 2013 11:38:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=GMOxKB&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=26331">¿Es
posible obtener una referencia al MBeanServer desde un GBean?</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~gawor">Jarek
Gawor</a>
    </h4>
        <br/>
                         <h4>Changes (0)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <style type='text/css'>/*<![CDATA[*/
table.ScrollbarTable  {border: none;padding: 3px;width: 100%;padding: 3px;margin: 0px;background-color:
#f0f0f0}
table.ScrollbarTable td.ScrollbarPrevIcon {text-align: center;width: 16px;border: none;}
table.ScrollbarTable td.ScrollbarPrevName {text-align: left;border: none;}
table.ScrollbarTable td.ScrollbarParent {text-align: center;border: none;}
table.ScrollbarTable td.ScrollbarNextName {text-align: right;border: none;}
table.ScrollbarTable td.ScrollbarNextIcon {text-align: center;width: 16px;border: none;}

/*]]>*/</style><div class="Scrollbar"><table class='ScrollbarTable'><tr><td
width='33%' class='ScrollbarPrevName'>&nbsp;</td><td width='33%' class='ScrollbarParent'><sup><a
href="/confluence/display/GMOxKB/Desarrollo+de+GBean"><img border='0' align='middle'
src='/confluence/images/icons/up_16.gif' width='8' height='8'></a></sup><a
href="/confluence/display/GMOxKB/Desarrollo+de+GBean">Desarrollo de GBean</a></td><td
width='33%' class='ScrollbarNextName'>&nbsp;</td></tr></table></div>

<p>Si.  Simplemente agrega una referencia de tipo MBeanServerReference a tu GBeanInfo,
e invoca a <tt>getMBeanServer()</tt> en la referencia para obtener al MBeanServer.
 Por ejemplo:</p>

<div class="code panel" style="border-style: solid;border-width: 1px;"><div class="codeContent
panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class Example {
    <span class="code-keyword">public</span> MEJB(AbstractName abstractName, MBeanServerReference
mbeanServerReference) {
        MBeanServer mbeanServer = mbeanServerReference.getMBeanServer());
    }

    <span class="code-keyword">public</span> <span class="code-keyword">static</span>
<span class="code-keyword">final</span> GBeanInfo GBEAN_INFO;
    <span class="code-keyword">static</span> {
        GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(Example.class);
        infoBuilder.addReference(<span class="code-quote">"MBeanServerReference"</span>,
MBeanServerReference.class);

        infoBuilder.setConstructor(<span class="code-keyword">new</span> <span
class="code-object">String</span>[]{<span class="code-quote">"MBeanServerReference"</span>});

        GBEAN_INFO = infoBuilder.getBeanInfo();
    }

    <span class="code-keyword">public</span> <span class="code-keyword">static</span>
GBeanInfo getGBeanInfo() {
        <span class="code-keyword">return</span> GBEAN_INFO;
    }
}
</pre>
</div></div>

<p>A continuación se muestra la configuración xml para ejemplo previo:</p>

<div class="code panel" style="border-style: solid;border-width: 1px;"><div class="codeContent
panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;module xmlns=<span class="code-quote">"http://geronimo.apache.org/xml/ns/deployment-1.1"</span>&gt;</span>
  <span class="code-tag">&lt;environment&gt;</span>

    <span class="code-tag">&lt;moduleId&gt;</span>
      <span class="code-tag">&lt;groupId&gt;</span>myco<span class="code-tag">&lt;/groupId&gt;</span>
      <span class="code-tag">&lt;artifactId&gt;</span>myco<span class="code-tag">&lt;/artifactId&gt;</span>
      <span class="code-tag">&lt;version&gt;</span>1.0<span class="code-tag">&lt;/version&gt;</span>
      <span class="code-tag">&lt;type&gt;</span>car<span class="code-tag">&lt;/type&gt;</span>
    <span class="code-tag">&lt;/moduleId&gt;</span>

    <span class="code-tag">&lt;dependencies&gt;</span>
      <span class="code-tag">&lt;dependency&gt;</span>
        <span class="code-tag">&lt;groupId&gt;</span>geronimo<span
class="code-tag">&lt;/groupId&gt;</span>
        <span class="code-tag">&lt;artifactId&gt;</span>rmi-naming<span
class="code-tag">&lt;/artifactId&gt;</span>
        <span class="code-tag">&lt;type&gt;</span>car<span class="code-tag">&lt;/type&gt;</span>
      <span class="code-tag">&lt;/dependency&gt;</span>
    <span class="code-tag">&lt;/dependencies&gt;</span>

  <span class="code-tag">&lt;/environment&gt;</span>

  <span class="code-tag">&lt;gbean name=<span class="code-quote">"Example"</span>
class=<span class="code-quote">"com.myco.Example"</span>&gt;</span>
      <span class="code-tag">&lt;reference name=<span class="code-quote">"MBeanServerReference"</span>&gt;</span>
          <span class="code-tag">&lt;name&gt;</span>MBeanServerReference<span
class="code-tag">&lt;/name&gt;</span>
      <span class="code-tag">&lt;/reference&gt;</span>
  <span class="code-tag">&lt;/gbean&gt;</span>
<span class="code-tag">&lt;/module&gt;</span>
</pre>
</div></div> 
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=26331">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=26331&revisedVersion=3&originalVersion=2">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=26331&showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message