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  * Developers:    Sasa Markovic (saxon@jrobin.org)
11  *
12  *
13  * This library is free software; you can redistribute it and/or modify it under the terms
14  * of the GNU Lesser General Public License as published by the Free Software Foundation;
15  * either version 2.1 of the License, or (at your option) any later version.
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
26 package org.jrobin.core;
27
28 import java.io.IOException;
29
30 /**
31  * Factory class which creates actual {@link RrdNioBackend} objects. This is the default factory since
32  * 1.4.0 version
33  */

34 public class RrdNioBackendFactory extends RrdFileBackendFactory {
35     /**
36      * factory name, "NIO"
37      */

38     public static final String NAME = "NIO";
39
40     /**
41      * Period in seconds between consecutive synchronizations when
42      * sync-mode is set to SYNC_BACKGROUND. By default in-memory cache will be
43      * transferred to the disc every 300 seconds (5 minutes). Default value can be
44      * changed via {@link #setSyncPeriod(int)} method.
45      */

46     public static final int DEFAULT_SYNC_PERIOD = 300; // seconds
47
48     private static int syncPeriod = DEFAULT_SYNC_PERIOD;
49
50     /**
51      * Returns time between two consecutive background synchronizations. If not changed via
52      * {@link #setSyncPeriod(int)} method call, defaults to {@link #DEFAULT_SYNC_PERIOD}.
53      * See {@link #setSyncPeriod(int)} for more information.
54      *
55      * @return Time in seconds between consecutive background synchronizations.
56      */

57     public static int getSyncPeriod() {
58         return syncPeriod;
59     }
60
61     /**
62      * Sets time between consecutive background synchronizations.
63      *
64      * @param syncPeriod Time in seconds between consecutive background synchronizations.
65      */

66     public static void setSyncPeriod(int syncPeriod) {
67         RrdNioBackendFactory.syncPeriod = syncPeriod;
68     }
69
70     /**
71      * Creates RrdNioBackend object for the given file path.
72      *
73      * @param path     File path
74      * @param readOnly True, if the file should be accessed in read/only mode.
75      *                 False otherwise.
76      * @return RrdNioBackend object which handles all I/O operations for the given file path
77      * @throws IOException Thrown in case of I/O error.
78      */

79     protected RrdBackend open(String path, boolean readOnly) throws IOException {
80         return new RrdNioBackend(path, readOnly, syncPeriod);
81     }
82
83     /**
84      * Returns the name of this factory.
85      *
86      * @return Factory name (equals to string "NIO")
87      */

88     public String getFactoryName() {
89         return NAME;
90     }
91 }
92