001: /*
002: * <copyright>
003: *
004: * Copyright 2001-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.mobility.arch;
028:
029: import org.cougaar.core.component.ComponentDescription;
030: import org.cougaar.core.mobility.MoveTicket;
031: import org.cougaar.core.mts.MessageAddress;
032: import org.cougaar.core.service.LoggingService;
033:
034: /**
035: * Base class for mobility-related handlers.
036: */
037: public abstract class AbstractHandler implements Runnable {
038:
039: protected final MobilitySupport support;
040:
041: protected final MessageAddress id;
042: protected final MessageAddress nodeId;
043: protected final MoveTicket moveTicket;
044: protected final LoggingService log;
045:
046: public AbstractHandler(MobilitySupport support) {
047: this .support = support;
048: // save these for easy base-class access
049: this .id = support.getId();
050: this .nodeId = support.getNodeId();
051: this .moveTicket = support.getTicket();
052: this .log = support.getLog();
053: }
054:
055: public abstract void run();
056:
057: // msg-sender
058:
059: protected void sendTransfer(ComponentDescription desc, Object state) {
060: support.sendTransfer(desc, state);
061: }
062:
063: protected void sendAck() {
064: support.sendAck();
065: }
066:
067: protected void sendNack(Throwable throwable) {
068: support.sendNack(throwable);
069: }
070:
071: // agent-container
072:
073: protected void addAgent(ComponentDescription desc) {
074: support.addAgent(desc);
075: }
076:
077: protected void removeAgent() {
078: support.removeAgent();
079: }
080:
081: // detachable mobility-listener
082:
083: protected void onDispatch() {
084: support.onDispatch();
085: }
086:
087: protected void onArrival() {
088: support.onArrival();
089: }
090:
091: protected void onFailure(Throwable throwable) {
092: support.onFailure(throwable);
093: }
094:
095: // to-string
096:
097: public String toString() {
098: return "Move (?) for agent " + id;
099: }
100: }
|