@Override protected AbstractCloseableRegistry< WrappingProxyCloseable<? extends Closeable>, SafetyNetCloseableRegistry.PhantomDelegatingCloseableRef> createRegistry() { return new SafetyNetCloseableRegistry(); }
/** * Activates the safety net for a thread. {@link FileSystem} instances obtained by the thread * that called this method will be guarded, meaning that their created streams are tracked and can * be closed via the safety net closing hook. * * <p>This method should be called at the beginning of a thread that should be guarded. * * @throws IllegalStateException Thrown, if a safety net was already registered for the thread. */ @Internal public static void initializeSafetyNetForThread() { SafetyNetCloseableRegistry oldRegistry = REGISTRIES.get(); checkState(null == oldRegistry, "Found an existing FileSystem safety net for this thread: %s " + "This may indicate an accidental repeated initialization, or a leak of the" + "(Inheritable)ThreadLocal through a ThreadPool.", oldRegistry); SafetyNetCloseableRegistry newRegistry = new SafetyNetCloseableRegistry(); REGISTRIES.set(newRegistry); }
@Test public void testReaperThreadSpawnAndStop() throws Exception { Assert.assertFalse(SafetyNetCloseableRegistry.isReaperThreadRunning()); try (SafetyNetCloseableRegistry ignored = new SafetyNetCloseableRegistry()) { Assert.assertTrue(SafetyNetCloseableRegistry.isReaperThreadRunning()); try (SafetyNetCloseableRegistry ignored2 = new SafetyNetCloseableRegistry()) { Assert.assertTrue(SafetyNetCloseableRegistry.isReaperThreadRunning()); } Assert.assertTrue(SafetyNetCloseableRegistry.isReaperThreadRunning()); } Assert.assertFalse(SafetyNetCloseableRegistry.isReaperThreadRunning()); } }
/** * Activates the safety net for a thread. {@link FileSystem} instances obtained by the thread * that called this method will be guarded, meaning that their created streams are tracked and can * be closed via the safety net closing hook. * * <p>This method should be called at the beginning of a thread that should be guarded. * * @throws IllegalStateException Thrown, if a safety net was already registered for the thread. */ @Internal public static void initializeSafetyNetForThread() { SafetyNetCloseableRegistry oldRegistry = REGISTRIES.get(); checkState(null == oldRegistry, "Found an existing FileSystem safety net for this thread: %s " + "This may indicate an accidental repeated initialization, or a leak of the" + "(Inheritable)ThreadLocal through a ThreadPool.", oldRegistry); SafetyNetCloseableRegistry newRegistry = new SafetyNetCloseableRegistry(); REGISTRIES.set(newRegistry); }
/** * Activates the safety net for a thread. {@link FileSystem} instances obtained by the thread * that called this method will be guarded, meaning that their created streams are tracked and can * be closed via the safety net closing hook. * * <p>This method should be called at the beginning of a thread that should be guarded. * * @throws IllegalStateException Thrown, if a safety net was already registered for the thread. */ @Internal public static void initializeSafetyNetForThread() { SafetyNetCloseableRegistry oldRegistry = REGISTRIES.get(); checkState(null == oldRegistry, "Found an existing FileSystem safety net for this thread: %s " + "This may indicate an accidental repeated initialization, or a leak of the" + "(Inheritable)ThreadLocal through a ThreadPool.", oldRegistry); SafetyNetCloseableRegistry newRegistry = new SafetyNetCloseableRegistry(); REGISTRIES.set(newRegistry); }