本文整理汇总了Java中javax.management.MBeanServer类的典型用法代码示例。如果您正苦于以下问题:Java MBeanServer类的具体用法?Java MBeanServer怎么用?Java MBeanServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MBeanServer类属于javax.management包,在下文中一共展示了MBeanServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRMIRegistry
import javax.management.MBeanServer; //导入依赖的package包/类
private void createRMIRegistry() throws Exception {
if (!this.agentConfig.isRmiRegistryEnabled()) {
return;
}
MBeanServer mbs = getMBeanServer();
String host = this.agentConfig.getRmiBindAddress();
int port = this.agentConfig.getRmiPort();
/*
* Register and start the rmi-registry naming MBean, which is needed by JSR 160
* RMIConnectorServer
*/
ObjectName registryName = getRMIRegistryNamingName();
try {
RMIRegistryService registryNamingService = null;
if (host != null && !("".equals(host.trim()))) {
registryNamingService = new RMIRegistryService(host, port);
} else {
registryNamingService = new RMIRegistryService(port);
}
mbs.registerMBean(registryNamingService, registryName);
} catch (javax.management.InstanceAlreadyExistsException e) {
logger.info(LocalizedMessage.create(LocalizedStrings.AgentImpl_0__IS_ALREADY_REGISTERED,
registryName));
}
mbs.invoke(registryName, "start", null, null);
}
示例2: registerMBean
import javax.management.MBeanServer; //导入依赖的package包/类
@SuppressWarnings({
"unchecked", "rawtypes"
})
public static String registerMBean(final Object object) throws JMException {
final ObjectName objectName = generateMBeanName(object.getClass());
final MBeanServer context = ManagementFactory.getPlatformMBeanServer();
final String mbeanName = object.getClass().getName() + "MBean";
for (final Class c : object.getClass().getInterfaces()) {
if (mbeanName.equals(c.getName())) {
context.registerMBean(new AnnotatedStandardMBean(object, c), objectName);
return objectName.getCanonicalName();
}
}
context.registerMBean(object, objectName);
return objectName.getCanonicalName();
}
示例3: main
import javax.management.MBeanServer; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
RMIJRMPServerImplSub impl = new RMIJRMPServerImplSub();
System.out.println("Creating connectorServer");
connectorServer = new RMIConnectorServer(url, null, impl, mbs);
System.out.println("Starting connectorServer");
connectorServer.start();
System.out.println("Making client");
RMIConnection cc = impl.newClient(null);
System.out.println("Closing client");
cc.close();
if (connectorServer.isActive()) {
System.out.println("Stopping connectorServer");
connectorServer.stop();
}
if (failure == null)
System.out.println("TEST PASSED, no deadlock");
else
System.out.println("TEST FAILED");
}
示例4: initJvmRuntime
import javax.management.MBeanServer; //导入依赖的package包/类
/**
* Initialization of the "JvmRuntime" group.
*
* To disable support of this group, redefine the
* "createJvmRuntimeMetaNode()" factory method, and make it return "null"
*
* @param server MBeanServer for this group (may be null)
*
**/
protected void initJvmRuntime(MBeanServer server)
throws Exception {
final String oid = getGroupOid("JvmRuntime", "1.3.6.1.4.1.42.2.145.3.163.1.1.4");
ObjectName objname = null;
if (server != null) {
objname = getGroupObjectName("JvmRuntime", oid, mibName + ":name=sun.management.snmp.jvmmib.JvmRuntime");
}
final JvmRuntimeMeta meta = createJvmRuntimeMetaNode("JvmRuntime", oid, objname, server);
if (meta != null) {
meta.registerTableNodes( this, server );
// Note that when using standard metadata,
// the returned object must implement the "JvmRuntimeMBean"
// interface.
//
final JvmRuntimeMBean group = (JvmRuntimeMBean) createJvmRuntimeMBean("JvmRuntime", oid, objname, server);
meta.setInstance( group );
registerGroupNode("JvmRuntime", oid, objname, meta, group, server);
}
}
示例5: initJvmThreading
import javax.management.MBeanServer; //导入依赖的package包/类
/**
* Initialization of the "JvmThreading" group.
*
* To disable support of this group, redefine the
* "createJvmThreadingMetaNode()" factory method, and make it return "null"
*
* @param server MBeanServer for this group (may be null)
*
**/
protected void initJvmThreading(MBeanServer server)
throws Exception {
final String oid = getGroupOid("JvmThreading", "1.3.6.1.4.1.42.2.145.3.163.1.1.3");
ObjectName objname = null;
if (server != null) {
objname = getGroupObjectName("JvmThreading", oid, mibName + ":name=sun.management.snmp.jvmmib.JvmThreading");
}
final JvmThreadingMeta meta = createJvmThreadingMetaNode("JvmThreading", oid, objname, server);
if (meta != null) {
meta.registerTableNodes( this, server );
// Note that when using standard metadata,
// the returned object must implement the "JvmThreadingMBean"
// interface.
//
final JvmThreadingMBean group = (JvmThreadingMBean) createJvmThreadingMBean("JvmThreading", oid, objname, server);
meta.setInstance( group );
registerGroupNode("JvmThreading", oid, objname, meta, group, server);
}
}
示例6: createSnmpRequestHandler
import javax.management.MBeanServer; //导入依赖的package包/类
private void createSnmpRequestHandler(SnmpAdaptorServer server,
int id,
DatagramSocket s,
DatagramPacket p,
SnmpMibTree tree,
Vector<SnmpMibAgent> m,
InetAddressAcl a,
SnmpPduFactory factory,
SnmpUserDataFactory dataFactory,
MBeanServer f,
ObjectName n) {
final SnmpRequestHandler handler =
new SnmpRequestHandler(this, id, s, p, tree, m, a, factory,
dataFactory, f, n);
threadService.submitTask(handler);
}
示例7: ClientHandler
import javax.management.MBeanServer; //导入依赖的package包/类
public ClientHandler(CommunicatorServer server, int id, MBeanServer f, ObjectName n) {
adaptorServer = server ;
requestId = id ;
mbs = f ;
objectName = n ;
interruptCalled = false ;
dbgTag = makeDebugTag() ;
//if (mbs == null ){
//thread = new Thread (this) ;
thread = createThread(this);
//} else {
//thread = mbs.getThreadAllocatorSrvIf().obtainThread(objectName,this) ;
//}
// Note: the thread will be started by the subclass.
}
示例8: testPrivate
import javax.management.MBeanServer; //导入依赖的package包/类
private static void testPrivate(Class<?> iface) throws Exception {
try {
System.out.println("Creating a proxy for private M(X)Bean " +
iface.getName() + " ...");
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName on = new ObjectName("test:type=Proxy");
JMX.newMBeanProxy(mbs, on, iface);
success("Created a proxy for private M(X)Bean - " + iface.getName());
} catch (Exception e) {
Throwable t = e;
while (t != null && !(t instanceof NotCompliantMBeanException)) {
t = t.getCause();
}
if (t != null) {
fail("Proxy not created");
} else {
throw e;
}
}
}
示例9: testSecondaryWebUi
import javax.management.MBeanServer; //导入依赖的package包/类
@Test
public void testSecondaryWebUi()
throws IOException, MalformedObjectNameException,
AttributeNotFoundException, MBeanException,
ReflectionException, InstanceNotFoundException {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName mxbeanName = new ObjectName(
"Hadoop:service=SecondaryNameNode,name=SecondaryNameNodeInfo");
String[] checkpointDir = (String[]) mbs.getAttribute(mxbeanName,
"CheckpointDirectories");
Assert.assertArrayEquals(checkpointDir, snn.getCheckpointDirectories());
String[] checkpointEditlogDir = (String[]) mbs.getAttribute(mxbeanName,
"CheckpointEditlogDirectories");
Assert.assertArrayEquals(checkpointEditlogDir,
snn.getCheckpointEditlogDirectories());
}
示例10: preRegister
import javax.management.MBeanServer; //导入依赖的package包/类
/**
* Initialization of the MIB with AUTOMATIC REGISTRATION in Java DMK.
*/
public ObjectName preRegister(MBeanServer server, ObjectName name)
throws Exception {
// Allow only one initialization of the MIB.
//
if (isInitialized == true) {
throw new InstanceAlreadyExistsException();
}
// Initialize MBeanServer information.
//
this.server = server;
populate(server, name);
isInitialized = true;
return name;
}
示例11: register
import javax.management.MBeanServer; //导入依赖的package包/类
public static ManagedConnection register ( final ManagedConnection connection, final SocketAddress socketAddress, final String baseName )
{
try
{
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer ();
logger.debug ( "Creating name for: {}", socketAddress );
final String remote = URLEncoder.encode ( socketAddress.toString (), "UTF-8" );
final ObjectName name = new ObjectName ( baseName, "remote", remote );
connection.setName ( name );
mbs.registerMBean ( connection, name );
return connection;
}
catch ( final Exception e )
{
logger.warn ( "Failed to register MXBean", e );
return null;
}
}
示例12: testPrivate
import javax.management.MBeanServer; //导入依赖的package包/类
private static void testPrivate(Class<?> iface, Object bean) throws Exception {
try {
System.out.println("Registering a private MBean " +
iface.getName() + " ...");
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName on = new ObjectName("test:type=Compliant");
mbs.registerMBean(bean, on);
success("Registered a private MBean - " + iface.getName());
} catch (Exception e) {
Throwable t = e;
while (t != null && !(t instanceof NotCompliantMBeanException)) {
t = t.getCause();
}
if (t != null) {
fail("MBean not registered");
} else {
throw e;
}
}
}
示例13: test
import javax.management.MBeanServer; //导入依赖的package包/类
private static boolean test(Object mbean, boolean expectImmutable)
throws Exception {
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName on = new ObjectName("a:b=c");
mbs.registerMBean(mbean, on);
MBeanInfo mbi = mbs.getMBeanInfo(on);
Descriptor d = mbi.getDescriptor();
String immutableValue = (String) d.getFieldValue("immutableInfo");
boolean immutable = ("true".equals(immutableValue));
if (immutable != expectImmutable) {
System.out.println("FAILED: " + mbean.getClass().getName() +
" -> " + immutableValue);
return false;
} else {
System.out.println("OK: " + mbean.getClass().getName());
return true;
}
}
示例14: preRegister
import javax.management.MBeanServer; //导入依赖的package包/类
private static ObjectName preRegister(
DynamicMBean mbean, MBeanServer mbs, ObjectName name)
throws InstanceAlreadyExistsException, MBeanRegistrationException {
ObjectName newName = null;
try {
if (mbean instanceof MBeanRegistration)
newName = ((MBeanRegistration) mbean).preRegister(mbs, name);
} catch (Throwable t) {
throwMBeanRegistrationException(t, "in preRegister method");
}
if (newName != null) return newName;
else return name;
}
示例15: createServer
import javax.management.MBeanServer; //导入依赖的package包/类
/**
* Create and configure (if necessary) and return the
* <code>MBeanServer</code> with which we will be
* registering our <code>DynamicMBean</code> implementations.
*/
public synchronized static MBeanServer createServer() {
if (mserver == null) {
try {
mserver = Registry.getRegistry(null, null).getMBeanServer();
} catch (Throwable t) {
t.printStackTrace(System.out);
System.exit(1);
}
}
return (mserver);
}