1 25 26 package org.jrobin.core; 27 28 import java.io.IOException ; 29 30 37 public class ArcState implements RrdUpdater { 38 private Archive parentArc; 39 40 private RrdDouble accumValue; 41 private RrdLong nanSteps; 42 43 ArcState(Archive parentArc, boolean shouldInitialize) throws IOException { 44 this.parentArc = parentArc; 45 accumValue = new RrdDouble(this); 46 nanSteps = new RrdLong(this); 47 if(shouldInitialize) { 48 Header header = parentArc.getParentDb().getHeader(); 49 long step = header.getStep(); 50 long lastUpdateTime = header.getLastUpdateTime(); 51 long arcStep = parentArc.getArcStep(); 52 long initNanSteps = (Util.normalize(lastUpdateTime, step) - 53 Util.normalize(lastUpdateTime, arcStep)) / step; 54 accumValue.set(Double.NaN); 55 nanSteps.set(initNanSteps); 56 } 57 } 58 59 String dump() throws IOException { 60 return "accumValue:" + accumValue.get() + " nanSteps:" + nanSteps.get() + "\n"; 61 } 62 63 void setNanSteps(long value) throws IOException { 64 nanSteps.set(value); 65 } 66 67 73 public long getNanSteps() throws IOException { 74 return nanSteps.get(); 75 } 76 77 void setAccumValue(double value) throws IOException { 78 accumValue.set(value); 79 } 80 81 87 public double getAccumValue() throws IOException { 88 return accumValue.get(); 89 } 90 91 96 public Archive getParent() { 97 return parentArc; 98 } 99 100 void appendXml(XmlWriter writer) throws IOException { 101 writer.startTag("ds"); 102 writer.writeTag("value", accumValue.get()); 103 writer.writeTag("unknown_datapoints", nanSteps.get()); 104 writer.closeTag(); } 106 107 113 public void copyStateTo(RrdUpdater other) throws IOException , RrdException { 114 if(!(other instanceof ArcState)) { 115 throw new RrdException( 116 "Cannot copy ArcState object to " + other.getClass().getName()); 117 } 118 ArcState arcState = (ArcState) other; 119 arcState.accumValue.set(accumValue.get()); 120 arcState.nanSteps.set(nanSteps.get()); 121 } 122 123 128 public RrdBackend getRrdBackend() { 129 return parentArc.getRrdBackend(); 130 } 131 132 136 public RrdAllocator getRrdAllocator() { 137 return parentArc.getRrdAllocator(); 138 } 139 } 140 | Popular Tags |