Verified Owner
Top Description Fields Constructors Methods
org.jabref.http

public Class JabRefSrvStateManager

extends AbstractSrvStateManager
Class Inheritance
Imports
java.io.IOException, java.nio.file.Files, .Path, java.nio.file.attribute.FileTime, java.util.HashMap, .List, .ListIterator, .Map, .Optional, java.util.function.Supplier, javafx.beans.binding.ObjectBinding, javafx.beans.property.SimpleBooleanProperty, javafx.collections.FXCollections, .ObservableList, org.jabref.logic.command.CommandSelectionTab, org.jabref.logic.importer.ImportFormatPreferences, org.jabref.logic.importer.fileformat.BibtexImporter, org.jabref.logic.search.SearchBackend, .SearchContext, org.jabref.logic.search.inmemory.InMemorySearchBackend, org.jabref.logic.util.OptionalObjectProperty, org.jabref.model.database.BibDatabaseContext, org.jabref.model.entry.BibEntry, .BibEntryPreferences, org.jabref.model.util.DummyFileUpdateMonitor, org.slf4j.Logger, .LoggerFactory

SrvStateManager for the stand-alone HTTP server.

The server serves a fixed set of libraries known at startup. Each one is parsed once in the constructor, an in-memory SearchContext is built for it, and the (BibDatabaseContext, mtime) pair is held for the lifetime of the process.

Because nothing watches the files asynchronously (jabsrv uses DummyFileUpdateMonitor everywhere), getOpenDatabases does a per-call stat on every tracked file and re-parses any that changed on disk since the last observation. The cost is one stat per library per request; only an actual modification triggers re-parsing. This is the cheap middle ground between "snapshot at startup" (broken when the user edits a .bib externally) and running a real org.jabref.model.util.FileUpdateMonitor thread.

There is no Postgres path: the in-memory backend has no startup cost, and the toggle is hardwired to false.

Field Summary

Modifier and TypeField and Description
private final BibEntryPreferences
private final BibtexImporter
private final Map<Path, FileTime>
private static final Logger
private final ObservableList<BibDatabaseContext>

Constructor Summary

AccessConstructor and Description
public
JabRefSrvStateManager(BibEntryPreferences bibEntryPreferences, ImportFormatPreferences importFormatPreferences, List<Path> files)

Method Summary

Modifier and TypeMethod and Description
public org.jabref.logic.util.OptionalObjectProperty<BibDatabaseContext>
public Optional<BibDatabaseContext>
public ObjectBinding<Optional<CommandSelectionTab>>
public synchronized List<String>
public synchronized ObservableList<BibDatabaseContext>
getOpenDatabases()

Implements org.jabref.http.SrvStateManager.getOpenDatabases.

Returns an unmodifiable snapshot of the open libraries.

public ObservableList<BibEntry>
private Optional<BibDatabaseContext>
parseLibrary(Path file)

Parses a single library.

private void
refreshStaleLibraries()

Compares each tracked file's current mtime against the snapshot taken at the last parse.

private void
Inherited from org.jabref.http.AbstractSrvStateManager:
getSearchContextremoveSearchContextsetSearchContext

Field Detail

bibEntryPreferencesback to summary
private final BibEntryPreferences bibEntryPreferences
importerback to summary
private final BibtexImporter importer
lastModifiedback to summary
private final Map<Path, FileTime> lastModified
LOGGERback to summary
private static final Logger LOGGER

Hides org.jabref.http.AbstractSrvStateManager.LOGGER.

openDatabasesback to summary
private final ObservableList<BibDatabaseContext> openDatabases

Constructor Detail

JabRefSrvStateManagerback to summary
public JabRefSrvStateManager(BibEntryPreferences bibEntryPreferences, ImportFormatPreferences importFormatPreferences, List<Path> files)

Method Detail

activeDatabasePropertyback to summary
public org.jabref.logic.util.OptionalObjectProperty<BibDatabaseContext> activeDatabaseProperty()

Implements org.jabref.http.SrvStateManager.activeDatabaseProperty.

Annotations
@Override
getActiveDatabaseback to summary
public Optional<BibDatabaseContext> getActiveDatabase()

Implements org.jabref.http.SrvStateManager.getActiveDatabase.

Annotations
@Override
getActiveSelectionTabPropertyback to summary
public ObjectBinding<Optional<CommandSelectionTab>> getActiveSelectionTabProperty()

Implements org.jabref.http.SrvStateManager.getActiveSelectionTabProperty.

Annotations
@Override
getAllDatabasePathsback to summary
public synchronized List<String> getAllDatabasePaths()

Implements org.jabref.http.SrvStateManager.getAllDatabasePaths.

Annotations
@Override
getOpenDatabasesback to summary
public synchronized ObservableList<BibDatabaseContext> getOpenDatabases()

Implements org.jabref.http.SrvStateManager.getOpenDatabases.

Returns an unmodifiable snapshot of the open libraries.

Grizzly/Jersey serve requests concurrently and several resources call getOpenDatabases().stream(). Returning the live openDatabases would let a caller iterate the list while another thread enters this method and refreshStaleLibraries structurally modifies it via the ListIterator#set in the reparse path. The snapshot is taken under the monitor so iteration after the call is race-free.

Annotations
@Override
getSelectedEntriesback to summary
public ObservableList<BibEntry> getSelectedEntries()

Implements org.jabref.http.SrvStateManager.getSelectedEntries.

Annotations
@Override
parseLibraryback to summary
private Optional<BibDatabaseContext> parseLibrary(Path file)

Parses a single library. A library that fails to parse is logged and skipped.

refreshStaleLibrariesback to summary
private void refreshStaleLibraries()

Compares each tracked file's current mtime against the snapshot taken at the last parse. If it changed, the library is re-parsed, the context in openDatabases is replaced, the old SearchContext is removed, and a fresh one is registered under the new context's uid.

registerSearchContextback to summary
private void registerSearchContext(BibDatabaseContext database)