org.rhq.enterprise.communications.command.client
Class ClientRemotePojoFactory

java.lang.Object
  extended by org.rhq.enterprise.communications.command.client.ClientRemotePojoFactory

public class ClientRemotePojoFactory
extends Object

This class is a factory of proxies that can be used to invoke methods on a remote POJO. This class provides configuration settings like guaranteed delivery, the timeout, async send mode and send throttling. These configuration settings define how the proxies will behave. If a remote POJO interface is annotated to indicate those settings (e.g. with Timeout or other remote POJO annotations), the annotations will take effect and override the settings in this class unless this object was told to ignore those annotations.

Author:
John Mazzitelli

Nested Class Summary
static class ClientRemotePojoFactory.GuaranteedDelivery
          Settings describing whether this factory generates proxies that have guaranteed delivery by default.
 
Constructor Summary
ClientRemotePojoFactory(ClientCommandSender ccs)
          Constructor for ClientRemotePojoFactory.
 
Method Summary
<T> T
getRemotePojo(Class<T> targetInterface)
          This method returns a proxy to the remote POJO.
 Long getTimeout()
          Returns the timeout (in milliseconds) that any new proxies will use for all POJO calls.
 boolean isAsynch()
          Returns true if new remote POJO proxies should make their invocations asynchronously; false means the invocations will be synchronous (and thus act like a "normal" method call).
 boolean isDeliveryGuaranteed()
          Returns the flag to indicate if the remote POJO calls should be made with guaranteed delivery.
 boolean isIgnoreAnnotations()
          If true, any remote POJO proxy returned by getRemotePojo(Class) will ignore all annotations define in that remote POJO's interface which allows you to override settings hardcoded in the annotations with settings defined in this class (e.g.
 boolean isSendThrottled()
          Returns the flag to indicate if the remote POJO calls should be "send-throttleable", that is, will need to pass the send-throttle before it will be sent.
 void setAsynch(boolean is_async, CommandResponseCallback callback)
          Tells this object to make any new remote POJO proxies (via getRemotePojo(Class)) such that they send their invocations asynchronously.
 void setDeliveryGuaranteed(ClientRemotePojoFactory.GuaranteedDelivery guaranteed)
          Sets the flag to indicate if the remote POJO calls should be made with guaranteed delivery.
 void setIgnoreAnnotations(boolean ignore)
          Indicates if remote POJO interface annotations are to be ignored or not.
 void setSendThrottled(boolean throttled)
          Sets the flag to indicate if the remote POJO calls should be "send-throttleable".
 void setTimeout(Long timeoutMillis)
          Sets the timeout (in milliseconds) that all POJO calls will be configured with.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClientRemotePojoFactory

public ClientRemotePojoFactory(ClientCommandSender ccs)
Constructor for ClientRemotePojoFactory.

Parameters:
ccs - the object that will be used to send the remote POJO invocation command
Method Detail

getRemotePojo

public <T> T getRemotePojo(Class<T> targetInterface)
This method returns a proxy to the remote POJO. The returned object can be used to make RPC calls to the remote POJO as if the POJO was a local object. The returned proxy will have its async mode set accordingly. If asynchronous mode is to be enabled in this proxy, its callback will be set to the object that was passed to setAsynch(boolean, CommandResponseCallback) (which may or may not be a null callback).

Parameters:
targetInterface -
Returns:
the proxy to the remote POJO

isIgnoreAnnotations

public boolean isIgnoreAnnotations()
If true, any remote POJO proxy returned by getRemotePojo(Class) will ignore all annotations define in that remote POJO's interface which allows you to override settings hardcoded in the annotations with settings defined in this class (e.g. isSendThrottled() will override any DisableSendThrottling annotation defined in the remote POJO interface). If false, annotations that exist in the remote POJO interface will take effect - thus overriding any of the settings defined in this object.

Returns:
flag to indicate of remote POJO interface annotations are ignored or not

setIgnoreAnnotations

public void setIgnoreAnnotations(boolean ignore)
Indicates if remote POJO interface annotations are to be ignored or not. Please see the description of isIgnoreAnnotations() for more information.

Parameters:
ignore - flag to indicate of remote POJO interface annotations are ignored or not

isAsynch

public boolean isAsynch()
Returns true if new remote POJO proxies should make their invocations asynchronously; false means the invocations will be synchronous (and thus act like a "normal" method call).

Returns:
the asynchronous flag
See Also:
setAsynch(boolean, CommandResponseCallback)

setAsynch

public void setAsynch(boolean is_async,
                      CommandResponseCallback callback)
Tells this object to make any new remote POJO proxies (via getRemotePojo(Class)) such that they send their invocations asynchronously. If is_async is true, then the optional callback will be used as the callback object that will be notified when the asynchronous remote invocation has been completed. The callback will receive RemotePojoInvocationCommandResponse objects as the response. If is_async is false, all proxy remote POJO invocations will be synchronous, and will thus act just like a "normal" POJO method call.

Setting the async mode will not effect any currently existing remote POJO proxies. If you change the async mode, you will need to create a new proxy via getRemotePojo(Class) and use that proxy to pick up the new async mode.

You can call this method to set a callback with is_async set to false; this allows you to set a callback for use with any POJOs that might be annotated as Asynchronous.

It is recommended that, if you want a callback, you use RemotePojoInvocationFuture as the callback implementation because that object is able to directly handle RemotePojoInvocationCommandResponse objects and can perform blocked waits.

Parameters:
is_async - indicates if new proxies to remote POJOs should be in asynchronous mode
callback - the callback to be notified when the invocation is complete (may be null)
See Also:
RemotePojoInvocationFuture

getTimeout

public Long getTimeout()
Returns the timeout (in milliseconds) that any new proxies will use for all POJO calls. If null is returned, the default will be used (the default is defined by the ClientCommandSender that was passed into this object's constructor). The timeout indicates how much time the client should wait for the command to return with a response. If the timeout is exceeded, the command will abort.

Returns:
the timeout (in milliseconds) that each command will be configured with; if null, a default will be used

setTimeout

public void setTimeout(Long timeoutMillis)
Sets the timeout (in milliseconds) that all POJO calls will be configured with. See getTimeout() for more information.

Note that setting a new timeout value will not affect any existing proxies that this object previously created via prior calls to getRemotePojo(Class). You must get a new remote POJO proxy in order for this new timeout to take effect.

Parameters:
timeoutMillis - the timeout (in milliseconds) that each command will be configured with; ifnull, a default will be used

isDeliveryGuaranteed

public boolean isDeliveryGuaranteed()
Returns the flag to indicate if the remote POJO calls should be made with guaranteed delivery.

Returns:
true if POJO calls should be made with guaranteed delivery; false otherwise

setDeliveryGuaranteed

public void setDeliveryGuaranteed(ClientRemotePojoFactory.GuaranteedDelivery guaranteed)
Sets the flag to indicate if the remote POJO calls should be made with guaranteed delivery.

Note that setting a new guaranteed delivery value will not affect any existing proxies that this object previously created via prior calls to getRemotePojo(Class). You must get a new remote POJO proxy in order for this new flag to take effect.

Parameters:
guaranteed - true if the remote POJO call should be made with guaranteed delivery

isSendThrottled

public boolean isSendThrottled()
Returns the flag to indicate if the remote POJO calls should be "send-throttleable", that is, will need to pass the send-throttle before it will be sent.

Returns:
true if POJO calls are to be send-throttled

setSendThrottled

public void setSendThrottled(boolean throttled)
Sets the flag to indicate if the remote POJO calls should be "send-throttleable".

Note that setting a new send-throttled flag will not affect any existing proxies that this object previously created via prior calls to getRemotePojo(Class). You must get a new remote POJO proxy in order for this new flag to take effect.

Parameters:
throttled - true if the remote POJO call should be send-throttled


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.