org.hd.d.pg2k.webSvr.ads
Class AdUtils.AdSlotMonitor

java.lang.Object
  extended by org.hd.d.pg2k.webSvr.ads.AdUtils.AdSlotMonitor
Enclosing class:
AdUtils

public static final class AdUtils.AdSlotMonitor
extends java.lang.Object

Unique thread-safe marker tag and stats object for a particular ad slot. Typically a private static final in the JSP/servlet, call 'mon.done()' in the same thread as showAds(..., mon) when an ad gated/enabled by showAds() with this as arg is completed.

Used to avoid showing ads when server-side insertion is taking too long.

This is lock-free and thread-safe for multiple JSP/servlet threads to use the same slots at the same time.


Field Summary
private  java.util.concurrent.atomic.AtomicInteger genTimeSmoothedMs
          Smoothed time of recent ad slot generation time; never null, value non-negative.
private  java.lang.ThreadLocal<java.lang.Long> lastStartTime
          Per-thread record of last start() time for this ad slot; never null.
 java.lang.String name
          Name of this ad slot; never null nor empty.
private  boolean pending
          Set when any ad is start()ed, cleared when any ad is done().
private  java.util.concurrent.atomic.AtomicInteger startCount
          Count of ads shown in this slot (or at least for which start() was called).
 
Constructor Summary
AdUtils.AdSlotMonitor(java.lang.String name)
          Construct an instance with a non-empty, non=null name.
 
Method Summary
 void done()
          Used by JSP code after generating text for an ad that showAds() allowed.
 int getGenTimeSmoothedMs()
          Get current 'smoothed' recent ad generation time; non-negative.
 boolean mayBePending()
          True if another showing of this slot may be pending.
(package private)  void start(SimpleLoggerIF log)
          Used by showAds() to start timing an ad that it has allowed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

public final java.lang.String name
Name of this ad slot; never null nor empty.


pending

private volatile boolean pending
Set when any ad is start()ed, cleared when any ad is done(). If this is true then there's probably an ad being filled in now or failed, if it is false then there is no ad pending or one completed successfully.

If there is currently no ad showing and all recent ads have completed fine then this will be false.

This is kept true for as short a time as possible.

We may choose not to show ads in some cases where one may be pending, though this is not any sort of guarantee because of concurrency/exceptions.

Marked volatile for timely sharing between threads.


lastStartTime

private final java.lang.ThreadLocal<java.lang.Long> lastStartTime
Per-thread record of last start() time for this ad slot; never null.


startCount

private final java.util.concurrent.atomic.AtomicInteger startCount
Count of ads shown in this slot (or at least for which start() was called).


genTimeSmoothedMs

private final java.util.concurrent.atomic.AtomicInteger genTimeSmoothedMs
Smoothed time of recent ad slot generation time; never null, value non-negative. Starts with a just-unacceptable time, forcing a cautious 'slow start'.

Constructor Detail

AdUtils.AdSlotMonitor

public AdUtils.AdSlotMonitor(java.lang.String name)
Construct an instance with a non-empty, non=null name.

Method Detail

start

void start(SimpleLoggerIF log)
Used by showAds() to start timing an ad that it has allowed. Default visibility so not accessible to JSPs, but visible to showAds().

Calling start() again with no intervening done() may have no effect and/or may provoke a warning.


done

public void done()
Used by JSP code after generating text for an ad that showAds() allowed. Public visibility so as to be accessible to JSPs.

Calling this if start() was not called (since the last done()) may have no effect and/or may provoke a warning.


mayBePending

public boolean mayBePending()
True if another showing of this slot may be pending.


getGenTimeSmoothedMs

public int getGenTimeSmoothedMs()
Get current 'smoothed' recent ad generation time; non-negative.


DHD Multimedia Gallery V1.53.0

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