org.hd.d.pg2k.svrCore.datasource
Class ExhibitDataTunnelSource.HIRPCCache

java.lang.Object
  extended by org.hd.d.pg2k.svrCore.datasource.ExhibitDataTunnelSource.HIRPCCache
All Implemented Interfaces:
java.lang.Runnable, MemoryTools.RecurrentEmergencyFreeHandle
Enclosing class:
ExhibitDataTunnelSource

public static final class ExhibitDataTunnelSource.HIRPCCache
extends java.lang.Object
implements MemoryTools.RecurrentEmergencyFreeHandle

Cache/lock to improve performance of inbound RPC. Meant to be opaque to all but handleInboundRPC() and is used to provide a better overall responsiveness, especially from expensive calls by vetoing concurrent expensive calls and by cacheing the responses from especially expensive calls.

Not all possibilities are exploited, just those that in practice seem to be important.

Can be registered to free its own content automagically if the system is very short of memory.


Field Summary
private  Tuple.Triple<AllExhibitPropertiesDelta,CompressionLevel,ExhibitDataTunnelSource.RawPacket> _AEP_diff_response
          Cache of extra-compressed AEP diff as tuple of longHash, compression format, and response packet for diff AEP fetch RPC; mutable.
private  Tuple.Pair<java.lang.Long,Tuple.Pair<CompressionLevel,ExhibitDataTunnelSource.RawPacket>> _AEP_extracomp_response
          Cache of full extra-compressed AEP as tuple of longHash, compression format, and response packet for diff AEP fetch RPC; mutable.
private  Tuple.Pair<java.lang.Long,ExhibitDataTunnelSource.RawPacket> _AEP_response
          Cache of current AEP as pair of longHash and response packet for simple AEP fetch RPC; mutable.
private  AllExhibitProperties aepPrev
          Cache of previous AEP value to assist with AEP diffs; initially null.
private  long currentAEPResponseCreatedOrLastUsed
          Time of creation / last use of basic AEP response; initially zero.
private  SoftReferenceMap<java.lang.Long,AllExhibitProperties> prevAEPs
          Soft cache of older AEP values to assist with AEP diffs; never null.
private  java.util.concurrent.locks.ReentrantLock slowResponseLock
          Lock to prevent servicing more than one very expensive call at once.
 
Constructor Summary
ExhibitDataTunnelSource.HIRPCCache()
           
 
Method Summary
 void run()
          Can be called to purge most or all internal state when very short of memory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

slowResponseLock

private final java.util.concurrent.locks.ReentrantLock slowResponseLock
Lock to prevent servicing more than one very expensive call at once. We do this to reduce strain on the memory/GC and CPU of the server.


currentAEPResponseCreatedOrLastUsed

private volatile long currentAEPResponseCreatedOrLastUsed
Time of creation / last use of basic AEP response; initially zero. This covers the GZIPped / extra-compressed / delta responses for the latest AEP, but no previous AEP values which are not essential to minimal client progress.


_AEP_response

private volatile Tuple.Pair<java.lang.Long,ExhibitDataTunnelSource.RawPacket> _AEP_response
Cache of current AEP as pair of longHash and response packet for simple AEP fetch RPC; mutable. Initially null.

Elements of this pair are never null.

Marked volatile for safe multi-threaded access.

Currently held for at least for a minimum period, until the AEP fetched has a new hash, not for example held via a SoftReference since a SoftReference would probably be cleared too soon for this to be effective.

This is likely to be many MB in size.


_AEP_extracomp_response

private volatile Tuple.Pair<java.lang.Long,Tuple.Pair<CompressionLevel,ExhibitDataTunnelSource.RawPacket>> _AEP_extracomp_response
Cache of full extra-compressed AEP as tuple of longHash, compression format, and response packet for diff AEP fetch RPC; mutable. Initially null.

Elements of this tuple are never null.

Marked volatile for safe multi-threaded access.

Currently held for at least for a minimum period, until the AEP fetched has a new hash, not for example held via a SoftReference since a SoftReference would probably be cleared too soon for this to be effective.

This is likely to be many MB in size.


_AEP_diff_response

private volatile Tuple.Triple<AllExhibitPropertiesDelta,CompressionLevel,ExhibitDataTunnelSource.RawPacket> _AEP_diff_response
Cache of extra-compressed AEP diff as tuple of longHash, compression format, and response packet for diff AEP fetch RPC; mutable. Initially null.

Elements of this tuple are never null.

Marked volatile for safe multi-threaded access.

Currently held for at least for a minimum period, until the AEP fetched has a new hash, not for example held via a SoftReference since a SoftReference would probably be cleared too soon for this to be effective.

This is likely relatively small.


aepPrev

private volatile AllExhibitProperties aepPrev
Cache of previous AEP value to assist with AEP diffs; initially null. Currently held indefinitely (or until very short of free memory), until the AEP fetched has a new hash, not for example held via a SoftReference since a SoftReference would probably be cleared too soon for this to be effective.

This should generally share most of its state with the current AEP and therefore should not represent a significant extra memory burden.


prevAEPs

private final SoftReferenceMap<java.lang.Long,AllExhibitProperties> prevAEPs
Soft cache of older AEP values to assist with AEP diffs; never null. This is present to help with requests for diffs against AEPs older than the previous value, if any such requests are made.

Thread-safe cache of SoftReferences to older AEPs, mapped from the Long hash values.

Map is not auto-clear()ed on memory stress other than the individual SoftReferences themselves during GC.

It is possible to synchronise on this instance to exclude other activity.

Constructor Detail

ExhibitDataTunnelSource.HIRPCCache

public ExhibitDataTunnelSource.HIRPCCache()
Method Detail

run

public void run()
Can be called to purge most or all internal state when very short of memory. Implements the emergency-free handler.

May not purge some elements which are not (or likely not) using significant memory but usually save a lot of time for us and for clients. To that end we try and estimate the space they are taking vs actual current free heap space.

Specified by:
run in interface java.lang.Runnable

DHD Multimedia Gallery V1.60.69

Copyright (c) 1996-2012, Damon Hart-Davis. All rights reserved.