|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.ThreadGroup
com.uwyn.rife.rep.BlockingRepository
public class BlockingRepository
The BlockingRepository class provides a
Repository implementation that loads the participants from an
XML file.
This file defaults to rep/participants.xml, but it can be
overridden by providing another filename to the method. The
participants are initialized according to their listed order.
initialize
Following is an example of such an XML file :
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE rep SYSTEM "/dtd/rep.dtd"> <rep> <participant blocking="true" parameter="rep/config.xml">ParticipantConfig</participant> <participant blocking="false" parameter="graphics/buttons/">ParticipantImages</participant> <participant name="my cursors" blocking="false" parameter="graphics/cursors/">ParticipantCursors</participant> </rep>
Each participant has a blocking attribute that determines
whether the repository should wait for the end of the participant's
initialization before progressing to the next participant or not. Using
this intelligently, it's possible to dramatically increase the perceived
startup time of an application.
Optionally a participant can have a name attribute which
makes it possible to declare multiple participants of the same class. If no
name is provided, the participant's class name will be used to identify the
declared participant.
Optionally a participant can also have a parameter
attribute which is merely a String that is provided to the
participant object for configuration purposes.
Listeners can be added to the repository to receive notifications about the initialization advancement of the participants and to know when the initialization has completely finished. These notifications can, for example, be used to display a progress bar in a splash window and to switch to the real application window when the initialization has finished.
The JDK's logging facility is used to output informative text during the advancement of the initialization. Each participant has to provide an initialization message that will be output.
RepositoryListener,
BlockingParticipant| Constructor Summary | |
|---|---|
BlockingRepository()
Default constructor without a repository context. |
|
BlockingRepository(Object context)
Constructor which sets up a the context in which the repository is initialized. |
|
| Method Summary | |
|---|---|
boolean |
addParticipant(Class klass)
Adds a BlockingParticipant to the repository, using the
class name as the name of the participant. |
boolean |
addParticipant(Class klass,
boolean blocking)
Adds a BlockingParticipant to the repository, using the
class name as the name of the participant. |
boolean |
addParticipant(Class klass,
boolean blocking,
String parameter)
Adds a BlockingParticipant to the repository, using the
class name as the name of the participant. |
boolean |
addParticipant(Class klass,
String parameter)
Adds a BlockingParticipant to the repository, using the
class name as the name of the participant. |
boolean |
addParticipant(Class klass,
String name,
boolean blocking,
String parameter)
Adds a BlockingParticipant to the repository. |
boolean |
addParticipant(String className)
Adds a BlockingParticipant to the repository, using the
class name for the name of the participant. |
boolean |
addParticipant(String className,
boolean blocking)
Adds a BlockingParticipant to the repository, using the
class name for the name of the participant. |
boolean |
addParticipant(String className,
boolean blocking,
String parameter)
Adds a BlockingParticipant to the repository, using the
class name for the name of the participant. |
boolean |
addParticipant(String className,
String parameter)
Adds a BlockingParticipant to the repository, using the
class name for the name of the participant. |
boolean |
addParticipant(String className,
String name,
boolean blocking,
String parameter)
Adds a BlockingParticipant to the repository. |
void |
addRepListener(RepositoryListener repListener)
Adds the specified repository listener to receive repository initialization events. |
void |
cleanup()
Cleans up the participants in the order in which they have been declared. |
void |
fireInitActionPerformed(BlockingParticipant participant)
Notifies the registered listeners that a new initialization action has been performed. |
void |
fireInitFinished()
Notifies the registered listeners that the repository initialization has finished. |
Object |
getContext()
Retrieves the context in which the repository was initialized. |
BlockingParticipant |
getParticipant(String name)
Looks for the participant that corresponds to a given name and returns it when found. |
Collection<BlockingParticipant> |
getParticipants(String className)
Returns all the participants with a given class name |
HierarchicalProperties |
getProperties()
Retrieves the repository's properties. |
boolean |
hasParticipant(String name)
Verifies if a participant that corresponds to a given name is present. |
void |
initialize(String repXmlPath,
ResourceFinder resourcefinder)
Parses the XML file to determine what the participants are. |
boolean |
isFinished()
Obtains the finished status of the initialization. |
void |
removeRepListener(RepositoryListener repListener)
Removes the repository listener so that it no longer receives repository initialization events. |
void |
runParticipants()
Sequentially execute the participants according to their registration order. |
void |
runParticipants(ResourceFinder resourceFinder)
Sequentially execute the participants according to their registration order. |
void |
uncaughtException(Thread thread,
Throwable e)
If participants call an exception, clean up correctly and rethrow the exception afterwards. |
| Methods inherited from class java.lang.ThreadGroup |
|---|
activeCount, activeGroupCount, allowThreadSuspension, checkAccess, destroy, enumerate, enumerate, enumerate, enumerate, getMaxPriority, getName, getParent, interrupt, isDaemon, isDestroyed, list, parentOf, resume, setDaemon, setMaxPriority, stop, suspend, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public BlockingRepository()
public BlockingRepository(Object context)
| Method Detail |
|---|
public boolean addParticipant(String className)
throws RepException
BlockingParticipant to the repository, using the
class name for the name of the participant.
The participant will not be blocking and have no parameter.
className - The fully resolved name of the participant's class, or
only the class name if the participant resides in the
com.uwyn.rife.rep.participants package.
true if the participants was added successfully;
or
false if errors occurred
RepExceptionBlockingParticipant,
Participant,
addParticipant(Class, String, boolean, String)
public boolean addParticipant(String className,
boolean blocking)
throws RepException
BlockingParticipant to the repository, using the
class name for the name of the participant.
The participant will have no parameter.
className - The fully resolved name of the participant's class, or
only the class name if the participant resides in the
com.uwyn.rife.rep.participants package.blocking - Indicates if this a blocking participant or not.
true if the participants was added successfully;
or
false if errors occurred
RepExceptionBlockingParticipant,
Participant,
addParticipant(Class, String, boolean, String)
public boolean addParticipant(String className,
String parameter)
throws RepException
BlockingParticipant to the repository, using the
class name for the name of the participant.
The participant will not be blocking.
className - The fully resolved name of the participant's class, or
only the class name if the participant resides in the
com.uwyn.rife.rep.participants package.parameter - An optional string that contains the parameter for
this participant.
true if the participants was added successfully;
or
false if errors occurred
RepExceptionBlockingParticipant,
Participant,
addParticipant(Class, String, boolean, String)
public boolean addParticipant(String className,
boolean blocking,
String parameter)
throws RepException
BlockingParticipant to the repository, using the
class name for the name of the participant.
className - The fully resolved name of the participant's class, or
only the class name if the participant resides in the
com.uwyn.rife.rep.participants package.blocking - Indicates if this a blocking participant or not.parameter - An optional string that contains the parameter for
this participant.
true if the participants was added successfully;
or
false if errors occurred
RepExceptionBlockingParticipant,
Participant,
addParticipant(Class, String, boolean, String)
public boolean addParticipant(String className,
String name,
boolean blocking,
String parameter)
throws RepException
BlockingParticipant to the repository.
className - The fully resolved name of the participant's class, or
only the class name if the participant resides in the
com.uwyn.rife.rep.participants package.name - The name under which the participant will be registered, if
the name is null the class name will be usedblocking - Indicates if this a blocking participant or not.parameter - An optional string that contains the parameter for
this participant.
true if the participants was added successfully;
or
false if errors occurred
RepExceptionBlockingParticipant,
Participant,
addParticipant(Class, String, boolean, String)
public boolean addParticipant(Class klass,
boolean blocking,
String parameter)
throws RepException
BlockingParticipant to the repository, using the
class name as the name of the participant.
klass - The class of the participant.blocking - Indicates if this a blocking participant or not.parameter - An optional string that contains the parameter for
this participant.
true if the participants was added successfully;
or
false if errors occurred
RepExceptionBlockingParticipant,
Participant,
addParticipant(Class, String, boolean, String)
public boolean addParticipant(Class klass)
throws RepException
BlockingParticipant to the repository, using the
class name as the name of the participant.
The participant will not be blocking and have no parameter.
klass - The class of the participant.
this participant.
true if the participants was added successfully;
or
false if errors occurred
RepExceptionBlockingParticipant,
Participant,
addParticipant(Class, String, boolean, String)
public boolean addParticipant(Class klass,
boolean blocking)
throws RepException
BlockingParticipant to the repository, using the
class name as the name of the participant.
The participant will have no parameter.
klass - The class of the participant.blocking - Indicates if this a blocking participant or not.
true if the participants was added successfully;
or
false if errors occurred
RepExceptionBlockingParticipant,
Participant,
addParticipant(Class, String, boolean, String)
public boolean addParticipant(Class klass,
String parameter)
throws RepException
BlockingParticipant to the repository, using the
class name as the name of the participant.
The participant will not be blocking.
klass - The class of the participant.parameter - An optional string that contains the parameter for
this participant.
true if the participants was added successfully;
or
false if errors occurred
RepExceptionBlockingParticipant,
Participant,
addParticipant(Class, String, boolean, String)
public boolean addParticipant(Class klass,
String name,
boolean blocking,
String parameter)
throws RepException
BlockingParticipant to the repository.
klass - The class of the participant.name - The name under which the participant will be registered, if
the name is null the class name will be usedblocking - Indicates if this a blocking participant or not.parameter - An optional string that contains the parameter for
this participant.
true if the participants was added successfully;
or
false if errors occurred
RepExceptionBlockingParticipant,
Participantpublic boolean hasParticipant(String name)
hasParticipant in interface Repositoryname - The name of the participant object that you wish to
retrieve from the repository. See the getParticipant method for detailed information about how the
participant's name is resolved.
true if the provided class name could be found, or
false otherwise
BlockingParticipant,
getParticipant(String)public BlockingParticipant getParticipant(String name)
getParticipant in interface Repositoryname - The name of the participant instance that you wish to
retrieve from the repository.
If no name was provided during the XML specification, the
participant will have been registered with its class name. If the
participant's class is not part of the
com.uwyn.rife.rep.participants package, its full class
name has to be provided, otherwise just the name of the class itself is
sufficient.
Also, even though a participant has been registered with a name, it'll still be known under its class name. When a class name is provided as the argument, the first known participant of that class will be returned. This can be seen as the default participant for the specified type.
BlockingParticipant instance if the provided
name could be found amongst the registered participants in the
repository; or
null if the participant couldn't be found
BlockingParticipant,
hasParticipant(String)public Collection<BlockingParticipant> getParticipants(String className)
getParticipants in interface RepositoryclassName - The class name of the participants that you wish to
retrieve from the repository.
If the participant's class is not part of the
com.uwyn.rife.rep.participants package, its full class
name has to be provided, otherwise just the name of the class itself is
sufficient.
Collection of BlockingParticipant
instances of the provided class name; or
null if no participants with the provided class name
could be found
BlockingParticipant,
getParticipant(String)public void runParticipants()
blocking attribute.
The resource finder that will be used is an instance of ResourceFinderClasspath.
ResourceFinderClasspath,
runParticipants(ResourceFinder)public void runParticipants(ResourceFinder resourceFinder)
blocking attribute.
resourceFinder - The resource finder that is used during the
initialization.
public void uncaughtException(Thread thread,
Throwable e)
uncaughtException in interface Thread.UncaughtExceptionHandleruncaughtException in class ThreadGroup
public void initialize(String repXmlPath,
ResourceFinder resourcefinder)
throws RepException
runParticipants method, waiting for
it to finish if its blocking attribute was set to
true.
repXmlPath - The path of the XML file.
If this is null, rep/participants.xml will
be used.
resourcefinder - The resource finder that will be used to look up
resources such as XML files and DTDs. It will also be used by other
classes after initialization through the
getResourceFinder() method.
If this is null, an instance of will be used.
ResourceFinderClasspath
RepException - when an error occurs during the initialization.public boolean isFinished()
isFinished in interface Repositoryfalse if the initialization is still busy; or
true if the initialization is finished
public void cleanup()
throws RepException
cleanup() method is
successively called.
cleanup in interface RepositoryRepException - when an error occurs during the cleanup.public HierarchicalProperties getProperties()
RepositorySystem.getProperties, but then not for the whole
system, but just for this application.
Also, instead of just have a map of String keys and values,
the property values are of the PropertyValue type and are looked
up at run-time in a hierachical manner. This provides them with IoC
capabilities.
Since Java allows the configuration of an application through the use of properties, many other sub-system have adopted a similar approach (for example servlet init parameters). Most of the time an application runs through several barriers of configuration that often function independently. These properties make it possible for each sub-system to add their properties to the same pool. This makes it much more convenient to retrieve a property value.
getProperties in interface Repositorypublic Object getContext()
Repository
getContext in interface Repositorynull if the context isn't accessible
public void addRepListener(RepositoryListener repListener)
repListener is null, no
exception is thrown and no action is performed.
repListener - The repository listener that will be added.RepositoryListener,
removeRepListener(RepositoryListener)public void removeRepListener(RepositoryListener repListener)
repListener
is null, no exception is thrown and no action is
performed.
repListener - The repository listener that will be removed.RepositoryListener,
addRepListener(RepositoryListener)public void fireInitActionPerformed(BlockingParticipant participant)
This is always triggered when a participant's initialization has finished. Each participant however has the possibility to call this method directly, allowed for finer-grained notification of the advancement of the initialization.
participant - The participant that triggered the action.RepositoryListenerpublic void fireInitFinished()
RepositoryListener
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||