Package name.pachler.nio.file.ext
Class Bootstrapper
java.lang.Object
name.pachler.nio.file.ext.Bootstrapper
The Bootstrapper is used to instantiate WatchService and Path instances.
Because jpathwatch does not implement all the underlying infrastructure
of JDK7's nio implementation, the non-standard Bootstrapper class is used
for these chores.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic long
Retrieves the default polling interval.static boolean
static Path
Creates a new Path instance for a given File.static WatchService
Creates a new WatchService.static File
pathToFile
(Path path) Gets the File that corresponds to the given path.static void
setDefaultPollingInterval
(long pollInterval) This method allows to set the default polling time interval for new WatchService implementations that use polling.static void
setForcePollingEnabled
(boolean forcePollingEnabled) When force polling is enabled, the Bootstrapper'snewWatchService()
method will only produce polling watch services.
-
Constructor Details
-
Bootstrapper
public Bootstrapper()
-
-
Method Details
-
newWatchService
Creates a new WatchService. This is a shortcut for callingFileSystems.getDefault().newWatchService()
and is not source-compatible to JDK7- Returns:
- a new WatchService implementation instance.
- See Also:
-
newPath
Creates a new Path instance for a given File.- Parameters:
file
- that a new Path is created for- Returns:
- a new Path() corresponding to the given File
-
pathToFile
Gets the File that corresponds to the given path.- Parameters:
path
- Path for with to retreive the corresponding File- Returns:
- The file which corresponds to the given Path instance.
-
isForcePollingEnabled
public static boolean isForcePollingEnabled()- Returns:
- whether polling is enforced.
-
setForcePollingEnabled
public static void setForcePollingEnabled(boolean forcePollingEnabled) When force polling is enabled, the Bootstrapper'snewWatchService()
method will only produce polling watch services. This feature is mostly useful for testing and debugging (and not not much else really).- Parameters:
forcePollingEnabled
- true to enable force polling
-
setDefaultPollingInterval
public static void setDefaultPollingInterval(long pollInterval) This method allows to set the default polling time interval for new WatchService implementations that use polling. Note that polling is only used on a few supported platforms when certain event kinds are used or on unsupported platforms (fallback implementation).
The polling interval determines how often a thread that calls
WatchService.take()
will wake up to check if files in the watched directory have changed. Longer time intervals will make a polling service less accurate, but costs less in CPU and disk resources, while shorter time intervals lead to higher accuracy but more consumed resources (up to the point where polling takes longer than the set interval in which case the machine will become very slow).- Parameters:
pollInterval
- the polling time interval in milliseconds
-
getDefaultPollingInterval
public static long getDefaultPollingInterval()Retrieves the default polling interval.- Returns:
- the default polling interval, in milliseconds
- See Also:
-