Skip to content

Commit

Permalink
Update to new style guidelines. (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
zalokhan authored and no2chem committed Jun 19, 2017
1 parent f6e4c69 commit e8ce7fa
Show file tree
Hide file tree
Showing 10 changed files with 619 additions and 388 deletions.
115 changes: 68 additions & 47 deletions runtime/src/main/java/org/corfudb/runtime/clients/BaseClient.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package org.corfudb.runtime.clients;

import io.netty.channel.ChannelHandlerContext;

import java.lang.invoke.MethodHandles;
import java.util.concurrent.CompletableFuture;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.corfudb.protocols.wireprotocol.*;
import org.corfudb.runtime.exceptions.WrongEpochException;

import java.lang.invoke.MethodHandles;
import java.util.concurrent.CompletableFuture;
import org.corfudb.protocols.wireprotocol.CorfuMsg;
import org.corfudb.protocols.wireprotocol.CorfuMsgType;
import org.corfudb.protocols.wireprotocol.CorfuPayloadMsg;
import org.corfudb.protocols.wireprotocol.JSONPayloadMsg;
import org.corfudb.protocols.wireprotocol.VersionInfo;
import org.corfudb.runtime.exceptions.WrongEpochException;

/**
* This is a base client which processes basic messages.
* It mainly handles PINGs, as well as the ACK/NACKs defined by
* the Corfu protocol.
* <p>
* Created by mwei on 12/9/15.
*
* <p>Created by mwei on 12/9/15.
*/
@Slf4j
public class BaseClient implements IClient {
Expand Down Expand Up @@ -43,6 +49,12 @@ public boolean pingSync() {
}
}

/**
* Sets the epoch on client router and on the target layout server.
*
* @param newEpoch New Epoch to be set
* @return Completable future which returns true on successful epoch set.
*/
public CompletableFuture<Boolean> setRemoteEpoch(long newEpoch) {
// Set our own epoch to this epoch.
router.setEpoch(newEpoch);
Expand All @@ -60,7 +72,7 @@ public CompletableFuture<VersionInfo> getVersionInfo() {
* Ping the endpoint, asynchronously.
*
* @return A completable future which will be completed with True if
* the endpoint is reachable, otherwise False or exceptional completion.
* the endpoint is reachable, otherwise False or exceptional completion.
*/
public CompletableFuture<Boolean> ping() {
return router.sendMessageAndGetCompletable(
Expand All @@ -71,87 +83,96 @@ public CompletableFuture<Boolean> ping() {
* Reset the endpoint, asynchronously.
*
* @return A completable future which will be completed with True if
* the endpoint acks, otherwise False or exceptional completion.
* the endpoint acks, otherwise False or exceptional completion.
*/
public CompletableFuture<Boolean> reset() {
return router.sendMessageAndGetCompletable(
new CorfuMsg(CorfuMsgType.RESET));
}

/** The handler and handlers which implement this client. */
/**
* The handler and handlers which implement this client.
*/
@Getter
public ClientMsgHandler msgHandler = new ClientMsgHandler(this)
.generateHandlers(MethodHandles.lookup(), this);
.generateHandlers(MethodHandles.lookup(), this);

/** Handle a ping request from the server.
/**
* Handle a ping request from the server.
*
* @param msg The ping request message
* @param ctx The context the message was sent under
* @param r A reference to the router
* @return The return value, null since this is a message from the server.
* @param msg The ping request message
* @param ctx The context the message was sent under
* @param r A reference to the router
* @return The return value, null since this is a message from the server.
*/
@ClientHandler(type=CorfuMsgType.PING)
@ClientHandler(type = CorfuMsgType.PING)
private static Object handlePing(CorfuMsg msg, ChannelHandlerContext ctx, IClientRouter r) {
r.sendResponseToServer(ctx, msg, new CorfuMsg(CorfuMsgType.PONG));
return null;
}

/** Handle a pong response from the server.
/**
* Handle a pong response from the server.
*
* @param msg The ping request message
* @param ctx The context the message was sent under
* @param r A reference to the router
* @return Always True, since the ping message was successful.
* @param msg The ping request message
* @param ctx The context the message was sent under
* @param r A reference to the router
* @return Always True, since the ping message was successful.
*/
@ClientHandler(type=CorfuMsgType.PONG)
@ClientHandler(type = CorfuMsgType.PONG)
private static Object handlePong(CorfuMsg msg, ChannelHandlerContext ctx, IClientRouter r) {
return true;
}

/** Handle an ACK response from the server.
/**
* Handle an ACK response from the server.
*
* @param msg The ping request message
* @param ctx The context the message was sent under
* @param r A reference to the router
* @return Always True, since the ACK message was successful.
* @param msg The ping request message
* @param ctx The context the message was sent under
* @param r A reference to the router
* @return Always True, since the ACK message was successful.
*/
@ClientHandler(type=CorfuMsgType.ACK)
@ClientHandler(type = CorfuMsgType.ACK)
private static Object handleAck(CorfuMsg msg, ChannelHandlerContext ctx, IClientRouter r) {
return true;
}

/** Handle a NACK response from the server.
/**
* Handle a NACK response from the server.
*
* @param msg The ping request message
* @param ctx The context the message was sent under
* @param r A reference to the router
* @return Always True, since the ACK message was successful.
* @param msg The ping request message
* @param ctx The context the message was sent under
* @param r A reference to the router
* @return Always True, since the ACK message was successful.
*/
@ClientHandler(type=CorfuMsgType.NACK)
@ClientHandler(type = CorfuMsgType.NACK)
private static Object handleNack(CorfuMsg msg, ChannelHandlerContext ctx, IClientRouter r) {
return false;
}

/** Handle a WRONG_EPOCH response from the server.
/**
* Handle a WRONG_EPOCH response from the server.
*
* @param msg The wrong epoch message
* @param ctx The context the message was sent under
* @param r A reference to the router
* @return none, throw a wrong epoch exception instead.
* @param msg The wrong epoch message
* @param ctx The context the message was sent under
* @param r A reference to the router
* @return none, throw a wrong epoch exception instead.
*/
@ClientHandler(type=CorfuMsgType.WRONG_EPOCH)
private static Object handleWrongEpoch(CorfuPayloadMsg<Long> msg, ChannelHandlerContext ctx, IClientRouter r) {
@ClientHandler(type = CorfuMsgType.WRONG_EPOCH)
private static Object handleWrongEpoch(CorfuPayloadMsg<Long> msg, ChannelHandlerContext ctx,
IClientRouter r) {
throw new WrongEpochException(msg.getPayload());
}

/** Handle a Version response from the server.
/**
* Handle a Version response from the server.
*
* @param msg The version message
* @param ctx The context the message was sent under
* @param r A reference to the router
* @return The versioninfo object.
* @param msg The version message
* @param ctx The context the message was sent under
* @param r A reference to the router
* @return The versioninfo object.
*/
@ClientHandler(type=CorfuMsgType.VERSION_RESPONSE)
@ClientHandler(type = CorfuMsgType.VERSION_RESPONSE)
private static Object handleVersionResponse(JSONPayloadMsg<VersionInfo> msg,
ChannelHandlerContext ctx, IClientRouter r) {
return msg.getPayload();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
package org.corfudb.runtime.clients;

import org.corfudb.protocols.wireprotocol.CorfuMsgType;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import java.lang.annotation.*;
import org.corfudb.protocols.wireprotocol.CorfuMsgType;

/**
* Created by mwei on 8/9/16.
* Registers the method with the annotation as a client response
* handler and invokes on reception of message response.
*
* <p>Created by mwei on 8/9/16.
*/

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface ClientHandler {

/**
* Type of CorfuMsg
*
* @return Returns the type of the corfu message.
*/
CorfuMsgType type();
}

0 comments on commit e8ce7fa

Please sign in to comment.