home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / prosrc.bin / TimerRegistration.java < prev    next >
Encoding:
Java Source  |  1998-03-18  |  2.9 KB  |  85 lines

  1. /*
  2.  * Copyright (c) 1997 Krumel & Associates, Inc. All Rights Reserved.
  3.  *
  4.  * www.krumel.com - controls@krumel.com
  5.  *
  6.  * Permission is given to the buyer of this package for one software
  7.  * developer to use this software on one CPU (one workstation) and to make
  8.  * one backup copy.  You may uitilize and/or modify this class for use in your
  9.  * projects.  You may distribute or sell any executable which results from
  10.  * using this code in yur application, except a utility or class of similar
  11.  * nature to this product.  You may distribute this product in compiled
  12.  * form only, but soley to be used with your cmpiled executable product
  13.  * for the puposes of dynamic loading. You may NOT redistribute the source
  14.  * code in any form or make it accessible through a network or other
  15.  * distribution media to others. Please refer to the file "copyright.html"
  16.  * for further important copyright and licensing information.
  17.  *
  18.  * The source code is the confidential and proprietary information
  19.  * of Krumel & Associates, Inc. ("Confidential Information").  You shall
  20.  * not disclose such Confidential Information and shall use it only in
  21.  * accordance with the terms of the license agreement you entered into
  22.  * with Krumel & Associates, Inc..
  23.  
  24.  * KRUMEL & ASSOCIATES MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
  25.  * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
  26.  * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  27.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. KRUMEL & ASSOCIATES SHALL NOT
  28.  * BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
  29.  * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  30.  */
  31.  
  32.  
  33. package symantec.itools.db.awt.genutil;
  34.  
  35. import java.util.*;
  36.  
  37. class TimerRegistration {
  38.     Observer    caller;
  39.     int         interval;
  40.     long        last;
  41.     boolean     active;
  42.  
  43.     TimerRegistration(Observer c, int i) {
  44.         caller = c;
  45.         interval = i;
  46.         last = System.currentTimeMillis();
  47.     }
  48.  
  49.     long next() {
  50.         return last + interval;
  51.     }
  52.  
  53.     void callIfRequired(Timer t, long time) {
  54.         if (active && time > last + interval) {
  55.             //catch all exceptions so as to not kill the notifier thread
  56.             try {
  57.                 caller.update(t, this);
  58.             } catch(Exception ex) {
  59.                 //this shouldn't happen but in case we hit bad code, print out
  60.                 //a message to the console
  61.                 ex.printStackTrace();
  62.             }
  63.  
  64.             last = System.currentTimeMillis();
  65.         }
  66.     }
  67.  
  68.     public void activate() {
  69.         active = true;
  70.         last = System.currentTimeMillis();
  71.     }
  72.  
  73.     public void inactivate() { active = false; }
  74.  
  75.     public boolean isActive() { return active; }
  76.  
  77.     public void updateInterval(int newInterval) {
  78.         interval = newInterval;
  79.     }
  80.  
  81.     public int getInterval() { return interval; }
  82. }
  83.  
  84.  
  85.