com.accendia.iris.client
Class ServerContext

java.lang.Object
  extended by com.accendia.iris.client.ServerContext

public class ServerContext
extends java.lang.Object

Encapsulates the client socket connection and information about the applications installed on the server: commands, factories and client callback interfaces. It is responsible for managing parallel access to the socket connection and to dispatch the client callback invocation made from the server side. All client application threads may invoke the server using proxies obtain from a shared ServerContext without synchronizing.

Since:
1.0

Constructor Summary
ServerContext()
          Creates an unconnected ServerContext.
ServerContext(java.lang.String hostname, int port, java.lang.String user, char[] password, boolean secure)
          Creates a connected server context.
 
Method Summary
 void addConnectionListener(IConnectionListener connectionListener)
          Adds a connection listener to this server context.
 void addHandler(java.lang.String appName, java.lang.Object handler)
          Registers a client handler for processing client callback invocations made from the server side.
 void close()
          Close the connection to the server.
 java.lang.Object getCommandProxy(java.lang.String appName, java.lang.String cmdName)
          Returns a proxy to a server command.
 java.lang.Object getFactoryProxy(java.lang.String appName, java.lang.String factoryName)
          Returns a proxy to a server command factory.
 java.net.InetAddress getInetAddress()
          Returns the IP address of the application server.
 int getPort()
          Returns the listening port number of the application server.
 java.net.InetAddress getProxyAddress()
           
 int getProxyPort()
           
 boolean getSecure()
           
 java.lang.String getServerVersion()
          Returns a comma separated list of the application versions installed on the server and the server version, example iris2.1,jns2.1,acme3.4.
 java.lang.String getUser()
           
 boolean isClosed()
           
 void login(java.lang.String user, char[] password)
          Login to the server.
 void removeAllHandlers(java.lang.String appName)
          Removes all registered client handlers for a remote application
 void removeConnectionListener(IConnectionListener connectionListener)
          Removes a connection listener from this server context.
 void removeHandler(java.lang.String appName, java.lang.Object handler)
          Removes a registered client handler
 void setApplicationDescriptor(java.lang.String applicationName, ApplicationDescriptor descriptor)
          This method is invoked by the client code in order to declare the remote application metadata and preventing the invocation of the server for this purpose.
 void setProxyAddress(java.net.InetAddress proxyhost, int proxyport)
          Set the HTTP proxy address if the client id behind a firewall and must connect to the server through an HTTP proxy.
 void setSecure(boolean secure)
          Sets the secure connection flag.
 void setServerAddress(java.net.InetAddress hostAddress, int port)
          Sets the address of the application server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerContext

public ServerContext()
Creates an unconnected ServerContext. Use this constructor if connection through an HTTP proxy.

Since:
2.1

ServerContext

public ServerContext(java.lang.String hostname,
                     int port,
                     java.lang.String user,
                     char[] password,
                     boolean secure)
              throws java.io.IOException,
                     LoginFailedException
Creates a connected server context.

Parameters:
hostname - The name of the host where the server is running
port - The server port.
user - The name of the user that is connecting to the server
password - The user password
secure - Set to true if secure communication is required
Throws:
java.io.IOException - If a network error occurs.
LoginFailedException - If the user does not exist, a wrong password was provided or a secure connection could not be established when secure flag is specified.
Since:
1.0
Method Detail

getServerVersion

public java.lang.String getServerVersion()
Returns a comma separated list of the application versions installed on the server and the server version, example iris2.1,jns2.1,acme3.4. The application version may be used to verify newer client version are connected to the corresponding server version or to ensure backward compatibility with older remote applications.

The application version is optional and is declared in the application.properties file:


        Application.version=acme3.4
 

Returns:
Server version string
Since:
2.1

setServerAddress

public void setServerAddress(java.net.InetAddress hostAddress,
                             int port)
Sets the address of the application server. The server address must be set before connection.

Parameters:
hostAddress - IP address of the application server
port - Listening port number of the server
Since:
2.1

getInetAddress

public java.net.InetAddress getInetAddress()
Returns the IP address of the application server.

Returns:
IP address of the application server
Since:
2.1

getPort

public int getPort()
Returns the listening port number of the application server.

Returns:
The listening port number of the server.
Since:
2.1

setProxyAddress

public void setProxyAddress(java.net.InetAddress proxyhost,
                            int proxyport)
Set the HTTP proxy address if the client id behind a firewall and must connect to the server through an HTTP proxy. If the HTTP proxy address is set the connection to the server will be established using an HTTP CONNECT method.

Parameters:
proxyhost - IP address of the HTTP proxy server
proxyport - Listening port number of the proxy server
Since:
2.1

getProxyAddress

public java.net.InetAddress getProxyAddress()
Returns:
The IP address of the proxy server
Since:
2.1

getProxyPort

public int getProxyPort()
Returns:
The listening port number of the HTTP proxy server
Since:
2.1

setSecure

public void setSecure(boolean secure)
Sets the secure connection flag. A secure connection means the data is encrypted and the server is authenticated. A server certificate must be installed on the server in order to be able to establish secure connections.

Parameters:
secure - Secure connection flag
Since:
2.1

getSecure

public boolean getSecure()
Returns:
Returns true if the connection is secure.
Since:
2.1

getUser

public java.lang.String getUser()
Returns:
Returns the logged in user.
Since:
2.1

login

public void login(java.lang.String user,
                  char[] password)
           throws java.io.IOException,
                  LoginFailedException
Login to the server. The method must be called after the server address was set.

Parameters:
user - The user name
password - The login password
Throws:
java.io.IOException - A communication error occurred
LoginFailedException - The login failed
Since:
2.1

getCommandProxy

public java.lang.Object getCommandProxy(java.lang.String appName,
                                        java.lang.String cmdName)
                                 throws RemoteObjectNotFoundException,
                                        java.lang.ClassNotFoundException,
                                        java.io.IOException
Returns a proxy to a server command. The client may cast the returned object to an interface implemented by the command.

Parameters:
appName - The name of the application installed on the server.
cmdName - The name of the command.
Returns:
A command proxy for the remote command.
Throws:
RemoteObjectNotFoundException - If the command does not exist.
java.lang.ClassNotFoundException - If any of the interfaces implemented by the command is not deployed with the client.
java.io.IOException - If a network errors occurs.
Since:
1.0

getFactoryProxy

public java.lang.Object getFactoryProxy(java.lang.String appName,
                                        java.lang.String factoryName)
                                 throws RemoteObjectNotFoundException,
                                        java.lang.ClassNotFoundException,
                                        java.io.IOException
Returns a proxy to a server command factory. The client may cast the returned object to an interface implemented by the command factory.

Parameters:
appName - The name of the application installed on the server.
factoryName - The name of the command factory.
Returns:
A command proxy for the remote command factory.
Throws:
RemoteObjectNotFoundException - If the command factory does not exist.
java.lang.ClassNotFoundException - If any of the interfaces implemented by the command factory is not deployed with the client.
java.io.IOException - If a network errors occurs.
Since:
1.0

addHandler

public void addHandler(java.lang.String appName,
                       java.lang.Object handler)
                throws java.lang.ClassNotFoundException,
                       java.io.IOException
Registers a client handler for processing client callback invocations made from the server side. The handler must implement interfaces declared by the application as client callback interfaces. The handler will be invoked when the server calls a client callback interface implemented by the handler. If a handler was already registered for a callback interface the newer handler will replace the previous handler for all the client interfaces implemented. The previously registered handler will still receive notifications for the client interfaces not implemented by the handler that is being registered.

Parameters:
appName - The application for which the handler is registered
handler - The client handler instance
Throws:
java.lang.ClassNotFoundException - If any of the client callback interfaces declared by the application is not deployed on the client.
java.io.IOException - If a network error occurs.
Since:
1.0

removeHandler

public void removeHandler(java.lang.String appName,
                          java.lang.Object handler)
Removes a registered client handler

Parameters:
appName - The name of the application from which the handler is removed.
handler - The client handler instance.
Since:
1.0

removeAllHandlers

public void removeAllHandlers(java.lang.String appName)
Removes all registered client handlers for a remote application

Parameters:
appName - The name of the application for which the handlers are removed
Since:
2.2

addConnectionListener

public void addConnectionListener(IConnectionListener connectionListener)
Adds a connection listener to this server context. The registered connection listeners will be invoken when the server connection is closed due to a network failure.

Parameters:
connectionListener - The connection listener to be added.
Since:
2.1

removeConnectionListener

public void removeConnectionListener(IConnectionListener connectionListener)
Removes a connection listener from this server context.

Parameters:
connectionListener - The connection listener to be removed.
Since:
2.1

setApplicationDescriptor

public void setApplicationDescriptor(java.lang.String applicationName,
                                     ApplicationDescriptor descriptor)
This method is invoked by the client code in order to declare the remote application metadata and preventing the invocation of the server for this purpose. This is usefull when the client and server are deployed on networks with high latency.

Parameters:
applicationName - The name of the remote application
descriptor - The application descriptor
Since:
2.2

close

public void close()
Close the connection to the server.

Since:
1.0

isClosed

public boolean isClosed()
Returns:
Return true if the connection to the server is closed.
Since:
1.0