comparison src/org/dancres/blitz/stats/HostStat.java @ 0:3dc0c5604566

Initial checkin of blitz 2.0 fcs - no installer yet.
author Dan Creswell <dan.creswell@gmail.com>
date Sat, 21 Mar 2009 11:00:06 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3dc0c5604566
1 package org.dancres.blitz.stats;
2
3 import java.net.InetAddress;
4 import java.net.NetworkInterface;
5
6 import java.util.ArrayList;
7 import java.util.Enumeration;
8
9 /**
10 <p>Provides information about the host on which this Blitz instance is
11 running.</p>
12 */
13 public class HostStat implements Stat, StatGenerator {
14 private long theId = StatGenerator.UNSET_ID;
15
16 private InetAddress[] theHostAddrs;
17 private InetAddress theHostAddr;
18
19 HostStat() {
20 try {
21 ArrayList myAllAddrs = new ArrayList();
22
23 Enumeration myIfs = NetworkInterface.getNetworkInterfaces();
24
25 while(myIfs.hasMoreElements()) {
26 NetworkInterface myIf = (NetworkInterface) myIfs.nextElement();
27
28 Enumeration myAddrs = myIf.getInetAddresses();
29 while (myAddrs.hasMoreElements()) {
30 InetAddress myAddr = (InetAddress) myAddrs.nextElement();
31
32 myAllAddrs.add(myAddr);
33 }
34 }
35
36 theHostAddrs = new InetAddress[myAllAddrs.size()];
37 theHostAddrs = (InetAddress[]) myAllAddrs.toArray(theHostAddrs);
38
39 theHostAddr = InetAddress.getLocalHost();
40 } catch (Exception anE) {
41 // Nothing to be done....
42 }
43 }
44
45 HostStat(long anId, InetAddress anAddr, InetAddress[] anAddrs) {
46 theId = anId;
47 theHostAddr = anAddr;
48 theHostAddrs = anAddrs;
49 }
50
51 public void setId(long anId) {
52 theId = anId;
53 }
54
55 public long getId() {
56 return theId;
57 }
58
59 public InetAddress getHostAddr() {
60 return theHostAddr;
61 }
62
63 public InetAddress[] getAllAddr() {
64 return theHostAddrs;
65 }
66
67 public synchronized Stat generate() {
68 HostStat myStat = new HostStat(theId,
69 theHostAddr,
70 theHostAddrs);
71 return myStat;
72 }
73
74 public String toString() {
75 return theHostAddr.getHostName() + "[" +
76 theHostAddr.getHostAddress() + "]";
77 }
78 }