本文整理汇总了Java中javax.management.MBeanServerFactory类的典型用法代码示例。如果您正苦于以下问题:Java MBeanServerFactory类的具体用法?Java MBeanServerFactory怎么用?Java MBeanServerFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MBeanServerFactory类属于javax.management包,在下文中一共展示了MBeanServerFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMBeanServer
import javax.management.MBeanServerFactory; //导入依赖的package包/类
/**
* Factory method to create (if necessary) and return our
* <code>MBeanServer</code> instance.
*
*/
public synchronized MBeanServer getMBeanServer() {
long t1=System.currentTimeMillis();
if (server == null) {
if( MBeanServerFactory.findMBeanServer(null).size() > 0 ) {
server = MBeanServerFactory.findMBeanServer(null).get(0);
if( log.isDebugEnabled() ) {
log.debug("Using existing MBeanServer " + (System.currentTimeMillis() - t1 ));
}
} else {
server = ManagementFactory.getPlatformMBeanServer();
if( log.isDebugEnabled() ) {
log.debug("Creating MBeanServer"+ (System.currentTimeMillis() - t1 ));
}
}
}
return (server);
}
示例2: findServer
import javax.management.MBeanServerFactory; //导入依赖的package包/类
/**
* Locate the MBean server to use based on user input from startup.
*
* @return The MBean server to use.
*/
private MBeanServer findServer() {
if ( usePlatformServer ) {
// they specified to use the platform (vm) server
return ManagementFactory.getPlatformMBeanServer();
}
// otherwise lookup all servers by (optional) agentId.
// IMPL NOTE : the findMBeanServer call treats a null agentId to mean match all...
ArrayList<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer( agentId );
if ( defaultDomain == null ) {
// they did not specify a domain by which to locate a particular MBeanServer to use, so chose the first
return mbeanServers.get( 0 );
}
for ( MBeanServer mbeanServer : mbeanServers ) {
// they did specify a domain, so attempt to locate an MBEanServer with a matching default domain, returning it
// if we find it.
if ( defaultDomain.equals( mbeanServer.getDefaultDomain() ) ) {
return mbeanServer;
}
}
return null;
}
示例3: invoke
import javax.management.MBeanServerFactory; //导入依赖的package包/类
private Object invoke(String objectName, String method, Object[] params, String[] types) throws Exception {
MBeanServer server = (MBeanServer) MBeanServerFactory.findMBeanServer(null).get(0);
ObjectName mbean = new ObjectName(objectName);
if (server == null) {
throw new Exception("Can't find mbean server");
}
getLog().info("invoking " + method);
return server.invoke(mbean, method, params, types);
}
示例4: monitorNotifications
import javax.management.MBeanServerFactory; //导入依赖的package包/类
/**
* Test the monitor notifications.
*/
public int monitorNotifications() throws Exception {
server = MBeanServerFactory.newMBeanServer();
MBeanServerForwarderInvocationHandler mbsfih =
(MBeanServerForwarderInvocationHandler)
Proxy.getInvocationHandler(server);
mbsfih.setGetAttributeException(
new RuntimeException("Test RuntimeException"));
domain = server.getDefaultDomain();
obsObjName = ObjectName.getInstance(domain + ":type=ObservedObject");
server.registerMBean(new ObservedObject(), obsObjName);
echo(">>> ----------------------------------------");
int error = counterMonitorNotification();
echo(">>> ----------------------------------------");
error += gaugeMonitorNotification();
echo(">>> ----------------------------------------");
error += stringMonitorNotification();
echo(">>> ----------------------------------------");
return error;
}
示例5: createServerSide
import javax.management.MBeanServerFactory; //导入依赖的package包/类
private JMXServiceURL createServerSide(Map<String, Object> serverMap)
throws Exception {
final int NINETY_SECONDS = 90;
System.out.println("SecurityTest::createServerSide: Start") ;
// Prepare server side security env
HashMap<String, Object> env = setServerSecurityEnv(serverMap);
// Create and start mbean server and connector server
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
cs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
cs.start();
// Waits availibility of connector server
Utils.waitReady(cs, NINETY_SECONDS);
JMXServiceURL addr = cs.getAddress();
System.out.println("SecurityTest::createServerSide: Done.") ;
return addr;
}
示例6: testPrivate
import javax.management.MBeanServerFactory; //导入依赖的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;
}
}
}
示例7: main
import javax.management.MBeanServerFactory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
if (System.getSecurityManager() == null)
throw new IllegalStateException("No security manager installed!");
System.out.println("java.security.policy=" +
System.getProperty("java.security.policy"));
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Register the MLetMBean
//
System.out.println("Create MLet MBean");
ObjectName mlet = new ObjectName("MLetTest:name=MLetMBean");
mbs.createMBean("javax.management.loading.MLet", mlet);
// Test OK!
//
System.out.println("Bye! Bye!");
}
示例8: testCaseProb
import javax.management.MBeanServerFactory; //导入依赖的package包/类
private static void testCaseProb() throws Exception {
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName name = new ObjectName("a:b=c");
mbs.registerMBean(new CaseProbImpl(), name);
CaseProbMXBean proxy = JMX.newMXBeanProxy(mbs, name, CaseProbMXBean.class);
try {
CaseProb prob = proxy.getCaseProb();
fail("No exception from proxy method getCaseProb");
} catch (IllegalArgumentException e) {
String messageChain = messageChain(e);
if (messageChain.contains("URLPath")) {
System.out.println("Message chain contains URLPath as required: "
+ messageChain);
} else {
fail("Exception chain for CaseProb does not mention property" +
" URLPath differing only in case");
System.out.println("Full stack trace:");
e.printStackTrace(System.out);
}
}
}
示例9: test
import javax.management.MBeanServerFactory; //导入依赖的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;
}
}
示例10: testNonCompliant
import javax.management.MBeanServerFactory; //导入依赖的package包/类
private static void testNonCompliant(Class<?> iface, Object bean) throws Exception {
try {
System.out.println("Registering a non-compliant MBean " +
iface.getName() + " ...");
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName on = new ObjectName("test:type=NonCompliant");
mbs.registerMBean(bean, on);
fail("Registered a non-compliant MBean - " + iface.getName());
} catch (Exception e) {
Throwable t = e;
while (t != null && !(t instanceof NotCompliantMBeanException)) {
t = t.getCause();
}
if (t != null) {
success("MBean not registered");
} else {
throw e;
}
}
}
示例11: testPrivate
import javax.management.MBeanServerFactory; //导入依赖的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;
}
}
}
示例12: testCompliant
import javax.management.MBeanServerFactory; //导入依赖的package包/类
private static void testCompliant(Class<?> iface, Object bean) throws Exception {
try {
System.out.println("Registering a compliant MBean " +
iface.getName() + " ...");
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName on = new ObjectName("test:type=Compliant");
mbs.registerMBean(bean, on);
success("Registered a compliant 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: getMBeanServer
import javax.management.MBeanServerFactory; //导入依赖的package包/类
/**
* Factory method to create (if necessary) and return our
* <code>MBeanServer</code> instance.
*
*/
public synchronized MBeanServer getMBeanServer() {
long t1 = System.currentTimeMillis();
if (server == null) {
if (MBeanServerFactory.findMBeanServer(null).size() > 0) {
server = MBeanServerFactory.findMBeanServer(null).get(0);
if (log.isDebugEnabled()) {
log.debug("Using existing MBeanServer " + (System.currentTimeMillis() - t1));
}
} else {
server = ManagementFactory.getPlatformMBeanServer();
if (log.isDebugEnabled()) {
log.debug("Creating MBeanServer" + (System.currentTimeMillis() - t1));
}
}
}
return (server);
}
示例14: registerToJMX
import javax.management.MBeanServerFactory; //导入依赖的package包/类
@Before
public void registerToJMX() throws Exception {
internalServer = MBeanServerFactory.createMBeanServer();
TestingFixedThreadPoolModuleFactory testingFixedThreadPoolConfigBeanFactory =
new TestingFixedThreadPoolModuleFactory();
threadPoolConfigBean = testingFixedThreadPoolConfigBeanFactory.createModule("", null, null);
threadPoolConfigBean.setThreadCount(threadCount);
AbstractDynamicWrapper dynamicWrapper = getDynamicWrapper(threadPoolConfigBean, MODULE_IDENTIFIER);
platformMBeanServer.registerMBean(dynamicWrapper, threadPoolDynamicWrapperON);
}
示例15: getMBeanServer
import javax.management.MBeanServerFactory; //导入依赖的package包/类
public static MBeanServer getMBeanServer() throws Exception {
if (mbeanServer == null) {
if (MBeanServerFactory.findMBeanServer(null).size() > 0) {
mbeanServer = MBeanServerFactory.findMBeanServer(null).get(0);
} else {
mbeanServer = MBeanServerFactory.createMBeanServer();
}
}
return mbeanServer;
}