Skip to content

serverSelector package

dosse91 edited this page Sep 25, 2019 · 2 revisions
TestPoint class

Defines a test point where the speedtest can be performed.

Constructors:

public TestPoint(String name, String server, String dlURL, String ulURL, String pingURL, String getIpURL)
  • name: User friendly name (eg. "Milan, Italy")
  • server: URL to the server where LibreSpeed is installed. If it only supports HTTP or HTTPS, specify it; if it supports both, simply use // followed by the address
  • dlURL: Path on your server where the download test can be performed (typically "garbage.php" or "backend/garbage.php")
  • urURL: Path on your server where the upload test can be performed (typically "empty.php" or "backend/empty.php")
  • pingURL: Path on your server where the ping/jitter test can be performed (typically "empty.php" or "backend/empty.php")
  • getIpURL: Path on your server where the IP address and ISP info can be fetched (typically "getIP.php" or "backend/getIP.php")
public TestPoint(JSONObject json)
  • json: JSON object with the same fields as above

The class also has a protected ping field, which is used by ServerSelector. It is initialized at -1, and after running the server selector, it will contain the ping in milliseconds to this test point.

The class provides getters for all fields.

ServerSelector class

Uses several parallel PingStream instances to ping a list of test points and find out which ones are online, and which one has the lowest ping.

This class uses 6 parallel streams (see PARALLELISM), and pings each server up to 3 times (see PINGS); if a ping takes more than 500ms (see SLOW_THRESHOLD), no more pings are done. If a server is offline, its ping field is set to -1, otherwise it will be set to the lowest measured ping for that server. Once all test points have been pinged, the server with the lowest ping is determined and a callback is called.

Constructor:

public ServerSelector(TestPoint[] servers, int timeout)
  • servers: list of servers. More can be added later. If you want to start with an empty list, use new TestPoint[0], not null.
  • timeout: timeout for a ping

Callbacks:

  • onServerSelected(TestPoint server): called at the end of server selection. server is the server with the lowest ping, or null if all test points are offline.

Methods:

  • addTestPoint(TestPoint t) and addTestPoint(JSONObject o): adds a TestPoint to the list of servers
  • addTestPoints(TestPoint[] servers) and addTestPoints(JSONArray a): adds a list of TestPoints to the list of servers
  • getTestPoints(): returns the list of servers as a TestPoint[]
  • start(): starts the server selection process
  • stopASAP(): stops the server selection process as soon as possible
Clone this wiki locally