View Javadoc
1   package info.mikethomas.fahview.v6project.model;
2   
3   /*
4    * #%L
5    * This file is part of FAHView-v6project.
6    * %%
7    * Copyright (C) 2011 - 2017 Mike Thomas <mikepthomas@outlook.com>
8    * %%
9    * FAHView is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as published by
11   * the Free Software Foundation, either version 3 of the License, or
12   * (at your option) any later version.
13   * %
14   * FAHView is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * %
19   * You should have received a copy of the GNU General Public License
20   * along with FAHView.  If not, see <http://www.gnu.org/licenses/>.
21   * #L%
22   */
23  
24  import info.mikethomas.fahview.v6project.utilities.QueueReader;
25  import java.net.Inet4Address;
26  import java.net.MalformedURLException;
27  import java.net.URL;
28  import java.net.UnknownHostException;
29  import java.util.Date;
30  import java.util.logging.Level;
31  import java.util.logging.Logger;
32  
33  /**
34   * Class to represent data stored about a Folding@home queue index.
35   *
36   * @author <a href="mailto:mikepthomas@outlook.com">Michael Thomas</a>
37   * @version 6.00
38   */
39  public class QueueIndexImpl implements QueueIndex {
40  
41      private int stat; // Status
42      private int z004; // Pad for Windows, others as of v4.01, as of v6.01 number of SMP Cores to use (LE)
43      private Date tdata; // Time data (epoch 0000 1jan00 UTC)
44      private int ustat; // Upload status
45      private URL url; // Web address for core downloads
46      private int m176; // Misc1a
47      private Core core; // Core_xx number (hex)
48      private int m184; // Misc1b
49      private int dsiz; // wudata_xx.dat file size
50      private byte[] z192; // z192
51      private WorkUnitImpl wuid;
52      private byte[] z224;
53      private int mid; // Machine ID (LE or BE, was only LE before v5 work servers)
54      private Inet4Address svr2; // Server IP address
55      private int port; // Server port number
56      private String type; // Work unit type
57      private String uname; // User Name
58      private int teamn; // Team Number
59      private long uid; // Stored ID for unit (UserID + MachineID) (LE or BE, usually BE, always BE for v5 work servers)
60      private int bench; // Benchmark (as of v3.24) (LE)
61      private int m476; // Misc3b (unused as of v3.24) (LE); Benchmark (as of v5.00) (BE)
62      private int cpu_type; // CPU type (LE or BE, sometimes 0) since 3.00
63      private int os_type; // OS type (LE or BE, sometimes 0) since 3.00
64      private int cpu_spec; // CPU species (LE or BE, sometimes 0) since 3.00
65      private int os_spec; // OS species (LE or BE, sometimes 0) since 3.00
66      private Date expire; // Allowed time to return (seconds)
67      private byte[] z500;
68      private int cltype; // Client type required (usually 0) (LE or BE)
69      private boolean aiflag; // Assignment info present flag (LE or BE)
70      private Date aitime; // Assignment timestamp (LE or BE)
71      private long aidata; // Assignment info (LE or BE)
72      private Inet4Address csip; // Collection server IP address (as of v5.00) (LE)
73      private Date dstart; // Download started time (as of v5.00) (BE)
74      private byte[] z528;
75      private int m532; // Misc4a (LE or BE)
76      private byte[] z536;
77      private int cores; // Number of SMP cores (as of v5.91) (BE)
78      private String tag; // Tag of Work Unit (as of v5.00)
79      private byte[] z564;
80      private String passkey; // Passkey (as of v6.00)
81      private int flops; // Flops per CPU (core) (as of v6.00) (BE)
82      private int memory; // Available memory (as of v6.00) (BE)
83      private int gpu_memory; // Available GPU memory (as of v6.20) (LE)
84      private byte[] z624;
85      private Date due; // WU expiration time
86      private int plimit; // Packet size limit (as of v5.00)
87      private int uploads; // Number of upload failures (as of v5.00)
88      
89      private int indexNumber, position;
90      private QueueReader reader;
91  
92      /**
93       * <p>Constructor for QueueIndexImpl.</p>
94       *
95       * @param indexNumber a int.
96       * @param reader a {@link info.mikethomas.fahview.v6project.utilities.QueueReader} object.
97       * @throws java.lang.InstantiationException if any.
98       */
99      public QueueIndexImpl(int indexNumber, QueueReader reader) throws InstantiationException {
100         this.indexNumber = indexNumber;
101         switch (indexNumber) {
102             case 0:
103                 position = QueueImpl.QUEUE_INDEX_0_POS;
104                 break;
105             case 1:
106                 position = QueueImpl.QUEUE_INDEX_1_POS;
107                 break;
108             case 2:
109                 position = QueueImpl.QUEUE_INDEX_2_POS;
110                 break;
111             case 3:
112                 position = QueueImpl.QUEUE_INDEX_3_POS;
113                 break;
114             case 4:
115                 position = QueueImpl.QUEUE_INDEX_4_POS;
116                 break;
117             case 5:
118                 position = QueueImpl.QUEUE_INDEX_5_POS;
119                 break;
120             case 6:
121                 position = QueueImpl.QUEUE_INDEX_6_POS;
122                 break;
123             case 7:
124                 position = QueueImpl.QUEUE_INDEX_7_POS;
125                 break;
126             case 8:
127                 position = QueueImpl.QUEUE_INDEX_8_POS;
128                 break;
129             case 9:
130                 position = QueueImpl.QUEUE_INDEX_9_POS;
131                 break;
132             default:
133                 throw new InstantiationException("Queue index should be 0-9.");
134         }
135         this.reader = reader;
136         update();
137     }
138 
139     /** {@inheritDoc} */
140     @Override
141     public int getStat() {
142         return stat;
143     }
144 
145     /** {@inheritDoc} */
146     @Override
147     public Date getTdata() {
148         return tdata;
149     }
150 
151     /** {@inheritDoc} */
152     @Override
153     public Inet4Address getSvr1() {
154         throw new UnsupportedOperationException("svr1 replaced by svr2.");
155     }
156 
157     /** {@inheritDoc} */
158     @Override
159     public int getUstat() {
160         return ustat;
161     }
162 
163     /** {@inheritDoc} */
164     @Override
165     public URL getUrl() {
166         return url;
167     }
168 
169     /** {@inheritDoc} */
170     @Override
171     public Core getCore() {
172         return core;
173     }
174 
175     /** {@inheritDoc} */
176     @Override
177     public int getDsiz() {
178         return dsiz;
179     }
180 
181     /** {@inheritDoc} */
182     @Override
183     public WorkUnitImpl getWuid() {
184         return wuid;
185     }
186 
187     /** {@inheritDoc} */
188     @Override
189     public int getMid() {
190         throw new UnsupportedOperationException("Not supported yet.");
191     }
192 
193     /** {@inheritDoc} */
194     @Override
195     public Inet4Address getSvr2() {
196         return svr2;
197     }
198 
199     /** {@inheritDoc} */
200     @Override
201     public int getPort() {
202         return port;
203     }
204 
205     /** {@inheritDoc} */
206     @Override
207     public String getType() {
208         return type;
209     }
210 
211     /** {@inheritDoc} */
212     @Override
213     public String getUname() {
214         return uname;
215     }
216 
217     /** {@inheritDoc} */
218     @Override
219     public int getTeamn() {
220         return teamn;
221     }
222 
223     /** {@inheritDoc} */
224     @Override
225     public long getUid() {
226         throw new UnsupportedOperationException("Not supported yet.");
227     }
228 
229     /** {@inheritDoc} */
230     @Override
231     public int getBench() {
232         throw new UnsupportedOperationException("Not supported yet.");
233     }
234 
235     /** {@inheritDoc} */
236     @Override
237     public String getCpuType() {
238         String cpu = null;
239         switch (cpu_type) {
240             case 100000:
241                 cpu = "x86";
242                 break;
243             case 100085:
244                 cpu = "x86";
245                 break;
246             case 100086:
247                 cpu = "i86";
248                 break;
249             case 100087:
250                 cpu = "Pentium IV";
251                 break;
252             case 100186:
253                 cpu = "i186";
254                 break;
255             case 100286:
256                 cpu = "i286";
257                 break;
258             case 100386:
259                 cpu = "i386";
260                 break;
261             case 100486:
262                 cpu = "i486";
263                 break;
264             case 100586:
265                 cpu = "Pentium";
266                 break;
267             case 100587:
268                 cpu = "Pentium MMX";
269                 break;
270             case 100686:
271                 cpu = "Pentium Pro";
272                 break;
273             case 100687:
274                 cpu = "Pentium II/III";
275                 break;
276             case 101000:
277                 cpu = "Cyrix x86";
278                 break;
279             case 102000:
280                 cpu = "AMD x86";
281                 break;
282             case 200000:
283                 cpu = "PowerPC";
284                 break;
285             case 1100000:
286                 cpu = "IA64";
287                 break;
288             case 1600000:
289                 cpu = "AMD64";
290                 break;
291             default:
292                 cpu = "Unknown";
293                 break;
294         }
295         return cpu;
296     }
297 
298     /** {@inheritDoc} */
299     @Override
300     public String getOsType() {
301         String os = null;
302         switch (os_type) {
303             case 100000:
304                 os = "Windows";
305                 break;
306             case 100001:
307                 os = "Win95";
308                 break;
309             case 100002:
310                 os = "Win95_OSR2";
311                 break;
312             case 100003:
313                 os = "Win98";
314                 break;
315             case 100004:
316                 os = "Win98SE";
317                 break;
318             case 100005:
319                 os = "WinME";
320                 break;
321             case 100006:
322                 os = "WinNT";
323                 break;
324             case 100007:
325                 os = "Win2K";
326                 break;
327             case 100008:
328                 os = "WinXP";
329                 break;
330             case 100009:
331                 os = "Win2K3";
332                 break;
333             case 200000:
334                 os = "MacOS";
335                 break;
336             case 300000:
337                 os = "OSX";
338                 break;
339             case 400000:
340                 os = "Linux";
341                 break;
342             case 700000:
343                 os = "FreeBSD";
344                 break;
345             case 800000:
346                 os = "OpenBSD";
347                 break;
348             case 1800000:
349                 os = "Win64";
350                 break;
351             case 1900000:
352                 os = "OS2";
353                 break;
354             default:
355                 os = "Unknown";
356                 break;
357         }
358         return os;
359     }
360 
361     /** {@inheritDoc} */
362     @Override
363     public String getCpuSpec() {
364         throw new UnsupportedOperationException("Not supported yet.");
365     }
366 
367     /** {@inheritDoc} */
368     @Override
369     public String getOsSpec() {
370         throw new UnsupportedOperationException("Not supported yet.");
371     }
372 
373     /** {@inheritDoc} */
374     @Override
375     public Date getExpire() {
376         throw new UnsupportedOperationException("Not supported yet.");
377     }
378 
379     /** {@inheritDoc} */
380     @Override
381     public int getCltype() {
382         throw new UnsupportedOperationException("Not supported yet.");
383     }
384 
385     /** {@inheritDoc} */
386     @Override
387     public boolean getAiflag() {
388         throw new UnsupportedOperationException("Not supported yet.");
389     }
390 
391     /** {@inheritDoc} */
392     @Override
393     public Date getAitime() {
394         throw new UnsupportedOperationException("Not supported yet.");
395     }
396 
397     /** {@inheritDoc} */
398     @Override
399     public long getAidata() {
400         throw new UnsupportedOperationException("Not supported yet.");
401     }
402 
403     /** {@inheritDoc} */
404     @Override
405     public Inet4Address getCsip() {
406         return csip;
407     }
408 
409     /** {@inheritDoc} */
410     @Override
411     public Date getDstart() {
412         throw new UnsupportedOperationException("Not supported yet.");
413     }
414 
415     /** {@inheritDoc} */
416     @Override
417     public int getCores() {
418         return cores;
419     }
420 
421     /** {@inheritDoc} */
422     @Override
423     public String getTag() {
424         return tag;
425     }
426 
427     /** {@inheritDoc} */
428     @Override
429     public String getPasskey() {
430         return passkey;
431     }
432 
433     /** {@inheritDoc} */
434     @Override
435     public int getFlops() {
436         throw new UnsupportedOperationException("Not supported yet.");
437     }
438 
439     /** {@inheritDoc} */
440     @Override
441     public int getMemory() {
442         return memory;
443     }
444 
445     /** {@inheritDoc} */
446     @Override
447     public int getGpuMemory() {
448         throw new UnsupportedOperationException("Not supported yet.");
449     }
450 
451     /** {@inheritDoc} */
452     @Override
453     public Date getDue() {
454         throw new UnsupportedOperationException("Not supported yet.");
455     }
456 
457     /** {@inheritDoc} */
458     @Override
459     public int getPlimit() {
460         throw new UnsupportedOperationException("Not supported yet.");
461     }
462 
463     /** {@inheritDoc} */
464     @Override
465     public int getUploads() {
466         throw new UnsupportedOperationException("Not supported yet.");
467     }
468 
469     /**
470      * Status Mutator
471      */
472     protected void setStat() {
473         stat = (int) reader.readLEUInt(STAT_POS + position, STAT_LENGTH);
474     }
475 
476     /**
477      * Set the value of Time data
478      */
479     protected void setTdata() {
480         throw new UnsupportedOperationException("Not supported yet.");
481     }
482 
483     /**
484      * Set the value of Upload status
485      */
486     protected void setUstat() {
487         throw new UnsupportedOperationException("Not supported yet.");
488     }
489 
490     /**
491      * Set the value of Web address for core download
492      */
493     protected void setUrl() {
494         try {
495             url = new URL("http://" + reader.readString(URL_POS + position, URL_LENGTH));
496         }
497         catch (MalformedURLException ex) {
498             Logger.getLogger(QueueIndexImpl.class.getName()).log(Level.SEVERE, null, ex);
499         }
500     }
501 
502     /**
503      * Set the value of Core_xx number (hex)
504      */
505     protected void setCore() {
506         try {
507             core = new Core(indexNumber, reader);
508         }
509         catch (InstantiationException ex) {
510             Logger.getLogger(QueueIndexImpl.class.getName()).log(Level.SEVERE, null, ex);
511         }
512     }
513 
514     /**
515      * Set the value of wudata_xx.dat file size
516      */
517     protected void setDsiz() {
518         dsiz = (int) reader.readLEUInt(DSIZ_POS + position, DSIZ_LENGTH);
519     }
520 
521     /**
522      * <p>Setter for the field <code>wuid</code>.</p>
523      */
524     protected void setWuid() {
525         try {
526             wuid = new WorkUnitImpl(indexNumber, reader);
527         }
528         catch (InstantiationException ex) {
529             Logger.getLogger(QueueIndexImpl.class.getName()).log(Level.SEVERE, null, ex);
530         }
531     }
532 
533     /**
534      * <p>Setter for the field <code>mid</code>.</p>
535      */
536     protected void setMid() {
537         throw new UnsupportedOperationException("Not supported yet.");
538     }
539 
540     /**
541      * <p>Setter for the field <code>svr2</code>.</p>
542      */
543     protected void setSvr2() {
544         try {
545             svr2 = (Inet4Address) Inet4Address.getByAddress(reader.readIP(SVR2_POS + position));
546         }
547         catch (UnknownHostException ex) {
548             Logger.getLogger(QueueIndexImpl.class.getName()).log(Level.SEVERE, null, ex);
549         }
550     }
551 
552     /**
553      * <p>Setter for the field <code>port</code>.</p>
554      */
555     protected void setPort() {
556         port = (int) reader.readLEUInt(PORT_POS + position, PORT_LENGTH);
557     }
558 
559     /**
560      * <p>Setter for the field <code>type</code>.</p>
561      */
562     protected void setType() {
563         type = reader.readString(TYPE_POS + position, TYPE_LENGTH);
564     }
565 
566     /**
567      * <p>Setter for the field <code>uname</code>.</p>
568      */
569     protected void setUname() {
570         uname = reader.readString(UNAME_POS + position, UNAME_LENGTH);
571     }
572 
573     /**
574      * <p>Setter for the field <code>teamn</code>.</p>
575      */
576     protected void setTeamn() {
577         teamn = Integer.valueOf(reader.readString(TEAMN_POS + position, TEAMN_LENGTH));
578     }
579 
580     /**
581      * <p>setUID.</p>
582      */
583     protected void setUID() {
584         throw new UnsupportedOperationException("Not supported yet.");
585     }
586 
587     /**
588      * <p>Setter for the field <code>bench</code>.</p>
589      */
590     protected void setBench() {
591         throw new UnsupportedOperationException("Not supported yet.");
592     }
593 
594     /**
595      * <p>setCpuType.</p>
596      */
597     protected void setCpuType() {
598         throw new UnsupportedOperationException("Not supported yet.");
599     }
600 
601     /**
602      * <p>setOsType.</p>
603      */
604     protected void setOsType() {
605         throw new UnsupportedOperationException("Not supported yet.");
606     }
607 
608     /**
609      * <p>setCpuSpec.</p>
610      */
611     protected void setCpuSpec() {
612         throw new UnsupportedOperationException("Not supported yet.");
613     }
614 
615     /**
616      * <p>setOsSpec.</p>
617      */
618     protected void setOsSpec() {
619         throw new UnsupportedOperationException("Not supported yet.");
620     }
621 
622     /**
623      * <p>Setter for the field <code>expire</code>.</p>
624      */
625     protected void setExpire() {
626         throw new UnsupportedOperationException("Not supported yet.");
627     }
628 
629     /**
630      * <p>Setter for the field <code>cltype</code>.</p>
631      */
632     protected void setCltype() {
633         throw new UnsupportedOperationException("Not supported yet.");
634     }
635 
636     /**
637      * <p>Setter for the field <code>aiflag</code>.</p>
638      */
639     protected void setAiflag() {
640         throw new UnsupportedOperationException("Not supported yet.");
641     }
642 
643     /**
644      * <p>Setter for the field <code>aitime</code>.</p>
645      */
646     protected void setAitime() {
647         throw new UnsupportedOperationException("Not supported yet.");
648     }
649 
650     /**
651      * <p>Setter for the field <code>aidata</code>.</p>
652      */
653     protected void setAidata() {
654         throw new UnsupportedOperationException("Not supported yet.");
655     }
656 
657     /**
658      * <p>Setter for the field <code>csip</code>.</p>
659      */
660     protected void setCsip() {
661         try {
662             csip = (Inet4Address) Inet4Address.getByAddress(reader.readIP(CSIP_POS + position));
663         }
664         catch (UnknownHostException ex) {
665             Logger.getLogger(QueueIndexImpl.class.getName()).log(Level.SEVERE, null, ex);
666         }
667     }
668 
669     /**
670      * <p>Setter for the field <code>dstart</code>.</p>
671      */
672     protected void setDstart() {
673         throw new UnsupportedOperationException("Not supported yet.");
674     }
675 
676     /**
677      * <p>Setter for the field <code>cores</code>.</p>
678      */
679     protected void setCores() {
680         cores = (int) reader.readLEUInt(CORES_POS + position, CORES_LENGTH);
681     }
682 
683     /**
684      * <p>Setter for the field <code>tag</code>.</p>
685      */
686     protected void setTag() {
687         tag = reader.readString(TAG_POS + position, TAG_LENGTH);
688     }
689 
690     /**
691      * <p>Setter for the field <code>passkey</code>.</p>
692      */
693     protected void setPasskey() {
694         passkey = reader.readString(PASSKEY_POS + position, PASSKEY_LENGTH);
695     }
696 
697     /**
698      * <p>Setter for the field <code>flops</code>.</p>
699      */
700     protected void setFlops() {
701         throw new UnsupportedOperationException("Not supported yet.");
702     }
703 
704     /**
705      * <p>Setter for the field <code>memory</code>.</p>
706      */
707     protected void setMemory() {
708         memory = (int) reader.readBEUInt(MEMORY_POS + position, MEMORY_LENGTH);
709     }
710 
711     /**
712      * <p>setGpuMemory.</p>
713      */
714     protected void setGpuMemory() {
715         throw new UnsupportedOperationException("Not supported yet.");
716     }
717 
718     /**
719      * <p>Setter for the field <code>due</code>.</p>
720      */
721     protected void setDue() {
722         throw new UnsupportedOperationException("Not supported yet.");
723     }
724 
725     /**
726      * <p>Setter for the field <code>plimit</code>.</p>
727      */
728     protected void setPlimit() {
729         throw new UnsupportedOperationException("Not supported yet.");
730     }
731 
732     /**
733      * <p>Setter for the field <code>uploads</code>.</p>
734      */
735     protected void setUploads() {
736         throw new UnsupportedOperationException("Not supported yet.");
737     }
738 
739     /**
740      * {@inheritDoc}
741      *
742      * Generate a String representation of the QueueImpl
743      */
744     @Override
745     public String toString() {
746         String result = "";
747         result += "queue.index[" + indexNumber + "].stat\t" + getStat();
748         result += "\nqueue.index[" + indexNumber + "].url\t" + getUrl();
749         result += "\n" + getCore();
750         result += "\nqueue.index[" + indexNumber + "].dsiz\t" + getDsiz();
751         result += "\n" + getWuid();
752         result += "\nqueue.index[" + indexNumber + "].svr2\t" + getSvr2();
753         result += "\nqueue.index[" + indexNumber + "].port\t" + getPort();
754         result += "\nqueue.index[" + indexNumber + "].type\t" + getType();
755         result += "\nqueue.index[" + indexNumber + "].uname\t" + getUname();
756         result += "\nqueue.index[" + indexNumber + "].teamn\t" + getTeamn();
757         result += "\nqueue.index[" + indexNumber + "].csip\t" + getCsip();
758         result += "\nqueue.index[" + indexNumber + "].cores\t" + getCores();
759         result += "\nqueue.index[" + indexNumber + "].tag\t" + getTag();
760         result += "\nqueue.index[" + indexNumber + "].passkey\t" + getPasskey();
761         result += "\nqueue.index[" + indexNumber + "].memory\t" + getMemory();
762         return result;
763     }
764 
765     /** {@inheritDoc} */
766     @Override
767     public final void update() {
768         setStat();
769         setUrl();
770         setCore();
771         setDsiz();
772         setWuid();
773         setSvr2();
774         setPort();
775         setType();
776         setUname();
777         setTeamn();
778         setCsip();
779         setCores();
780         setTag();
781         setPasskey();
782         setMemory();
783     }
784 }