Class LockDefeater

java.lang.Object
nz.org.riskscape.engine.data.relation.LockDefeater

public class LockDefeater extends Object

Provides a simple single-threaded work queue to let us work around geotool's thread-bound locks for accessing shapefiles. See code in ShpFiles for more info.

Calling code can workaround the thread-per-lock constraint by requiring all lock-sensitive code to be called via this 'defeater', e.g.

FeatureSource fs = lockDefeater.call(() -> dataStore.openFeatureSource()); // use features ... (doesn't need to be done via queue) lockDefeater.call(() -> fs.close());

https://gitlab.catalyst.net.nz/riskscape/riskscape/-/issues/307

# An alternative...

The whole reason that this has to exist is because of the locking assumptions in ShpFiles - if we can remove the locking, then this issue is side-stepped (our code doesn't assume a multi-user system). One way that might remove some of the clutter and potentially be more efficient would be to go direct from ShapefileReader and DbaseFileReader to Tuple and 'cut out the middle-man' - the FeatureSource code.

  • Constructor Details

    • LockDefeater

      public LockDefeater(String name)
  • Method Details

    • call

      public <T> T call(String taskName, Callable<T> callable)

      Call some code in the lock defeater's thread. Enqueues a task, waits for it to finish, then returns its result.

      Type Parameters:
      T - return type
      Parameters:
      taskName - name to use for debug/log output
      callable - code to call
      Returns:
      the result from the callable
      Throws:
      RuntimeException - if the calleable throws any kind of exception, it will be wrapped in a RuntimeException and thrown from this thread
    • stop

      public void stop()