anon.util
Class Updater

java.lang.Object
  extended by anon.util.Updater
All Implemented Interfaces:
java.util.Observer
Direct Known Subclasses:
AbstractDatabaseUpdater, AccountUpdater

public abstract class Updater
extends java.lang.Object
implements java.util.Observer

Updates the local database. This may be done automatically (by a background thread) and manually by method call. The automatic update is only done if this is allowed by the model.

Author:
Rolf Wendolsky

Nested Class Summary
protected static class Updater.ConstantUpdateInterval
           
protected static class Updater.DynamicUpdateInterval
           
protected static interface Updater.IUpdateInterval
           
static class Updater.ObservableInfo
           
 
Field Summary
private  boolean m_bAutoUpdateChanged
           
private  boolean m_bInitialRun
           
private  boolean m_bUpdating
           
private  boolean m_interrupted
           
private  Updater.ObservableInfo m_observable
           
private  Updater.IUpdateInterval m_updateInterval
           
private  java.lang.Thread m_updateThread
           
private static long MIN_WAITING_TIME_MS
           
private  java.lang.Object UPDATE_SYNC
           
 
Constructor Summary
Updater(Updater.IUpdateInterval a_updateInterval, Updater.ObservableInfo a_observable)
          Initialises and starts the database update thread.
 
Method Summary
protected  Updater.ObservableInfo getObservableInfo()
           
abstract  java.lang.Class getUpdatedClass()
           
protected  java.lang.String getUpdatedClassName()
           
 Updater.IUpdateInterval getUpdateInterval()
           
private  void init()
          May be used to re-initialise the thread after stopping it.
abstract  boolean isFirstUpdateDone()
           
protected  boolean isUpdatePaused()
          May be overwritten if an update is currently no wanted.
 void start(boolean a_bSynchronized)
          Starts the thread if it has not already started or has been stopped before.
 void stop()
          Stops the update thread.
 boolean update()
          Force a synchronized update of the known database entries.
private  boolean update(boolean a_bSynchronized)
          Force an update of the known database entries.
 void update(java.util.Observable a_observable, java.lang.Object a_argument)
           
 void updateAsync()
          Force an update of the known database entries.
protected abstract  void updateInternal()
          Does the update and should tell if it was successful or not.
protected abstract  boolean wasUpdateSuccessful()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_WAITING_TIME_MS

private static final long MIN_WAITING_TIME_MS
See Also:
Constant Field Values

m_updateInterval

private Updater.IUpdateInterval m_updateInterval

m_updateThread

private java.lang.Thread m_updateThread

m_bAutoUpdateChanged

private boolean m_bAutoUpdateChanged

m_bInitialRun

private boolean m_bInitialRun

m_interrupted

private boolean m_interrupted

m_bUpdating

private boolean m_bUpdating

UPDATE_SYNC

private java.lang.Object UPDATE_SYNC

m_observable

private Updater.ObservableInfo m_observable
Constructor Detail

Updater

public Updater(Updater.IUpdateInterval a_updateInterval,
               Updater.ObservableInfo a_observable)
Initialises and starts the database update thread.

Method Detail

init

private final void init()
May be used to re-initialise the thread after stopping it.


getObservableInfo

protected Updater.ObservableInfo getObservableInfo()

update

public void update(java.util.Observable a_observable,
                   java.lang.Object a_argument)
Specified by:
update in interface java.util.Observer

start

public final void start(boolean a_bSynchronized)
Starts the thread if it has not already started or has been stopped before.


update

public final boolean update()
Force a synchronized update of the known database entries.

Returns:
true if the update was successful, false otherwise

updateAsync

public final void updateAsync()
Force an update of the known database entries. The current thread does not wait until it is done.


update

private final boolean update(boolean a_bSynchronized)
Force an update of the known database entries.

Parameters:
a_bSynchronized - true if the current thread should wait until the update is done; false otherwise
Returns:
true if the update was successful, false otherwise

stop

public final void stop()
Stops the update thread. No further updates are possible.


getUpdateInterval

public final Updater.IUpdateInterval getUpdateInterval()

getUpdatedClass

public abstract java.lang.Class getUpdatedClass()

wasUpdateSuccessful

protected abstract boolean wasUpdateSuccessful()

isFirstUpdateDone

public abstract boolean isFirstUpdateDone()

updateInternal

protected abstract void updateInternal()
Does the update and should tell if it was successful or not.


isUpdatePaused

protected boolean isUpdatePaused()
May be overwritten if an update is currently no wanted.

Returns:
boolean

getUpdatedClassName

protected final java.lang.String getUpdatedClassName()