Advertisement
kendy

OraclePingTarget

Oct 19th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. package OraclePinger;
  2.  
  3. import java.net.InetSocketAddress;
  4. import java.nio.channels.SocketChannel;
  5.  
  6. // Representation of a ping target
  7. //
  8. public class Target {
  9.     InetSocketAddress address;
  10.     SocketChannel channel;
  11.     Exception failure;
  12.     long connectStart;
  13.     long connectFinish = 0;
  14.     public boolean resolved = false;
  15.     //  public boolean timedout = false;
  16.  
  17.     public Target(String host, int port) {
  18.         try { //resolve host address
  19.             address = new InetSocketAddress(host, port);
  20.             resolved = true;
  21.         } catch (Exception x) {
  22.             failure = x;
  23.         }
  24.     }
  25.  
  26.     //  public void timedout() {
  27.     //      if (resolved && connectFinish == 0)
  28.     //          timedout = true;
  29.     //  }
  30.  
  31.     public long time(){
  32.         if(!resolved) //flat graph
  33.             return 0;
  34.         if(resolved && connectFinish==0 /*timedout*/)   // packet lost / etc over max time. /in nanosecs
  35.             return -1;
  36.         return connectFinish-connectStart;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement