Example usage for javax.management MBeanServerInvocationHandler newProxyInstance

List of usage examples for javax.management MBeanServerInvocationHandler newProxyInstance

Introduction

In this page you can find the example usage for javax.management MBeanServerInvocationHandler newProxyInstance.

Prototype

public static <T> T newProxyInstance(MBeanServerConnection connection, ObjectName objectName,
        Class<T> interfaceClass, boolean notificationBroadcaster) 

Source Link

Document

Return a proxy that implements the given interface by forwarding its methods through the given MBean server to the named MBean.

Usage

From source file:org.rhq.plugins.jslee.RAEntityComponent.java

private OperationResult doListActivityContexts() throws Exception {
    try {/*from   w w  w .  j a  v  a 2  s.  c  o  m*/
        MBeanServerConnection connection = this.mbeanUtils.getConnection();
        this.mbeanUtils.login();

        ObjectName actMana = new ObjectName("org.mobicents.slee:name=ActivityManagementMBean");

        ActivityManagementMBeanImplMBean aciManagMBean = (ActivityManagementMBeanImplMBean) MBeanServerInvocationHandler
                .newProxyInstance(connection, actMana,
                        org.mobicents.slee.container.management.jmx.ActivityManagementMBeanImplMBean.class,
                        false);

        Object[] activities = aciManagMBean
                .retrieveActivityContextIDByResourceAdaptorEntityName(this.raEntityName);
        // Object[] activities = aciManagMBean.listActivityContexts(true);

        PropertyList columnList = new PropertyList("result");
        if (activities != null) {
            for (Object obj : activities) {
                Object[] tempObjects = (Object[]) obj;
                PropertyMap col = new PropertyMap("element");

                Object tempObj = tempObjects[0];
                PropertySimple activityHandle = new PropertySimple("ActivityHandle",
                        tempObj != null ? ((JmxActivityContextHandle) tempObj).getActivityHandleToString()
                                : "-");

                col.put(activityHandle);

                col.put(new PropertySimple("Class", tempObjects[1]));

                tempObj = tempObjects[2];
                Date d = new Date(Long.parseLong((String) tempObj));
                col.put(new PropertySimple("LastAccessTime", d));

                tempObj = tempObjects[3];
                col.put(new PropertySimple("ResourceAdaptor", tempObj == null ? "-" : tempObj));

                tempObj = tempObjects[4];
                // PropertyList propertyList = new PropertyList("SbbAttachments");
                String[] strArr = (String[]) tempObj;
                StringBuffer sb = new StringBuffer();
                for (String s : strArr) {
                    // PropertyMap SbbAttachment = new PropertyMap("SbbAttachment");
                    // SbbAttachment.put(new PropertySimple("SbbAttachmentValue", s));
                    // propertyList.add(SbbAttachment);
                    sb.append(s).append("; ");
                }
                col.put(new PropertySimple("SbbAttachmentValue", sb.toString()));

                tempObj = tempObjects[5];
                // propertyList = new PropertyList("NamesBoundTo");
                sb = new StringBuffer();
                strArr = (String[]) tempObj;
                for (String s : strArr) {
                    // PropertyMap NameBoundTo = new PropertyMap("NameBoundTo");
                    // NameBoundTo.put(new PropertySimple("NameBoundToValue", s));
                    // propertyList.add(NameBoundTo);
                    sb.append(s).append("; ");
                }
                col.put(new PropertySimple("NameBoundToValue", sb.toString()));

                tempObj = tempObjects[6];
                // propertyList = new PropertyList("Timers");
                sb = new StringBuffer();
                strArr = (String[]) tempObj;
                for (String s : strArr) {
                    // PropertyMap Timer = new PropertyMap("Timer");
                    // Timer.put(new PropertySimple("TimerValue", s));
                    // propertyList.add(Timer);
                    sb.append(s).append("; ");
                }
                col.put(new PropertySimple("TimerValue", sb.toString()));

                tempObj = tempObjects[7];
                // propertyList = new PropertyList("DataProperties");
                sb = new StringBuffer();
                strArr = (String[]) tempObj;
                for (String s : strArr) {
                    // PropertyMap DataProperty = new PropertyMap("DataProperty");
                    // DataProperty.put(new PropertySimple("DataPropertyValue", s));
                    // propertyList.add(DataProperty);
                    sb.append(s).append("; ");
                }
                col.put(new PropertySimple("DataPropertyValue", sb.toString()));

                columnList.add(col);
            }
        }

        OperationResult result = new OperationResult();
        result.getComplexResults().put(columnList);

        return result;
    } finally {
        try {
            this.mbeanUtils.logout();
        } catch (LoginException e) {
            if (log.isDebugEnabled()) {
                log.debug("Failed to logout from secured JMX", e);
            }
        }
    }
}

From source file:org.rhq.plugins.jslee.RAEntityDiscoveryComponent.java

public Set<DiscoveredResourceDetails> discoverResources(
        ResourceDiscoveryContext<ResourceAdaptorComponent> context)
        throws InvalidPluginConfigurationException, Exception {
    MBeanServerUtils mbeanUtils = context.getParentResourceComponent().getMBeanServerUtils();
    try {//  www.ja  v  a  2 s.c o m
        if (log.isDebugEnabled()) {
            log.debug("RAEntityDiscoveryComponent.discoverResources() called");
        }
        Set<DiscoveredResourceDetails> discoveredRAEntities = new HashSet<DiscoveredResourceDetails>();

        MBeanServerConnection connection = mbeanUtils.getConnection();
        mbeanUtils.login();

        ObjectName resourceManagement = new ObjectName(ResourceManagementMBean.OBJECT_NAME);

        ResourceManagementMBean resourceManagementMBean = (ResourceManagementMBean) MBeanServerInvocationHandler
                .newProxyInstance(connection, resourceManagement,
                        javax.slee.management.ResourceManagementMBean.class, false);

        ResourceAdaptorID raID = context.getParentResourceComponent().getResourceAdaptorID();
        String[] raEntities = resourceManagementMBean.getResourceAdaptorEntities(raID);

        for (String entityName : raEntities) {
            String description = "RA Entity : " + entityName + " For ResourceAdaptor : " + raID.toString();

            DiscoveredResourceDetails discoveredEntity = new DiscoveredResourceDetails(
                    context.getResourceType(), entityName, entityName + " Entity", raID.getVersion(),
                    description, null, null);
            discoveredEntity.getPluginConfiguration().put(new PropertySimple("entityName", entityName));
            discoveredEntity.getPluginConfiguration().put(new PropertySimple("name", raID.getName()));
            discoveredEntity.getPluginConfiguration().put(new PropertySimple("version", raID.getVersion()));
            discoveredEntity.getPluginConfiguration().put(new PropertySimple("vendor", raID.getVendor()));
            discoveredRAEntities.add(discoveredEntity);
        }

        if (log.isInfoEnabled()) {
            log.info("Discovered " + discoveredRAEntities.size()
                    + " JAIN SLEE Resource Adaptor Entity Components.");
        }
        return discoveredRAEntities;
    } finally {
        try {
            mbeanUtils.logout();
        } catch (LoginException e) {
            if (log.isDebugEnabled()) {
                log.debug("Failed to logout from secured JMX", e);
            }
        }
    }
}

From source file:org.rhq.plugins.jslee.RAEntityLinkComponent.java

public AvailabilityType getAvailability() {
    if (log.isTraceEnabled()) {
        log.trace("getAvailability() called.");
    }/*from   ww w  .j  a  v  a  2  s  .c om*/

    try {
        MBeanServerConnection connection = this.mbeanUtils.getConnection();
        this.mbeanUtils.login();

        ResourceManagementMBean resourceManagementMBean = (ResourceManagementMBean) MBeanServerInvocationHandler
                .newProxyInstance(connection, this.resourceManagement,
                        javax.slee.management.ResourceManagementMBean.class, false);

        this.boundSbbs = resourceManagementMBean.getBoundSbbs(this.raEntityLinkName);

    } catch (Exception e) {
        log.error("getAvailability failed for RAEntityLinkComponent Link = " + this.raEntityLinkName);

        return AvailabilityType.DOWN;
    } finally {
        try {
            this.mbeanUtils.logout();
        } catch (LoginException e) {
            if (log.isDebugEnabled()) {
                log.debug("Failed to logout from secured JMX", e);
            }
        }
    }

    return AvailabilityType.UP;
}

From source file:org.rhq.plugins.jslee.RAEntityLinkComponent.java

public void deleteResource() throws Exception {
    if (log.isTraceEnabled()) {
        log.trace("deleteResource() called.");
    }/*from w  ww  .  j a va2s  .co  m*/

    try {
        MBeanServerConnection connection = this.mbeanUtils.getConnection();
        this.mbeanUtils.login();

        ResourceManagementMBean resourceManagementMBean = (ResourceManagementMBean) MBeanServerInvocationHandler
                .newProxyInstance(connection, this.resourceManagement,
                        javax.slee.management.ResourceManagementMBean.class, false);

        resourceManagementMBean.unbindLinkName(this.raEntityLinkName);
    } finally {
        try {
            this.mbeanUtils.logout();
        } catch (LoginException e) {
            if (log.isDebugEnabled()) {
                log.debug("Failed to logout from secured JMX", e);
            }
        }
    }
}

From source file:org.rhq.plugins.jslee.RAEntityLinkComponent.java

private OperationResult doListBoundSBBs() throws Exception {
    try {/*from  w ww.  jav  a  2  s  . co m*/
        MBeanServerConnection connection = this.mbeanUtils.getConnection();
        this.mbeanUtils.login();

        ResourceManagementMBean resourceManagementMBean = (ResourceManagementMBean) MBeanServerInvocationHandler
                .newProxyInstance(connection, this.resourceManagement,
                        javax.slee.management.ResourceManagementMBean.class, false);

        SbbID[] sbbIds = resourceManagementMBean.getBoundSbbs(this.raEntityLinkName);

        PropertyList columnList = new PropertyList("result");

        for (SbbID sbbID : sbbIds) {
            PropertyMap col = new PropertyMap("element");
            col.put(new PropertySimple("SbbName", sbbID.getName()));
            col.put(new PropertySimple("SbbVendeor", sbbID.getVendor()));
            col.put(new PropertySimple("SbbVersion", sbbID.getVersion()));

            columnList.add(col);
        }

        OperationResult result = new OperationResult();
        result.getComplexResults().put(columnList);

        return result;
    } finally {
        try {
            this.mbeanUtils.logout();
        } catch (LoginException e) {
            if (log.isDebugEnabled()) {
                log.debug("Failed to logout from secured JMX", e);
            }
        }
    }
}

From source file:org.rhq.plugins.jslee.RAEntityLinkDiscoveryComponent.java

public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<RAEntityComponent> context)
        throws InvalidPluginConfigurationException, Exception {
    if (log.isDebugEnabled()) {
        log.debug("RAEntityLinkDiscoveryComponent.discoverResources() called");
    }/*from  w ww .j a  va  2  s.  co m*/

    Set<DiscoveredResourceDetails> discoveredLinks = new HashSet<DiscoveredResourceDetails>();

    MBeanServerUtils mbeanUtils = context.getParentResourceComponent().getMBeanServerUtils();

    try {
        MBeanServerConnection connection = mbeanUtils.getConnection();
        mbeanUtils.login();

        ObjectName resourceManagement = new ObjectName(ResourceManagementMBean.OBJECT_NAME);

        ResourceManagementMBean resourceManagementMBean = (ResourceManagementMBean) MBeanServerInvocationHandler
                .newProxyInstance(connection, resourceManagement,
                        javax.slee.management.ResourceManagementMBean.class, false);

        raEntityName = context.getParentResourceComponent().getRAEntityName();
        this.raID = context.getParentResourceComponent().getResourceAdaptorID();

        String[] links = resourceManagementMBean.getLinkNames(raEntityName);

        for (String link : links) {
            String description = "Link : " + link + " For ResourceAdaptor Entity : " + raEntityName;

            DiscoveredResourceDetails discoveredEntity = new DiscoveredResourceDetails(
                    context.getResourceType(), link, link + " Link", raID.getVersion(), description, null,
                    null);
            discoveredEntity.getPluginConfiguration().put(new PropertySimple("linkName", link));

            discoveredLinks.add(discoveredEntity);
        }

        if (log.isInfoEnabled()) {
            log.info("Discovered " + discoveredLinks.size()
                    + " JAIN SLEE Resource Adaptor Entity Link Components.");
        }
        return discoveredLinks;
    } finally {
        try {
            mbeanUtils.logout();
        } catch (LoginException e) {
            if (log.isDebugEnabled()) {
                log.debug("Failed to logout from secured JMX", e);
            }
        }
    }
}

From source file:org.rhq.plugins.jslee.ResourceAdaptorComponent.java

public AvailabilityType getAvailability() {
    if (log.isTraceEnabled()) {
        log.trace("getAvailability() called.");
    }// www  .  java  2s.  c o  m

    try {
        MBeanServerConnection connection = this.mbeanUtils.getConnection();
        this.mbeanUtils.login();

        ResourceManagementMBean resourceManagementMBean = (ResourceManagementMBean) MBeanServerInvocationHandler
                .newProxyInstance(connection, this.resourceManagement,
                        javax.slee.management.ResourceManagementMBean.class, false);

        configProperties = resourceManagementMBean.getConfigurationProperties(this.raId);

    } catch (Exception e) {
        log.error("getAvailability failed for ResourceAdaptorID = " + this.raId);

        return AvailabilityType.DOWN;
    } finally {
        try {
            this.mbeanUtils.logout();
        } catch (LoginException e) {
            if (log.isDebugEnabled()) {
                log.debug("Failed to logout from secured JMX", e);
            }
        }
    }

    return AvailabilityType.UP;
}

From source file:org.rhq.plugins.jslee.ResourceAdaptorComponent.java

public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) throws Exception {
    if (log.isTraceEnabled()) {
        log.trace("getValues(" + report + "," + metrics + ") called.");
    }/*  w w w .  j av  a2 s  .  c om*/

    try {
        MBeanServerConnection connection = this.mbeanUtils.getConnection();
        this.mbeanUtils.login();

        for (MeasurementScheduleRequest request : metrics) {
            if (request.getName().equals("entities")) {
                ResourceManagementMBean resourceManagementMBean = (ResourceManagementMBean) MBeanServerInvocationHandler
                        .newProxyInstance(connection, this.resourceManagement,
                                javax.slee.management.ResourceManagementMBean.class, false);

                String[] raEntities = resourceManagementMBean.getResourceAdaptorEntities(this.raId);
                report.addData(new MeasurementDataNumeric(request, (double) raEntities.length));
            } else if (request.getName().equals("ratype")) {
                DeploymentMBean deploymentMBean = (DeploymentMBean) MBeanServerInvocationHandler
                        .newProxyInstance(connection, deploymentManagement,
                                javax.slee.management.DeploymentMBean.class, false);
                ResourceAdaptorTypeID[] raTypes = ((ResourceAdaptorDescriptor) deploymentMBean
                        .getDescriptor(raId)).getResourceAdaptorTypes();
                String raTypesString = "";
                for (ResourceAdaptorTypeID raTypeId : raTypes) {
                    raTypesString += raTypeId + "; ";
                }
                report.addData(new MeasurementDataTrait(request, raTypesString));
            }
        }
    } finally {
        try {
            this.mbeanUtils.logout();
        } catch (LoginException e) {
            if (log.isDebugEnabled()) {
                log.debug("Failed to logout from secured JMX", e);
            }
        }
    }
}

From source file:org.rhq.plugins.jslee.ResourceAdaptorComponent.java

public CreateResourceReport createResource(CreateResourceReport report) {
    try {//from ww  w.  j a va  2s  .  com
        Configuration configuration = report.getResourceConfiguration();

        String entityName = configuration.getSimple("entityName").getStringValue();
        PropertyList columnList = configuration.getList("properties");

        ConfigProperties props = new ConfigProperties();

        for (Property c : columnList.getList()) {
            PropertyMap column = (PropertyMap) c;

            String propName = column.getSimple("propertyName").getStringValue();
            String propType = column.getSimple("propertyType").getStringValue();
            String propValue = column.getSimple("propertyValue").getStringValue();

            if (log.isDebugEnabled()) {
                log.debug("Property (name=" + propName + ", type=" + propType + ", value=" + propValue + ")");
            }

            Object value = null;
            if (propType.equals("java.lang.String")) {
                value = propValue;
            } else if (propType.equals("java.lang.Integer")) {
                value = Integer.valueOf(propValue);
            } else if (propType.equals("java.lang.Long")) {
                value = Long.valueOf(propValue);
            }
            ConfigProperties.Property p = new ConfigProperties.Property(propName, propType, value);
            props.addProperty(p);
        }

        MBeanServerConnection connection = this.mbeanUtils.getConnection();
        this.mbeanUtils.login();

        ResourceManagementMBean resourceManagementMBean = (ResourceManagementMBean) MBeanServerInvocationHandler
                .newProxyInstance(connection, this.resourceManagement,
                        javax.slee.management.ResourceManagementMBean.class, false);

        report.setResourceKey(entityName);
        resourceManagementMBean.createResourceAdaptorEntity(this.raId, entityName, props);

        report.setStatus(CreateResourceStatus.SUCCESS);
        report.setResourceName(entityName);
    } catch (Exception e) {
        log.error("Adding new ResourceAdaptor Entity failed ", e);
        report.setException(e);
        report.setStatus(CreateResourceStatus.FAILURE);
    } finally {
        try {
            this.mbeanUtils.logout();
        } catch (LoginException e) {
            if (log.isDebugEnabled()) {
                log.debug("Failed to logout from secured JMX", e);
            }
        }
    }

    return report;
}

From source file:org.rhq.plugins.jslee.ResourceAdaptorDiscoveryComponent.java

public Set<DiscoveredResourceDetails> discoverResources(
        ResourceDiscoveryContext<JainSleeServerComponent> context)
        throws InvalidPluginConfigurationException, Exception {
    if (log.isDebugEnabled()) {
        log.debug("ResourceAdapterDiscoveryComponent.discoverResources() called");
    }//from w ww  .jav a2 s.c o m

    Set<DiscoveredResourceDetails> discoveredRAs = new HashSet<DiscoveredResourceDetails>();

    MBeanServerUtils mbeanUtils = context.getParentResourceComponent().getMBeanServerUtils();
    try {
        MBeanServerConnection connection = mbeanUtils.getConnection();
        mbeanUtils.login();

        ObjectName deploymentMBeanObj = new ObjectName(DeploymentMBean.OBJECT_NAME);
        DeploymentMBean deploymentMBean = (DeploymentMBean) MBeanServerInvocationHandler.newProxyInstance(
                connection, deploymentMBeanObj, javax.slee.management.DeploymentMBean.class, false);

        ResourceAdaptorID[] ras = deploymentMBean.getResourceAdaptors();

        for (ResourceAdaptorID raID : ras) {
            String key = raID.toString();
            String description = raID.toString();

            DiscoveredResourceDetails discoveredService = new DiscoveredResourceDetails(
                    context.getResourceType(), key, raID.getName(), raID.getVersion(), description, null, null);
            discoveredService.getPluginConfiguration().put(new PropertySimple("name", raID.getName()));
            discoveredService.getPluginConfiguration().put(new PropertySimple("version", raID.getVersion()));
            discoveredService.getPluginConfiguration().put(new PropertySimple("vendor", raID.getVendor()));
            discoveredRAs.add(discoveredService);
        }

        if (log.isInfoEnabled()) {
            log.info("Discovered " + discoveredRAs.size() + " JAIN SLEE Resource Adaptor Components.");
        }

        return discoveredRAs;
    } finally {
        try {
            mbeanUtils.logout();
        } catch (LoginException e) {
            if (log.isDebugEnabled()) {
                log.debug("Failed to logout from secured JMX", e);
            }
        }
    }
}