public class Skew extends java.lang.Object implements java.util.concurrent.Callable<SkewCorrection>, java.io.Serializable
Callable
object.
As a standalone application it can be invoked with command-line options indicating the local ip address and port and remote ip address and port.
For example, At NODE1:
./skew.sh NODE1:4001 NODE2:4002
./skew.sh NODE2:4002 NODE1:4001
As a Callable
object it can be serialized and
sent to a remote node using an appropriate framework-level transport. The other
node can then deserialize the job and invoke the call()
() method.
A number of short UDP (or TCP) exchanges are sent back and forth between the nodes. Initial exchanges are discarded under the assumption that they may have irregular timing while the dialog is just starting up. This may be due to router path discovery, JVM loading and caching, and OS I/O stack initialization. Packets may also be discarded if the sequencing somehow gets messed up.
By default the latency and clock difference are output to System.out.
Constructor and Description |
---|
Skew(java.net.InetSocketAddress localAddress,
java.net.InetSocketAddress otherNodeAddress)
Constructor for a node.
|
Skew(java.lang.String otherNodeNameOrIPAddress,
int port)
Constructor for a node.
|
Skew(java.lang.String otherNodeNameOrIPAddress,
int listenPort,
int sendPort)
Constructor for a node.
|
Modifier and Type | Method and Description |
---|---|
void |
addSkewCorrectionListener(SkewCorrectionListener listener)
Register a listener to handle the correction
when the calibration exchange and computation is complete.
|
SkewCorrection |
call()
Allows this to be invoked as a
Callable . |
int |
getBufSize() |
double |
getClockDiffMs() |
SkewCorrection |
getCorrection()
Returns the computed correction.
|
double |
getLatencyMs()
Returns the one-way delay.
|
long |
getMillisToWaitForOtherEnd() |
int |
getNumberOfExchangesUsed() |
Skew |
getPeer()
Instantiates and returns an instance of Skew that can be used at
the peer end to talk to this instance.
|
double |
getPingPongBandwidthInBytesPerSecond()
The ping-pong byte bandwidth is "net" in each direction
and includes the effect of latency.
|
boolean |
isTcpReceiver() |
boolean |
isUsingTCP() |
boolean |
isVerbose() |
static void |
main(java.lang.String[] args)
Can be run as a standalone application.
|
void |
removeSkewCorrectionListener(SkewCorrectionListener listener)
Remove a listener .
|
void |
setBufSize(int bufSize)
Set the buffer size for outgoing packets.
|
void |
setMillisToWaitForOtherEnd(long millis)
Set the maximum time to wait for the other end in milliseconds.
|
void |
setTcpReceiver(boolean tcpReceiver) |
void |
setUsingTCP(boolean useTCP)
By default the exchanges are done using UDP.
|
void |
setVerbose(boolean verbose) |
java.util.concurrent.Future<SkewCorrection> |
startInSeparateThread()
Creates a new daemon thread and invokes the call() method.
|
public Skew(java.net.InetSocketAddress localAddress, java.net.InetSocketAddress otherNodeAddress)
localAddress
- otherNodeAddress
- public Skew(java.lang.String otherNodeNameOrIPAddress, int port)
otherNodeNameOrIPAddress
- port
- is used by both the local and remote nodes for send and listenpublic Skew(java.lang.String otherNodeNameOrIPAddress, int listenPort, int sendPort)
otherNodeNameOrIPAddress
- listenPort
- port used to receivesendPort
- port used to send to other endpublic void addSkewCorrectionListener(SkewCorrectionListener listener)
listener
- public SkewCorrection call()
Callable
.
When this object is serialized the two constructor
arguments are serialized as part of the object.
The analysis involves sending a number of short packets back and forth. Most but not all of the packets are used in the analysis. In particular the initial packets are discarded under the assumption that they may have irregular timing while the dialog is just starting up. This may be due to router path discovery, JVM loading and caching, and OS I/O stack initialization. Packets may also be discarded if the sequencing somehow gets messed up.
call
in interface java.util.concurrent.Callable<SkewCorrection>
public int getBufSize()
public double getClockDiffMs()
public SkewCorrection getCorrection()
public double getLatencyMs()
public long getMillisToWaitForOtherEnd()
public int getNumberOfExchangesUsed()
public Skew getPeer()
public double getPingPongBandwidthInBytesPerSecond()
public boolean isTcpReceiver()
public boolean isUsingTCP()
public boolean isVerbose()
public static void main(java.lang.String[] args)
public void removeSkewCorrectionListener(SkewCorrectionListener listener)
listener
- public void setBufSize(int bufSize)
bufSize
- the buffer sizepublic void setMillisToWaitForOtherEnd(long millis)
millis
- time to wait in millisecondspublic void setTcpReceiver(boolean tcpReceiver)
tcpReceiver
- true to get this instance to listen for incoming connectionspublic void setUsingTCP(boolean useTCP)
useTCP
- the useTCP to setpublic void setVerbose(boolean verbose)
verbose
- set false to disable calibration results sent to the console (default is true)public java.util.concurrent.Future<SkewCorrection> startInSeparateThread()