atg.rview
Class InvalidationRelay

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.nucleus.TimedOperationService
              extended by atg.server.tcp.RequestServer
                  extended by atg.rview.InvalidationRelay
All Implemented Interfaces:
NameContextBindingListener, NameContextElement, NameResolver, AdminableService, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, atg.nucleus.logging.VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener

public class InvalidationRelay
extends RequestServer

The InvalidationRelay is used to broadcast cache invalidations from one RelationalViewManager to other RelationalViewManagers, thereby allowing them to keep their caches in sync. This service is a TCP server, so that other InvalidationRelays can connect to this and direct the local RelationalViewManagers to invalidate their caches. This service also acts as a TCP client to connect to remote RelationalViewManagers and direct them to invalidate their caches.

Each InvalidationRelay recognizes that there may be more than one RelationalViewManager running in a Dynamo, each of which needs to communicate with the corresponding RelationalViewManager in other Dynamos. To make this work, an InvalidationRelay requires each local RelationalViewManager to register itself with a name through the method registerCacheInvalidationListener. When a RelationalViewManager sends a message to invalidate a cache, it also sends its own name. The message will then be broadcast to other InvalidationRelays, which will then pass the message to their own local RelationalViewManagers registered with that name. It is therefore important that RelationalViewManagers keep consistent names across Dynamos - this is usually done by making the name be the Nucleus name of the RelationalViewManager service, and making sure that corresponding RelationalViewManagers have the same Nucleus names in other Dynamos. It is also important that the corresponding RelationalViewManagers be running the same relational view definition files, or else the cache invalidations will not make much sense.

The InvalidationRelay is configured with a list of host/port entries to which it will attempt to relay its cache invalidations. Whenever it successfully connects to another InvalidationRelay, it will immediately notify that relay to invalidate all of its caches, since the caches may have gotten out of sync while the relays were disconnected.

If a connection fails, the relay will attempt to reconnect, but only after a period specified by "clientReconnectTime".

The protocol looks like this:

 Upon connection, the connector sends a magic# and a protocol version
   0xfacade99 (int)
   version# (int, starting with 0x0001)

 For each group of invalidations:
   destination (String, 0-length means all)
   # of invalidations (int)
   for each invalidation:
     invalidation type (byte)
       INVALIDATE_ALL_CACHES
         (no further info)
       INVALIDATE_CACHES_BY_TABLE_NAME
         table name (String)
       INVALIDATE_CACHE
         cache name (String)
       INVALIDATE_CACHE_ENTRY
         cache name (String)
         # key elements (int)
           each key element (KeyObject)
       INVALIDATE_CACHE_ENTRIES
         cache name (String)
         # cache keys (int)
           each cache key:
             # key elements (int)
               each key element (KeyObject)
 

And the format for a KeyObject:

 TYPE_NULL
 TYPE_BOOLEAN
   value (boolean)
 TYPE_BYTE
   value (byte)
 TYPE_SHORT
   value (short)
 TYPE_INTEGER
   value (int)
 TYPE_LONG
   value (long)
 TYPE_FLOAT
   value (float)
 TYPE_DOUBLE
   value (double)
 TYPE_STRING
   value (String)
 TYPE_DATE
   msec value (long)
 TYPE_TIME
   msec value (long)
 TYPE_TIMESTAMP
   msec value (long)
 TYPE_BIGDECIMAL
   String value (String)
 


Field Summary
static java.lang.String CLASS_VERSION
           
static int INVALIDATE_ALL_CACHES
           
static int INVALIDATE_CACHE
           
static int INVALIDATE_CACHE_ENTRIES
           
static int INVALIDATE_CACHE_ENTRY
           
static int INVALIDATE_CACHES_BY_TABLE_NAME
           
static int MAGIC_NUMBER
           
 java.util.Dictionary mCacheInvalidationListeners
           
static int PROTOCOL_VERSION
           
static int TYPE_BIGDECIMAL
           
static int TYPE_BOOLEAN
           
static int TYPE_BYTE
           
static int TYPE_DATE
           
static int TYPE_DOUBLE
           
static int TYPE_FLOAT
           
static int TYPE_INTEGER
           
static int TYPE_LONG
           
static int TYPE_NULL
           
static int TYPE_SHORT
           
static int TYPE_STRING
           
static int TYPE_TIME
           
static int TYPE_TIMESTAMP
           
 
Fields inherited from class atg.server.tcp.RequestServer
DEFAULT_BACKLOG, mAllowedConnection, mAllowedConnectionMatcher, mBacklog, mEnabled, mHandlerCount, mHostAddr, mHostName, mLocalPort, mPort, mPortRegistry, mReadTimeout
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
InvalidationRelay()
           
 
Method Summary
 void broadcastInvalidationCommand(java.lang.String pDestination, atg.rview.CacheInvalidationCommand pCommand)
          Queues the specified cache invalidation command to be broadcast to RelationalViewManagers registered with the given destination.
 void broadcastInvalidationCommands(java.lang.String pDestination, atg.rview.CacheInvalidationCommand[] pCommands)
          Queues the specified cache invalidation commands to be broadcast to RelationalViewManagers registered with the given destination.
protected  javax.servlet.Servlet createAdminServlet()
          Creates and returns a new Servlet that will administer this service.
protected  RequestServerHandler createHandler(java.lang.ThreadGroup pGroup, java.lang.String pThreadName, java.net.Socket pSocket)
          Constructs a new RequestServerHandler.
 void deregisterIncomingClient(atg.rview.InvalidationRelayRequestHandler pHandler)
          Notifies the relay that an incoming client has detached
 void doStartService()
          Sets up the clients
 CacheInvalidationListener getCacheInvalidationListener(java.lang.String pName)
          Returns the CacheInvalidationListener registered with the given name, or null if none is registered with that name.
 long getClientReconnectTime()
           
 boolean getHasClients()
          Returns true if there are any clients to send invalidations to.
 java.net.InetAddress[] getRemoteRelayHosts()
           
 int[] getRemoteRelayPorts()
           
 boolean isInvalidateAllOnConnect()
           
 void registerCacheInvalidationListener(java.lang.String pName, CacheInvalidationListener pListener)
          Registers a local CacheInvalidationListener (probably a RelationalViewManager) with the given name.
 void registerIncomingClient(atg.rview.InvalidationRelayRequestHandler pHandler)
          Notifies the relay that an incoming client has attached
 void setClientReconnectTime(long pClientReconnectTime)
           
 void setInvalidateAllOnConnect(boolean pInvalidateAllOnConnect)
           
 void setRemoteRelayHosts(java.net.InetAddress[] pRemoteRelayHosts)
           
 void setRemoteRelayPorts(int[] pRemoteRelayPorts)
           
 
Methods inherited from class atg.server.tcp.RequestServer
acceptConnection, acceptConnections, createAndStartHandler, createAndStartHandlerIfNeeded, createServerSocket, doStopService, getAcceptorPriorityDelta, getActiveHandlerCount, getAllowedConnection, getBacklog, getCloseSocketWhenStopped, getConnectionAcceptor, getEnabled, getHandlerCount, getHostAddr, getHostName, getLocalPort, getMaxZombieHandlerCount, getNewHandlerRequestCount, getPort, getPortRegistry, getReadTimeout, getRequestHandlers, getRequestServerSocket, getRunningHandlerCount, getServerSocketFactory, getWaitForRequestHandlersToStop, getWaitingHandlerCount, getZombieHandlerCount, isOutOfMemoryDetected, isSuccessfulServerStartup, isUseServerSocketFactory, setAcceptorPriorityDelta, setAllowedConnection, setBacklog, setCloseSocketWhenStopped, setConnectionAcceptor, setEnabled, setHandlerCount, setHostAddr, setHostName, setMaxZombieHandlerCount, setOutOfMemoryDetected, setPort, setPortRegistry, setReadTimeout, setServerSocketFactory, setSocketReadTimeout, setSuccessfulServerStartup, setUseServerSocketFactory, setWaitForRequestHandlersToStop, startServer
 
Methods inherited from class atg.nucleus.TimedOperationService
getAverageRequestHandlingTime, getHandledRequestCount, getRequestStartTime, getTotalRequestHandlingTime, isKeepingStatistics, notifyHandledRequest, resetStatistics, setKeepingStatistics
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, getAbsoluteName, getAdminServlet, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION

MAGIC_NUMBER

public static final int MAGIC_NUMBER
See Also:
Constant Field Values

PROTOCOL_VERSION

public static final int PROTOCOL_VERSION
See Also:
Constant Field Values

INVALIDATE_ALL_CACHES

public static final int INVALIDATE_ALL_CACHES
See Also:
Constant Field Values

INVALIDATE_CACHES_BY_TABLE_NAME

public static final int INVALIDATE_CACHES_BY_TABLE_NAME
See Also:
Constant Field Values

INVALIDATE_CACHE

public static final int INVALIDATE_CACHE
See Also:
Constant Field Values

INVALIDATE_CACHE_ENTRY

public static final int INVALIDATE_CACHE_ENTRY
See Also:
Constant Field Values

INVALIDATE_CACHE_ENTRIES

public static final int INVALIDATE_CACHE_ENTRIES
See Also:
Constant Field Values

TYPE_NULL

public static final int TYPE_NULL
See Also:
Constant Field Values

TYPE_BOOLEAN

public static final int TYPE_BOOLEAN
See Also:
Constant Field Values

TYPE_BYTE

public static final int TYPE_BYTE
See Also:
Constant Field Values

TYPE_SHORT

public static final int TYPE_SHORT
See Also:
Constant Field Values

TYPE_INTEGER

public static final int TYPE_INTEGER
See Also:
Constant Field Values

TYPE_LONG

public static final int TYPE_LONG
See Also:
Constant Field Values

TYPE_FLOAT

public static final int TYPE_FLOAT
See Also:
Constant Field Values

TYPE_DOUBLE

public static final int TYPE_DOUBLE
See Also:
Constant Field Values

TYPE_STRING

public static final int TYPE_STRING
See Also:
Constant Field Values

TYPE_DATE

public static final int TYPE_DATE
See Also:
Constant Field Values

TYPE_TIME

public static final int TYPE_TIME
See Also:
Constant Field Values

TYPE_TIMESTAMP

public static final int TYPE_TIMESTAMP
See Also:
Constant Field Values

TYPE_BIGDECIMAL

public static final int TYPE_BIGDECIMAL
See Also:
Constant Field Values

mCacheInvalidationListeners

public java.util.Dictionary mCacheInvalidationListeners
Constructor Detail

InvalidationRelay

public InvalidationRelay()
Method Detail

getClientReconnectTime

public long getClientReconnectTime()

setClientReconnectTime

public void setClientReconnectTime(long pClientReconnectTime)

getRemoteRelayHosts

public java.net.InetAddress[] getRemoteRelayHosts()

setRemoteRelayHosts

public void setRemoteRelayHosts(java.net.InetAddress[] pRemoteRelayHosts)

getRemoteRelayPorts

public int[] getRemoteRelayPorts()

setRemoteRelayPorts

public void setRemoteRelayPorts(int[] pRemoteRelayPorts)

isInvalidateAllOnConnect

public boolean isInvalidateAllOnConnect()

setInvalidateAllOnConnect

public void setInvalidateAllOnConnect(boolean pInvalidateAllOnConnect)

registerCacheInvalidationListener

public void registerCacheInvalidationListener(java.lang.String pName,
                                              CacheInvalidationListener pListener)
Registers a local CacheInvalidationListener (probably a RelationalViewManager) with the given name. Remote notifications to perform a cache invalidation bearing that name will be sent to the registered CacheInvalidationListener.


getCacheInvalidationListener

public CacheInvalidationListener getCacheInvalidationListener(java.lang.String pName)
Returns the CacheInvalidationListener registered with the given name, or null if none is registered with that name.


getHasClients

public boolean getHasClients()
Returns true if there are any clients to send invalidations to.


broadcastInvalidationCommand

public void broadcastInvalidationCommand(java.lang.String pDestination,
                                         atg.rview.CacheInvalidationCommand pCommand)
Queues the specified cache invalidation command to be broadcast to RelationalViewManagers registered with the given destination.


broadcastInvalidationCommands

public void broadcastInvalidationCommands(java.lang.String pDestination,
                                          atg.rview.CacheInvalidationCommand[] pCommands)
Queues the specified cache invalidation commands to be broadcast to RelationalViewManagers registered with the given destination.


createHandler

protected RequestServerHandler createHandler(java.lang.ThreadGroup pGroup,
                                             java.lang.String pThreadName,
                                             java.net.Socket pSocket)
Constructs a new RequestServerHandler. Subclasses should override this to create their own subclasses of RequestServerHandler.

Overrides:
createHandler in class RequestServer
Parameters:
pGroup - the ThreadGroup to which the new handler should belong
pThreadName - the name that should be assigned to the handler's thread.
pSocket - the socket that the handler should use to perform its one-shot request. If null, then the handler should obtain sockets by calling "acceptConnection".

registerIncomingClient

public void registerIncomingClient(atg.rview.InvalidationRelayRequestHandler pHandler)
Notifies the relay that an incoming client has attached


deregisterIncomingClient

public void deregisterIncomingClient(atg.rview.InvalidationRelayRequestHandler pHandler)
Notifies the relay that an incoming client has detached


doStartService

public void doStartService()
                    throws ServiceException
Sets up the clients

Overrides:
doStartService in class RequestServer
Throws:
ServiceException - if there was a problem

createAdminServlet

protected javax.servlet.Servlet createAdminServlet()
Creates and returns a new Servlet that will administer this service. By default, this creates a ServiceAdminServlet, but subclasses may create their own servlets.

Overrides:
createAdminServlet in class GenericService