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, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitisInitialized, isRunningprotected 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
ModulegetDependencies in interface ModulegetDependencies in class AbstractModulemanager - The module manager handling this module.ModuleExceptionpublic void init(ModuleManager manager, java.util.HashMap<java.lang.String,java.lang.Object> settings) throws ModuleException
ModuleInitialises 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 Moduleinit in class AbstractModulemanager - The module manager handling this module. You may keep a
reference to it if needed.ModuleExceptionpublic void start(ModuleManager manager) throws ModuleException
Modulestart in interface Modulestart in class AbstractModulemanager - The module manager handling this module.ModuleExceptionpublic void stop(ModuleManager manager)
Modulestop in interface Modulestop in class AbstractModulemanager - The module manager handling this module.protected void startAutoThread()
protected void autoThreadRun()
public void saveTopicMap()
public void reloadTopicMap()
public boolean lockRead()
TopicMapManagerlockRead in interface TopicMapManagerpublic void unlockRead()
TopicMapManagerunlockRead in interface TopicMapManagerpublic boolean lockWrite()
TopicMapManagerlockWrite in interface TopicMapManagerpublic void unlockWrite()
TopicMapManagerunlockWrite in interface TopicMapManagerpublic TopicMap getTopicMap()
TopicMapManagergetTopicMap in interface TopicMapManagerpublic void addTopicMapManagerListener(TopicMapManager.TopicMapManagerListener listener)
TopicMapManageraddTopicMapManagerListener in interface TopicMapManagerlistener - The topic map listener.public void removeTopicMapManagerListener(TopicMapManager.TopicMapManagerListener listener)
TopicMapManagerremoveTopicMapManagerListener in interface TopicMapManagerlistener - The listener.Copyright 2004-2015 Wandora Team