1 9 package org.jrobin.core.jrrd; 10 11 import java.io.*; 12 import java.text.NumberFormat ; 13 14 20 public class DataSource { 21 22 long offset; 23 long size; 24 String name; 25 DataSourceType type; 26 int minimumHeartbeat; 27 double minimum; 28 double maximum; 29 PDPStatusBlock pdpStatusBlock; 30 31 DataSource(RRDFile file) throws IOException { 32 33 offset = file.getFilePointer(); 34 name = file.readString(Constants.DS_NAM_SIZE); 35 type = DataSourceType.get(file.readString(Constants.DST_SIZE)); 36 37 file.align(8); 38 39 minimumHeartbeat = file.readInt(true); 40 41 file.align(8); 42 43 minimum = file.readDouble(); 44 maximum = file.readDouble(); 45 46 file.align(); 48 file.skipBytes(56); 49 50 size = file.getFilePointer() - offset; 51 } 52 53 void loadPDPStatusBlock(RRDFile file) throws IOException { 54 pdpStatusBlock = new PDPStatusBlock(file); 55 } 56 57 62 public PDPStatusBlock getPDPStatusBlock() { 63 return pdpStatusBlock; 64 } 65 66 71 public int getMinimumHeartbeat() { 72 return minimumHeartbeat; 73 } 74 75 80 public double getMinimum() { 81 return minimum; 82 } 83 84 90 public DataSourceType getType() { 91 return type; 92 } 93 94 99 public double getMaximum() { 100 return maximum; 101 } 102 103 108 public String getName() { 109 return name; 110 } 111 112 void printInfo(PrintStream s, NumberFormat numberFormat) { 113 114 StringBuffer sb = new StringBuffer ("ds["); 115 116 sb.append(name); 117 s.print(sb); 118 s.print("].type = \""); 119 s.print(type); 120 s.println("\""); 121 s.print(sb); 122 s.print("].minimal_heartbeat = "); 123 s.println(minimumHeartbeat); 124 s.print(sb); 125 s.print("].min = "); 126 s.println(Double.isNaN(minimum) 127 ? "NaN" 128 : numberFormat.format(minimum)); 129 s.print(sb); 130 s.print("].max = "); 131 s.println(Double.isNaN(maximum) 132 ? "NaN" 133 : numberFormat.format(maximum)); 134 s.print(sb); 135 s.print("].last_ds = "); 136 s.println(pdpStatusBlock.lastReading); 137 s.print(sb); 138 s.print("].value = "); 139 140 double value = pdpStatusBlock.value; 141 142 s.println(Double.isNaN(value) 143 ? "NaN" 144 : numberFormat.format(value)); 145 s.print(sb); 146 s.print("].unknown_sec = "); 147 s.println(pdpStatusBlock.unknownSeconds); 148 } 149 150 void toXml(PrintStream s) { 151 152 s.println("\t<ds>"); 153 s.print("\t\t<name> "); 154 s.print(name); 155 s.println(" </name>"); 156 s.print("\t\t<type> "); 157 s.print(type); 158 s.println(" </type>"); 159 s.print("\t\t<minimal_heartbeat> "); 160 s.print(minimumHeartbeat); 161 s.println(" </minimal_heartbeat>"); 162 s.print("\t\t<min> "); 163 s.print(minimum); 164 s.println(" </min>"); 165 s.print("\t\t<max> "); 166 s.print(maximum); 167 s.println(" </max>"); 168 s.println(); 169 s.println("\t\t<!-- PDP Status -->"); 170 s.print("\t\t<last_ds> "); 171 s.print(pdpStatusBlock.lastReading); 172 s.println(" </last_ds>"); 173 s.print("\t\t<value> "); 174 s.print(pdpStatusBlock.value); 175 s.println(" </value>"); 176 s.print("\t\t<unknown_sec> "); 177 s.print(pdpStatusBlock.unknownSeconds); 178 s.println(" </unknown_sec>"); 179 s.println("\t</ds>"); 180 s.println(); 181 } 182 183 188 public String toString() { 189 190 StringBuffer sb = new StringBuffer ("[DataSource: OFFSET=0x"); 191 192 sb.append(Long.toHexString(offset)); 193 sb.append(", SIZE=0x"); 194 sb.append(Long.toHexString(size)); 195 sb.append(", name="); 196 sb.append(name); 197 sb.append(", type="); 198 sb.append(type.toString()); 199 sb.append(", minHeartbeat="); 200 sb.append(minimumHeartbeat); 201 sb.append(", min="); 202 sb.append(minimum); 203 sb.append(", max="); 204 sb.append(maximum); 205 sb.append("]"); 206 sb.append("\n\t\t"); 207 sb.append(pdpStatusBlock.toString()); 208 209 return sb.toString(); 210 } 211 } 212 | Popular Tags |