Ejemplo n.º 1
0
  @Before
  public void setUp() {
    when(publicationLimit.getVolatile()).thenReturn(2L * SEND_BUFFER_CAPACITY);
    when(logBuffers.termBuffers()).thenReturn(termBuffers);
    when(logBuffers.termLength()).thenReturn(TERM_MIN_LENGTH);
    when(logBuffers.metaDataBuffer()).thenReturn(logMetaDataBuffer);
    when(conductor.mainLock()).thenReturn(conductorLock);

    initialTermId(logMetaDataBuffer, TERM_ID_1);
    timeOfLastStatusMessage(logMetaDataBuffer, 0);

    for (int i = 0; i < PARTITION_COUNT; i++) {
      termBuffers[i] = new UnsafeBuffer(allocateDirect(TERM_MIN_LENGTH));
    }

    publication =
        new Publication(
            conductor,
            CHANNEL,
            STREAM_ID_1,
            SESSION_ID_1,
            publicationLimit,
            logBuffers,
            CORRELATION_ID);

    publication.incRef();

    initialiseTailWithTermId(logMetaDataBuffer, PARTITION_INDEX, TERM_ID_1);
  }
Ejemplo n.º 2
0
  Publication(
      final ClientConductor clientConductor,
      final String channel,
      final int streamId,
      final int sessionId,
      final ReadablePosition publicationLimit,
      final LogBuffers logBuffers,
      final long registrationId) {
    final UnsafeBuffer[] buffers = logBuffers.atomicBuffers();
    final UnsafeBuffer logMetaDataBuffer = buffers[LOG_META_DATA_SECTION_INDEX];
    final UnsafeBuffer[] defaultFrameHeaders = defaultFrameHeaders(logMetaDataBuffer);
    final int mtuLength = mtuLength(logMetaDataBuffer);

    for (int i = 0; i < PARTITION_COUNT; i++) {
      termAppenders[i] =
          new TermAppender(
              buffers[i], buffers[i + PARTITION_COUNT], defaultFrameHeaders[i], mtuLength);
    }

    this.clientConductor = clientConductor;
    this.channel = channel;
    this.streamId = streamId;
    this.sessionId = sessionId;
    this.logBuffers = logBuffers;
    this.logMetaDataBuffer = logMetaDataBuffer;
    this.registrationId = registrationId;
    this.publicationLimit = publicationLimit;
    this.positionBitsToShift = Integer.numberOfTrailingZeros(logBuffers.termLength());
  }
Ejemplo n.º 3
0
  @Before
  public void setUp() {
    when(publicationLimit.getVolatile()).thenReturn(2L * SEND_BUFFER_CAPACITY);
    when(logBuffers.atomicBuffers()).thenReturn(buffers);
    when(logBuffers.termLength()).thenReturn(TERM_MIN_LENGTH);

    initialTermId(logMetaDataBuffer, TERM_ID_1);
    activeTermId(logMetaDataBuffer, TERM_ID_1);

    for (int i = 0; i < PARTITION_COUNT; i++) {
      termBuffers[i] = new UnsafeBuffer(ByteBuffer.allocateDirect(TERM_MIN_LENGTH));
      termMetaDataBuffers[i] = new UnsafeBuffer(ByteBuffer.allocateDirect(TERM_META_DATA_LENGTH));

      buffers[i] = termBuffers[i];
      buffers[i + PARTITION_COUNT] = termMetaDataBuffers[i];
    }
    buffers[LOG_META_DATA_SECTION_INDEX] = logMetaDataBuffer;

    publication =
        new Publication(
            conductor,
            CHANNEL,
            STREAM_ID_1,
            SESSION_ID_1,
            publicationLimit,
            logBuffers,
            CORRELATION_ID);

    publication.incRef();
  }
Ejemplo n.º 4
0
 /** Release resources and forcibly close the Publication regardless of reference count. */
 void release() {
   if (!isClosed) {
     isClosed = true;
     clientConductor.releasePublication(this);
     logBuffers.close();
   }
 }
Ejemplo n.º 5
0
 /**
  * Get the length in bytes for each term partition in the log buffer.
  *
  * @return the length in bytes for each term partition in the log buffer.
  */
 public int termBufferLength() {
   return logBuffers.termLength();
 }