Package org.mule.util.store

Source Code of org.mule.util.store.SimpleMemoryObjectStore

/*
* $Id: SimpleMemoryObjectStore.java 21762 2011-05-03 01:29:28Z mike.schilling $
* --------------------------------------------------------------------------------------
* Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
*
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/

package org.mule.util.store;

import org.mule.api.store.ListableObjectStore;
import org.mule.api.store.ObjectStoreException;
import org.mule.config.i18n.CoreMessages;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SimpleMemoryObjectStore<T extends Serializable> extends AbstractObjectStore<T> implements ListableObjectStore<T>
{
    private Map<Serializable, T> map = Collections.synchronizedMap(new HashMap<Serializable, T>());


    /**
     * {@inheritDoc}
     */
    public boolean isPersistent()
    {
        return false;
    }

    @Override
    protected boolean doContains(Serializable key)
    {
        return map.containsKey(key);
    }

    @Override
    protected void doStore(Serializable key, T value) throws ObjectStoreException
    {
        if (value == null)
        {
            throw new ObjectStoreException(CoreMessages.objectIsNull("value"));
        }

        map.put(key, value);
    }

    @Override
    protected T doRetrieve(Serializable key)
    {
        return map.get(key);
    }

    @Override
    protected T doRemove(Serializable key)
    {
        return map.remove(key);
    }

    public void open() throws ObjectStoreException
    {
        // this is a no-op
    }

    public void close() throws ObjectStoreException
    {
        // this is a no-op
    }

    public List<Serializable> allKeys() throws ObjectStoreException
    {
        return new ArrayList<Serializable>(map.keySet());
    }
}
TOP

Related Classes of org.mule.util.store.SimpleMemoryObjectStore

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.