01: /*
02: * <copyright>
03: *
04: * Copyright 2001-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:
27: package org.cougaar.pizza.relay;
28:
29: import org.cougaar.core.mts.MessageAddress;
30: import org.cougaar.core.relay.Relay;
31: import org.cougaar.core.util.UID;
32: import org.cougaar.pizza.Constants;
33:
34: import java.io.Serializable;
35:
36: /**
37: * A {@link org.cougaar.core.relay.Relay.TargetFactory} for {@link RSVPRelayTarget}s.
38: * <p/>
39: * This factory is required in order to produce the correct Relay.Target
40: * when the Relay has been received by the target Agent.
41: */
42: public class RSVPTargetRelayFactory implements Relay.TargetFactory,
43: Serializable {
44:
45: // Typically you only need one instance of your TargteFactory.
46: private final static Relay.TargetFactory SINGLETON_FACTORY = new RSVPTargetRelayFactory();
47:
48: /** Get s singleton instance of the TargetFactory */
49: public static synchronized Relay.TargetFactory getTargetFactory() {
50: return SINGLETON_FACTORY;
51: }
52:
53: /**
54: * Whenever you have a factory you should implement the readResolve method on
55: * an object that implements Serializable.
56: *
57: * The reason is to prevent proliferation of new copies of
58: * the factory every time the relay gets sent. (The relay has a reference
59: * to this factory.)
60: *
61: * GC would eventually remove those extra copies, but having a readResolve method wastes less time.
62: */
63: private Object readResolve() {
64: return SINGLETON_FACTORY;
65: }
66:
67: /**
68: * TargetFactory implementation - create an RSVPRelayTarget.
69: * Note that the RSVPRelay doesn't use the token slot, though some implementations might.
70: */
71: public Relay.Target create(UID uid, MessageAddress source,
72: Object content, Relay.Token token) {
73: // Note that in our case the content is always Constants.INVITATION_QUERY
74: RSVPRelayTarget result = new RSVPRelayTarget(uid, source,
75: content);
76: return result;
77: }
78:
79: }
|