Package org.openstreetmap.josm.gui.layer
Class AutosaveTask
java.lang.Object
java.util.TimerTask
org.openstreetmap.josm.gui.layer.AutosaveTask
- All Implemented Interfaces:
Runnable,DataSetListenerAdapter.Listener,NoteData.NoteDataUpdateListener,LayerManager.LayerChangeListener
public class AutosaveTask
extends TimerTask
implements LayerManager.LayerChangeListener, DataSetListenerAdapter.Listener, NoteData.NoteDataUpdateListener
Saves data and note layers periodically so they can be recovered in case of a crash.
There are 2 directories
- autosave dir: copies of the currently open data layers are saved here every
PROP_INTERVAL seconds. When a data layer is closed normally, the corresponding
files are removed. If this dir is non-empty on start, JOSM assumes
that it crashed last time.
- deleted layers dir: "secondary archive" - when autosaved layers are restored
they are copied to this directory. We cannot keep them in the autosave folder,
but just deleting it would be dangerous: Maybe a feature inside the file
caused JOSM to crash. If the data is valuable, the user can still try to
open with another versions of JOSM or fix the problem manually.
The deleted layers dir keeps at most PROP_DELETED_LAYERS files.
- Since:
- 3378 (creation), 10386 (new LayerChangeListener interface)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate final Fileprivate final DataSetListenerAdapterprivate static final Stringprivate final Fileprivate static final char[]private final List<AutosaveTask.AutosaveLayerInfo<?>>private final Objectstatic final BooleanPropertyIf autosave is enabledstatic final IntegerPropertyHow many deleted layers should be storedstatic final IntegerPropertyThe number of files to store per layerstatic final IntegerPropertyThe maximum number of autosave files to storestatic final IntegerPropertyThe autosave interval, in secondsstatic final BooleanPropertyDefines if a notification should be displayed after each autosave -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcleanupLayer(AbstractModifiableLayer removedLayer) private static voidcreateNewPidFile(File autosaveDir, String filename) booleandataUpdated(Data data) Indicate that data has changed, and it might be a good idea to autosave.voidMark all unsaved layers as deleted.protected voidfinal PathReplies the autosave directory.private static StringgetFileName(String layerName, int index) protected FilegetNewLayerFile(AutosaveTask.AutosaveLayerInfo<?> layer, Instant now, int startIndex) protected FilegetPidFile(File osmFile) Replies the list of .osm files still present in autosave dir, that are not currently managed by another instance of JOSM.private static booleanjvmPerfDataFileExists(String jvmId) voidNotifies this listener that a layer has been added.voidNotifies this listener that the order of layers was changed.voidNotifies this listener that a layer was just removed.private voidMove file to the deleted layers directory.voidnoteDataUpdated(NoteData data) Called when the note data is updatedvoidCalled when notified about any type of dataset change event.Future<?>Recover the unsaved layers and open them asynchronously.private voidregisterNewlayer(NoteLayer layer) private voidregisterNewlayer(OsmDataLayer layer) voidrun()private voidsavelayer(AutosaveTask.AutosaveLayerInfo<?> info) voidschedule()Starts the autosave background task.voidselectedNoteChanged(NoteData noteData) The selected node was changedprivate voidMethods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
-
Field Details
-
ILLEGAL_CHARACTERS
-
AUTOSAVE_DIR
- See Also:
-
DELETED_LAYERS_DIR
- See Also:
-
PROP_AUTOSAVE_ENABLED
If autosave is enabled -
PROP_FILES_PER_LAYER
The number of files to store per layer -
PROP_DELETED_LAYERS
How many deleted layers should be stored -
PROP_INTERVAL
The autosave interval, in seconds -
PROP_INDEX_LIMIT
The maximum number of autosave files to store -
PROP_NOTIFICATION
Defines if a notification should be displayed after each autosave -
datasetAdapter
-
changedData
-
layersInfo
-
layersLock
-
deletedLayers
-
autosaveDir
-
deletedLayersDir
-
-
Constructor Details
-
AutosaveTask
public AutosaveTask()
-
-
Method Details
-
getAutosaveDir
Replies the autosave directory.- Returns:
- the autosave directory
- Since:
- 10299
-
schedule
Starts the autosave background task. -
getFileName
-
setLayerFileName
-
getNewLayerFile
protected File getNewLayerFile(AutosaveTask.AutosaveLayerInfo<?> layer, Instant now, int startIndex) -
createNewPidFile
-
savelayer
-
run
-
displayNotification
-
layerOrderChanged
Description copied from interface:LayerManager.LayerChangeListenerNotifies this listener that the order of layers was changed.Listeners are called in the EDT thread. You should not do blocking or long-running tasks in this method.
- Specified by:
layerOrderChangedin interfaceLayerManager.LayerChangeListener- Parameters:
e- The order change event.
-
registerNewlayer
-
registerNewlayer
-
layerAdded
Description copied from interface:LayerManager.LayerChangeListenerNotifies this listener that a layer has been added.Listeners are called in the EDT thread. You should not do blocking or long-running tasks in this method.
- Specified by:
layerAddedin interfaceLayerManager.LayerChangeListener- Parameters:
e- The new added layer event
-
layerRemoving
Description copied from interface:LayerManager.LayerChangeListenerNotifies this listener that a layer was just removed.Listeners are called in the EDT thread after the layer was removed. Use
LayerManager.LayerRemoveEvent.scheduleRemoval(Collection)to remove more layers. You should not do blocking or long-running tasks in this method.- Specified by:
layerRemovingin interfaceLayerManager.LayerChangeListener- Parameters:
e- The layer to be removed (as event)
-
cleanupLayer
-
processDatasetEvent
Description copied from interface:DataSetListenerAdapter.ListenerCalled when notified about any type of dataset change event.- Specified by:
processDatasetEventin interfaceDataSetListenerAdapter.Listener- Parameters:
event- dataset change event
-
noteDataUpdated
Description copied from interface:NoteData.NoteDataUpdateListenerCalled when the note data is updated- Specified by:
noteDataUpdatedin interfaceNoteData.NoteDataUpdateListener- Parameters:
data- The data that was changed
-
dataUpdated
Indicate that data has changed, and it might be a good idea to autosave.- Parameters:
data- The data that has changed- Returns:
- See
Set.add(E) - Since:
- 16548
-
selectedNoteChanged
Description copied from interface:NoteData.NoteDataUpdateListenerThe selected node was changed- Specified by:
selectedNoteChangedin interfaceNoteData.NoteDataUpdateListener- Parameters:
noteData- The data of which the selected node was changed
-
getPidFile
-
getUnsavedLayersFiles
Replies the list of .osm files still present in autosave dir, that are not currently managed by another instance of JOSM. These files are hence unsaved layers from an old instance of JOSM that crashed and may be recovered by this instance.- Returns:
- The list of .osm files still present in autosave dir, that are not currently managed by another instance of JOSM
-
jvmPerfDataFileExists
-
recoverUnsavedLayers
Recover the unsaved layers and open them asynchronously.- Returns:
- A future that can be used to wait for the completion of this task.
-
moveToDeletedLayersFolder
Move file to the deleted layers directory. If moving does not work, it will try to delete the file directly. Afterwards, if the number of deleted layers gets larger than PROP_DELETED_LAYERS, some files in the deleted layers directory will be removed.- Parameters:
f- the file, usually from the autosave dir
-
discardUnsavedLayers
Mark all unsaved layers as deleted. They are still preserved in the deleted layers folder.
-