Class Ship

  • All Implemented Interfaces:
    java.lang.AutoCloseable, ShipInterface

    public class Ship
    extends java.lang.Object
    implements ShipInterface, java.lang.AutoCloseable
    • Constructor Detail

      • Ship

        public Ship​(ShipNodeConfiguration nodeConfig,
                    ConnectionHandler connHandler)
        creates a new node on construction
        Parameters:
        nodeConfig - the configuration to be used for the node
        connHandler - connection handler
    • Method Detail

      • openConnection

        public ShipConnectionInterface openConnection​(java.lang.String ipAddr)
        opens a connection to a device/server
        Specified by:
        openConnection in interface ShipInterface
        Parameters:
        ipAddr - the IP address of the device/server to connect to. Example: "127.0.0.1:4059"
        Returns:
        an object representing the connection to the device/server if the connection was successful, else null
      • runConnectionDataPreparation

        public void runConnectionDataPreparation​(ShipConnection connection)
        run the states in connection data preparation, this method is non-blocking and the states will run asynchronously
        Parameters:
        connection - the connection that should run the connection data preparation states
      • getOwnSki

        public java.lang.String getOwnSki()
      • addTrustedSki

        public void addTrustedSki​(java.lang.String ski)
        adding a SKI authenticates the SHIP node using that SKI. The SKI of other SHIP nodes is typically communicated through the ConnectionHandler or manually acquired through ShipConnectionInterface
        Parameters:
        ski - the ski to add to the trusted SKIs
      • removeTrustedSki

        public boolean removeTrustedSki​(java.lang.String ski)
        tries to remove a ski from the trusted SKIs
        Parameters:
        ski - the ski to remove
        Returns:
        true if the ski was removed successfully, otherwise false, for example because the trusted SKI list did not contain the passed ski
      • setAutoAcceptMode

        public void setAutoAcceptMode()
        Sets the node to auto-accept-mode. Authentication can be skipped that way but clients have a time window of 1 to 120 seconds for the connection The default value for the window is 60 seconds. If the time window passed without any client connecting, the auto-accept-mode will be turned off.
      • requestAccessMethods

        public void requestAccessMethods​(ShipConnectionImpl connection)
        Requests the access methods for the communication partner of the specified connection. Can be used for reconnection.
        Parameters:
        connection - the connection to request the access methods for
      • setConnHandler

        public void setConnHandler​(ConnectionHandler connHandler)
        Description copied from interface: ShipInterface
        sets a connection handler
        Specified by:
        setConnHandler in interface ShipInterface
        Parameters:
        connHandler - connectionHandler to handle all interactions with SHIP peer
      • getServices

        public javax.jmdns.ServiceInfo[] getServices()
        returns an array with all detected services, including own service
        Returns:
        the array with all detected services
      • shutDown

        public void shutDown()
                      throws java.io.IOException
        shuts down service discovery, all servers and clients on the node and the node itself
        Throws:
        java.io.IOException - if service discovery shutdown unsuccessful
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.io.IOException