votorola.a
Class ElectoralSubserver.Run

java.lang.Object
  extended by ElectoralSubserver.Run
Enclosing class:
ElectoralSubserver

@ThreadSafe
public final class ElectoralSubserver.Run
extends Object

A run of the electoral subserver.


Field Summary
(package private)  ReentrantLock singleServiceLock
           
 
Constructor Summary
ElectoralSubserver.Run(boolean isSingleThreaded)
          Constructs a Run.
 
Method Summary
 District district(String name)
          Returns an electoral district that is active in this run.
 List<RegionalElectionNode> districtRegionalChildren(String name)
          Returns all regional children (election nodes) of a district.
 ElectoralService electoralService(String name)
          Returns an electoral service provided in this run.
 Geocode.Table geocodeTable()
          The relational cache of geocoded residential addresses.
 Database getOrInitializeDatabase(Database keyDatabase)
          Returns an already-initialized instance of the specified keyDatabase.
 void init_done()
          Records that initialization is complete -- that no further calls will be made to init_ methods.
 void init_ensureAllElectoralServices()
          Ensures all ElectoralServices of the subserver account (runtime user) are created and stored for later retrieval.
 District init_ensureDistrict(String districtConfigurationPath)
          Returns an electoral district; creating it, if necessary, and storing it for later retrieval.
 Election init_ensureElection(String name)
          Returns an election; creating it, if necessary, and storing it for later retrieval.
 ElectoralService init_ensureElectoralService(String name, Class serviceClassExpected)
          Returns an electoral service; creating it, if necessary, and storing it for later retrieval.
 RegionalScheme init_ensureRegionalScheme(String name)
          Returns a regional scheme; creating it, if necessary, and storing it for later retrieval.
 void init_putElectoralService(ElectoralService service)
          Stores an electoral service in this run, for later retrieval.
 boolean isSingleThreaded()
          Returns true if this run is restricted to a single client thread; false if multiple client threads are allowed.
 District[] newDistrictArray()
          Returns all electoral districts that are active in this run.
 ElectoralService[] newElectoralServiceArray()
          Returns all electoral services provided in this run.
 RegionalScheme regionalScheme(String name)
          Returns a regional scheme that is active in this run.
 List<District> regionalSchemeChildren(String name)
          Returns all children (districts) of a regional scheme.
 List<RegionalScheme> regionalSchemes()
          Returns all regional schemes.
 Register register()
          The electoral register for this subserver - a shared object (not thread safe).
 ReentrantLock singleServiceLock()
          Returns the thread access lock shared by all services; or null if all services do not share the same lock.
 ElectoralSubserver subserver()
          The subserver for this run.
 UserSettings.Table userTable()
          The relational store of service preferences and other settings, for the users of this subserver.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

singleServiceLock

final ReentrantLock singleServiceLock
Constructor Detail

ElectoralSubserver.Run

public ElectoralSubserver.Run(boolean isSingleThreaded)
                       throws IOException,
                              ScriptException,
                              SQLException
Constructs a Run.

Parameters:
isSingleThreaded - per isSingleThreaded() - if false (multi-threaded), the client should call init_done() after initialization is complete
Throws:
IOException
ScriptException
SQLException
Method Detail

init_done

public void init_done()
Records that initialization is complete -- that no further calls will be made to init_ methods. Single-threaded clients need not call this method; it only enables thread-safety assertions in the init_ methods. [No longer true, as some late constructs will now throw an IllegalStateException if this method has not been called.]


init_ensureAllElectoralServices

@ThreadRestricted(value="constructor")
public void init_ensureAllElectoralServices()
                                     throws IOException,
                                            ScriptException,
                                            SQLException
Ensures all ElectoralServices of the subserver account (runtime user) are created and stored for later retrieval.

Throws:
IOException
ScriptException
SQLException
See Also:
init_ensureElectoralService(String,Class)

init_ensureDistrict

@ThreadRestricted(value="constructor")
public District init_ensureDistrict(String districtConfigurationPath)
                             throws IOException,
                                    ScriptException
Returns an electoral district; creating it, if necessary, and storing it for later retrieval.

Parameters:
districtConfigurationPath - per District.configurationFile().getPath()
Throws:
IOException
ScriptException
See Also:
district(String)

init_ensureElection

@ThreadRestricted(value="constructor")
public Election init_ensureElection(String name)
                             throws IOException,
                                    ScriptException,
                                    SQLException
Returns an election; creating it, if necessary, and storing it for later retrieval. This is just a convenience wrapper for init_ensureElectoralService(name,serviceClassExpected).

Throws:
IOException
ScriptException
SQLException

init_ensureElectoralService

@ThreadRestricted(value="constructor")
public ElectoralService init_ensureElectoralService(String name,
                                                                          Class serviceClassExpected)
                                             throws IOException,
                                                    ScriptException,
                                                    SQLException
Returns an electoral service; creating it, if necessary, and storing it for later retrieval.

Parameters:
serviceClassExpected - class of service to ensure, or null to ensure regardless of class
Throws:
ElectoralSubserver.NoSuchServiceException - if name does not identify an electoral service configured for the subserver
IOException
ScriptException
SQLException
See Also:
init_ensureAllElectoralServices(), init_putElectoralService(ElectoralService), electoralService(String)

init_ensureRegionalScheme

@ThreadRestricted(value="constructor")
public RegionalScheme init_ensureRegionalScheme(String name)
                                         throws IOException,
                                                ScriptException
Returns a regional scheme; creating it, if necessary, and storing it for later retrieval.

Throws:
IOException
ScriptException
See Also:
regionalScheme(String)

init_putElectoralService

@ThreadRestricted(value="constructor")
public void init_putElectoralService(ElectoralService service)
Stores an electoral service in this run, for later retrieval.

Throws:
IllegalStateException - if an instance of the same service was already stored
See Also:
init_ensureElectoralService(String,Class), electoralService(String), init_ensureAllElectoralServices()

district

public District district(String name)
Returns an electoral district that is active in this run.

See Also:
init_ensureDistrict(String), newDistrictArray(), regionalSchemeChildren(String)

districtRegionalChildren

public List<RegionalElectionNode> districtRegionalChildren(String name)
Returns all regional children (election nodes) of a district.

Parameters:
name - the name of the district
Returns:
unmodifiable list of nodes
Throws:
IllegalStateException - if init_done() not already called
See Also:
electoralService(String)

electoralService

public ElectoralService electoralService(String name)
Returns an electoral service provided in this run.

Parameters:
name - per ElectoralService.name()
See Also:
districtRegionalChildren(String), init_ensureElectoralService(String,Class), init_putElectoralService(ElectoralService), newElectoralServiceArray()

geocodeTable

public Geocode.Table geocodeTable()
The relational cache of geocoded residential addresses.

See Also:
ElectoralSubserver.ConfigurationContext.geocodeDatabase()

getOrInitializeDatabase

public Database getOrInitializeDatabase(Database keyDatabase)
                                 throws ScriptException,
                                        SQLException
Returns an already-initialized instance of the specified keyDatabase. If no instance has already been initialized, the keyDatabase is initialized and returned, after caching it for later reuse.

Parameters:
keyDatabase - a database (typically uninitialized), to use as a key in searching for an already initialized instance of the same database in the cache
Throws:
ScriptException
SQLException

isSingleThreaded

public boolean isSingleThreaded()
Returns true if this run is restricted to a single client thread; false if multiple client threads are allowed.


newDistrictArray

public District[] newDistrictArray()
Returns all electoral districts that are active in this run.

Returns:
newly created array of districts
See Also:
district(String)

newElectoralServiceArray

public ElectoralService[] newElectoralServiceArray()
Returns all electoral services provided in this run.

Returns:
newly created array of electoral services
See Also:
electoralService(String)

regionalScheme

public RegionalScheme regionalScheme(String name)
Returns a regional scheme that is active in this run.

See Also:
regionalSchemes(), init_ensureRegionalScheme(String)

regionalSchemeChildren

public List<District> regionalSchemeChildren(String name)
Returns all children (districts) of a regional scheme.

Parameters:
name - the name of the scheme
Returns:
unmodifiable list of districts
Throws:
IllegalStateException - if init_done() not already called
See Also:
district(String)

regionalSchemes

public List<RegionalScheme> regionalSchemes()
Returns all regional schemes.

Returns:
unmodifiable list of schemes
Throws:
IllegalStateException - if init_done() not already called
See Also:
regionalScheme(String)

register

public Register register()
The electoral register for this subserver - a shared object (not thread safe). This method itself is thread safe, but the object it returns is not; it has its own thread-saftety restrictions, q.v.


singleServiceLock

public ReentrantLock singleServiceLock()
Returns the thread access lock shared by all services; or null if all services do not share the same lock. All services share the same lock only if the run is single threaded.

See Also:
ElectoralService.lock()

subserver

public ElectoralSubserver subserver()
The subserver for this run.


userTable

public UserSettings.Table userTable()
The relational store of service preferences and other settings, for the users of this subserver.

See Also:
ElectoralSubserver.ConfigurationContext.userDatabase()