Skip to content
Merged
7 changes: 0 additions & 7 deletions jme3-networking/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
dependencies {
api project(':jme3-core')
}

javadoc {
// Disable doclint for JDK8+.
if (JavaVersion.current().isJava8Compatible()){
options.addStringOption('Xdoclint:none', '-quiet')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,18 @@ public abstract class AbstractMessage implements Message
{
private transient boolean reliable = true;

/**
* Creates a reliable message by default.
*/
protected AbstractMessage()
{
}

/**
* Creates a message with the specified reliability.
*
* @param reliable true if the message should be sent reliably
*/
protected AbstractMessage( boolean reliable )
{
this.reliable = reliable;
Expand Down
31 changes: 30 additions & 1 deletion jme3-networking/src/main/java/com/jme3/network/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,38 +52,50 @@ public interface Client extends MessageConnection
/**
* Returns true if this client is fully connected to the
* host.
*
* @return true if the client is connected to the server
*/
public boolean isConnected();

/**
* Returns true if this client has been started and is still
* running.
*
* @return true if the client has been started and not yet closed
*/
public boolean isStarted();

/**
* Returns a unique ID for this client within the remote
* server or -1 if this client isn't fully connected to the
* server.
*
* @return the server-assigned client id, or -1 if not connected
*/
public int getId();

/**
* Returns the 'game name' for servers to which this client should be able
* to connect. This should match the 'game name' set on the server or this
* client will be turned away.
*
* @return the configured game name
*/
public String getGameName();

/**
* Returns the game-specific version of the server this client should
* be able to connect to.
*
* @return the expected game protocol version
*/
public int getVersion();

/**
* Returns the manager for client services. Client services extend
* the functionality of the client.
*
* @return the client service manager
*/
public ClientServiceManager getServices();

Expand All @@ -108,35 +120,49 @@ public interface Client extends MessageConnection
/**
* Adds a listener that will be notified about connection
* state changes.
*
* @param listener the listener to add
*/
public void addClientStateListener( ClientStateListener listener );

/**
* Removes a previously registered connection listener.
*
* @param listener the listener to remove
*/
public void removeClientStateListener( ClientStateListener listener );

/**
* Adds a listener that will be notified when any message or object
* is received from the server.
*
* @param listener the listener to add
*/
public void addMessageListener( MessageListener<? super Client> listener );

/**
* Adds a listener that will be notified when messages of the specified
* types are received.
*
* @param listener the listener to add
* @param classes the message classes the listener should receive
*/
public void addMessageListener( MessageListener<? super Client> listener, Class... classes );

/**
* Removes a previously registered wildcard listener. This does
* not remove this listener from any type-specific registrations.
*
* @param listener the listener to remove
*/
public void removeMessageListener( MessageListener<? super Client> listener );

/**
* Removes a previously registered type-specific listener from
* the specified types.
*
* @param listener the listener to remove
* @param classes the message classes to unregister
*/
public void removeMessageListener( MessageListener<? super Client> listener, Class... classes );

Expand All @@ -146,13 +172,16 @@ public interface Client extends MessageConnection
* is to close the connection and provide an appropriate DisconnectInfo
* to any ClientStateListeners. If the application adds its own error
* listeners then it must take care of closing the connection itself.
*
* @param listener the listener to add
*/
public void addErrorListener( ErrorListener<? super Client> listener );

/**
* Removes a previously registered error listener.
*
* @param listener the listener to remove
*/
public void removeErrorListener( ErrorListener<? super Client> listener );
}


Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public interface ClientStateListener
/**
* Called when the specified client is fully connected to
* the remote server.
*
* @param c the connected client
*/
public void clientConnected( Client c );

Expand All @@ -52,6 +54,9 @@ public interface ClientStateListener
* server. If info is null then the client shut down the
* connection normally, otherwise the info object contains
* additional information about the disconnect.
*
* @param c the disconnected client
* @param info extra disconnect information, or null for a normal close
*/
public void clientDisconnected( Client c, DisconnectInfo info );

Expand All @@ -61,8 +66,20 @@ public interface ClientStateListener
*/
public class DisconnectInfo
{
/**
* A human-readable reason for the disconnect, if provided.
*/
public String reason;
/**
* The underlying disconnect cause, if one is available.
*/
public Throwable error;

/**
* Creates an empty disconnect information object.
*/
public DisconnectInfo() {
}

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@ public interface ConnectionListener
/**
* Called when a connection has been added to the specified server and
* is fully setup.
*
* @param server the server that accepted the connection
* @param conn the newly connected client
*/
public void connectionAdded( Server server, HostedConnection conn );

/**
* Called when a connection has been removed from the specified
* server.
*
* @param server the server that removed the connection
* @param conn the disconnected client
*/
public void connectionRemoved( Server server, HostedConnection conn );
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@
/**
* Notified when errors happen on a connection.
*
* @param <S> the connection or endpoint type that produced the error
* @version $Revision$
* @author Paul Speed
*/
public interface ErrorListener<S>
{
/**
* Handles an error that occurred on the specified source.
*
* @param source the connection or endpoint that produced the error
* @param t the error that was raised
*/
public void handleError( S source, Throwable t );
}
5 changes: 4 additions & 1 deletion jme3-networking/src/main/java/com/jme3/network/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
/**
* Determines a true or false value for a given input.
*
* @param <T> the input type tested by this filter
* @version $Revision$
* @author Paul Speed
*/
Expand All @@ -43,8 +44,10 @@ public interface Filter<T>
/**
* Returns true if the specified input is accepted by this
* filter.
*
* @param input the value to test
* @return true if the input is accepted
*/
public boolean apply( T input );
}


29 changes: 28 additions & 1 deletion jme3-networking/src/main/java/com/jme3/network/Filters.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ private Filters() {
/**
* Creates a filter that returns true for any value in the specified
* list of values and false for all other cases.
*
* @param <T> the value type
* @param values the accepted values
* @return a membership filter for the provided values
*/
@SuppressWarnings("unchecked")
public static <T> Filter<T> in( T... values )
Expand All @@ -62,6 +66,10 @@ public static <T> Filter<T> in( T... values )
/**
* Creates a filter that returns true for any value in the specified
* collection and false for all other cases.
*
* @param <T> the value type
* @param collection the accepted values
* @return a membership filter for the provided collection
*/
public static <T> Filter<T> in( Collection<? extends T> collection )
{
Expand All @@ -72,6 +80,10 @@ public static <T> Filter<T> in( Collection<? extends T> collection )
* Creates a filter that returns true for any value NOT in the specified
* list of values and false for all other cases. This is the equivalent
* of calling not(in(values)).
*
* @param <T> the value type
* @param values the rejected values
* @return a negated membership filter for the provided values
*/
@SuppressWarnings("unchecked")
public static <T> Filter<T> notIn( T... values )
Expand All @@ -83,6 +95,10 @@ public static <T> Filter<T> notIn( T... values )
* Creates a filter that returns true for any value NOT in the specified
* collection and false for all other cases. This is the equivalent
* of calling not(in(collection)).
*
* @param <T> the value type
* @param collection the rejected values
* @return a negated membership filter for the provided collection
*/
public static <T> Filter<T> notIn( Collection<? extends T> collection )
{
Expand All @@ -92,6 +108,10 @@ public static <T> Filter<T> notIn( Collection<? extends T> collection )
/**
* Creates a filter that returns true for inputs that are .equals()
* equivalent to the specified value.
*
* @param <T> the value type
* @param value the accepted value
* @return an equality filter
*/
public static <T> Filter<T> equalTo( T value )
{
Expand All @@ -102,6 +122,10 @@ public static <T> Filter<T> equalTo( T value )
* Creates a filter that returns true for inputs that are NOT .equals()
* equivalent to the specified value. This is the equivalent of calling
* not(equalTo(value)).
*
* @param <T> the value type
* @param value the rejected value
* @return an inequality filter
*/
public static <T> Filter<T> notEqualTo( T value )
{
Expand All @@ -111,6 +135,10 @@ public static <T> Filter<T> notEqualTo( T value )
/**
* Creates a filter that returns true when the specified delegate filter
* returns false, and vice versa.
*
* @param <T> the value type
* @param f the delegate filter
* @return a negated filter
*/
public static <T> Filter<T> not( Filter<T> f )
{
Expand Down Expand Up @@ -166,4 +194,3 @@ public boolean apply( T input )
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ public interface HostedConnection extends MessageConnection
{
/**
* Returns the Server instance that is hosting this connection.
*
* @return the owning server
*/
public Server getServer();

/**
* Returns the server-unique ID for this client.
*
* @return the hosted connection id
*/
public int getId();

Expand All @@ -57,19 +61,25 @@ public interface HostedConnection extends MessageConnection
* as a string. This may or may not be unique per connection depending
* on the type of transport. It is provided for information and filtering
* purposes.
*
* @return the remote address string
*/
public String getAddress();

/**
* Closes and removes this connection from the server
* sending the optional reason to the remote client.
*
* @param reason the optional disconnect reason
*/
public void close( String reason );

/**
* Sets a session attribute specific to this connection. If the value
* is set to null then the attribute is removed.
*
* @param name the attribute name
* @param value the attribute value, or null to remove it
* @return The previous session value for this key or null
* if there was no previous value.
*/
Expand All @@ -78,12 +88,18 @@ public interface HostedConnection extends MessageConnection
/**
* Retrieves a previously stored session attribute or
* null if no such attribute exists.
*
* @param <T> the expected attribute type
* @param name the attribute name
* @return the stored attribute value, or null if none exists
*/
public <T> T getAttribute( String name );

/**
* Returns a read-only set of attribute names currently stored
* for this client session.
*
* @return the current attribute names
*/
public Set<String> attributeNames();
}
Loading
Loading