sun.com | docs.sun.com | How To Buy | My Sun | Worldwide Sites |  |

| Previous Contents Index Next
Chapter 10 # Receiving Notifications This chapter explains the NMA notification mechanism and describes the NMA notifications in detail. This chapter contains the following sections: Registering to Receive Notifications Registering to Receive SNMP Traps ## Registering to Receive Notifications For information and instructions about writing and registering a notification listener, see the Java Dynamic Management Kit 5.0 Tutorial. Note that this information applies to the NMA only and is separate from the process of registering for notifications sent by the CMM. For information on these, see "Receiving and Handling Change Notifications" in the Netra High Availability Suite Foundation Services 2.1 6/03 CMM Programming Guide. ### `NhasCmmNotification` A `NhasCmmNotification` notification is sent by the `ClusterNodeMBean` when a node leaves or joins the cluster, or when a failover or switchover occurs. In addition to the standard notification information, this notification contains the following information:
`type` | The possible types for this notification are listed below.
`source` | The `ObjectName` of the node.
The notification type is one of the following:
`MASTER` | The node is now the cluster master node
`VICEMASTER` | The node is now the cluster vice-master node
`IN_CLUSTER` | The node is now part of the cluster
`OUT_OF_CLUSTER` | The node is no longer part of the cluster
### `NhasPmdMaxRetriesNotification` A `NhasPmdMaxRetriesNotification` notification is sent by the `PmdStatisticsMBean` when the maximum number of retries has been reached for a nametag. In addition to the standard notification information, this notification contains the following information:
`source` | The `PmdStatisticsMBean` `ObjectName`.
`maxRetry` | The maximum retry number that was exceeded.
The `MAX_RETRIES` field of this notification contains the name of the nametag that reached its maximum number of retries limit. ### `NhasPmdAttributeChangeNotification` A `javax.management.AttributeChangeNotification` is sent by the `PmdNameTagStatisticsMBean` when either of the following conditions is true: The number of allowed retries changes The retry counter is reset In addition to the standard notification information, this notification contains the following information:
`type` | `ATTRIBUTE_CHANGE`
`source` | `PmdNameTagStatisticsMBean`
`attributeName` | Either `RetryCount` if the retry counter has been reset, or `MaxRetryCount` if the maximum number of retries allowed has changed.
`oldValue` | The old number of retries allowed
`newValue` | The new number of retries allowed
The `nametag` field contains the name of the nametag that has been affected. ### `NhasPmdNewNameTagNotification` A `NhasPmdNewNameTagNotification` is sent whenever the Daemon Monitor creates a new nametag. This notification contains the field `NEW_NAMETAG` which contains the name of the new nametag. ### `NhasPmdRemoveNameTagNotification` A `NhasPmdRemoveNameTagNotification` is sent whenever the Daemon Monitor removes a nametag from the collection. This notification contains the field `REMOVE_NAMETAG` which contains the name of the nametag that was removed. ## Registering to Receive SNMP Traps For a Java DMK SNMP manager to receive SNMP traps, an implementation of the `SnmpTrapListener` class must be registered on the SNMP trap port. Example 10-1 is an implementation of the `SnmpTrapListener` that listens for SNMPv1, SNMPv2 and SNMPv3 traps. Example 10-2 is a code snippet that registers the `TrapListenerImpl` class as a trap listener on trap port `trapPort`. The `TrapListenerImpl` class prints the details of all the traps it receives to the standard output. Example 10-1 Implementation of the `SnmpTrapListener` Class
    class TrapListenerImpl implements SnmpTrapListener {

      public void processSnmpTrapV1(SnmpPduTrap trap) {
        System.out.println("NOTE: TrapListenerImpl received trap V1:");
        System.out.println("\tGeneric " + trap.genericTrap);
        System.out.println("\tSpecific " + trap.specificTrap);
        System.out.println("\tTimeStamp " + trap.timeStamp);
        System.out.println("\tAgent adress " + trap.agentAddr.stringValue());
      }

      public void processSnmpTrapV2(SnmpPduRequest trap) {
        System.out.println("NOTE: TrapListenerImpl received trap V2:");

        SnmpPdu pdu = trap.getResponsePdu();
        System.out.println("\tFrom Address" + pdu.address.getHostAddress());
      }

      public void processSnmpTrapV3(SnmpScopedPduRequest trap) {
        System.out.println("NOTE: TrapListenerImpl received trap V3:");
        System.out.println("\tContextEngineId : " +
        SnmpEngineId.createEngineId(trap.contextEngineId));

        System.out.println("\tContextName : " + new String(trap.contextName));
        System.out.println("\tVarBind list :");
        for (int i = 0; i < trap.varBindList.length; i++) {
          System.out.println("oid : " + trap.varBindList[i].getOid() +
          " val : " + trap.varBindList[i].getSnmpValue());
        }
      }
The following code snippet registers the `TrapListenerImpl` class as a trap listener on trap port `trapPort`. Example 10-2 Registering a Trap Listener
    System.out.println("Creating the trap listener on trapPort = " + trapPort);

    // Create the Trap listener
    TrapListenerImpl trapListener = new TrapListenerImpl();
    SnmpEventReportDispatcher trapAgent = null;

    try{
      trapAgent = new SnmpEventReportDispatcher(trapPort);
    } catch (SocketException e) {
      System.out.println("ERROR Creating the trapListener " + e.getMessage());
    }

    // Start the Event Report dispatcher
    new Thread(trapAgent).start();

    // Add the trap listener on the Event report dispatcher
    trapAgent.addTrapListener(trapListener);

    System.out.println("Created the trap listener");
Previous Contents Index Next

Copyright 1994-2004 Sun Microsystems