1 /* ============================================================
2 * JRobin : Pure java implementation of RRDTool's functionality
3 * ============================================================
4 *
5 * Project Info: http://www.jrobin.org
6 * Project Lead: Sasa Markovic (saxon@jrobin.org);
7 *
8 * (C) Copyright 2003-2005, by Sasa Markovic.
9 *
10 * This library is free software; you can redistribute it and/or modify it under the terms
11 * of the GNU Lesser General Public License as published by the Free Software Foundation;
12 * either version 2.1 of the License, or (at your option) any later version.
13 *
14 * Developers: Sasa Markovic (saxon@jrobin.org)
15 *
16 *
17 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 * See the GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License along with this
22 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23 * Boston, MA 02111-1307, USA.
24 */
25 package org.jrobin.core;
26
27 import java.io.IOException;
28
29 /**
30 * Factory class which creates actual {@link RrdSafeFileBackend} objects.
31 */
32 public class RrdSafeFileBackendFactory extends RrdFileBackendFactory {
33 /**
34 * Default time (in milliseconds) this backend will wait for a file lock.
35 */
36 public static final long LOCK_WAIT_TIME = 3000L;
37 private static long lockWaitTime = LOCK_WAIT_TIME;
38
39 /**
40 * Default time between two consecutive file locking attempts.
41 */
42 public static final long LOCK_RETRY_PERIOD = 50L;
43 private static long lockRetryPeriod = LOCK_RETRY_PERIOD;
44
45 /**
46 * factory name, "SAFE"
47 */
48 public static final String NAME = "SAFE";
49
50 /**
51 * Creates RrdSafeFileBackend object for the given file path.
52 *
53 * @param path File path
54 * @param readOnly This parameter is ignored
55 * @return RrdSafeFileBackend object which handles all I/O operations for the given file path
56 * @throws IOException Thrown in case of I/O error.
57 */
58 protected RrdBackend open(String path, boolean readOnly) throws IOException {
59 return new RrdSafeFileBackend(path, lockWaitTime, lockRetryPeriod);
60 }
61
62 /**
63 * Returns the name of this factory.
64 *
65 * @return Factory name (equals to string "SAFE")
66 */
67 public String getFactoryName() {
68 return NAME;
69 }
70
71 /**
72 * Returns time this backend will wait for a file lock.
73 *
74 * @return Time (in milliseconds) this backend will wait for a file lock.
75 */
76 public static long getLockWaitTime() {
77 return lockWaitTime;
78 }
79
80 /**
81 * Sets time this backend will wait for a file lock.
82 *
83 * @param lockWaitTime Maximum lock wait time (in milliseconds)
84 */
85 public static void setLockWaitTime(long lockWaitTime) {
86 RrdSafeFileBackendFactory.lockWaitTime = lockWaitTime;
87 }
88
89 /**
90 * Returns time between two consecutive file locking attempts.
91 *
92 * @return Time (im milliseconds) between two consecutive file locking attempts.
93 */
94 public static long getLockRetryPeriod() {
95 return lockRetryPeriod;
96 }
97
98 /**
99 * 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 }
107