@Test public void shouldCleanupBeInvokedDuringClose() throws IOException { final AtomicInteger count = new AtomicInteger(); final StorageFactory storageFactory = new StorageFactory() { @Override protected Storage create(final String id, final int maximumSize) throws IOException { return createStorage(); } @Override protected void cleanup() throws IOException { count.incrementAndGet(); } }; storageFactory.close(); Assert.assertEquals(1, count.get()); }
@Idempotent @Override public final void close() throws IOException { cleanup(); for (final T storage : this.cache.values()) { try { close(storage); } catch (IOException e) { if (Loggers.BASE_LOGGER.isLoggable(Level.WARNING)) { Loggers.BASE_LOGGER.log(Level.WARNING, "Got an exception while cleaning <"+storage+">", e); } } } this.cache.clear(); }
StorageFactory implements Closeable { @Idempotent @Override public final void close() throws IOException { cleanup(); for (final T storage : this.cache.values()) { try { close(storage); } catch (IOException e) { if (Loggers.BASE_LOGGER.isLoggable(Level.WARNING)) { Loggers.BASE_LOGGER.log(Level.WARNING, "Got an exception while cleaning <"+storage+">", e); } } } this.cache.clear(); } }
StorageFactory implements Closeable { @Idempotent @Override public final void close() throws IOException { cleanup(); for (final T storage : this.cache.values()) { try { close(storage); } catch (IOException e) { if (Loggers.BASE_LOGGER.isLoggable(Level.WARNING)) { Loggers.BASE_LOGGER.log(Level.WARNING, "Got an exception while cleaning <"+storage+">", e); } } } this.cache.clear(); }  }
StorageFactory implements Closeable { @Idempotent @Override public final void close() throws IOException { cleanup(); for (final T storage : this.cache.values()) { try { close(storage); } catch (IOException e) { if (Loggers.BASE_LOGGER.isLoggable(Level.WARNING)) { Loggers.BASE_LOGGER.log(Level.WARNING, "Got an exception while cleaning <"+storage+">", e); } } } this.cache.clear(); }  final T createOrGet(final String id, final int granularity, final long duration); @Idempotent @Override final void close(); @Idempotent final boolean close(final String id); @Idempotent void delete(String id); }
StorageFactory implements Closeable { @Idempotent @Override public final void close() throws IOException { cleanup(); for (final T storage : this.cache.values()) { try { close(storage); } catch (IOException e) { if (Loggers.BASE_LOGGER.isLoggable(Level.WARNING)) { Loggers.BASE_LOGGER.log(Level.WARNING, "Got an exception while cleaning <"+storage+">", e); } } } this.cache.clear(); }  final T createOrGet(final String id, final int granularity, final long duration); @Idempotent @Override final void close(); @Idempotent final boolean close(final String id); @Idempotent void delete(String id);  }