- java.lang.Object
-
- aeonics.entity.Entity
-
- aeonics.manager.Manager.Type
-
- aeonics.manager.Network
-
- All Implemented Interfaces:
Exportable
,Snapshotable
public abstract class Network extends Manager.Type
Creates and manages network connections
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Network.Connection
This class represents an established network connection ready read and write data.static class
Network.SecurityOptions
This class represents a set of security options that can be applied to secure aNetwork.Connection
.static interface
Network.Server
This class represents a listening server connection ready to accept clients.
-
Constructor Summary
Constructors Constructor Description Network()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Network.Connection
client(java.lang.String remoteAddress, int remotePort)
Establishes a client connection to the specified remote network endpoint.abstract Network.Connection
client(java.lang.String remoteAddress, int remotePort, Network.SecurityOptions options)
Establishes a secure client connection to the specified remote network endpoint.static javax.net.ssl.KeyManager
keyManager(Network.SecurityOptions options, boolean clientMode)
Returns a key manager that matches the provided security options.java.lang.Class<? extends Manager.Type>
manager()
Hardcoded manager typeabstract void
refresh()
This method forces the network manager to refresh its internal state if necessary.abstract Network.Connection
securize(Network.Connection unsecure, Network.SecurityOptions options)
Transforms an unsecure connection into a secure one using the provided security options.Network.Server
server(java.lang.String localAddress, int localPort)
Opens a server that listens for incoming network connections.abstract Network.Server
server(java.lang.String localAddress, int localPort, Network.SecurityOptions options)
Opens a server that listens for incoming network connectionsstatic javax.net.ssl.SSLContext
sslContext(Network.SecurityOptions options, boolean clientMode)
Returns an ssl context that matches the provided security optionsstatic javax.net.ssl.SSLEngine
sslEngine(Network.SecurityOptions options, boolean clientMode)
Returns an ssl engine that matches the provided security optionsstatic javax.net.ssl.TrustManager
trustManager(Network.SecurityOptions options)
Returns a trust manager that matches the provided security options.-
Methods inherited from class aeonics.manager.Manager.Type
category, internal
-
Methods inherited from class aeonics.entity.Entity
addRelation, addRelation, addRelation, cast, clearRelation, config, defineRelation, equals, export, firstRelation, hashCode, hasRelation, id, name, name, onCreate, onRemove, onUpdate, parameter, relations, relationships, removeRelation, snapshot, type, valueOf, valueOf
-
-
-
-
Method Detail
-
manager
public final java.lang.Class<? extends Manager.Type> manager()
Hardcoded manager type- Specified by:
manager
in classManager.Type
- Returns:
- the type of manager
-
keyManager
public static javax.net.ssl.KeyManager keyManager(Network.SecurityOptions options, boolean clientMode)
Returns a key manager that matches the provided security options. This is useful to initialize SSL connections.- Parameters:
options
- the security options (may be null)clientMode
- whether or not the role is client (or otherwise server)- Returns:
- a matching key manager
-
trustManager
public static javax.net.ssl.TrustManager trustManager(Network.SecurityOptions options)
Returns a trust manager that matches the provided security options. This is useful to initialize SSL connections.- Parameters:
options
- the security options (may be null)- Returns:
- a matching trust manager
-
sslEngine
public static javax.net.ssl.SSLEngine sslEngine(Network.SecurityOptions options, boolean clientMode)
Returns an ssl engine that matches the provided security options- Parameters:
options
- the security options (may be null)clientMode
- whether or not the role is client (or otherwise server)- Returns:
- a matching ssl engine
-
sslContext
public static javax.net.ssl.SSLContext sslContext(Network.SecurityOptions options, boolean clientMode)
Returns an ssl context that matches the provided security options- Parameters:
options
- the security options (may be null)clientMode
- whether or not the role is client (or otherwise server)- Returns:
- a matching ssl context
-
securize
public abstract Network.Connection securize(Network.Connection unsecure, Network.SecurityOptions options)
Transforms an unsecure connection into a secure one using the provided security options. If the connection is alreadyNetwork.Connection.isSecure()
then it is returned as is. If the security options argument is null, the connection is returned as is.Caution that if some existing
Network.Connection.onReady()
orNetwork.Connection.onClose()
handlers were set on the original connection, you should adjust them on the returned secured connection instead- Parameters:
unsecure
- the connection to secureoptions
- the security options for this connection, may be null- Returns:
- the secured connection
- See Also:
Network.SecurityOptions
-
client
public Network.Connection client(java.lang.String remoteAddress, int remotePort) throws java.io.IOException
Establishes a client connection to the specified remote network endpoint. This is equivalent to callingclient(String, int, SecurityOptions)
without security options.- Parameters:
remoteAddress
- the remote ip addressremotePort
- the remote port number- Returns:
- the connected network connection
- Throws:
java.io.IOException
- if a underlying I/O error happens
-
client
public abstract Network.Connection client(java.lang.String remoteAddress, int remotePort, Network.SecurityOptions options) throws java.io.IOException
Establishes a secure client connection to the specified remote network endpoint.- Parameters:
remoteAddress
- the remote ip addressremotePort
- the remote port numberoptions
- the client security options for this connection, may be null to specify "without security options"- Returns:
- the connected network connection
- Throws:
java.io.IOException
- if a underlying I/O error happens
-
server
public Network.Server server(java.lang.String localAddress, int localPort) throws java.io.IOException
Opens a server that listens for incoming network connections. This is equivalent to callingserver(String, int, SecurityOptions)
without security options.- Parameters:
localAddress
- the local ip addresslocalPort
- the local port number- Returns:
- the connected network channel
- Throws:
java.io.IOException
- if a underlying I/O error happens
-
server
public abstract Network.Server server(java.lang.String localAddress, int localPort, Network.SecurityOptions options) throws java.io.IOException
Opens a server that listens for incoming network connections- Parameters:
localAddress
- the local ip addresslocalPort
- the local port numberoptions
- the server security options to apply to all clients, may be null to specify "without security options"- Returns:
- the connected network channel
- Throws:
java.io.IOException
- if a underlying I/O error happens
-
refresh
public abstract void refresh()
This method forces the network manager to refresh its internal state if necessary.
-
-