-
Notifications
You must be signed in to change notification settings - Fork 459
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
Fix: CloudConnection did not forward close() call to cloud proxy #4546
Changes from 1 commit
a31272f
e911010
2cc47a1
e9cc83c
d2d0180
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,26 +4,58 @@ namespace Microsoft.Azure.Devices.Edge.Hub.MqttBrokerAdapter | |
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Devices.Edge.Hub.Core.Cloud; | ||
using Microsoft.Azure.Devices.Edge.Hub.Core.Identity; | ||
using Microsoft.Azure.Devices.Edge.Util; | ||
using Microsoft.Extensions.Logging; | ||
|
||
public class BrokeredCloudConnection : ICloudConnection | ||
{ | ||
IIdentity identity; | ||
|
||
public BrokeredCloudConnection(BrokeredCloudProxy cloudProxy) | ||
{ | ||
Preconditions.CheckNotNull(cloudProxy); | ||
|
||
this.IsActive = true; | ||
this.CloudProxy = Option.Some(cloudProxy as ICloudProxy); | ||
this.identity = cloudProxy.Identity; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems odd... can we just pass in the Identity separately, like we do for CloudConnection? |
||
} | ||
|
||
public Option<ICloudProxy> CloudProxy { get; } | ||
|
||
public bool IsActive { get; private set; } | ||
|
||
public Task<bool> CloseAsync() | ||
public async Task<bool> CloseAsync() | ||
{ | ||
// TODO, in order to tear down the connection higher level, | ||
// it should unsubscribe from all topics | ||
this.IsActive = false; | ||
return Task.FromResult(true); | ||
var result = default(bool); | ||
|
||
try | ||
{ | ||
result = await this.CloudProxy.Match( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: suggest: .Map().GetOrElse(true) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test? |
||
cp => cp.CloseAsync(), | ||
() => Task.FromResult(true)); | ||
} | ||
catch (Exception e) | ||
{ | ||
result = false; | ||
Events.ErrorClosingCloudProxy(e, this.identity.Id); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
static class Events | ||
{ | ||
const int IdStart = MqttBridgeEventIds.BrokeredCloudConnection; | ||
static readonly ILogger Log = Logger.Factory.CreateLogger<BrokeredCloudConnection>(); | ||
|
||
enum EventIds | ||
{ | ||
ErrorClosingCloudProxy = IdStart, | ||
} | ||
|
||
public static void ErrorClosingCloudProxy(Exception e, string id) => Log.LogError((int)EventIds.ErrorClosingCloudProxy, e, $"Error closing cloud-proxy for {id}"); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not a ICloudProxy? We should avoid passing in actual types.. if possible.