Subject: Java Agent - Timer ActionListener problem
Very curious.
I have an even simpler version of the same thing and it behaves the same way: after Domino server starts, the agent runs as expected - the first time; afterwards, actionPerformed(…) is never invoked.
I then tried re-creating the ActionListener in each loop:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import lotus.domino.*;
public class JavaAgent extends AgentBase
{ public void NotesMain()
{ ActionListener al_InputPaused;
Timer tm_InputPaused;
tm_InputPaused = new Timer( 1000, null );
tm_InputPaused.setRepeats( false );
for( int i__Loop = 0; i__Loop < 5; i__Loop++ )
{ al_InputPaused = new ActionListener()
{ public void actionPerformed( ActionEvent ae_AdsbPaused )
{ System.out.println( "ActionListener called." );
}
};
tm_InputPaused.addActionListener( al_InputPaused );
tm_InputPaused.start();
System.out.println( "Timer is" + (tm_InputPaused.isRunning() ? " " : " not ") + "running and has " + tm_InputPaused.getActionListeners().length + " ActionListener(s)" );
try
{ sleep( 5000 );
} catch( Exception ex )
{
}
// tm_InputPaused.stop();
tm_InputPaused.removeActionListener( al_InputPaused );
System.out.println( "Timer is" + (tm_InputPaused.isRunning() ? " " : " not ") + "running and has " + tm_InputPaused.getActionListeners().length + " ActionListener(s)" );
al_InputPaused = null;
}
}
}
Stopping the Timer doesn’t help either.
This is from the log, just after startup:
12/02/2010 10:39:54 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is running and has 1 ActionListener(s)
12/02/2010 10:39:55 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: ActionListener called.
12/02/2010 10:39:59 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is not running and has 0 ActionListener(s)
12/02/2010 10:39:59 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is running and has 1 ActionListener(s)
12/02/2010 10:40:00 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: ActionListener called.
12/02/2010 10:40:04 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is not running and has 0 ActionListener(s)
12/02/2010 10:40:04 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is running and has 1 ActionListener(s)
12/02/2010 10:40:05 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: ActionListener called.
12/02/2010 10:40:09 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is not running and has 0 ActionListener(s)
12/02/2010 10:40:09 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is running and has 1 ActionListener(s)
12/02/2010 10:40:10 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: ActionListener called.
12/02/2010 10:40:14 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is not running and has 0 ActionListener(s)
12/02/2010 10:40:14 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is running and has 1 ActionListener(s)
12/02/2010 10:40:15 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: ActionListener called.
Subsequent entries, whether the agent runs every 5 minutes, 30 minutes, or 60 minutes look like this:
12/02/2010 11:10:38 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is running and has 1 ActionListener(s)
12/02/2010 11:10:43 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is running and has 0 ActionListener(s)
12/02/2010 11:10:43 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is running and has 1 ActionListener(s)
12/02/2010 11:10:48 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is running and has 0 ActionListener(s)
12/02/2010 11:10:48 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is running and has 1 ActionListener(s)
12/02/2010 11:10:53 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is running and has 0 ActionListener(s)
12/02/2010 11:10:53 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is running and has 1 ActionListener(s)
12/02/2010 11:10:58 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is running and has 0 ActionListener(s)
12/02/2010 11:10:58 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is running and has 1 ActionListener(s)
12/02/2010 11:11:03 AM AMgr: Agent (‘ListenerTest’ in ‘.nsf’) printing: Timer is running and has 0 ActionListener(s)
Timer.stop() and Timer.restart() are extremely handy in my actual code. java.util.Timer is not so flexible.
P.S. We’re running Domino 7.