de.netseeker.ejoe
Class EJClient

java.lang.Object
  extended by de.netseeker.ejoe.EJClient
All Implemented Interfaces:
java.io.Serializable

public class EJClient
extends java.lang.Object
implements java.io.Serializable

This is the client component of EJOE. You have to use this component to send and retrieve data to/from a EJOE server.

Basic usage:

                             EJClient client = new EJClient("127.0.0.1", 12577); //you could also use EJConstants.EJOE_PORT
                             Object response = client.execute("Hello World");
                             ...
 

Usage with persistent connections:

                             EJClient client = new EJClient("127.0.0.1", 12577); //you could also use EJConstants.EJOE_PORT
                             client.enablePersistentConnection(true); //request a persistent connection to the server
                             Object response = client.execute("Hello World");
                             ...
                             reponse = client.execute("Bye World");
                             //close the connection
                             client.close();
                             ...
 

Usage with In-JVM EJServer:

                             EJClient client = new EJClient("127.0.0.1", 12577); //you could also use EJConstants.EJOE_PORT
                             client.setInJvm(true); //enable In-JVM mode, no socket connections will be used
                             Object response = client.execute("Hello World");
                             ...
                             reponse = client.execute("Bye World");
                             ...
 

Since:
0.3.0
Author:
netseeker aka Michael Manske
See Also:
Serialized Form

Constructor Summary
EJClient()
          Creates an instance of the EJOE client pre-configured with settings from the global ejoe.properties file.
EJClient(java.util.Properties properties)
          Creates an instance of the EJOE client pre-configured with settings from the given properties store.
EJClient(java.lang.String pathToConfigFile)
          Creates an instance of the EJOE client pre-configured with settings from a global properties file.
EJClient(java.lang.String host, int port)
          Creates an instance of the EJOE client preconfigured to use an instance of de.netseeker.ejoe.adapter.ObjectStreamAdapter for (de)serializing.
EJClient(java.lang.String host, int port, SerializeAdapter adapter)
          Creates an instance of the EJOE client.
EJClient(java.lang.String host, int port, SerializeAdapter adapter, boolean isPersistent, boolean isHttp, boolean useCompression)
          Creates an instance of the EJOE client.
 
Method Summary
 void close()
          Closes an existing persistent connection to the corresponding EJOE server.
 void enableCompression(boolean enable)
          Tells this client to use compression (if supported by the server) or not.
 void enableCompression(int compressionLevel)
          Tells this client to use compression (if supported by the server) with the given compression level.
 void enableHttpPackaging(boolean enable)
          Enables/disables usage of a persistent connection.
 void enablePersistentConnection(boolean enable)
          Enables/disables usage of a persistent connection.
 void enableRemoteClassloading()
          Enables remote classloading on the default remote port.
 java.lang.Object execute(java.lang.Object obj)
          Main entry point for client tier implementations.
 long executeAsync(java.lang.Object obj, EJAsyncCallback callback)
          Asynchrounous entry point for executing server invocations.
 ConnectionHeader getConnectionHeader()
          Getter method to get direct access to the underlying ConnectionHeader (as required by the WSIF port implementation)
 boolean isInJVM()
           
 void setAdapterStrategy(int adapterStrategy)
          Controls the used Adapter Strategy: ADAPTER_STRATEGY_DEFAULT: both, client and server, will serialize and deserialize objects.
 void setConnectionTimeout(int timeout)
          Sets the connection timeout used when waiting for server responses.
 void setInJVM(boolean injvm)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EJClient

public EJClient()
Creates an instance of the EJOE client pre-configured with settings from the global ejoe.properties file. You MUST provide such an property file on the classpath to use this constructor.


EJClient

public EJClient(java.lang.String pathToConfigFile)
Creates an instance of the EJOE client pre-configured with settings from a global properties file.

Parameters:
pathToConfigFile - path to the properties file

EJClient

public EJClient(java.util.Properties properties)
Creates an instance of the EJOE client pre-configured with settings from the given properties store.

Parameters:
properties - properties store containing EJClient settings

EJClient

public EJClient(java.lang.String host,
                int port)
Creates an instance of the EJOE client preconfigured to use an instance of de.netseeker.ejoe.adapter.ObjectStreamAdapter for (de)serializing.

Parameters:
host - address (dns name or ip address) of the EJOE server
port - port which the EJOE server listens to

EJClient

public EJClient(java.lang.String host,
                int port,
                SerializeAdapter adapter)
Creates an instance of the EJOE client.

Parameters:
host - address (dns name or ip address) of the EJOE server
port - port which the EJOE server listens to
adapter - the adapter used for (de)serializing input paramter objects for the server and the return values

EJClient

public EJClient(java.lang.String host,
                int port,
                SerializeAdapter adapter,
                boolean isPersistent,
                boolean isHttp,
                boolean useCompression)
Creates an instance of the EJOE client.

Parameters:
host - address (dns name or ip address) of the EJOE server
port - port which the EJOE server listens to
adapter - the adapter used for (de)serializing input paramter objects for the server and the return values
isPersistent - whether EJClient should use a persistent connection to the server or not
isHttp - whether EJClient should wrap requests in HTTP headers or not (lets EJClient socket data look like a HTTP 1.1 browser communication)
Method Detail

setConnectionTimeout

public void setConnectionTimeout(int timeout)
Sets the connection timeout used when waiting for server responses. A value of zero (the default) blocks indefinitely.

Parameters:
timeout - the new timeout in milliseconds

enableCompression

public void enableCompression(boolean enable)
Tells this client to use compression (if supported by the server) or not.

Parameters:
enable -

enableCompression

public void enableCompression(int compressionLevel)
Tells this client to use compression (if supported by the server) with the given compression level.

Parameters:
compressionLevel - the level of compression to use, must be in range of 0-9

enablePersistentConnection

public void enablePersistentConnection(boolean enable)
Enables/disables usage of a persistent connection. If persistent connection is disabled a new connection will be used for each request.

Parameters:
enable -

enableHttpPackaging

public void enableHttpPackaging(boolean enable)
Enables/disables usage of a persistent connection. If persistent connection is disabled a new connection will be used for each request.

Parameters:
enable -

isInJVM

public boolean isInJVM()
Returns:
the _inJVM

setInJVM

public void setInJVM(boolean injvm)
Parameters:
injvm - the _inJVM to set

setAdapterStrategy

public void setAdapterStrategy(int adapterStrategy)
Controls the used Adapter Strategy:

Parameters:
adapterStrategy -

enableRemoteClassloading

public void enableRemoteClassloading()
Enables remote classloading on the default remote port.


getConnectionHeader

public ConnectionHeader getConnectionHeader()
Getter method to get direct access to the underlying ConnectionHeader (as required by the WSIF port implementation)

Returns:
the used client configuration represented as ConnectionHeader

execute

public java.lang.Object execute(java.lang.Object obj)
                         throws java.io.IOException
Main entry point for client tier implementations. Handles all remote server calls... This method is threadsafe, ensuring that only one request is processed at a time.

Parameters:
obj - input objects for the EJOE Server
Returns:
the object(s) returned by the EJOE server
Throws:
java.io.IOException

executeAsync

public long executeAsync(java.lang.Object obj,
                         EJAsyncCallback callback)
Asynchrounous entry point for executing server invocations. This method works asynchrounous in that way, as it starts each invocation in a new thread.

Parameters:
obj - input objects for the EJOE Server
callback - callback instance which will be notified if the request was processed or an an error occured
Returns:
an unique identifier for the started asynchrounous server invocation

close

public void close()
Closes an existing persistent connection to the corresponding EJOE server. Invoking this method when using non-persistent connections has no effect.



Copyright © 2005-2007 netseeker. All Rights Reserved.