FileDocCategorySizeDatePackage
MBeanServerNotificationFilter.javaAPI DocJava SE 5 API15202Fri Aug 26 14:57:36 BST 2005javax.management.relation

MBeanServerNotificationFilter

public class MBeanServerNotificationFilter extends NotificationFilterSupport
Filter for {@link MBeanServerNotification}. This filter filters MBeanServerNotification notifications by selecting the ObjectNames of interest and the operations (registration, unregistration, both) of interest (corresponding to notification types).
since
1.5

Fields Summary
private static final long
oldSerialVersionUID
private static final long
newSerialVersionUID
private static final ObjectStreamField[]
oldSerialPersistentFields
private static final ObjectStreamField[]
newSerialPersistentFields
private static final long
serialVersionUID
private static final ObjectStreamField[]
serialPersistentFields
private static boolean
compat
private List
selectedNames
private List
deselectedNames
private static String
localClassName
Constructors Summary
public MBeanServerNotificationFilter()
Creates a filter selecting all MBeanServerNotification notifications for all ObjectNames.

  
    //
    // Constructor
    //

                   
      

	super();

        if (isTraceOn())
            trace("Constructor: entering", null);

	enableType(MBeanServerNotification.REGISTRATION_NOTIFICATION);
	enableType(MBeanServerNotification.UNREGISTRATION_NOTIFICATION);

        if (isTraceOn())
            trace("Constructor: exiting", null);
	return;
    
Methods Summary
private voiddebug(java.lang.String methodName, java.lang.String info)

        Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_RELATION, localClassName, methodName, info);
	Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_RELATION, "", "", "\n");
    
public synchronized voiddisableAllObjectNames()
Disables any MBeanServerNotification (all ObjectNames are deselected).


        if (isTraceOn())
            trace("disableAllObjectNames: entering", null);

	selectedNames = new Vector();
	deselectedNames = null;

        if (isTraceOn())
            trace("disableAllObjectNames: exiting", null);
	return;
    
public synchronized voiddisableObjectName(javax.management.ObjectName theObjName)
Disables MBeanServerNotifications concerning given ObjectName.

param
theObjName ObjectName no longer of interest
exception
IllegalArgumentException if the given ObjectName is null


	if (theObjName == null) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isTraceOn())
            trace("disableObjectName: entering", theObjName.toString());

	// Removes from selected ObjectNames, if present
	if (selectedNames != null) {
	    if (selectedNames.size() != 0) {
		selectedNames.remove(theObjName);
	    }
	}

	// Adds it in deselected ObjectNames
	if (deselectedNames != null) {
	    // If all are deselected, no need to do anything :)
	    if (!(deselectedNames.contains(theObjName))) {
		// ObjectName was not already deselected
		deselectedNames.add(theObjName);
	    }
	}

        if (isTraceOn())
            trace("disableObjectName: exiting", null);
	return;
    
public synchronized voidenableAllObjectNames()
Enables all MBeanServerNotifications (all ObjectNames are selected).


	if (isTraceOn())
            trace("enableAllObjectNames: entering", null);

    	selectedNames = null;
	deselectedNames = new Vector();

        if (isTraceOn())
            trace("enableAllObjectNames: exiting", null);
	return;
    
public synchronized voidenableObjectName(javax.management.ObjectName theObjName)
Enables MBeanServerNotifications concerning given ObjectName.

param
theObjName ObjectName of interest
exception
IllegalArgumentException if the given ObjectName is null


	if (theObjName == null) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isTraceOn())
            trace("enableObjectName: entering", theObjName.toString());

	// Removes from deselected ObjectNames, if present
	if (deselectedNames != null) {
	    if (deselectedNames.size() != 0) {
		deselectedNames.remove(theObjName);
	    }
	}

	// Adds it in selected ObjectNames
	if (selectedNames != null) {
	    // If all are selected, no need to do anything :)
	    if (!(selectedNames.contains(theObjName))) {
		// ObjectName was not already selected
		selectedNames.add(theObjName);
	    }
	}

        if (isTraceOn())
            trace("enableObjectName: exiting", null);
	return;
    
public synchronized java.util.VectorgetDisabledObjectNames()
Gets all the ObjectNames disabled.

return
Vector of ObjectNames:

- null means all ObjectNames are implicitly deselected, except the ObjectNames explicitly selected

- empty means all ObjectNames are selected, i.e. no ObjectName deselected.

	if (deselectedNames != null) {
	    return (Vector)((Vector)deselectedNames).clone();
	} else {
	    return null;
	}
    
public synchronized java.util.VectorgetEnabledObjectNames()
Gets all the ObjectNames enabled.

return
Vector of ObjectNames:

- null means all ObjectNames are implicitly selected, except the ObjectNames explicitly deselected

- empty means all ObjectNames are deselected, i.e. no ObjectName selected.

	if (selectedNames != null) {
	    return (Vector)((Vector)selectedNames).clone();
	} else {
	    return null;
	}
    
private booleanisDebugOn()

        return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_RELATION);
    
public synchronized booleanisNotificationEnabled(javax.management.Notification theNtf)
Invoked before sending the specified notification to the listener.

If:

- the ObjectName of the concerned MBean is selected (explicitly OR (implicitly and not explicitly deselected))

AND

- the type of the operation (registration or unregistration) is selected

then the notification is sent to the listener.

param
theNtf The notification to be sent.
return
true if the notification has to be sent to the listener, false otherwise.
exception
IllegalArgumentException if null parameter


	if (theNtf == null) {
	    // Revisit [cebro] Localize message
	    String excMsg = "Invalid parameter.";
	    throw new IllegalArgumentException(excMsg);
	}

	if (isTraceOn())
            trace("isNotificationEnabled: entering", theNtf.toString());

	// Checks the type first
	String ntfType = theNtf.getType();
	Vector enabledTypes = getEnabledTypes();
	if (!(enabledTypes.contains(ntfType))) {

	    if (isTraceOn())
		trace("isNotificationEnabled: type not selected, exiting", null);
	    return false;
	}

	// We have a MBeanServerNotification: downcasts it
	MBeanServerNotification mbsNtf = (MBeanServerNotification)theNtf;

	// Checks the ObjectName
	ObjectName objName = mbsNtf.getMBeanName();
	// Is it selected?
	boolean isSelectedFlg = false;
	if (selectedNames != null) {
	    // Not all are implicitly selected:
	    // checks for explicit selection
	    if (selectedNames.size() == 0) {
		// All are explicitly not selected
		if (isTraceOn())
		    trace("isNotificationEnabled: no ObjectNames selected, exiting", null);
		return false;
	    }

	    isSelectedFlg = selectedNames.contains(objName);
	    if (!isSelectedFlg) {
		// Not in the explicit selected list
		if (isTraceOn())
		    trace("isNotificationEnabled: ObjectName not in selected list, exiting", null);
		return false;
	    }
	}

	if (!isSelectedFlg) {
	    // Not explicitly selected: is it deselected?

	    if (deselectedNames == null) {
		// All are implicitly deselected and it is not explicitly
		// selected
		if (isTraceOn())
		    trace("isNotificationEnabled: ObjectName not selected and all deselectedm, exiting", null);
		return false;

	    } else if (deselectedNames.contains(objName)) {
		// Explicitly deselected
		if (isTraceOn())
		    trace("isNotificationEnabled: ObjectName explicitly not selected, exiting", null);
		return false;
	    }
	}

	if (isTraceOn())
	    trace("isNotificationEnabled: ObjectName selected, exiting", null);
	return true;
    
private booleanisTraceOn()


    // trace level
       
        return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_RELATION);
    
private voidreadObject(java.io.ObjectInputStream in)
Deserializes an {@link MBeanServerNotificationFilter} from an {@link ObjectInputStream}.

      if (compat)
      {
        // Read an object serialized in the old serial form
        //
        ObjectInputStream.GetField fields = in.readFields();
	selectedNames = (List) fields.get("mySelectObjNameList", null);
	if (fields.defaulted("mySelectObjNameList"))
        {
          throw new NullPointerException("mySelectObjNameList");
        }
	deselectedNames = (List) fields.get("myDeselectObjNameList", null);
	if (fields.defaulted("myDeselectObjNameList"))
        {
          throw new NullPointerException("myDeselectObjNameList");
        }
      }
      else
      {
        // Read an object serialized in the new serial form
        //
        in.defaultReadObject();
      }
    
private voidtrace(java.lang.String methodName, java.lang.String info)

        Trace.send(Trace.LEVEL_TRACE, Trace.INFO_RELATION, localClassName, methodName, info);
	Trace.send(Trace.LEVEL_TRACE, Trace.INFO_RELATION, "", "", "\n");
    
private voidwriteObject(java.io.ObjectOutputStream out)
Serializes an {@link MBeanServerNotificationFilter} to an {@link ObjectOutputStream}.

      if (compat)
      {
        // Serializes this instance in the old serial form
        //
        ObjectOutputStream.PutField fields = out.putFields();
	fields.put("mySelectObjNameList", (Vector)selectedNames);
	fields.put("myDeselectObjNameList", (Vector)deselectedNames);
	out.writeFields();
      }
      else
      {
        // Serializes this instance in the new serial form
        //
        out.defaultWriteObject();
      }