Class DummyConnection

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public final class DummyConnection
    extends Connection
    A dummy connection, used for AI players.
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • otherConnection

        private DummyConnection otherConnection
        The other connection, to which outgoing requests are forwarded .
    • Constructor Detail

      • DummyConnection

        public DummyConnection​(java.lang.String name)
        Sets up a dummy connection using the specified message handler.
        Parameters:
        name - A name for this connection.
    • Method Detail

      • getOtherConnection

        public DummyConnection getOtherConnection()
        Gets the DummyConnection this object is connected to.
        Returns:
        The DummyConnection .
      • setOtherConnection

        public void setOtherConnection​(DummyConnection dc)
        Sets the other connection for this dummy connection.
        Parameters:
        dc - The DummyConnection to connect to.
      • isAlive

        public boolean isAlive()
        Is this connection alive?
        Overrides:
        isAlive in class Connection
        Returns:
        True if the connection is alive.
      • close

        public void close()
        Close this connection.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class Connection
      • sendMessage

        public void sendMessage​(Message message)
                         throws FreeColException,
                                java.io.IOException
        Send a message, do not consider a response. Public as this is called from ReceivingThread.
        Overrides:
        sendMessage in class Connection
        Parameters:
        message - The Message to send.
        Throws:
        FreeColException - on extreme confusion.
        java.io.IOException - on failure to send.
      • askMessage

        public Message askMessage​(Message message,
                                  long timeout)
                           throws FreeColException,
                                  java.io.IOException
        Send a message, and return the response. Log both.
        Overrides:
        askMessage in class Connection
        Parameters:
        message - The Message to send.
        timeout - A timeout in milliseconds, after which a TimeoutException gets thrown when waiting for a reply.
        Returns:
        The response.
        Throws:
        FreeColException - on extreme confusion.
        java.io.IOException - on failure to send.