Class TcpBuildConnection

  • All Implemented Interfaces:
    BuildConnection

    @Named("default")
    @Singleton
    public class TcpBuildConnection
    extends java.lang.Object
    implements BuildConnection
    Default implementation using the system property plexus.build.ipc.port to communicate with an endpoint to exchange messages
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static TcpBuildConnection.ServerConnection createServer​(java.util.function.Function<Message,​java.util.Map<java.lang.String,​java.lang.String>> consumer)
      Creates a new server that will receive messages from a remote endpoint and inform the consumer
      boolean isEnabled()
      This method allows code to perform an eager check if a buildconnection is present to send messages.
      Message send​(Message message, org.apache.maven.execution.MavenSession mavenSession)
      Send a message and returns the reply from the other endpoint, should only be called from a maven thread!
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TcpBuildConnection

        public TcpBuildConnection()
    • Method Detail

      • isEnabled

        public boolean isEnabled()
        Description copied from interface: BuildConnection
        This method allows code to perform an eager check if a buildconnection is present to send messages. This can be used to guard operations to prevent allocate resources or objects if the message will be dropped.
        Specified by:
        isEnabled in interface BuildConnection
        Returns:
        true if the connection can be used to send messages or if they will be discarded
      • send

        public Message send​(Message message,
                            org.apache.maven.execution.MavenSession mavenSession)
        Description copied from interface: BuildConnection
        Send a message and returns the reply from the other endpoint, should only be called from a maven thread!
        Specified by:
        send in interface BuildConnection
        Parameters:
        message - the message to send
        mavenSession - the maven session to reference
        Returns:
        the reply message or null if this connection is not enabled and the message was discarded.
      • createServer

        public static TcpBuildConnection.ServerConnection createServer​(java.util.function.Function<Message,​java.util.Map<java.lang.String,​java.lang.String>> consumer)
                                                                throws java.io.IOException
        Creates a new server that will receive messages from a remote endpoint and inform the consumer
        Parameters:
        consumer - the consumer of messages, might be called by different threads, if the consumer throws an exception while handling a message it will maybe no longer receive some messages. The returned map is used as a payload for the reply to the server, if null is returned a simple acknowledgement without any payload will be send to the endpoint. If the consumer performs blocking operations the further execution of the maven process might be halted depending on the message type, if that is not desired work should be offloaded by the consumer to a different thread.
        Returns:
        a TcpBuildConnection.ServerConnection that can be used to shutdown the server and get properties that needs to be passed to the maven process
        Throws:
        java.io.IOException - if no local socket can be opened