java.lang.Object
org.eclipse.milo.opcua.sdk.client.subscriptions.OpcUaSubscription

public class OpcUaSubscription extends Object
  • Constructor Details

    • OpcUaSubscription

      public OpcUaSubscription(OpcUaClient client)
    • OpcUaSubscription

      public OpcUaSubscription(OpcUaClient client, double publishingInterval)
  • Method Details

    • getClient

      public OpcUaClient getClient()
      Get the client this Subscription belongs to.
      Returns:
      the OpcUaClient this Subscription belongs to.
    • create

      public void create() throws org.eclipse.milo.opcua.stack.core.UaException
      Create this Subscription on the Server.
      Throws:
      org.eclipse.milo.opcua.stack.core.UaException - if a service- or operation-level error occurs.
    • createAsync

      public CompletionStage<org.eclipse.milo.opcua.stack.core.util.Unit> createAsync()
      Create this Subscription on the Server.
      Returns:
      a CompletionStage that completes successfully if the Subscription was created, or completes exceptionally if there was a service- or operation-level error.
    • modify

      public void modify() throws org.eclipse.milo.opcua.stack.core.UaException
      Call the ModifySubscription service to update the Subscription's parameters on the Server.
      Throws:
      org.eclipse.milo.opcua.stack.core.UaException - if a service- or operation-level error occurs.
    • modifyAsync

      public CompletionStage<org.eclipse.milo.opcua.stack.core.util.Unit> modifyAsync()
      Call the ModifySubscription service to update the Subscription's parameters on the Server.
      Returns:
      a CompletionStage that completes successfully if the Subscription was modified, or completes exceptionally if there was a service- or operation-level error.
    • delete

      public void delete() throws org.eclipse.milo.opcua.stack.core.UaException
      Delete this Subscription from the Server.
      Throws:
      org.eclipse.milo.opcua.stack.core.UaException - if a service- or operation-level error occurs.
    • deleteAsync

      public CompletionStage<org.eclipse.milo.opcua.stack.core.util.Unit> deleteAsync()
      Delete this Subscription from the Server.
      Returns:
      a CompletionStage that completes successfully if the Subscription was deleted, or completes exceptionally if there was a service- or operation-level error.
    • addMonitoredItem

      public void addMonitoredItem(OpcUaMonitoredItem item)
      Add a MonitoredItem to this Subscription.

      This item will not be created on the server until synchronizeMonitoredItems() is called.

      Parameters:
      item - the MonitoredItem to add.
      Throws:
      org.eclipse.milo.opcua.stack.core.UaRuntimeException - if the Subscription has not been created yet.
    • addMonitoredItems

      public void addMonitoredItems(List<OpcUaMonitoredItem> items)
      Add a group of MonitoredItems to this Subscription.

      These items will not be created on the server until synchronizeMonitoredItems() is called.

      Parameters:
      items - the MonitoredItems to add.
      Throws:
      org.eclipse.milo.opcua.stack.core.UaRuntimeException - if the Subscription has not been created yet.
    • removeMonitoredItem

      public void removeMonitoredItem(OpcUaMonitoredItem item)
      Remove a MonitoredItem from this Subscription.

      This item will not be deleted from the server until synchronizeMonitoredItems() is called

      Parameters:
      item - the MonitoredItem to remove.
    • removeMonitoredItems

      public void removeMonitoredItems(List<OpcUaMonitoredItem> items)
      Remove a group of MonitoredItems from this Subscription.

      These items will not be deleted from the server until synchronizeMonitoredItems() is called.

      Parameters:
      items - the MonitoredItems to remove.
      Throws:
      org.eclipse.milo.opcua.stack.core.UaRuntimeException - if the Subscription has not been created yet.
    • synchronizeMonitoredItems

      public void synchronizeMonitoredItems() throws MonitoredItemSynchronizationException
      Synchronize the Subscription's MonitoredItems with the Server.

      This is a compound operation that deletes any MonitoredItems that have been removed from the Subscription, modifies any existing MonitoredItems that have been changed, and creates any new MonitoredItems that have been added but not yet created on the Server.

      Throws:
      MonitoredItemSynchronizationException - if one or more MonitoredItems failed to synchronize for any reason. This could be a service-level failure or an operation-level failure. Check the MonitoredItemServiceOperationResults for details.
    • createMonitoredItems

      public List<MonitoredItemServiceOperationResult> createMonitoredItems()
      Create any MonitoredItems that have been added to the Subscription but not yet created on the Server.
      Returns:
      a List of MonitoredItemServiceOperationResults that contain the MonitoredItem and the service- and operation-level results associated with the attempt to create it.
    • createMonitoredItems

      public List<MonitoredItemServiceOperationResult> createMonitoredItems(Predicate<OpcUaMonitoredItem> filter)
      Create any MonitoredItems that have been added to the Subscription but not yet created on the Server, filtered by the given predicate.

      This could be used to e.g. further restrict the MonitoredItems to be created to only those that have not had a previous creation attempt:

         List results = subscription.createMonitoredItems(
            item -> item.getCreateResult().isEmpty()
         );
       
      Parameters:
      filter - a predicate that allows further restriction of the MonitoredItems to be created.
      Returns:
      a List of MonitoredItemServiceOperationResults that contain the MonitoredItem and the service- and operation-level results associated with the attempt to create it.
    • modifyMonitoredItems

      public List<MonitoredItemServiceOperationResult> modifyMonitoredItems()
      Modify any MonitoredItems that have been changed.
      Returns:
      a List of the MonitoredItems that were modified.
    • deleteMonitoredItems

      public List<MonitoredItemServiceOperationResult> deleteMonitoredItems()
      Delete any MonitoredItems that have been removed from the Subscription.
      Returns:
      a List of the MonitoredItems that were deleted.
    • setMonitoringMode

      public List<MonitoredItemServiceOperationResult> setMonitoringMode(org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode monitoringMode, List<OpcUaMonitoredItem> monitoredItems)
      Set the MonitoringMode for a group of MonitoredItems.

      These MonitoredItems must exist on the Server before setting the MonitoringMode.

      Parameters:
      monitoringMode - the MonitoringMode to set.
      monitoredItems - the MonitoredItems to set the MonitoringMode for.
      Returns:
      a List of MonitoredItemServiceOperationResults that contain the MonitoredItem and the service- and operation-level results associated with the attempt to set the MonitoringMode.
    • setPublishingMode

      public void setPublishingMode(boolean enabled) throws org.eclipse.milo.opcua.stack.core.UaException
      Set the publishing mode, i.e. enable or disable publishing, for this Subscription.
      Parameters:
      enabled - true to enable publishing, false to disable publishing.
      Throws:
      org.eclipse.milo.opcua.stack.core.UaException - if a service- or operation-level error occurs.
    • setPublishingModeAsync

      public CompletionStage<org.eclipse.milo.opcua.stack.core.util.Unit> setPublishingModeAsync(boolean enabled)
      Set the publishing mode, i.e. enable or disable publishing, for this Subscription.
      Parameters:
      enabled - true to enable publishing, false to disable publishing.
      Returns:
      a CompletionStage that completes successfully if the operation was successful, or completes exceptionally if there was a service- or operation-level error.
    • getSyncState

      public OpcUaSubscription.SyncState getSyncState()
      Returns:
      the current OpcUaSubscription.SyncState of this Subscription.
    • getServerState

      public Optional<OpcUaSubscription.ServerState> getServerState()
      Returns:
      the current OpcUaSubscription.ServerState of this Subscription, if it has been created.
    • getMonitoredItems

      public List<OpcUaMonitoredItem> getMonitoredItems()
      Get a list of the MonitoredItems belonging to this Subscription.

      If synchronizeMonitoredItems() has not been called since adding or removing MonitoredItems, this List may not represent the server's view of the MonitoredItems.

      Returns:
      a List of the MonitoredItems belonging to this Subscription.
    • getPublishingInterval

      public Double getPublishingInterval()
      Get the current PublishingInterval for this Subscription.

      The server may have revised it upon creation or modification.

      Returns:
      the current PublishingInterval for this Subscription.
      See Also:
    • getLifetimeCount

      public org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger getLifetimeCount()
      Get the current LifetimeCount for this Subscription.

      The server may have revised it upon creation or modification.

      Returns:
      the current LifetimeCount for this Subscription.
      See Also:
    • getMaxKeepAliveCount

      public org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger getMaxKeepAliveCount()
      Get the current MaxKeepAliveCount for this Subscription.

      The server may have revised it upon creation or modification.

      Returns:
      the current MaxKeepAliveCount for this Subscription.
      See Also:
    • getPriority

      public org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte getPriority()
      Get the Subscription's Priority setting.

      The Server does not revise this setting, so the value reflects the most recently requested by a create or modify operation.

      Returns:
      the Subscription's Priority setting.
    • getMaxNotificationsPerPublish

      public org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger getMaxNotificationsPerPublish()
      Get the Subscription's MaxNotificationsPerPublish setting.

      The Server does not revise this setting, so the value reflects the most recently requested by a create or modify operation.

      Returns:
      the Subscription's MaxNotificationsPerPublish setting.
    • isPublishingEnabled

      public Optional<Boolean> isPublishingEnabled()
      Get whether publishing is enabled for this Subscription.

      This is available only after the Subscription has been created.

      Returns:
      true if publishing is enabled for this Subscription.
    • getSubscriptionId

      public Optional<org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger> getSubscriptionId()
      Get the SubscriptionId assigned to this Subscription by the Server.

      The SubscriptionId is available only after the Subscription has been created.

      Returns:
      the SubscriptionId assigned to this Subscription by the Server.
    • getRevisedPublishingInterval

      public Optional<Double> getRevisedPublishingInterval()
      Get the revised PublishingInterval from the most recent create or modify operation.

      The revised PublishingInterval is available only after the Subscription has been created or modified.

      Returns:
      the revised PublishingInterval from the most recent create or modify operation.
    • getRevisedLifetimeCount

      public Optional<org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger> getRevisedLifetimeCount()
      Get the revised LifetimeCount from the most recent create or modify operation.

      The revised LifetimeCount is available only after the Subscription has been created or modified.

      Returns:
      the revised LifetimeCount from the most recent create or modify operation.
    • getRevisedMaxKeepAliveCount

      public Optional<org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger> getRevisedMaxKeepAliveCount()
      Get the revised MaxKeepAliveCount from the most recent create or modify operation.

      The revised MaxKeepAliveCount is available only after the Subscription has been created or modified.

      Returns:
      the revised MaxKeepAliveCount from the most recent create or modify operation.
    • setPublishingInterval

      public void setPublishingInterval(Double publishingInterval)
      Set a new PublishingInterval for this Subscription.

      If the Subscription has not yet been created, this will be the PublishingInterval used during the create service call.

      If the Subscription has already been created, this will be the PublishingInterval used during the next modify service call.

      Parameters:
      publishingInterval - the new PublishingInterval.
      See Also:
    • setLifetimeCount

      public void setLifetimeCount(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger lifetimeCount)
      Set a new LifetimeCount for this Subscription.

      If the Subscription has not yet been created, this will be the LifetimeCount used during the create service call.

      If the Subscription has already been created, this will be the LifetimeCount used during the next modify service call.

      Parameters:
      lifetimeCount - the new LifetimeCount.
      See Also:
    • setMaxKeepAliveCount

      public void setMaxKeepAliveCount(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger maxKeepAliveCount)
      Set a new MaxKeepAliveCount for this Subscription.

      If the Subscription has not yet been created, this will be the MaxKeepAliveCount used during the create service call.

      If the Subscription has already been created, this will be the MaxKeepAliveCount used during the next modify service call.

      Parameters:
      maxKeepAliveCount - the new MaxKeepAliveCount.
      See Also:
    • setPriority

      public void setPriority(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte priority)
      Set a new Priority for this Subscription.

      If the Subscription has not yet been created, this will be the Priority used during the create service call.

      If the Subscription has already been created, this will be the Priority used during the next modify service call.

      Parameters:
      priority - the new Priority.
      See Also:
    • setMaxNotificationsPerPublish

      public void setMaxNotificationsPerPublish(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger maxNotificationsPerPublish)
      Set a new MaxNotificationsPerPublish for this Subscription.

      If the Subscription has not yet been created, this will be the MaxNotificationsPerPublish used during the create service call.

      If the Subscription has already been created, this will be the MaxNotificationsPerPublish used during the next modify service call.

      Parameters:
      maxNotificationsPerPublish - the new MaxNotificationsPerPublish.
      See Also:
    • setLifetimeAndKeepAliveCalculated

      public void setLifetimeAndKeepAliveCalculated(boolean lifetimeAndKeepAliveCalculated)
      Set whether the LifetimeCount and MaxKeepAliveCount should be calculated automatically any time the PublishingInterval is set.
      Parameters:
      lifetimeAndKeepAliveCalculated - true if the LifetimeCount and MaxKeepAliveCount should be calculated automatically.
      See Also:
    • isLifetimeAndKeepAliveCalculated

      public boolean isLifetimeAndKeepAliveCalculated()
      Returns:
      true if the LifetimeCount and MaxKeepAliveCount are calculated automatically any time the Publishing Interval is set.
      See Also:
    • setTargetKeepAliveInterval

      public void setTargetKeepAliveInterval(double targetKeepAliveInterval)
      Set the target keep-alive interval, in milliseconds, for this Subscription.

      The Subscription must be configured to automatically calculate the Lifetime and KeepAlive for this to have any effect. MaxKeepAliveCount and LifetimeCount will be recalculated based on the target value. The Subscription settings must be synchronized before this change takes effect.

      Parameters:
      targetKeepAliveInterval - the target keep-alive interval, in milliseconds.
      See Also:
    • setMaxMonitoredItemsPerCall

      public void setMaxMonitoredItemsPerCall(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger maxMonitoredItemsPerCall)
      Set the maximum number of MonitoredItems that can be created/modified/deleted in a single service call.

      This value is compared against the value read from the Server's OperationLimits object, and the smaller of the two is used.

      Parameters:
      maxMonitoredItemsPerCall - the maximum number of MonitoredItems that can be created/modified/deleted in a single service call.
    • setWatchdogMultiplier

      public void setWatchdogMultiplier(double watchdogMultiplier)
      Set the multiplier used to calculate the watchdog timeout. The multiplier is applied to the keep-alive interval.
      Parameters:
      watchdogMultiplier - the watchdog multiplier.
    • setSubscriptionListener

      public void setSubscriptionListener(@Nullable OpcUaSubscription.SubscriptionListener listener)
      Set the OpcUaSubscription.SubscriptionListener for this Subscription.
      Parameters:
      listener - the OpcUaSubscription.SubscriptionListener for this Subscription.
    • setUserObject

      public void setUserObject(@Nullable Object userObject)
      Associate an arbitrary user object with this Subscription.
      Parameters:
      userObject - the user object to associate with this Subscription.
    • getUserObject

      public Optional<Object> getUserObject()
      Returns:
      the user object associated with this Subscription.
    • getDeliveryQueue

      public org.eclipse.milo.opcua.stack.core.util.TaskQueue getDeliveryQueue()
      Get the TaskQueue used to deliver notifications for this Subscription.
      Returns:
      the TaskQueue used to deliver notifications for this Subscription.
    • reset

      public void reset()
      Reset this Subscription.

      Resetting the Subscription removes it from the Client and PublishingManager, cancels the watchdog timer, and sets the OpcUaSubscription.SyncState back to OpcUaSubscription.SyncState.INITIAL.

      OpcUaMonitoredItems that have been added are reset, but the collection is not cleared. If the Subscription is created again, the call synchronizeMonitoredItems() or createMonitoredItems() to create the items on the Server again.

      This is called automatically when the Subscription is deleted, but can also be called manually when necessary if it has been determined the Subscription no longer exists on the Server.

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • notifyTransferFailed

      public void notifyTransferFailed(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode status)