org.tranche.remote
Class RemoteCallbackRegistry

java.lang.Object
  extended by org.tranche.remote.RemoteCallbackRegistry

public class RemoteCallbackRegistry
extends java.lang.Object

Register all callbacks, unregister when called back. Registry invokes an interrupt on timeout.

Author:
Bryan E. Smith - bryanesmith@gmail.com

Constructor Summary
RemoteCallbackRegistry()
           
 
Method Summary
static boolean addRemoteCallbackPurgeListener(RemoteCallbackPurgeListener l)
          Add a purge listener.
static void clearRemoteCallbackPurgeListeners()
          Remove all purge listeners.
static void fireCallbackPurged(RemoteCallback callback, RemoteTrancheServer server, long createdTimestamp)
          The caller should be the RemoteCallback, which will only happen if it is purged.
static long getAbsoluteCallbackTimeoutInMillis()
          The age at which any timeout is purged, regardless of whether the server is active or not.
static long getCallbackTimeoutInMillis()
          Callback will be interrupted after this time in milliseconds, throwing a PurgedCallbackException.
static long getServerTimeoutInMillis()
          The minimum amount of time should wait for a quite server before purging a callback.
static void register(RemoteCallback callback, RemoteTrancheServer server)
          Add the callback to the registrar.
static boolean removeRemoteCallbackPurgeListener(RemoteCallbackPurgeListener l)
          Remove the given purge listener.
static void setAbsoluteCallbackTimeoutInMillis(long aAbsoluteTimeoutInMillis)
          The age at which any timeout is purged, regardless of whether the server is active or not.
static void setCallbackTimeoutInMillis(long aTimeoutInMillis)
          Callback will be interrupted after this time in milliseconds, throwing a PurgedCallbackException.
static void setServerTimeoutInMillis(long aTimeoutInMillisSinceServerLastSent)
          The minimum amount of time should wait for a quite server before purging a callback.
static void unregister(RemoteCallback callback)
          Unregister a callback that has been added to the registry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RemoteCallbackRegistry

public RemoteCallbackRegistry()
Method Detail

register

public static void register(RemoteCallback callback,
                            RemoteTrancheServer server)

Add the callback to the registrar. Registrar automatically purges callbacks that are timed out based on internal heuristics.

If a callback is returned, make sure to unregister it.

Parameters:
callback -
server -

unregister

public static void unregister(RemoteCallback callback)

Unregister a callback that has been added to the registry.

Parameters:
callback -

fireCallbackPurged

public static void fireCallbackPurged(RemoteCallback callback,
                                      RemoteTrancheServer server,
                                      long createdTimestamp)

The caller should be the RemoteCallback, which will only happen if it is purged.

Parameters:
callback -
server -
createdTimestamp -

addRemoteCallbackPurgeListener

public static boolean addRemoteCallbackPurgeListener(RemoteCallbackPurgeListener l)

Add a purge listener.

Parameters:
l -
Returns:

removeRemoteCallbackPurgeListener

public static boolean removeRemoteCallbackPurgeListener(RemoteCallbackPurgeListener l)

Remove the given purge listener.

Parameters:
l -
Returns:

clearRemoteCallbackPurgeListeners

public static void clearRemoteCallbackPurgeListeners()

Remove all purge listeners.


getServerTimeoutInMillis

public static long getServerTimeoutInMillis()

The minimum amount of time should wait for a quite server before purging a callback.

This only happens if the callback is at least a certain age.

Returns:
See Also:
callbackTimeoutInMillis, absoluteCallbackTimeoutInMillis

setServerTimeoutInMillis

public static void setServerTimeoutInMillis(long aTimeoutInMillisSinceServerLastSent)

The minimum amount of time should wait for a quite server before purging a callback.

This only happens if the callback is at least a certain age.

Parameters:
aTimeoutInMillisSinceServerLastSent -
See Also:
callbackTimeoutInMillis, absoluteCallbackTimeoutInMillis

getAbsoluteCallbackTimeoutInMillis

public static long getAbsoluteCallbackTimeoutInMillis()

The age at which any timeout is purged, regardless of whether the server is active or not. 0 (or any negative number) will disable this timeout.

This is quite different from the other heuristic, which looks at both the age of the request and the length of time since last server response.

Returns:
See Also:
callbackTimeoutInMillis, serverTimeoutInMillis

setAbsoluteCallbackTimeoutInMillis

public static void setAbsoluteCallbackTimeoutInMillis(long aAbsoluteTimeoutInMillis)

The age at which any timeout is purged, regardless of whether the server is active or not. 0 (or any negative number) will disable this timeout.

This is quite different from the other heuristic, which looks at both the age of the request and the length of time since last server response.

Parameters:
aAbsoluteTimeoutInMillis -
See Also:
callbackTimeoutInMillis, serverTimeoutInMillis

getCallbackTimeoutInMillis

public static long getCallbackTimeoutInMillis()

Callback will be interrupted after this time in milliseconds, throwing a PurgedCallbackException.

This only happens if the server hasn't received any data for a minimal period.

Returns:
See Also:
serverTimeoutInMillis, absoluteCallbackTimeoutInMillis

setCallbackTimeoutInMillis

public static void setCallbackTimeoutInMillis(long aTimeoutInMillis)

Callback will be interrupted after this time in milliseconds, throwing a PurgedCallbackException.

This only happens if the server hasn't received any data for a minimal period.

Parameters:
aTimeoutInMillis -
See Also:
serverTimeoutInMillis, absoluteCallbackTimeoutInMillis


This code is free for use both commercially and non-commercially as stated in the project's license