Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18483/org/jrobin/core Modified Files: FetchRequest.java RrdBackend.java RrdDb.java RrdDbPool.java RrdFileBackend.java RrdNioBackend.java Sample.java Log Message: small tweaks Index: RrdDbPool.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDbPool.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RrdDbPool.java 20 May 2004 10:29:33 -0000 1.7 --- RrdDbPool.java 28 May 2004 10:22:47 -0000 1.8 *************** *** 112,115 **** --- 112,116 ---- private Map rrdMap = new HashMap(); private List rrdGcList = new LinkedList(); + private RrdBackendFactory factory; /** *************** *** 154,158 **** } else { // not found, open it ! RrdDb rrdDb = new RrdDb(path); addRrdEntry(keypath, rrdDb); return rrdDb; --- 155,159 ---- } else { // not found, open it ! RrdDb rrdDb = new RrdDb(path, getFactory()); addRrdEntry(keypath, rrdDb); return rrdDb; *************** *** 174,178 **** String keypath = getCanonicalPath(path); prooveInactive(keypath); ! RrdDb rrdDb = new RrdDb(path, xmlPath); addRrdEntry(keypath, rrdDb); return rrdDb; --- 175,179 ---- String keypath = getCanonicalPath(path); prooveInactive(keypath); ! RrdDb rrdDb = new RrdDb(path, xmlPath, getFactory()); addRrdEntry(keypath, rrdDb); return rrdDb; *************** *** 191,195 **** String keypath = getCanonicalPath(path); prooveInactive(keypath); ! RrdDb rrdDb = new RrdDb(rrdDef); addRrdEntry(keypath, rrdDb); return rrdDb; --- 192,196 ---- String keypath = getCanonicalPath(path); prooveInactive(keypath); ! RrdDb rrdDb = new RrdDb(rrdDef, getFactory()); addRrdEntry(keypath, rrdDb); return rrdDb; *************** *** 370,373 **** --- 371,386 ---- } + private RrdBackendFactory getFactory() throws RrdException { + if(factory == null) { + factory = RrdBackendFactory.getDefaultFactory(); + if(!(factory instanceof RrdFileBackendFactory)) { + factory = null; + throw new RrdException( + "RrdDbPool cannot work with factories not derived from RrdFileBackendFactory"); + } + } + return factory; + } + private class RrdEntry { private RrdDb rrdDb; Index: RrdBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdBackend.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdBackend.java 21 May 2004 12:30:00 -0000 1.2 --- RrdBackend.java 28 May 2004 10:22:47 -0000 1.3 *************** *** 140,143 **** --- 140,153 ---- public abstract void close() throws IOException; + /** + * This method forces all data cached in memory but not yet stored in the persistant + * storage, to be stored in it. In the base class this method does nothing but + * subclasses might provide real functionality.<p> + * + * @throws IOException Thrown in case of I/O error + */ + protected void sync() throws IOException { + } + final void writeInt(long offset, int value) throws IOException { write(offset, getIntBytes(value)); Index: RrdNioBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdNioBackend.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdNioBackend.java 20 May 2004 10:34:00 -0000 1.1 --- RrdNioBackend.java 28 May 2004 10:22:47 -0000 1.2 *************** *** 82,88 **** */ public void close() throws IOException { - byteBuffer.force(); super.close(); } } --- 82,99 ---- */ public void close() throws IOException { super.close(); } + /** + * This method forces all data cached in memory but not yet stored in the file, + * to be stored in it. RrdNioBackend uses (a lot of) memory to cache I/O data. + * This method is automatically invoked when the {@link #close()} + * method is called. In other words, you don't have to call sync() before you call close().<p> + * + * @throws IOException Thrown in case of I/O error + */ + protected void sync() throws IOException { + byteBuffer.force(); + } + } Index: FetchRequest.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/FetchRequest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FetchRequest.java 20 May 2004 10:29:32 -0000 1.5 --- FetchRequest.java 28 May 2004 10:22:47 -0000 1.6 *************** *** 168,174 **** */ public FetchPoint[] fetch() throws RrdException, IOException { ! synchronized(parentDb) { ! return parentDb.fetch(this); ! } } --- 168,172 ---- */ public FetchPoint[] fetch() throws RrdException, IOException { ! return parentDb.fetch(this); } *************** *** 182,188 **** */ public FetchData fetchData() throws RrdException, IOException { ! synchronized(parentDb) { ! return parentDb.fetchData(this); ! } } --- 180,184 ---- */ public FetchData fetchData() throws RrdException, IOException { ! return parentDb.fetchData(this); } Index: RrdFileBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdFileBackend.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdFileBackend.java 21 May 2004 10:40:50 -0000 1.2 --- RrdFileBackend.java 28 May 2004 10:22:47 -0000 1.3 *************** *** 82,85 **** --- 82,86 ---- */ public void close() throws IOException { + sync(); unlockFile(); file.close(); Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** RrdDb.java 20 May 2004 10:29:32 -0000 1.16 --- RrdDb.java 28 May 2004 10:22:47 -0000 1.17 *************** *** 459,463 **** } ! void store(Sample sample) throws IOException, RrdException { if(closed) { throw new RrdException("RRD already closed, cannot store this sample"); --- 459,463 ---- } ! synchronized void store(Sample sample) throws IOException, RrdException { if(closed) { throw new RrdException("RRD already closed, cannot store this sample"); *************** *** 477,481 **** } ! FetchPoint[] fetch(FetchRequest request) throws IOException, RrdException { if(closed) { throw new RrdException("RRD already closed, cannot fetch data"); --- 477,481 ---- } ! synchronized FetchPoint[] fetch(FetchRequest request) throws IOException, RrdException { if(closed) { throw new RrdException("RRD already closed, cannot fetch data"); *************** *** 486,490 **** } ! FetchData fetchData(FetchRequest request) throws IOException, RrdException { if(closed) { throw new RrdException("RRD already closed, cannot fetch data"); --- 486,490 ---- } ! synchronized FetchData fetchData(FetchRequest request) throws IOException, RrdException { if(closed) { throw new RrdException("RRD already closed, cannot fetch data"); *************** *** 696,700 **** * @return Last update time (in seconds). */ ! public long getLastUpdateTime() throws IOException { return header.getLastUpdateTime(); } --- 696,700 ---- * @return Last update time (in seconds). */ ! public synchronized long getLastUpdateTime() throws IOException { return header.getLastUpdateTime(); } *************** *** 717,721 **** * @throws RrdException Thrown in case of JRobin specific error. */ ! public RrdDef getRrdDef() throws RrdException, IOException { // set header long startTime = header.getLastUpdateTime(); --- 717,721 ---- * @throws RrdException Thrown in case of JRobin specific error. */ ! public synchronized RrdDef getRrdDef() throws RrdException, IOException { // set header long startTime = header.getLastUpdateTime(); *************** *** 785,789 **** * @throws RrdException Thrown if supplied argument is not a compatible RrdDb object */ ! public void copyStateTo(RrdUpdater other) throws IOException, RrdException { if(!(other instanceof RrdDb)) { throw new RrdException( --- 785,789 ---- * @throws RrdException Thrown if supplied argument is not a compatible RrdDb object */ ! public synchronized void copyStateTo(RrdUpdater other) throws IOException, RrdException { if(!(other instanceof RrdDb)) { throw new RrdException( *************** *** 898,904 **** * @throws IOException Thrown in case of I/O related error. */ ! public byte[] getBytes() throws IOException { return backend.readAll(); } } --- 898,917 ---- * @throws IOException Thrown in case of I/O related error. */ ! public synchronized byte[] getBytes() throws IOException { return backend.readAll(); } + /** + * This method forces all RRD data cached in memory but not yet stored in the persistant + * storage, to be stored in it. This method should be used only if you RrdDb object uses + * RrdBackend which implements any kind of data caching (like {@link RrdNioBackend}). This method + * need not be called before the {@link #close()} method call since the close() method always + * synchronizes all data in memory with the data in the persisant storage.<p> + * + * @throws IOException Thrown in case of I/O error + */ + public synchronized void sync() throws IOException { + backend.sync(); + } + } Index: Sample.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Sample.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Sample.java 20 May 2004 10:29:33 -0000 1.7 --- Sample.java 28 May 2004 10:22:47 -0000 1.8 *************** *** 197,203 **** */ public void update() throws IOException, RrdException { ! synchronized(parentDb) { ! parentDb.store(this); ! } clearCurrentValues(); } --- 197,201 ---- */ public void update() throws IOException, RrdException { ! parentDb.store(this); clearCurrentValues(); } |