Produced by Araxis Merge on 6/5/2018 10:24:10 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | patch_205_build_9.zip\Java\ImagingCommon\main\src\java\gov\va\med\imaging\monitor | DriveSpaceMonitor.java | Wed May 30 14:35:23 2018 UTC |
2 | patch_205_build_9.zip\Java\ImagingCommon\main\src\java\gov\va\med\imaging\monitor | DriveSpaceMonitor.java | Fri Jun 1 20:45:52 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 516 |
Changed | 1 | 2 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | /** | |
2 | * | |
3 | */ | |
4 | package go v.va.med.i maging.mon itor; | |
5 | ||
6 | import jav a.io.Buffe redInputSt ream; | |
7 | import jav a.io.Input Stream; | |
8 | import jav a.io.Input StreamRead er; | |
9 | import jav a.io.LineN umberReade r; | |
10 | import jav a.util.*; | |
11 | import org .apache.lo gging.log4 j.LogManag er; | |
12 | import org .apache.lo gging.log4 j.Logger; | |
13 | ||
14 | /** | |
15 | * This cl ass is def inately NO T thread-s afe. It r elies on a single th read doing the | |
16 | * collect ion of the drive sta tistics an d the eval uation of the set li mits. | |
17 | * | |
18 | * @author PII | |
19 | * | |
20 | */ | |
21 | public abs tract clas s DriveSpa ceMonitor | |
22 | extends Ti merTask | |
23 | { | |
24 | pr ivate Logg er logger = LogManag er.getLogg er(this.ge tClass().g etName()); | |
25 | pr ivate stat ic DriveSp aceMonitor singleton ; | |
26 | pr ivate stat ic final l ong defaul tPeriodici ty = 60000 L; | |
27 | ||
28 | pu blic stati c synchron ized Drive SpaceMonit or getSing leton() | |
29 | { | |
30 | if(s ingleton = = null) | |
31 | { | |
32 | single ton = crea teOSSpecif icMonitor( ); | |
33 | ||
34 | if(sin gleton != null && si ngleton in stanceof T imerTask) | |
35 | { | |
36 | String t imerThread Name = Dri veSpaceMon itorProper ties.getSt ring("Driv eSpaceMoni tor.TimerT hread"); | |
37 | long per iodicity = DriveSpac eMonitorPr operties.g etLong("Dr iveSpaceMo nitor.Peri odicity", defaultPer iodicity); | |
38 | ||
39 | new Time r(timerThr eadName, t rue).sched ule(single ton, new D ate(), per iodicity); //$NON-NL S-1$ | |
40 | } | |
41 | } | |
42 | ||
43 | retu rn singlet on; | |
44 | } | |
45 | ||
46 | /* * | |
47 | * | |
48 | * / | |
49 | pr ivate stat ic DriveSp aceMonitor createOSS pecificMon itor() | |
50 | { | |
51 | Stri ng osName = System.g etProperty ("os.name" ); //$NON- NLS-1$ | |
52 | if(o sName == n ull) | |
53 | return null; | |
54 | // t rim and lo wer case t o make com parison ea sier | |
55 | osNa me = osNam e.trim().t oLowerCase (); | |
56 | ||
57 | if(o sName.star tsWith("wi ndows")) / /$NON-NLS- 1$ | |
58 | return new Windo wsDiskSpac eMonitor() ; | |
59 | ||
60 | retu rn null; | |
61 | } | |
62 | ||
63 | pr ivate Driv eStatistic s[] driveS tatistics; | |
64 | ||
65 | @O verride | |
66 | pu blic void run() | |
67 | { | |
68 | logg er.traceEn try("run") ; | |
69 | acqu ireDriveSt atistics() ; | |
70 | eval uateListen erLimits() ; | |
71 | logg er.traceEx it("run"); | |
72 | } | |
73 | ||
74 | /* * | |
75 | * | |
76 | * / | |
77 | pr ivate void acquireDr iveStatist ics() | |
78 | { | |
79 | logg er.traceEn try("acqui reDriverSt atistics") ; | |
80 | try | |
81 | { | |
82 | char[] driveLett ers = getD riveRoots( ); | |
83 | driveS tatistics = new Driv eStatistic s[driveLet ters == nu ll ? 0 : d riveLetter s.length]; | |
84 | ||
85 | for(in t index=0; index < d riveLetter s.length; ++index) | |
86 | driveSta tistics[in dex] = get DriveStati stics(driv eLetters[i ndex]); | |
87 | } | |
88 | catc h (Excepti on x) | |
89 | { | |
90 | x.prin tStackTrac e(); | |
91 | } | |
92 | logg er.traceEx it("acquir eDriverSta tistics"); | |
93 | } | |
94 | ||
95 | /* * | |
96 | * | |
97 | * / | |
98 | pr ivate Map< DriveLimit , DriveSpa ceMonitorL istener> l isteners = new HashM ap<DriveLi mit, Drive SpaceMonit orListener >(); | |
99 | ||
100 | pu blic void addListene r(DriveLim it limit, DriveSpace MonitorLis tener list ener) | |
101 | { | |
102 | sync hronized(l isteners) | |
103 | { | |
104 | listen ers.put(li mit, liste ner); | |
105 | } | |
106 | } | |
107 | ||
108 | /* * | |
109 | * Add a col lection of drice lim it notific ations wit h a single listener | |
110 | * | |
111 | * @param re questedNot ifications | |
112 | * @param no tifier | |
113 | * / | |
114 | pu blic void addListene r(Collecti on<DriveLi mit> reque stedNotifi cations, D riveSpaceM onitorList ener liste ner) | |
115 | { | |
116 | sync hronized(l isteners) | |
117 | { | |
118 | for( D riveLimit driveLimit : request edNotifica tions ) | |
119 | addListe ner(driveL imit, list ener); | |
120 | } | |
121 | } | |
122 | ||
123 | pu blic void removeList ener(Drive Limit limi t) | |
124 | { | |
125 | sync hronized(l isteners) | |
126 | { | |
127 | listen ers.remove (limit); | |
128 | } | |
129 | } | |
130 | ||
131 | pr ivate void evaluateL istenerLim its() | |
132 | { | |
133 | sync hronized(l isteners) | |
134 | { | |
135 | if(lis teners != null && li steners.si ze() > 0 & & this.dri veStatisti cs != null && this.d riveStatis tics.lengt h > 0) | |
136 | for(Driv eLimit lim it : liste ners.keySe t() ) | |
137 | for(DriveS tatistics stats : th is.driveSt atistics) | |
138 | if ( limit.is OutOfLimit (stats) ) | |
139 | noti fyListener (listeners .get(limit ), limit, stats); | |
140 | } | |
141 | } | |
142 | ||
143 | /* * | |
144 | * Notify a listener t hat a Limi t has been exceeded. | |
145 | * | |
146 | * @param li stener | |
147 | * @param li mit | |
148 | * @param st ats | |
149 | * / | |
150 | pr ivate void notifyLis tener(Driv eSpaceMoni torListene r listener , DriveLim it limit, DriveStati stics stat s) | |
151 | { | |
152 | list ener.limit ExceededNo tification (limit, st ats); | |
153 | } | |
154 | ||
155 | pu blic abstr act char[] getDriveR oots() | |
156 | th rows Excep tion; | |
157 | ||
158 | pu blic abstr act DriveS tatistics getDriveSt atistics(c har drive) | |
159 | th rows Excep tion; | |
160 | ||
161 | pu blic Drive Statistics getDriveS tatistics( ) | |
162 | th rows Excep tion | |
163 | { | |
164 | retu rn getDriv eStatistic s(getDrive Roots()[0] ); | |
165 | } | |
166 | ||
167 | pu blic stati c class Wi ndowsDiskS paceMonito r | |
168 | ex tends Driv eSpaceMoni tor | |
169 | { | |
170 | stat ic final S tring driv eListingCo mmand = "f sutil fsin fo drives" ; //$NON-N LS-1$ | |
171 | stat ic final S tring free SpaceComma nd = "fsut il fsinfo ntfsinfo " ; // c oncatenate drive let ter and a colon //$N ON-NLS-1$ | |
172 | ||
173 | publ ic char[] getDriveRo ots() | |
174 | thro ws Excepti on | |
175 | { | |
176 | Proces s p = Runt ime.getRun time().exe c(driveLis tingComman d); | |
177 | InputS tream inSt ream = new BufferedI nputStream ( p.getInp utStream() ); | |
178 | LineNu mberReader reader = new LineNu mberReader (new Input StreamRead er(inStrea m)); | |
179 | for(St ring line = reader.r eadLine(); line != n ull; line = reader.r eadLine() ) | |
180 | { | |
181 | line = l ine.trim() .toUpperCa se(); | |
182 | if( line .startsWit h("DRIVES: ") ) //$NO N-NLS-1$ | |
183 | { | |
184 | for(int in dex=0; ind ex < line. length(); ++index) | |
185 | Sy stem.out.p rint("0x00 " + line.c harAt(inde x) + "(" + Integer.t oHexString ((int)line .charAt(in dex)) + ") \t"); //$N ON-NLS-1$ //$NON-NLS -2$ //$NON -NLS-3$ | |
186 | System.out .println() ; | |
187 | ||
188 | String[] l ineElement s = line.s plit("[ \t \0x00]"); //$NON-NL S-1$ | |
189 | char[] dri ves = new char[lineE lements.le ngth-1]; | |
190 | for(int in dex=1; ind ex < lineE lements.le ngth; ++in dex) | |
191 | dr ives[index -1] = line Elements[i ndex].char At(0); | |
192 | ||
193 | return dri ves; | |
194 | } | |
195 | } | |
196 | return null; | |
197 | } | |
198 | ||
199 | publ ic DriveSt atistics g etDriveSta tistics(ch ar drive) | |
200 | thro ws Excepti on | |
201 | { | |
202 | long t otalCluste rs = 0L; | |
203 | long f reeCluster s = 0L; | |
204 | long b ytesPerClu ster = 0L; | |
205 | ||
206 | Proces s p = Runt ime.getRun time().exe c(freeSpac eCommand + drive + " :"); //$NO N-NLS-1$ | |
207 | InputS tream inSt ream = new BufferedI nputStream ( p.getInp utStream() ); | |
208 | LineNu mberReader reader = new LineNu mberReader (new Input StreamRead er(inStrea m)); | |
209 | for(St ring line = reader.r eadLine(); line != n ull; line = reader.r eadLine() ) | |
210 | { | |
211 | line = l ine.trim() .toUpperCa se(); | |
212 | if(line. startsWith ("TOTAL CL USTERS")) //$NON-NLS -1$ | |
213 | { | |
214 | String[] l ineElement s = line.s plit("[ \t ]"); //$NO N-NLS-1$ | |
215 | String num ber = line Elements[l ineElement s.length-1 ]; | |
216 | totalClust ers = pars eNumeric(n umber); | |
217 | } | |
218 | if(line. startsWith ("FREE CLU STERS")) / /$NON-NLS- 1$ | |
219 | { | |
220 | String[] l ineElement s = line.s plit("[ \t ]"); //$NO N-NLS-1$ | |
221 | String num ber = line Elements[l ineElement s.length-1 ]; | |
222 | freeCluste rs = parse Numeric(nu mber); | |
223 | } | |
224 | if(line. startsWith ("BYTES PE R CLUSTER" )) //$NON- NLS-1$ | |
225 | { | |
226 | String[] l ineElement s = line.s plit("[ \t ]"); //$NO N-NLS-1$ | |
227 | String num ber = line Elements[l ineElement s.length-1 ]; | |
228 | bytesPerCl uster = pa rseNumeric (number); | |
229 | } | |
230 | } | |
231 | ||
232 | return new Drive Statistics (String.va lueOf(driv e), freeCl usters * b ytesPerClu ster, tota lClusters * bytesPer Cluster); | |
233 | } | |
234 | ||
235 | /** | |
236 | * | |
237 | * @ param nume ric | |
238 | * @ return | |
239 | */ | |
240 | publ ic long pa rseNumeric (String nu meric) | |
241 | { | |
242 | long r esult; | |
243 | ||
244 | if(num eric.toLow erCase().s tartsWith( "0x")) //$ NON-NLS-1$ | |
245 | result = Long.pars eLong(nume ric.substr ing(2), 16 ); | |
246 | else | |
247 | result = Long.pars eLong(nume ric); | |
248 | ||
249 | return result; | |
250 | } | |
251 | } | |
252 | ||
253 | pu blic stati c void mai n(String[] argv) | |
254 | { | |
255 | Driv eSpaceMoni tor monito r = create OSSpecific Monitor(); | |
256 | moni tor.acquir eDriveStat istics(); | |
257 | } | |
258 | ||
259 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.