1 25 26 package org.jrobin.core; 27 28 import java.io.IOException ; 29 30 41 public class FetchRequest { 42 private RrdDb parentDb; 43 private String consolFun; 44 private long fetchStart; 45 private long fetchEnd; 46 private long resolution; 47 private String [] filter; 48 49 FetchRequest(RrdDb parentDb, String consolFun, long fetchStart, long fetchEnd, 50 long resolution) throws RrdException { 51 this.parentDb = parentDb; 52 this.consolFun = consolFun; 53 this.fetchStart = fetchStart; 54 this.fetchEnd = fetchEnd; 55 this.resolution = resolution; 56 validate(); 57 } 58 59 68 public void setFilter(String [] filter) { 69 this.filter = filter; 70 } 71 72 81 public void setFilter(String filter) { 82 this.filter = (filter == null)? null: (new String [] { filter }); 83 } 84 85 90 public String [] getFilter() { 91 return filter; 92 } 93 94 98 public String getConsolFun() { 99 return consolFun; 100 } 101 102 106 public long getFetchStart() { 107 return fetchStart; 108 } 109 110 114 public long getFetchEnd() { 115 return fetchEnd; 116 } 117 118 122 public long getResolution() { 123 return resolution; 124 } 125 126 private void validate() throws RrdException { 127 if(!ArcDef.isValidConsolFun(consolFun)) { 128 throw new RrdException("Invalid consolidation function in fetch request: " + consolFun); 129 } 130 if(fetchStart < 0) { 131 throw new RrdException("Invalid start time in fetch request: " + fetchStart); 132 } 133 if(fetchEnd < 0) { 134 throw new RrdException("Invalid end time in fetch request: " + fetchEnd); 135 } 136 if(fetchStart > fetchEnd) { 137 throw new RrdException("Invalid start/end time in fetch request: " + fetchStart + 138 " > " + fetchEnd); 139 } 140 if(resolution <= 0) { 141 throw new RrdException("Invalid resolution in fetch request: " + resolution); 142 } 143 } 144 145 149 public String dump() { 150 return "fetch \"" + parentDb.getRrdBackend().getPath() + 151 "\" " + consolFun + " --start " + fetchStart + " --end " + fetchEnd + 152 (resolution > 1? " --resolution " + resolution: ""); 153 } 154 155 String getRrdToolCommand() { 156 return dump(); 157 } 158 159 169 public FetchPoint[] fetch() throws RrdException, IOException { 170 return parentDb.fetch(this); 171 } 172 173 181 public FetchData fetchData() throws RrdException, IOException { 182 return parentDb.fetchData(this); 183 } 184 185 189 public RrdDb getParentDb() { 190 return parentDb; 191 } 192 193 } 194 | Popular Tags |