1 25 package org.jrobin.graph; 26 27 import java.util.HashMap ; 28 import java.util.ArrayList ; 29 import java.io.IOException ; 30 31 import org.jrobin.core.RrdException; 32 import org.jrobin.core.RrdDb; 33 import org.jrobin.core.RrdOpener; 34 35 41 public class FetchSourceList 42 { 43 private HashMap map; 47 private ArrayList list; 48 49 private int defCount; 50 51 private boolean persistent; 52 private boolean openerLocked; 53 private boolean opened; 54 55 private RrdOpener rrdOpener; 56 57 58 70 public FetchSourceList( int defaultSize ) 71 { 72 this( defaultSize, false, false ); 73 } 74 75 85 public FetchSourceList( int defaultSize, boolean persistent, boolean lockOpener ) 86 { 87 map = new HashMap ( defaultSize ); 88 list = new ArrayList ( defaultSize ); 89 90 opened = false; 91 this.persistent = persistent; 92 this.openerLocked = lockOpener; 93 } 94 95 107 public FetchSourceList( int defaultSize, boolean persistent, boolean lockOpener, RrdOpener rrdOpener ) 108 { 109 this( defaultSize, persistent , lockOpener); 110 111 this.rrdOpener = rrdOpener; 112 } 113 114 115 123 public void setRrdOpener( RrdOpener rrdOpener ) 124 { 125 if ( !persistent && !openerLocked ) 127 this.rrdOpener = rrdOpener; 128 } 129 130 public RrdOpener getRrdOpener() { 131 return rrdOpener; 132 } 133 134 147 public void setPersistent( boolean persistent ) 148 { 149 this.persistent = persistent; 150 } 151 152 156 public void lockOpener() { 157 openerLocked = true; 158 } 159 160 164 public void unlockOpener() { 165 openerLocked = false; 166 } 167 168 172 public int size() { 173 return list.size(); 174 } 175 176 181 public int defCount() { 182 return defCount; 183 } 184 185 193 public void openAll() throws RrdException, IOException 194 { 195 if ( opened ) return; 196 197 for ( int i = 0; i < size(); i++ ) 198 get(i).openRrd(); 199 200 opened = true; 201 } 202 203 212 public void releaseAll() throws RrdException, IOException 213 { 214 if ( persistent ) return; 216 for ( int i = 0; i < size(); i++ ) 217 get(i).release(); 218 219 opened = false; 220 } 221 222 231 public void clear() throws RrdException, IOException 232 { 233 persistent = false; 234 235 releaseAll(); 236 237 map.clear(); 238 list.clear(); 239 } 240 241 250 public long getLastUpdateTime() throws RrdException, IOException 251 { 252 RrdDb rrd; 253 254 long maxUpdateTime = 0; 255 long lastUpdateTime = 0; 256 257 for ( int i = 0; i < size(); i++ ) 258 { 259 rrd = get(i).getRrd(); 260 261 lastUpdateTime = rrd.getLastUpdateTime(); 262 if ( lastUpdateTime > maxUpdateTime ) 263 maxUpdateTime = lastUpdateTime; 264 } 265 266 return maxUpdateTime; 267 } 268 269 282 public void add( String name, String file, String dsName, String consolFunc, String backend ) throws RrdException 283 { 284 if ( map.containsKey(file) ) 285 { 286 FetchSource rf = (FetchSource) map.get(file); 287 rf.addSource( consolFunc, dsName, name ); 288 } 289 else 290 { 291 FetchSource fs = new FetchSource( file, consolFunc, dsName, name, backend, this ); 292 map.put( file, fs ); 293 list.add( fs ); 294 } 295 296 defCount++; 297 } 298 299 311 public void add( String name, String file, String dsName, String consolFunc ) throws RrdException 312 { 313 if ( map.containsKey(file) ) 314 { 315 FetchSource rf = (FetchSource) map.get(file); 316 rf.addSource( consolFunc, dsName, name ); 317 } 318 else 319 { 320 FetchSource fs = new FetchSource( file, consolFunc, dsName, name, this ); 321 map.put( file, fs ); 322 list.add( fs ); 323 } 324 325 defCount++; 326 } 327 328 337 protected FetchSource get( int index ) 338 { 339 return (FetchSource) list.get(index); 340 } 341 } 342 | Popular Tags |