diff --git a/src/java/com/threerings/presents/annotation/TransportHint.java b/src/java/com/threerings/presents/annotation/TransportHint.java index 96cd3142c..bff207ab5 100644 --- a/src/java/com/threerings/presents/annotation/TransportHint.java +++ b/src/java/com/threerings/presents/annotation/TransportHint.java @@ -26,7 +26,7 @@ import java.lang.annotation.Target; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import com.threerings.presents.net.Transport; +import com.threerings.presents.net.TransportType; /** * An annotation indicating the type of transport desired for a distributed object @@ -37,7 +37,7 @@ import com.threerings.presents.net.Transport; public @interface TransportHint { /** The type of transport to use. */ - Transport.Type type () default Transport.Type.RELIABLE_ORDERED; + TransportType type () default TransportType.RELIABLE_ORDERED; /** For ordered transport types, the channel to use. */ int channel () default 0; diff --git a/src/java/com/threerings/presents/net/Transport.java b/src/java/com/threerings/presents/net/Transport.java index d1c13a21c..94e5b20ac 100644 --- a/src/java/com/threerings/presents/net/Transport.java +++ b/src/java/com/threerings/presents/net/Transport.java @@ -32,94 +32,21 @@ import com.samskivert.util.HashIntMap; */ public class Transport { - /** - * The available types of transport. - */ - public enum Type - { - /** - * Messages are neither guaranteed to arrive nor, if they do arrive, to arrive in order - * and without duplicates. Functionally identical to UDP. - */ - UNRELIABLE_UNORDERED(false, false) { - public Type combine (Type other) { - return other; // we defer to all - } - }, - - /** - * Messages are not guaranteed to arrive, but if they do arrive, then they will arrive in - * order and without duplicates. In other words, out-of-order packets will be dropped. - */ - UNRELIABLE_ORDERED(false, true) { - public Type combine (Type other) { - return other.isReliable() ? RELIABLE_ORDERED : this; - } - }, - - /** - * Messages are guaranteed to arrive eventually, but they are not guaranteed to arrive in - * order. - */ - RELIABLE_UNORDERED(true, false) { - public Type combine (Type other) { - return other.isOrdered() ? RELIABLE_ORDERED : this; - } - }, - - /** - * Messages are guaranteed to arrive, and will arrive in the order in which they are sent. - * Functionally identical to TCP. - */ - RELIABLE_ORDERED(true, true) { - public Type combine (Type other) { - return this; // we override all - } - }; - - /** - * Checks whether this transport type guarantees that messages will be delivered. - */ - public boolean isReliable () - { - return _reliable; - } - - /** - * Checks whether this transport type guarantees that messages will be received in the - * order in which they were sent, if they are received at all. - */ - public boolean isOrdered () - { - return _ordered; - } - - /** - * Returns a transport type that combines the requirements of this type with those of the - * specified other type. - */ - public abstract Type combine (Type other); - - Type (boolean reliable, boolean ordered) - { - _reliable = reliable; - _ordered = ordered; - } - - protected boolean _reliable, _ordered; - } - /** The unreliable/unordered mode of transport. */ - public static final Transport UNRELIABLE_UNORDERED = getInstance(Type.UNRELIABLE_UNORDERED); + public static final Transport UNRELIABLE_UNORDERED = getInstance( + TransportType.UNRELIABLE_UNORDERED); /** The unreliable/ordered mode on the default channel. */ - public static final Transport UNRELIABLE_ORDERED = getInstance(Type.UNRELIABLE_ORDERED, 0); + public static final Transport UNRELIABLE_ORDERED = getInstance( + TransportType.UNRELIABLE_ORDERED, 0); /** The reliable/unordered mode. */ - public static final Transport RELIABLE_UNORDERED = getInstance(Type.RELIABLE_UNORDERED); + public static final Transport RELIABLE_UNORDERED = getInstance( + TransportType.RELIABLE_UNORDERED); /** The reliable/ordered mode on the default channel. */ - public static final Transport RELIABLE_ORDERED = getInstance(Type.RELIABLE_ORDERED, 0); + public static final Transport RELIABLE_ORDERED = getInstance( + TransportType.RELIABLE_ORDERED, 0); /** The default mode of transport. */ public static final Transport DEFAULT = RELIABLE_ORDERED; @@ -127,7 +54,7 @@ public class Transport /** * Returns the shared instance with the specified parameters. */ - public static Transport getInstance (Type type) + public static Transport getInstance (TransportType type) { return getInstance(type, 0); } @@ -135,14 +62,14 @@ public class Transport /** * Returns the shared instance with the specified parameters. */ - public static Transport getInstance (Type type, int channel) + public static Transport getInstance (TransportType type, int channel) { // were there more parameters in transport objects, it would be better to have a single map // of instances and use Transport objects as keys (as in examples of the flyweight // pattern). however, doing it this way avoids the need to create a new object on lookup if (_unordered == null) { - _unordered = new HashMap(); - _ordered = new HashMap>(); + _unordered = new HashMap(); + _ordered = new HashMap>(); } // for unordered transport, we map on the type alone @@ -169,7 +96,7 @@ public class Transport /** * Returns the type of transport. */ - public Type getType () + public TransportType getType () { return _type; } @@ -231,27 +158,27 @@ public class Transport return "[type=" + _type + ", channel=" + _channel + "]"; } - protected Transport (Type type) + protected Transport (TransportType type) { this(type, 0); } - protected Transport (Type type, int channel) + protected Transport (TransportType type, int channel) { _type = type; _channel = channel; } /** The type of transport. */ - protected Type _type; + protected TransportType _type; /** The transport channel. */ protected int _channel; /** Unordered instances mapped by type (would use {@link java.util.EnumMap}, but it doesn't * work with Retroweaver). */ - protected static HashMap _unordered; + protected static HashMap _unordered; /** Ordered instances mapped by type and channel. */ - protected static HashMap> _ordered; + protected static HashMap> _ordered; } diff --git a/src/java/com/threerings/presents/net/TransportType.java b/src/java/com/threerings/presents/net/TransportType.java new file mode 100644 index 000000000..c083cdbbf --- /dev/null +++ b/src/java/com/threerings/presents/net/TransportType.java @@ -0,0 +1,99 @@ +// +// $Id$ +// +// Narya library - tools for developing networked games +// Copyright (C) 2002-2008 Three Rings Design, Inc., All Rights Reserved +// http://www.threerings.net/code/narya/ +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.threerings.presents.net; + +/** + * The available types of transport. + */ +public enum TransportType +{ + /** + * Messages are neither guaranteed to arrive nor, if they do arrive, to arrive in order + * and without duplicates. Functionally identical to UDP. + */ + UNRELIABLE_UNORDERED(false, false) { + public TransportType combine (TransportType other) { + return other; // we defer to all + } + }, + + /** + * Messages are not guaranteed to arrive, but if they do arrive, then they will arrive in + * order and without duplicates. In other words, out-of-order packets will be dropped. + */ + UNRELIABLE_ORDERED(false, true) { + public TransportType combine (TransportType other) { + return other.isReliable() ? RELIABLE_ORDERED : this; + } + }, + + /** + * Messages are guaranteed to arrive eventually, but they are not guaranteed to arrive in + * order. + */ + RELIABLE_UNORDERED(true, false) { + public TransportType combine (TransportType other) { + return other.isOrdered() ? RELIABLE_ORDERED : this; + } + }, + + /** + * Messages are guaranteed to arrive, and will arrive in the order in which they are sent. + * Functionally identical to TCP. + */ + RELIABLE_ORDERED(true, true) { + public TransportType combine (TransportType other) { + return this; // we override all + } + }; + + /** + * Checks whether this transport type guarantees that messages will be delivered. + */ + public boolean isReliable () + { + return _reliable; + } + + /** + * Checks whether this transport type guarantees that messages will be received in the + * order in which they were sent, if they are received at all. + */ + public boolean isOrdered () + { + return _ordered; + } + + /** + * Returns a transport type that combines the requirements of this type with those of the + * specified other type. + */ + public abstract TransportType combine (TransportType other); + + TransportType (boolean reliable, boolean ordered) + { + _reliable = reliable; + _ordered = ordered; + } + + protected boolean _reliable, _ordered; +} diff --git a/src/java/com/threerings/presents/tools/GenDObjectTask.java b/src/java/com/threerings/presents/tools/GenDObjectTask.java index ab05544bc..a7a5cb273 100644 --- a/src/java/com/threerings/presents/tools/GenDObjectTask.java +++ b/src/java/com/threerings/presents/tools/GenDObjectTask.java @@ -219,7 +219,7 @@ public class GenDObjectTask extends Task transport = "DEFAULT"; } else { transport = "getInstance(\n" + - " com.threerings.presents.net.Transport.Type." + + " com.threerings.presents.net.TransportType." + hint.type().name() + ", " + hint.channel() + ")"; } ctx.put("transport", "com.threerings.presents.net.Transport." + transport); diff --git a/src/java/com/threerings/presents/tools/InvocationTask.java b/src/java/com/threerings/presents/tools/InvocationTask.java index d9b6fc8fd..587d65880 100644 --- a/src/java/com/threerings/presents/tools/InvocationTask.java +++ b/src/java/com/threerings/presents/tools/InvocationTask.java @@ -263,7 +263,7 @@ public abstract class InvocationTask extends Task if (hint == null) { return "Transport.DEFAULT"; } - return "Transport.getInstance(Transport.Type." + + return "Transport.getInstance(TransportType." + hint.type().name() + ", " + hint.channel() + ")"; }