Search in sources :

Example 1 with GetHeadResponse

use of org.apache.jackrabbit.oak.segment.standby.codec.GetHeadResponse in project jackrabbit-oak by apache.

the class GetHeadRequestHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, GetHeadRequest msg) throws Exception {
    log.debug("Reading head for client {}", msg.getClientId());
    String id = reader.readHeadRecordId();
    if (id == null) {
        log.debug("Head not found, discarding request from client {}", msg.getClientId());
        return;
    }
    ctx.writeAndFlush(new GetHeadResponse(msg.getClientId(), id));
}
Also used : GetHeadResponse(org.apache.jackrabbit.oak.segment.standby.codec.GetHeadResponse)

Example 2 with GetHeadResponse

use of org.apache.jackrabbit.oak.segment.standby.codec.GetHeadResponse in project jackrabbit-oak by apache.

the class StandbyClient method getHead.

@Nullable
String getHead() throws InterruptedException {
    channel.writeAndFlush(new GetHeadRequest(clientId));
    GetHeadResponse response = headQueue.poll(readTimeoutMs, TimeUnit.MILLISECONDS);
    if (response == null) {
        return null;
    }
    return response.getHeadRecordId();
}
Also used : GetHeadRequest(org.apache.jackrabbit.oak.segment.standby.codec.GetHeadRequest) GetHeadResponse(org.apache.jackrabbit.oak.segment.standby.codec.GetHeadResponse) Nullable(javax.annotation.Nullable)

Example 3 with GetHeadResponse

use of org.apache.jackrabbit.oak.segment.standby.codec.GetHeadResponse in project jackrabbit-oak by apache.

the class GetHeadRequestHandlerTest method successfulReadsShouldGenerateResponses.

@Test
public void successfulReadsShouldGenerateResponses() throws Exception {
    StandbyHeadReader reader = mock(StandbyHeadReader.class);
    when(reader.readHeadRecordId()).thenReturn("recordId");
    EmbeddedChannel channel = new EmbeddedChannel(new GetHeadRequestHandler(reader));
    channel.writeInbound(new GetHeadRequest("clientId"));
    GetHeadResponse response = (GetHeadResponse) channel.readOutbound();
    assertEquals("recordId", response.getHeadRecordId());
    assertEquals("clientId", response.getClientId());
}
Also used : GetHeadRequest(org.apache.jackrabbit.oak.segment.standby.codec.GetHeadRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) GetHeadResponse(org.apache.jackrabbit.oak.segment.standby.codec.GetHeadResponse) Test(org.junit.Test)

Aggregations

GetHeadResponse (org.apache.jackrabbit.oak.segment.standby.codec.GetHeadResponse)3 GetHeadRequest (org.apache.jackrabbit.oak.segment.standby.codec.GetHeadRequest)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 Nullable (javax.annotation.Nullable)1 Test (org.junit.Test)1