Example usage for javax.management.openmbean CompositeData get

List of usage examples for javax.management.openmbean CompositeData get

Introduction

In this page you can find the example usage for javax.management.openmbean CompositeData get.

Prototype

public Object get(String key);

Source Link

Document

Returns the value of the item whose name is key .

Usage

From source file:com.streamsets.datacollector.http.JMXJsonServlet.java

private void writeObject(JsonGenerator jg, Object value) throws IOException {
    if (value == null) {
        jg.writeNull();/*w  w w  . jav a2 s  . c om*/
    } else {
        Class<?> c = value.getClass();
        if (c.isArray()) {
            jg.writeStartArray();
            int len = Array.getLength(value);
            for (int j = 0; j < len; j++) {
                Object item = Array.get(value, j);
                writeObject(jg, item);
            }
            jg.writeEndArray();
        } else if (value instanceof Number) {
            Number n = (Number) value;
            jg.writeNumber(n.toString());
        } else if (value instanceof Boolean) {
            Boolean b = (Boolean) value;
            jg.writeBoolean(b);
        } else if (value instanceof CompositeData) {
            CompositeData cds = (CompositeData) value;
            CompositeType comp = cds.getCompositeType();
            Set<String> keys = comp.keySet();
            jg.writeStartObject();
            for (String key : keys) {
                writeAttribute(jg, key, cds.get(key));
            }
            jg.writeEndObject();
        } else if (value instanceof TabularData) {
            TabularData tds = (TabularData) value;
            jg.writeStartArray();
            for (Object entry : tds.values()) {
                writeObject(jg, entry);
            }
            jg.writeEndArray();
        } else if (value instanceof GaugeValue) {
            ((GaugeValue) value).serialize(jg);
        } else {
            jg.writeString(value.toString());
        }
    }
}

From source file:dk.netarkivet.harvester.harvesting.controller.JMXHeritrixController.java

/** Get the name of the one job we let this Heritrix run.  The handling
 * of done jobs depends on Heritrix not being in crawl.  This call
 * may take several seconds to finish.//ww w .j ava2s  .  c o m
 *
 * @return The name of the one job that Heritrix has.
 * @throws IOFailure if the job created failed to initialize or didn't
 * appear in time.
 * @throws IllegalState if more than one job in done list,
 *  or more than one pending job
 */
private String getJobName() {
    /* This is called just after we've told Heritrix to create a job.
     * It may take a while before the job is actually created, so we have
     * to wait around a bit.
     */
    TabularData pendingJobs = null;
    TabularData doneJobs;
    int retries = 0;
    while (retries++ < JMXUtils.getMaxTries()) {
        // If the job turns up in Heritrix' pending jobs list, it's ready
        pendingJobs = (TabularData) executeHeritrixCommand(PENDING_JOBS_COMMAND);
        if (pendingJobs != null && pendingJobs.size() > 0) {
            break; // It's ready, we can move on.
        }

        // If there's an error in the job configuration, the job will be put
        // in Heritrix' completed jobs list.
        doneJobs = (TabularData) executeHeritrixCommand(COMPLETED_JOBS_COMMAND);
        if (doneJobs != null && doneJobs.size() >= 1) {
            // Since we haven't allowed Heritrix to start any crawls yet,
            //  the only way the job could have ended and then put into 
            //  the list of completed jobs is by error.
            if (doneJobs.size() > 1) {
                throw new IllegalState("More than one job in done list: " + doneJobs);
            } else {
                CompositeData job = JMXUtils.getOneCompositeData(doneJobs);
                throw new IOFailure("Job " + job + " failed: " + job.get(STATUS_ATTRIBUTE));
            }
        }
        if (retries < JMXUtils.getMaxTries()) {
            TimeUtils.exponentialBackoffSleep(retries);
        }
    }
    // If all went well, we now have exactly one job in the pending
    // jobs list.
    if (pendingJobs == null || pendingJobs.size() == 0) {
        throw new IOFailure("Heritrix has not created a job after "
                + (Math.pow(2, JMXUtils.getMaxTries()) / 1000) + " seconds, giving up.");
    } else if (pendingJobs.size() > 1) {
        throw new IllegalState("More than one pending job: " + pendingJobs);
    } else {
        // Note that we may actually get through to here even if the job
        // is malformed.  The job will then die as soon as we tell it to
        // start crawling.
        CompositeData job = JMXUtils.getOneCompositeData(pendingJobs);
        String name = job.get(JmxUtils.NAME) + "-" + job.get(UID_PROPERTY);
        log.info("Heritrix created a job with name " + name);
        return name;
    }
}

From source file:org.wso2.carbon.analytics.jmx.agent.tasks.JmxTask.java

private ArrayList<Object> getMBeansDetail(JmxAgent jmxAgent) {
    ArrayList<Object> arrayList = new ArrayList<Object>();
    JMXConnector jmxConnector = null;

    try {//from   w ww . ja  v a 2 s.  c o m
        jmxConnector = jmxAgent.openJmxConnection();

        MBean[] mBeans = jmxAgent.getProfile().getSelectedMBeans();
        Object attrValue;
        for (MBean mBean : mBeans) {
            for (MBeanAttribute mBeanAttribute : mBean.getAttributes()) {
                // If MBean is a composite.
                if (mBeanAttribute.getProperties() != null) {
                    CompositeData cd = (CompositeData) jmxAgent.getAttribute(jmxConnector, mBean.getMBeanName(),
                            mBeanAttribute.getAttributeName());

                    for (MBeanAttributeProperty mBeanAttributeProperty : mBeanAttribute.getProperties()) {
                        attrValue = cd.get(mBeanAttributeProperty.getPropertyName());
                        addMBeanDetail(arrayList, attrValue);
                    }
                } else {
                    attrValue = jmxAgent.getAttribute(jmxConnector, mBean.getMBeanName(),
                            mBeanAttribute.getAttributeName());
                    addMBeanDetail(arrayList, attrValue);
                }
            }
        }
    } catch (JmxConnectionException e) {
        log.error("Jmx Connection Exception", e);
        return null;
    } catch (JmxMBeanException e) {
        log.error("Jmx MBean exception", e);
        return null;
    } finally {
        if (jmxConnector != null) {
            try {
                jmxAgent.closeJmxConnection(jmxConnector);
            } catch (JmxConnectionException e) {
                log.error("Unable to close JMX connection.", e);
            }
        }
    }
    return arrayList;
}

From source file:com.adobe.acs.tools.explain_query.impl.ExplainQueryServlet.java

private JSONArray compositeQueryDataToJSON(Collection<CompositeData> queries) throws JSONException {
    final JSONArray jsonArray = new JSONArray();

    for (CompositeData query : queries) {
        Long duration = (Long) query.get("duration");
        Integer occurrenceCount = (Integer) query.get("occurrenceCount");
        String language = (String) query.get("language");
        String statement = (String) query.get("statement");

        if (!ArrayUtils.contains(LANGUAGES, language)) {
            // Not a supported language
            continue;
        } else if (StringUtils.startsWithIgnoreCase(statement, "EXPLAIN ")
                || StringUtils.startsWithIgnoreCase(statement, "MEASURE ")) {
            // Don't show EXPLAIN or MEASURE queries
            continue;
        }/*from   www  .  j  a  v  a2  s.  c  o m*/

        final JSONObject json = new JSONObject();

        try {
            json.put("duration", duration);
            json.put("language", language);
            json.put("occurrenceCount", occurrenceCount);
            json.put("statement", statement);

            jsonArray.put(json);
        } catch (JSONException e) {
            log.warn("Could not add query to results [ {} ]", statement);
            continue;
        }
    }

    return jsonArray;
}

From source file:org.wso2.carbon.analytics.jmx.agent.tasks.JmxTask.java

private String createStreamDefinition(String streamName, String version, JmxAgent jmxAgent,
        DataPublisher dataPublisher) throws MalformedURLException, StreamDefinitionException,
        DifferentStreamDefinitionAlreadyDefinedException, AgentException, MalformedStreamDefinitionException,
        JmxConnectionException, JmxMBeanException {

    StringBuilder stringBuilder = new StringBuilder();

    stringBuilder.append("{'name':'").append(streamName).append("',").append("  'version':'").append(version)
            .append("',").append("  'nickName': 'JMX Dump',").append("  'description': 'JMX monitoring data',")
            .append("  'metaData':[").append("          {'name':'clientType','type':'STRING'},")
            .append("          {'name':'host','type':'STRING'}").append("  ],").append("  'payloadData':[");

    JMXConnector jmxConnector = null;

    try {//from w  w  w  . j  a  v a2s  .c  o m
        jmxConnector = jmxAgent.openJmxConnection();

        MBean[] mBeans = jmxAgent.getProfile().getSelectedMBeans();
        //add the attributes
        Object attrValue;
        for (MBean mBean : mBeans) {
            for (MBeanAttribute mBeanAttribute : mBean.getAttributes()) {

                // If MBean is a composite.
                if (mBeanAttribute.getProperties() != null) {
                    CompositeData cd = (CompositeData) jmxAgent.getAttribute(jmxConnector, mBean.getMBeanName(),
                            mBeanAttribute.getAttributeName());

                    for (MBeanAttributeProperty mBeanAttributeProperty : mBeanAttribute.getProperties()) {
                        attrValue = cd.get(mBeanAttributeProperty.getPropertyName());
                        appendColumnName(stringBuilder, attrValue, mBeanAttributeProperty.getAliasName());
                    }
                } else {
                    attrValue = jmxAgent.getAttribute(jmxConnector, mBean.getMBeanName(),
                            mBeanAttribute.getAttributeName());
                    appendColumnName(stringBuilder, attrValue, mBeanAttribute.getAliasName());
                }
            }
        }

        //to delete the last comma
        stringBuilder.deleteCharAt(stringBuilder.length() - 1);
        stringBuilder.append("  ]}");

    } finally {
        if (jmxConnector != null) {
            try {
                jmxAgent.closeJmxConnection(jmxConnector);
            } catch (JmxConnectionException e) {
                log.error("Unable to close Jmx connection.", e);
            }
        }

        return dataPublisher.defineStream(stringBuilder.toString());
    }
}

From source file:org.red5.server.scope.Scope.java

/**
 * Allows for reconstruction via CompositeData.
 * /*from   w w w  . jav a  2  s .c o  m*/
 * @param cd composite data
 * @return Scope class instance
 */
public static Scope from(CompositeData cd) {
    IScope parent = null;
    ScopeType type = ScopeType.UNDEFINED;
    String name = null;
    boolean persistent = false;
    if (cd.containsKey("parent")) {
        parent = (IScope) cd.get("parent");
    }
    if (cd.containsKey("type")) {
        type = (ScopeType) cd.get("type");
    }
    if (cd.containsKey("name")) {
        name = (String) cd.get("name");
    }
    if (cd.containsKey("persistent")) {
        persistent = (Boolean) cd.get("persistent");
    }
    return new Scope(new Builder(parent, type, name, persistent));
}

From source file:org.eclipse.virgo.server.svt.hostedrepo.RemoteHostedRepositoryOtherThan8080Tests.java

@Test
public void testUnscopedPlanThatDependsUponArtifactsInRemoteHostedRepo() throws IOException, Exception {
    signature = new String[] { String.class.getName() };
    params = new Object[] { new File(APP_URI_PLAN_UNSCOPED).toURI().toString() };
    CompositeData compositeData = deploy(signature, params);
    artifactName4 = compositeData.get("symbolicName").toString();
    artifactType4 = compositeData.get("type").toString();
    artifactVersion4 = compositeData.get("version").toString();

    waitForMBeanRegister(artifactType4, artifactName4, artifactVersion4, HALF_SECOND, TWO_MINUTES);
    assertArtifactExists(artifactType4, artifactName4, artifactVersion4);
    assertArtifactState(artifactType4, artifactName4, artifactVersion4, "ACTIVE");
}

From source file:org.eclipse.virgo.server.svt.hostedrepo.RemoteHostedRepositoryOtherThan8080Tests.java

@Test
public void testDeploymentOfSharedServicesWarDependsOnArtfiactsInUnscopedPlan() throws IOException, Exception {
    signature = new String[] { String.class.getName() };
    params = new Object[] { new File(APP_URI_SHAREDSERVICES_WAR1).toURI().toString() };
    CompositeData compositeData = deploy(signature, params);
    artifactName5 = compositeData.get("symbolicName").toString();
    artifactType5 = compositeData.get("type").toString();
    artifactVersion5 = compositeData.get("version").toString();

    waitForMBeanRegister(artifactType5, artifactName5, artifactVersion5, HALF_SECOND, TWO_MINUTES);
    UrlWaitLatch.waitFor("http://localhost:8083/hello_war_shared_services/");
    assertArtifactExists(artifactType5, artifactName5, artifactVersion5);
    assertArtifactState(artifactType5, artifactName5, artifactVersion5, "ACTIVE");
}

From source file:org.eclipse.virgo.server.svt.hostedrepo.RemoteHostedRepositoryOtherThan8080Tests.java

@Test
public void testParDeployThatDependsUponArtifactsInRemoteHostedRepo() throws Exception {
    signature = new String[] { String.class.getName() };
    params = new Object[] { new File(APP_URI_PAR).toURI().toString() };
    CompositeData compositeData = deploy(signature, params);
    artifactName7 = compositeData.get("symbolicName").toString();
    artifactType7 = compositeData.get("type").toString();
    artifactVersion7 = compositeData.get("version").toString();

    waitForMBeanRegister(artifactType7, artifactName7, artifactVersion7, HALF_SECOND, TWO_MINUTES);
    assertArtifactExists(artifactType7, artifactName7, artifactVersion7);
    UrlWaitLatch.waitFor("http://localhost:8083/greenpages/app/home.htm");
    assertArtifactState(artifactType7, artifactName7, artifactVersion7, "ACTIVE");
}

From source file:org.eclipse.virgo.server.svt.hostedrepo.RemoteHostedRepositoryOtherThan8080Tests.java

@Test
public void testSharedServicesWarDeployThatDependsUponArtifactsInRemoteHostedRepo() throws Exception {
    signature = new String[] { String.class.getName() };
    params = new Object[] { new File(APP_URI_SHAREDSERVICES_WAR2).toURI().toString() };
    CompositeData compositeData = deploy(signature, params);
    artifactName6 = compositeData.get("symbolicName").toString();
    artifactType6 = compositeData.get("type").toString();
    artifactVersion6 = compositeData.get("version").toString();

    waitForMBeanRegister(artifactType6, artifactName6, artifactVersion6, HALF_SECOND, TWO_MINUTES);
    UrlWaitLatch.waitFor("http://localhost:8083/formtags-shared-services-war-2.0.1.BUILD-20100413113234");
    UrlWaitLatch//w w  w .  j  av a2s.co  m
            .waitFor("http://localhost:8083/formtags-shared-services-war-2.0.1.BUILD-20100413113234/list.htm");
    UrlWaitLatch.waitFor(
            "http://localhost:8083/formtags-shared-services-war-2.0.1.BUILD-20100413113234/form.htm?id=1");
    assertArtifactExists(artifactType6, artifactName6, artifactVersion6);
    assertArtifactState(artifactType6, artifactName6, artifactVersion6, "ACTIVE");
}