From: Sasa M. <sa...@us...> - 2004-05-21 12:30:10
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6801/org/jrobin/core Modified Files: RrdBackend.java RrdBackendFactory.java Log Message: Method provided to replace the default backend but before any RRD gets created. Index: RrdBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdBackend.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdBackend.java 20 May 2004 10:34:00 -0000 1.1 --- RrdBackend.java 21 May 2004 12:30:00 -0000 1.2 *************** *** 69,72 **** --- 69,73 ---- public abstract class RrdBackend { private String path; + private static long count = 0; /** *************** *** 78,81 **** --- 79,83 ---- protected RrdBackend(String path) { this.path = path; + count++; } *************** *** 302,304 **** --- 304,310 ---- return Double.longBitsToDouble(getLong(b)); } + + static long getCount() { + return count; + } } Index: RrdBackendFactory.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdBackendFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdBackendFactory.java 20 May 2004 14:49:29 -0000 1.2 --- RrdBackendFactory.java 21 May 2004 12:30:00 -0000 1.3 *************** *** 73,77 **** // Here is the default backend factory ! defaultFactory = fileFactory; } catch (RrdException e) { --- 73,79 ---- // Here is the default backend factory ! //defaultFactory = fileFactory; ! defaultFactory = nioFactory; ! //defaultFactory = memoryFactory; } catch (RrdException e) { *************** *** 133,136 **** --- 135,158 ---- /** + * Replaces the default backend factory with a new one. This method must be called before + * the first RRD gets created. <p> + * @param factoryName Name of the default factory. Out of the box, JRobin supports three + * different RRD backends: "FILE" (java.io.* based), "NIO" (java.nio.* based) and "MEMORY" + * (byte[] based). + * @throws RrdException Thrown if invalid factory name is supplied or not called before + * the first RRD is created. + */ + public static void setDefaultFactory(String factoryName) throws RrdException { + // We will allow this only if no RRDs are created + if(RrdBackend.getCount() == 0) { + defaultFactory = getFactory(factoryName); + } + else { + throw new RrdException("Could not change the default backend factory. " + + "This method must be called before the first RRD gets created"); + } + } + + /** * Creates RrdBackend object for the given storage path. * @param path Storage path |