public class SimpleTopicMapManager extends AbstractModule implements TopicMapManager
Basic implementation of the topic map manager. Simply loads the topic map from a file and gives direct access to that. The file can either be an xtm file or a Wandora project file. Optionally, can be set to save the topic map at regular intervals, or alternatively to reload the topic map file at regular intervals.
The topic map file is set with the initialisation parameter topicMapFile. Alternatively you can also set the topic map directly by giving a topic map object in the parameter topicMap. In this case the auto save and reload features cannot be used.
Auto saving is set with the autoSave initialisation parameter. The value is the saving interval in minutes. Use 0 to disable auto saving, which is the default. Setting this parameter to "true" enables auto saving every 10 minutes. Note that the topic map will be written to disk whether or not actual changes in it have occurred.
Automatic file reloading can be set with autoRefresh parameter, set it to true to enable automatic reloading. The topic map is reloaded whenever its timestamp changes, this is checked roughly once every minute.
You should not use both auto saving and reloading at the same time. Or in general, you should not use auto saving at all if you intend to modify the file while this module is running. This can very easily lead to a situation where this module overwrites your changes.
TopicMapManager.TopicMapManagerListener
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoRefresh |
protected int |
autoSave |
protected java.lang.String |
autoSaveFile |
protected java.lang.Thread |
autoThread |
protected boolean |
autoThreadRunning |
protected java.lang.Object |
autoThreadWait |
protected long |
lastLoad |
protected long |
lastSave |
protected ListenerList<TopicMapManager.TopicMapManagerListener> |
managerListeners |
protected TopicMap |
tm |
protected java.util.concurrent.locks.ReadWriteLock |
tmLock |
protected java.lang.String |
topicMapFile |
autoStart, isInitialized, isRunning, logging, loggingModule, moduleManager
Constructor and Description |
---|
SimpleTopicMapManager() |
Modifier and Type | Method and Description |
---|---|
void |
addTopicMapManagerListener(TopicMapManager.TopicMapManagerListener listener)
Adds a topic map listener that will be notified when the managed
topic map is replaced with another topic map.
|
protected void |
autoThreadRun() |
protected void |
fireTopicMapChanged(TopicMap old,
TopicMap neu) |
java.util.Collection<Module> |
getDependencies(ModuleManager manager)
Returns all the modules this module depends on.
|
TopicMap |
getTopicMap()
Returns the topic map managed by this topic map manager.
|
void |
init(ModuleManager manager,
java.util.HashMap<java.lang.String,java.lang.Object> settings)
Initialises the module.
|
boolean |
lockRead()
Locks the topic map for reading.
|
boolean |
lockWrite()
Locks the topic map for writing.
|
void |
reloadTopicMap() |
void |
removeTopicMapManagerListener(TopicMapManager.TopicMapManagerListener listener)
Removes a topic map listener.
|
void |
saveTopicMap() |
void |
start(ModuleManager manager)
Starts the module.
|
protected void |
startAutoThread() |
void |
stop(ModuleManager manager)
Stops the module.
|
void |
unlockRead()
Releases a previously acquired read lock.
|
void |
unlockWrite()
Releases a previously acquired write lock.
|
isInitialized, isRunning, requireLogging, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isInitialized, isRunning
protected final ListenerList<TopicMapManager.TopicMapManagerListener> managerListeners
protected java.util.concurrent.locks.ReadWriteLock tmLock
protected TopicMap tm
protected java.lang.String topicMapFile
protected java.lang.String autoSaveFile
protected boolean autoRefresh
protected int autoSave
protected long lastSave
protected long lastLoad
protected boolean autoThreadRunning
protected java.lang.Thread autoThread
protected final java.lang.Object autoThreadWait
public java.util.Collection<Module> getDependencies(ModuleManager manager) throws ModuleException
Module
getDependencies
in interface Module
getDependencies
in class AbstractModule
manager
- The module manager handling this module.ModuleException
public void init(ModuleManager manager, java.util.HashMap<java.lang.String,java.lang.Object> settings) throws ModuleException
Module
Initialises the module. After constructor, this is the first method called in the life cycle of a module. It should not perform anything time consuming or anything with notable outside side effects. It should only read the parameters and initialise the module so that it can later be started. Note that a module being initialised doesn't mean that it necessarily will ever be started.
A ModuleException may be thrown if something vital is missing from the parameters or they are not sensible. In some cases you may not want to throw an exception even if vital initialisation information is missing. If, for example, it is possible that the module is initialised in some other way between the init and the start method calls. A ModuleException may also be thrown at the start method if the module is still not initialised.
init
in interface Module
init
in class AbstractModule
manager
- The module manager handling this module. You may keep a
reference to it if needed.ModuleException
public void start(ModuleManager manager) throws ModuleException
Module
start
in interface Module
start
in class AbstractModule
manager
- The module manager handling this module.ModuleException
public void stop(ModuleManager manager)
Module
stop
in interface Module
stop
in class AbstractModule
manager
- The module manager handling this module.protected void startAutoThread()
protected void autoThreadRun()
public void saveTopicMap()
public void reloadTopicMap()
public boolean lockRead()
TopicMapManager
lockRead
in interface TopicMapManager
public void unlockRead()
TopicMapManager
unlockRead
in interface TopicMapManager
public boolean lockWrite()
TopicMapManager
lockWrite
in interface TopicMapManager
public void unlockWrite()
TopicMapManager
unlockWrite
in interface TopicMapManager
public TopicMap getTopicMap()
TopicMapManager
getTopicMap
in interface TopicMapManager
public void addTopicMapManagerListener(TopicMapManager.TopicMapManagerListener listener)
TopicMapManager
addTopicMapManagerListener
in interface TopicMapManager
listener
- The topic map listener.public void removeTopicMapManagerListener(TopicMapManager.TopicMapManagerListener listener)
TopicMapManager
removeTopicMapManagerListener
in interface TopicMapManager
listener
- The listener.Copyright 2004-2015 Wandora Team