costin 2002/11/01 15:10:11
Modified: modeler/src/java/org/apache/commons/modeler
BaseModelMBean.java
Log:
Few small enhancements.
- send the notification on attribute change
- keep all the attributes that are set in a local hashtable, and
provide access to it.
- also allow attributes to be pushed into it directly ( to be used
if some attributes are set via digester or introspection in the
real component ).
Revision Changes Path
1.5 +39 -7
jakarta-commons/modeler/src/java/org/apache/commons/modeler/BaseModelMBean.java
Index: BaseModelMBean.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/BaseModelMBean.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BaseModelMBean.java 18 Oct 2002 15:34:09 -0000 1.4
+++ BaseModelMBean.java 1 Nov 2002 23:10:10 -0000 1.5
@@ -100,6 +100,7 @@
import javax.management.modelmbean.ModelMBeanNotificationInfo;
import javax.management.modelmbean.ModelMBeanOperationInfo;
+// TODO: enable ant-like substitutions ? ( or at least discuss it )
/**
* <p>Basic implementation of the <code>ModelMBean</code> interface, which
@@ -123,6 +124,7 @@
* </ul>
*
* @author Craig R. McClanahan
+ * @author Costin Manolache
* @version $Revision$ $Date$
*/
@@ -208,6 +210,8 @@
// key: operation val: invoke method
Hashtable invokeAttMap=new Hashtable();
+ // All attributes that are set via this interface ( original values )
+ Hashtable attributes=new Hashtable();
/**
* Obtain and return the value of a specific attribute of this MBean.
@@ -498,7 +502,6 @@
throws AttributeNotFoundException, MBeanException,
ReflectionException
{
- // XXX Send attribute changed notification !!!
// Validate the input parameters
if (attribute == null)
throw new RuntimeOperationsException
@@ -512,7 +515,16 @@
(new IllegalArgumentException("Attribute name is null"),
"Attribute name is null");
- // Extract the method from cache
+ try {
+ // XXX Is it before or after ?
+ Object oldValue=getAttribute( name );
+ sendAttributeChangeNotification(new Attribute( name, oldValue),
+ attribute);
+ } catch( Exception ex ) {
+ log.error( "Error sending notification " + name, ex );
+ }
+
+ // Extract the method from cache
Method m=(Method)setAttMap.get( name );
if( m==null ) {
@@ -578,6 +590,8 @@
throw new MBeanException
(e, "Exception invoking method " + name);
}
+
+ attributes.put( name, value );
}
@@ -810,6 +824,8 @@
"Notification is null");
if (attributeBroadcaster == null)
return; // This means there are no registered listeners
+ if( log.isDebugEnabled() )
+ log.debug( "AttributeChangeNotification " + notification );
attributeBroadcaster.sendNotification(notification);
}
@@ -1068,7 +1084,7 @@
*/
public void load() throws InstanceNotFoundException,
MBeanException, RuntimeOperationsException {
-
+ // XXX If a context was set, use it to load the data
throw new MBeanException
(new IllegalStateException("Persistence is not supported"),
"Persistence is not supported");
@@ -1095,12 +1111,28 @@
public void store() throws InstanceNotFoundException,
MBeanException, RuntimeOperationsException {
+ // XXX if a context was set, use it to store the data
throw new MBeanException
(new IllegalStateException("Persistence is not supported"),
"Persistence is not supported");
}
+ // ------------------- Special methods ----------------------------------
+
+ /** Get all attributes that were set via JMX. This data can be persisted.
+ *
+ */
+ public Hashtable getAttributes() {
+ return attributes;
+ }
+
+ /** "Backdoor" method to push configuration data that
+ * was set using other methods ( like digester and direct introspection )
+ */
+ public void putAttribute( String name, Object value ) {
+ attributes.put(name, value );
+ }
// ------------------------------------------------------ Protected Methods
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>