001 /* ============================================================
002 * JRobin : Pure java implementation of RRDTool's functionality
003 * ============================================================
004 *
005 * Project Info: http://www.jrobin.org
006 * Project Lead: Sasa Markovic (saxon@jrobin.org);
007 *
008 * (C) Copyright 2003-2005, by Sasa Markovic.
009 *
010 * This library is free software; you can redistribute it and/or modify it under the terms
011 * of the GNU Lesser General Public License as published by the Free Software Foundation;
012 * either version 2.1 of the License, or (at your option) any later version.
013 *
014 * Developers: Sasa Markovic (saxon@jrobin.org)
015 *
016 *
017 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
018 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
019 * See the GNU Lesser General Public License for more details.
020 *
021 * You should have received a copy of the GNU Lesser General Public License along with this
022 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
023 * Boston, MA 02111-1307, USA.
024 */
025 package org.jrobin.core;
026
027 import java.io.IOException;
028
029 /**
030 * Factory class which creates actual {@link RrdSafeFileBackend} objects.
031 */
032 public class RrdSafeFileBackendFactory extends RrdFileBackendFactory {
033 /**
034 * Default time (in milliseconds) this backend will wait for a file lock.
035 */
036 public static final long LOCK_WAIT_TIME = 3000L;
037 private static long lockWaitTime = LOCK_WAIT_TIME;
038
039 /**
040 * Default time between two consecutive file locking attempts.
041 */
042 public static final long LOCK_RETRY_PERIOD = 50L;
043 private static long lockRetryPeriod = LOCK_RETRY_PERIOD;
044
045 /**
046 * factory name, "SAFE"
047 */
048 public static final String NAME = "SAFE";
049
050 /**
051 * Creates RrdSafeFileBackend object for the given file path.
052 *
053 * @param path File path
054 * @param readOnly This parameter is ignored
055 * @return RrdSafeFileBackend object which handles all I/O operations for the given file path
056 * @throws IOException Thrown in case of I/O error.
057 */
058 protected RrdBackend open(String path, boolean readOnly) throws IOException {
059 return new RrdSafeFileBackend(path, lockWaitTime, lockRetryPeriod);
060 }
061
062 /**
063 * Returns the name of this factory.
064 *
065 * @return Factory name (equals to string "SAFE")
066 */
067 public String getFactoryName() {
068 return NAME;
069 }
070
071 /**
072 * Returns time this backend will wait for a file lock.
073 *
074 * @return Time (in milliseconds) this backend will wait for a file lock.
075 */
076 public static long getLockWaitTime() {
077 return lockWaitTime;
078 }
079
080 /**
081 * Sets time this backend will wait for a file lock.
082 *
083 * @param lockWaitTime Maximum lock wait time (in milliseconds)
084 */
085 public static void setLockWaitTime(long lockWaitTime) {
086 RrdSafeFileBackendFactory.lockWaitTime = lockWaitTime;
087 }
088
089 /**
090 * Returns time between two consecutive file locking attempts.
091 *
092 * @return Time (im milliseconds) between two consecutive file locking attempts.
093 */
094 public static long getLockRetryPeriod() {
095 return lockRetryPeriod;
096 }
097
098 /**
099 * Sets time between two consecutive file locking attempts.
100 *
101 * @param lockRetryPeriod time (in milliseconds) between two consecutive file locking attempts.
102 */
103 public static void setLockRetryPeriod(long lockRetryPeriod) {
104 RrdSafeFileBackendFactory.lockRetryPeriod = lockRetryPeriod;
105 }
106 }