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.tools.server.rmi;
028:
029: import java.rmi.RemoteException;
030: import java.rmi.server.UnicastRemoteObject;
031: import java.util.List;
032:
033: import org.cougaar.tools.server.ProcessDescription;
034: import org.cougaar.tools.server.RemoteFileSystem;
035: import org.cougaar.tools.server.RemoteHost;
036: import org.cougaar.tools.server.RemoteProcessManager;
037:
038: /**
039: * Server implementation to create and control processes on a
040: * single host, plus basic file-system support.
041: */
042: class RemoteHostImpl extends UnicastRemoteObject implements
043: RemoteHostDecl {
044:
045: private final RemoteHost rh;
046:
047: private final Object lock = new Object();
048: private RemoteProcessManagerDecl rpmd;
049: private RemoteFileSystemDecl rfsd;
050:
051: public RemoteHostImpl(RemoteHost rh) throws RemoteException {
052: this .rh = rh;
053: if (rh == null) {
054: throw new NullPointerException();
055: }
056: }
057:
058: public RemoteProcessManagerDecl getRemoteProcessManager()
059: throws Exception {
060: synchronized (lock) {
061: if (rpmd == null) {
062: RemoteProcessManager rpm = rh.getRemoteProcessManager();
063: rpmd = ((rpm != null) ? (new RemoteProcessManagerImpl(
064: rpm)) : null);
065: }
066: }
067: return rpmd;
068: }
069:
070: public RemoteFileSystemDecl getRemoteFileSystem() throws Exception {
071: synchronized (lock) {
072: if (rfsd == null) {
073: RemoteFileSystem rfs = rh.getRemoteFileSystem();
074: rfsd = ((rfs != null) ? (new RemoteFileSystemImpl(rfs))
075: : null);
076: }
077: }
078: return rfsd;
079: }
080:
081: public RemoteProcessDecl createRemoteProcess(ProcessDescription pd,
082: RemoteListenableConfigWrapper rlcw) throws Exception {
083: return getRemoteProcessManager().createRemoteProcess(pd, rlcw);
084: }
085:
086: public RemoteProcessDecl getRemoteProcess(String procName)
087: throws Exception {
088: return getRemoteProcessManager().getRemoteProcess(procName);
089: }
090:
091: //
092: // delegate the rest:
093: //
094:
095: public long ping() throws Exception {
096: return rh.ping();
097: }
098:
099: public int killRemoteProcess(String procName) throws Exception {
100: return getRemoteProcessManager().killRemoteProcess(procName);
101: }
102:
103: public ProcessDescription getProcessDescription(String procName)
104: throws Exception {
105: return getRemoteProcessManager()
106: .getProcessDescription(procName);
107: }
108:
109: public List listProcessDescriptions(String procGroup)
110: throws Exception {
111: return getRemoteProcessManager().listProcessDescriptions(
112: procGroup);
113: }
114:
115: public List listProcessDescriptions() throws Exception {
116: return getRemoteProcessManager().listProcessDescriptions();
117: }
118: }
|