Class ActiveAppBeacon

java.lang.Object
org.mbari.jcommons.util.ActiveAppBeacon

public class ActiveAppBeacon extends Object
ActiveAppBeacon is a beacon that can be attached to a port and will ping a message when any application connects to that port. It's useful for letting other apps know that a particular app is already running.

The beacon accepts a collection of ports to attempt to connect to and will open a ServerSocket on the first port in the collection that is available.

Example usage:

  // --- Shared properties both the beacon and pinger will need
  // These are the potential ports the beacon could be on.
  var BEACON_PORTS = Lists.newArrayList(4002, 4121, 5097, 6238, 6609,
          7407, 8169, 9069, 9669, 16569);
  // The unique-ish message that the that is checked for by the pinger.
  String BEACON_MESSAGE = "My Awesome App";

  // Create a beacon
  ActiveAppBeacon beacon = new ActiveAppBeacon(BEACON_PORTS, BEACON_MESSAGE);

  // Another app can check for the existence of the beacon on the same computer using:
  boolean beaconExists = ActiveAppPinger.pingAll(BEACON_PORTS, BEACON_MESSAGE);

  // You can terminate a beacon at any time using:
  beacon.kill();

 
Created by brian on 6/17/14.
  • Field Details

    • MIN_PORT_NUMBER

      public static final int MIN_PORT_NUMBER
      The minimum number of server port number.
      See Also:
    • MAX_PORT_NUMBER

      public static final int MAX_PORT_NUMBER
      The maximum number of server port number.
      See Also:
  • Constructor Details

  • Method Details

    • kill

      public void kill()
    • available

      public static boolean available(int port)
      Checks to see if a specific port is available.
      Parameters:
      port - the port to check for availability
    • isAlive

      public boolean isAlive()