/** * Closes RRD. No further operations are allowed on this RrdDb object. * * @throws IOException Thrown in case of I/O related error. */ public synchronized void close() throws IOException { if (!closed) { closed = true; backend.close(); } }
protected void writeDouble(long offset, double value) throws IOException { write(offset, getDoubleBytes(value)); }
protected final void writeString(long offset, String value) throws IOException { if (nextBigStringOffset < 0) { nextBigStringOffset = getLength() - (Short.SIZE / 8); } value = value.trim(); // Over-sized string are appended at the end of the RRD // The real position is encoded in the "short" ds name, using the private use area from Unicode // This area span the range E000-F8FF, that' a 6400 char area, if (value.length() > RrdPrimitive.STRING_LENGTH) { String bigString = value; int byteStringLength = Math.min(MAXUNSIGNEDSHORT, bigString.length()); long bigStringOffset = nextBigStringOffset; nextBigStringOffset -= byteStringLength * 2 + (Short.SIZE / 8); writeShort(bigStringOffset, (short)byteStringLength); writeString(bigStringOffset - bigString.length() * 2, bigString, byteStringLength); // Now we generate the new string that encode the position long reminder = bigStringOffset; StringBuilder newValue = new StringBuilder(value.substring(0, RrdPrimitive.STRING_LENGTH)); int i = RrdPrimitive.STRING_LENGTH; // Read in inverse order, so write in inverse order while (reminder > 0) { // Only the first char is kept, as it will never byte a multi-char code point newValue.setCharAt(--i, Character.toChars((int)(reminder % PRIVATEAREASIZE + STARTPRIVATEAREACODEPOINT))[0]); reminder = (long) Math.floor( ((float)reminder) / (float)PRIVATEAREASIZE); } value = newValue.toString(); } writeString(offset, value, RrdPrimitive.STRING_LENGTH); }
/** * Returns the path to this RRD. * * @return Path to this RRD. */ public String getPath() { return backend.getPath(); }
protected void writeInt(long offset, int value) throws IOException { write(offset, getIntBytes(value)); }
protected void writeLong(long offset, long value) throws IOException { write(offset, getLongBytes(value)); }
RrdPrimitive(RrdUpdater<U> updater, int type, int count, boolean isConstant) throws IOException { this.backend = updater.getRrdBackend(); this.byteCount = RRD_PRIM_SIZES[type] * count; this.pointer = updater.getRrdAllocator().allocate(byteCount); this.cachingAllowed = isConstant || backend.isCachingAllowed(); }
private static byte[] getDoubleBytes(double value) { return getLongBytes(Double.doubleToLongBits(value)); }
private static double getDouble(byte[] b) { assert b.length == 8 : "Invalid number of bytes for double conversion"; return Double.longBitsToDouble(getLong(b)); }
void setFile(File newFile) { try { values = null; String path = newFile.getAbsolutePath(); RrdDb rrd = new RrdDb(path, true); try { Header header = rrd.getHeader(); String signature = header.getSignature(); String step = "" + header.getStep(); String lastTimestamp = header.getLastUpdateTime() + " [" + new Date(header.getLastUpdateTime() * 1000L) + "]"; String datasources = "" + header.getDsCount(); String archives = "" + header.getArcCount(); String size = rrd.getRrdBackend().getLength() + " bytes"; values = new Object[]{ path, signature, step, lastTimestamp, datasources, archives, size }; } finally { rrd.close(); } fireTableDataChanged(); } catch (Exception e) { Util.error(null, e); } } }
/** * Returns path to this RRD. * * @return Path to this RRD. */ public String getPath() { return backend.getPath(); }