org.idoox.transport
Interface Transport


public interface Transport

Interface for a transport layer. The transport is loaded and destroyed by transport repository. It can be CLIENT type and/or SERVER type.

Since:
4.0
Component:
Core

Field Summary
static short CLIENT
          Client transport.
static short SERVER
          Server transport.
 
Method Summary
 void destroy()
          Destroys the transport.
 Endpoint[] getAbsolutePath(java.lang.String path)
          Returns all possible endpoints for local path.
 java.lang.String getLocalPath(URI endpoint)
          Returns local path or null.
 java.util.Set getMethods()
          Get supported methods for connections.
 int getType()
          Gets type of the transport.
 boolean isStarted()
          If a server is started.
 void load(Configurable config)
          Loads the transport.
 ClientConnection newConnection(URI uri, TransportMethod method, java.util.Map properties)
          Factory for new outgoing connections to the given URI.
 ConnectionHandler setHandler(ConnectionHandler handler)
          Sets handler for new incoming connections.
 void start(URI endpoint)
          Starts listening for new incoming connections on given endpoint.
 void stop()
          Stops listening for new incoming connections.
 

Field Detail

SERVER

public static final short SERVER
Server transport. This type of transport is started, stopped and is a factory for new ServerConnections. This connections must be passed to ConnectionHandler if this one is registered.

See Also:
Constant Field Values

CLIENT

public static final short CLIENT
Client transport. This type of transport is a factory for new ClientConnections.

See Also:
Constant Field Values
Method Detail

load

public void load(Configurable config)
Loads the transport.

Parameters:
config - configurable object with transport config

destroy

public void destroy()
Destroys the transport.


getType

public int getType()
Gets type of the transport.

Returns:
combination of SERVER and CLIENT

getMethods

public java.util.Set getMethods()
Get supported methods for connections.

Returns:
a combination of TransportMethod.GET, TransportMethod.POST, TransportMethod.PUT and TransportMethod.DELETE

start

public void start(URI endpoint)
           throws TransportStartException
Starts listening for new incoming connections on given endpoint. The endpoint is a string like http://googoo:6060/wasp/ and it's used for determining absolute path and local path on the transport or null for default configuration.

Parameters:
endpoint - null or endpoint string
Throws:
TransportStartException - if the transport couldn't be started
See Also:
getLocalPath(org.idoox.transport.URI), getAbsolutePath(java.lang.String)

stop

public void stop()
Stops listening for new incoming connections.


isStarted

public boolean isStarted()
If a server is started.

Returns:
true if a server is started, otherwise false

setHandler

public ConnectionHandler setHandler(ConnectionHandler handler)
Sets handler for new incoming connections. This handler must be called when new ServerConnection is accepted. The connection must contain input and output messages if given transport method requires these.

Parameters:
handler - the handler
Returns:
previous handler or null

getLocalPath

public java.lang.String getLocalPath(URI endpoint)
Returns local path or null. Returns also null if this transport is only client one.

Parameters:
endpoint - the endpoint being tested
Returns:
the local path of the endpoint
See Also:
TransportRepository.getLocalPath(org.idoox.transport.URI)

getAbsolutePath

public Endpoint[] getAbsolutePath(java.lang.String path)
                           throws java.net.MalformedURLException
Returns all possible endpoints for local path. Returns null if this transport is only client one.

Parameters:
path - the local path of the endpoint
Returns:
the endpoints for given path
Throws:
java.net.MalformedURLException
See Also:
TransportRepository.getAbsolutePath(String)

newConnection

public ClientConnection newConnection(URI uri,
                                      TransportMethod method,
                                      java.util.Map properties)
                               throws java.io.IOException
Factory for new outgoing connections to the given URI. The connection must contain input and output messages if given transport method requires these.

Parameters:
uri - URI
method - the method of a transport like TransportMethod.GET
properties - properties for the transport or null if they aren't set
Returns:
new connection
Throws:
java.io.IOException - if an I/O error occurs