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.JainSleeServerComponent.java

private OperationResult doListActivityContexts(Configuration paramteres) throws Exception {
    try {//w w  w.j  a v a  2 s.c om
        OperationResult result = new OperationResult();

        MBeanServerConnection connection = this.mBeanServerUtils.getConnection();
        this.mBeanServerUtils.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.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);
            }
        }
        result.getComplexResults().put(columnList);

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

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

private EventRouterStatisticsMBean getEventRouterStatisticsMBean() throws Exception {
    try {//w  ww .j a  v a  2s. c o  m
        MBeanServerConnection connection = this.mBeanServerUtils.getConnection();
        this.mBeanServerUtils.login();

        ObjectName erStatsObjectName = new ObjectName(
                "org.mobicents.slee:name=EventRouterStatistics"/* FIXME */);
        EventRouterStatisticsMBean erStatsMBean = (EventRouterStatisticsMBean) MBeanServerInvocationHandler
                .newProxyInstance(connection, erStatsObjectName, EventRouterStatisticsMBean.class, false);

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

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

private EventRouterConfigurationMBean getEventRouterConfigurationMBean() throws Exception {
    try {/*from ww w . ja  v a 2 s  . c  om*/
        MBeanServerConnection connection = this.mBeanServerUtils.getConnection();
        this.mBeanServerUtils.login();

        ObjectName erConfigObjectName = new ObjectName(
                "org.mobicents.slee:name=EventRouterConfiguration"/* FIXME */);
        EventRouterConfigurationMBean erConfigMBean = (EventRouterConfigurationMBean) MBeanServerInvocationHandler
                .newProxyInstance(connection, erConfigObjectName, EventRouterConfigurationMBean.class, false);

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

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

public AvailabilityType getAvailability() {
    if (log.isTraceEnabled()) {
        log.trace("getAvailability() called.");
    }//from   w w w  . ja  va  2 s.  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.raEntityName);
    } catch (Exception e) {
        log.error("getAvailability failed for ResourceAdaptor Entity = " + this.raEntityName);
        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.RAEntityComponent.java

private ResourceAdaptorEntityState getState() throws Exception {
    try {/*from  www  .j a  v a  2 s . c  om*/
        MBeanServerConnection connection = this.mbeanUtils.getConnection();
        this.mbeanUtils.login();

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

        return resourceManagementMBean.getState(this.raEntityName);
    } 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.RAEntityComponent.java

private Object[] getActivityContextID() throws Exception {
    try {//from w  w  w . ja v  a 2 s  .  c o  m
        ObjectName actMana = new ObjectName("org.mobicents.slee:name=ActivityManagementMBean");

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

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

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

        return activities;
    } 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.RAEntityComponent.java

public void updateResourceConfiguration(ConfigurationUpdateReport configurationUpdateReport) {
    try {/* w  ww .  j  a v a2s.c om*/
        MBeanServerConnection connection = this.mbeanUtils.getConnection();
        this.mbeanUtils.login();

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

        // Get the JOPR updated properties
        PropertyList propsList = configurationUpdateReport.getConfiguration().getList("properties");

        // Get the current RA Entity properties
        ConfigProperties cps = resourceManagementMBean.getConfigurationProperties(this.raEntityName);

        for (Property p : propsList.getList()) {
            PropertyMap pMap = (PropertyMap) p;
            String propName = ((PropertySimple) pMap.get("propertyName")).getStringValue();
            String propType = ((PropertySimple) pMap.get("propertyType")).getStringValue();
            String propValue = ((PropertySimple) pMap.get("propertyValue")).getStringValue();
            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 cp = cps.getProperty(propName);
            if (value != null && cp != null && !value.equals(cp.getValue())) {
                if (log.isDebugEnabled()) {
                    log.debug("Changing property '" + propName + "' from value [" + cp.getValue() + "] to ["
                            + value + "].");
                }
                cp.setValue(value);
            }
        }
        resourceManagementMBean.updateConfigurationProperties(this.raEntityName, cps);
        configurationUpdateReport.setStatus(ConfigurationUpdateStatus.SUCCESS);
    } catch (Exception e) {
        log.error("Failed to update Resource Configuration.", e);
        configurationUpdateReport.setErrorMessageFromThrowable(e);
        configurationUpdateReport.setStatus(ConfigurationUpdateStatus.FAILURE);
    } 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.RAEntityComponent.java

public void deleteResource() throws Exception {
    try {/*from w  ww.jav  a  2s  .c  om*/
        MBeanServerConnection connection = this.mbeanUtils.getConnection();
        this.mbeanUtils.login();

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

        resourceManagementMBean.removeResourceAdaptorEntity(this.raEntityName);
    } 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.RAEntityComponent.java

public CreateResourceReport createResource(CreateResourceReport report) {
    try {//from  w w w. j a va2 s . c o m
        Configuration configuration = report.getResourceConfiguration();

        String linkName = configuration.getSimple("linkName").getStringValue();

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

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

        report.setResourceKey(linkName);
        resourceManagementMBean.bindLinkName(this.raEntityName, linkName);

        report.setStatus(CreateResourceStatus.SUCCESS);
        report.setResourceName(linkName);
    } 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.RAEntityComponent.java

private OperationResult doChangeRaEntityState(Configuration parameters) throws Exception {
    try {/*w  w  w .  j av  a2s  .c  o  m*/
        String message = null;
        String action = parameters.getSimple("action").getStringValue();

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

        ResourceManagementMBean resourceManagementMBean = (ResourceManagementMBean) MBeanServerInvocationHandler
                .newProxyInstance(connection, this.resourceManagement,
                        javax.slee.management.ResourceManagementMBean.class, false);
        if ("activate".equals(action)) {
            resourceManagementMBean.activateResourceAdaptorEntity(this.raEntityName);
            message = "Successfully Activated Resource Adaptor Entity " + this.raEntityName;
        } else if ("deactivate".equals(action)) {
            resourceManagementMBean.deactivateResourceAdaptorEntity(this.raEntityName);
            message = "Successfully DeActivated Resource Adaptor Entity " + this.raEntityName;
        }

        OperationResult result = new OperationResult();
        result.getComplexResults().put(new PropertySimple("result", message));

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