/** @see DynamicMBean#setAttributes */ public AttributeList setAttributes(AttributeList attributes) { /* Sanity checking. */ if (attributes == null) { throw new IllegalArgumentException("attribute list can't be null"); } /* Set each attribute specified. */ AttributeList results = new AttributeList(); for (int i = 0; i < attributes.size(); i++) { Attribute attr = (Attribute) attributes.get(i); try { /* Set new value. */ jeHelper.setAttribute(targetEnv, attr); /* * Add the name and new value to the result list. Be sure * to ask the MBean for the new value, rather than simply * using attr.getValue(), because the new value may not * be same if it is modified according to the JE * implementation. */ String name = attr.getName(); Object newValue = jeHelper.getAttribute(targetEnv, name); results.add(new Attribute(name, newValue)); } catch (Exception e) { e.printStackTrace(); } } return results; }
/** * Open a JE environment using the configuration specified through MBean attributes and recorded * within the JEMBeanHelper. */ private void openEnvironment() throws MBeanException { try { if (targetEnv == null) { /* * The environment configuration has been set through * mbean attributes managed by the JEMBeanHelper. */ targetEnv = new Environment(jeHelper.getEnvironmentHome(), jeHelper.getEnvironmentOpenConfig()); resetMBeanInfo(); } } catch (DatabaseException e) { throw new MBeanException(e); } }
/** @see DynamicMBean#getAttributes */ public AttributeList getAttributes(String[] attributes) { /* Sanity checking. */ if (attributes == null) { throw new IllegalArgumentException("Attributes cannot be null"); } /* Get each requested attribute. */ AttributeList results = new AttributeList(); for (int i = 0; i < attributes.length; i++) { try { String name = attributes[i]; Object value = jeHelper.getAttribute(targetEnv, name); results.add(new Attribute(name, value)); } catch (Exception e) { e.printStackTrace(); } } return results; }
/** @see DynamicMBean#invoke */ public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException { Object result = null; if (actionName == null) { throw new IllegalArgumentException("actionName cannot be null"); } if (actionName.equals(OP_OPEN)) { openEnvironment(); return null; } else if (actionName.equals(OP_CLOSE)) { closeEnvironment(); return null; } else { result = jeHelper.invoke(targetEnv, actionName, params, signature); } return result; }
/** @see DynamicMBean#setAttribute */ public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException { jeHelper.setAttribute(targetEnv, attribute); }
/** @see DynamicMBean#getAttribute */ public Object getAttribute(String attributeName) throws AttributeNotFoundException, MBeanException { return jeHelper.getAttribute(targetEnv, attributeName); }
/** * Create the available management interface for this environment. The attributes and operations * available vary according to environment configuration. */ private synchronized void resetMBeanInfo() { /* * Get JE attributes, operation and notification information * from JEMBeanHelper. An application may choose to add functionality * of its own when constructing the MBeanInfo. */ /* Attributes. */ List attributeList = jeHelper.getAttributeList(targetEnv); MBeanAttributeInfo[] attributeInfo = new MBeanAttributeInfo[attributeList.size()]; attributeList.toArray(attributeInfo); /* Constructors. */ Constructor[] constructors = this.getClass().getConstructors(); MBeanConstructorInfo[] constructorInfo = new MBeanConstructorInfo[constructors.length]; for (int i = 0; i < constructors.length; i++) { constructorInfo[i] = new MBeanConstructorInfo(this.getClass().getName(), constructors[i]); } /* Operations. */ /* * Get the list of operations available from the jeHelper. Then add * an open and close operation. */ List operationList = jeHelper.getOperationList(targetEnv); if (targetEnv == null) { operationList.add( new MBeanOperationInfo( OP_OPEN, "Configure and open the JE environment.", new MBeanParameterInfo[0], // no params "java.lang.Boolean", MBeanOperationInfo.ACTION_INFO)); } else { operationList.add( new MBeanOperationInfo( OP_CLOSE, "Close the JE environment.", new MBeanParameterInfo[0], // no params "void", MBeanOperationInfo.ACTION_INFO)); } MBeanOperationInfo[] operationInfo = new MBeanOperationInfo[operationList.size()]; operationList.toArray(operationInfo); /* Notifications. */ MBeanNotificationInfo[] notificationInfo = jeHelper.getNotificationInfo(targetEnv); /* Generate the MBean description. */ mbeanInfo = new MBeanInfo( this.getClass().getName(), DESCRIPTION, attributeInfo, constructorInfo, operationInfo, notificationInfo); }