01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.core.service;
28:
29: import org.cougaar.bootstrap.SystemProperties;
30: import org.cougaar.core.component.Service;
31:
32: /**
33: * This service is used to tell the agent (or node) to exit, for
34: * example due to an {@link java.lang.OutOfMemoryError}.
35: * <p>
36: * The intent is to allow major components to report that they
37: * have recognised that they have been corrupted by various means and
38: * so should be restarted.
39: *
40: * @property org.cougaar.core.service.SuicideService.enable If true, will enable
41: * suicide of Nodes and Agents. Otherwise, the suicide API exists but only logs
42: * attempts rather than actually kills anything. The default is false.
43: * @property org.cougaar.core.service.SuicideService.proactive If true, the SuicideService
44: * will attempt to kill things proactively when it notices low-memory situations. Defaults
45: * to true, but only takes effect if the SuicideService is enabled.
46: * @property org.cougaar.core.service.SuicideService.proactivePeriod Defines the period
47: * of proactive suicide checks, in seconds. By default, this is 1.
48: * @property org.cougaar.core.service.SuicideService.lowMem Specify a quantity of
49: * memory to use as the definition of "dangerously low" for proactive kill situations.
50: * This is interpreted as a factor of Runtime.maxMemory(). The default value is "0.02" meaning
51: * 2 percent. If this value is greater than or equal to 1.0, then it is interpreted
52: * as a number of kilobytes. Examples: if maxMemory is 100Mb, then "0.005" and "512" are both
53: * interpreted as one half a megabyte.
54: */
55: public interface SuicideService extends Service {
56: /**
57: * If the VM exits as a result of a suicide call, it will do so
58: * using this value.
59: */
60: int EXIT_CODE = 5;
61:
62: String SUICIDE_PROP = (SuicideService.class).getName() + ".enable";
63: boolean isSuicideEnabled_default = false;
64: boolean isSuicideEnabled = SystemProperties.getBoolean(
65: SUICIDE_PROP, isSuicideEnabled_default);
66:
67: String PROACTIVE_PROP = (SuicideService.class).getName()
68: + ".proactive";
69: boolean isProactiveEnabled_default = true;
70: boolean isProactiveEnabled = SystemProperties.getBoolean(
71: PROACTIVE_PROP, isProactiveEnabled_default);
72:
73: String PROPERIOD_PROP = (SuicideService.class).getName()
74: + ".proactivePeriod";
75: double proactivePeriod_default = 1.0;
76: double proactivePeriod = SystemProperties.getDouble(PROPERIOD_PROP,
77: proactivePeriod_default);
78:
79: String LOWMEM_PROP = (SuicideService.class).getName() + ".lowMem";
80: double lowMem_default = 0.02;
81: double lowMem = SystemProperties.getDouble(LOWMEM_PROP,
82: lowMem_default);
83:
84: /**
85: * Report a fatal error and die. This call might not return.
86: *
87: * @param component Which component should be killed. May be specified as
88: * null, implying that the whole node is suspect, or a specific component
89: * descriptor (e.g. an agent name). It is probably illegal to specify a component
90: * other than yourself or null.
91: * @param error The error indicating the problem. An attempt will be made
92: * to log the error during the component's death throws. May not be specified
93: * as null.
94: */
95: void die(Object component, Throwable error);
96: }
|