diff --git a/RELEASE.md b/RELEASE.md index 0a05623d..d4ea2251 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,4 +1,4 @@ #### Port Aeron.NET has been ported against Java version: - Agrona: 0.9.12-30-gec52107 -- Aeron: 1.7.0-493-g2412c5c89 +- Aeron: 1.8.2-0-g9ca8498a5 diff --git a/driver/Aeron.Driver.nuspec b/driver/Aeron.Driver.nuspec index e6ef8f6f..a5e46afe 100644 --- a/driver/Aeron.Driver.nuspec +++ b/driver/Aeron.Driver.nuspec @@ -2,7 +2,7 @@ Aeron.Driver - 1.7.0.0 + 1.8.2 Aeron Driver Adaptive Financial Consulting Ltd. Adaptive Financial Consulting Ltd. diff --git a/driver/media-driver.jar b/driver/media-driver.jar index 969d6026..2192abc6 100644 Binary files a/driver/media-driver.jar and b/driver/media-driver.jar differ diff --git a/driver/start-media-driver.bat b/driver/start-media-driver.bat index baca03d8..46cabf4a 100644 --- a/driver/start-media-driver.bat +++ b/driver/start-media-driver.bat @@ -1,6 +1,5 @@ @echo off echo Media Driver Started... -java -cp media-driver.jar ^ - io.aeron.cluster.ClusteredMediaDriver +java -cp media-driver.jar io.aeron.driver.MediaDriver echo Media Driver Stopped. pause \ No newline at end of file diff --git a/driver/version.txt b/driver/version.txt new file mode 100644 index 00000000..88109528 --- /dev/null +++ b/driver/version.txt @@ -0,0 +1,2 @@ +v1.8.2 +http://repo1.maven.org/maven2/io/aeron/aeron-all/1.8.2/ diff --git a/src/Adaptive.Aeron.Tests/LogBuffer/TermAppenderTest.cs b/src/Adaptive.Aeron.Tests/LogBuffer/TermAppenderTest.cs index c7c2a305..eea80401 100644 --- a/src/Adaptive.Aeron.Tests/LogBuffer/TermAppenderTest.cs +++ b/src/Adaptive.Aeron.Tests/LogBuffer/TermAppenderTest.cs @@ -254,6 +254,51 @@ public void ShouldAppendFragmentedFromVectorsToEmptyLog() .Then(A.CallTo(() => _termBuffer.PutLong(tail2 + DataHeaderFlyweight.RESERVED_VALUE_OFFSET, RV, ByteOrder.LittleEndian)).MustHaveHappened()) .Then(A.CallTo(() => _termBuffer.PutIntOrdered(tail2, frameTwoLength)).MustHaveHappened()); } + + [Test] + public void ShouldAppendFragmentedFromVectorsWithNonZeroOffsetToEmptyLog() + { + var mtu = 2048; + var headerLength = _defaultHeader.Capacity; + var maxPayloadLength = mtu - headerLength; + var bufferOneLength = 64; + var offset = 15; + var bufferTwoTotalLength = 3000; + var bufferTwoLength = bufferTwoTotalLength - offset; + var bufferOne = new UnsafeBuffer(new byte[bufferOneLength]); + var bufferTwo = new UnsafeBuffer(new byte[bufferTwoTotalLength]); + bufferOne.SetMemory(0, bufferOne.Capacity, (byte) '1'); + bufferTwo.SetMemory(0, bufferTwo.Capacity, (byte) '2'); + var msgLength = bufferOneLength + bufferTwoLength; + var tail = 0; + var frameOneLength = mtu; + var frameTwoLength = (msgLength - (mtu - headerLength)) + headerLength; + var resultingOffset = frameOneLength + BitUtil.Align(frameTwoLength, FrameDescriptor.FRAME_ALIGNMENT); + + _logMetaDataBuffer.PutLong(TermTailCounterOffset, LogBufferDescriptor.PackTail(TermID, tail)); + + var vectors = new[] + { + new DirectBufferVector(bufferOne, 0, bufferOneLength), + new DirectBufferVector(bufferTwo, offset, bufferTwoLength) + }; + + Assert.That(_termAppender.AppendFragmentedMessage(_headerWriter, vectors, msgLength, maxPayloadLength, RVS, TermID), Is.EqualTo(resultingOffset)); + + var tail2 = tail + frameOneLength; + var bufferTwoOffset = maxPayloadLength - bufferOneLength + offset; + var fragmentTwoPayloadLength = bufferTwoLength - (maxPayloadLength - bufferOneLength); + + A.CallTo(() => _headerWriter.Write(_termBuffer, tail, frameOneLength, TermID)).MustHaveHappened() + .Then(A.CallTo(() => _termBuffer.PutBytes(headerLength, bufferOne, 0, bufferOneLength)).MustHaveHappened()) + .Then(A.CallTo(() => _termBuffer.PutBytes(headerLength + bufferOneLength, bufferTwo, offset, maxPayloadLength - bufferOneLength)).MustHaveHappened()) + .Then(A.CallTo(() => _termBuffer.PutLong(tail + DataHeaderFlyweight.RESERVED_VALUE_OFFSET, RV, ByteOrder.LittleEndian)).MustHaveHappened()) + .Then(A.CallTo(() => _termBuffer.PutIntOrdered(tail, frameOneLength)).MustHaveHappened()) + .Then(A.CallTo(() => _headerWriter.Write(_termBuffer, tail2, frameTwoLength, TermID)).MustHaveHappened()) + .Then(A.CallTo(() => _termBuffer.PutBytes(tail2 + headerLength, bufferTwo, bufferTwoOffset, fragmentTwoPayloadLength)).MustHaveHappened()) + .Then(A.CallTo(() => _termBuffer.PutLong(tail2 + DataHeaderFlyweight.RESERVED_VALUE_OFFSET, RV, ByteOrder.LittleEndian)).MustHaveHappened()) + .Then(A.CallTo(() => _termBuffer.PutIntOrdered(tail2, frameTwoLength)).MustHaveHappened()); + } [Test] [ExpectedException(typeof(InvalidOperationException))] diff --git a/src/Adaptive.Aeron/Adaptive.Aeron.csproj b/src/Adaptive.Aeron/Adaptive.Aeron.csproj index 6fac5898..2dc35669 100644 --- a/src/Adaptive.Aeron/Adaptive.Aeron.csproj +++ b/src/Adaptive.Aeron/Adaptive.Aeron.csproj @@ -2,7 +2,7 @@ netstandard2.0;net45 Aeron.Client - 1.7.0 + 1.8.2 Adaptive Financial Consulting Ltd. Adaptive Financial Consulting Ltd. Aeron Client diff --git a/src/Adaptive.Aeron/Aeron.cs b/src/Adaptive.Aeron/Aeron.cs index 7c1d4401..0b6bba8b 100644 --- a/src/Adaptive.Aeron/Aeron.cs +++ b/src/Adaptive.Aeron/Aeron.cs @@ -156,6 +156,17 @@ public static Aeron Connect(Context ctx) } } + /// + /// Print out the values from which can be useful for debugging. + /// + /// to where the counters get printed. + public void PrintCounters(StreamWriter @out) + { + CountersReader counters = CountersReader(); + counters.ForEach((value, id, label) => @out.WriteLine("{0,3}: {1:} - {2}", id, value, label)); + } + + /// /// Has the client been closed? If not then the CnC file may not be unmapped. /// @@ -370,7 +381,7 @@ public class Context : IDisposable private long _keepAliveInterval = KeepaliveIntervalNs; private long _interServiceTimeout = 0; private FileInfo _cncFile; - private string _aeronDirectoryName; + private string _aeronDirectoryName = GetAeronDirectoryName(); private DirectoryInfo _aeronDirectory; private long _driverTimeoutMs = DRIVER_TIMEOUT_MS; private MappedByteBuffer _cncByteBuffer; @@ -477,7 +488,7 @@ public class Context : IDisposable /// Key for the linger timeout for a publication to wait around after draining in nanoseconds. /// public const string LINGER_PARAM_NAME = "linger"; - + /// /// Valid value for when manual control is desired. /// @@ -493,9 +504,14 @@ public class Context : IDisposable /// public const string RELIABLE_STREAM_PARAM_NAME = "reliable"; - public Context() + /// + /// Get the default directory name to be used if is not set. This will take + /// the if set and if not then . + /// + /// the default directory name to be used if is not set. + public static string GetAeronDirectoryName() { - _aeronDirectoryName = Config.GetProperty(AERON_DIR_PROP_NAME, AERON_DIR_PROP_DEFAULT); + return Config.GetProperty(AERON_DIR_PROP_NAME, AERON_DIR_PROP_DEFAULT); } /// @@ -511,6 +527,15 @@ public Context ConcludeAeronDirectory() return this; } + + /// + /// Perform a shallow copy of the object. + /// + /// a shallow copy of the object. + public virtual Context Clone() + { + return (Context)MemberwiseClone(); + } /// /// This is called automatically by and its overloads. diff --git a/src/Adaptive.Aeron/ClientConductor.cs b/src/Adaptive.Aeron/ClientConductor.cs index 274356c8..b54fdf04 100644 --- a/src/Adaptive.Aeron/ClientConductor.cs +++ b/src/Adaptive.Aeron/ClientConductor.cs @@ -749,8 +749,7 @@ private int checkLingeringResources(long nowNs) if (nowNs > (resource.TimeOfLastStateChange() + RESOURCE_LINGER_NS)) { - ListUtil.FastUnorderedRemove(lingeringResources, i, lastIndex); - lastIndex--; + ListUtil.FastUnorderedRemove(lingeringResources, i, lastIndex--); resource.Delete(); } } diff --git a/src/Adaptive.Aeron/Config.cs b/src/Adaptive.Aeron/Config.cs index dc96a740..f9ab397b 100644 --- a/src/Adaptive.Aeron/Config.cs +++ b/src/Adaptive.Aeron/Config.cs @@ -37,7 +37,7 @@ static Config() } } - public static string GetProperty(string propertyName, string defaultValue) + public static string GetProperty(string propertyName, string defaultValue = null) { string value; return Params.TryGetValue(propertyName, out value) ? value : defaultValue; diff --git a/src/Adaptive.Aeron/LogBuffer/ExclusiveTermAppender.cs b/src/Adaptive.Aeron/LogBuffer/ExclusiveTermAppender.cs index 86afcae4..7d77008a 100644 --- a/src/Adaptive.Aeron/LogBuffer/ExclusiveTermAppender.cs +++ b/src/Adaptive.Aeron/LogBuffer/ExclusiveTermAppender.cs @@ -152,7 +152,7 @@ public virtual int AppendUnfragmentedMessage( int termId, int termOffset, HeaderWriter header, - UnsafeBuffer srcBuffer, + IDirectBuffer srcBuffer, int srcOffset, int length, ReservedValueSupplier reservedValueSupplier) @@ -407,7 +407,7 @@ public int AppendFragmentedMessage( int vectorRemaining = vector.length - vectorOffset; int numBytes = Math.Min(bytesToWrite - bytesWritten, vectorRemaining); - termBuffer.PutBytes(payloadOffset, vector.buffer, vectorOffset, numBytes); + termBuffer.PutBytes(payloadOffset, vector.buffer, vector.offset + vectorOffset, numBytes); bytesWritten += numBytes; payloadOffset += numBytes; diff --git a/src/Adaptive.Aeron/LogBuffer/TermAppender.cs b/src/Adaptive.Aeron/LogBuffer/TermAppender.cs index ca6ba6ef..854d0d3a 100644 --- a/src/Adaptive.Aeron/LogBuffer/TermAppender.cs +++ b/src/Adaptive.Aeron/LogBuffer/TermAppender.cs @@ -349,7 +349,7 @@ public int AppendFragmentedMessage(HeaderWriter header, DirectBufferVector[] vec int vectorRemaining = vector.length - vectorOffset; int numBytes = Math.Min(bytesToWrite - bytesWritten, vectorRemaining); - termBuffer.PutBytes(payloadOffset, vector.buffer, vectorOffset, numBytes); + termBuffer.PutBytes(payloadOffset, vector.buffer, vector.offset + vectorOffset, numBytes); bytesWritten += numBytes; payloadOffset += numBytes; diff --git a/src/Adaptive.Aeron/LogBuffers.cs b/src/Adaptive.Aeron/LogBuffers.cs index 611d478d..6bc396dc 100644 --- a/src/Adaptive.Aeron/LogBuffers.cs +++ b/src/Adaptive.Aeron/LogBuffers.cs @@ -58,7 +58,7 @@ public LogBuffers(string logFileName) // if log length exceeds MAX_INT we need multiple mapped buffers, (see FileChannel.map doc). if (logLength < int.MaxValue) { - var mappedBuffer = IoUtil.MapExistingFile(logFileName, MapMode.ReadWrite); + var mappedBuffer = IoUtil.MapExistingFile(logFileName, MapMode.ReadWrite); // TODO Java has sparse hint _mappedByteBuffers = new[] {mappedBuffer}; _logMetaDataBuffer = new UnsafeBuffer(mappedBuffer.Pointer, diff --git a/src/Adaptive.Agrona/Adaptive.Agrona.csproj b/src/Adaptive.Agrona/Adaptive.Agrona.csproj index 987cf7cb..5051c0f7 100644 --- a/src/Adaptive.Agrona/Adaptive.Agrona.csproj +++ b/src/Adaptive.Agrona/Adaptive.Agrona.csproj @@ -3,7 +3,7 @@ netstandard2.0;net45 true Agrona - 0.9.13 + 1.8.2 Adaptive Financial Consulting Ltd. Adaptive Financial Consulting Ltd. Agrona libraries initially included in Aeron Client diff --git a/src/Adaptive.Agrona/Concurrent/Status/CountersReader.cs b/src/Adaptive.Agrona/Concurrent/Status/CountersReader.cs index 262874be..46cd7c52 100644 --- a/src/Adaptive.Agrona/Concurrent/Status/CountersReader.cs +++ b/src/Adaptive.Agrona/Concurrent/Status/CountersReader.cs @@ -77,6 +77,14 @@ public class CountersReader /// for the counter. /// for the counter. public delegate void MetaData(int counterId, int typeId, IDirectBuffer keyBuffer, string label); + + /// + /// Callback function for consuming basic counter details and value. + /// + /// of the counter. + /// of the counter + /// for the counter. + public delegate void CounterConsumer(long value, int counterId, string label); /// /// Can be used to representing a null counter id when passed as a argument. @@ -244,6 +252,31 @@ public void ForEach(IntObjConsumer consumer) counterId++; } } + + /// + /// Iterate over the counters and provide the value and basic metadata. + /// + /// for each allocated counter. + public void ForEach(CounterConsumer consumer) + { + int counterId = 0; + + for (int i = 0, capacity = MetaDataBuffer.Capacity; i < capacity; i += METADATA_LENGTH) + { + int recordStatus = MetaDataBuffer.GetIntVolatile(i); + + if (RECORD_ALLOCATED == recordStatus) + { + consumer(ValuesBuffer.GetLongVolatile(CounterOffset(counterId)), counterId, LabelValue(i)); + } + else if (RECORD_UNUSED == recordStatus) + { + break; + } + + counterId++; + } + } /// /// Iterate over all the metadata in the buffer. diff --git a/src/Adaptive.Agrona/CncFile.cs b/src/Adaptive.Agrona/MarkFile.cs similarity index 84% rename from src/Adaptive.Agrona/CncFile.cs rename to src/Adaptive.Agrona/MarkFile.cs index 1494a08b..28310c2c 100644 --- a/src/Adaptive.Agrona/CncFile.cs +++ b/src/Adaptive.Agrona/MarkFile.cs @@ -12,15 +12,15 @@ namespace Adaptive.Agrona /// The assumptions are: (1) the version field is an int in size, (2) the timestamp field is a long in size, /// and (3) the version field comes before the timestamp field. /// - public class CncFile : IDisposable + public class MarkFile : IDisposable { private readonly int versionFieldOffset; private readonly int timestampFieldOffset; - private readonly DirectoryInfo cncDir; - private readonly FileInfo cncFile; - private readonly MappedByteBuffer mappedCncBuffer; - private readonly UnsafeBuffer cncBuffer; + private readonly DirectoryInfo parentDir; + private readonly FileInfo markFile; + private readonly MappedByteBuffer mappedBuffer; + private readonly UnsafeBuffer buffer; private volatile bool isClosed = false; @@ -41,7 +41,7 @@ public class CncFile : IDisposable /// to use for time checks /// to use for existing CnC file and version field /// to use to signal progress or null - public CncFile(DirectoryInfo directory, string filename, bool warnIfDirectoryExists, bool dirDeleteOnStart, + public MarkFile(DirectoryInfo directory, string filename, bool warnIfDirectoryExists, bool dirDeleteOnStart, int versionFieldOffset, int timestampFieldOffset, int totalFileLength, long timeoutMs, IEpochClock epochClock, Action versionCheck, Action logger) { @@ -50,10 +50,10 @@ public CncFile(DirectoryInfo directory, string filename, bool warnIfDirectoryExi EnsureDirectoryExists(directory, filename, warnIfDirectoryExists, dirDeleteOnStart, versionFieldOffset, timestampFieldOffset, timeoutMs, epochClock, versionCheck, logger); - this.cncDir = directory; - this.cncFile = new FileInfo(Path.Combine(directory.Name, filename)); - this.mappedCncBuffer = MapNewFile(cncFile, totalFileLength); - this.cncBuffer = new UnsafeBuffer(mappedCncBuffer.Pointer, totalFileLength); + this.parentDir = directory; + this.markFile = new FileInfo(Path.Combine(directory.Name, filename)); + this.mappedBuffer = MapNewFile(markFile, totalFileLength); + this.buffer = new UnsafeBuffer(mappedBuffer.Pointer, totalFileLength); this.versionFieldOffset = versionFieldOffset; this.timestampFieldOffset = timestampFieldOffset; } @@ -64,7 +64,7 @@ public CncFile(DirectoryInfo directory, string filename, bool warnIfDirectoryExi /// /// Total length of CnC file will be mapped until is called. /// - /// to use + /// to use /// or not /// to use for version field access /// to use for timestamp field access @@ -73,18 +73,18 @@ public CncFile(DirectoryInfo directory, string filename, bool warnIfDirectoryExi /// to use for time checks /// to use for existing CnC file and version field /// to use to signal progress or null - public CncFile(FileInfo cncFile, bool shouldPreExist, int versionFieldOffset, int timestampFieldOffset, + public MarkFile(FileInfo markFile, bool shouldPreExist, int versionFieldOffset, int timestampFieldOffset, int totalFileLength, long timeoutMs, IEpochClock epochClock, Action versionCheck, Action logger) { ValidateOffsets(versionFieldOffset, timestampFieldOffset); - this.cncDir = cncFile.Directory; - this.cncFile = cncFile; - this.mappedCncBuffer = MapNewOrExistingCncFile(cncFile, shouldPreExist, versionFieldOffset, + this.parentDir = markFile.Directory; + this.markFile = markFile; + this.mappedBuffer = MapNewOrExistingCncFile(markFile, shouldPreExist, versionFieldOffset, timestampFieldOffset, totalFileLength, timeoutMs, epochClock, versionCheck, logger); - this.cncBuffer = new UnsafeBuffer(mappedCncBuffer.Pointer, totalFileLength); + this.buffer = new UnsafeBuffer(mappedBuffer.Pointer, totalFileLength); this.versionFieldOffset = versionFieldOffset; this.timestampFieldOffset = timestampFieldOffset; } @@ -102,16 +102,16 @@ public CncFile(FileInfo cncFile, bool shouldPreExist, int versionFieldOffset, in /// to use for time checks /// to use for existing CnC file and version field /// to use to signal progress or null - public CncFile(DirectoryInfo directory, string filename, int versionFieldOffset, int timestampFieldOffset, + public MarkFile(DirectoryInfo directory, string filename, int versionFieldOffset, int timestampFieldOffset, long timeoutMs, IEpochClock epochClock, Action versionCheck, Action logger) { ValidateOffsets(versionFieldOffset, timestampFieldOffset); - this.cncDir = directory; - this.cncFile = new FileInfo(Path.Combine(directory.FullName, filename)); - this.mappedCncBuffer = MapExistingCncFile(cncFile, versionFieldOffset, timestampFieldOffset, timeoutMs, + this.parentDir = directory; + this.markFile = new FileInfo(Path.Combine(directory.FullName, filename)); + this.mappedBuffer = MapExistingCncFile(markFile, versionFieldOffset, timestampFieldOffset, timeoutMs, epochClock, versionCheck, logger); - this.cncBuffer = new UnsafeBuffer(mappedCncBuffer); + this.buffer = new UnsafeBuffer(mappedBuffer); this.versionFieldOffset = versionFieldOffset; this.timestampFieldOffset = timestampFieldOffset; } @@ -121,17 +121,17 @@ public CncFile(DirectoryInfo directory, string filename, int versionFieldOffset, /// /// If mappedCncBuffer is not null, then it will be unmapped upon . /// - /// for the CnC fields + /// for the CnC fields /// for the version field /// for the timestamp field - public CncFile(MappedByteBuffer mappedCncBuffer, int versionFieldOffset, int timestampFieldOffset) + public MarkFile(MappedByteBuffer mappedBuffer, int versionFieldOffset, int timestampFieldOffset) { ValidateOffsets(versionFieldOffset, timestampFieldOffset); - this.cncDir = null; - this.cncFile = null; - this.mappedCncBuffer = mappedCncBuffer; - this.cncBuffer = new UnsafeBuffer(mappedCncBuffer); + this.parentDir = null; + this.markFile = null; + this.mappedBuffer = mappedBuffer; + this.buffer = new UnsafeBuffer(mappedBuffer); this.versionFieldOffset = versionFieldOffset; this.timestampFieldOffset = timestampFieldOffset; } @@ -139,17 +139,17 @@ public CncFile(MappedByteBuffer mappedCncBuffer, int versionFieldOffset, int tim /// /// Manage a CnC file given a buffer and offsets of version and timestamp. /// - /// for the CnC fields + /// for the CnC fields /// for the version field /// for the timestamp field - public CncFile(UnsafeBuffer cncBuffer, int versionFieldOffset, int timestampFieldOffset) + public MarkFile(UnsafeBuffer buffer, int versionFieldOffset, int timestampFieldOffset) { ValidateOffsets(versionFieldOffset, timestampFieldOffset); - this.cncDir = null; - this.cncFile = null; - this.mappedCncBuffer = null; - this.cncBuffer = cncBuffer; + this.parentDir = null; + this.markFile = null; + this.mappedBuffer = null; + this.buffer = buffer; this.versionFieldOffset = versionFieldOffset; this.timestampFieldOffset = timestampFieldOffset; } @@ -163,68 +163,68 @@ public void Dispose() { if (!isClosed) { - if (null != mappedCncBuffer) + if (null != mappedBuffer) { - IoUtil.Unmap(mappedCncBuffer); + IoUtil.Unmap(mappedBuffer); } isClosed = true; } } - public virtual void SignalCncReady(int version) + public virtual void SignalReady(int version) { - cncBuffer.PutIntOrdered(versionFieldOffset, version); + buffer.PutIntOrdered(versionFieldOffset, version); } public virtual int VersionVolatile() { - return cncBuffer.GetIntVolatile(versionFieldOffset); + return buffer.GetIntVolatile(versionFieldOffset); } public virtual int VersionWeak() { - return cncBuffer.GetInt(versionFieldOffset); + return buffer.GetInt(versionFieldOffset); } public virtual void TimestampOrdered(long timestamp) { - cncBuffer.PutLongOrdered(timestampFieldOffset, timestamp); + buffer.PutLongOrdered(timestampFieldOffset, timestamp); } public virtual long TimestampVolatile() { - return cncBuffer.GetLongVolatile(timestampFieldOffset); + return buffer.GetLongVolatile(timestampFieldOffset); } public virtual long TimestampWeak() { - return cncBuffer.GetLong(timestampFieldOffset); + return buffer.GetLong(timestampFieldOffset); } public virtual void DeleteDirectory(bool ignoreFailures) { - IoUtil.Delete(cncDir, ignoreFailures); + IoUtil.Delete(parentDir, ignoreFailures); } public virtual DirectoryInfo CncDirectory() { - return cncDir; + return parentDir; } public virtual FileInfo CncFileName() { - return cncFile; + return markFile; } public virtual MappedByteBuffer MappedByteBuffer() { - return mappedCncBuffer; + return mappedBuffer; } public virtual UnsafeBuffer Buffer() { - return cncBuffer; + return buffer; } public static void EnsureDirectoryExists(DirectoryInfo directory, string filename, bool warnIfDirectoryExists, diff --git a/src/Adaptive.Archiver/Adaptive.Archiver.csproj b/src/Adaptive.Archiver/Adaptive.Archiver.csproj index 659db171..f577813c 100644 --- a/src/Adaptive.Archiver/Adaptive.Archiver.csproj +++ b/src/Adaptive.Archiver/Adaptive.Archiver.csproj @@ -3,7 +3,7 @@ netstandard2.0;net45 true Aeron.Archiver - 1.7.0 + 1.8.2 Adaptive Financial Consulting Ltd. Adaptive Financial Consulting Ltd. Clustering libraries over the Aeron transport diff --git a/src/Adaptive.Archiver/AeronArchive.cs b/src/Adaptive.Archiver/AeronArchive.cs index f8c21f82..e157feb4 100644 --- a/src/Adaptive.Archiver/AeronArchive.cs +++ b/src/Adaptive.Archiver/AeronArchive.cs @@ -299,7 +299,7 @@ public ExclusivePublication AddRecordedExclusivePublication(string channel, int { _lock.Unlock(); } - + return publication; } @@ -589,7 +589,7 @@ public int ListRecordings(long fromRecordingId, int recordCount, IRecordingDescr /// /// at which to begin the listing. /// to limit for each query. - /// to match. + /// for a contains match on the stripped channel stored with the archive descriptor. /// to match. /// to which the descriptors are dispatched. /// the number of descriptors found and consumed. @@ -818,7 +818,7 @@ public class Configuration public const string MESSAGE_TIMEOUT_PROP_NAME = "aeron.archive.message.timeout"; /// - /// Timeout when waiting on a message to be sent or received. Default to 5 seconds in nanoseconds. + /// Timeout when waiting on a message to be sent or received. /// public static readonly long MESSAGE_TIMEOUT_DEFAULT_NS = 5000000000; @@ -828,7 +828,7 @@ public class Configuration public const string CONTROL_CHANNEL_PROP_NAME = "aeron.archive.control.channel"; /// - /// Channel for sending control messages to an archive. Default to localhost:8010. + /// Channel for sending control messages to an archive. /// public const string CONTROL_CHANNEL_DEFAULT = "aeron:udp?endpoint=localhost:8010"; @@ -838,9 +838,9 @@ public class Configuration public const string CONTROL_STREAM_ID_PROP_NAME = "aeron.archive.control.stream.id"; /// - /// Stream id within a channel for sending control messages to an archive. Default to stream id of 0. + /// Stream id within a channel for sending control messages to an archive. /// - public const int CONTROL_STREAM_ID_DEFAULT = 0; + public const int CONTROL_STREAM_ID_DEFAULT = 10; /// /// Channel for sending control messages to a driver local archive. @@ -859,9 +859,8 @@ public class Configuration /// /// Stream id within a channel for sending control messages to a driver local archive. - /// Default to stream id of 10. /// - public const int LOCAL_CONTROL_STREAM_ID_DEFAULT = 10; + public const int LOCAL_CONTROL_STREAM_ID_DEFAULT = 11; /// /// Channel for receiving control response messages from an archive. @@ -869,7 +868,7 @@ public class Configuration public const string CONTROL_RESPONSE_CHANNEL_PROP_NAME = "aeron.archive.control.response.channel"; /// - /// Channel for receiving control response messages from an archive. Default to localhost:8020. + /// Channel for receiving control response messages from an archive. /// public const string CONTROL_RESPONSE_CHANNEL_DEFAULT = "aeron:udp?endpoint=localhost:8020"; @@ -879,9 +878,9 @@ public class Configuration public const string CONTROL_RESPONSE_STREAM_ID_PROP_NAME = "aeron.archive.control.response.stream.id"; /// - /// Stream id within a channel for receiving control messages from an archive. Default to stream id of 0. + /// Stream id within a channel for receiving control messages from an archive. /// - public const int CONTROL_RESPONSE_STREAM_ID_DEFAULT = 0; + public const int CONTROL_RESPONSE_STREAM_ID_DEFAULT = 20; /// /// Channel for receiving progress events of recordings from an archive. @@ -889,11 +888,11 @@ public class Configuration public const string RECORDING_EVENTS_CHANNEL_PROP_NAME = "aeron.archive.recording.events.channel"; /// - /// Channel for receiving progress events of recordings from an archive. Defaults to localhost:8011. + /// Channel for receiving progress events of recordings from an archive. /// For production it is recommended that multicast or dynamic multi-destination-cast (MDC) is used to allow /// for dynamic subscribers. /// - public const string RECORDING_EVENTS_CHANNEL_DEFAULT = "aeron:udp?endpoint=localhost:8011"; + public const string RECORDING_EVENTS_CHANNEL_DEFAULT = "aeron:udp?endpoint=localhost:8030"; /// /// Stream id within a channel for receiving progress of recordings from an archive. @@ -901,9 +900,9 @@ public class Configuration public const string RECORDING_EVENTS_STREAM_ID_PROP_NAME = "aeron.archive.recording.events.stream.id"; /// - /// Stream id within a channel for receiving progress of recordings from an archive. Default to a stream id of 0. + /// Stream id within a channel for receiving progress of recordings from an archive. /// - public const int RECORDING_EVENTS_STREAM_ID_DEFAULT = 0; + public const int RECORDING_EVENTS_STREAM_ID_DEFAULT = 30; /// /// Term length for control streams. @@ -1061,10 +1060,15 @@ public class Context : IDisposable internal IIdleStrategy idleStrategy; internal ILock _lock; - internal string aeronDirectoryName; + internal string aeronDirectoryName = Aeron.Aeron.Context.GetAeronDirectoryName(); internal Aeron.Aeron aeron; internal bool ownsAeronClient = false; + public Context Clone() + { + return (Context) MemberwiseClone(); + } + /// /// Conclude configuration by setting up defaults when specifics are not provided. /// @@ -1072,14 +1076,7 @@ public void Conclude() { if (null == aeron) { - var ctx = new Aeron.Aeron.Context(); - - if (aeronDirectoryName != null) - { - ctx.AeronDirectoryName(aeronDirectoryName); - } - - aeron = Aeron.Aeron.Connect(ctx); + aeron = Aeron.Aeron.Connect(new Aeron.Aeron.Context().AeronDirectoryName(aeronDirectoryName)); ownsAeronClient = true; } diff --git a/src/Adaptive.Cluster/Adaptive.Cluster.csproj b/src/Adaptive.Cluster/Adaptive.Cluster.csproj index 714c56d2..dfe494e4 100644 --- a/src/Adaptive.Cluster/Adaptive.Cluster.csproj +++ b/src/Adaptive.Cluster/Adaptive.Cluster.csproj @@ -3,7 +3,7 @@ netstandard2.0;net45 true Aeron.Cluster - 1.7.0 + 1.8.2 Adaptive Financial Consulting Ltd. Adaptive Financial Consulting Ltd. Clustering libraries over the Aeron transport diff --git a/src/Adaptive.Cluster/Client/AeronCluster.cs b/src/Adaptive.Cluster/Client/AeronCluster.cs index dc48e1ac..5f657263 100644 --- a/src/Adaptive.Cluster/Client/AeronCluster.cs +++ b/src/Adaptive.Cluster/Client/AeronCluster.cs @@ -1,5 +1,6 @@ using System; using System.Security.Authentication; +using System.Text; using Adaptive.Aeron; using Adaptive.Aeron.LogBuffer; using Adaptive.Agrona; @@ -33,6 +34,7 @@ public sealed class AeronCluster : IDisposable private readonly BufferClaim _bufferClaim = new BufferClaim(); private readonly MessageHeaderEncoder _messageHeaderEncoder = new MessageHeaderEncoder(); private readonly SessionKeepAliveRequestEncoder _keepAliveRequestEncoder = new SessionKeepAliveRequestEncoder(); + private readonly AdminQueryEncoder _adminQueryEncoder = new AdminQueryEncoder(); /// /// Connect to the cluster using default configuration. @@ -206,6 +208,84 @@ public bool SendKeepAlive() } } + /// + /// Query cluster member for endpoint information. + /// + /// + /// id=num,memberStatus=member-facing:port,log=log:port,archive=archive:port + /// + /// + /// + /// + /// result of query. + public string QueryForEndpoints() + { + _lock.Lock(); + try + { + long deadlineNs = _nanoClock.NanoTime() + _ctx.MessageTimeoutNs(); + long correlationId = SendAdminQuery(AdminQueryType.ENDPOINTS, deadlineNs); + EgressPoller poller = new EgressPoller(_subscription, FRAGMENT_LIMIT); + + while (true) + { + PollNextResponse(deadlineNs, correlationId, poller); + + if (poller.CorrelationId() == correlationId) + { + if (poller.TemplateId() == AdminResponseDecoder.TEMPLATE_ID) + { + return Encoding.ASCII.GetString(poller.AdminResponseData()); // TODO check default charset for Java + } + else if (poller.EventCode() == EventCode.ERROR) + { + throw new InvalidOperationException(poller.Detail()); + } + } + } + } + finally + { + _lock.Unlock(); + } + } + + /// + /// Query cluster member for recording log information. + /// + /// result of query. + public byte[] QueryForRecordingLog() + { + _lock.Lock(); + try + { + long deadlineNs = _nanoClock.NanoTime() + _ctx.MessageTimeoutNs(); + long correlationId = SendAdminQuery(AdminQueryType.RECORDING_LOG, deadlineNs); + EgressPoller poller = new EgressPoller(_subscription, FRAGMENT_LIMIT); + + while (true) + { + PollNextResponse(deadlineNs, correlationId, poller); + + if (poller.CorrelationId() == correlationId) + { + if (poller.TemplateId() == AdminResponseDecoder.TEMPLATE_ID) + { + return poller.AdminResponseData(); + } + else if (poller.EventCode() == EventCode.ERROR) + { + throw new InvalidOperationException(poller.Detail()); + } + } + } + } + finally + { + _lock.Unlock(); + } + } + private void CloseSession() { _idleStrategy.Reset(); @@ -415,6 +495,44 @@ private long SendConnectRequest(byte[] credentialData, long deadlineNs) return correlationId; } + private long SendAdminQuery(AdminQueryType queryType, long deadlineNs) + { + long correlationId = _aeron.NextCorrelationId(); + int length = MessageHeaderEncoder.ENCODED_LENGTH + AdminQueryEncoder.BLOCK_LENGTH; + int attempts = SEND_ATTEMPTS; + + _idleStrategy.Reset(); + + while (true) + { + long result = _publication.TryClaim(length, _bufferClaim); + + if (result > 0) + { + _adminQueryEncoder + .WrapAndApplyHeader(_bufferClaim.Buffer, _bufferClaim.Offset, _messageHeaderEncoder) + .CorrelationId(correlationId) + .ClusterSessionId(_clusterSessionId) + .QueryType(queryType); + + _bufferClaim.Commit(); + + break; + } + + CheckResult(result); + + if (--attempts <= 0 || _nanoClock.NanoTime() > deadlineNs) + { + throw new TimeoutException("Failed to send query"); + } + + _idleStrategy.Idle(); + } + + return correlationId; + } + private long SendChallengeResponse(long sessionId, byte[] credentialData, long deadlineNs) { long correlationId = _aeron.NextCorrelationId(); @@ -481,7 +599,7 @@ public class Configuration public const string CLUSTER_MEMBER_ENDPOINTS_PROP_NAME = "aeron.cluster.member.endpoints"; /// - /// Property name for the comma separated list of cluster member endpoints. Default of null is for multicast. + /// Property name for the comma separated list of cluster member endpoints. /// public const string CLUSTER_MEMBER_ENDPOINTS_DEFAULT = null; @@ -492,7 +610,7 @@ public class Configuration public const string INGRESS_CHANNEL_PROP_NAME = "aeron.cluster.ingress.channel"; /// - /// Channel for sending messages to a cluster. Default to localhost:9010 for testing. + /// Channel for sending messages to a cluster. /// public const string INGRESS_CHANNEL_DEFAULT = "aeron:udp?endpoint=localhost:9010"; @@ -502,7 +620,7 @@ public class Configuration public const string INGRESS_STREAM_ID_PROP_NAME = "aeron.cluster.ingress.stream.id"; /// - /// Stream id within a channel for sending messages to a cluster. Default to stream id of 1. + /// Stream id within a channel for sending messages to a cluster. /// public const int INGRESS_STREAM_ID_DEFAULT = 1; @@ -512,7 +630,7 @@ public class Configuration public const string EGRESS_CHANNEL_PROP_NAME = "aeron.cluster.egress.channel"; /// - /// Channel for receiving response messages from a cluster. Default to localhost:9020 for testing. + /// Channel for receiving response messages from a cluster. /// public const string EGRESS_CHANNEL_DEFAULT = "aeron:udp?endpoint=localhost:9020"; @@ -522,7 +640,7 @@ public class Configuration public const string EGRESS_STREAM_ID_PROP_NAME = "aeron.archive.control.response.stream.id"; /// - /// Stream id within a channel for receiving messages from a cluster. Default to stream id of 2. + /// Stream id within a channel for receiving messages from a cluster. /// public const int EGRESS_STREAM_ID_DEFAULT = 2; @@ -607,24 +725,27 @@ public class Context : IDisposable private int _egressStreamId = Configuration.EgressStreamId(); private IIdleStrategy _idleStrategy; private ILock _lock; - private string _aeronDirectoryName; + private string _aeronDirectoryName = Adaptive.Aeron.Aeron.Context.GetAeronDirectoryName(); private Aeron.Aeron _aeron; private ICredentialsSupplier _credentialsSupplier; - private bool _ownsAeronClient = true; + private bool _ownsAeronClient = false; private bool _isIngressExclusive = true; + /// + /// Perform a shallow copy of the object. + /// + /// a shall copy of the object. + public Context Clone() + { + return (Context)MemberwiseClone(); + } + public void Conclude() { if (null == _aeron) { - var ctx = new Aeron.Aeron.Context(); - - if (_aeronDirectoryName != null) - { - ctx.AeronDirectoryName(_aeronDirectoryName); - } - - _aeron = Adaptive.Aeron.Aeron.Connect(ctx); + _aeron = Adaptive.Aeron.Aeron.Connect(new Aeron.Aeron.Context().AeronDirectoryName(_aeronDirectoryName)); + _ownsAeronClient = true; } if (null == _idleStrategy) diff --git a/src/Adaptive.Cluster/Client/EgressPoller.cs b/src/Adaptive.Cluster/Client/EgressPoller.cs index e9ee069f..3301461f 100644 --- a/src/Adaptive.Cluster/Client/EgressPoller.cs +++ b/src/Adaptive.Cluster/Client/EgressPoller.cs @@ -14,6 +14,7 @@ public class EgressPoller : IControlledFragmentHandler private readonly NewLeaderEventDecoder newLeaderEventDecoder = new NewLeaderEventDecoder(); private readonly SessionHeaderDecoder sessionHeaderDecoder = new SessionHeaderDecoder(); private readonly ChallengeDecoder challengeDecoder = new ChallengeDecoder(); + private readonly AdminResponseDecoder adminResponseDecoder = new AdminResponseDecoder(); private readonly ControlledFragmentAssembler fragmentAssembler; private readonly Subscription subscription; private long clusterSessionId = -1; @@ -23,6 +24,7 @@ public class EgressPoller : IControlledFragmentHandler private EventCode eventCode; private string detail = ""; private byte[] challengeData; + private byte[] adminResponseData; public EgressPoller(Subscription subscription, int fragmentLimit) { @@ -94,6 +96,15 @@ public byte[] ChallengeData() { return challengeData; } + + /// + /// Get the response data in the last admin response. + /// + /// the response data in the last admin response or null if last message was not an admin response. + public byte[] AdminResponseData() + { + return adminResponseData; + } /// /// Has the last polling action received a complete event? @@ -121,6 +132,7 @@ public int Poll() eventCode = Codecs.EventCode.NULL_VALUE; detail = ""; challengeData = null; + adminResponseData = null; pollComplete = false; return subscription.ControlledPoll(fragmentAssembler, fragmentLimit); @@ -168,6 +180,21 @@ public ControlledFragmentHandlerAction OnFragment(IDirectBuffer buffer, int offs clusterSessionId = challengeDecoder.ClusterSessionId(); correlationId = challengeDecoder.CorrelationId(); break; + + case AdminResponseDecoder.TEMPLATE_ID: + adminResponseDecoder.Wrap( + buffer, + offset + MessageHeaderDecoder.ENCODED_LENGTH, + messageHeaderDecoder.BlockLength(), + messageHeaderDecoder.Version()); + + adminResponseData = new byte[adminResponseDecoder.ResponseDataLength()]; + adminResponseDecoder.GetResponseData(adminResponseData, 0, adminResponseDecoder.ResponseDataLength()); + + clusterSessionId = adminResponseDecoder.ClusterSessionId(); + correlationId = adminResponseDecoder.CorrelationId(); + break; + default: throw new InvalidOperationException("Unknown templateId: " + templateId); diff --git a/src/Adaptive.Cluster/Codecs/AdminQueryDecoder.cs b/src/Adaptive.Cluster/Codecs/AdminQueryDecoder.cs new file mode 100644 index 00000000..e436ae0c --- /dev/null +++ b/src/Adaptive.Cluster/Codecs/AdminQueryDecoder.cs @@ -0,0 +1,287 @@ +/* Generated SBE (Simple Binary Encoding) message codec */ +using System; +using System.Text; +using System.Collections.Generic; +using Adaptive.Agrona; + + +namespace Adaptive.Cluster.Codecs { + +public class AdminQueryDecoder +{ + public const ushort BLOCK_LENGTH = 20; + public const ushort TEMPLATE_ID = 9; + public const ushort SCHEMA_ID = 1; + public const ushort SCHEMA_VERSION = 1; + + private AdminQueryDecoder _parentMessage; + private IDirectBuffer _buffer; + protected int _offset; + protected int _limit; + protected int _actingBlockLength; + protected int _actingVersion; + + public AdminQueryDecoder() + { + _parentMessage = this; + } + + public ushort SbeBlockLength() + { + return BLOCK_LENGTH; + } + + public ushort SbeTemplateId() + { + return TEMPLATE_ID; + } + + public ushort SbeSchemaId() + { + return SCHEMA_ID; + } + + public ushort SbeSchemaVersion() + { + return SCHEMA_VERSION; + } + + public string SbeSemanticType() + { + return ""; + } + + public IDirectBuffer Buffer() + { + return _buffer; + } + + public int Offset() + { + return _offset; + } + + public AdminQueryDecoder Wrap( + IDirectBuffer buffer, int offset, int actingBlockLength, int actingVersion) + { + this._buffer = buffer; + this._offset = offset; + this._actingBlockLength = actingBlockLength; + this._actingVersion = actingVersion; + Limit(offset + actingBlockLength); + + return this; + } + + public int EncodedLength() + { + return _limit - _offset; + } + + public int Limit() + { + return _limit; + } + + public void Limit(int limit) + { + this._limit = limit; + } + + public static int CorrelationIdId() + { + return 1; + } + + public static int CorrelationIdSinceVersion() + { + return 0; + } + + public static int CorrelationIdEncodingOffset() + { + return 0; + } + + public static int CorrelationIdEncodingLength() + { + return 8; + } + + public static string CorrelationIdMetaAttribute(MetaAttribute metaAttribute) + { + switch (metaAttribute) + { + case MetaAttribute.EPOCH: return "unix"; + case MetaAttribute.TIME_UNIT: return "nanosecond"; + case MetaAttribute.SEMANTIC_TYPE: return ""; + case MetaAttribute.PRESENCE: return "required"; + } + + return ""; + } + + public static long CorrelationIdNullValue() + { + return -9223372036854775808L; + } + + public static long CorrelationIdMinValue() + { + return -9223372036854775807L; + } + + public static long CorrelationIdMaxValue() + { + return 9223372036854775807L; + } + + public long CorrelationId() + { + return _buffer.GetLong(_offset + 0, ByteOrder.LittleEndian); + } + + + public static int ClusterSessionIdId() + { + return 2; + } + + public static int ClusterSessionIdSinceVersion() + { + return 0; + } + + public static int ClusterSessionIdEncodingOffset() + { + return 8; + } + + public static int ClusterSessionIdEncodingLength() + { + return 8; + } + + public static string ClusterSessionIdMetaAttribute(MetaAttribute metaAttribute) + { + switch (metaAttribute) + { + case MetaAttribute.EPOCH: return "unix"; + case MetaAttribute.TIME_UNIT: return "nanosecond"; + case MetaAttribute.SEMANTIC_TYPE: return ""; + case MetaAttribute.PRESENCE: return "required"; + } + + return ""; + } + + public static long ClusterSessionIdNullValue() + { + return -9223372036854775808L; + } + + public static long ClusterSessionIdMinValue() + { + return -9223372036854775807L; + } + + public static long ClusterSessionIdMaxValue() + { + return 9223372036854775807L; + } + + public long ClusterSessionId() + { + return _buffer.GetLong(_offset + 8, ByteOrder.LittleEndian); + } + + + public static int QueryTypeId() + { + return 3; + } + + public static int QueryTypeSinceVersion() + { + return 0; + } + + public static int QueryTypeEncodingOffset() + { + return 16; + } + + public static int QueryTypeEncodingLength() + { + return 4; + } + + public static string QueryTypeMetaAttribute(MetaAttribute metaAttribute) + { + switch (metaAttribute) + { + case MetaAttribute.EPOCH: return "unix"; + case MetaAttribute.TIME_UNIT: return "nanosecond"; + case MetaAttribute.SEMANTIC_TYPE: return ""; + case MetaAttribute.PRESENCE: return "required"; + } + + return ""; + } + + public AdminQueryType QueryType() + { + return (AdminQueryType)_buffer.GetInt(_offset + 16, ByteOrder.LittleEndian); + } + + + + public override string ToString() + { + return AppendTo(new StringBuilder(100)).ToString(); + } + + public StringBuilder AppendTo(StringBuilder builder) + { + int originalLimit = Limit(); + Limit(_offset + _actingBlockLength); + builder.Append("[AdminQuery](sbeTemplateId="); + builder.Append(TEMPLATE_ID); + builder.Append("|sbeSchemaId="); + builder.Append(SCHEMA_ID); + builder.Append("|sbeSchemaVersion="); + if (_parentMessage._actingVersion != SCHEMA_VERSION) + { + builder.Append(_parentMessage._actingVersion); + builder.Append('/'); + } + builder.Append(SCHEMA_VERSION); + builder.Append("|sbeBlockLength="); + if (_actingBlockLength != BLOCK_LENGTH) + { + builder.Append(_actingBlockLength); + builder.Append('/'); + } + builder.Append(BLOCK_LENGTH); + builder.Append("):"); + //Token{signal=BEGIN_FIELD, name='correlationId', referencedName='null', description='null', id=1, version=0, deprecated=0, encodedLength=0, offset=0, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=ENCODING, name='int64', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=8, offset=0, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT64, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + builder.Append("CorrelationId="); + builder.Append(CorrelationId()); + builder.Append('|'); + //Token{signal=BEGIN_FIELD, name='clusterSessionId', referencedName='null', description='null', id=2, version=0, deprecated=0, encodedLength=0, offset=8, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=ENCODING, name='int64', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=8, offset=8, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT64, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + builder.Append("ClusterSessionId="); + builder.Append(ClusterSessionId()); + builder.Append('|'); + //Token{signal=BEGIN_FIELD, name='queryType', referencedName='null', description='null', id=3, version=0, deprecated=0, encodedLength=0, offset=16, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_ENUM, name='AdminQueryType', referencedName='null', description='Type of admin qery', id=-1, version=0, deprecated=0, encodedLength=4, offset=16, componentTokenCount=4, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='null', timeUnit=null, semanticType='null'}} + builder.Append("QueryType="); + builder.Append(QueryType()); + + Limit(originalLimit); + + return builder; + } +} +} diff --git a/src/Adaptive.Cluster/Codecs/AdminQueryEncoder.cs b/src/Adaptive.Cluster/Codecs/AdminQueryEncoder.cs new file mode 100644 index 00000000..3f62438b --- /dev/null +++ b/src/Adaptive.Cluster/Codecs/AdminQueryEncoder.cs @@ -0,0 +1,193 @@ +/* Generated SBE (Simple Binary Encoding) message codec */ +using System; +using System.Text; +using System.Collections.Generic; +using Adaptive.Agrona; + + +namespace Adaptive.Cluster.Codecs { + +public class AdminQueryEncoder +{ + public const ushort BLOCK_LENGTH = 20; + public const ushort TEMPLATE_ID = 9; + public const ushort SCHEMA_ID = 1; + public const ushort SCHEMA_VERSION = 1; + + private AdminQueryEncoder _parentMessage; + private IMutableDirectBuffer _buffer; + protected int _offset; + protected int _limit; + + public AdminQueryEncoder() + { + _parentMessage = this; + } + + public ushort SbeBlockLength() + { + return BLOCK_LENGTH; + } + + public ushort SbeTemplateId() + { + return TEMPLATE_ID; + } + + public ushort SbeSchemaId() + { + return SCHEMA_ID; + } + + public ushort SbeSchemaVersion() + { + return SCHEMA_VERSION; + } + + public string SbeSemanticType() + { + return ""; + } + + public IMutableDirectBuffer Buffer() + { + return _buffer; + } + + public int Offset() + { + return _offset; + } + + public AdminQueryEncoder Wrap(IMutableDirectBuffer buffer, int offset) + { + this._buffer = buffer; + this._offset = offset; + Limit(offset + BLOCK_LENGTH); + + return this; + } + + public AdminQueryEncoder WrapAndApplyHeader( + IMutableDirectBuffer buffer, int offset, MessageHeaderEncoder headerEncoder) + { + headerEncoder + .Wrap(buffer, offset) + .BlockLength(BLOCK_LENGTH) + .TemplateId(TEMPLATE_ID) + .SchemaId(SCHEMA_ID) + .Version(SCHEMA_VERSION); + + return Wrap(buffer, offset + MessageHeaderEncoder.ENCODED_LENGTH); + } + + public int EncodedLength() + { + return _limit - _offset; + } + + public int Limit() + { + return _limit; + } + + public void Limit(int limit) + { + this._limit = limit; + } + + public static int CorrelationIdEncodingOffset() + { + return 0; + } + + public static int CorrelationIdEncodingLength() + { + return 8; + } + + public static long CorrelationIdNullValue() + { + return -9223372036854775808L; + } + + public static long CorrelationIdMinValue() + { + return -9223372036854775807L; + } + + public static long CorrelationIdMaxValue() + { + return 9223372036854775807L; + } + + public AdminQueryEncoder CorrelationId(long value) + { + _buffer.PutLong(_offset + 0, value, ByteOrder.LittleEndian); + return this; + } + + + public static int ClusterSessionIdEncodingOffset() + { + return 8; + } + + public static int ClusterSessionIdEncodingLength() + { + return 8; + } + + public static long ClusterSessionIdNullValue() + { + return -9223372036854775808L; + } + + public static long ClusterSessionIdMinValue() + { + return -9223372036854775807L; + } + + public static long ClusterSessionIdMaxValue() + { + return 9223372036854775807L; + } + + public AdminQueryEncoder ClusterSessionId(long value) + { + _buffer.PutLong(_offset + 8, value, ByteOrder.LittleEndian); + return this; + } + + + public static int QueryTypeEncodingOffset() + { + return 16; + } + + public static int QueryTypeEncodingLength() + { + return 4; + } + + public AdminQueryEncoder QueryType(AdminQueryType value) + { + _buffer.PutInt(_offset + 16, (int)value, ByteOrder.LittleEndian); + return this; + } + + + public override string ToString() + { + return AppendTo(new StringBuilder(100)).ToString(); + } + + public StringBuilder AppendTo(StringBuilder builder) + { + AdminQueryDecoder writer = new AdminQueryDecoder(); + writer.Wrap(_buffer, _offset, BLOCK_LENGTH, SCHEMA_VERSION); + + return writer.AppendTo(builder); + } +} +} diff --git a/src/Adaptive.Cluster/Codecs/AdminQueryType.cs b/src/Adaptive.Cluster/Codecs/AdminQueryType.cs new file mode 100644 index 00000000..7956d202 --- /dev/null +++ b/src/Adaptive.Cluster/Codecs/AdminQueryType.cs @@ -0,0 +1,10 @@ +/* Generated SBE (Simple Binary Encoding) message codec */ +namespace Adaptive.Cluster.Codecs { + + public enum AdminQueryType : int + { + ENDPOINTS = 0, + RECORDING_LOG = 1, + NULL_VALUE = -2147483648 + } +} diff --git a/src/Adaptive.Cluster/Codecs/AdminResponseDecoder.cs b/src/Adaptive.Cluster/Codecs/AdminResponseDecoder.cs new file mode 100644 index 00000000..74cabb06 --- /dev/null +++ b/src/Adaptive.Cluster/Codecs/AdminResponseDecoder.cs @@ -0,0 +1,305 @@ +/* Generated SBE (Simple Binary Encoding) message codec */ +using System; +using System.Text; +using System.Collections.Generic; +using Adaptive.Agrona; + + +namespace Adaptive.Cluster.Codecs { + +public class AdminResponseDecoder +{ + public const ushort BLOCK_LENGTH = 16; + public const ushort TEMPLATE_ID = 10; + public const ushort SCHEMA_ID = 1; + public const ushort SCHEMA_VERSION = 1; + + private AdminResponseDecoder _parentMessage; + private IDirectBuffer _buffer; + protected int _offset; + protected int _limit; + protected int _actingBlockLength; + protected int _actingVersion; + + public AdminResponseDecoder() + { + _parentMessage = this; + } + + public ushort SbeBlockLength() + { + return BLOCK_LENGTH; + } + + public ushort SbeTemplateId() + { + return TEMPLATE_ID; + } + + public ushort SbeSchemaId() + { + return SCHEMA_ID; + } + + public ushort SbeSchemaVersion() + { + return SCHEMA_VERSION; + } + + public string SbeSemanticType() + { + return ""; + } + + public IDirectBuffer Buffer() + { + return _buffer; + } + + public int Offset() + { + return _offset; + } + + public AdminResponseDecoder Wrap( + IDirectBuffer buffer, int offset, int actingBlockLength, int actingVersion) + { + this._buffer = buffer; + this._offset = offset; + this._actingBlockLength = actingBlockLength; + this._actingVersion = actingVersion; + Limit(offset + actingBlockLength); + + return this; + } + + public int EncodedLength() + { + return _limit - _offset; + } + + public int Limit() + { + return _limit; + } + + public void Limit(int limit) + { + this._limit = limit; + } + + public static int CorrelationIdId() + { + return 1; + } + + public static int CorrelationIdSinceVersion() + { + return 0; + } + + public static int CorrelationIdEncodingOffset() + { + return 0; + } + + public static int CorrelationIdEncodingLength() + { + return 8; + } + + public static string CorrelationIdMetaAttribute(MetaAttribute metaAttribute) + { + switch (metaAttribute) + { + case MetaAttribute.EPOCH: return "unix"; + case MetaAttribute.TIME_UNIT: return "nanosecond"; + case MetaAttribute.SEMANTIC_TYPE: return ""; + case MetaAttribute.PRESENCE: return "required"; + } + + return ""; + } + + public static long CorrelationIdNullValue() + { + return -9223372036854775808L; + } + + public static long CorrelationIdMinValue() + { + return -9223372036854775807L; + } + + public static long CorrelationIdMaxValue() + { + return 9223372036854775807L; + } + + public long CorrelationId() + { + return _buffer.GetLong(_offset + 0, ByteOrder.LittleEndian); + } + + + public static int ClusterSessionIdId() + { + return 2; + } + + public static int ClusterSessionIdSinceVersion() + { + return 0; + } + + public static int ClusterSessionIdEncodingOffset() + { + return 8; + } + + public static int ClusterSessionIdEncodingLength() + { + return 8; + } + + public static string ClusterSessionIdMetaAttribute(MetaAttribute metaAttribute) + { + switch (metaAttribute) + { + case MetaAttribute.EPOCH: return "unix"; + case MetaAttribute.TIME_UNIT: return "nanosecond"; + case MetaAttribute.SEMANTIC_TYPE: return ""; + case MetaAttribute.PRESENCE: return "required"; + } + + return ""; + } + + public static long ClusterSessionIdNullValue() + { + return -9223372036854775808L; + } + + public static long ClusterSessionIdMinValue() + { + return -9223372036854775807L; + } + + public static long ClusterSessionIdMaxValue() + { + return 9223372036854775807L; + } + + public long ClusterSessionId() + { + return _buffer.GetLong(_offset + 8, ByteOrder.LittleEndian); + } + + + public static int ResponseDataId() + { + return 3; + } + + public static int ResponseDataSinceVersion() + { + return 0; + } + + public static string ResponseDataMetaAttribute(MetaAttribute metaAttribute) + { + switch (metaAttribute) + { + case MetaAttribute.EPOCH: return "unix"; + case MetaAttribute.TIME_UNIT: return "nanosecond"; + case MetaAttribute.SEMANTIC_TYPE: return ""; + case MetaAttribute.PRESENCE: return "required"; + } + + return ""; + } + + public static int ResponseDataHeaderLength() + { + return 4; + } + + public int ResponseDataLength() + { + int limit = _parentMessage.Limit(); + return (int)unchecked((uint)_buffer.GetInt(limit, ByteOrder.LittleEndian)); + } + + public int GetResponseData(IMutableDirectBuffer dst, int dstOffset, int length) + { + int headerLength = 4; + int limit = _parentMessage.Limit(); + int dataLength = (int)unchecked((uint)_buffer.GetInt(limit, ByteOrder.LittleEndian)); + int bytesCopied = Math.Min(length, dataLength); + _parentMessage.Limit(limit + headerLength + dataLength); + _buffer.GetBytes(limit + headerLength, dst, dstOffset, bytesCopied); + + return bytesCopied; + } + + public int GetResponseData(byte[] dst, int dstOffset, int length) + { + int headerLength = 4; + int limit = _parentMessage.Limit(); + int dataLength = (int)unchecked((uint)_buffer.GetInt(limit, ByteOrder.LittleEndian)); + int bytesCopied = Math.Min(length, dataLength); + _parentMessage.Limit(limit + headerLength + dataLength); + _buffer.GetBytes(limit + headerLength, dst, dstOffset, bytesCopied); + + return bytesCopied; + } + + + public override string ToString() + { + return AppendTo(new StringBuilder(100)).ToString(); + } + + public StringBuilder AppendTo(StringBuilder builder) + { + int originalLimit = Limit(); + Limit(_offset + _actingBlockLength); + builder.Append("[AdminResponse](sbeTemplateId="); + builder.Append(TEMPLATE_ID); + builder.Append("|sbeSchemaId="); + builder.Append(SCHEMA_ID); + builder.Append("|sbeSchemaVersion="); + if (_parentMessage._actingVersion != SCHEMA_VERSION) + { + builder.Append(_parentMessage._actingVersion); + builder.Append('/'); + } + builder.Append(SCHEMA_VERSION); + builder.Append("|sbeBlockLength="); + if (_actingBlockLength != BLOCK_LENGTH) + { + builder.Append(_actingBlockLength); + builder.Append('/'); + } + builder.Append(BLOCK_LENGTH); + builder.Append("):"); + //Token{signal=BEGIN_FIELD, name='correlationId', referencedName='null', description='null', id=1, version=0, deprecated=0, encodedLength=0, offset=0, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=ENCODING, name='int64', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=8, offset=0, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT64, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + builder.Append("CorrelationId="); + builder.Append(CorrelationId()); + builder.Append('|'); + //Token{signal=BEGIN_FIELD, name='clusterSessionId', referencedName='null', description='null', id=2, version=0, deprecated=0, encodedLength=0, offset=8, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=ENCODING, name='int64', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=8, offset=8, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT64, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + builder.Append("ClusterSessionId="); + builder.Append(ClusterSessionId()); + builder.Append('|'); + //Token{signal=BEGIN_VAR_DATA, name='responseData', referencedName='null', description='null', id=3, version=0, deprecated=0, encodedLength=0, offset=16, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + builder.Append("ResponseData="); + builder.Append(ResponseDataLength() + " raw bytes"); + + Limit(originalLimit); + + return builder; + } +} +} diff --git a/src/Adaptive.Cluster/Codecs/AdminResponseEncoder.cs b/src/Adaptive.Cluster/Codecs/AdminResponseEncoder.cs new file mode 100644 index 00000000..f90bd187 --- /dev/null +++ b/src/Adaptive.Cluster/Codecs/AdminResponseEncoder.cs @@ -0,0 +1,232 @@ +/* Generated SBE (Simple Binary Encoding) message codec */ +using System; +using System.Text; +using System.Collections.Generic; +using Adaptive.Agrona; + + +namespace Adaptive.Cluster.Codecs { + +public class AdminResponseEncoder +{ + public const ushort BLOCK_LENGTH = 16; + public const ushort TEMPLATE_ID = 10; + public const ushort SCHEMA_ID = 1; + public const ushort SCHEMA_VERSION = 1; + + private AdminResponseEncoder _parentMessage; + private IMutableDirectBuffer _buffer; + protected int _offset; + protected int _limit; + + public AdminResponseEncoder() + { + _parentMessage = this; + } + + public ushort SbeBlockLength() + { + return BLOCK_LENGTH; + } + + public ushort SbeTemplateId() + { + return TEMPLATE_ID; + } + + public ushort SbeSchemaId() + { + return SCHEMA_ID; + } + + public ushort SbeSchemaVersion() + { + return SCHEMA_VERSION; + } + + public string SbeSemanticType() + { + return ""; + } + + public IMutableDirectBuffer Buffer() + { + return _buffer; + } + + public int Offset() + { + return _offset; + } + + public AdminResponseEncoder Wrap(IMutableDirectBuffer buffer, int offset) + { + this._buffer = buffer; + this._offset = offset; + Limit(offset + BLOCK_LENGTH); + + return this; + } + + public AdminResponseEncoder WrapAndApplyHeader( + IMutableDirectBuffer buffer, int offset, MessageHeaderEncoder headerEncoder) + { + headerEncoder + .Wrap(buffer, offset) + .BlockLength(BLOCK_LENGTH) + .TemplateId(TEMPLATE_ID) + .SchemaId(SCHEMA_ID) + .Version(SCHEMA_VERSION); + + return Wrap(buffer, offset + MessageHeaderEncoder.ENCODED_LENGTH); + } + + public int EncodedLength() + { + return _limit - _offset; + } + + public int Limit() + { + return _limit; + } + + public void Limit(int limit) + { + this._limit = limit; + } + + public static int CorrelationIdEncodingOffset() + { + return 0; + } + + public static int CorrelationIdEncodingLength() + { + return 8; + } + + public static long CorrelationIdNullValue() + { + return -9223372036854775808L; + } + + public static long CorrelationIdMinValue() + { + return -9223372036854775807L; + } + + public static long CorrelationIdMaxValue() + { + return 9223372036854775807L; + } + + public AdminResponseEncoder CorrelationId(long value) + { + _buffer.PutLong(_offset + 0, value, ByteOrder.LittleEndian); + return this; + } + + + public static int ClusterSessionIdEncodingOffset() + { + return 8; + } + + public static int ClusterSessionIdEncodingLength() + { + return 8; + } + + public static long ClusterSessionIdNullValue() + { + return -9223372036854775808L; + } + + public static long ClusterSessionIdMinValue() + { + return -9223372036854775807L; + } + + public static long ClusterSessionIdMaxValue() + { + return 9223372036854775807L; + } + + public AdminResponseEncoder ClusterSessionId(long value) + { + _buffer.PutLong(_offset + 8, value, ByteOrder.LittleEndian); + return this; + } + + + public static int ResponseDataId() + { + return 3; + } + + public static string ResponseDataMetaAttribute(MetaAttribute metaAttribute) + { + switch (metaAttribute) + { + case MetaAttribute.EPOCH: return "unix"; + case MetaAttribute.TIME_UNIT: return "nanosecond"; + case MetaAttribute.SEMANTIC_TYPE: return ""; + case MetaAttribute.PRESENCE: return "required"; + } + + return ""; + } + + public static int ResponseDataHeaderLength() + { + return 4; + } + + public AdminResponseEncoder PutResponseData(IDirectBuffer src, int srcOffset, int length) + { + if (length > 1073741824) + { + throw new InvalidOperationException("length > maxValue for type: " + length); + } + + int headerLength = 4; + int limit = _parentMessage.Limit(); + _parentMessage.Limit(limit + headerLength + length); + _buffer.PutInt(limit, unchecked((int)length), ByteOrder.LittleEndian); + _buffer.PutBytes(limit + headerLength, src, srcOffset, length); + + return this; + } + + public AdminResponseEncoder PutResponseData(byte[] src, int srcOffset, int length) + { + if (length > 1073741824) + { + throw new InvalidOperationException("length > maxValue for type: " + length); + } + + int headerLength = 4; + int limit = _parentMessage.Limit(); + _parentMessage.Limit(limit + headerLength + length); + _buffer.PutInt(limit, unchecked((int)length), ByteOrder.LittleEndian); + _buffer.PutBytes(limit + headerLength, src, srcOffset, length); + + return this; + } + + + public override string ToString() + { + return AppendTo(new StringBuilder(100)).ToString(); + } + + public StringBuilder AppendTo(StringBuilder builder) + { + AdminResponseDecoder writer = new AdminResponseDecoder(); + writer.Wrap(_buffer, _offset, BLOCK_LENGTH, SCHEMA_VERSION); + + return writer.AppendTo(builder); + } +} +} diff --git a/src/Adaptive.Cluster/Codecs/CancelTimerRequestDecoder.cs b/src/Adaptive.Cluster/Codecs/CancelTimerDecoder.cs similarity index 95% rename from src/Adaptive.Cluster/Codecs/CancelTimerRequestDecoder.cs rename to src/Adaptive.Cluster/Codecs/CancelTimerDecoder.cs index 94e26bd3..3886adde 100644 --- a/src/Adaptive.Cluster/Codecs/CancelTimerRequestDecoder.cs +++ b/src/Adaptive.Cluster/Codecs/CancelTimerDecoder.cs @@ -7,21 +7,21 @@ namespace Adaptive.Cluster.Codecs { -public class CancelTimerRequestDecoder +public class CancelTimerDecoder { public const ushort BLOCK_LENGTH = 8; public const ushort TEMPLATE_ID = 31; public const ushort SCHEMA_ID = 1; public const ushort SCHEMA_VERSION = 1; - private CancelTimerRequestDecoder _parentMessage; + private CancelTimerDecoder _parentMessage; private IDirectBuffer _buffer; protected int _offset; protected int _limit; protected int _actingBlockLength; protected int _actingVersion; - public CancelTimerRequestDecoder() + public CancelTimerDecoder() { _parentMessage = this; } @@ -61,7 +61,7 @@ public int Offset() return _offset; } - public CancelTimerRequestDecoder Wrap( + public CancelTimerDecoder Wrap( IDirectBuffer buffer, int offset, int actingBlockLength, int actingVersion) { this._buffer = buffer; @@ -152,7 +152,7 @@ public StringBuilder AppendTo(StringBuilder builder) { int originalLimit = Limit(); Limit(_offset + _actingBlockLength); - builder.Append("[CancelTimerRequest](sbeTemplateId="); + builder.Append("[CancelTimer](sbeTemplateId="); builder.Append(TEMPLATE_ID); builder.Append("|sbeSchemaId="); builder.Append(SCHEMA_ID); diff --git a/src/Adaptive.Cluster/Codecs/CancelTimerRequestEncoder.cs b/src/Adaptive.Cluster/Codecs/CancelTimerEncoder.cs similarity index 86% rename from src/Adaptive.Cluster/Codecs/CancelTimerRequestEncoder.cs rename to src/Adaptive.Cluster/Codecs/CancelTimerEncoder.cs index cfdbe0cc..3d0ec5f7 100644 --- a/src/Adaptive.Cluster/Codecs/CancelTimerRequestEncoder.cs +++ b/src/Adaptive.Cluster/Codecs/CancelTimerEncoder.cs @@ -7,19 +7,19 @@ namespace Adaptive.Cluster.Codecs { -public class CancelTimerRequestEncoder +public class CancelTimerEncoder { public const ushort BLOCK_LENGTH = 8; public const ushort TEMPLATE_ID = 31; public const ushort SCHEMA_ID = 1; public const ushort SCHEMA_VERSION = 1; - private CancelTimerRequestEncoder _parentMessage; + private CancelTimerEncoder _parentMessage; private IMutableDirectBuffer _buffer; protected int _offset; protected int _limit; - public CancelTimerRequestEncoder() + public CancelTimerEncoder() { _parentMessage = this; } @@ -59,7 +59,7 @@ public int Offset() return _offset; } - public CancelTimerRequestEncoder Wrap(IMutableDirectBuffer buffer, int offset) + public CancelTimerEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; @@ -68,7 +68,7 @@ public CancelTimerRequestEncoder Wrap(IMutableDirectBuffer buffer, int offset) return this; } - public CancelTimerRequestEncoder WrapAndApplyHeader( + public CancelTimerEncoder WrapAndApplyHeader( IMutableDirectBuffer buffer, int offset, MessageHeaderEncoder headerEncoder) { headerEncoder @@ -121,7 +121,7 @@ public static long CorrelationIdMaxValue() return 9223372036854775807L; } - public CancelTimerRequestEncoder CorrelationId(long value) + public CancelTimerEncoder CorrelationId(long value) { _buffer.PutLong(_offset + 0, value, ByteOrder.LittleEndian); return this; @@ -136,7 +136,7 @@ public override string ToString() public StringBuilder AppendTo(StringBuilder builder) { - CancelTimerRequestDecoder writer = new CancelTimerRequestDecoder(); + CancelTimerDecoder writer = new CancelTimerDecoder(); writer.Wrap(_buffer, _offset, BLOCK_LENGTH, SCHEMA_VERSION); return writer.AppendTo(builder); diff --git a/src/Adaptive.Cluster/Codecs/ClientSessionDecoder.cs b/src/Adaptive.Cluster/Codecs/ClientSessionDecoder.cs index 2d9bd200..e5d00ad0 100644 --- a/src/Adaptive.Cluster/Codecs/ClientSessionDecoder.cs +++ b/src/Adaptive.Cluster/Codecs/ClientSessionDecoder.cs @@ -271,17 +271,17 @@ public string ResponseChannel() return Encoding.ASCII.GetString(tmp); } - public static int PrincipalDataId() + public static int EncodedPrincipalId() { return 4; } - public static int PrincipalDataSinceVersion() + public static int EncodedPrincipalSinceVersion() { return 0; } - public static string PrincipalDataMetaAttribute(MetaAttribute metaAttribute) + public static string EncodedPrincipalMetaAttribute(MetaAttribute metaAttribute) { switch (metaAttribute) { @@ -294,18 +294,18 @@ public static string PrincipalDataMetaAttribute(MetaAttribute metaAttribute) return ""; } - public static int PrincipalDataHeaderLength() + public static int EncodedPrincipalHeaderLength() { return 4; } - public int PrincipalDataLength() + public int EncodedPrincipalLength() { int limit = _parentMessage.Limit(); return (int)unchecked((uint)_buffer.GetInt(limit, ByteOrder.LittleEndian)); } - public int GetPrincipalData(IMutableDirectBuffer dst, int dstOffset, int length) + public int GetEncodedPrincipal(IMutableDirectBuffer dst, int dstOffset, int length) { int headerLength = 4; int limit = _parentMessage.Limit(); @@ -317,7 +317,7 @@ public int GetPrincipalData(IMutableDirectBuffer dst, int dstOffset, int length) return bytesCopied; } - public int GetPrincipalData(byte[] dst, int dstOffset, int length) + public int GetEncodedPrincipal(byte[] dst, int dstOffset, int length) { int headerLength = 4; int limit = _parentMessage.Limit(); @@ -372,9 +372,9 @@ public StringBuilder AppendTo(StringBuilder builder) builder.Append("ResponseChannel="); builder.Append(ResponseChannel()); builder.Append('|'); - //Token{signal=BEGIN_VAR_DATA, name='principalData', referencedName='null', description='null', id=4, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} - builder.Append("PrincipalData="); - builder.Append(PrincipalDataLength() + " raw bytes"); + //Token{signal=BEGIN_VAR_DATA, name='encodedPrincipal', referencedName='null', description='null', id=4, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + builder.Append("EncodedPrincipal="); + builder.Append(EncodedPrincipalLength() + " raw bytes"); Limit(originalLimit); diff --git a/src/Adaptive.Cluster/Codecs/ClientSessionEncoder.cs b/src/Adaptive.Cluster/Codecs/ClientSessionEncoder.cs index 84daf54f..6b364f05 100644 --- a/src/Adaptive.Cluster/Codecs/ClientSessionEncoder.cs +++ b/src/Adaptive.Cluster/Codecs/ClientSessionEncoder.cs @@ -237,12 +237,12 @@ public ClientSessionEncoder ResponseChannel(string value) return this; } - public static int PrincipalDataId() + public static int EncodedPrincipalId() { return 4; } - public static string PrincipalDataMetaAttribute(MetaAttribute metaAttribute) + public static string EncodedPrincipalMetaAttribute(MetaAttribute metaAttribute) { switch (metaAttribute) { @@ -255,12 +255,12 @@ public static string PrincipalDataMetaAttribute(MetaAttribute metaAttribute) return ""; } - public static int PrincipalDataHeaderLength() + public static int EncodedPrincipalHeaderLength() { return 4; } - public ClientSessionEncoder PutPrincipalData(IDirectBuffer src, int srcOffset, int length) + public ClientSessionEncoder PutEncodedPrincipal(IDirectBuffer src, int srcOffset, int length) { if (length > 1073741824) { @@ -276,7 +276,7 @@ public ClientSessionEncoder PutPrincipalData(IDirectBuffer src, int srcOffset, i return this; } - public ClientSessionEncoder PutPrincipalData(byte[] src, int srcOffset, int length) + public ClientSessionEncoder PutEncodedPrincipal(byte[] src, int srcOffset, int length) { if (length > 1073741824) { diff --git a/src/Adaptive.Cluster/Codecs/CloseReason.cs b/src/Adaptive.Cluster/Codecs/CloseReason.cs index d659e10f..3347e214 100644 --- a/src/Adaptive.Cluster/Codecs/CloseReason.cs +++ b/src/Adaptive.Cluster/Codecs/CloseReason.cs @@ -3,8 +3,9 @@ namespace Adaptive.Cluster.Codecs { public enum CloseReason : int { - USER_ACTION = 0, - TIMEOUT = 1, + CLIENT_ACTION = 0, + SERVICE_ACTION = 1, + TIMEOUT = 2, NULL_VALUE = -2147483648 } } diff --git a/src/Adaptive.Cluster/Codecs/CloseSessionDecoder.cs b/src/Adaptive.Cluster/Codecs/CloseSessionDecoder.cs new file mode 100644 index 00000000..0232f9b5 --- /dev/null +++ b/src/Adaptive.Cluster/Codecs/CloseSessionDecoder.cs @@ -0,0 +1,184 @@ +/* Generated SBE (Simple Binary Encoding) message codec */ +using System; +using System.Text; +using System.Collections.Generic; +using Adaptive.Agrona; + + +namespace Adaptive.Cluster.Codecs { + +public class CloseSessionDecoder +{ + public const ushort BLOCK_LENGTH = 8; + public const ushort TEMPLATE_ID = 34; + public const ushort SCHEMA_ID = 1; + public const ushort SCHEMA_VERSION = 1; + + private CloseSessionDecoder _parentMessage; + private IDirectBuffer _buffer; + protected int _offset; + protected int _limit; + protected int _actingBlockLength; + protected int _actingVersion; + + public CloseSessionDecoder() + { + _parentMessage = this; + } + + public ushort SbeBlockLength() + { + return BLOCK_LENGTH; + } + + public ushort SbeTemplateId() + { + return TEMPLATE_ID; + } + + public ushort SbeSchemaId() + { + return SCHEMA_ID; + } + + public ushort SbeSchemaVersion() + { + return SCHEMA_VERSION; + } + + public string SbeSemanticType() + { + return ""; + } + + public IDirectBuffer Buffer() + { + return _buffer; + } + + public int Offset() + { + return _offset; + } + + public CloseSessionDecoder Wrap( + IDirectBuffer buffer, int offset, int actingBlockLength, int actingVersion) + { + this._buffer = buffer; + this._offset = offset; + this._actingBlockLength = actingBlockLength; + this._actingVersion = actingVersion; + Limit(offset + actingBlockLength); + + return this; + } + + public int EncodedLength() + { + return _limit - _offset; + } + + public int Limit() + { + return _limit; + } + + public void Limit(int limit) + { + this._limit = limit; + } + + public static int ClusterSessionIdId() + { + return 1; + } + + public static int ClusterSessionIdSinceVersion() + { + return 0; + } + + public static int ClusterSessionIdEncodingOffset() + { + return 0; + } + + public static int ClusterSessionIdEncodingLength() + { + return 8; + } + + public static string ClusterSessionIdMetaAttribute(MetaAttribute metaAttribute) + { + switch (metaAttribute) + { + case MetaAttribute.EPOCH: return "unix"; + case MetaAttribute.TIME_UNIT: return "nanosecond"; + case MetaAttribute.SEMANTIC_TYPE: return ""; + case MetaAttribute.PRESENCE: return "required"; + } + + return ""; + } + + public static long ClusterSessionIdNullValue() + { + return -9223372036854775808L; + } + + public static long ClusterSessionIdMinValue() + { + return -9223372036854775807L; + } + + public static long ClusterSessionIdMaxValue() + { + return 9223372036854775807L; + } + + public long ClusterSessionId() + { + return _buffer.GetLong(_offset + 0, ByteOrder.LittleEndian); + } + + + + public override string ToString() + { + return AppendTo(new StringBuilder(100)).ToString(); + } + + public StringBuilder AppendTo(StringBuilder builder) + { + int originalLimit = Limit(); + Limit(_offset + _actingBlockLength); + builder.Append("[CloseSession](sbeTemplateId="); + builder.Append(TEMPLATE_ID); + builder.Append("|sbeSchemaId="); + builder.Append(SCHEMA_ID); + builder.Append("|sbeSchemaVersion="); + if (_parentMessage._actingVersion != SCHEMA_VERSION) + { + builder.Append(_parentMessage._actingVersion); + builder.Append('/'); + } + builder.Append(SCHEMA_VERSION); + builder.Append("|sbeBlockLength="); + if (_actingBlockLength != BLOCK_LENGTH) + { + builder.Append(_actingBlockLength); + builder.Append('/'); + } + builder.Append(BLOCK_LENGTH); + builder.Append("):"); + //Token{signal=BEGIN_FIELD, name='clusterSessionId', referencedName='null', description='null', id=1, version=0, deprecated=0, encodedLength=0, offset=0, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=ENCODING, name='int64', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=8, offset=0, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT64, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + builder.Append("ClusterSessionId="); + builder.Append(ClusterSessionId()); + + Limit(originalLimit); + + return builder; + } +} +} diff --git a/src/Adaptive.Cluster/Codecs/CloseSessionEncoder.cs b/src/Adaptive.Cluster/Codecs/CloseSessionEncoder.cs new file mode 100644 index 00000000..68bcba3b --- /dev/null +++ b/src/Adaptive.Cluster/Codecs/CloseSessionEncoder.cs @@ -0,0 +1,145 @@ +/* Generated SBE (Simple Binary Encoding) message codec */ +using System; +using System.Text; +using System.Collections.Generic; +using Adaptive.Agrona; + + +namespace Adaptive.Cluster.Codecs { + +public class CloseSessionEncoder +{ + public const ushort BLOCK_LENGTH = 8; + public const ushort TEMPLATE_ID = 34; + public const ushort SCHEMA_ID = 1; + public const ushort SCHEMA_VERSION = 1; + + private CloseSessionEncoder _parentMessage; + private IMutableDirectBuffer _buffer; + protected int _offset; + protected int _limit; + + public CloseSessionEncoder() + { + _parentMessage = this; + } + + public ushort SbeBlockLength() + { + return BLOCK_LENGTH; + } + + public ushort SbeTemplateId() + { + return TEMPLATE_ID; + } + + public ushort SbeSchemaId() + { + return SCHEMA_ID; + } + + public ushort SbeSchemaVersion() + { + return SCHEMA_VERSION; + } + + public string SbeSemanticType() + { + return ""; + } + + public IMutableDirectBuffer Buffer() + { + return _buffer; + } + + public int Offset() + { + return _offset; + } + + public CloseSessionEncoder Wrap(IMutableDirectBuffer buffer, int offset) + { + this._buffer = buffer; + this._offset = offset; + Limit(offset + BLOCK_LENGTH); + + return this; + } + + public CloseSessionEncoder WrapAndApplyHeader( + IMutableDirectBuffer buffer, int offset, MessageHeaderEncoder headerEncoder) + { + headerEncoder + .Wrap(buffer, offset) + .BlockLength(BLOCK_LENGTH) + .TemplateId(TEMPLATE_ID) + .SchemaId(SCHEMA_ID) + .Version(SCHEMA_VERSION); + + return Wrap(buffer, offset + MessageHeaderEncoder.ENCODED_LENGTH); + } + + public int EncodedLength() + { + return _limit - _offset; + } + + public int Limit() + { + return _limit; + } + + public void Limit(int limit) + { + this._limit = limit; + } + + public static int ClusterSessionIdEncodingOffset() + { + return 0; + } + + public static int ClusterSessionIdEncodingLength() + { + return 8; + } + + public static long ClusterSessionIdNullValue() + { + return -9223372036854775808L; + } + + public static long ClusterSessionIdMinValue() + { + return -9223372036854775807L; + } + + public static long ClusterSessionIdMaxValue() + { + return 9223372036854775807L; + } + + public CloseSessionEncoder ClusterSessionId(long value) + { + _buffer.PutLong(_offset + 0, value, ByteOrder.LittleEndian); + return this; + } + + + + public override string ToString() + { + return AppendTo(new StringBuilder(100)).ToString(); + } + + public StringBuilder AppendTo(StringBuilder builder) + { + CloseSessionDecoder writer = new CloseSessionDecoder(); + writer.Wrap(_buffer, _offset, BLOCK_LENGTH, SCHEMA_VERSION); + + return writer.AppendTo(builder); + } +} +} diff --git a/src/Adaptive.Cluster/Codecs/ServiceActionAckDecoder.cs b/src/Adaptive.Cluster/Codecs/ClusterActionAckDecoder.cs similarity index 97% rename from src/Adaptive.Cluster/Codecs/ServiceActionAckDecoder.cs rename to src/Adaptive.Cluster/Codecs/ClusterActionAckDecoder.cs index 3fb1ab0f..2b422283 100644 --- a/src/Adaptive.Cluster/Codecs/ServiceActionAckDecoder.cs +++ b/src/Adaptive.Cluster/Codecs/ClusterActionAckDecoder.cs @@ -7,21 +7,21 @@ namespace Adaptive.Cluster.Codecs { -public class ServiceActionAckDecoder +public class ClusterActionAckDecoder { public const ushort BLOCK_LENGTH = 24; public const ushort TEMPLATE_ID = 32; public const ushort SCHEMA_ID = 1; public const ushort SCHEMA_VERSION = 1; - private ServiceActionAckDecoder _parentMessage; + private ClusterActionAckDecoder _parentMessage; private IDirectBuffer _buffer; protected int _offset; protected int _limit; protected int _actingBlockLength; protected int _actingVersion; - public ServiceActionAckDecoder() + public ClusterActionAckDecoder() { _parentMessage = this; } @@ -61,7 +61,7 @@ public int Offset() return _offset; } - public ServiceActionAckDecoder Wrap( + public ClusterActionAckDecoder Wrap( IDirectBuffer buffer, int offset, int actingBlockLength, int actingVersion) { this._buffer = buffer; @@ -299,7 +299,7 @@ public StringBuilder AppendTo(StringBuilder builder) { int originalLimit = Limit(); Limit(_offset + _actingBlockLength); - builder.Append("[ServiceActionAck](sbeTemplateId="); + builder.Append("[ClusterActionAck](sbeTemplateId="); builder.Append(TEMPLATE_ID); builder.Append("|sbeSchemaId="); builder.Append(SCHEMA_ID); diff --git a/src/Adaptive.Cluster/Codecs/ServiceActionAckEncoder.cs b/src/Adaptive.Cluster/Codecs/ClusterActionAckEncoder.cs similarity index 87% rename from src/Adaptive.Cluster/Codecs/ServiceActionAckEncoder.cs rename to src/Adaptive.Cluster/Codecs/ClusterActionAckEncoder.cs index f5424afd..aec9fe8e 100644 --- a/src/Adaptive.Cluster/Codecs/ServiceActionAckEncoder.cs +++ b/src/Adaptive.Cluster/Codecs/ClusterActionAckEncoder.cs @@ -7,19 +7,19 @@ namespace Adaptive.Cluster.Codecs { -public class ServiceActionAckEncoder +public class ClusterActionAckEncoder { public const ushort BLOCK_LENGTH = 24; public const ushort TEMPLATE_ID = 32; public const ushort SCHEMA_ID = 1; public const ushort SCHEMA_VERSION = 1; - private ServiceActionAckEncoder _parentMessage; + private ClusterActionAckEncoder _parentMessage; private IMutableDirectBuffer _buffer; protected int _offset; protected int _limit; - public ServiceActionAckEncoder() + public ClusterActionAckEncoder() { _parentMessage = this; } @@ -59,7 +59,7 @@ public int Offset() return _offset; } - public ServiceActionAckEncoder Wrap(IMutableDirectBuffer buffer, int offset) + public ClusterActionAckEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; @@ -68,7 +68,7 @@ public ServiceActionAckEncoder Wrap(IMutableDirectBuffer buffer, int offset) return this; } - public ServiceActionAckEncoder WrapAndApplyHeader( + public ClusterActionAckEncoder WrapAndApplyHeader( IMutableDirectBuffer buffer, int offset, MessageHeaderEncoder headerEncoder) { headerEncoder @@ -121,7 +121,7 @@ public static long LogPositionMaxValue() return 9223372036854775807L; } - public ServiceActionAckEncoder LogPosition(long value) + public ClusterActionAckEncoder LogPosition(long value) { _buffer.PutLong(_offset + 0, value, ByteOrder.LittleEndian); return this; @@ -153,7 +153,7 @@ public static long LeadershipTermIdMaxValue() return 9223372036854775807L; } - public ServiceActionAckEncoder LeadershipTermId(long value) + public ClusterActionAckEncoder LeadershipTermId(long value) { _buffer.PutLong(_offset + 8, value, ByteOrder.LittleEndian); return this; @@ -185,7 +185,7 @@ public static int ServiceIdMaxValue() return 2147483647; } - public ServiceActionAckEncoder ServiceId(int value) + public ClusterActionAckEncoder ServiceId(int value) { _buffer.PutInt(_offset + 16, value, ByteOrder.LittleEndian); return this; @@ -202,7 +202,7 @@ public static int ActionEncodingLength() return 4; } - public ServiceActionAckEncoder Action(ClusterAction value) + public ClusterActionAckEncoder Action(ClusterAction value) { _buffer.PutInt(_offset + 20, (int)value, ByteOrder.LittleEndian); return this; @@ -216,7 +216,7 @@ public override string ToString() public StringBuilder AppendTo(StringBuilder builder) { - ServiceActionAckDecoder writer = new ServiceActionAckDecoder(); + ClusterActionAckDecoder writer = new ClusterActionAckDecoder(); writer.Wrap(_buffer, _offset, BLOCK_LENGTH, SCHEMA_VERSION); return writer.AppendTo(builder); diff --git a/src/Adaptive.Cluster/Codecs/ClusterSessionDecoder.cs b/src/Adaptive.Cluster/Codecs/ClusterSessionDecoder.cs index eb94cb63..337d5996 100644 --- a/src/Adaptive.Cluster/Codecs/ClusterSessionDecoder.cs +++ b/src/Adaptive.Cluster/Codecs/ClusterSessionDecoder.cs @@ -9,7 +9,7 @@ namespace Adaptive.Cluster.Codecs { public class ClusterSessionDecoder { - public const ushort BLOCK_LENGTH = 36; + public const ushort BLOCK_LENGTH = 40; public const ushort TEMPLATE_ID = 103; public const ushort SCHEMA_ID = 1; public const ushort SCHEMA_VERSION = 1; @@ -304,11 +304,50 @@ public long TimeOfLastActivity() } - public static int ResponseStreamIdId() + public static int CloseReasonId() { return 5; } + public static int CloseReasonSinceVersion() + { + return 0; + } + + public static int CloseReasonEncodingOffset() + { + return 32; + } + + public static int CloseReasonEncodingLength() + { + return 4; + } + + public static string CloseReasonMetaAttribute(MetaAttribute metaAttribute) + { + switch (metaAttribute) + { + case MetaAttribute.EPOCH: return "unix"; + case MetaAttribute.TIME_UNIT: return "nanosecond"; + case MetaAttribute.SEMANTIC_TYPE: return ""; + case MetaAttribute.PRESENCE: return "required"; + } + + return ""; + } + + public CloseReason CloseReason() + { + return (CloseReason)_buffer.GetInt(_offset + 32, ByteOrder.LittleEndian); + } + + + public static int ResponseStreamIdId() + { + return 6; + } + public static int ResponseStreamIdSinceVersion() { return 0; @@ -316,7 +355,7 @@ public static int ResponseStreamIdSinceVersion() public static int ResponseStreamIdEncodingOffset() { - return 32; + return 36; } public static int ResponseStreamIdEncodingLength() @@ -354,13 +393,13 @@ public static int ResponseStreamIdMaxValue() public int ResponseStreamId() { - return _buffer.GetInt(_offset + 32, ByteOrder.LittleEndian); + return _buffer.GetInt(_offset + 36, ByteOrder.LittleEndian); } public static int ResponseChannelId() { - return 6; + return 7; } public static int ResponseChannelSinceVersion() @@ -482,12 +521,17 @@ public StringBuilder AppendTo(StringBuilder builder) builder.Append("TimeOfLastActivity="); builder.Append(TimeOfLastActivity()); builder.Append('|'); - //Token{signal=BEGIN_FIELD, name='responseStreamId', referencedName='null', description='null', id=5, version=0, deprecated=0, encodedLength=0, offset=32, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} - //Token{signal=ENCODING, name='int32', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=32, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_FIELD, name='closeReason', referencedName='null', description='null', id=5, version=0, deprecated=0, encodedLength=0, offset=32, componentTokenCount=7, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_ENUM, name='CloseReason', referencedName='null', description='Reason why a session was closed', id=-1, version=0, deprecated=0, encodedLength=4, offset=32, componentTokenCount=5, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='null', timeUnit=null, semanticType='null'}} + builder.Append("CloseReason="); + builder.Append(CloseReason()); + builder.Append('|'); + //Token{signal=BEGIN_FIELD, name='responseStreamId', referencedName='null', description='null', id=6, version=0, deprecated=0, encodedLength=0, offset=36, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=ENCODING, name='int32', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=36, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} builder.Append("ResponseStreamId="); builder.Append(ResponseStreamId()); builder.Append('|'); - //Token{signal=BEGIN_VAR_DATA, name='responseChannel', referencedName='null', description='null', id=6, version=0, deprecated=0, encodedLength=0, offset=36, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_VAR_DATA, name='responseChannel', referencedName='null', description='null', id=7, version=0, deprecated=0, encodedLength=0, offset=40, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} builder.Append("ResponseChannel="); builder.Append(ResponseChannel()); diff --git a/src/Adaptive.Cluster/Codecs/ClusterSessionEncoder.cs b/src/Adaptive.Cluster/Codecs/ClusterSessionEncoder.cs index d2d8111e..e501d6c7 100644 --- a/src/Adaptive.Cluster/Codecs/ClusterSessionEncoder.cs +++ b/src/Adaptive.Cluster/Codecs/ClusterSessionEncoder.cs @@ -9,7 +9,7 @@ namespace Adaptive.Cluster.Codecs { public class ClusterSessionEncoder { - public const ushort BLOCK_LENGTH = 36; + public const ushort BLOCK_LENGTH = 40; public const ushort TEMPLATE_ID = 103; public const ushort SCHEMA_ID = 1; public const ushort SCHEMA_VERSION = 1; @@ -224,11 +224,27 @@ public ClusterSessionEncoder TimeOfLastActivity(long value) } - public static int ResponseStreamIdEncodingOffset() + public static int CloseReasonEncodingOffset() { return 32; } + public static int CloseReasonEncodingLength() + { + return 4; + } + + public ClusterSessionEncoder CloseReason(CloseReason value) + { + _buffer.PutInt(_offset + 32, (int)value, ByteOrder.LittleEndian); + return this; + } + + public static int ResponseStreamIdEncodingOffset() + { + return 36; + } + public static int ResponseStreamIdEncodingLength() { return 4; @@ -251,14 +267,14 @@ public static int ResponseStreamIdMaxValue() public ClusterSessionEncoder ResponseStreamId(int value) { - _buffer.PutInt(_offset + 32, value, ByteOrder.LittleEndian); + _buffer.PutInt(_offset + 36, value, ByteOrder.LittleEndian); return this; } public static int ResponseChannelId() { - return 6; + return 7; } public static string ResponseChannelCharacterEncoding() diff --git a/src/Adaptive.Cluster/Codecs/JoinLogRequestDecoder.cs b/src/Adaptive.Cluster/Codecs/JoinLogDecoder.cs similarity index 98% rename from src/Adaptive.Cluster/Codecs/JoinLogRequestDecoder.cs rename to src/Adaptive.Cluster/Codecs/JoinLogDecoder.cs index 50d0afcb..94ec1aab 100644 --- a/src/Adaptive.Cluster/Codecs/JoinLogRequestDecoder.cs +++ b/src/Adaptive.Cluster/Codecs/JoinLogDecoder.cs @@ -7,21 +7,21 @@ namespace Adaptive.Cluster.Codecs { -public class JoinLogRequestDecoder +public class JoinLogDecoder { public const ushort BLOCK_LENGTH = 20; public const ushort TEMPLATE_ID = 33; public const ushort SCHEMA_ID = 1; public const ushort SCHEMA_VERSION = 1; - private JoinLogRequestDecoder _parentMessage; + private JoinLogDecoder _parentMessage; private IDirectBuffer _buffer; protected int _offset; protected int _limit; protected int _actingBlockLength; protected int _actingVersion; - public JoinLogRequestDecoder() + public JoinLogDecoder() { _parentMessage = this; } @@ -61,7 +61,7 @@ public int Offset() return _offset; } - public JoinLogRequestDecoder Wrap( + public JoinLogDecoder Wrap( IDirectBuffer buffer, int offset, int actingBlockLength, int actingVersion) { this._buffer = buffer; @@ -389,7 +389,7 @@ public StringBuilder AppendTo(StringBuilder builder) { int originalLimit = Limit(); Limit(_offset + _actingBlockLength); - builder.Append("[JoinLogRequest](sbeTemplateId="); + builder.Append("[JoinLog](sbeTemplateId="); builder.Append(TEMPLATE_ID); builder.Append("|sbeSchemaId="); builder.Append(SCHEMA_ID); diff --git a/src/Adaptive.Cluster/Codecs/JoinLogRequestEncoder.cs b/src/Adaptive.Cluster/Codecs/JoinLogEncoder.cs similarity index 89% rename from src/Adaptive.Cluster/Codecs/JoinLogRequestEncoder.cs rename to src/Adaptive.Cluster/Codecs/JoinLogEncoder.cs index d51fbbe3..d26bacf3 100644 --- a/src/Adaptive.Cluster/Codecs/JoinLogRequestEncoder.cs +++ b/src/Adaptive.Cluster/Codecs/JoinLogEncoder.cs @@ -7,19 +7,19 @@ namespace Adaptive.Cluster.Codecs { -public class JoinLogRequestEncoder +public class JoinLogEncoder { public const ushort BLOCK_LENGTH = 20; public const ushort TEMPLATE_ID = 33; public const ushort SCHEMA_ID = 1; public const ushort SCHEMA_VERSION = 1; - private JoinLogRequestEncoder _parentMessage; + private JoinLogEncoder _parentMessage; private IMutableDirectBuffer _buffer; protected int _offset; protected int _limit; - public JoinLogRequestEncoder() + public JoinLogEncoder() { _parentMessage = this; } @@ -59,7 +59,7 @@ public int Offset() return _offset; } - public JoinLogRequestEncoder Wrap(IMutableDirectBuffer buffer, int offset) + public JoinLogEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; @@ -68,7 +68,7 @@ public JoinLogRequestEncoder Wrap(IMutableDirectBuffer buffer, int offset) return this; } - public JoinLogRequestEncoder WrapAndApplyHeader( + public JoinLogEncoder WrapAndApplyHeader( IMutableDirectBuffer buffer, int offset, MessageHeaderEncoder headerEncoder) { headerEncoder @@ -121,7 +121,7 @@ public static long LeadershipTermIdMaxValue() return 9223372036854775807L; } - public JoinLogRequestEncoder LeadershipTermId(long value) + public JoinLogEncoder LeadershipTermId(long value) { _buffer.PutLong(_offset + 0, value, ByteOrder.LittleEndian); return this; @@ -153,7 +153,7 @@ public static int CommitPositionIdMaxValue() return 2147483647; } - public JoinLogRequestEncoder CommitPositionId(int value) + public JoinLogEncoder CommitPositionId(int value) { _buffer.PutInt(_offset + 8, value, ByteOrder.LittleEndian); return this; @@ -185,7 +185,7 @@ public static int LogSessionIdMaxValue() return 2147483647; } - public JoinLogRequestEncoder LogSessionId(int value) + public JoinLogEncoder LogSessionId(int value) { _buffer.PutInt(_offset + 12, value, ByteOrder.LittleEndian); return this; @@ -217,7 +217,7 @@ public static int LogStreamIdMaxValue() return 2147483647; } - public JoinLogRequestEncoder LogStreamId(int value) + public JoinLogEncoder LogStreamId(int value) { _buffer.PutInt(_offset + 16, value, ByteOrder.LittleEndian); return this; @@ -252,7 +252,7 @@ public static int LogChannelHeaderLength() return 4; } - public JoinLogRequestEncoder PutLogChannel(IDirectBuffer src, int srcOffset, int length) + public JoinLogEncoder PutLogChannel(IDirectBuffer src, int srcOffset, int length) { if (length > 1073741824) { @@ -268,7 +268,7 @@ public JoinLogRequestEncoder PutLogChannel(IDirectBuffer src, int srcOffset, int return this; } - public JoinLogRequestEncoder PutLogChannel(byte[] src, int srcOffset, int length) + public JoinLogEncoder PutLogChannel(byte[] src, int srcOffset, int length) { if (length > 1073741824) { @@ -284,7 +284,7 @@ public JoinLogRequestEncoder PutLogChannel(byte[] src, int srcOffset, int length return this; } - public JoinLogRequestEncoder LogChannel(string value) + public JoinLogEncoder LogChannel(string value) { int length = value.Length; if (length > 1073741824) @@ -309,7 +309,7 @@ public override string ToString() public StringBuilder AppendTo(StringBuilder builder) { - JoinLogRequestDecoder writer = new JoinLogRequestDecoder(); + JoinLogDecoder writer = new JoinLogDecoder(); writer.Wrap(_buffer, _offset, BLOCK_LENGTH, SCHEMA_VERSION); return writer.AppendTo(builder); diff --git a/src/Adaptive.Cluster/Codecs/ClusterComponentType.cs b/src/Adaptive.Cluster/Codecs/Mark/ClusterComponentType.cs similarity index 84% rename from src/Adaptive.Cluster/Codecs/ClusterComponentType.cs rename to src/Adaptive.Cluster/Codecs/Mark/ClusterComponentType.cs index 0eb929f5..b6def316 100644 --- a/src/Adaptive.Cluster/Codecs/ClusterComponentType.cs +++ b/src/Adaptive.Cluster/Codecs/Mark/ClusterComponentType.cs @@ -1,5 +1,5 @@ /* Generated SBE (Simple Binary Encoding) message codec */ -namespace Adaptive.Cluster.Codecs { +namespace Adaptive.Cluster.Codecs.Mark { public enum ClusterComponentType : int { diff --git a/src/Adaptive.Cluster/Codecs/CncHeaderDecoder.cs b/src/Adaptive.Cluster/Codecs/Mark/MarkFileHeaderDecoder.cs similarity index 86% rename from src/Adaptive.Cluster/Codecs/CncHeaderDecoder.cs rename to src/Adaptive.Cluster/Codecs/Mark/MarkFileHeaderDecoder.cs index d4713ced..fc838bf3 100644 --- a/src/Adaptive.Cluster/Codecs/CncHeaderDecoder.cs +++ b/src/Adaptive.Cluster/Codecs/Mark/MarkFileHeaderDecoder.cs @@ -5,23 +5,23 @@ using Adaptive.Agrona; -namespace Adaptive.Cluster.Codecs { +namespace Adaptive.Cluster.Codecs.Mark { -public class CncHeaderDecoder +public class MarkFileHeaderDecoder { public const ushort BLOCK_LENGTH = 128; public const ushort TEMPLATE_ID = 200; public const ushort SCHEMA_ID = 1; public const ushort SCHEMA_VERSION = 1; - private CncHeaderDecoder _parentMessage; + private MarkFileHeaderDecoder _parentMessage; private IDirectBuffer _buffer; protected int _offset; protected int _limit; protected int _actingBlockLength; protected int _actingVersion; - public CncHeaderDecoder() + public MarkFileHeaderDecoder() { _parentMessage = this; } @@ -61,7 +61,7 @@ public int Offset() return _offset; } - public CncHeaderDecoder Wrap( + public MarkFileHeaderDecoder Wrap( IDirectBuffer buffer, int offset, int actingBlockLength, int actingVersion) { this._buffer = buffer; @@ -142,27 +142,27 @@ public int Version() } - public static int FileTypeId() + public static int ComponentTypeId() { return 2; } - public static int FileTypeSinceVersion() + public static int ComponentTypeSinceVersion() { return 0; } - public static int FileTypeEncodingOffset() + public static int ComponentTypeEncodingOffset() { return 4; } - public static int FileTypeEncodingLength() + public static int ComponentTypeEncodingLength() { return 4; } - public static string FileTypeMetaAttribute(MetaAttribute metaAttribute) + public static string ComponentTypeMetaAttribute(MetaAttribute metaAttribute) { switch (metaAttribute) { @@ -175,7 +175,7 @@ public static string FileTypeMetaAttribute(MetaAttribute metaAttribute) return ""; } - public ClusterComponentType FileType() + public ClusterComponentType ComponentType() { return (ClusterComponentType)_buffer.GetInt(_offset + 4, ByteOrder.LittleEndian); } @@ -235,11 +235,65 @@ public long ActivityTimestamp() } - public static int PidId() + public static int StartTimestampId() { return 4; } + public static int StartTimestampSinceVersion() + { + return 0; + } + + public static int StartTimestampEncodingOffset() + { + return 16; + } + + public static int StartTimestampEncodingLength() + { + return 8; + } + + public static string StartTimestampMetaAttribute(MetaAttribute metaAttribute) + { + switch (metaAttribute) + { + case MetaAttribute.EPOCH: return "unix"; + case MetaAttribute.TIME_UNIT: return "nanosecond"; + case MetaAttribute.SEMANTIC_TYPE: return ""; + case MetaAttribute.PRESENCE: return "required"; + } + + return ""; + } + + public static long StartTimestampNullValue() + { + return -9223372036854775808L; + } + + public static long StartTimestampMinValue() + { + return -9223372036854775807L; + } + + public static long StartTimestampMaxValue() + { + return 9223372036854775807L; + } + + public long StartTimestamp() + { + return _buffer.GetLong(_offset + 16, ByteOrder.LittleEndian); + } + + + public static int PidId() + { + return 5; + } + public static int PidSinceVersion() { return 0; @@ -247,12 +301,12 @@ public static int PidSinceVersion() public static int PidEncodingOffset() { - return 16; + return 24; } public static int PidEncodingLength() { - return 4; + return 8; } public static string PidMetaAttribute(MetaAttribute metaAttribute) @@ -268,30 +322,30 @@ public static string PidMetaAttribute(MetaAttribute metaAttribute) return ""; } - public static int PidNullValue() + public static long PidNullValue() { - return -2147483648; + return -9223372036854775808L; } - public static int PidMinValue() + public static long PidMinValue() { - return -2147483647; + return -9223372036854775807L; } - public static int PidMaxValue() + public static long PidMaxValue() { - return 2147483647; + return 9223372036854775807L; } - public int Pid() + public long Pid() { - return _buffer.GetInt(_offset + 16, ByteOrder.LittleEndian); + return _buffer.GetLong(_offset + 24, ByteOrder.LittleEndian); } public static int ArchiveStreamIdId() { - return 5; + return 6; } public static int ArchiveStreamIdSinceVersion() @@ -301,7 +355,7 @@ public static int ArchiveStreamIdSinceVersion() public static int ArchiveStreamIdEncodingOffset() { - return 20; + return 32; } public static int ArchiveStreamIdEncodingLength() @@ -339,13 +393,13 @@ public static int ArchiveStreamIdMaxValue() public int ArchiveStreamId() { - return _buffer.GetInt(_offset + 20, ByteOrder.LittleEndian); + return _buffer.GetInt(_offset + 32, ByteOrder.LittleEndian); } public static int ServiceControlStreamIdId() { - return 6; + return 7; } public static int ServiceControlStreamIdSinceVersion() @@ -355,7 +409,7 @@ public static int ServiceControlStreamIdSinceVersion() public static int ServiceControlStreamIdEncodingOffset() { - return 24; + return 36; } public static int ServiceControlStreamIdEncodingLength() @@ -393,13 +447,13 @@ public static int ServiceControlStreamIdMaxValue() public int ServiceControlStreamId() { - return _buffer.GetInt(_offset + 24, ByteOrder.LittleEndian); + return _buffer.GetInt(_offset + 36, ByteOrder.LittleEndian); } public static int IngressStreamIdId() { - return 7; + return 8; } public static int IngressStreamIdSinceVersion() @@ -409,7 +463,7 @@ public static int IngressStreamIdSinceVersion() public static int IngressStreamIdEncodingOffset() { - return 28; + return 40; } public static int IngressStreamIdEncodingLength() @@ -447,13 +501,13 @@ public static int IngressStreamIdMaxValue() public int IngressStreamId() { - return _buffer.GetInt(_offset + 28, ByteOrder.LittleEndian); + return _buffer.GetInt(_offset + 40, ByteOrder.LittleEndian); } public static int MemberIdId() { - return 8; + return 9; } public static int MemberIdSinceVersion() @@ -463,7 +517,7 @@ public static int MemberIdSinceVersion() public static int MemberIdEncodingOffset() { - return 32; + return 44; } public static int MemberIdEncodingLength() @@ -501,13 +555,13 @@ public static int MemberIdMaxValue() public int MemberId() { - return _buffer.GetInt(_offset + 32, ByteOrder.LittleEndian); + return _buffer.GetInt(_offset + 44, ByteOrder.LittleEndian); } public static int ServiceIdId() { - return 9; + return 10; } public static int ServiceIdSinceVersion() @@ -517,7 +571,7 @@ public static int ServiceIdSinceVersion() public static int ServiceIdEncodingOffset() { - return 36; + return 48; } public static int ServiceIdEncodingLength() @@ -555,13 +609,13 @@ public static int ServiceIdMaxValue() public int ServiceId() { - return _buffer.GetInt(_offset + 36, ByteOrder.LittleEndian); + return _buffer.GetInt(_offset + 48, ByteOrder.LittleEndian); } public static int AeronDirectoryId() { - return 10; + return 11; } public static int AeronDirectorySinceVersion() @@ -636,7 +690,7 @@ public string AeronDirectory() public static int ArchiveChannelId() { - return 11; + return 12; } public static int ArchiveChannelSinceVersion() @@ -711,7 +765,7 @@ public string ArchiveChannel() public static int ServiceControlChannelId() { - return 12; + return 13; } public static int ServiceControlChannelSinceVersion() @@ -786,7 +840,7 @@ public string ServiceControlChannel() public static int IngressChannelId() { - return 13; + return 14; } public static int IngressChannelSinceVersion() @@ -861,7 +915,7 @@ public string IngressChannel() public static int ServiceNameId() { - return 14; + return 15; } public static int ServiceNameSinceVersion() @@ -936,7 +990,7 @@ public string ServiceName() public static int AuthenticatorId() { - return 15; + return 16; } public static int AuthenticatorSinceVersion() @@ -1019,7 +1073,7 @@ public StringBuilder AppendTo(StringBuilder builder) { int originalLimit = Limit(); Limit(_offset + _actingBlockLength); - builder.Append("[CncHeader](sbeTemplateId="); + builder.Append("[MarkFileHeader](sbeTemplateId="); builder.Append(TEMPLATE_ID); builder.Append("|sbeSchemaId="); builder.Append(SCHEMA_ID); @@ -1043,67 +1097,72 @@ public StringBuilder AppendTo(StringBuilder builder) builder.Append("Version="); builder.Append(Version()); builder.Append('|'); - //Token{signal=BEGIN_FIELD, name='fileType', referencedName='null', description='null', id=2, version=0, deprecated=0, encodedLength=0, offset=4, componentTokenCount=7, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_FIELD, name='componentType', referencedName='null', description='null', id=2, version=0, deprecated=0, encodedLength=0, offset=4, componentTokenCount=7, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} //Token{signal=BEGIN_ENUM, name='ClusterComponentType', referencedName='null', description='Type of Cluster Component', id=-1, version=0, deprecated=0, encodedLength=4, offset=4, componentTokenCount=5, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='null', timeUnit=null, semanticType='null'}} - builder.Append("FileType="); - builder.Append(FileType()); + builder.Append("ComponentType="); + builder.Append(ComponentType()); builder.Append('|'); //Token{signal=BEGIN_FIELD, name='activityTimestamp', referencedName='null', description='null', id=3, version=0, deprecated=0, encodedLength=0, offset=8, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} //Token{signal=ENCODING, name='time_t', referencedName='null', description='Epoch time in milliseconds since 1 Jan 1970 UTC', id=-1, version=0, deprecated=0, encodedLength=8, offset=8, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT64, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} builder.Append("ActivityTimestamp="); builder.Append(ActivityTimestamp()); builder.Append('|'); - //Token{signal=BEGIN_FIELD, name='pid', referencedName='null', description='null', id=4, version=0, deprecated=0, encodedLength=0, offset=16, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} - //Token{signal=ENCODING, name='int32', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=16, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_FIELD, name='startTimestamp', referencedName='null', description='null', id=4, version=0, deprecated=0, encodedLength=0, offset=16, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=ENCODING, name='time_t', referencedName='null', description='Epoch time in milliseconds since 1 Jan 1970 UTC', id=-1, version=0, deprecated=0, encodedLength=8, offset=16, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT64, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + builder.Append("StartTimestamp="); + builder.Append(StartTimestamp()); + builder.Append('|'); + //Token{signal=BEGIN_FIELD, name='pid', referencedName='null', description='null', id=5, version=0, deprecated=0, encodedLength=0, offset=24, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=ENCODING, name='int64', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=8, offset=24, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT64, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} builder.Append("Pid="); builder.Append(Pid()); builder.Append('|'); - //Token{signal=BEGIN_FIELD, name='archiveStreamId', referencedName='null', description='null', id=5, version=0, deprecated=0, encodedLength=0, offset=20, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} - //Token{signal=ENCODING, name='int32', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=20, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_FIELD, name='archiveStreamId', referencedName='null', description='null', id=6, version=0, deprecated=0, encodedLength=0, offset=32, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=ENCODING, name='int32', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=32, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} builder.Append("ArchiveStreamId="); builder.Append(ArchiveStreamId()); builder.Append('|'); - //Token{signal=BEGIN_FIELD, name='serviceControlStreamId', referencedName='null', description='null', id=6, version=0, deprecated=0, encodedLength=0, offset=24, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} - //Token{signal=ENCODING, name='int32', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=24, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_FIELD, name='serviceControlStreamId', referencedName='null', description='null', id=7, version=0, deprecated=0, encodedLength=0, offset=36, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=ENCODING, name='int32', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=36, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} builder.Append("ServiceControlStreamId="); builder.Append(ServiceControlStreamId()); builder.Append('|'); - //Token{signal=BEGIN_FIELD, name='ingressStreamId', referencedName='null', description='null', id=7, version=0, deprecated=0, encodedLength=0, offset=28, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} - //Token{signal=ENCODING, name='int32', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=28, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_FIELD, name='ingressStreamId', referencedName='null', description='null', id=8, version=0, deprecated=0, encodedLength=0, offset=40, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=ENCODING, name='int32', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=40, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} builder.Append("IngressStreamId="); builder.Append(IngressStreamId()); builder.Append('|'); - //Token{signal=BEGIN_FIELD, name='memberId', referencedName='null', description='null', id=8, version=0, deprecated=0, encodedLength=0, offset=32, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} - //Token{signal=ENCODING, name='int32', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=32, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_FIELD, name='memberId', referencedName='null', description='null', id=9, version=0, deprecated=0, encodedLength=0, offset=44, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=ENCODING, name='int32', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=44, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} builder.Append("MemberId="); builder.Append(MemberId()); builder.Append('|'); - //Token{signal=BEGIN_FIELD, name='serviceId', referencedName='null', description='null', id=9, version=0, deprecated=0, encodedLength=0, offset=36, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} - //Token{signal=ENCODING, name='int32', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=36, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_FIELD, name='serviceId', referencedName='null', description='null', id=10, version=0, deprecated=0, encodedLength=0, offset=48, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=ENCODING, name='int32', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=48, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} builder.Append("ServiceId="); builder.Append(ServiceId()); builder.Append('|'); - //Token{signal=BEGIN_VAR_DATA, name='aeronDirectory', referencedName='null', description='null', id=10, version=0, deprecated=0, encodedLength=0, offset=128, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_VAR_DATA, name='aeronDirectory', referencedName='null', description='null', id=11, version=0, deprecated=0, encodedLength=0, offset=128, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} builder.Append("AeronDirectory="); builder.Append(AeronDirectory()); builder.Append('|'); - //Token{signal=BEGIN_VAR_DATA, name='archiveChannel', referencedName='null', description='null', id=11, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_VAR_DATA, name='archiveChannel', referencedName='null', description='null', id=12, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} builder.Append("ArchiveChannel="); builder.Append(ArchiveChannel()); builder.Append('|'); - //Token{signal=BEGIN_VAR_DATA, name='serviceControlChannel', referencedName='null', description='null', id=12, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_VAR_DATA, name='serviceControlChannel', referencedName='null', description='null', id=13, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} builder.Append("ServiceControlChannel="); builder.Append(ServiceControlChannel()); builder.Append('|'); - //Token{signal=BEGIN_VAR_DATA, name='ingressChannel', referencedName='null', description='null', id=13, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_VAR_DATA, name='ingressChannel', referencedName='null', description='null', id=14, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} builder.Append("IngressChannel="); builder.Append(IngressChannel()); builder.Append('|'); - //Token{signal=BEGIN_VAR_DATA, name='serviceName', referencedName='null', description='null', id=14, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_VAR_DATA, name='serviceName', referencedName='null', description='null', id=15, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} builder.Append("ServiceName="); builder.Append(ServiceName()); builder.Append('|'); - //Token{signal=BEGIN_VAR_DATA, name='authenticator', referencedName='null', description='null', id=15, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_VAR_DATA, name='authenticator', referencedName='null', description='null', id=16, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} builder.Append("Authenticator="); builder.Append(Authenticator()); diff --git a/src/Adaptive.Cluster/Codecs/CncHeaderEncoder.cs b/src/Adaptive.Cluster/Codecs/Mark/MarkFileHeaderEncoder.cs similarity index 83% rename from src/Adaptive.Cluster/Codecs/CncHeaderEncoder.cs rename to src/Adaptive.Cluster/Codecs/Mark/MarkFileHeaderEncoder.cs index 7a904d49..23f1011d 100644 --- a/src/Adaptive.Cluster/Codecs/CncHeaderEncoder.cs +++ b/src/Adaptive.Cluster/Codecs/Mark/MarkFileHeaderEncoder.cs @@ -5,21 +5,21 @@ using Adaptive.Agrona; -namespace Adaptive.Cluster.Codecs { +namespace Adaptive.Cluster.Codecs.Mark { -public class CncHeaderEncoder +public class MarkFileHeaderEncoder { public const ushort BLOCK_LENGTH = 128; public const ushort TEMPLATE_ID = 200; public const ushort SCHEMA_ID = 1; public const ushort SCHEMA_VERSION = 1; - private CncHeaderEncoder _parentMessage; + private MarkFileHeaderEncoder _parentMessage; private IMutableDirectBuffer _buffer; protected int _offset; protected int _limit; - public CncHeaderEncoder() + public MarkFileHeaderEncoder() { _parentMessage = this; } @@ -59,7 +59,7 @@ public int Offset() return _offset; } - public CncHeaderEncoder Wrap(IMutableDirectBuffer buffer, int offset) + public MarkFileHeaderEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; @@ -68,7 +68,7 @@ public CncHeaderEncoder Wrap(IMutableDirectBuffer buffer, int offset) return this; } - public CncHeaderEncoder WrapAndApplyHeader( + public MarkFileHeaderEncoder WrapAndApplyHeader( IMutableDirectBuffer buffer, int offset, MessageHeaderEncoder headerEncoder) { headerEncoder @@ -121,24 +121,24 @@ public static int VersionMaxValue() return 2147483647; } - public CncHeaderEncoder Version(int value) + public MarkFileHeaderEncoder Version(int value) { _buffer.PutInt(_offset + 0, value, ByteOrder.LittleEndian); return this; } - public static int FileTypeEncodingOffset() + public static int ComponentTypeEncodingOffset() { return 4; } - public static int FileTypeEncodingLength() + public static int ComponentTypeEncodingLength() { return 4; } - public CncHeaderEncoder FileType(ClusterComponentType value) + public MarkFileHeaderEncoder ComponentType(ClusterComponentType value) { _buffer.PutInt(_offset + 4, (int)value, ByteOrder.LittleEndian); return this; @@ -169,48 +169,80 @@ public static long ActivityTimestampMaxValue() return 9223372036854775807L; } - public CncHeaderEncoder ActivityTimestamp(long value) + public MarkFileHeaderEncoder ActivityTimestamp(long value) { _buffer.PutLong(_offset + 8, value, ByteOrder.LittleEndian); return this; } - public static int PidEncodingOffset() + public static int StartTimestampEncodingOffset() { return 16; } + public static int StartTimestampEncodingLength() + { + return 8; + } + + public static long StartTimestampNullValue() + { + return -9223372036854775808L; + } + + public static long StartTimestampMinValue() + { + return -9223372036854775807L; + } + + public static long StartTimestampMaxValue() + { + return 9223372036854775807L; + } + + public MarkFileHeaderEncoder StartTimestamp(long value) + { + _buffer.PutLong(_offset + 16, value, ByteOrder.LittleEndian); + return this; + } + + + public static int PidEncodingOffset() + { + return 24; + } + public static int PidEncodingLength() { - return 4; + return 8; } - public static int PidNullValue() + public static long PidNullValue() { - return -2147483648; + return -9223372036854775808L; } - public static int PidMinValue() + public static long PidMinValue() { - return -2147483647; + return -9223372036854775807L; } - public static int PidMaxValue() + public static long PidMaxValue() { - return 2147483647; + return 9223372036854775807L; } - public CncHeaderEncoder Pid(int value) + public MarkFileHeaderEncoder Pid(long value) { - _buffer.PutInt(_offset + 16, value, ByteOrder.LittleEndian); + _buffer.PutLong(_offset + 24, value, ByteOrder.LittleEndian); return this; } public static int ArchiveStreamIdEncodingOffset() { - return 20; + return 32; } public static int ArchiveStreamIdEncodingLength() @@ -233,16 +265,16 @@ public static int ArchiveStreamIdMaxValue() return 2147483647; } - public CncHeaderEncoder ArchiveStreamId(int value) + public MarkFileHeaderEncoder ArchiveStreamId(int value) { - _buffer.PutInt(_offset + 20, value, ByteOrder.LittleEndian); + _buffer.PutInt(_offset + 32, value, ByteOrder.LittleEndian); return this; } public static int ServiceControlStreamIdEncodingOffset() { - return 24; + return 36; } public static int ServiceControlStreamIdEncodingLength() @@ -265,16 +297,16 @@ public static int ServiceControlStreamIdMaxValue() return 2147483647; } - public CncHeaderEncoder ServiceControlStreamId(int value) + public MarkFileHeaderEncoder ServiceControlStreamId(int value) { - _buffer.PutInt(_offset + 24, value, ByteOrder.LittleEndian); + _buffer.PutInt(_offset + 36, value, ByteOrder.LittleEndian); return this; } public static int IngressStreamIdEncodingOffset() { - return 28; + return 40; } public static int IngressStreamIdEncodingLength() @@ -297,16 +329,16 @@ public static int IngressStreamIdMaxValue() return 2147483647; } - public CncHeaderEncoder IngressStreamId(int value) + public MarkFileHeaderEncoder IngressStreamId(int value) { - _buffer.PutInt(_offset + 28, value, ByteOrder.LittleEndian); + _buffer.PutInt(_offset + 40, value, ByteOrder.LittleEndian); return this; } public static int MemberIdEncodingOffset() { - return 32; + return 44; } public static int MemberIdEncodingLength() @@ -329,16 +361,16 @@ public static int MemberIdMaxValue() return 2147483647; } - public CncHeaderEncoder MemberId(int value) + public MarkFileHeaderEncoder MemberId(int value) { - _buffer.PutInt(_offset + 32, value, ByteOrder.LittleEndian); + _buffer.PutInt(_offset + 44, value, ByteOrder.LittleEndian); return this; } public static int ServiceIdEncodingOffset() { - return 36; + return 48; } public static int ServiceIdEncodingLength() @@ -361,16 +393,16 @@ public static int ServiceIdMaxValue() return 2147483647; } - public CncHeaderEncoder ServiceId(int value) + public MarkFileHeaderEncoder ServiceId(int value) { - _buffer.PutInt(_offset + 36, value, ByteOrder.LittleEndian); + _buffer.PutInt(_offset + 48, value, ByteOrder.LittleEndian); return this; } public static int AeronDirectoryId() { - return 10; + return 11; } public static string AeronDirectoryCharacterEncoding() @@ -396,7 +428,7 @@ public static int AeronDirectoryHeaderLength() return 4; } - public CncHeaderEncoder PutAeronDirectory(IDirectBuffer src, int srcOffset, int length) + public MarkFileHeaderEncoder PutAeronDirectory(IDirectBuffer src, int srcOffset, int length) { if (length > 1073741824) { @@ -412,7 +444,7 @@ public CncHeaderEncoder PutAeronDirectory(IDirectBuffer src, int srcOffset, int return this; } - public CncHeaderEncoder PutAeronDirectory(byte[] src, int srcOffset, int length) + public MarkFileHeaderEncoder PutAeronDirectory(byte[] src, int srcOffset, int length) { if (length > 1073741824) { @@ -428,7 +460,7 @@ public CncHeaderEncoder PutAeronDirectory(byte[] src, int srcOffset, int length) return this; } - public CncHeaderEncoder AeronDirectory(string value) + public MarkFileHeaderEncoder AeronDirectory(string value) { int length = value.Length; if (length > 1073741824) @@ -447,7 +479,7 @@ public CncHeaderEncoder AeronDirectory(string value) public static int ArchiveChannelId() { - return 11; + return 12; } public static string ArchiveChannelCharacterEncoding() @@ -473,7 +505,7 @@ public static int ArchiveChannelHeaderLength() return 4; } - public CncHeaderEncoder PutArchiveChannel(IDirectBuffer src, int srcOffset, int length) + public MarkFileHeaderEncoder PutArchiveChannel(IDirectBuffer src, int srcOffset, int length) { if (length > 1073741824) { @@ -489,7 +521,7 @@ public CncHeaderEncoder PutArchiveChannel(IDirectBuffer src, int srcOffset, int return this; } - public CncHeaderEncoder PutArchiveChannel(byte[] src, int srcOffset, int length) + public MarkFileHeaderEncoder PutArchiveChannel(byte[] src, int srcOffset, int length) { if (length > 1073741824) { @@ -505,7 +537,7 @@ public CncHeaderEncoder PutArchiveChannel(byte[] src, int srcOffset, int length) return this; } - public CncHeaderEncoder ArchiveChannel(string value) + public MarkFileHeaderEncoder ArchiveChannel(string value) { int length = value.Length; if (length > 1073741824) @@ -524,7 +556,7 @@ public CncHeaderEncoder ArchiveChannel(string value) public static int ServiceControlChannelId() { - return 12; + return 13; } public static string ServiceControlChannelCharacterEncoding() @@ -550,7 +582,7 @@ public static int ServiceControlChannelHeaderLength() return 4; } - public CncHeaderEncoder PutServiceControlChannel(IDirectBuffer src, int srcOffset, int length) + public MarkFileHeaderEncoder PutServiceControlChannel(IDirectBuffer src, int srcOffset, int length) { if (length > 1073741824) { @@ -566,7 +598,7 @@ public CncHeaderEncoder PutServiceControlChannel(IDirectBuffer src, int srcOffse return this; } - public CncHeaderEncoder PutServiceControlChannel(byte[] src, int srcOffset, int length) + public MarkFileHeaderEncoder PutServiceControlChannel(byte[] src, int srcOffset, int length) { if (length > 1073741824) { @@ -582,7 +614,7 @@ public CncHeaderEncoder PutServiceControlChannel(byte[] src, int srcOffset, int return this; } - public CncHeaderEncoder ServiceControlChannel(string value) + public MarkFileHeaderEncoder ServiceControlChannel(string value) { int length = value.Length; if (length > 1073741824) @@ -601,7 +633,7 @@ public CncHeaderEncoder ServiceControlChannel(string value) public static int IngressChannelId() { - return 13; + return 14; } public static string IngressChannelCharacterEncoding() @@ -627,7 +659,7 @@ public static int IngressChannelHeaderLength() return 4; } - public CncHeaderEncoder PutIngressChannel(IDirectBuffer src, int srcOffset, int length) + public MarkFileHeaderEncoder PutIngressChannel(IDirectBuffer src, int srcOffset, int length) { if (length > 1073741824) { @@ -643,7 +675,7 @@ public CncHeaderEncoder PutIngressChannel(IDirectBuffer src, int srcOffset, int return this; } - public CncHeaderEncoder PutIngressChannel(byte[] src, int srcOffset, int length) + public MarkFileHeaderEncoder PutIngressChannel(byte[] src, int srcOffset, int length) { if (length > 1073741824) { @@ -659,7 +691,7 @@ public CncHeaderEncoder PutIngressChannel(byte[] src, int srcOffset, int length) return this; } - public CncHeaderEncoder IngressChannel(string value) + public MarkFileHeaderEncoder IngressChannel(string value) { int length = value.Length; if (length > 1073741824) @@ -678,7 +710,7 @@ public CncHeaderEncoder IngressChannel(string value) public static int ServiceNameId() { - return 14; + return 15; } public static string ServiceNameCharacterEncoding() @@ -704,7 +736,7 @@ public static int ServiceNameHeaderLength() return 4; } - public CncHeaderEncoder PutServiceName(IDirectBuffer src, int srcOffset, int length) + public MarkFileHeaderEncoder PutServiceName(IDirectBuffer src, int srcOffset, int length) { if (length > 1073741824) { @@ -720,7 +752,7 @@ public CncHeaderEncoder PutServiceName(IDirectBuffer src, int srcOffset, int len return this; } - public CncHeaderEncoder PutServiceName(byte[] src, int srcOffset, int length) + public MarkFileHeaderEncoder PutServiceName(byte[] src, int srcOffset, int length) { if (length > 1073741824) { @@ -736,7 +768,7 @@ public CncHeaderEncoder PutServiceName(byte[] src, int srcOffset, int length) return this; } - public CncHeaderEncoder ServiceName(string value) + public MarkFileHeaderEncoder ServiceName(string value) { int length = value.Length; if (length > 1073741824) @@ -755,7 +787,7 @@ public CncHeaderEncoder ServiceName(string value) public static int AuthenticatorId() { - return 15; + return 16; } public static string AuthenticatorCharacterEncoding() @@ -781,7 +813,7 @@ public static int AuthenticatorHeaderLength() return 4; } - public CncHeaderEncoder PutAuthenticator(IDirectBuffer src, int srcOffset, int length) + public MarkFileHeaderEncoder PutAuthenticator(IDirectBuffer src, int srcOffset, int length) { if (length > 1073741824) { @@ -797,7 +829,7 @@ public CncHeaderEncoder PutAuthenticator(IDirectBuffer src, int srcOffset, int l return this; } - public CncHeaderEncoder PutAuthenticator(byte[] src, int srcOffset, int length) + public MarkFileHeaderEncoder PutAuthenticator(byte[] src, int srcOffset, int length) { if (length > 1073741824) { @@ -813,7 +845,7 @@ public CncHeaderEncoder PutAuthenticator(byte[] src, int srcOffset, int length) return this; } - public CncHeaderEncoder Authenticator(string value) + public MarkFileHeaderEncoder Authenticator(string value) { int length = value.Length; if (length > 1073741824) @@ -838,7 +870,7 @@ public override string ToString() public StringBuilder AppendTo(StringBuilder builder) { - CncHeaderDecoder writer = new CncHeaderDecoder(); + MarkFileHeaderDecoder writer = new MarkFileHeaderDecoder(); writer.Wrap(_buffer, _offset, BLOCK_LENGTH, SCHEMA_VERSION); return writer.AppendTo(builder); diff --git a/src/Adaptive.Cluster/Codecs/Mark/MessageHeaderDecoder.cs b/src/Adaptive.Cluster/Codecs/Mark/MessageHeaderDecoder.cs new file mode 100644 index 00000000..dd46cd91 --- /dev/null +++ b/src/Adaptive.Cluster/Codecs/Mark/MessageHeaderDecoder.cs @@ -0,0 +1,188 @@ +/* Generated SBE (Simple Binary Encoding) message codec */ +using System; +using System.Text; +using Adaptive.Agrona; + +namespace Adaptive.Cluster.Codecs.Mark { +public class MessageHeaderDecoder +{ + public static int ENCODED_LENGTH = 8; + private int _offset; + private IDirectBuffer _buffer; + + public MessageHeaderDecoder Wrap(IDirectBuffer buffer, int offset) + { + this._buffer = buffer; + this._offset = offset; + + return this; + } + + public IDirectBuffer Buffer() + { + return _buffer; + } + + public int Offset() + { + return _offset; + } + + public int EncodedLength() + { + return ENCODED_LENGTH; + } + + public static int BlockLengthEncodingOffset() + { + return 0; + } + + public static int BlockLengthEncodingLength() + { + return 2; + } + + public static ushort BlockLengthNullValue() + { + return 65535; + } + + public static ushort BlockLengthMinValue() + { + return 0; + } + + public static ushort BlockLengthMaxValue() + { + return 65534; + } + + public ushort BlockLength() + { + return unchecked((ushort)_buffer.GetShort(_offset + 0, ByteOrder.LittleEndian)); + } + + + public static int TemplateIdEncodingOffset() + { + return 2; + } + + public static int TemplateIdEncodingLength() + { + return 2; + } + + public static ushort TemplateIdNullValue() + { + return 65535; + } + + public static ushort TemplateIdMinValue() + { + return 0; + } + + public static ushort TemplateIdMaxValue() + { + return 65534; + } + + public ushort TemplateId() + { + return unchecked((ushort)_buffer.GetShort(_offset + 2, ByteOrder.LittleEndian)); + } + + + public static int SchemaIdEncodingOffset() + { + return 4; + } + + public static int SchemaIdEncodingLength() + { + return 2; + } + + public static ushort SchemaIdNullValue() + { + return 65535; + } + + public static ushort SchemaIdMinValue() + { + return 0; + } + + public static ushort SchemaIdMaxValue() + { + return 65534; + } + + public ushort SchemaId() + { + return unchecked((ushort)_buffer.GetShort(_offset + 4, ByteOrder.LittleEndian)); + } + + + public static int VersionEncodingOffset() + { + return 6; + } + + public static int VersionEncodingLength() + { + return 2; + } + + public static ushort VersionNullValue() + { + return 65535; + } + + public static ushort VersionMinValue() + { + return 0; + } + + public static ushort VersionMaxValue() + { + return 65534; + } + + public ushort Version() + { + return unchecked((ushort)_buffer.GetShort(_offset + 6, ByteOrder.LittleEndian)); + } + + + public override string ToString() + { + return AppendTo(new StringBuilder(100)).ToString(); + } + + public StringBuilder AppendTo(StringBuilder builder) + { + builder.Append('('); + //Token{signal=ENCODING, name='blockLength', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=2, offset=0, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=UINT16, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='null', timeUnit=null, semanticType='null'}} + builder.Append("BlockLength="); + builder.Append(BlockLength()); + builder.Append('|'); + //Token{signal=ENCODING, name='templateId', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=2, offset=2, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=UINT16, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='null', timeUnit=null, semanticType='null'}} + builder.Append("TemplateId="); + builder.Append(TemplateId()); + builder.Append('|'); + //Token{signal=ENCODING, name='schemaId', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=2, offset=4, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=UINT16, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='null', timeUnit=null, semanticType='null'}} + builder.Append("SchemaId="); + builder.Append(SchemaId()); + builder.Append('|'); + //Token{signal=ENCODING, name='version', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=2, offset=6, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=UINT16, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='null', timeUnit=null, semanticType='null'}} + builder.Append("Version="); + builder.Append(Version()); + builder.Append(')'); + + return builder; + } +} +} diff --git a/src/Adaptive.Cluster/Codecs/Mark/MessageHeaderEncoder.cs b/src/Adaptive.Cluster/Codecs/Mark/MessageHeaderEncoder.cs new file mode 100644 index 00000000..b0c422b7 --- /dev/null +++ b/src/Adaptive.Cluster/Codecs/Mark/MessageHeaderEncoder.cs @@ -0,0 +1,177 @@ +/* Generated SBE (Simple Binary Encoding) message codec */ +using System; +using System.Text; +using Adaptive.Agrona; + +namespace Adaptive.Cluster.Codecs.Mark { +public class MessageHeaderEncoder +{ + public static int ENCODED_LENGTH = 8; + private int _offset; + private IMutableDirectBuffer _buffer; + + public MessageHeaderEncoder Wrap(IMutableDirectBuffer buffer, int offset) + { + this._buffer = buffer; + this._offset = offset; + + return this; + } + + public IMutableDirectBuffer Buffer() + { + return _buffer; + } + + public int Offset() + { + return _offset; + } + + public int EncodedLength() + { + return ENCODED_LENGTH; + } + + public static int BlockLengthEncodingOffset() + { + return 0; + } + + public static int BlockLengthEncodingLength() + { + return 2; + } + + public static ushort BlockLengthNullValue() + { + return 65535; + } + + public static ushort BlockLengthMinValue() + { + return 0; + } + + public static ushort BlockLengthMaxValue() + { + return 65534; + } + + public MessageHeaderEncoder BlockLength(ushort value) + { + _buffer.PutShort(_offset + 0, unchecked((short)value), ByteOrder.LittleEndian); + return this; + } + + + public static int TemplateIdEncodingOffset() + { + return 2; + } + + public static int TemplateIdEncodingLength() + { + return 2; + } + + public static ushort TemplateIdNullValue() + { + return 65535; + } + + public static ushort TemplateIdMinValue() + { + return 0; + } + + public static ushort TemplateIdMaxValue() + { + return 65534; + } + + public MessageHeaderEncoder TemplateId(ushort value) + { + _buffer.PutShort(_offset + 2, unchecked((short)value), ByteOrder.LittleEndian); + return this; + } + + + public static int SchemaIdEncodingOffset() + { + return 4; + } + + public static int SchemaIdEncodingLength() + { + return 2; + } + + public static ushort SchemaIdNullValue() + { + return 65535; + } + + public static ushort SchemaIdMinValue() + { + return 0; + } + + public static ushort SchemaIdMaxValue() + { + return 65534; + } + + public MessageHeaderEncoder SchemaId(ushort value) + { + _buffer.PutShort(_offset + 4, unchecked((short)value), ByteOrder.LittleEndian); + return this; + } + + + public static int VersionEncodingOffset() + { + return 6; + } + + public static int VersionEncodingLength() + { + return 2; + } + + public static ushort VersionNullValue() + { + return 65535; + } + + public static ushort VersionMinValue() + { + return 0; + } + + public static ushort VersionMaxValue() + { + return 65534; + } + + public MessageHeaderEncoder Version(ushort value) + { + _buffer.PutShort(_offset + 6, unchecked((short)value), ByteOrder.LittleEndian); + return this; + } + + + public override string ToString() + { + return AppendTo(new StringBuilder(100)).ToString(); + } + + public StringBuilder AppendTo(StringBuilder builder) + { + MessageHeaderDecoder writer = new MessageHeaderDecoder(); + writer.Wrap(_buffer, _offset); + + return writer.AppendTo(builder); + } +} +} diff --git a/src/Adaptive.Cluster/Codecs/Mark/MetaAttribute.cs b/src/Adaptive.Cluster/Codecs/Mark/MetaAttribute.cs new file mode 100644 index 00000000..35b2888e --- /dev/null +++ b/src/Adaptive.Cluster/Codecs/Mark/MetaAttribute.cs @@ -0,0 +1,11 @@ +/* Generated SBE (Simple Binary Encoding) message codec */ +namespace Adaptive.Cluster.Codecs.Mark { + +public enum MetaAttribute +{ + EPOCH, + TIME_UNIT, + SEMANTIC_TYPE, + PRESENCE +} +} diff --git a/src/Adaptive.Cluster/Codecs/Mark/VarAsciiEncodingDecoder.cs b/src/Adaptive.Cluster/Codecs/Mark/VarAsciiEncodingDecoder.cs new file mode 100644 index 00000000..90866a27 --- /dev/null +++ b/src/Adaptive.Cluster/Codecs/Mark/VarAsciiEncodingDecoder.cs @@ -0,0 +1,110 @@ +/* Generated SBE (Simple Binary Encoding) message codec */ +using System; +using System.Text; +using Adaptive.Agrona; + +namespace Adaptive.Cluster.Codecs.Mark { +public class VarAsciiEncodingDecoder +{ + public static int ENCODED_LENGTH = -1; + private int _offset; + private IDirectBuffer _buffer; + + public VarAsciiEncodingDecoder Wrap(IDirectBuffer buffer, int offset) + { + this._buffer = buffer; + this._offset = offset; + + return this; + } + + public IDirectBuffer Buffer() + { + return _buffer; + } + + public int Offset() + { + return _offset; + } + + public int EncodedLength() + { + return ENCODED_LENGTH; + } + + public static int LengthEncodingOffset() + { + return 0; + } + + public static int LengthEncodingLength() + { + return 4; + } + + public static uint LengthNullValue() + { + return 4294967295; + } + + public static uint LengthMinValue() + { + return 0; + } + + public static uint LengthMaxValue() + { + return 1073741824; + } + + public uint Length() + { + return unchecked((uint)_buffer.GetInt(_offset + 0, ByteOrder.LittleEndian)); + } + + + public static int VarDataEncodingOffset() + { + return 4; + } + + public static int VarDataEncodingLength() + { + return -1; + } + + public static byte VarDataNullValue() + { + return (byte)255; + } + + public static byte VarDataMinValue() + { + return (byte)0; + } + + public static byte VarDataMaxValue() + { + return (byte)254; + } + + public override string ToString() + { + return AppendTo(new StringBuilder(100)).ToString(); + } + + public StringBuilder AppendTo(StringBuilder builder) + { + builder.Append('('); + //Token{signal=ENCODING, name='length', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=4, offset=0, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=UINT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=1073741824, nullValue=null, constValue=null, characterEncoding='null', epoch='null', timeUnit=null, semanticType='null'}} + builder.Append("Length="); + builder.Append(Length()); + builder.Append('|'); + //Token{signal=ENCODING, name='varData', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=-1, offset=4, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=UINT8, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='US-ASCII', epoch='null', timeUnit=null, semanticType='null'}} + builder.Append(')'); + + return builder; + } +} +} diff --git a/src/Adaptive.Cluster/Codecs/Mark/VarAsciiEncodingEncoder.cs b/src/Adaptive.Cluster/Codecs/Mark/VarAsciiEncodingEncoder.cs new file mode 100644 index 00000000..6b8d5ba9 --- /dev/null +++ b/src/Adaptive.Cluster/Codecs/Mark/VarAsciiEncodingEncoder.cs @@ -0,0 +1,106 @@ +/* Generated SBE (Simple Binary Encoding) message codec */ +using System; +using System.Text; +using Adaptive.Agrona; + +namespace Adaptive.Cluster.Codecs.Mark { +public class VarAsciiEncodingEncoder +{ + public static int ENCODED_LENGTH = -1; + private int _offset; + private IMutableDirectBuffer _buffer; + + public VarAsciiEncodingEncoder Wrap(IMutableDirectBuffer buffer, int offset) + { + this._buffer = buffer; + this._offset = offset; + + return this; + } + + public IMutableDirectBuffer Buffer() + { + return _buffer; + } + + public int Offset() + { + return _offset; + } + + public int EncodedLength() + { + return ENCODED_LENGTH; + } + + public static int LengthEncodingOffset() + { + return 0; + } + + public static int LengthEncodingLength() + { + return 4; + } + + public static uint LengthNullValue() + { + return 4294967295; + } + + public static uint LengthMinValue() + { + return 0; + } + + public static uint LengthMaxValue() + { + return 1073741824; + } + + public VarAsciiEncodingEncoder Length(uint value) + { + _buffer.PutInt(_offset + 0, unchecked((int)value), ByteOrder.LittleEndian); + return this; + } + + + public static int VarDataEncodingOffset() + { + return 4; + } + + public static int VarDataEncodingLength() + { + return -1; + } + + public static byte VarDataNullValue() + { + return (byte)255; + } + + public static byte VarDataMinValue() + { + return (byte)0; + } + + public static byte VarDataMaxValue() + { + return (byte)254; + } + + public override string ToString() + { + return AppendTo(new StringBuilder(100)).ToString(); + } + + public StringBuilder AppendTo(StringBuilder builder) + { + VarAsciiEncodingDecoder writer = new VarAsciiEncodingDecoder(); + writer.Wrap(_buffer, _offset); + + return writer.AppendTo(builder); + } +} +} diff --git a/src/Adaptive.Cluster/Codecs/ScheduleTimerRequestDecoder.cs b/src/Adaptive.Cluster/Codecs/ScheduleTimerDecoder.cs similarity index 96% rename from src/Adaptive.Cluster/Codecs/ScheduleTimerRequestDecoder.cs rename to src/Adaptive.Cluster/Codecs/ScheduleTimerDecoder.cs index 48c33b31..3bf68f06 100644 --- a/src/Adaptive.Cluster/Codecs/ScheduleTimerRequestDecoder.cs +++ b/src/Adaptive.Cluster/Codecs/ScheduleTimerDecoder.cs @@ -7,21 +7,21 @@ namespace Adaptive.Cluster.Codecs { -public class ScheduleTimerRequestDecoder +public class ScheduleTimerDecoder { public const ushort BLOCK_LENGTH = 16; public const ushort TEMPLATE_ID = 30; public const ushort SCHEMA_ID = 1; public const ushort SCHEMA_VERSION = 1; - private ScheduleTimerRequestDecoder _parentMessage; + private ScheduleTimerDecoder _parentMessage; private IDirectBuffer _buffer; protected int _offset; protected int _limit; protected int _actingBlockLength; protected int _actingVersion; - public ScheduleTimerRequestDecoder() + public ScheduleTimerDecoder() { _parentMessage = this; } @@ -61,7 +61,7 @@ public int Offset() return _offset; } - public ScheduleTimerRequestDecoder Wrap( + public ScheduleTimerDecoder Wrap( IDirectBuffer buffer, int offset, int actingBlockLength, int actingVersion) { this._buffer = buffer; @@ -206,7 +206,7 @@ public StringBuilder AppendTo(StringBuilder builder) { int originalLimit = Limit(); Limit(_offset + _actingBlockLength); - builder.Append("[ScheduleTimerRequest](sbeTemplateId="); + builder.Append("[ScheduleTimer](sbeTemplateId="); builder.Append(TEMPLATE_ID); builder.Append("|sbeSchemaId="); builder.Append(SCHEMA_ID); diff --git a/src/Adaptive.Cluster/Codecs/ScheduleTimerRequestEncoder.cs b/src/Adaptive.Cluster/Codecs/ScheduleTimerEncoder.cs similarity index 86% rename from src/Adaptive.Cluster/Codecs/ScheduleTimerRequestEncoder.cs rename to src/Adaptive.Cluster/Codecs/ScheduleTimerEncoder.cs index be7ac6c1..f4fa6a94 100644 --- a/src/Adaptive.Cluster/Codecs/ScheduleTimerRequestEncoder.cs +++ b/src/Adaptive.Cluster/Codecs/ScheduleTimerEncoder.cs @@ -7,19 +7,19 @@ namespace Adaptive.Cluster.Codecs { -public class ScheduleTimerRequestEncoder +public class ScheduleTimerEncoder { public const ushort BLOCK_LENGTH = 16; public const ushort TEMPLATE_ID = 30; public const ushort SCHEMA_ID = 1; public const ushort SCHEMA_VERSION = 1; - private ScheduleTimerRequestEncoder _parentMessage; + private ScheduleTimerEncoder _parentMessage; private IMutableDirectBuffer _buffer; protected int _offset; protected int _limit; - public ScheduleTimerRequestEncoder() + public ScheduleTimerEncoder() { _parentMessage = this; } @@ -59,7 +59,7 @@ public int Offset() return _offset; } - public ScheduleTimerRequestEncoder Wrap(IMutableDirectBuffer buffer, int offset) + public ScheduleTimerEncoder Wrap(IMutableDirectBuffer buffer, int offset) { this._buffer = buffer; this._offset = offset; @@ -68,7 +68,7 @@ public ScheduleTimerRequestEncoder Wrap(IMutableDirectBuffer buffer, int offset) return this; } - public ScheduleTimerRequestEncoder WrapAndApplyHeader( + public ScheduleTimerEncoder WrapAndApplyHeader( IMutableDirectBuffer buffer, int offset, MessageHeaderEncoder headerEncoder) { headerEncoder @@ -121,7 +121,7 @@ public static long CorrelationIdMaxValue() return 9223372036854775807L; } - public ScheduleTimerRequestEncoder CorrelationId(long value) + public ScheduleTimerEncoder CorrelationId(long value) { _buffer.PutLong(_offset + 0, value, ByteOrder.LittleEndian); return this; @@ -153,7 +153,7 @@ public static long DeadlineMaxValue() return 9223372036854775807L; } - public ScheduleTimerRequestEncoder Deadline(long value) + public ScheduleTimerEncoder Deadline(long value) { _buffer.PutLong(_offset + 8, value, ByteOrder.LittleEndian); return this; @@ -168,7 +168,7 @@ public override string ToString() public StringBuilder AppendTo(StringBuilder builder) { - ScheduleTimerRequestDecoder writer = new ScheduleTimerRequestDecoder(); + ScheduleTimerDecoder writer = new ScheduleTimerDecoder(); writer.Wrap(_buffer, _offset, BLOCK_LENGTH, SCHEMA_VERSION); return writer.AppendTo(builder); diff --git a/src/Adaptive.Cluster/Codecs/SequencerDecoder.cs b/src/Adaptive.Cluster/Codecs/SequencerDecoder.cs new file mode 100644 index 00000000..c6cef790 --- /dev/null +++ b/src/Adaptive.Cluster/Codecs/SequencerDecoder.cs @@ -0,0 +1,184 @@ +/* Generated SBE (Simple Binary Encoding) message codec */ +using System; +using System.Text; +using System.Collections.Generic; +using Adaptive.Agrona; + + +namespace Adaptive.Cluster.Codecs { + +public class SequencerDecoder +{ + public const ushort BLOCK_LENGTH = 8; + public const ushort TEMPLATE_ID = 105; + public const ushort SCHEMA_ID = 1; + public const ushort SCHEMA_VERSION = 1; + + private SequencerDecoder _parentMessage; + private IDirectBuffer _buffer; + protected int _offset; + protected int _limit; + protected int _actingBlockLength; + protected int _actingVersion; + + public SequencerDecoder() + { + _parentMessage = this; + } + + public ushort SbeBlockLength() + { + return BLOCK_LENGTH; + } + + public ushort SbeTemplateId() + { + return TEMPLATE_ID; + } + + public ushort SbeSchemaId() + { + return SCHEMA_ID; + } + + public ushort SbeSchemaVersion() + { + return SCHEMA_VERSION; + } + + public string SbeSemanticType() + { + return ""; + } + + public IDirectBuffer Buffer() + { + return _buffer; + } + + public int Offset() + { + return _offset; + } + + public SequencerDecoder Wrap( + IDirectBuffer buffer, int offset, int actingBlockLength, int actingVersion) + { + this._buffer = buffer; + this._offset = offset; + this._actingBlockLength = actingBlockLength; + this._actingVersion = actingVersion; + Limit(offset + actingBlockLength); + + return this; + } + + public int EncodedLength() + { + return _limit - _offset; + } + + public int Limit() + { + return _limit; + } + + public void Limit(int limit) + { + this._limit = limit; + } + + public static int NextSessionIdId() + { + return 1; + } + + public static int NextSessionIdSinceVersion() + { + return 0; + } + + public static int NextSessionIdEncodingOffset() + { + return 0; + } + + public static int NextSessionIdEncodingLength() + { + return 8; + } + + public static string NextSessionIdMetaAttribute(MetaAttribute metaAttribute) + { + switch (metaAttribute) + { + case MetaAttribute.EPOCH: return "unix"; + case MetaAttribute.TIME_UNIT: return "nanosecond"; + case MetaAttribute.SEMANTIC_TYPE: return ""; + case MetaAttribute.PRESENCE: return "required"; + } + + return ""; + } + + public static long NextSessionIdNullValue() + { + return -9223372036854775808L; + } + + public static long NextSessionIdMinValue() + { + return -9223372036854775807L; + } + + public static long NextSessionIdMaxValue() + { + return 9223372036854775807L; + } + + public long NextSessionId() + { + return _buffer.GetLong(_offset + 0, ByteOrder.LittleEndian); + } + + + + public override string ToString() + { + return AppendTo(new StringBuilder(100)).ToString(); + } + + public StringBuilder AppendTo(StringBuilder builder) + { + int originalLimit = Limit(); + Limit(_offset + _actingBlockLength); + builder.Append("[Sequencer](sbeTemplateId="); + builder.Append(TEMPLATE_ID); + builder.Append("|sbeSchemaId="); + builder.Append(SCHEMA_ID); + builder.Append("|sbeSchemaVersion="); + if (_parentMessage._actingVersion != SCHEMA_VERSION) + { + builder.Append(_parentMessage._actingVersion); + builder.Append('/'); + } + builder.Append(SCHEMA_VERSION); + builder.Append("|sbeBlockLength="); + if (_actingBlockLength != BLOCK_LENGTH) + { + builder.Append(_actingBlockLength); + builder.Append('/'); + } + builder.Append(BLOCK_LENGTH); + builder.Append("):"); + //Token{signal=BEGIN_FIELD, name='nextSessionId', referencedName='null', description='null', id=1, version=0, deprecated=0, encodedLength=0, offset=0, componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=ENCODING, name='int64', referencedName='null', description='null', id=-1, version=0, deprecated=0, encodedLength=8, offset=0, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, primitiveType=INT64, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + builder.Append("NextSessionId="); + builder.Append(NextSessionId()); + + Limit(originalLimit); + + return builder; + } +} +} diff --git a/src/Adaptive.Cluster/Codecs/SequencerEncoder.cs b/src/Adaptive.Cluster/Codecs/SequencerEncoder.cs new file mode 100644 index 00000000..3589cd22 --- /dev/null +++ b/src/Adaptive.Cluster/Codecs/SequencerEncoder.cs @@ -0,0 +1,145 @@ +/* Generated SBE (Simple Binary Encoding) message codec */ +using System; +using System.Text; +using System.Collections.Generic; +using Adaptive.Agrona; + + +namespace Adaptive.Cluster.Codecs { + +public class SequencerEncoder +{ + public const ushort BLOCK_LENGTH = 8; + public const ushort TEMPLATE_ID = 105; + public const ushort SCHEMA_ID = 1; + public const ushort SCHEMA_VERSION = 1; + + private SequencerEncoder _parentMessage; + private IMutableDirectBuffer _buffer; + protected int _offset; + protected int _limit; + + public SequencerEncoder() + { + _parentMessage = this; + } + + public ushort SbeBlockLength() + { + return BLOCK_LENGTH; + } + + public ushort SbeTemplateId() + { + return TEMPLATE_ID; + } + + public ushort SbeSchemaId() + { + return SCHEMA_ID; + } + + public ushort SbeSchemaVersion() + { + return SCHEMA_VERSION; + } + + public string SbeSemanticType() + { + return ""; + } + + public IMutableDirectBuffer Buffer() + { + return _buffer; + } + + public int Offset() + { + return _offset; + } + + public SequencerEncoder Wrap(IMutableDirectBuffer buffer, int offset) + { + this._buffer = buffer; + this._offset = offset; + Limit(offset + BLOCK_LENGTH); + + return this; + } + + public SequencerEncoder WrapAndApplyHeader( + IMutableDirectBuffer buffer, int offset, MessageHeaderEncoder headerEncoder) + { + headerEncoder + .Wrap(buffer, offset) + .BlockLength(BLOCK_LENGTH) + .TemplateId(TEMPLATE_ID) + .SchemaId(SCHEMA_ID) + .Version(SCHEMA_VERSION); + + return Wrap(buffer, offset + MessageHeaderEncoder.ENCODED_LENGTH); + } + + public int EncodedLength() + { + return _limit - _offset; + } + + public int Limit() + { + return _limit; + } + + public void Limit(int limit) + { + this._limit = limit; + } + + public static int NextSessionIdEncodingOffset() + { + return 0; + } + + public static int NextSessionIdEncodingLength() + { + return 8; + } + + public static long NextSessionIdNullValue() + { + return -9223372036854775808L; + } + + public static long NextSessionIdMinValue() + { + return -9223372036854775807L; + } + + public static long NextSessionIdMaxValue() + { + return 9223372036854775807L; + } + + public SequencerEncoder NextSessionId(long value) + { + _buffer.PutLong(_offset + 0, value, ByteOrder.LittleEndian); + return this; + } + + + + public override string ToString() + { + return AppendTo(new StringBuilder(100)).ToString(); + } + + public StringBuilder AppendTo(StringBuilder builder) + { + SequencerDecoder writer = new SequencerDecoder(); + writer.Wrap(_buffer, _offset, BLOCK_LENGTH, SCHEMA_VERSION); + + return writer.AppendTo(builder); + } +} +} diff --git a/src/Adaptive.Cluster/Codecs/SessionCloseEventDecoder.cs b/src/Adaptive.Cluster/Codecs/SessionCloseEventDecoder.cs index dba3a831..191fdeb1 100644 --- a/src/Adaptive.Cluster/Codecs/SessionCloseEventDecoder.cs +++ b/src/Adaptive.Cluster/Codecs/SessionCloseEventDecoder.cs @@ -333,8 +333,8 @@ public StringBuilder AppendTo(StringBuilder builder) builder.Append("Timestamp="); builder.Append(Timestamp()); builder.Append('|'); - //Token{signal=BEGIN_FIELD, name='closeReason', referencedName='null', description='null', id=4, version=0, deprecated=0, encodedLength=0, offset=24, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} - //Token{signal=BEGIN_ENUM, name='CloseReason', referencedName='null', description='Reason why a session was closed', id=-1, version=0, deprecated=0, encodedLength=4, offset=24, componentTokenCount=4, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='null', timeUnit=null, semanticType='null'}} + //Token{signal=BEGIN_FIELD, name='closeReason', referencedName='null', description='null', id=4, version=0, deprecated=0, encodedLength=0, offset=24, componentTokenCount=7, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + //Token{signal=BEGIN_ENUM, name='CloseReason', referencedName='null', description='Reason why a session was closed', id=-1, version=0, deprecated=0, encodedLength=4, offset=24, componentTokenCount=5, encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='null', timeUnit=null, semanticType='null'}} builder.Append("CloseReason="); builder.Append(CloseReason()); diff --git a/src/Adaptive.Cluster/Codecs/SessionOpenEventDecoder.cs b/src/Adaptive.Cluster/Codecs/SessionOpenEventDecoder.cs index 0d1f7f30..f4998cf6 100644 --- a/src/Adaptive.Cluster/Codecs/SessionOpenEventDecoder.cs +++ b/src/Adaptive.Cluster/Codecs/SessionOpenEventDecoder.cs @@ -379,17 +379,17 @@ public string ResponseChannel() return Encoding.ASCII.GetString(tmp); } - public static int PrincipalDataId() + public static int EncodedPrincipalId() { return 6; } - public static int PrincipalDataSinceVersion() + public static int EncodedPrincipalSinceVersion() { return 0; } - public static string PrincipalDataMetaAttribute(MetaAttribute metaAttribute) + public static string EncodedPrincipalMetaAttribute(MetaAttribute metaAttribute) { switch (metaAttribute) { @@ -402,18 +402,18 @@ public static string PrincipalDataMetaAttribute(MetaAttribute metaAttribute) return ""; } - public static int PrincipalDataHeaderLength() + public static int EncodedPrincipalHeaderLength() { return 4; } - public int PrincipalDataLength() + public int EncodedPrincipalLength() { int limit = _parentMessage.Limit(); return (int)unchecked((uint)_buffer.GetInt(limit, ByteOrder.LittleEndian)); } - public int GetPrincipalData(IMutableDirectBuffer dst, int dstOffset, int length) + public int GetEncodedPrincipal(IMutableDirectBuffer dst, int dstOffset, int length) { int headerLength = 4; int limit = _parentMessage.Limit(); @@ -425,7 +425,7 @@ public int GetPrincipalData(IMutableDirectBuffer dst, int dstOffset, int length) return bytesCopied; } - public int GetPrincipalData(byte[] dst, int dstOffset, int length) + public int GetEncodedPrincipal(byte[] dst, int dstOffset, int length) { int headerLength = 4; int limit = _parentMessage.Limit(); @@ -490,9 +490,9 @@ public StringBuilder AppendTo(StringBuilder builder) builder.Append("ResponseChannel="); builder.Append(ResponseChannel()); builder.Append('|'); - //Token{signal=BEGIN_VAR_DATA, name='principalData', referencedName='null', description='null', id=6, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} - builder.Append("PrincipalData="); - builder.Append(PrincipalDataLength() + " raw bytes"); + //Token{signal=BEGIN_VAR_DATA, name='encodedPrincipal', referencedName='null', description='null', id=6, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} + builder.Append("EncodedPrincipal="); + builder.Append(EncodedPrincipalLength() + " raw bytes"); Limit(originalLimit); diff --git a/src/Adaptive.Cluster/Codecs/SessionOpenEventEncoder.cs b/src/Adaptive.Cluster/Codecs/SessionOpenEventEncoder.cs index 2bcdf909..3e730762 100644 --- a/src/Adaptive.Cluster/Codecs/SessionOpenEventEncoder.cs +++ b/src/Adaptive.Cluster/Codecs/SessionOpenEventEncoder.cs @@ -301,12 +301,12 @@ public SessionOpenEventEncoder ResponseChannel(string value) return this; } - public static int PrincipalDataId() + public static int EncodedPrincipalId() { return 6; } - public static string PrincipalDataMetaAttribute(MetaAttribute metaAttribute) + public static string EncodedPrincipalMetaAttribute(MetaAttribute metaAttribute) { switch (metaAttribute) { @@ -319,12 +319,12 @@ public static string PrincipalDataMetaAttribute(MetaAttribute metaAttribute) return ""; } - public static int PrincipalDataHeaderLength() + public static int EncodedPrincipalHeaderLength() { return 4; } - public SessionOpenEventEncoder PutPrincipalData(IDirectBuffer src, int srcOffset, int length) + public SessionOpenEventEncoder PutEncodedPrincipal(IDirectBuffer src, int srcOffset, int length) { if (length > 1073741824) { @@ -340,7 +340,7 @@ public SessionOpenEventEncoder PutPrincipalData(IDirectBuffer src, int srcOffset return this; } - public SessionOpenEventEncoder PutPrincipalData(byte[] src, int srcOffset, int length) + public SessionOpenEventEncoder PutEncodedPrincipal(byte[] src, int srcOffset, int length) { if (length > 1073741824) { diff --git a/src/Adaptive.Cluster/Service/BoundedLogAdapter.cs b/src/Adaptive.Cluster/Service/BoundedLogAdapter.cs index a76ab0d8..5dbd235a 100644 --- a/src/Adaptive.Cluster/Service/BoundedLogAdapter.cs +++ b/src/Adaptive.Cluster/Service/BoundedLogAdapter.cs @@ -83,10 +83,10 @@ public ControlledFragmentHandlerAction OnFragment(IDirectBuffer buffer, int offs openEventDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version()); string responseChannel = openEventDecoder.ResponseChannel(); - byte[] principalData = new byte[openEventDecoder.PrincipalDataLength()]; - openEventDecoder.GetPrincipalData(principalData, 0, principalData.Length); + byte[] encodedPrincipal = new byte[openEventDecoder.EncodedPrincipalLength()]; + openEventDecoder.GetEncodedPrincipal(encodedPrincipal, 0, encodedPrincipal.Length); - agent.OnSessionOpen(openEventDecoder.ClusterSessionId(), openEventDecoder.Timestamp(), openEventDecoder.ResponseStreamId(), responseChannel, principalData); + agent.OnSessionOpen(openEventDecoder.ClusterSessionId(), openEventDecoder.Timestamp(), openEventDecoder.ResponseStreamId(), responseChannel, encodedPrincipal); break; } diff --git a/src/Adaptive.Cluster/Service/ClientSession.cs b/src/Adaptive.Cluster/Service/ClientSession.cs index f93d055b..65018660 100644 --- a/src/Adaptive.Cluster/Service/ClientSession.cs +++ b/src/Adaptive.Cluster/Service/ClientSession.cs @@ -20,18 +20,18 @@ public class ClientSession private readonly int _responseStreamId; private readonly string _responseChannel; private Publication _responsePublication; - private readonly byte[] _principalData; + private readonly byte[] _encodedPrincipal; private readonly DirectBufferVector[] _vectors = new DirectBufferVector[2]; private readonly DirectBufferVector _messageBuffer = new DirectBufferVector(); private readonly SessionHeaderEncoder _sessionHeaderEncoder = new SessionHeaderEncoder(); private readonly ICluster _cluster; - internal ClientSession(long sessionId, int responseStreamId, string responseChannel, byte[] principalData, ICluster cluster) + internal ClientSession(long sessionId, int responseStreamId, string responseChannel, byte[] encodedPrincipal, ICluster cluster) { _id = sessionId; _responseStreamId = responseStreamId; _responseChannel = responseChannel; - _principalData = principalData; + _encodedPrincipal = encodedPrincipal; _cluster = cluster; UnsafeBuffer headerBuffer = new UnsafeBuffer(new byte[SESSION_HEADER_LENGTH]); @@ -69,13 +69,13 @@ public string ResponseChannel() } /// - /// Cluster session principal data passed from + /// Cluster session encoded principal passed from /// when the session was authenticated. /// - /// The Principal data passed. May be 0 length to indicate no data. - public byte[] PrincipalData() + /// The encoded Principal passed. May be 0 length to indicate none present. + public byte[] EncodedPrincipal() { - return _principalData; + return _encodedPrincipal; } /// @@ -108,7 +108,7 @@ internal void Connect(Aeron.Aeron aeron) throw new InvalidOperationException("Response publication already present"); } - _responsePublication = aeron.AddExclusivePublication(_responseChannel, _responseStreamId); + _responsePublication = aeron.AddPublication(_responseChannel, _responseStreamId); } internal void Disconnect() diff --git a/src/Adaptive.Cluster/Service/ClusterCncFile.cs b/src/Adaptive.Cluster/Service/ClusterCncFile.cs deleted file mode 100644 index 0d1ea901..00000000 --- a/src/Adaptive.Cluster/Service/ClusterCncFile.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using Adaptive.Agrona; -using Adaptive.Agrona.Concurrent; -using Adaptive.Cluster.Codecs; - -namespace Adaptive.Cluster.Service -{ - public class ClusterCncFile : IDisposable - { - public const string FILENAME = "cnc.dat"; - public const int ALIGNMENT = 1024; - - private readonly CncHeaderDecoder cncHeaderDecoder; - private readonly CncHeaderEncoder cncHeaderEncoder; - private readonly CncFile cncFile; - private readonly UnsafeBuffer cncBuffer; - - public ClusterCncFile(FileInfo file, ClusterComponentType type, int totalFileLength, IEpochClock epochClock, long timeoutMs) - { - cncFile = new CncFile(file, file.Exists, CncHeaderDecoder.VersionEncodingOffset(), CncHeaderDecoder.ActivityTimestampEncodingOffset(), totalFileLength, timeoutMs, epochClock, (version) => - { - if (version != CncHeaderDecoder.SCHEMA_VERSION) - { - throw new ArgumentException("CnC file version " + version + " does not match software:" + CncHeaderDecoder.SCHEMA_VERSION); - } - }, null); - - cncBuffer = cncFile.Buffer(); - - cncHeaderDecoder = new CncHeaderDecoder(); - cncHeaderEncoder = new CncHeaderEncoder(); - - cncHeaderEncoder.Wrap(cncBuffer, 0); - cncHeaderDecoder.Wrap(cncBuffer, 0, CncHeaderDecoder.BLOCK_LENGTH, CncHeaderDecoder.SCHEMA_VERSION); - - ClusterComponentType existingType = cncHeaderDecoder.FileType(); - - if (existingType != ClusterComponentType.NULL && existingType != type) - { - throw new InvalidOperationException("existing CnC file type " + existingType + " not same as required type " + type); - } - - cncHeaderEncoder.FileType(type); - cncHeaderEncoder.Pid(Process.GetCurrentProcess().Id); - } - - public ClusterCncFile(DirectoryInfo directory, string filename, IEpochClock epochClock, long timeoutMs, Action logger) - { - cncFile = new CncFile(directory, filename, CncHeaderDecoder.VersionEncodingOffset(), CncHeaderDecoder.ActivityTimestampEncodingOffset(), timeoutMs, epochClock, (version) => - { - if (version != CncHeaderDecoder.SCHEMA_VERSION) - { - throw new ArgumentException("CnC file version " + version + " does not match software:" + CncHeaderDecoder.SCHEMA_VERSION); - } - }, logger); - - cncBuffer = cncFile.Buffer(); - - cncHeaderDecoder = new CncHeaderDecoder(); - cncHeaderEncoder = null; - - cncHeaderDecoder.Wrap(cncBuffer, 0, CncHeaderDecoder.BLOCK_LENGTH, CncHeaderDecoder.SCHEMA_VERSION); - } - - public virtual void Dispose() - { - cncFile?.Dispose(); - } - - public virtual void SignalCncReady() - { - cncFile.SignalCncReady(CncHeaderEncoder.SCHEMA_VERSION); - } - - public virtual void UpdateActivityTimestamp(long nowMs) - { - cncFile.TimestampOrdered(nowMs); - } - - public virtual CncHeaderEncoder Encoder() - { - return cncHeaderEncoder; - } - - public virtual CncHeaderDecoder Decoder() - { - return cncHeaderDecoder; - } - - public static int AlignedTotalFileLength(int alignment, string aeronDirectory, string archiveChannel, string serviceControlChannel, string ingressChannel, string serviceName, string authenticator) - { - if (aeronDirectory == null) throw new ArgumentNullException(nameof(aeronDirectory)); - if (archiveChannel == null) throw new ArgumentNullException(nameof(archiveChannel)); - if (serviceControlChannel == null) throw new ArgumentNullException(nameof(serviceControlChannel)); - - return BitUtil.Align(CncHeaderEncoder.BLOCK_LENGTH + (6 * VarAsciiEncodingEncoder.LengthEncodingLength()) + aeronDirectory.Length + archiveChannel.Length + serviceControlChannel.Length + ((null == ingressChannel) ? 0 : ingressChannel.Length) + ((null == serviceName) ? 0 : serviceName.Length) + ((null == authenticator) ? 0 : authenticator.Length), alignment); - } - } -} \ No newline at end of file diff --git a/src/Adaptive.Cluster/Service/ClusterMarkFile.cs b/src/Adaptive.Cluster/Service/ClusterMarkFile.cs new file mode 100644 index 00000000..7faf3622 --- /dev/null +++ b/src/Adaptive.Cluster/Service/ClusterMarkFile.cs @@ -0,0 +1,100 @@ +using System; +using System.Diagnostics; +using System.IO; +using Adaptive.Agrona; +using Adaptive.Agrona.Concurrent; +using Adaptive.Cluster.Codecs.Mark; + +namespace Adaptive.Cluster +{ + public class ClusterMarkFile : IDisposable +{ + public const string FILENAME = "cluster-mark.dat"; + public const int ALIGNMENT = 1024; + + private readonly MarkFileHeaderDecoder headerDecoder = new MarkFileHeaderDecoder(); + private readonly MarkFileHeaderEncoder headerEncoder = new MarkFileHeaderEncoder(); + private readonly MarkFile markFile; + private readonly UnsafeBuffer buffer; + + public ClusterMarkFile(FileInfo file, ClusterComponentType type, int totalFileLength, IEpochClock epochClock, long timeoutMs) + { + markFile = new MarkFile(file, file.Exists, MarkFileHeaderDecoder.VersionEncodingOffset(), MarkFileHeaderDecoder.ActivityTimestampEncodingOffset(), totalFileLength, timeoutMs, epochClock, (version) => + { + if (version != MarkFileHeaderDecoder.SCHEMA_VERSION) + { + throw new ArgumentException("Mark file version " + version + " does not match software:" + MarkFileHeaderDecoder.SCHEMA_VERSION); + } + }, null); + + buffer = markFile.Buffer(); + + headerEncoder.Wrap(buffer, 0); + headerDecoder.Wrap(buffer, 0, MarkFileHeaderDecoder.BLOCK_LENGTH, MarkFileHeaderDecoder.SCHEMA_VERSION); + + var existingType = headerDecoder.ComponentType(); + + if (existingType != ClusterComponentType.NULL && existingType != type) + { + throw new InvalidOperationException("existing Mark file type " + existingType + " not same as required type " + type); + } + + headerEncoder.ComponentType(type); + headerEncoder.Pid(Process.GetCurrentProcess().Id); + } + + public ClusterMarkFile(DirectoryInfo directory, string filename, IEpochClock epochClock, long timeoutMs, Action logger) + { + markFile = new MarkFile(directory, filename, MarkFileHeaderDecoder.VersionEncodingOffset(), MarkFileHeaderDecoder.ActivityTimestampEncodingOffset(), timeoutMs, epochClock, (version) => + { + if (version != MarkFileHeaderDecoder.SCHEMA_VERSION) + { + throw new ArgumentException("Mark file version " + version + " does not match software:" + MarkFileHeaderDecoder.SCHEMA_VERSION); + } + }, logger); + + buffer = markFile.Buffer(); + headerDecoder.Wrap(buffer, 0, MarkFileHeaderDecoder.BLOCK_LENGTH, MarkFileHeaderDecoder.SCHEMA_VERSION); + } + + public void Dispose() + { + markFile?.Dispose(); + } + + public void SignalReady() + { + markFile.SignalReady(MarkFileHeaderDecoder.SCHEMA_VERSION); + } + + public void UpdateActivityTimestamp(long nowMs) + { + markFile.TimestampOrdered(nowMs); + } + + public long ActivityTimestampVolatile() + { + return markFile.TimestampVolatile(); + } + + public MarkFileHeaderEncoder Encoder() + { + return headerEncoder; + } + + public MarkFileHeaderDecoder Decoder() + { + return headerDecoder; + } + + public static int AlignedTotalFileLength(int alignment, string aeronDirectory, string archiveChannel, string serviceControlChannel, string ingressChannel, string serviceName, string authenticator) + { + if (aeronDirectory == null) throw new ArgumentNullException(nameof(aeronDirectory)); + if (archiveChannel == null) throw new ArgumentNullException(nameof(archiveChannel)); + if (serviceControlChannel == null) throw new ArgumentNullException(nameof(serviceControlChannel)); + + return BitUtil.Align(MarkFileHeaderEncoder.BLOCK_LENGTH + (6 * VarAsciiEncodingEncoder.LengthEncodingLength()) + aeronDirectory.Length + archiveChannel.Length + serviceControlChannel.Length + (null == ingressChannel ? 0 : ingressChannel.Length) + (null == serviceName ? 0 : serviceName.Length) + (null == authenticator ? 0 : authenticator.Length), alignment); + } +} + +} \ No newline at end of file diff --git a/src/Adaptive.Cluster/Service/ClusteredServiceAgent.cs b/src/Adaptive.Cluster/Service/ClusteredServiceAgent.cs index 3c18b774..c99bbb0e 100644 --- a/src/Adaptive.Cluster/Service/ClusteredServiceAgent.cs +++ b/src/Adaptive.Cluster/Service/ClusteredServiceAgent.cs @@ -27,7 +27,7 @@ internal sealed class ClusteredServiceAgent : IAgent, ICluster, IServiceControlL private readonly RecordingLog recordingLog; private readonly IEpochClock epochClock; private readonly CachedEpochClock cachedEpochClock = new CachedEpochClock(); - private readonly ClusterCncFile cncFile; + private readonly ClusterMarkFile markFile; private long baseLogPosition = 0; private long leadershipTermId; @@ -49,7 +49,7 @@ internal ClusteredServiceAgent(ClusteredServiceContainer.Context ctx) idleStrategy = ctx.IdleStrategy(); serviceId = ctx.ServiceId(); epochClock = ctx.EpochClock(); - cncFile = ctx.CncFile(); + markFile = ctx.MarkFile(); serviceControlPublisher = new ServiceControlPublisher( @@ -66,7 +66,7 @@ public void OnStart() service.OnStart(this); CountersReader counters = aeron.CountersReader(); - int recoveryCounterId = FindRecoveryCounterId(counters); + int recoveryCounterId = AwaitRecoveryCounterId(counters); isRecovering = true; CheckForSnapshot(counters, recoveryCounterId); @@ -75,7 +75,7 @@ public void OnStart() JoinActiveLog(counters); - FindClusterRoleCounter(counters); + roleCounter = AwaitClusterRoleCounter(counters); role = (ClusterRole) roleCounter.Get(); if (ClusterRole.Leader == role) @@ -107,7 +107,7 @@ public int DoWork() long nowMs = epochClock.Time(); if (cachedEpochClock.Time() != nowMs) { - cncFile.UpdateActivityTimestamp(nowMs); + markFile.UpdateActivityTimestamp(nowMs); cachedEpochClock.Update(nowMs); } @@ -160,6 +160,17 @@ public ICollection GetClientSessions() return sessionByIdMap.Values; } + public bool CloseSession(long clusterSessionId) + { + if (sessionByIdMap.ContainsKey(clusterSessionId)) + { + serviceControlPublisher.CloseSession(clusterSessionId); + return true; + } + + return false; + } + public long TimeMs() { return timestampMs; @@ -196,6 +207,11 @@ public void OnJoinLog(long leadershipTermId, int commitPositionId, int logSessio activeLog = new ActiveLog(leadershipTermId, commitPositionId, logSessionId, logStreamId, logChannel); } + public void OnServiceCloseSession(long clusterSessionId) + { + // Not Implemented + } + internal void OnSessionMessage(long clusterSessionId, long correlationId, long timestampMs, IDirectBuffer buffer, int offset, int length, Header header) { @@ -212,12 +228,12 @@ internal void OnTimerEvent(long correlationId, long timestampMs) } internal void OnSessionOpen(long clusterSessionId, long timestampMs, int responseStreamId, - string responseChannel, byte[] principalData) + string responseChannel, byte[] encodedPrincipal) { this.timestampMs = timestampMs; ClientSession session = - new ClientSession(clusterSessionId, responseStreamId, responseChannel, principalData, this); + new ClientSession(clusterSessionId, responseStreamId, responseChannel, encodedPrincipal, this); if (ClusterRole.Leader == role) { @@ -246,14 +262,23 @@ internal void OnServiceAction(long termPosition, long timestampMs, ClusterAction } internal void AddSession(long clusterSessionId, int responseStreamId, string responseChannel, - byte[] principalData) + byte[] encodedPrincipal) { ClientSession session = - new ClientSession(clusterSessionId, responseStreamId, responseChannel, principalData, this); + new ClientSession(clusterSessionId, responseStreamId, responseChannel, encodedPrincipal, this); sessionByIdMap[clusterSessionId] = session; } + private void Role(ClusterRole newRole) + { + if (newRole != role) + { + role = newRole; + service.OnRoleChange(newRole); + } + } + private void CheckForSnapshot(CountersReader counters, int recoveryCounterId) { long termPosition = RecoveryState.GetTermPosition(counters, recoveryCounterId); @@ -306,8 +331,8 @@ private void CheckForReplay(CountersReader counters, int recoveryCounterId) ConsumeImage(image, adapter); - serviceControlPublisher.AckAction(baseLogPosition, leadershipTermId, serviceId, - ClusterAction.REPLAY); + long logPosition = baseLogPosition + image.Position(); + serviceControlPublisher.AckAction(logPosition, leadershipTermId, serviceId, ClusterAction.REPLAY); } } @@ -317,6 +342,7 @@ private void CheckForReplay(CountersReader counters, int recoveryCounterId) private void AwaitActiveLog() { activeLog = null; + idleStrategy.Reset(); while (true) { int fragments = serviceControlAdapter.Poll(); @@ -354,10 +380,10 @@ private void ConsumeImage(Image image, BoundedLogAdapter adapter) } } - private int FindRecoveryCounterId(CountersReader counters) + private int AwaitRecoveryCounterId(CountersReader counters) { + idleStrategy.Reset(); int counterId = RecoveryState.FindCounterId(counters); - while (CountersReader.NULL_COUNTER_ID == counterId) { CheckInterruptedStatus(); @@ -405,10 +431,9 @@ private Image AwaitImage(int sessionId, Subscription subscription) return image; } - private void FindClusterRoleCounter(CountersReader counters) + private ReadableCounter AwaitClusterRoleCounter(CountersReader counters) { idleStrategy.Reset(); - int counterId = ClusterNodeRole.FindCounterId(counters); while (CountersReader.NULL_COUNTER_ID == counterId) { @@ -417,7 +442,7 @@ private void FindClusterRoleCounter(CountersReader counters) counterId = ClusterNodeRole.FindCounterId(counters); } - roleCounter = new ReadableCounter(counters, counterId); + return new ReadableCounter(counters, counterId); } private void LoadSnapshot(long recordingId) @@ -570,7 +595,6 @@ private void ExecuteAction(ClusterAction action, long termPosition) private int AwaitRecordingCounter(Publication publication, CountersReader counters) { idleStrategy.Reset(); - int counterId = RecordingPos.FindCounterIdBySession(counters, publication.SessionId); while (CountersReader.NULL_COUNTER_ID == counterId) { diff --git a/src/Adaptive.Cluster/Service/ClusteredServiceContainer.cs b/src/Adaptive.Cluster/Service/ClusteredServiceContainer.cs index 121c129b..c15c15f0 100644 --- a/src/Adaptive.Cluster/Service/ClusteredServiceContainer.cs +++ b/src/Adaptive.Cluster/Service/ClusteredServiceContainer.cs @@ -6,6 +6,7 @@ using Adaptive.Agrona.Concurrent.Status; using Adaptive.Archiver; using Adaptive.Cluster.Codecs; +using Adaptive.Cluster.Codecs.Mark; namespace Adaptive.Cluster.Service { @@ -109,6 +110,12 @@ public class Configuration /// public const string SERVICE_NAME_DEFAULT = "clustered-service"; + /// + /// Class name for dynamically loading a . This is used if + /// is not set. + /// + public const string SERVICE_CLASS_NAME_PROP_NAME = "aeron.cluster.service.class.name"; + /// /// Channel to be used for log or snapshot replay on startup. /// @@ -149,7 +156,7 @@ public class Configuration /// Default to stream id of 5. /// public const int CONSENSUS_MODULE_STREAM_ID_DEFAULT = 5; - + /// /// Channel to be used for archiving snapshots. /// @@ -188,7 +195,7 @@ public static int ServiceId() { return Config.GetInteger(SERVICE_ID_PROP_NAME, SERVICE_ID_DEFAULT); } - + /// /// The value or system property if set. /// @@ -277,9 +284,11 @@ public static Func IdleStrategySupplier(StatusIndicator controlla } /// - /// The value or system property if set. + /// The value or system property + /// if set. /// - /// or system property if set. + /// or system property + /// if set. public static string ClusteredServiceDirName() { return Config.GetProperty(CLUSTERED_SERVICE_DIR_PROP_NAME, CLUSTERED_SERVICE_DIR_DEFAULT); @@ -305,8 +314,9 @@ public class Context : IDisposable internal AtomicCounter errorCounter; internal CountedErrorHandler countedErrorHandler; internal AeronArchive.Context archiveContext; + private string clusteredServiceDirectoryName = Configuration.ClusteredServiceDirName(); internal DirectoryInfo clusteredServiceDir; - internal string aeronDirectoryName; + internal string aeronDirectoryName = Adaptive.Aeron.Aeron.Context.GetAeronDirectoryName(); internal Aeron.Aeron aeron; internal bool ownsAeronClient; @@ -314,7 +324,16 @@ public class Context : IDisposable internal RecordingLog recordingLog; internal ShutdownSignalBarrier shutdownSignalBarrier; internal Action terminationHook; - internal ClusterCncFile cncFile; + internal ClusterMarkFile markFile; + + /// + /// Perform a shallow copy of the object. + /// + /// a shallow copy of the object. + public Context Clone() + { + return (Context) MemberwiseClone(); + } public void Conclude() { @@ -338,25 +357,14 @@ public void Conclude() throw new InvalidOperationException("Error handler must be supplied"); } - + if (null == aeron) { - var context = new Aeron.Aeron.Context() - .EpochClock(epochClock); - - if (aeronDirectoryName != null) - { - context.AeronDirectoryName(aeronDirectoryName); - } - - if (countedErrorHandler != null) - { - context.ErrorHandler(countedErrorHandler.OnError); - } - aeron = Adaptive.Aeron.Aeron.Connect( - context - ); + new Aeron.Aeron.Context() + .AeronDirectoryName(aeronDirectoryName) + .ErrorHandler(countedErrorHandler.OnError) + .EpochClock(epochClock)); if (null == errorCounter) { @@ -371,7 +379,7 @@ public void Conclude() { throw new InvalidOperationException("Error counter must be supplied"); } - + if (null == countedErrorHandler) { countedErrorHandler = new CountedErrorHandler(errorHandler, errorCounter); @@ -383,11 +391,17 @@ public void Conclude() if (null == archiveContext) { - archiveContext = (new AeronArchive.Context()).AeronClient(aeron).OwnsAeronClient(false) + archiveContext = new AeronArchive.Context() .ControlRequestChannel(AeronArchive.Configuration.LocalControlChannel()) - .ControlRequestStreamId(AeronArchive.Configuration.LocalControlStreamId()).Lock(new NoOpLock()); + .ControlResponseChannel(AeronArchive.Configuration.LocalControlChannel()) + .ControlRequestStreamId(AeronArchive.Configuration.LocalControlStreamId()); } + archiveContext + .AeronClient(aeron) + .OwnsAeronClient(false) + .Lock(new NoOpLock()); + if (deleteDirOnStart) { if (null != clusteredServiceDir) @@ -402,7 +416,7 @@ public void Conclude() if (null == clusteredServiceDir) { - clusteredServiceDir = new DirectoryInfo(Configuration.ClusteredServiceDirName()); + clusteredServiceDir = new DirectoryInfo(clusteredServiceDirectoryName); } if (!clusteredServiceDir.Exists) @@ -425,7 +439,18 @@ public void Conclude() terminationHook = () => shutdownSignalBarrier.Signal(); } - ConcludeCncFile(); + if (null == clusteredService) + { + string className = Config.GetProperty(Configuration.SERVICE_CLASS_NAME_PROP_NAME); + if (null == className) + { + throw new InvalidOperationException("Either a ClusteredService instance or class name for the service must be provided"); + } + + clusteredService = (IClusteredService) Activator.CreateInstance(Type.GetType(className)); + } + + ConcludeMarkFile(); } /// @@ -849,6 +874,28 @@ public bool DeleteDirOnStart() return deleteDirOnStart; } + /// + /// Set the directory name to use for the clustered service container. + /// + /// to use. + /// this for a fluent API. + /// + public Context ClusteredServiceDirectoryName(string clusteredServiceDirectoryName) + { + this.clusteredServiceDirectoryName = clusteredServiceDirectoryName; + return this; + } + + /// + /// The directory name used for the clustered service container. + /// + /// directory for the cluster container. + /// + public string ClusteredServiceDirectoryName() + { + return clusteredServiceDirectoryName; + } + /// /// Set the directory to use for the clustered service container. /// @@ -892,7 +939,7 @@ public RecordingLog RecordingLog() } /// - /// Set the that can be used to shutdown a clustered service. + /// Set the that can be used to shutdown a clustered service. /// /// that can be used to shutdown a clustered service. /// this for a fluent API. @@ -903,9 +950,9 @@ public Context ShutdownSignalBarrier(ShutdownSignalBarrier barrier) } /// - /// Get the that can be used to shutdown a clustered service. + /// Get the that can be used to shutdown a clustered service. /// - /// the that can be used to shutdown a clustered service. + /// the that can be used to shutdown a clustered service. public ShutdownSignalBarrier ShutdownSignalBarrier() { return shutdownSignalBarrier; @@ -936,25 +983,25 @@ public Action TerminationHook() { return terminationHook; } - + /// - /// Set the in use. + /// Set the in use. /// /// to use. /// this for a fluent API. - public Context CncFile(ClusterCncFile cncFile) + public Context MarkFile(ClusterMarkFile cncFile) { - this.cncFile = cncFile; + this.markFile = cncFile; return this; } /// - /// The in use. + /// The in use. /// /// CnC file in use. - public ClusterCncFile CncFile() + public ClusterMarkFile MarkFile() { - return cncFile; + return markFile; } /// @@ -976,23 +1023,35 @@ public void DeleteDirectory() /// public void Dispose() { - cncFile?.Dispose(); - + markFile?.Dispose(); + if (ownsAeronClient) { aeron?.Dispose(); } } - - private void ConcludeCncFile() + + private void ConcludeMarkFile() { - if (null == cncFile) + if (null == markFile) { - int alignedTotalCncFileLength = ClusterCncFile.AlignedTotalFileLength(ClusterCncFile.ALIGNMENT, aeron.Ctx().AeronDirectoryName(), archiveContext.ControlRequestChannel(), ServiceControlChannel(), null, serviceName, null); - - cncFile = new ClusterCncFile(new FileInfo(Path.Combine(clusteredServiceDir.FullName, ClusterCncFile.FILENAME)), ClusterComponentType.CONTAINER, alignedTotalCncFileLength, epochClock, 0); - - CncHeaderEncoder cncEncoder = cncFile.Encoder(); + int alignedTotalCncFileLength = ClusterMarkFile.AlignedTotalFileLength( + ClusterMarkFile.ALIGNMENT, + aeron.Ctx().AeronDirectoryName(), + archiveContext.ControlRequestChannel(), + ServiceControlChannel(), + null, + serviceName, + null); + + markFile = new ClusterMarkFile( + new FileInfo(Path.Combine(clusteredServiceDir.FullName, ClusterMarkFile.FILENAME)), + ClusterComponentType.CONTAINER, + alignedTotalCncFileLength, + epochClock, + 0); + + MarkFileHeaderEncoder cncEncoder = markFile.Encoder(); cncEncoder .ArchiveStreamId(archiveContext.ControlRequestStreamId()) @@ -1007,11 +1066,10 @@ private void ConcludeCncFile() .ServiceName(serviceName) .Authenticator(""); - cncFile.SignalCncReady(); - cncFile.UpdateActivityTimestamp(epochClock.Time()); + markFile.UpdateActivityTimestamp(epochClock.Time()); + markFile.SignalReady(); } } - } } } \ No newline at end of file diff --git a/src/Adaptive.Cluster/Service/ICluster.cs b/src/Adaptive.Cluster/Service/ICluster.cs index 5aafeccd..065beb78 100644 --- a/src/Adaptive.Cluster/Service/ICluster.cs +++ b/src/Adaptive.Cluster/Service/ICluster.cs @@ -32,6 +32,13 @@ public interface ICluster /// /// the s. ICollection GetClientSessions(); + + /// + /// Close a cluster session. + /// + /// to be closed. + /// true if the instruction is successfully or false if the session id does not exist. + bool CloseSession(long clusterSessionId); /// /// Current Epoch time in milliseconds. diff --git a/src/Adaptive.Cluster/Service/IClusteredService.cs b/src/Adaptive.Cluster/Service/IClusteredService.cs index 49d26489..d18e8ecb 100644 --- a/src/Adaptive.Cluster/Service/IClusteredService.cs +++ b/src/Adaptive.Cluster/Service/IClusteredService.cs @@ -90,5 +90,11 @@ public interface IClusteredService /// /// void OnReplayEnd(); + + /// + /// Notify that the cluster node has changed role. + /// + /// that the node has assumed. + void OnRoleChange(ClusterRole newRole); } } \ No newline at end of file diff --git a/src/Adaptive.Cluster/Service/IServiceControlListener.cs b/src/Adaptive.Cluster/Service/IServiceControlListener.cs index 1db49dc9..e51ba361 100644 --- a/src/Adaptive.Cluster/Service/IServiceControlListener.cs +++ b/src/Adaptive.Cluster/Service/IServiceControlListener.cs @@ -41,5 +41,11 @@ public interface IServiceControlListener /// to subscribe to for the log. /// to subscribe to for the log. void OnJoinLog(long leadershipTermId, int commitPositionId, int logSessionId, int logStreamId, string logChannel); + + /// + /// Request that a cluster session be closed. + /// + /// of the session to be closed. + void OnServiceCloseSession(long clusterSessionId); } } \ No newline at end of file diff --git a/src/Adaptive.Cluster/Service/ServiceControlAdapter.cs b/src/Adaptive.Cluster/Service/ServiceControlAdapter.cs new file mode 100644 index 00000000..1698b19b --- /dev/null +++ b/src/Adaptive.Cluster/Service/ServiceControlAdapter.cs @@ -0,0 +1,92 @@ +using System; +using Adaptive.Aeron; +using Adaptive.Aeron.LogBuffer; +using Adaptive.Agrona; +using Adaptive.Cluster.Codecs; + +namespace Adaptive.Cluster.Service +{ + public sealed class ServiceControlAdapter : IFragmentHandler, IDisposable + { + internal readonly Subscription subscription; + internal readonly IServiceControlListener serviceControlListener; + + private readonly MessageHeaderDecoder messageHeaderDecoder = new MessageHeaderDecoder(); + private readonly ScheduleTimerDecoder scheduleTimerDecoder = new ScheduleTimerDecoder(); + private readonly CancelTimerDecoder cancelTimerDecoder = new CancelTimerDecoder(); + private readonly ClusterActionAckDecoder clusterActionAckDecoder = new ClusterActionAckDecoder(); + private readonly JoinLogDecoder joinLogDecoder = new JoinLogDecoder(); + private readonly CloseSessionDecoder closeSessionDecoder = new CloseSessionDecoder(); + + public ServiceControlAdapter(Subscription subscription, IServiceControlListener serviceControlListener) + { + this.subscription = subscription; + this.serviceControlListener = serviceControlListener; + } + + public void Dispose() + { + subscription?.Dispose(); + } + + public int Poll() + { + return subscription.Poll(this, 1); + } + + public void OnFragment(IDirectBuffer buffer, int offset, int length, Header header) + { + messageHeaderDecoder.Wrap(buffer, offset); + + int templateId = messageHeaderDecoder.TemplateId(); + switch (templateId) + { + case ScheduleTimerDecoder.TEMPLATE_ID: + scheduleTimerDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, + messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version()); + + serviceControlListener.OnScheduleTimer(scheduleTimerDecoder.CorrelationId(), + scheduleTimerDecoder.Deadline()); + break; + + case CancelTimerDecoder.TEMPLATE_ID: + cancelTimerDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, + messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version()); + + serviceControlListener.OnCancelTimer(scheduleTimerDecoder.CorrelationId()); + break; + + case ClusterActionAckDecoder.TEMPLATE_ID: + clusterActionAckDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, + messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version()); + + serviceControlListener.OnServiceAck(clusterActionAckDecoder.LogPosition(), + clusterActionAckDecoder.LeadershipTermId(), clusterActionAckDecoder.ServiceId(), + clusterActionAckDecoder.Action()); + break; + + case JoinLogDecoder.TEMPLATE_ID: + joinLogDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, + messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version()); + + serviceControlListener.OnJoinLog(joinLogDecoder.LeadershipTermId(), + joinLogDecoder.CommitPositionId(), joinLogDecoder.LogSessionId(), + joinLogDecoder.LogStreamId(), joinLogDecoder.LogChannel()); + break; + + case CloseSessionDecoder.TEMPLATE_ID: + closeSessionDecoder.Wrap( + buffer, + offset + MessageHeaderDecoder.ENCODED_LENGTH, + messageHeaderDecoder.BlockLength(), + messageHeaderDecoder.Version()); + + serviceControlListener.OnServiceCloseSession(closeSessionDecoder.ClusterSessionId()); + break; + + default: + throw new ArgumentException("Unknown template id: " + templateId); + } + } + } +} \ No newline at end of file diff --git a/src/Adaptive.Cluster/Service/ServiceControlAdapter.java.cs b/src/Adaptive.Cluster/Service/ServiceControlAdapter.java.cs deleted file mode 100644 index 67eea9eb..00000000 --- a/src/Adaptive.Cluster/Service/ServiceControlAdapter.java.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using Adaptive.Aeron; -using Adaptive.Aeron.LogBuffer; -using Adaptive.Agrona; -using Adaptive.Agrona.Concurrent; -using Adaptive.Cluster.Codecs; - -namespace Adaptive.Cluster.Service -{ - public sealed class ServiceControlAdapter : IFragmentHandler, IDisposable - { - internal readonly Subscription subscription; - internal readonly IServiceControlListener serviceControlListener; - - private readonly MessageHeaderDecoder messageHeaderDecoder = new MessageHeaderDecoder(); - private readonly ScheduleTimerRequestDecoder scheduleTimerRequestDecoder = new ScheduleTimerRequestDecoder(); - private readonly CancelTimerRequestDecoder cancelTimerRequestDecoder = new CancelTimerRequestDecoder(); - private readonly ServiceActionAckDecoder serviceActionAckDecoder = new ServiceActionAckDecoder(); - private readonly JoinLogRequestDecoder joinLogRequestDecoder = new JoinLogRequestDecoder(); - - public ServiceControlAdapter(Subscription subscription, IServiceControlListener serviceControlListener) - { - this.subscription = subscription; - this.serviceControlListener = serviceControlListener; - } - - public void Dispose() - { - subscription?.Dispose(); - } - - public int Poll() - { - return subscription.Poll(this, 1); - } - - public void OnFragment(IDirectBuffer buffer, int offset, int length, Header header) - { - messageHeaderDecoder.Wrap(buffer, offset); - - int templateId = messageHeaderDecoder.TemplateId(); - switch (templateId) - { - case ScheduleTimerRequestDecoder.TEMPLATE_ID: - scheduleTimerRequestDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, - messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version()); - - serviceControlListener.OnScheduleTimer(scheduleTimerRequestDecoder.CorrelationId(), - scheduleTimerRequestDecoder.Deadline()); - break; - - case CancelTimerRequestDecoder.TEMPLATE_ID: - cancelTimerRequestDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, - messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version()); - - serviceControlListener.OnCancelTimer(scheduleTimerRequestDecoder.CorrelationId()); - break; - - case ServiceActionAckDecoder.TEMPLATE_ID: - serviceActionAckDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, - messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version()); - - serviceControlListener.OnServiceAck(serviceActionAckDecoder.LogPosition(), - serviceActionAckDecoder.LeadershipTermId(), serviceActionAckDecoder.ServiceId(), - serviceActionAckDecoder.Action()); - break; - - case JoinLogRequestDecoder.TEMPLATE_ID: - joinLogRequestDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, - messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version()); - - serviceControlListener.OnJoinLog(joinLogRequestDecoder.LeadershipTermId(), - joinLogRequestDecoder.CommitPositionId(), joinLogRequestDecoder.LogSessionId(), - joinLogRequestDecoder.LogStreamId(), joinLogRequestDecoder.LogChannel()); - break; - - default: - throw new ArgumentException("Unknown template id: " + templateId); - } - } - } -} \ No newline at end of file diff --git a/src/Adaptive.Cluster/Service/ServiceControlPublisher.cs b/src/Adaptive.Cluster/Service/ServiceControlPublisher.cs index a8e4837c..1e5f940f 100644 --- a/src/Adaptive.Cluster/Service/ServiceControlPublisher.cs +++ b/src/Adaptive.Cluster/Service/ServiceControlPublisher.cs @@ -11,10 +11,11 @@ internal class ServiceControlPublisher : IDisposable private readonly BufferClaim _bufferClaim = new BufferClaim(); private readonly MessageHeaderEncoder _messageHeaderEncoder = new MessageHeaderEncoder(); - private readonly ScheduleTimerRequestEncoder _scheduleTimerRequestEncoder = new ScheduleTimerRequestEncoder(); - private readonly CancelTimerRequestEncoder _cancelTimerRequestEncoder = new CancelTimerRequestEncoder(); - private readonly ServiceActionAckEncoder _serviceActionAckEncoder = new ServiceActionAckEncoder(); - private readonly JoinLogRequestEncoder _joinLogRequestEncoder = new JoinLogRequestEncoder(); + private readonly ScheduleTimerEncoder _scheduleTimerEncoder = new ScheduleTimerEncoder(); + private readonly CancelTimerEncoder _cancelTimerEncoder = new CancelTimerEncoder(); + private readonly ClusterActionAckEncoder _clusterActionAckEncoder = new ClusterActionAckEncoder(); + private readonly JoinLogEncoder _joinLogEncoder = new JoinLogEncoder(); + private readonly CloseSessionEncoder _closeSessionEncoder = new CloseSessionEncoder(); private readonly Publication _publication; internal ServiceControlPublisher(Publication publication) @@ -29,7 +30,7 @@ public void Dispose() public void ScheduleTimer(long correlationId, long deadlineMs) { - int length = MessageHeaderEncoder.ENCODED_LENGTH + ScheduleTimerRequestEncoder.BLOCK_LENGTH; + int length = MessageHeaderEncoder.ENCODED_LENGTH + ScheduleTimerEncoder.BLOCK_LENGTH; int attempts = SEND_ATTEMPTS; do @@ -37,7 +38,7 @@ public void ScheduleTimer(long correlationId, long deadlineMs) long result = _publication.TryClaim(length, _bufferClaim); if (result > 0) { - _scheduleTimerRequestEncoder + _scheduleTimerEncoder .WrapAndApplyHeader(_bufferClaim.Buffer, _bufferClaim.Offset, _messageHeaderEncoder) .CorrelationId(correlationId) .Deadline(deadlineMs); @@ -55,7 +56,7 @@ public void ScheduleTimer(long correlationId, long deadlineMs) public void CancelTimer(long correlationId) { - int length = MessageHeaderEncoder.ENCODED_LENGTH + CancelTimerRequestEncoder.BLOCK_LENGTH; + int length = MessageHeaderEncoder.ENCODED_LENGTH + CancelTimerEncoder.BLOCK_LENGTH; int attempts = SEND_ATTEMPTS; do @@ -63,7 +64,7 @@ public void CancelTimer(long correlationId) long result = _publication.TryClaim(length, _bufferClaim); if (result > 0) { - _cancelTimerRequestEncoder + _cancelTimerEncoder .WrapAndApplyHeader(_bufferClaim.Buffer, _bufferClaim.Offset, _messageHeaderEncoder) .CorrelationId(correlationId); @@ -80,7 +81,7 @@ public void CancelTimer(long correlationId) public void AckAction(long logPosition, long leadershipTermId, int serviceId, ClusterAction action) { - int length = MessageHeaderEncoder.ENCODED_LENGTH + ServiceActionAckEncoder.BLOCK_LENGTH; + int length = MessageHeaderEncoder.ENCODED_LENGTH + ClusterActionAckEncoder.BLOCK_LENGTH; int attempts = SEND_ATTEMPTS; do @@ -88,7 +89,7 @@ public void AckAction(long logPosition, long leadershipTermId, int serviceId, Cl long result = _publication.TryClaim(length, _bufferClaim); if (result > 0) { - _serviceActionAckEncoder + _clusterActionAckEncoder .WrapAndApplyHeader(_bufferClaim.Buffer, _bufferClaim.Offset, _messageHeaderEncoder) .LogPosition(logPosition) .LeadershipTermId(leadershipTermId) @@ -108,7 +109,7 @@ public void AckAction(long logPosition, long leadershipTermId, int serviceId, Cl public void JoinLog(long leadershipTermId, int commitPositionId, int logSessionId, int logStreamId, string channel) { - int length = MessageHeaderEncoder.ENCODED_LENGTH + JoinLogRequestEncoder.BLOCK_LENGTH + JoinLogRequestEncoder.LogChannelHeaderLength() + channel.Length; + int length = MessageHeaderEncoder.ENCODED_LENGTH + JoinLogEncoder.BLOCK_LENGTH + JoinLogEncoder.LogChannelHeaderLength() + channel.Length; int attempts = SEND_ATTEMPTS * 2; do @@ -116,7 +117,7 @@ public void JoinLog(long leadershipTermId, int commitPositionId, int logSessionI long result = _publication.TryClaim(length, _bufferClaim); if (result > 0) { - _joinLogRequestEncoder + _joinLogEncoder .WrapAndApplyHeader(_bufferClaim.Buffer, _bufferClaim.Offset, _messageHeaderEncoder) .LeadershipTermId(leadershipTermId) .CommitPositionId(commitPositionId) @@ -135,6 +136,31 @@ public void JoinLog(long leadershipTermId, int commitPositionId, int logSessionI throw new InvalidOperationException("Failed to send log connect request"); } + public void CloseSession(long clusterSessionId) + { + int length = MessageHeaderEncoder.ENCODED_LENGTH + CloseSessionEncoder.BLOCK_LENGTH; + + int attempts = SEND_ATTEMPTS; + do + { + long result = _publication.TryClaim(length, _bufferClaim); + if (result > 0) + { + _closeSessionEncoder + .WrapAndApplyHeader(_bufferClaim.Buffer, _bufferClaim.Offset, _messageHeaderEncoder) + .ClusterSessionId(clusterSessionId); + + _bufferClaim.Commit(); + + return; + } + + CheckResult(result); + } while (--attempts > 0); + + throw new InvalidOperationException("Failed to schedule timer"); + } + private static void CheckResult(long result) { if (result == Publication.NOT_CONNECTED || result == Publication.CLOSED || result == Publication.MAX_POSITION_EXCEEDED) diff --git a/src/Adaptive.Cluster/Service/ServiceSnapshotLoader.cs b/src/Adaptive.Cluster/Service/ServiceSnapshotLoader.cs index 0c8633c3..e277c036 100644 --- a/src/Adaptive.Cluster/Service/ServiceSnapshotLoader.cs +++ b/src/Adaptive.Cluster/Service/ServiceSnapshotLoader.cs @@ -74,13 +74,21 @@ public ControlledFragmentHandlerAction OnFragment(IDirectBuffer buffer, int offs break; case ClientSessionDecoder.TEMPLATE_ID: - clientSessionDecoder.Wrap(buffer, offset + MessageHeaderDecoder.ENCODED_LENGTH, messageHeaderDecoder.BlockLength(), messageHeaderDecoder.Version()); + clientSessionDecoder.Wrap( + buffer, + offset + MessageHeaderDecoder.ENCODED_LENGTH, + messageHeaderDecoder.BlockLength(), + messageHeaderDecoder.Version()); string responseChannel = clientSessionDecoder.ResponseChannel(); - byte[] principalData = new byte[clientSessionDecoder.PrincipalDataLength()]; - clientSessionDecoder.GetPrincipalData(principalData, 0, principalData.Length); - - agent.AddSession(clientSessionDecoder.ClusterSessionId(), clientSessionDecoder.ResponseStreamId(), responseChannel, principalData); + byte[] encodedPrincipal = new byte[clientSessionDecoder.EncodedPrincipalLength()]; + clientSessionDecoder.GetEncodedPrincipal(encodedPrincipal, 0, encodedPrincipal.Length); + + agent.AddSession( + clientSessionDecoder.ClusterSessionId(), + clientSessionDecoder.ResponseStreamId(), + responseChannel, + encodedPrincipal); break; default: diff --git a/src/Adaptive.Cluster/Service/ServiceSnapshotTaker.cs b/src/Adaptive.Cluster/Service/ServiceSnapshotTaker.cs index 42aa12fa..3329d870 100644 --- a/src/Adaptive.Cluster/Service/ServiceSnapshotTaker.cs +++ b/src/Adaptive.Cluster/Service/ServiceSnapshotTaker.cs @@ -8,15 +8,18 @@ internal class ServiceSnapshotTaker : SnapshotTaker { private readonly ClientSessionEncoder _clientSessionEncoder = new ClientSessionEncoder(); - internal ServiceSnapshotTaker(Publication publication, IIdleStrategy idleStrategy, AgentInvoker aeronClientInvoker) : base(publication, idleStrategy, aeronClientInvoker) + internal ServiceSnapshotTaker(Publication publication, IIdleStrategy idleStrategy, AgentInvoker aeronClientInvoker) + : base(publication, idleStrategy, aeronClientInvoker) { } public void SnapshotSession(ClientSession session) { string responseChannel = session.ResponseChannel(); - byte[] principalData = session.PrincipalData(); - int length = MessageHeaderEncoder.ENCODED_LENGTH + ClientSessionEncoder.BLOCK_LENGTH + ClientSessionEncoder.ResponseChannelHeaderLength() + responseChannel.Length + ClientSessionEncoder.PrincipalDataHeaderLength() + principalData.Length; + byte[] encodedPrincipal = session.EncodedPrincipal(); + int length = MessageHeaderEncoder.ENCODED_LENGTH + ClientSessionEncoder.BLOCK_LENGTH + + ClientSessionEncoder.ResponseChannelHeaderLength() + responseChannel.Length + + ClientSessionEncoder.EncodedPrincipalHeaderLength() + encodedPrincipal.Length; idleStrategy.Reset(); while (true) @@ -28,7 +31,7 @@ public void SnapshotSession(ClientSession session) .ClusterSessionId(session.Id()) .ResponseStreamId(session.ResponseStreamId()) .ResponseChannel(responseChannel) - .PutPrincipalData(principalData, 0, principalData.Length); + .PutEncodedPrincipal(encodedPrincipal, 0, encodedPrincipal.Length); bufferClaim.Commit(); break; diff --git a/src/Adaptive.Cluster/aeron-cluster-codecs.xml b/src/Adaptive.Cluster/aeron-cluster-codecs.xml index 439628fc..f12944ed 100644 --- a/src/Adaptive.Cluster/aeron-cluster-codecs.xml +++ b/src/Adaptive.Cluster/aeron-cluster-codecs.xml @@ -36,8 +36,9 @@ 3 - 0 - 1 + 0 + 1 + 2 0 @@ -54,12 +55,11 @@ 1 2 - - - 0 - 1 - 2 + + 0 + 1 + - + - - - + description="Service acknowledging a cluster action request"> - + description="Consensus Module instructing the service to join a log"> @@ -261,6 +277,12 @@ + + + + - - - - - - - - - - - - - - - - - + + diff --git a/src/Adaptive.Cluster/aeron-cluster-mark-codecs.xml b/src/Adaptive.Cluster/aeron-cluster-mark-codecs.xml new file mode 100644 index 00000000..8d6d10c2 --- /dev/null +++ b/src/Adaptive.Cluster/aeron-cluster-mark-codecs.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + 0 + 1 + 2 + + + + + + + + + + + + + + + + + + + + + + + + +