Exemplo n.º 1
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());
  }
Exemplo n.º 2
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();
  }
Exemplo n.º 3
0
 /** Release resources and forcibly close the Publication regardless of reference count. */
 void release() {
   if (!isClosed) {
     isClosed = true;
     clientConductor.releasePublication(this);
     logBuffers.close();
   }
 }
Exemplo n.º 4
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();
 }