Apama 10.3 | Apama Documentation | Developing Apama Applications | Developing Apama Applications in Java | Overview of Apama JMon Applications | About event listeners and match listeners | Removing listeners
Removing listeners
A MatchListener instance that is no longer connected to an event expression, and to which there are no references, is garbage collected in the usual way. In some situations, you might want to be notified when the correlator removes its reference to the MatchListener (when it can no longer fire). For example, you might need this notification if the MatchListener has unmanaged resources (for example, open files) that need to be explicitly cleaned up when it is no longer needed, or your application has other references to the MatchListener that need to be removed when the listener can no longer fire so that it can be garbage collected. In those situations, you can define your listener so that it implements the com.apama.jmon.RemoveListener interface. There is no requirement to implement this interface. It is up to you to determine whether you need it.
The RemoveListener interface extends the MatchListener interface by providing one additional method: removed(). If you implement the RemoveListener interface, the correlator calls your implementation of the removed() method in the following situations:
*The application removes your listener from the event expression it is attached to.
*The event expression your listener is attached to is in a state that will never match. For example, on A() within (10.0) after 10 seconds have elapsed without an A().
In the following example, the removed() method is called because the event expression dies after 10 seconds.
import java.util.HashMap;
import com.apama.jmon.*;
public class Test implements Monitor {
   public Test() {}
   public void onLoad() {
     EventExpression e = new EventExpression("TestEvent() within(10.0)");
     e.addMatchListener(new RemoveListener() {
       public void match(MatchEvent event) {
         System.out.println(Correlator.getCurrentTime() +
             ": Received match");
      public void removed(EventExpression e) {
         System.out.println(Correlator.getCurrentTime() +
            ": Received removed");

Copyright © 2013-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.