001/*
002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Antoine Taillefer <ataillefer@nuxeo.com>
018 */
019package org.nuxeo.ecm.core.transientstore;
020
021import java.io.Serializable;
022import java.util.List;
023import java.util.Map;
024import java.util.concurrent.ConcurrentHashMap;
025import java.util.concurrent.ConcurrentMap;
026
027import org.apache.commons.logging.Log;
028import org.apache.commons.logging.LogFactory;
029import org.nuxeo.ecm.core.transientstore.api.TransientStore;
030
031/**
032 * Class representing an entry stored in the {@link TransientStore}.
033 *
034 * @since 7.10
035 */
036public class StorageEntry implements Serializable {
037
038    protected Log log = LogFactory.getLog(StorageEntry.class);
039
040    private static final long serialVersionUID = 1L;
041
042    protected ConcurrentMap<String, Serializable> params;
043
044    protected List<Map<String, String>> blobInfos;
045
046    protected long size;
047
048    protected boolean completed;
049
050    public StorageEntry() {
051        this(0, false);
052    }
053
054    public StorageEntry(long size, boolean completed) {
055        params = null;
056        blobInfos = null;
057        this.size = size;
058        this.completed = completed;
059    }
060
061    public Map<String, Serializable> getParams() {
062        if (params == null) {
063            params = new ConcurrentHashMap<>();
064        }
065        return params;
066    }
067
068    public void putParams(Map<String, Serializable> params) {
069        if (this.params == null) {
070            this.params = new ConcurrentHashMap<>();
071        }
072        this.params.putAll(params);
073    }
074
075    public Serializable getParam(String param) {
076        if (params == null) {
077            return null;
078        }
079        return params.get(param);
080    }
081
082    public void putParam(String param, Serializable value) {
083        if (params == null) {
084            params = new ConcurrentHashMap<>();
085        }
086        params.put(param, value);
087    }
088
089    public List<Map<String, String>> getBlobInfos() {
090        return blobInfos;
091    }
092
093    public void setBlobInfos(List<Map<String, String>> blobInfos) {
094        this.blobInfos = blobInfos;
095    }
096
097    public long getSize() {
098        return size;
099    }
100
101    public void setSize(long size) {
102        this.size = size;
103    }
104
105    public boolean isCompleted() {
106        return completed;
107    }
108
109    public void setCompleted(boolean completed) {
110        this.completed = completed;
111    }
112
113}