com.gridsystems.innergrid.api
Class AbstractConnection

java.lang.Object
  extended by com.gridsystems.innergrid.api.AbstractConnection
All Implemented Interfaces:
Connection
Direct Known Subclasses:
DirectConnection

public abstract class AbstractConnection
extends java.lang.Object
implements Connection

Connects to a single server.

Author:
Rodrigo Ruiz, Xmas

Field Summary
protected  java.lang.String attachmentFormat
          Attachments format.
protected  boolean chunkedTransferEnabled
          Chunked Transfer encoding control flag.
protected  boolean connChecked
          Flag that avoid repeating the connection test.
protected  java.lang.String contextPath
          Web-application context path base.
protected  Credentials credentials
          The credentials to use.
static int DEFAULT_RETRIES
          Default retries.
protected  java.lang.String host
          Host to connect.
protected  boolean keepAliveEnabled
          Keep-Alive control flag.
protected  int port
          Port to connect.
protected  int retries
          Number of retries.
protected  boolean secured
          Secured connection.
protected  SSLConnectionInfo sslInfo
          SSL Connection Info.
protected  java.lang.Object sync
          To synchronise host, port, and secured access.
protected  int timeout
          Connection timeout.
 
Fields inherited from interface com.gridsystems.innergrid.api.Connection
DEFAULT_TIMEOUT, DIME, MIME, MTOM
 
Constructor Summary
AbstractConnection(java.lang.String h, int p, boolean secure, SSLConnectionInfo sslinfo, Credentials credentials)
          Creates an instance of the connector to the specified host:port, and using the specified credentials.
AbstractConnection(java.lang.String h, int p, java.lang.String ctxPath, boolean secure, SSLConnectionInfo sslinfo, Credentials credentials)
          Creates an instance of the connector to the specified host:port, and using the specified credentials.
 
Method Summary
 void checkConnection()
          Checks that the connection is directed to an open port with the proper protocol.
 void clearChecks()
          Avoids checking the connection data.
 java.lang.String getAttachmentFormat()
          Gets the attachment format (DIME, MIME or MTOM).
abstract  java.lang.String getBaseUrl()
          Gets the base URL for all API URLs.
 java.lang.String getContextPath()
          Gets the connection context path.
 Credentials getCredentials()
          Gets the credentials for the connection.
 java.lang.String getHost()
          Gets Host to connect.
 int getPort()
          Gets Port to connect.
 int getRetries()
          Gets retries.
 SSLConnectionInfo getSSLConnectionInfo()
          Obtain additional information to establish SSL connection.
 int getTimeout()
          Gets the connection timeout.
 java.net.URL getUrl(java.lang.String apiName)
          Gets a target URL to the SOAP service for the specified API (Internal use only).
 boolean isChunkedTransferEnabled()
          Gets the value of the chunked transfer control flag.
 boolean isKeepAliveEnabled()
          Gets the keep-alive control flag value.
 boolean isSecured()
          Use a secured connection.
abstract  void manageException(KernelException ke, int retry)
          Manage Exceptions.
 void setAttachmentFormat(java.lang.String format)
          Sets the attachment format (DIME, MIME or MTOM).
 void setChunkedTransferEnabled(boolean enabled)
          Enables or disables chunked transfer encoding (it is enabled by default).
 void setContextPath(java.lang.String ctxPath)
          Sets the context path template.
 void setKeepAliveEnabled(boolean enabled)
          Sets the keep-alive control flag value.
 void setRetries(int retries)
          Sets retires.
 void setTimeout(int timeout)
          Sets the connection timeout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.gridsystems.innergrid.api.Connection
close, success
 

Field Detail

DEFAULT_RETRIES

public static final int DEFAULT_RETRIES
Default retries.

See Also:
Constant Field Values

host

protected java.lang.String host
Host to connect.


port

protected int port
Port to connect.


contextPath

protected java.lang.String contextPath
Web-application context path base.


secured

protected boolean secured
Secured connection.


sslInfo

protected SSLConnectionInfo sslInfo
SSL Connection Info.


credentials

protected Credentials credentials
The credentials to use.


timeout

protected int timeout
Connection timeout.


chunkedTransferEnabled

protected boolean chunkedTransferEnabled
Chunked Transfer encoding control flag.


keepAliveEnabled

protected boolean keepAliveEnabled
Keep-Alive control flag.


attachmentFormat

protected java.lang.String attachmentFormat
Attachments format.


retries

protected int retries
Number of retries.


connChecked

protected boolean connChecked
Flag that avoid repeating the connection test.


sync

protected java.lang.Object sync
To synchronise host, port, and secured access.

Constructor Detail

AbstractConnection

public AbstractConnection(java.lang.String h,
                          int p,
                          java.lang.String ctxPath,
                          boolean secure,
                          SSLConnectionInfo sslinfo,
                          Credentials credentials)
Creates an instance of the connector to the specified host:port, and using the specified credentials.

Parameters:
h - The remote server host name or address
p - The remote server port
ctxPath - Context path base
secure - Whether to use a secure protocol(HTTPS) or not
sslinfo - Additional info to establish SSL connection
credentials - The user name.

AbstractConnection

public AbstractConnection(java.lang.String h,
                          int p,
                          boolean secure,
                          SSLConnectionInfo sslinfo,
                          Credentials credentials)
Creates an instance of the connector to the specified host:port, and using the specified credentials.

Parameters:
h - The remote server host name or address
p - The remote server port
secure - Whether to use a secure protocol(HTTPS) or not
sslinfo - Additional info to establish SSL connection
credentials - The user name.
Method Detail

getHost

public java.lang.String getHost()
Gets Host to connect.

Specified by:
getHost in interface Connection
Returns:
Host to connect.

getPort

public int getPort()
Gets Port to connect.

Specified by:
getPort in interface Connection
Returns:
Port to connect.

getContextPath

public java.lang.String getContextPath()
Gets the connection context path.

By default, Kernel services are located in /kernel/api.

Specified by:
getContextPath in interface Connection
Returns:
The connection base context path

setContextPath

public void setContextPath(java.lang.String ctxPath)
Sets the context path template.

Parameters:
ctxPath - Template

isSecured

public boolean isSecured()
Use a secured connection.

Specified by:
isSecured in interface Connection
Returns:
true if this connection uses SSL.

getTimeout

public int getTimeout()
Gets the connection timeout.

Specified by:
getTimeout in interface Connection
Returns:
The connection timeout in milliseconds

setTimeout

public void setTimeout(int timeout)
Sets the connection timeout. By default, it is 30 seconds.

Specified by:
setTimeout in interface Connection
Parameters:
timeout - The connection timeout in milliseconds

isChunkedTransferEnabled

public boolean isChunkedTransferEnabled()
Gets the value of the chunked transfer control flag.

This flag is set to true by default.

Specified by:
isChunkedTransferEnabled in interface Connection
Returns:
The current transfer control flag value

setChunkedTransferEnabled

public void setChunkedTransferEnabled(boolean enabled)
Enables or disables chunked transfer encoding (it is enabled by default).

This flag must be set to false when connecting to servers that do not support this transfer encoding. In particular, simple servers used by MUSE for event notification require this flag to be disabled.

Embedded servers used during unit tests will usually require this encoding to be disabled too.

Specified by:
setChunkedTransferEnabled in interface Connection
Parameters:
enabled - The new flag value

isKeepAliveEnabled

public boolean isKeepAliveEnabled()
Gets the keep-alive control flag value.

Specified by:
isKeepAliveEnabled in interface Connection
Returns:
The current flag value

setKeepAliveEnabled

public void setKeepAliveEnabled(boolean enabled)
Sets the keep-alive control flag value.

Keep-alive is disabled by default for scalability reasons. However, if several calls must be performed in a short time period, enabling it can drastically improve the performance.

Specified by:
setKeepAliveEnabled in interface Connection
Parameters:
enabled - The new flag value

getAttachmentFormat

public java.lang.String getAttachmentFormat()
Gets the attachment format (DIME, MIME or MTOM).

Specified by:
getAttachmentFormat in interface Connection
Returns:
The attachment format to use

setAttachmentFormat

public void setAttachmentFormat(java.lang.String format)
Sets the attachment format (DIME, MIME or MTOM). By default, the format is automatically selected through the Service deployment meta-data. By setting this value, the user can override these default values.

Specified by:
setAttachmentFormat in interface Connection
Parameters:
format - The attachment format to use

getRetries

public int getRetries()
Gets retries.

Returns:
Return retries value.

setRetries

public void setRetries(int retries)
Sets retires.

Parameters:
retries - New value for retries

getUrl

public java.net.URL getUrl(java.lang.String apiName)
                    throws KernelException
Gets a target URL to the SOAP service for the specified API (Internal use only).

Specified by:
getUrl in interface Connection
Parameters:
apiName - the name of the API
Returns:
the target URL to apiName
Throws:
KernelException - CLT008 if the resulting URL is invalid

getCredentials

public Credentials getCredentials()
Gets the credentials for the connection.

Specified by:
getCredentials in interface Connection
Returns:
the needed Credentials. They can be null.

getSSLConnectionInfo

public SSLConnectionInfo getSSLConnectionInfo()
Obtain additional information to establish SSL connection.

Returns:
SLL Connection Info

getBaseUrl

public abstract java.lang.String getBaseUrl()
                                     throws KernelException
Gets the base URL for all API URLs.

Returns:
The base URL
Throws:
KernelException - If the URL is not well formed

manageException

public abstract void manageException(KernelException ke,
                                     int retry)
                              throws KernelException
Manage Exceptions.

Specified by:
manageException in interface Connection
Parameters:
ke - KernelException captured
retry - Number of retry
Throws:
KernelException - Throws ke exception if do not desire retry.

clearChecks

public final void clearChecks()
Avoids checking the connection data.

When the connection is used the first time, it performs a test to find out if the data (specially the protocol used) is right. Calling this method avoids calling the tests, improving the connection performance for that first time.


checkConnection

public final void checkConnection()
                           throws KernelException
Checks that the connection is directed to an open port with the proper protocol.

Specified by:
checkConnection in interface Connection
Throws:
KernelException - CLT060 if the port cannot be reached.


Copyright © 2007-2008 Grid Systems, S.A.. All Rights Reserved.