Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Server] Restore durable subscriptions on Server Restart #3025

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"ConsoleReferenceClient": {
"commandName": "Project",
"commandLineArgs": "-ds -un sysadmin -up demo"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"ConsoleReferenceServer": {
"commandName": "Project",
"commandLineArgs": "-l -c"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,85 +28,73 @@
* ======================================================================*/


using System;
using Opc.Ua;
using Opc.Ua.Server;

namespace Quickstarts.Servers
{
/// <summary>
/// A factory for <see cref="IDataChangeMonitoredItemQueue"> and </see> <see cref="IEventMonitoredItemQueue"/>
/// </summary>
public class DurableMonitoredItemQueueFactory : IMonitoredItemQueueFactory
public class DurableDataChangeMonitoredItemQueue : DataChangeMonitoredItemQueue
{
/// <inheritdoc/>
public bool SupportsDurableQueues => true;
/// <inheritdoc/>
public IDataChangeMonitoredItemQueue CreateDataChangeQueue(bool createDurable, uint monitoredItemId)
{
//use durable queue only if MI is durable
if (createDurable)
{

return new DurableDataChangeMonitoredItemQueue(createDurable, monitoredItemId);
}
else
{
return new DataChangeMonitoredItemQueue(createDurable, monitoredItemId);
}

}

/// <inheritdoc/>
public IEventMonitoredItemQueue CreateEventQueue(bool createDurable, uint monitoredItemId)
{
//use durable queue only if MI is durable
if (createDurable)
{

return new DurableEventMonitoredItemQueue(createDurable, monitoredItemId);
}
else
{
return new EventMonitoredItemQueue(createDurable, monitoredItemId);
}
}

/// <inheritdoc/>
public void Dispose()
{
//only needed for managed resources
}
}
/// <summary>
/// Invoked when the queue is disposed
/// </summary>
public event EventHandler Disposed;

public class DurableEventMonitoredItemQueue : EventMonitoredItemQueue
{
/// <summary>
/// Creates an empty queue.
/// </summary>
public DurableEventMonitoredItemQueue(bool createDurable, uint monitoredItemId) : base(false, monitoredItemId)
public DurableDataChangeMonitoredItemQueue(bool createDurable, uint monitoredItemId) : base(false, monitoredItemId)
{
IsDurable = createDurable;
}
/// <summary>
/// Creates a queue from a template
/// </summary>
public DurableDataChangeMonitoredItemQueue(StorableDataChangeQueue queue) : base(false, queue.MonitoredItemId)
{
IsDurable = queue.IsDurable;
m_start = queue.Start;
m_end = queue.End;
m_values = queue.Values;
m_errors = queue.Errors;
}

#region Public Methods
/// <inheritdoc/>
public override bool IsDurable { get; }
#endregion
}

public class DurableDataChangeMonitoredItemQueue : DataChangeMonitoredItemQueue
{
/// <summary>
/// Creates an empty queue.
/// Brings the queue with content into a storable format
/// </summary>
public DurableDataChangeMonitoredItemQueue(bool createDurable, uint monitoredItemId) : base(false, monitoredItemId)
/// <returns></returns>
public StorableDataChangeQueue ToStorableQueue()
{
IsDurable = createDurable;

return new StorableDataChangeQueue {
IsDurable = IsDurable,
MonitoredItemId = MonitoredItemId,
Start = m_start,
End = m_end,
Values = m_values,
Errors = m_errors
};
}

#region Public Methods
/// <inheritdoc/>
public override bool IsDurable { get; }

public override void Dispose()
{
Disposed?.Invoke(this, new EventArgs());
}
#endregion
}

public class StorableDataChangeQueue
{
public bool IsDurable { get; set; }
public uint MonitoredItemId { get; set; }
public int Start { get; set; }
public int End { get; set; }
public DataValue[] Values { get; set; }
public ServiceResult[] Errors { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/* ========================================================================
* Copyright (c) 2005-2024 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* The complete license agreement can be found here:
* http://opcfoundation.org/License/MIT/1.00/
* ======================================================================*/


using System;
using System.Collections.Generic;
using Opc.Ua;
using Opc.Ua.Server;

namespace Quickstarts.Servers
{
public class DurableEventMonitoredItemQueue : EventMonitoredItemQueue
{
/// <summary>
/// Invoked when the queue is disposed
/// </summary>
public event EventHandler Disposed;

/// <summary>
/// Creates an empty queue.
/// </summary>
public DurableEventMonitoredItemQueue(bool createDurable, uint monitoredItemId) : base(false, monitoredItemId)
{
IsDurable = createDurable;
}

/// <summary>
/// Creates a queue from a template
/// </summary>
public DurableEventMonitoredItemQueue(StorableEventQueue queue) : base(false, queue.MonitoredItemId)
{
IsDurable = queue.IsDurable;
m_events = queue.Events;
QueueSize = queue.QueueSize;
}

#region Public Methods
/// <summary>
/// Brings the queue with contents into a storable format
/// </summary>
/// <returns></returns>
public StorableEventQueue ToStorableQueue()
{

return new StorableEventQueue {
IsDurable = IsDurable,
MonitoredItemId = MonitoredItemId,
Events = m_events,
QueueSize = QueueSize,
};
}
/// <inheritdoc/>
public override bool IsDurable { get; }

public override void Dispose()
{
Disposed?.Invoke(this, new EventArgs());
}
#endregion
}
public class StorableEventQueue
{
public bool IsDurable { get; set; }
public uint MonitoredItemId { get; set; }
public List<EventFieldList> Events { get; set; }
public uint QueueSize { get; set; }
}
}
Loading
Loading