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.io.IOException;
030: import java.util.List;
031:
032: import org.cougaar.tools.server.ProcessDescription;
033: import org.cougaar.tools.server.RemoteListenableConfig;
034: import org.cougaar.tools.server.RemoteProcess;
035: import org.cougaar.tools.server.RemoteProcessManager;
036:
037: /**
038: * This implementation of RemoteProcessManager that communicates
039: * with a single "host:port" via RMI.
040: *
041: * @see RemoteProcessManager
042: */
043: class RemoteProcessManagerStub implements RemoteProcessManager {
044:
045: private RemoteProcessManagerDecl rpmd;
046:
047: public RemoteProcessManagerStub(RemoteProcessManagerDecl rpmd) {
048: this .rpmd = rpmd;
049: }
050:
051: public RemoteProcess createRemoteProcess(ProcessDescription pd,
052: RemoteListenableConfig rlc) throws Exception {
053:
054: // wrap listener(s)
055: RemoteListenableConfigWrapper rlcw = new RemoteListenableConfigWrapper(
056: rlc);
057:
058: // get reference to remote process on app server
059: RemoteProcessDecl rpd;
060: try {
061: rpd = (RemoteProcessDecl) rpmd
062: .createRemoteProcess(pd, rlcw);
063: } catch (IOException ioe) {
064: System.out
065: .println("Unable to create RemoteProcess (IO Failure)");
066: throw ioe;
067: } catch (RuntimeException re) {
068: System.out
069: .println("Unable to create RemoteProcess (Runtime Failure)");
070: throw re;
071: }
072: if (rpd == null) {
073: return null;
074: }
075:
076: // wrap for client
077: RemoteProcessStub rps = new RemoteProcessStub(rpd, pd);
078: return rps;
079: }
080:
081: public RemoteProcess getRemoteProcess(String procName)
082: throws Exception {
083: RemoteProcessDecl rpd = rpmd.getRemoteProcess(procName);
084: if (rpd == null) {
085: return null;
086: }
087: ProcessDescription pd = rpd.getProcessDescription();
088: RemoteProcessStub rps = new RemoteProcessStub(rpd, pd);
089: return rps;
090: }
091:
092: //
093: // delegate the rest:
094: //
095:
096: public int killRemoteProcess(String procName) throws Exception {
097: return rpmd.killRemoteProcess(procName);
098: }
099:
100: public ProcessDescription getProcessDescription(String procName)
101: throws Exception {
102: return rpmd.getProcessDescription(procName);
103: }
104:
105: public List listProcessDescriptions(String procGroup)
106: throws Exception {
107: return rpmd.listProcessDescriptions(procGroup);
108: }
109:
110: public List listProcessDescriptions() throws Exception {
111: return rpmd.listProcessDescriptions();
112: }
113: }
|