# EventSchedulerImpl.jcs Sample

This topic inludes the source code for the EventSchedulerImpl.jcs Sample.

## Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/ExtensionDevKit/ControlDevKit/ControlFeatures/controlEvents/

## Sample Source Code

`01 package controlEvents; 02 03 import com.bea.control.*; 04 import java.util.Date; 05 06 /** 07 * EventScheduler illustrates how you can schedule a control's 08 * callbacks to occur at specified times. This example receives 09 * a request to send a callback after a specified interval. The 10 * control's client passes in the interval. Note that this control 11 * does not use a Timer control. 12 * 13 * @jcs:jc-jar palette-priority="7" label="EventScheduler" 14 * version="1.0" 15 * icon-16="/images/buffer_16.gif" 16 * icon-32="/images/buffer_32.gif" 17 * group-name="Feature Sample Controls" 18 * description="Schedules a callback at a point in the future" 19 */ 20 public class EventSchedulerImpl implements EventScheduler, com.bea.control.ControlSource 21 { 22 public Callback callback; 23 24 /** 25 * @common:context 26 */ 27 com.bea.control.ControlContext context; 28 29 /** 30 * The setAlarm method receives an interval value, then uses 31 * that value to schedule its callback. The callback will occur 32 * on or after the interval's passing. 33 * 34 * @common:operation 35 */ 36 public void setAlarm(long delayInMsecs) 37 { 38 /* 39 * The alarm is set for the current time plus the interval 40 * specified by the client. 41 */ 42 long alarmTime = new Date().getTime() + delayInMsecs; 43 44 /* Arguments for the scheduled callback are stored in 45 * an Object array. That array is passed as an argument 46 * to the scheduleEvent method. 47 */ 48 Object[] callbackArgs = new Object[2]; 49 callbackArgs[0] = "Time to wake up."; 50 callbackArgs[1] = new Long(alarmTime); 51 52 /* 53 * The scheduleEvent method schedules the callback's firing by 54 * specifying the callback's name, its arguments (as an Object array), 55 * the time at/after which the callback should be sent, and a boolean 56 * value indicating whether the callback should be ignored (and no 57 * exception generated) if the callback is sent to a finished 58 * instance. 59 */ 60 context.scheduleEvent("onAlarmRinging", callbackArgs, alarmTime, true); 61 } 62 63 /** 64 * cancelAlarm provides a way for clients to cancel the alarm. 65 * The cancelEvents method specifies which scheduled callback should 66 * be canceled. 67 * 68 * @common:operation 69 */ 70 public void cancelAlarm() 71 { 72 context.cancelEvents("onAlarmRinging"); 73 } 74 75 76 77 }`