Skip to content

Commit

Permalink
Merge branch 'main' into throw-null-log-prepop
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored May 7, 2022
2 parents d4e4711 + fc6a092 commit 57c541d
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryDelete() -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryLease(int leasePeriodMilliseconds) -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryRead(out byte[]? buffer) -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryWrite(byte[]! buffer, int leasePeriodMilliseconds = 0) -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable<OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob!>!
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryCreateBlob(byte[]! buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryCreateBlob(byte[]! buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.PersistentBlob() -> void
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryDelete() -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryLease(int leasePeriodMilliseconds) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryRead(out byte[]? buffer) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryWrite(byte[]! buffer, int leasePeriodMilliseconds = 0) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.GetBlobs() -> System.Collections.Generic.IEnumerable<OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob!>!
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.PersistentBlobProvider() -> void
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryCreateBlob(byte[]! buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryCreateBlob(byte[]! buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryDelete() -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryLease(int leasePeriodMilliseconds) -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryRead(out byte[]? buffer) -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryWrite(byte[]! buffer, int leasePeriodMilliseconds = 0) -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable<OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob!>!
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryCreateBlob(byte[]! buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryCreateBlob(byte[]! buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.PersistentBlob() -> void
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryDelete() -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryLease(int leasePeriodMilliseconds) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryRead(out byte[]? buffer) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryWrite(byte[]! buffer, int leasePeriodMilliseconds = 0) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.GetBlobs() -> System.Collections.Generic.IEnumerable<OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob!>!
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.PersistentBlobProvider() -> void
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryCreateBlob(byte[]! buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryCreateBlob(byte[]! buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryDelete() -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryLease(int leasePeriodMilliseconds) -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryRead(out byte[]? buffer) -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.OnTryWrite(byte[]! buffer, int leasePeriodMilliseconds = 0) -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable<OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob!>!
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryCreateBlob(byte[]! buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryCreateBlob(byte[]! buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
abstract OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.PersistentBlob() -> void
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryDelete() -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryLease(int leasePeriodMilliseconds) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryRead(out byte[]? buffer) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob.TryWrite(byte[]! buffer, int leasePeriodMilliseconds = 0) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.GetBlobs() -> System.Collections.Generic.IEnumerable<OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob!>!
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.PersistentBlobProvider() -> void
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryCreateBlob(byte[]! buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryCreateBlob(byte[]! buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlobProvider.TryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// <copyright file="AssemblyInfo.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System;

[assembly: CLSCompliant(false)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// <copyright file="NotNullWhenAttribute.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

#if NETSTANDARD2_0 || NET462
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.All)]
internal sealed class NotNullWhenAttribute : Attribute
{
/// <summary>Initializes a new instance of the <see cref="NotNullWhenAttribute"/> class.Initializes the attribute with the specified return value condition.</summary>
/// <param name="returnValue">
/// The return value condition. If the method returns this value, the associated parameter will not be null.
/// </param>
public NotNullWhenAttribute(bool returnValue) => this.ReturnValue = returnValue;

/// <summary>Gets a value indicating whether gets the return value condition.</summary>
public bool ReturnValue { get; }
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
<TargetFrameworks Condition="'$(Configuration)' == 'Debug'">$(TargetFrameworks);net6.0</TargetFrameworks> <!-- Added just to get proper nullable analysis in IDE -->
<Description>OpenTelemetry Persistent Storage Abstractions</Description>
<MinVerTagPrefix>Extensions.PersistentStorage.Abstractions-</MinVerTagPrefix>
</PropertyGroup>

<PropertyGroup>
<NoWarn>$(NoWarn),1591</NoWarn>
<Nullable>enable</Nullable>
<EnableAnalysis>true</EnableAnalysis>
<EnablePublicApi>true</EnablePublicApi>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// </copyright>

using System;
using System.Diagnostics.CodeAnalysis;

namespace OpenTelemetry.Extensions.PersistentStorage.Abstractions
{
Expand All @@ -32,8 +33,9 @@ public abstract class PersistentBlob
/// <returns>
/// True if read was successful or else false.
/// </returns>
public bool TryRead(out byte[] buffer)
public bool TryRead([NotNullWhen(true)] out byte[]? buffer)
{
#pragma warning disable CA1031 // Do not catch general exception types
try
{
return this.OnTryRead(out buffer);
Expand All @@ -44,6 +46,7 @@ public bool TryRead(out byte[] buffer)
buffer = null;
return false;
}
#pragma warning restore CA1031 // Do not catch general exception types
}

/// <summary>
Expand All @@ -60,6 +63,7 @@ public bool TryRead(out byte[] buffer)
/// </returns>
public bool TryWrite(byte[] buffer, int leasePeriodMilliseconds = 0)
{
#pragma warning disable CA1031 // Do not catch general exception types
try
{
return this.OnTryWrite(buffer, leasePeriodMilliseconds);
Expand All @@ -69,6 +73,7 @@ public bool TryWrite(byte[] buffer, int leasePeriodMilliseconds = 0)
// TODO: log exception.
return false;
}
#pragma warning restore CA1031 // Do not catch general exception types
}

/// <summary>
Expand All @@ -82,6 +87,7 @@ public bool TryWrite(byte[] buffer, int leasePeriodMilliseconds = 0)
/// </returns>
public bool TryLease(int leasePeriodMilliseconds)
{
#pragma warning disable CA1031 // Do not catch general exception types
try
{
return this.OnTryLease(leasePeriodMilliseconds);
Expand All @@ -91,6 +97,7 @@ public bool TryLease(int leasePeriodMilliseconds)
// TODO: log exception.
return false;
}
#pragma warning restore CA1031 // Do not catch general exception types
}

/// <summary>
Expand All @@ -101,6 +108,7 @@ public bool TryLease(int leasePeriodMilliseconds)
/// </returns>
public bool TryDelete()
{
#pragma warning disable CA1031 // Do not catch general exception types
try
{
return this.OnTryDelete();
Expand All @@ -110,9 +118,10 @@ public bool TryDelete()
// TODO: log exception.
return false;
}
#pragma warning restore CA1031 // Do not catch general exception types
}

protected abstract bool OnTryRead(out byte[] buffer);
protected abstract bool OnTryRead([NotNullWhen(true)] out byte[]? buffer);

protected abstract bool OnTryWrite(byte[] buffer, int leasePeriodMilliseconds = 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace OpenTelemetry.Extensions.PersistentStorage.Abstractions
Expand All @@ -40,8 +41,9 @@ public abstract class PersistentBlobProvider
/// <returns>
/// True if the blob was created or else false.
/// </returns>
public bool TryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out PersistentBlob blob)
public bool TryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, [NotNullWhen(true)] out PersistentBlob? blob)
{
#pragma warning disable CA1031 // Do not catch general exception types
try
{
return this.OnTryCreateBlob(buffer, leasePeriodMilliseconds, out blob);
Expand All @@ -52,6 +54,7 @@ public bool TryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out Persis
blob = null;
return false;
}
#pragma warning restore CA1031 // Do not catch general exception types
}

/// <summary>
Expand All @@ -66,8 +69,9 @@ public bool TryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out Persis
/// <returns>
/// True if the blob was created or else false.
/// </returns>
public bool TryCreateBlob(byte[] buffer, out PersistentBlob blob)
public bool TryCreateBlob(byte[] buffer, [NotNullWhen(true)] out PersistentBlob? blob)
{
#pragma warning disable CA1031 // Do not catch general exception types
try
{
return this.OnTryCreateBlob(buffer, out blob);
Expand All @@ -78,6 +82,7 @@ public bool TryCreateBlob(byte[] buffer, out PersistentBlob blob)
blob = null;
return false;
}
#pragma warning restore CA1031 // Do not catch general exception types
}

/// <summary>
Expand All @@ -89,8 +94,9 @@ public bool TryCreateBlob(byte[] buffer, out PersistentBlob blob)
/// <returns>
/// True if blob is present or else false.
/// </returns>
public bool TryGetBlob(out PersistentBlob blob)
public bool TryGetBlob([NotNullWhen(true)] out PersistentBlob? blob)
{
#pragma warning disable CA1031 // Do not catch general exception types
try
{
return this.OnTryGetBlob(out blob);
Expand All @@ -101,6 +107,7 @@ public bool TryGetBlob(out PersistentBlob blob)
blob = null;
return false;
}
#pragma warning restore CA1031 // Do not catch general exception types
}

/// <summary>
Expand All @@ -111,6 +118,7 @@ public bool TryGetBlob(out PersistentBlob blob)
/// </returns>
public IEnumerable<PersistentBlob> GetBlobs()
{
#pragma warning disable CA1031 // Do not catch general exception types
try
{
return this.OnGetBlobs() ?? Enumerable.Empty<PersistentBlob>();
Expand All @@ -120,14 +128,15 @@ public IEnumerable<PersistentBlob> GetBlobs()
// TODO: log exception
return Enumerable.Empty<PersistentBlob>();
}
#pragma warning restore CA1031 // Do not catch general exception types
}

protected abstract IEnumerable<PersistentBlob> OnGetBlobs();

protected abstract bool OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out PersistentBlob blob);
protected abstract bool OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, [NotNullWhen(true)] out PersistentBlob? blob);

protected abstract bool OnTryCreateBlob(byte[] buffer, out PersistentBlob blob);
protected abstract bool OnTryCreateBlob(byte[] buffer, [NotNullWhen(true)] out PersistentBlob? blob);

protected abstract bool OnTryGetBlob(out PersistentBlob blob);
protected abstract bool OnTryGetBlob([NotNullWhen(true)] out PersistentBlob? blob);
}
}

0 comments on commit 57c541d

Please sign in to comment.