diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/dancres/blitz/stats/HostStat.java	Sat Mar 21 11:00:06 2009 +0000
@@ -0,0 +1,78 @@
+package org.dancres.blitz.stats;
+
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+
+/**
+   <p>Provides information about the host on which this Blitz instance is
+   running.</p>
+ */
+public class HostStat implements Stat, StatGenerator {
+    private long theId = StatGenerator.UNSET_ID;
+
+    private InetAddress[] theHostAddrs;
+    private InetAddress theHostAddr;
+
+    HostStat() {
+        try {
+            ArrayList myAllAddrs = new ArrayList();
+
+            Enumeration myIfs = NetworkInterface.getNetworkInterfaces();
+
+            while(myIfs.hasMoreElements()) {
+                NetworkInterface myIf = (NetworkInterface) myIfs.nextElement();
+
+                Enumeration myAddrs = myIf.getInetAddresses();
+                while (myAddrs.hasMoreElements()) {
+                    InetAddress myAddr = (InetAddress) myAddrs.nextElement();
+
+                    myAllAddrs.add(myAddr);
+                }
+            }
+
+            theHostAddrs = new InetAddress[myAllAddrs.size()];
+            theHostAddrs = (InetAddress[]) myAllAddrs.toArray(theHostAddrs);
+
+            theHostAddr = InetAddress.getLocalHost();
+        } catch (Exception anE) {
+            // Nothing to be done....
+        }
+    }
+
+    HostStat(long anId, InetAddress anAddr, InetAddress[] anAddrs) {
+        theId = anId;
+        theHostAddr = anAddr;
+        theHostAddrs = anAddrs;
+    }
+
+    public void setId(long anId) {
+        theId = anId;
+    }
+
+    public long getId() {
+        return theId;
+    }
+
+    public InetAddress getHostAddr() {
+        return theHostAddr;
+    }
+
+    public InetAddress[] getAllAddr() {
+        return theHostAddrs;
+    }
+
+    public synchronized Stat generate() {
+        HostStat myStat = new HostStat(theId, 
+                                       theHostAddr,
+                                       theHostAddrs);
+        return myStat;
+    }
+
+    public String toString() {
+        return theHostAddr.getHostName() + "[" +
+            theHostAddr.getHostAddress() + "]";
+    }
+}