001/*
002 * (C) Copyright 2017 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 *     bdelbosc
018 */
019package org.nuxeo.ecm.platform.importer.mqueues.chronicle;
020
021import org.nuxeo.common.Environment;
022import org.nuxeo.runtime.api.Framework;
023
024import java.nio.file.Path;
025import java.nio.file.Paths;
026
027/**
028 * @since 9.2
029 */
030public class ChronicleConfig {
031    public static final String NUXEO_MQUEUE_DIR_PROP = "nuxeo.mqueue.chronicle.dir";
032
033    public static final String NUXEO_MQUEUE_RET_DURATION_PROP = "nuxeo.mqueue.chronicle.retention.duration";
034
035    /**
036     * Returns the base path to store Chronicle Queues
037     */
038    public static Path getBasePath(String name) {
039        String ret = Framework.getProperty(NUXEO_MQUEUE_DIR_PROP);
040        if (ret != null) {
041            return Paths.get(ret).toAbsolutePath();
042        }
043        ret = Framework.getProperty(Environment.NUXEO_DATA_DIR);
044        if (ret != null) {
045            return Paths.get(ret, "mqueue", name).toAbsolutePath();
046        }
047        return Paths.get(Framework.getRuntime().getHome().getAbsolutePath(),
048                "data", "mqueue", name).toAbsolutePath();
049    }
050
051    /**
052     * Returns the retention duration property
053     */
054    public static String getRetentionDuration() {
055        return Framework.getProperty(NUXEO_MQUEUE_RET_DURATION_PROP);
056    }
057
058}