Skip to content

Commit

Permalink
Use fields instead of getters/setters for Aeron Client
Browse files Browse the repository at this point in the history
  • Loading branch information
JPWatson committed Oct 30, 2018
1 parent d3ce581 commit 3182262
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 34 deletions.
39 changes: 15 additions & 24 deletions src/Adaptive.Aeron/Aeron.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static Aeron Connect(Context ctx)
var aeron = new Aeron(ctx);
if (ctx.UseConductorAgentInvoker())
{
aeron.ConductorAgentInvoker().Start();
aeron.ConductorAgentInvoker.Start();
}
else
{
Expand All @@ -125,7 +125,7 @@ public static Aeron Connect(Context ctx)
/// <param name="out"> to where the counters get printed. </param>
public void PrintCounters(StreamWriter @out)
{
CountersReader counters = CountersReader();
CountersReader counters = CountersReader;
counters.ForEach((value, id, label) => @out.WriteLine("{0,3}: {1:} - {2}", id, value, label));
}

Expand All @@ -134,37 +134,25 @@ public void PrintCounters(StreamWriter @out)
/// Has the client been closed? If not then the CnC file may not be unmapped.
/// </summary>
/// <returns> true if the client has been explicitly closed otherwise false. </returns>
public bool IsClosed()
{
return _isClosed.Get();
}
public bool IsClosed => _isClosed.Get();

/// <summary>
/// Get the <seealso cref="Context"/> that is used by this client.
/// </summary>
/// <returns> the <seealso cref="Context"/> that is use by this client. </returns>
public Context Ctx()
{
return _ctx;
}
public Context Ctx => _ctx;

/// <summary>
/// Get the client identity that has been allocated for communicating with the media driver.
/// </summary>
/// <returns> the client identity that has been allocated for communicating with the media driver. </returns>
public long ClientId()
{
return _clientId;
}
public long ClientId => _clientId;

/// <summary>
/// Get the <seealso cref="AgentInvoker"/> for the client conductor.
/// </summary>
/// <returns> the <seealso cref="AgentInvoker"/> for the client conductor. </returns>
public AgentInvoker ConductorAgentInvoker()
{
return _conductorInvoker;
}
public AgentInvoker ConductorAgentInvoker => _conductorInvoker;

/// <summary>
/// Clean up and release all Aeron client resources and shutdown conducator thread if not using
Expand Down Expand Up @@ -274,14 +262,17 @@ public long NextCorrelationId()
/// Get the <see cref="CountersReader"/> for the Aeron media driver counters.
/// </summary>
/// <returns> new <see cref="CountersReader"/> for the Aeron media driver in use.</returns>
public CountersReader CountersReader()
public CountersReader CountersReader
{
if (_conductor.IsClosed())
get
{
throw new AeronException("client is closed");
}
if (_conductor.IsClosed())
{
throw new AeronException("client is closed");
}

return _conductor.CountersReader();
return _conductor.CountersReader();
}
}

/// <summary>
Expand Down Expand Up @@ -1144,7 +1135,7 @@ public long ResourceLingerDurationNs()
return _resourceLingerDurationNs;
}


/// <summary>
/// Get the top level Aeron directory used for communication between the client and Media Driver, and
/// the location of the data buffers.
Expand Down
7 changes: 3 additions & 4 deletions src/Adaptive.Archiver/AeronArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ internal AeronArchive(Context ctx)

context = ctx;
aeron = ctx.AeronClient();
aeronClientInvoker = aeron.ConductorAgentInvoker();
aeronClientInvoker = aeron.ConductorAgentInvoker;
idleStrategy = ctx.IdleStrategy();
messageTimeoutNs = ctx.MessageTimeoutNs();
_lock = ctx.Lock();
nanoClock = aeron.Ctx().NanoClock();
nanoClock = aeron.Ctx.NanoClock();

subscription = aeron.AddSubscription(ctx.ControlResponseChannel(), ctx.ControlResponseStreamId());
controlResponsePoller = new ControlResponsePoller(subscription);
Expand Down Expand Up @@ -193,8 +193,7 @@ public static AsyncConnect ConnectAsync(Context ctx)
publication = aeron.AddExclusivePublication(ctx.ControlRequestChannel(), ctx.ControlRequestStreamId());
ArchiveProxy archiveProxy = new ArchiveProxy(publication,
ctx.IdleStrategy(),
aeron.Ctx()
.NanoClock(),
aeron.Ctx.NanoClock(),
messageTimeoutNs,
ArchiveProxy.DEFAULT_RETRY_ATTEMPTS);

Expand Down
2 changes: 1 addition & 1 deletion src/Adaptive.Cluster/Client/AeronCluster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private AeronCluster(Context ctx)

_aeron = ctx.Aeron();
_idleStrategy = ctx.IdleStrategy();
_nanoClock = _aeron.Ctx().NanoClock();
_nanoClock = _aeron.Ctx.NanoClock();
_isUnicast = ctx.ClusterMemberEndpoints() != null;

subscription = _aeron.AddSubscription(ctx.EgressChannel(), ctx.EgressStreamId());
Expand Down
4 changes: 2 additions & 2 deletions src/Adaptive.Cluster/Service/ClusteredServiceAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ internal ClusteredServiceAgent(ClusteredServiceContainer.Context ctx)

public void OnStart()
{
CountersReader counters = aeron.CountersReader();
CountersReader counters = aeron.CountersReader;
roleCounter = AwaitClusterRoleCounter(counters);
heartbeatCounter = AwaitHeartbeatCounter(counters);
commitPosition = AwaitCommitPositionCounter(counters);
Expand Down Expand Up @@ -599,7 +599,7 @@ private long OnTakeSnapshot(long logPosition, long leadershipTermId)

try
{
CountersReader counters = aeron.CountersReader();
CountersReader counters = aeron.CountersReader;
int counterId = AwaitRecordingCounter(publication.SessionId, counters);

recordingId = RecordingPos.GetRecordingId(counters, counterId);
Expand Down
6 changes: 3 additions & 3 deletions src/Adaptive.Cluster/Service/ClusteredServiceContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ public void Conclude()
countedErrorHandler = new CountedErrorHandler(errorHandler, errorCounter);
if (ownsAeronClient)
{
aeron.Ctx().ErrorHandler(countedErrorHandler.OnError);
aeron.Ctx.ErrorHandler(countedErrorHandler.OnError);
}
}

Expand Down Expand Up @@ -1155,7 +1155,7 @@ public void Dispose()
private void ConcludeMarkFile()
{
ClusterMarkFile.CheckHeaderLength(
aeron.Ctx().AeronDirectoryName(),
aeron.Ctx.AeronDirectoryName(),
archiveContext.ControlRequestChannel(),
ServiceControlChannel(),
null,
Expand All @@ -1171,7 +1171,7 @@ private void ConcludeMarkFile()
.IngressStreamId(0)
.MemberId(Adaptive.Aeron.Aeron.NULL_VALUE)
.ServiceId(serviceId)
.AeronDirectory(aeron.Ctx().AeronDirectoryName())
.AeronDirectory(aeron.Ctx.AeronDirectoryName())
.ArchiveChannel(archiveContext.ControlRequestChannel())
.ServiceControlChannel(serviceControlChannel)
.IngressChannel("")
Expand Down

0 comments on commit 3182262

Please sign in to comment.