Class StatusMessage

java.lang.Object
de.iip_ecosphere.platform.transport.status.StatusMessage

public class StatusMessage extends Object
Represents a status message for a component. A component is denoted by the device id (of the ECS runtime) the component is running on, the component id (in the context of a device) and optional alias ids, e.g., introduced by a specific device management approach. If the component to notify about is a device, the device id and the component id shall be equal.
Author:
Holger Eichelberger, SSE
  • Field Details

  • Constructor Details

    • StatusMessage

      StatusMessage()
      Creates an empty status message. [deserialization]
    • StatusMessage

      public StatusMessage(ActionType action, String id, String... aliasIds)
      Creates a new status message for devices, i.e., ComponentTypes.DEVICE.
      Parameters:
      action - the action
      id - the id of the component
      aliasIds - optional alias ids
    • StatusMessage

      public StatusMessage(ComponentType componentType, ActionType action, String id, String deviceId, String... aliasIds)
      Creates a new status message.
      Parameters:
      componentType - the component type
      action - the action
      id - the id of the component
      deviceId - the id of device providing the context, shall be equal to id if componentType is ComponentTypes.DEVICE.
      aliasIds - optional alias ids
  • Method Details

    • getComponentType

      public ComponentType getComponentType()
      Returns the component type.
      Returns:
      the component type
    • setComponentType

      void setComponentType(ComponentType componentType)
      Changes the component type. [deserialization]
      Parameters:
      componentType - the new component type
    • getAction

      public ActionType getAction()
      Returns the action type causing this message.
      Returns:
      the action type causing this message
    • setAction

      void setAction(ActionType action)
      Changes the action type. [deserialization]
      Parameters:
      action - the new action type
    • getId

      public String getId()
      Returns the primary id of the component.
      Returns:
      the primary id, may be equal to getDeviceId() if getComponentType() is ComponentTypes.DEVICE.
    • setId

      void setId(String id)
      Changes the primary id of the component. [deserialization]
      Parameters:
      id - the primary id
    • getDeviceId

      public String getDeviceId()
      Returns the device (context) id of the component.
      Returns:
      the device id, shall be equal to getId() if getComponentType() is ComponentTypes.DEVICE.
    • setDeviceId

      void setDeviceId(String deviceId)
      Changes the device (context) id of the component. [deserialization]
      Parameters:
      deviceId - the device id
    • getAliasIds

      public String[] getAliasIds()
      Returns optional alias ids of the component.
      Returns:
      the alias ids, may be empty
    • setAliasIds

      void setAliasIds(String[] aliasIds)
      Changes the alias ids of the component. [deserialization]
      Parameters:
      aliasIds - the primary id
    • send

      public void send(TransportConnector conn) throws IOException
      Sends this message to the given connector on #STATUS_STREAM. [convenience]
      Parameters:
      conn - the connector
      Throws:
      IOException - if sending fails
    • withProgress

      public StatusMessage withProgress(int progress)
      Defines the progress for ActionTypes.PROCESS.
      Parameters:
      progress - the progress in [0;100]; if 100 longer running process is assumed to be completed
      Returns:
      this
    • getProgress

      public int getProgress()
      Returns the progress for ActionTypes.PROCESS.
      Returns:
      the progress in percent: if negative, no progress will be reported. If positive, further messages shall follow until 100.
    • withDescription

      public StatusMessage withDescription(String description)
      Sets the description for getProgress(), ActionTypes.PROCESS.
      Parameters:
      description - the description, may be null or ""
      Returns:
      this
    • getDescription

      public String getDescription()
      Returns the description, ActionTypes.PROCESS.
      Returns:
      the description, may be empty but not null
    • withSubDescription

      public StatusMessage withSubDescription(String subDescription)
      Sets the sub(-task) description for getProgress(), ActionTypes.PROCESS.
      Parameters:
      subDescription - the sub(-task) description, may be null or ""
      Returns:
      this
    • getSubDescription

      public String getSubDescription()
      Returns the sub(-task) description, ActionTypes.PROCESS.
      Returns:
      the sub(-task) description, may be empty but not null
    • withTask

      public StatusMessage withTask()
      Adds task information if the actually running process were, e.g., initiated from the UI. Takes the registered task data for the actual thread from the TaskRegistry.
      Returns:
      this
      See Also:
    • withTask

      public StatusMessage withTask(de.iip_ecosphere.platform.support.TaskRegistry.TaskData data)
      Adds task information if the actually running process were, e.g., initiated from the UI. Does not attach results.
      Parameters:
      data - the task data (from TaskRegistry
      Returns:
      this
      See Also:
    • withTask

      public StatusMessage withTask(de.iip_ecosphere.platform.support.TaskRegistry.TaskData data, Object result)
      Adds task information if the actually running process were, e.g., initiated from the UI.
      Parameters:
      data - the task data (from TaskRegistry
      result - the result (must be serializable, see SerializerRegistry) if getAction() is ActionTypes.RESULT or information about an error/exception if getAction() is ActionTypes.ERROR, may be null
      Returns:
      this
      See Also:
    • withResult

      public StatusMessage withResult(Object result)
      Sets the result of task-based processing.
      Parameters:
      result - the result (must be serializable, see SerializerRegistry) if getAction() is ActionTypes.RESULT or information about an error/exception if getAction() is ActionTypes.ERROR, may be null
      Returns:
      this
    • getTaskId

      public String getTaskId()
      Returns the task id this message is sent from within. Not all status messages have a task id, e.g., if the are not started from the UI as longer running task.
      Returns:
      the task id, may be null
    • getResult

      public Object getResult()
      Returns the result of task-based processing.
      Returns:
      the result (must be serializable, see SerializerRegistry) if getAction() is ActionTypes.RESULT or information about an error/exception if getAction() is ActionTypes.ERROR, may be null