Hex Artifact Content
Not logged in

Artifact fe4ff90cc2cf8b9abc7db4c39a7c8634c949d148:


0000: 2f 2a 20 0a 20 2a 20 54 69 6d 65 72 48 61 6e 64  /* . * TimerHand
0010: 6c 65 72 54 65 73 74 2e 6a 61 76 61 20 2d 2d 0a  lerTest.java --.
0020: 20 2a 0a 20 2a 09 54 68 69 73 20 66 69 6c 65 20   *. *.This file 
0030: 69 73 20 75 73 65 64 20 62 79 20 6a 61 76 61 54  is used by javaT
0040: 69 6d 65 72 2e 74 65 73 74 20 74 6f 20 74 65 73  imer.test to tes
0050: 74 20 74 68 65 20 54 69 6d 65 72 48 61 6e 64 6c  t the TimerHandl
0060: 65 72 0a 20 2a 09 69 6e 74 65 72 66 61 63 65 73  er. *.interfaces
0070: 2e 0a 20 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68  .. *. * Copyrigh
0080: 74 20 28 63 29 20 31 39 39 38 20 62 79 20 53 75  t (c) 1998 by Su
0090: 6e 20 4d 69 63 72 6f 73 79 73 74 65 6d 73 2c 20  n Microsystems, 
00a0: 49 6e 63 2e 0a 20 2a 0a 20 2a 20 53 65 65 20 74  Inc.. *. * See t
00b0: 68 65 20 66 69 6c 65 20 22 6c 69 63 65 6e 73 65  he file "license
00c0: 2e 74 65 72 6d 73 22 20 66 6f 72 20 69 6e 66 6f  .terms" for info
00d0: 72 6d 61 74 69 6f 6e 20 6f 6e 20 75 73 61 67 65  rmation on usage
00e0: 20 61 6e 64 20 72 65 64 69 73 74 72 69 62 75 74   and redistribut
00f0: 69 6f 6e 0a 20 2a 20 6f 66 20 74 68 69 73 20 66  ion. * of this f
0100: 69 6c 65 2c 20 61 6e 64 20 66 6f 72 20 61 20 44  ile, and for a D
0110: 49 53 43 4c 41 49 4d 45 52 20 4f 46 20 41 4c 4c  ISCLAIMER OF ALL
0120: 20 57 41 52 52 41 4e 54 49 45 53 2e 0a 20 2a 0a   WARRANTIES.. *.
0130: 20 2a 20 52 43 53 3a 20 40 28 23 29 20 24 49 64   * RCS: @(#) $Id
0140: 3a 20 54 69 6d 65 72 48 61 6e 64 6c 65 72 54 65  : TimerHandlerTe
0150: 73 74 2e 6a 61 76 61 2c 76 20 31 2e 31 20 31 39  st.java,v 1.1 19
0160: 39 39 2f 30 35 2f 31 30 20 30 34 3a 30 38 3a 35  99/05/10 04:08:5
0170: 33 20 64 65 6a 6f 6e 67 20 45 78 70 20 24 0a 20  3 dejong Exp $. 
0180: 2a 2f 0a 0a 70 61 63 6b 61 67 65 20 74 65 73 74  */..package test
0190: 73 3b 0a 69 6d 70 6f 72 74 20 74 63 6c 2e 6c 61  s;.import tcl.la
01a0: 6e 67 2e 2a 3b 0a 0a 70 75 62 6c 69 63 20 63 6c  ng.*;..public cl
01b0: 61 73 73 20 54 69 6d 65 72 48 61 6e 64 6c 65 72  ass TimerHandler
01c0: 54 65 73 74 20 65 78 74 65 6e 64 73 20 54 69 6d  Test extends Tim
01d0: 65 72 48 61 6e 64 6c 65 72 20 7b 0a 0a 70 75 62  erHandler {..pub
01e0: 6c 69 63 20 69 6e 74 20 76 61 6c 75 65 20 3d 20  lic int value = 
01f0: 30 3b 0a 70 75 62 6c 69 63 20 62 6f 6f 6c 65 61  0;.public boolea
0200: 6e 20 65 72 72 20 3d 20 66 61 6c 73 65 3b 0a 0a  n err = false;..
0210: 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d  ../*. *---------
0220: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0230: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0240: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0250: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a  -------------. *
0260: 0a 20 2a 20 54 69 6d 65 72 48 61 6e 64 6c 65 72  . * TimerHandler
0270: 54 65 73 74 20 2d 2d 0a 20 2a 0a 20 2a 09 43 72  Test --. *. *.Cr
0280: 65 61 74 65 20 61 20 74 69 6d 65 72 20 68 61 6e  eate a timer han
0290: 64 6c 65 72 20 74 6f 20 62 65 20 66 69 72 65 64  dler to be fired
02a0: 20 61 66 74 65 72 20 74 68 65 20 67 69 76 65 6e   after the given
02b0: 20 74 69 6d 65 20 6c 61 70 73 65 2e 0a 20 2a 0a   time lapse.. *.
02c0: 20 2a 20 52 65 73 75 6c 74 73 3a 0a 20 2a 09 4e   * Results:. *.N
02d0: 6f 6e 65 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 20  one.. *. * Side 
02e0: 65 66 66 65 63 74 73 3a 0a 20 2a 09 54 68 65 20  effects:. *.The 
02f0: 74 69 6d 65 72 20 69 73 20 72 65 67 69 73 74 65  timer is registe
0300: 72 65 64 20 69 6e 20 74 68 65 20 6c 69 73 74 20  red in the list 
0310: 6f 66 20 74 69 6d 65 72 73 20 69 6e 20 74 68 65  of timers in the
0320: 20 67 69 76 65 6e 0a 20 2a 09 6e 6f 74 69 66 69   given. *.notifi
0330: 65 72 2e 20 41 66 74 65 72 20 6d 69 6c 6c 69 73  er. After millis
0340: 65 63 6f 6e 64 73 20 68 61 76 65 20 65 6c 61 70  econds have elap
0350: 73 65 64 2c 20 74 68 65 0a 20 2a 09 70 72 6f 63  sed, the. *.proc
0360: 65 73 73 54 69 6d 65 72 45 76 65 6e 74 28 29 20  essTimerEvent() 
0370: 6d 65 74 68 6f 64 20 77 69 6c 6c 20 62 65 20 69  method will be i
0380: 6e 76 6f 6b 65 64 20 65 78 61 63 74 6c 79 20 6f  nvoked exactly o
0390: 6e 63 65 20 69 6e 73 69 64 65 0a 20 2a 09 74 68  nce inside. *.th
03a0: 65 20 70 72 69 6d 61 72 79 20 74 68 72 65 61 64  e primary thread
03b0: 20 6f 66 20 74 68 65 20 6e 6f 74 69 66 69 65 72   of the notifier
03c0: 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d  .. *. *---------
03d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
03e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
03f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0400: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a  -------------. *
0410: 2f 0a 0a 70 75 62 6c 69 63 0a 54 69 6d 65 72 48  /..public.TimerH
0420: 61 6e 64 6c 65 72 54 65 73 74 28 0a 20 20 20 20  andlerTest(.    
0430: 4e 6f 74 69 66 69 65 72 20 6e 2c 09 09 09 2f 2f  Notifier n,...//
0440: 20 54 68 65 20 6e 6f 74 69 66 69 65 72 20 74 6f   The notifier to
0450: 20 66 69 72 65 20 74 68 65 20 65 76 65 6e 74 2e   fire the event.
0460: 0a 20 20 20 20 69 6e 74 20 6d 69 6c 6c 69 73 65  .    int millise
0470: 63 6f 6e 64 73 29 0a 7b 0a 20 20 20 20 73 75 70  conds).{.    sup
0480: 65 72 28 6e 2c 20 6d 69 6c 6c 69 73 65 63 6f 6e  er(n, millisecon
0490: 64 73 29 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d  ds);.}.../*. *--
04a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
04b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
04c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
04d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
04e0: 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20 70 72 6f 63 65  ----. *. * proce
04f0: 73 73 54 69 6d 65 72 45 76 65 6e 74 20 2d 2d 0a  ssTimerEvent --.
0500: 20 2a 0a 20 2a 09 54 68 69 73 20 6d 65 74 68 6f   *. *.This metho
0510: 64 20 69 73 20 63 61 6c 6c 65 64 20 77 68 65 6e  d is called when
0520: 20 74 68 65 20 74 69 6d 65 72 20 69 73 20 65 78   the timer is ex
0530: 70 69 72 65 64 2e 0a 20 2a 0a 20 2a 20 52 65 73  pired.. *. * Res
0540: 75 6c 74 73 3a 0a 20 2a 09 4e 6f 6e 65 2e 0a 20  ults:. *.None.. 
0550: 2a 0a 20 2a 20 53 69 64 65 20 65 66 66 65 63 74  *. * Side effect
0560: 73 3a 0a 20 2a 09 49 74 20 69 6e 63 72 65 6d 65  s:. *.It increme
0570: 6e 74 73 20 74 68 65 20 63 6f 75 6e 74 65 72 20  nts the counter 
0580: 66 6f 72 20 74 68 69 73 20 6f 62 6a 65 63 74 2e  for this object.
0590: 0a 20 2a 20 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d  . * . *---------
05a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
05b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
05c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
05d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a  -------------. *
05e0: 2f 0a 0a 70 75 62 6c 69 63 20 76 6f 69 64 0a 70  /..public void.p
05f0: 72 6f 63 65 73 73 54 69 6d 65 72 45 76 65 6e 74  rocessTimerEvent
0600: 28 29 20 7b 0a 20 20 20 20 76 61 6c 75 65 2b 2b  () {.    value++
0610: 3b 0a 20 20 20 20 69 66 20 28 65 72 72 29 20 7b  ;.    if (err) {
0620: 0a 09 74 68 72 6f 77 20 6e 65 77 20 4e 75 6c 6c  ..throw new Null
0630: 50 6f 69 6e 74 65 72 45 78 63 65 70 74 69 6f 6e  PointerException
0640: 28 22 54 69 6d 65 72 48 61 6e 64 6c 65 72 54 65  ("TimerHandlerTe
0650: 73 74 22 29 3b 0a 20 20 20 20 7d 0a 7d 0a 0a 7d  st");.    }.}..}
0660: 20 2f 2f 20 65 6e 64 20 54 65 73 74 54 69 6d 65   // end TestTime
0670: 72 0a 0a                                         r..