There is already an example of accessing the
MBeanServer via the RMIAdaptor.
You are looking for a non-external usage example of
the MBeanServer?
xxxxxxxxxxxxxxxxxxxxxxxx Scott Stark Chief Technology
Officer JBoss Group, LLC xxxxxxxxxxxxxxxxxxxxxxxx
----- Original Message -----
Sent: Thursday, November 14, 2002 3:31
PM
Subject: RE: [JBoss-user] Lookup
MBean
Cool,
Thanks.
We should
probably see about weaving that into the jboss3 book.
.peter
Peter,
For use in
your apps, the correct way is to get a reference to the MBeanServer and
invoke methods on the MBean by passing object name, method name, method
signature stuff to MBeanServer ref.
#1 for use when the calling code
is running in same JVM as MBeanServer: This is some simple code I
wrote to access one of my own MBean from a servlet: public class
FileSystem { public static void deleteFilesFromDirectory (String
path, String[] excludedExtentions) { try
{ Object[] args = new
Object[2]; args[0] =
path; args[1] =
excludedExtentions; String[] argClasses =
new String[2]; argClasses[0] =
"java.lang.String"; argClasses[1] =
"java.lang.String[]"; getServer().invoke
(getObjectName(), "deleteFilesFromDirectory", args,
argClasses); } catch (Exception
ex) {
} } private static
ObjectName getObjectName () throws Exception { return
new ObjectName ("Tes:service=FileSystemService"); }
private static MBeanServer getServer () throws Exception
{ return
(MBeanServer)MBeanServerFactory.findMBeanServer(null).iterator().next();
} }
#2 for use when the calling code is running in a different JVM
from the MBeanServer This is an example I wrote to access MBean from
main.
public class Client {
public static void main
(String[] args) throws Exception { try
{ // Set up jndi
properties Properties props = new
Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
props.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interfaces");
props.put(Context.PROVIDER_URL,
"jnp://localhost:1099"); InitialContext
ctx = new InitialContext(props);
System.out.println ("Got context");
//
Retrieve the RMI adaptor, can see this in jmx
console Object obj =
ctx.lookup("jmx:<machine
name>:rmi"); System.out.println ("Got
RMI Adapter");
ctx.close();
// Wrap it in a
connector RemoteMBeanServer server = new
RMIConnectorImpl((RMIAdaptor)obj);
//
add your code here to call invoke method on server just like
above. } catch (Exception ex)
{
ex.printStackTrace(); } } }
#3 for
calling simple methods on MBeanServer from html. See implementation of
jmx-console.
Hope this
helps.
Greg
Luttrell, Peter wrote:
I have a
custom JMX MBean.
What is the
'correct' way to look it up for use in my apps (webapps if it
matters)?
I know i
could manually bind it the jndi tree, or create a singleton like accessor
method, but what is considered the 'correct' way to access the
bean?
thanks.
.peter
This transmission contains information solely
for intended recipient and may be privileged, confidential and/or
otherwise protect from disclosure. If you are not the intended recipient,
please contact the sender and delete all copies of this transmission. This
message and/or the materials contained herein are not an offer to sell, or
a solicitation of an offer to buy, any securities or other instruments.
The information has been obtained or derived from sources believed by us
to be reliable, but we do not represent that it is accurate or complete.
Any opinions or estimates contained in this information constitute our
judgment as of this date and are subject to change without notice. Any
information you share with us will be used in the operation of our
business, and we do not request and do not want any material, nonpublic
information. Absent an express prior written agreement, we are not
agreeing to treat any information confidentially and will use any and all
information and reserve the right to publish or disclose any information
you share with us.
--
Greg Turner, JBoss Authorized Consultant
Tiburon Enterprise Systems
http://www.tiburon-e-systems.com
Box 1171
Tiburon, CA 94920
415-927-2543
This transmission contains information solely for
intended recipient and may be privileged, confidential and/or otherwise
protect from disclosure. If you are not the intended recipient, please contact
the sender and delete all copies of this transmission. This message and/or the
materials contained herein are not an offer to sell, or a solicitation of an
offer to buy, any securities or other instruments. The information has been
obtained or derived from sources believed by us to be reliable, but we do not
represent that it is accurate or complete. Any opinions or estimates contained
in this information constitute our judgment as of this date and are subject to
change without notice. Any information you share with us will be used in the
operation of our business, and we do not request and do not want any material,
nonpublic information. Absent an express prior written agreement, we are not
agreeing to treat any information confidentially and will use any and all
information and reserve the right to publish or disclose any information you
share with us.
|