Search in sources :

Example 6 with CorfuMsg

use of org.corfudb.protocols.wireprotocol.CorfuMsg in project CorfuDB by CorfuDB.

the class ManagementServer method handleManagementBootstrap.

/**
     * Bootstraps the management server.
     * The msg contains the layout to be bootstrapped.
     *
     * @param msg
     * @param ctx
     * @param r
     */
@ServerHandler(type = CorfuMsgType.MANAGEMENT_BOOTSTRAP_REQUEST, opTimer = metricsPrefix + "bootstrap-request")
public synchronized void handleManagementBootstrap(CorfuPayloadMsg<Layout> msg, ChannelHandlerContext ctx, IServerRouter r, boolean isMetricsEnabled) {
    if (latestLayout != null) {
        // We are already bootstrapped, bootstrap again is not allowed.
        log.warn("Got a request to bootstrap a server which is already bootstrapped, rejecting!");
        r.sendResponse(ctx, msg, new CorfuMsg(CorfuMsgType.MANAGEMENT_ALREADY_BOOTSTRAP_ERROR));
    } else {
        log.info("Received Bootstrap Layout : {}", msg.getPayload());
        safeUpdateLayout(msg.getPayload());
        r.sendResponse(ctx, msg, new CorfuMsg(CorfuMsgType.ACK));
    }
}
Also used : CorfuMsg(org.corfudb.protocols.wireprotocol.CorfuMsg)

Example 7 with CorfuMsg

use of org.corfudb.protocols.wireprotocol.CorfuMsg in project CorfuDB by CorfuDB.

the class NettyServerRouter method channelRead.

/**
     * Handle an incoming message read on the channel.
     *
     * @param ctx Channel handler context
     * @param msg The incoming message on that channel.
     */
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
    try {
        // The incoming message should have been transformed to a CorfuMsg earlier in the pipeline.
        CorfuMsg m = ((CorfuMsg) msg);
        // We get the handler for this message from the map
        AbstractServer handler = handlerMap.get(m.getMsgType());
        if (handler == null) {
            // The message was unregistered, we are dropping it.
            log.warn("Received unregistered message {}, dropping", m);
        } else {
            if (validateEpoch(m, ctx)) {
                // Route the message to the handler.
                log.trace("Message routed to {}: {}", handler.getClass().getSimpleName(), msg);
                handlerWorkers.submit(() -> handler.handleMessage(m, ctx, this));
            }
        }
    } catch (Exception e) {
        log.error("Exception during read!", e);
    }
}
Also used : CorfuMsg(org.corfudb.protocols.wireprotocol.CorfuMsg)

Example 8 with CorfuMsg

use of org.corfudb.protocols.wireprotocol.CorfuMsg in project CorfuDB by CorfuDB.

the class TestServerRouter method simulateSerialization.

/**
     * This simulates the serialization and deserialization that happens in the Netty pipeline for all messages
     * from server to client.
     *
     * @param message
     * @return
     */
public CorfuMsg simulateSerialization(CorfuMsg message) {
    /* simulate serialization/deserialization */
    ByteBuf oBuf = Unpooled.buffer();
    //Class<? extends CorfuMsg> type = message.getMsgType().messageType;
    //extra assert needed to simulate real Netty behavior
    //assertThat(message.getClass().getSimpleName()).isEqualTo(type.getSimpleName());
    //type.cast(message).serialize(oBuf);
    message.serialize(oBuf);
    oBuf.resetReaderIndex();
    CorfuMsg msgOut = CorfuMsg.deserialize(oBuf);
    oBuf.release();
    return msgOut;
}
Also used : CorfuMsg(org.corfudb.protocols.wireprotocol.CorfuMsg) ByteBuf(io.netty.buffer.ByteBuf)

Example 9 with CorfuMsg

use of org.corfudb.protocols.wireprotocol.CorfuMsg in project CorfuDB by CorfuDB.

the class BaseServerTest method testPing.

@Test
public void testPing() {
    sendMessage(new CorfuMsg(CorfuMsgType.PING));
    Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.PONG);
}
Also used : CorfuMsg(org.corfudb.protocols.wireprotocol.CorfuMsg) Test(org.junit.Test)

Example 10 with CorfuMsg

use of org.corfudb.protocols.wireprotocol.CorfuMsg in project CorfuDB by CorfuDB.

the class BaseServerTest method shutdownServerDoesNotRespond.

@Test
public void shutdownServerDoesNotRespond() {
    getDefaultServer().shutdown();
    Assertions.assertThat(getLastMessage()).isNull();
    sendMessage(new CorfuMsg(CorfuMsgType.PING));
    Assertions.assertThat(getLastMessage()).isNull();
}
Also used : CorfuMsg(org.corfudb.protocols.wireprotocol.CorfuMsg) Test(org.junit.Test)

Aggregations

CorfuMsg (org.corfudb.protocols.wireprotocol.CorfuMsg)15 ByteBuf (io.netty.buffer.ByteBuf)4 Test (org.junit.Test)2 Timer (com.codahale.metrics.Timer)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 java.lang.invoke (java.lang.invoke)1 Modifier (java.lang.reflect.Modifier)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CorfuMsgType (org.corfudb.protocols.wireprotocol.CorfuMsgType)1 WrongEpochException (org.corfudb.runtime.exceptions.WrongEpochException)1 MetricsUtils (org.corfudb.util.MetricsUtils)1