/** {@inheritDoc} */ @Override public boolean deleteWithVersion(long version, String context, String key) throws IOException, VersionMismatchException { return deleteImpl(version, context, key); }
/** {@inheritDoc} */ @Override protected void doDestroy() { contextMap = null; lock = null; super.doDestroy(); }
/** {@inheritDoc} */ @Override protected void doInitialize() throws ComponentInitializationException { super.doInitialize(); contextMap = new HashMap<>(); lock = new ReentrantReadWriteLock(true); }
/** Constructor. */ public AbstractMapBackedStorageService() { setContextSize(Integer.MAX_VALUE); setKeySize(Integer.MAX_VALUE); setValueSize(Integer.MAX_VALUE); }
/** {@inheritDoc} */ @Override public void deleteContext(@Nonnull @NotEmpty final String context) throws IOException { final Lock writeLock = getLock().writeLock(); try { writeLock.lock(); setDirty(); try { getContextMap().remove(context); } catch (final Exception e) { throw new IOException(e); } } finally { writeLock.unlock(); } log.debug("Deleted context '{}'", context); }
/** {@inheritDoc} */ @Override public void reap(@Nonnull @NotEmpty final String context) throws IOException { final Lock writeLock = getLock().writeLock(); try { writeLock.lock(); final Map<String,Map<String,MutableStorageRecord>> contextMap; try { contextMap = getContextMap(); } catch (final Exception e) { throw new IOException(e); } final Map<String, MutableStorageRecord> dataMap = contextMap.get(context); if (dataMap != null) { if (reapWithLock(dataMap, System.currentTimeMillis())) { setDirty(); if (dataMap.isEmpty()) { contextMap.remove(context); } } } } finally { writeLock.unlock(); } }
/** {@inheritDoc} */ @Override public boolean updateExpiration(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key, @Nullable final Long expiration) throws IOException { try { return updateImpl(null, context, key, null, expiration) != null; } catch (VersionMismatchException e) { throw new IOException("Unexpected exception thrown by update.", e); } }
@Nonnull @NotEmpty final String key, @Nullable final Long version) throws IOException { Lock readLock = getLock().readLock(); try { readLock.lock(); contextMap = getContextMap(); } catch (final Exception e) { throw new IOException(e);
/** {@inheritDoc} */ @Override @Nonnull public Pair<Long, StorageRecord> read(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key, final long version) throws IOException { return readImpl(context, key, version); }
/** {@inheritDoc} */ @Override public synchronized void setCleanupInterval(final long interval) { // Don't allow a cleanup task. super.setCleanupInterval(0); }
public void updateContextExpiration(@Nonnull @NotEmpty final String context, @Nullable final Long expiration) throws IOException { final Lock writeLock = getLock().writeLock(); contextMap = getContextMap(); } catch (final Exception e) { throw new IOException(e); setDirty(); Long now = System.currentTimeMillis(); for (MutableStorageRecord record : dataMap.values()) {
/** {@inheritDoc} */ @Override @Nullable protected Long updateImpl(@Nullable final Long version, @Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key, @Nullable final String value, @Nullable final Long expiration) throws IOException, VersionMismatchException { final Long i = super.updateImpl(version, context, key, value, expiration); if (i != null) { setDirty(true); } return i; }
/** {@inheritDoc} */ @Override @Nullable public StorageRecord read(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key) throws IOException { return readImpl(context, key, null).getSecond(); }
/** {@inheritDoc} */ @Override public synchronized void setCleanupInterval(final long interval) { // Don't allow a cleanup task. super.setCleanupInterval(0); }
public boolean create(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key, @Nonnull @NotEmpty final String value, @Nullable final Long expiration) throws IOException { final Lock writeLock = getLock().writeLock(); contextMap = getContextMap(); } catch (final Exception e) { throw new IOException(e); new Object[] { key, context, expiration }); setDirty(); return true;
/** {@inheritDoc} */ @Override public boolean update(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key, @Nonnull @NotEmpty final String value, @Nullable final Long expiration) throws IOException { try { return updateImpl(null, context, key, value, expiration) != null; } catch (VersionMismatchException e) { throw new IOException("Unexpected exception thrown by update.", e); } }
/** {@inheritDoc} */ @Override protected void doInitialize() throws ComponentInitializationException { super.doInitialize(); if (httpServletRequest == null) { throw new ComponentInitializationException("HttpServletRequest must be set"); } else if (dataSealer == null || cookieManager == null) { throw new ComponentInitializationException("DataSealer and CookieManager must be set"); } }
/** {@inheritDoc} */ @Override public boolean delete(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key) throws IOException { try { return deleteImpl(null, context, key); } catch (VersionMismatchException e) { throw new IOException("Unexpected exception thrown by delete.", e); } }
@Nonnull @NotEmpty final String key) throws IOException, VersionMismatchException { final Lock writeLock = getLock().writeLock(); contextMap = getContextMap(); } catch (final Exception e) { throw new IOException(e); throw new VersionMismatchException(); } else { setDirty(); dataMap.remove(key); log.trace("Deleted record '{}' in context '{}'", key, context);
/** {@inheritDoc} */ @Override @Nullable public Long updateWithVersion(final long version, @Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key, @Nonnull @NotEmpty final String value, @Nullable final Long expiration) throws IOException, VersionMismatchException { return updateImpl(version, context, key, value, expiration); }