AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
addShutdownHook (Callable funct, ...) yoix.system
addShutdownHook (Pointer ptr, ...)  
 
Arranges to call funct from a special thread right before Java's virtual machine shuts down. Everything that follows funct in the addShutdownHook call are arguments that will be passed to funct when it is executed. addShutdownHook aborts with a badcall error if funct requires a different number of arguments than were actually supplied in the addShutdownHook call.

If the first argument is a Pointer then *ptr must be Callable and it will be the Function or Builtin that addShutdownHook executes. In addition, when *ptr is a Function and ptr is a Dictionary or any other object that associates names with values, then ptr is used as the function's local context. In other words, ptr will be used to resolve this and it will also be searched immediately before the function's global context.

Multiple addShutdownHook calls are allowed and each request is currently queued, so the function that is queued first is the one that that is called first. In addition, a function that calls exit while it is running in the special shutdown thread currently halts Java's virtual machine, which means other queued functions will not get a chance to run.
 
 Example:   The program
import yoix.*.*;

VM.create = FALSE;

setErrorLimit(1);

One(double time) {
    printf("%s: with argument %d\n", argv[0], argv[1]);
    x = 100;     // trigger an error
    sleep(1);
}

Two(double time) {
    printf("%s: with argument %d\n", argv[0], argv[1]);
    exit(1);     // prevents Three from running
    sleep(1);
}

Three(double time) {
    printf("%s: with argument %d\n", argv[0], argv[1]);
    sleep(1);
}

printf("Adding shutdown hook One\n");
addShutdownHook(One, time());
sleep(2);

printf("Adding shutdown hook Two\n");
addShutdownHook(Two, time());
sleep(2);

printf("Adding shutdown hook Three\n");
addShutdownHook(Three, time());
sleep(2);

printf("Sleeping for a few seconds\n");
sleep(3);
printf("All done...\n");
prints something like
Adding shutdown hook One
Adding shutdown hook Two
Adding shutdown hook Three
Sleeping for a few seconds
All done...
One: with argument 1143210616
Error: undefined; Name: x; Line: 9; Source: /tmp/xxx
Two: with argument 1143210618
on standard output if you sit back and let it run, but you also should try interrupting it.
 
 Return:   none
 
 See Also:   isShutdownThread

 

Yoix is a registered trademark of AT&T Inc.