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));
}
}
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);
}
}
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;
}
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);
}
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();
}
Aggregations