/// <summary> /// Allocate an indicator for tracking the status of a channel endpoint. /// </summary> /// <param name="tempBuffer"> to be used for labels and metadata. </param> /// <param name="name"> of the counter for the label. </param> /// <param name="typeId"> of the counter for classification. </param> /// <param name="countersManager"> from which to allocated the underlying storage. </param> /// <param name="channel"> for the stream of messages. </param> /// <returns> a new <seealso cref="AtomicCounter"/> for tracking the status. </returns> public static AtomicCounter Allocate(IMutableDirectBuffer tempBuffer, string name, int typeId, CountersManager countersManager, string channel) { int keyLength = tempBuffer.PutStringWithoutLengthAscii(CHANNEL_OFFSET + BitUtil.SIZE_OF_INT, channel, 0, MAX_CHANNEL_LENGTH); tempBuffer.PutInt(CHANNEL_OFFSET, keyLength); int labelLength = 0; labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, name); labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, ": "); labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, channel, 0, CountersReader.MAX_LABEL_LENGTH - labelLength); if (labelLength < CountersReader.MAX_LABEL_LENGTH) { tempBuffer.PutByte(keyLength + labelLength, (byte)' '); labelLength += 1; } return(countersManager.NewCounter(typeId, tempBuffer, 0, keyLength, tempBuffer, keyLength, labelLength)); }
public void ShouldCopeWithExceptionKeyFunc() { var ex = new Exception(); try { _manager.Allocate("label", CountersManager.DEFAULT_TYPE_ID, _ => { throw ex; }); } catch (Exception caught) { Assert.AreEqual(ex, caught); var counter = _manager.NewCounter("new label"); Assert.AreEqual(0, counter.Id); return; } Assert.Fail("Should have thrown exception."); }