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: package org.cougaar.mts.rmi;
27:
28: import java.rmi.RemoteException;
29: import java.rmi.server.RemoteObject;
30: import java.rmi.server.UnicastRemoteObject;
31:
32: import org.cougaar.core.component.ServiceBroker;
33: import org.cougaar.core.mts.MessageAddress;
34: import org.cougaar.core.mts.MessageAttributes;
35: import org.cougaar.mts.base.MessageDeliverer;
36: import org.cougaar.mts.base.MisdeliveredMessageException;
37: import org.cougaar.mts.base.SocketFactory;
38: import org.cougaar.mts.std.AttributedMessage;
39:
40: /**
41: * RMI remote object providing the implementation of {@link MT}. Note
42: * that this class extends {@link RemoteObject}, not {@link
43: * UnicastRemoteObject}, and will therefore not be exported in tne
44: * super constructor. The export has to happen later, and is handled
45: * by {@link RMILinkProtocol}.
46: *
47: * <p>The transient tags shouldn't really be necessary since this
48: * object should always be serialized as an RMI stub. But leave them
49: * in anyway, for documentation if nothing else.
50: **/
51: public class MTImpl extends RemoteObject implements MT {
52: private MessageAddress address;
53:
54: private transient ServiceBroker sb;
55: private transient MessageDeliverer deliverer;
56: private transient SocketFactory socfac;
57:
58: public MTImpl(MessageAddress addr, ServiceBroker sb,
59: SocketFactory socfac) throws RemoteException {
60: // super(0, socfac, socfac);
61: super ();
62: this .socfac = socfac;
63: this .sb = sb;
64: this .address = addr;
65: this .deliverer = (MessageDeliverer) sb.getService(this ,
66: MessageDeliverer.class, null);
67: }
68:
69: public SocketFactory getSocketFactory() {
70: return socfac;
71: }
72:
73: public MessageAttributes rerouteMessage(AttributedMessage message)
74: throws MisdeliveredMessageException {
75: return deliverer.deliverMessage(message, message.getTarget());
76: }
77:
78: public MessageAddress getMessageAddress() {
79: return address;
80: }
81:
82: public String toString() {
83: return "MT for " + getMessageAddress();
84: }
85: }
|