@@ -44,7 +44,7 @@ public class DirectAgentAttache extends AgentAttache {
4444 private final static Logger s_logger = Logger .getLogger (DirectAgentAttache .class );
4545
4646 ServerResource _resource ;
47- static ScheduledExecutorService _executor = new ScheduledThreadPoolExecutor (100 , new NamedThreadFactory ("DirectAgent" ));
47+ static ScheduledExecutorService s_executor = new ScheduledThreadPoolExecutor (100 , new NamedThreadFactory ("DirectAgent" ));
4848 List <ScheduledFuture <?>> _futures = new ArrayList <ScheduledFuture <?>>();
4949 AgentManagerImpl _mgr ;
5050 long _seq = 0 ;
@@ -98,15 +98,15 @@ public void send(Request req) throws AgentUnavailableException {
9898 if (answers != null && answers [0 ] instanceof StartupAnswer ) {
9999 StartupAnswer startup = (StartupAnswer )answers [0 ];
100100 int interval = startup .getPingInterval ();
101- _futures .add (_executor .scheduleAtFixedRate (new PingTask (), interval , interval , TimeUnit .SECONDS ));
101+ _futures .add (s_executor .scheduleAtFixedRate (new PingTask (), interval , interval , TimeUnit .SECONDS ));
102102 }
103103 } else {
104104 Command [] cmds = req .getCommands ();
105105 if (cmds .length > 0 && !(cmds [0 ] instanceof CronCommand )) {
106- _executor .execute (new Task (req ));
106+ s_executor .execute (new Task (req ));
107107 } else {
108108 CronCommand cmd = (CronCommand )cmds [0 ];
109- _futures .add (_executor .scheduleAtFixedRate (new Task (req ), cmd .getInterval (), cmd .getInterval (), TimeUnit .SECONDS ));
109+ _futures .add (s_executor .scheduleAtFixedRate (new Task (req ), cmd .getInterval (), cmd .getInterval (), TimeUnit .SECONDS ));
110110 }
111111 }
112112 }
@@ -117,10 +117,20 @@ public void process(Answer[] answers) {
117117 StartupAnswer startup = (StartupAnswer )answers [0 ];
118118 int interval = startup .getPingInterval ();
119119 s_logger .info ("StartupAnswer received " + startup .getHostId () + " Interval = " + interval );
120- _futures .add (_executor .scheduleAtFixedRate (new PingTask (), interval , interval , TimeUnit .SECONDS ));
120+ _futures .add (s_executor .scheduleAtFixedRate (new PingTask (), interval , interval , TimeUnit .SECONDS ));
121121 }
122122 }
123123
124+ @ Override
125+ protected void finalize () {
126+ assert _resource == null : "Come on now....If you're going to dabble in agent code, you better know how to close out our resources. Ever considered why there's a method called disconnect()?" ;
127+ synchronized (this ) {
128+ if (_resource != null ) {
129+ disconnect (Status .Alert );
130+ }
131+ }
132+ }
133+
124134 protected class PingTask implements Runnable {
125135 @ Override
126136 public synchronized void run () {
0 commit comments