org.hd.d.pg2k.clApp.atHome
Class AHStandaloneMain.Callback

java.lang.Object
  extended by org.hd.d.pg2k.clApp.atHome.AHStandaloneMain.Callback
All Implemented Interfaces:
ScorerPopulation.NewBestCallbackIF
Enclosing class:
AHStandaloneMain

private static final class AHStandaloneMain.Callback
extends java.lang.Object
implements ScorerPopulation.NewBestCallbackIF

Container of various items of information we need to run the worker threads. The cache and worker instances are cleared/replaced atomically.


Field Summary
private  MiniScorerCacheImpl cache
          Light-weight Scorer cache and population; never null.
(package private)  SimpleExhibitPipelineIF dataSource
          Data source; never null.
private  int generation
          Generation number; strictly positive.
private  long lastNewScorerReport
          Time last new Scorer was locally generated and reported.
(package private)  SimpleLoggerIF log
          Logger; never null.
private  java.lang.String queuedBestScorer
          Last 'best' Scorer queued to report to server; null if currently no such item.
private  ScorerCreator.ScorerWork scorerWork
          Work controller object; never null.
private  java.util.Set<java.lang.String> serverBestScorerNAP
          Immutable Set of server's "best" Scorers; never null but may be empty.
(package private)  java.lang.String tunnelURL
          Full tunnel URL for Scorer work; never null.
 
Constructor Summary
AHStandaloneMain.Callback(java.lang.String tunnelURL, SimpleExhibitPipelineIF dataSource, SimpleLoggerIF log)
          Make an instance wrapped round the tunnel URL, log and (restricted) dataSource.
 
Method Summary
(package private)  MiniScorerCacheImpl getCache()
          Get the cache; never null.
(package private)  int getGeneration()
          Get the current generation number; strictly positive.
(package private)  long getLastNewScorerReport()
          Get time last new Scorer was locally generated and reported.
(package private)  java.lang.String getQueuedBestScorer()
          Atomically get and clear any queued best Scorer to send to the server; null if currently no such item.
(package private)  ScorerCreator.ScorerWork getScorerWork()
          Get the work controller object; never null.
(package private)  java.util.Set<java.lang.String> getServerBestScorerNAP()
          Get immutable Set of server's "best" Scorers; never null but may be empty.
 void reportNewBestScorer(java.lang.String scorerNameAndParameters)
          Used to post a new "best of breed" Scorer name and parameters for posterity.
(package private)  void reset()
          Replace cache and worker objects atomically.
(package private)  void setServerBestScorerNAP(java.util.Collection<java.lang.String> bestScorers)
          Set the server's "best" Scorers; may not be null nor contain nulls or invalid name-and-parameter values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tunnelURL

final java.lang.String tunnelURL
Full tunnel URL for Scorer work; never null.


dataSource

final SimpleExhibitPipelineIF dataSource
Data source; never null.


log

final SimpleLoggerIF log
Logger; never null.


cache

private MiniScorerCacheImpl cache
Light-weight Scorer cache and population; never null.


scorerWork

private ScorerCreator.ScorerWork scorerWork
Work controller object; never null.


generation

private int generation
Generation number; strictly positive. When the cache is non-zero-sized and is reset, this value is incremented.

Accessed under the same lock used to protect the cache.


serverBestScorerNAP

private volatile java.util.Set<java.lang.String> serverBestScorerNAP
Immutable Set of server's "best" Scorers; never null but may be empty. Marked volatile for atomic replacement and lock-free thread-safe access; this is not protected under the same instance lock as the cache/worker fields.


lastNewScorerReport

private volatile long lastNewScorerReport
Time last new Scorer was locally generated and reported. This notes time of generation of a new Scorer that was the best in its sub-population. While these reports are still coming in, this client is probably doing useful work.

Marked volatile for lock-free thread-safe access.


queuedBestScorer

private java.lang.String queuedBestScorer
Last 'best' Scorer queued to report to server; null if currently no such item. We only retain the last item since we assume it to be the best. We then poll for this to send it back to the server, possibly reducing the traffic sent the server's way.

Accessed under the instance lock.

Constructor Detail

AHStandaloneMain.Callback

AHStandaloneMain.Callback(java.lang.String tunnelURL,
                          SimpleExhibitPipelineIF dataSource,
                          SimpleLoggerIF log)
Make an instance wrapped round the tunnel URL, log and (restricted) dataSource.

Method Detail

getCache

MiniScorerCacheImpl getCache()
Get the cache; never null.


getScorerWork

ScorerCreator.ScorerWork getScorerWork()
Get the work controller object; never null.


getGeneration

int getGeneration()
Get the current generation number; strictly positive.


reset

final void reset()
Replace cache and worker objects atomically.


getServerBestScorerNAP

java.util.Set<java.lang.String> getServerBestScorerNAP()
Get immutable Set of server's "best" Scorers; never null but may be empty.


setServerBestScorerNAP

void setServerBestScorerNAP(java.util.Collection<java.lang.String> bestScorers)
Set the server's "best" Scorers; may not be null nor contain nulls or invalid name-and-parameter values.


getLastNewScorerReport

long getLastNewScorerReport()
Get time last new Scorer was locally generated and reported.


getQueuedBestScorer

java.lang.String getQueuedBestScorer()
Atomically get and clear any queued best Scorer to send to the server; null if currently no such item.


reportNewBestScorer

public void reportNewBestScorer(java.lang.String scorerNameAndParameters)
Used to post a new "best of breed" Scorer name and parameters for posterity. This routine should not throw any exceptions.

This routine is not synchronized so as to avoid possibility of deadlock, especially on reentrant calls to the cache and/or computations. It does grab the cache value under a lock to work on later at leisure.

Specified by:
reportNewBestScorer in interface ScorerPopulation.NewBestCallbackIF
Parameters:
scorerNameAndParameters - valid name-and-parameters set; never null.

DHD Multimedia Gallery V1.50.55

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