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 net.bull.javamelody.internal.model;
27
28 import java.io.IOException;
29
30 import org.jrobin.core.RrdBackend;
31 import org.jrobin.core.RrdFileBackendFactory;
32
33 /**
34 * Factory class which creates actual {@link RrdNioBackend} objects. This is the default factory since
35 * 1.4.0 version
36 */
37 public class RrdNioBackendFactory extends RrdFileBackendFactory {
38 /**
39 * factory name, "NIO-JavaMelody".
40 */
41 public static final String FACTORY_NAME = "NIO-JavaMelody";
42
43 /**
44 * Period in seconds between consecutive synchronizations when
45 * sync-mode is set to SYNC_BACKGROUND. By default in-memory cache will be
46 * transferred to the disc every 300 seconds (5 minutes). Default value can be
47 * changed via {@link #setSyncPeriod(int)} method.
48 */
49 public static final int DEFAULT_SYNC_PERIOD = 300; // seconds
50
51 private static int syncPeriod = DEFAULT_SYNC_PERIOD;
52
53 /**
54 * Returns time between two consecutive background synchronizations. If not changed via
55 * {@link #setSyncPeriod(int)} method call, defaults to {@link #DEFAULT_SYNC_PERIOD}.
56 * See {@link #setSyncPeriod(int)} for more information.
57 *
58 * @return Time in seconds between consecutive background synchronizations.
59 */
60 public static int getSyncPeriod() {
61 return syncPeriod;
62 }
63
64 /**
65 * Sets time between consecutive background synchronizations.
66 *
67 * @param syncPeriod Time in seconds between consecutive background synchronizations.
68 */
69 public static void setSyncPeriod(int syncPeriod) {
70 RrdNioBackendFactory.syncPeriod = syncPeriod;
71 }
72
73 /**
74 * Creates RrdNioBackend object for the given file path.
75 *
76 * @param path File path
77 * @param readOnly True, if the file should be accessed in read/only mode.
78 * False otherwise.
79 * @return RrdNioBackend object which handles all I/O operations for the given file path
80 * @throws IOException Thrown in case of I/O error.
81 */
82 @Override
83 protected RrdBackend open(String path, boolean readOnly) throws IOException {
84 return new RrdNioBackend(path, readOnly, syncPeriod);
85 }
86
87 /**
88 * Returns the name of this factory.
89 *
90 * @return Factory name (equals to string "NIO-JavaMelody")
91 */
92 @Override
93 public String getFactoryName() {
94 return FACTORY_NAME;
95 }
96 }
97