Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3307/org/jrobin/core Modified Files: ArcState.java Robin.java RrdDb.java RrdDouble.java RrdFile.java RrdInt.java RrdLong.java RrdString.java Log Message: Added option to open RRD files in READ-ONLY mode. Index: RrdString.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdString.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdString.java 29 Mar 2004 14:38:28 -0000 1.5 --- RrdString.java 20 Apr 2004 08:20:29 -0000 1.6 *************** *** 40,44 **** void loadCache() throws IOException { RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getMode() == RrdFile.MODE_RESTORE) { rrdFile.seek(getPointer()); char[] c = new char[SIZE]; --- 40,44 ---- void loadCache() throws IOException { RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getRrdMode() == RrdFile.MODE_RESTORE) { rrdFile.seek(getPointer()); char[] c = new char[SIZE]; Index: RrdLong.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdLong.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdLong.java 29 Mar 2004 14:38:28 -0000 1.5 --- RrdLong.java 20 Apr 2004 08:20:29 -0000 1.6 *************** *** 40,44 **** void loadCache() throws IOException { RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getMode() == RrdFile.MODE_RESTORE) { rrdFile.seek(getPointer()); cache = rrdFile.readLong(); --- 40,44 ---- void loadCache() throws IOException { RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getRrdMode() == RrdFile.MODE_RESTORE) { rrdFile.seek(getPointer()); cache = rrdFile.readLong(); Index: ArcState.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/ArcState.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ArcState.java 2 Dec 2003 10:18:17 -0000 1.6 --- ArcState.java 20 Apr 2004 08:20:29 -0000 1.7 *************** *** 43,47 **** ArcState(Archive parentArc) throws IOException { this.parentArc = parentArc; ! if(getRrdFile().getMode() == RrdFile.MODE_CREATE) { // should initialize Header header = parentArc.getParentDb().getHeader(); --- 43,47 ---- ArcState(Archive parentArc) throws IOException { this.parentArc = parentArc; ! if(getRrdFile().getRrdMode() == RrdFile.MODE_CREATE) { // should initialize Header header = parentArc.getParentDb().getHeader(); Index: Robin.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Robin.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Robin.java 30 Mar 2004 09:55:22 -0000 1.10 --- Robin.java 20 Apr 2004 08:20:29 -0000 1.11 *************** *** 49,53 **** this.parentArc = parentArc; this.rows = rows; ! if(getRrdFile().getMode() == RrdFile.MODE_CREATE) { pointer = new RrdInt(0, this); values = new RrdDoubleArray(this, rows, Double.NaN); --- 49,53 ---- this.parentArc = parentArc; this.rows = rows; ! if(getRrdFile().getRrdMode() == RrdFile.MODE_CREATE) { pointer = new RrdInt(0, this); values = new RrdDoubleArray(this, rows, Double.NaN); Index: RrdFile.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdFile.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RrdFile.java 26 Mar 2004 08:47:05 -0000 1.6 --- RrdFile.java 20 Apr 2004 08:20:29 -0000 1.7 *************** *** 46,51 **** static final int MODE_CREATE = 2; ! static final long LOCK_DELAY = 500; // 0.5sec ! static final String FLAGS = "rw"; // R/W access static int lockMode = RrdDb.NO_LOCKS; --- 46,55 ---- static final int MODE_CREATE = 2; ! static final long LOCK_DELAY = 100; // 0.1sec ! ! // access mode ! static final String ACCESS_READ_WRITE = "rw"; ! static final String ACCESS_READ_ONLY = "r"; ! static int lockMode = RrdDb.NO_LOCKS; *************** *** 53,62 **** private FileLock fileLock; private List primitives = new LinkedList(); ! private int mode; ! RrdFile(String filePath, int mode) throws IOException { ! super(filePath, FLAGS); this.filePath = filePath; ! this.mode = mode; lockFile(); } --- 57,66 ---- private FileLock fileLock; private List primitives = new LinkedList(); ! private int rrdMode; ! RrdFile(String filePath, int rrdMode, boolean readOnly) throws IOException { ! super(filePath, readOnly? ACCESS_READ_ONLY: ACCESS_READ_WRITE); this.filePath = filePath; ! this.rrdMode = rrdMode; lockFile(); } *************** *** 170,179 **** } ! int getMode() { ! return mode; } ! void setMode(int mode) { ! this.mode = mode; } --- 174,183 ---- } ! int getRrdMode() { ! return rrdMode; } ! void setRrdMode(int rrdMode) { ! this.rrdMode = rrdMode; } Index: RrdInt.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdInt.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdInt.java 29 Mar 2004 14:38:28 -0000 1.5 --- RrdInt.java 20 Apr 2004 08:20:29 -0000 1.6 *************** *** 40,44 **** void loadCache() throws IOException { RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getMode() == RrdFile.MODE_RESTORE) { rrdFile.seek(getPointer()); cache = rrdFile.readInt(); --- 40,44 ---- void loadCache() throws IOException { RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getRrdMode() == RrdFile.MODE_RESTORE) { rrdFile.seek(getPointer()); cache = rrdFile.readInt(); Index: RrdDouble.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDouble.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdDouble.java 29 Mar 2004 14:38:28 -0000 1.5 --- RrdDouble.java 20 Apr 2004 08:20:29 -0000 1.6 *************** *** 40,44 **** void loadCache() throws IOException { RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getMode() == RrdFile.MODE_RESTORE) { rrdFile.seek(getPointer()); cache = rrdFile.readDouble(); --- 40,44 ---- void loadCache() throws IOException { RrdFile rrdFile = getRrdFile(); ! if(rrdFile.getRrdMode() == RrdFile.MODE_RESTORE) { rrdFile.seek(getPointer()); cache = rrdFile.readDouble(); Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** RrdDb.java 11 Mar 2004 13:54:25 -0000 1.13 --- RrdDb.java 20 Apr 2004 08:20:29 -0000 1.14 *************** *** 108,112 **** public RrdDb(RrdDef rrdDef) throws IOException, RrdException { rrdDef.validate(); ! initializeSetup(rrdDef.getPath(), RrdFile.MODE_CREATE); // create header header = new Header(this, rrdDef); --- 108,112 ---- public RrdDb(RrdDef rrdDef) throws IOException, RrdException { rrdDef.validate(); ! initializeSetup(rrdDef.getPath(), RrdFile.MODE_CREATE, false); // create header header = new Header(this, rrdDef); *************** *** 130,141 **** /** * <p>Constructor used to open already existing RRD file. ! * Obtains read/write access to RRD file so that future ! * fetch and update operations are possible.</p> * * @param path Path to existing RRD file. * @throws IOException Thrown in case of I/O error. * @throws RrdException Thrown in case of JRobin specific error. */ ! public RrdDb(String path) throws IOException, RrdException { // opens existing RRD file - throw exception if the file does not exist... File rrdFile = new File(path); --- 130,145 ---- /** * <p>Constructor used to open already existing RRD file. ! * Obtains read or read/write access to RRD file.</p> * * @param path Path to existing RRD file. + * @param readOnly Should be set to <code>false</code> if you want to update + * the underlying RRD file. If you want just to fetch data from the RRD file + * (read-only access), specify <code>true</code>. If you try to update RRD file + * open in read-only mode (<code>readOnly</code> set to <code>true</code>), + * <code>IOException</code> will be thrown. * @throws IOException Thrown in case of I/O error. * @throws RrdException Thrown in case of JRobin specific error. */ ! public RrdDb(String path, boolean readOnly) throws IOException, RrdException { // opens existing RRD file - throw exception if the file does not exist... File rrdFile = new File(path); *************** *** 144,148 **** } try { ! initializeSetup(path, RrdFile.MODE_RESTORE); // restore header header = new Header(this); --- 148,152 ---- } try { ! initializeSetup(path, RrdFile.MODE_RESTORE, readOnly); // restore header header = new Header(this); *************** *** 167,170 **** --- 171,187 ---- /** + * <p>Constructor used to open already existing RRD file. + * Obtains <b>full</b> (read/write) access to the underlying RRD file + * so that future RRD updates are possible.</p> + * + * @param path Path to existing RRD file. + * @throws IOException Thrown in case of I/O error. + * @throws RrdException Thrown in case of JRobin specific error. + */ + public RrdDb(String path) throws IOException, RrdException { + this(path, false); + } + + /** * <p>Constructor used to create new RRD file from XML dump. JRobin and RRDTool * use the same format for XML dump and this constructor should be used to *************** *** 189,193 **** */ public RrdDb(String rrdPath, String xmlPath) throws IOException, RrdException { ! initializeSetup(rrdPath, RrdFile.MODE_CREATE); XmlReader reader = new XmlReader(xmlPath); // create header --- 206,210 ---- */ public RrdDb(String rrdPath, String xmlPath) throws IOException, RrdException { ! initializeSetup(rrdPath, RrdFile.MODE_CREATE, false); XmlReader reader = new XmlReader(xmlPath); // create header *************** *** 210,219 **** ! private void initializeSetup(String path, int mode) throws IOException { ! file = new RrdFile(path, mode); } private void finalizeSetup() throws IOException { ! int mode = file.getMode(); if(mode == RrdFile.MODE_CREATE) { file.truncateFile(); --- 227,236 ---- ! private void initializeSetup(String path, int mode, boolean readOnly) throws IOException { ! file = new RrdFile(path, mode, readOnly); } private void finalizeSetup() throws IOException { ! int mode = file.getRrdMode(); if(mode == RrdFile.MODE_CREATE) { file.truncateFile(); *************** *** 224,228 **** } } ! file.setMode(RrdFile.MODE_NORMAL); canonicalPath = file.getCanonicalFilePath(); } --- 241,245 ---- } } ! file.setRrdMode(RrdFile.MODE_NORMAL); canonicalPath = file.getCanonicalFilePath(); } |