001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.core.node.service.jvmdump;
028:
029: import org.cougaar.core.component.Component;
030: import org.cougaar.core.component.ServiceBroker;
031: import org.cougaar.core.component.ServiceProvider;
032: import org.cougaar.core.node.NodeControlService;
033: import org.cougaar.core.service.JvmStackDumpService;
034:
035: /**
036: * This component provides the {@link JvmStackDumpService}.
037: * <p>
038: * This is simply a node-level wrapper for our package-private
039: * JNI implementation (JniStackDump).
040: * <p>
041: * This can be loaded in a node by adding this line to a
042: * node's ".ini" or CSMART configuration:
043: * <pre>
044: * Node.AgentManager.Agent.JvmDump = org.cougaar.core.node.service.jvmdump.JvmStackDumpServiceComponent
045: * </pre>
046: */
047: public class JvmStackDumpServiceComponent extends
048: org.cougaar.util.GenericStateModelAdapter implements Component {
049: private ServiceBroker sb;
050:
051: private ServiceProvider mySP;
052:
053: // ignore "setServiceBroker", we want the node-level service broke
054:
055: public void setNodeControlService(NodeControlService ncs) {
056: if (ncs != null) {
057: this .sb = ncs.getRootServiceBroker();
058: }
059: }
060:
061: public void load() {
062: super .load();
063: // create and advertise our service
064: this .mySP = new JvmStackDumpServiceProviderImpl();
065: sb.addService(JvmStackDumpService.class, mySP);
066: }
067:
068: public void unload() {
069: // revoke our service
070: if (mySP != null) {
071: sb.revokeService(JvmStackDumpService.class, mySP);
072: mySP = null;
073: }
074: super .unload();
075: }
076:
077: /**
078: * Service provider for our <code>JvmStackDumpService</code>.
079: */
080: private class JvmStackDumpServiceProviderImpl implements
081: ServiceProvider {
082:
083: // single service instance, since it's just a wrapper
084: private final JvmStackDumpServiceImpl SINGLETON = new JvmStackDumpServiceImpl();
085:
086: public Object getService(ServiceBroker sb, Object requestor,
087: Class serviceClass) {
088: if (serviceClass != JvmStackDumpService.class) {
089: throw new IllegalArgumentException(
090: "JvmStackDumpService does not provide a service for: "
091: + serviceClass);
092: }
093: return SINGLETON;
094: }
095:
096: public void releaseService(ServiceBroker sb, Object requestor,
097: Class serviceClass, Object service) {
098: if (!(service instanceof JvmStackDumpServiceImpl)) {
099: throw new IllegalArgumentException(
100: "JvmStackDumpService unable to release service: "
101: + ((service != null) ? service
102: .getClass().toString() : "null"));
103: }
104: // ignore our singleton
105: }
106:
107: private class JvmStackDumpServiceImpl implements
108: JvmStackDumpService {
109: public boolean dumpStack() {
110: // call our package-private implementation!
111: return JniStackDump.dumpStack();
112: }
113: }
114: }
115: }
|