001/*
002 * (C) Copyright 2015 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 * Nuxeo - initial API and implementation
016 */
017
018package org.nuxeo.ecm.core.transientstore;
019
020import java.util.concurrent.atomic.AtomicLong;
021
022import org.nuxeo.ecm.core.cache.Cache;
023import org.nuxeo.ecm.core.cache.InMemoryCacheImpl;
024import org.nuxeo.ecm.core.transientstore.api.TransientStore;
025
026/**
027 * Default implementation (i.e, not Cluster Aware) implementation of the {@link TransientStore}
028 *
029 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a>
030 * @since 7.2
031 */
032public class SimpleTransientStore extends AbstractTransientStore {
033
034    protected AtomicLong storageSize = new AtomicLong(0);
035
036    public SimpleTransientStore() {
037    }
038
039    @Override
040    protected void incrementStorageSize(long size) {
041        storageSize.addAndGet(size);
042    }
043
044    @Override
045    protected void decrementStorageSize(long size) {
046        storageSize.addAndGet(-size);
047    }
048
049    @Override
050    protected void setStorageSize(long newSize) {
051        storageSize.set(newSize);
052    }
053
054    @Override
055    public long getStorageSize() {
056        return (int) storageSize.get();
057    }
058
059    @Override
060    public Class<? extends Cache> getCacheImplClass() {
061        return InMemoryCacheImpl.class;
062    }
063
064}