Class ServiceMessage

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ServiceMessage​(java.lang.String messageName)  
      protected ServiceMessage​(java.lang.String messageName, java.lang.String argument)  
      protected ServiceMessage​(java.lang.String messageName, java.util.Map<java.lang.String,​java.lang.String> attributes)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addTag​(java.lang.String tag)
      Adds a new tag to service message.
      java.lang.String asString()
      Converts this service message to service message string
      static java.lang.String asString​(java.lang.String messageName, java.lang.String argument)
      Returns a string representation of a service message with a single argument.
      static java.lang.String asString​(java.lang.String messageName, java.util.Map<java.lang.String,​java.lang.String> attributes)
      Returns a string representation of a service message with attribute map.
      java.lang.String getArgument()  
      java.util.Map<java.lang.String,​java.lang.String> getAttributes()
      Returns map of parameters of the message in format ##teamcity[<message name> <param name>='<param value>' <param name>='<param value>'...] if parameters were specified, and empty map otherwise
      protected java.lang.String getAttributeValue​(java.lang.String attrName)  
      ServiceMessage.Timestamp getCreationTimestamp()
      Returns service message creation timestamp in case it was specified with attribute "timestamp".
      java.lang.String getFlowId()
      Returns service message flow id in case it was specified and null otherwise
      java.lang.String getMessageName()  
      java.util.Collection<java.lang.String> getTags()  
      static ServiceMessage parse​(java.lang.String text)
      If message is text message according to the pattern ##teamcity[key...], return parsed message.
      static void parse​(java.lang.String text, ServiceMessageParserCallback parserCallback)
      Accepts mixed text (text that can contain service messages inside) and parser callback.
      static ServiceMessage parseSimple​(java.lang.String text, boolean shouldValidate)
      Creates a ServiceMessage instance out of the specified text.
      void setFlowId​(java.lang.String flowId)  
      void setTimestamp​(java.util.Date timestamp)  
      java.lang.String toString()  
      protected void validate()
      Service message validator checks that all methods which marked with RequiredAttribute annotation return not-null value after initialization.
      void visit​(ServiceMessageVisitor visitor)
      Depending on this service message type calls corresponding method in the supplied visitor.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • SERVICE_MESSAGE_START

        @NotNull
        public static final java.lang.String SERVICE_MESSAGE_START
        See Also:
        Constant Field Values
      • SERVICE_MESSAGE_END

        @NotNull
        public static final java.lang.String SERVICE_MESSAGE_END
        See Also:
        Constant Field Values
      • PARSE_SERVICE_MESSAGES_INSIDE_TAG

        public static final java.lang.String PARSE_SERVICE_MESSAGES_INSIDE_TAG
        This tag can be used to inform that service message can have other service messages inside its attributes.
        Since:
        10.0
        See Also:
        Constant Field Values
    • Constructor Detail

      • ServiceMessage

        protected ServiceMessage​(@NotNull
                                 java.lang.String messageName)
      • ServiceMessage

        protected ServiceMessage​(@NotNull
                                 java.lang.String messageName,
                                 @Nullable
                                 java.lang.String argument)
      • ServiceMessage

        protected ServiceMessage​(@NotNull
                                 java.lang.String messageName,
                                 @NotNull
                                 java.util.Map<java.lang.String,​java.lang.String> attributes)
    • Method Detail

      • parse

        @Nullable
        public static ServiceMessage parse​(@NotNull
                                           java.lang.String text)
                                    throws java.text.ParseException
        If message is text message according to the pattern ##teamcity[key...], return parsed message. Otherwise, return null Throws ParseException if message is a service message but its arguments cannot be parsed.
        Parameters:
        text - text to parse
        Returns:
        see above
        Throws:
        java.text.ParseException - if parsing failed
      • parse

        public static void parse​(@NotNull
                                 java.lang.String text,
                                 @NotNull
                                 ServiceMessageParserCallback parserCallback)
        Accepts mixed text (text that can contain service messages inside) and parser callback. Notifies parser callback on any occurrence of the service message or regular text.
        Parameters:
        text - text with service messages
        parserCallback - callback
        Since:
        6.0
      • getMessageName

        @NotNull
        public java.lang.String getMessageName()
        Returns:
        name part of the service message
      • getArgument

        @Nullable
        public java.lang.String getArgument()
        Returns:
        argument text for message ##teamcity[<message name> '< argument>'] or null
      • getCreationTimestamp

        @Nullable
        public ServiceMessage.Timestamp getCreationTimestamp()
        Returns service message creation timestamp in case it was specified with attribute "timestamp". If it was not returns null. The format of timestamp has to be "yyyy-MM-dd'T'HH:mm:ss.SSSZ" or "yyyy-MM-dd'T'HH:mm:ss.SSS". Returns null if attribute value does not match the format.
        Returns:
        service message creation timestamp in case it was correctly specified with attribute "timestamp", null otherwise.
      • getFlowId

        @Nullable
        public java.lang.String getFlowId()
        Returns service message flow id in case it was specified and null otherwise
        Returns:
        service message flow id in case it was specified and null otherwise
      • getTags

        @NotNull
        public java.util.Collection<java.lang.String> getTags()
      • getAttributes

        @NotNull
        public java.util.Map<java.lang.String,​java.lang.String> getAttributes()
        Returns map of parameters of the message in format ##teamcity[<message name> <param name>='<param value>' <param name>='<param value>'...] if parameters were specified, and empty map otherwise
        Returns:
        see above
      • visit

        public void visit​(@NotNull
                          ServiceMessageVisitor visitor)
        Depending on this service message type calls corresponding method in the supplied visitor.
        Parameters:
        visitor - visitor
      • setTimestamp

        public void setTimestamp​(@NotNull
                                 java.util.Date timestamp)
      • setFlowId

        public void setFlowId​(@NotNull
                              java.lang.String flowId)
      • addTag

        public void addTag​(@NotNull
                           java.lang.String tag)
        Adds a new tag to service message.
        Parameters:
        tag - a tag to add
        Since:
        10.0
      • getAttributeValue

        @Nullable
        protected java.lang.String getAttributeValue​(@NotNull
                                                     java.lang.String attrName)
      • parseSimple

        @NotNull
        public static ServiceMessage parseSimple​(@NotNull
                                                 java.lang.String text,
                                                 boolean shouldValidate)
                                          throws java.text.ParseException
        Creates a ServiceMessage instance out of the specified text. Currently the ServiceMessage class doesn't have any RequiredAttribute so validation is not performed
        Parameters:
        text - text to parse
        shouldValidate - whether to validate required attributes or not (currently ignored)
        Returns:
        parsed service message
        Throws:
        java.text.ParseException - if parsing fails
      • validate

        protected void validate()
                         throws java.text.ParseException
        Service message validator checks that all methods which marked with RequiredAttribute annotation return not-null value after initialization.
        Throws:
        java.text.ParseException
      • asString

        @NotNull
        public java.lang.String asString()
        Converts this service message to service message string
        Returns:
        serialized service message object with ##teamcity[ prefix
        Since:
        6.0
      • asString

        @NotNull
        public static java.lang.String asString​(@NotNull
                                                java.lang.String messageName,
                                                @NotNull
                                                java.util.Map<java.lang.String,​java.lang.String> attributes)
        Returns a string representation of a service message with attribute map. This method is useful when there is a need of outputting service text without creating a ServiceMessage instance.
        Parameters:
        messageName - name of the message
        attributes - attribute map
        Returns:
        service message string
        Since:
        6.0
      • asString

        @NotNull
        public static java.lang.String asString​(@NotNull
                                                java.lang.String messageName,
                                                @NotNull
                                                java.lang.String argument)
        Returns a string representation of a service message with a single argument. This method is useful when there is a need of outputting service text without creating a ServiceMessage instance.
        Parameters:
        messageName - name of the message
        argument - the argument
        Returns:
        service message string
        Since:
        6.0
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object