Skip to content

Commit

Permalink
Update style org.corfudb.protocols.wireprotocol (#741)
Browse files Browse the repository at this point in the history
Update to new style guidelines package
org.corfudb.protocols.wireprotocol.
  • Loading branch information
annym authored and no2chem committed Jun 19, 2017
1 parent c2af0de commit 4f8bbb4
Show file tree
Hide file tree
Showing 35 changed files with 451 additions and 238 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package org.corfudb.protocols.wireprotocol;

import io.netty.buffer.ByteBuf;
import lombok.*;

import java.util.Arrays;
import java.util.Map;
import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* Created by mwei on 9/15/15.
*/
Expand All @@ -18,49 +21,52 @@
public class CorfuMsg {

/**
* Marker field value, should equal 0xC0FC0FC0
* Marker field value, should equal 0xC0FC0FC0.
*/
final static int markerField = 0xC0FC0FC0;
static final int markerField = 0xC0FC0FC0;
static Map<Byte, CorfuMsgType> typeMap =
Arrays.<CorfuMsgType>stream(CorfuMsgType.values())
.collect(Collectors.toMap(CorfuMsgType::asByte, Function.identity()));
/**
* The unique id of the client making the request
* The unique id of the client making the request.
*/
@SuppressWarnings({"checkstyle:abbreviationaswordinname", "checkstyle:membername"})
UUID clientID;

/**
* The request id of this request/response
* The request id of this request/response.
*/
@SuppressWarnings({"checkstyle:abbreviationaswordinname", "checkstyle:membername"})
long requestID;

/**
* The epoch of this request/response
* The epoch of this request/response.
*/
long epoch;

/**
* The underlying ByteBuf, if present.
*/
ByteBuf buf;

;
/**
* The type of message
* The type of message.
*/
CorfuMsgType msgType;

/**
* Constructor which generates a message based only the message type.
* Typically used for generating error messages, since sendmessage will populate the rest of the fields.
* Typically used for generating error messages, since sendmessage
* will populate the rest of the fields.
*
* @param type The type of message to send.
*/
public CorfuMsg(CorfuMsgType type) {
this.msgType = type;
}

/* The wire format of the NettyCorfuMessage message is below:
markerField(1) | client ID(8) | request ID(8) | epoch(8) | type(1) |
*/

// The wire format of the NettyCorfuMessage message is below:
// markerField(1) | client ID(8) | request ID(8) | epoch(8) | type(1) |

/**
* Take the given bytebuffer and deserialize it into a message.
Expand All @@ -74,14 +80,14 @@ public static CorfuMsg deserialize(ByteBuf buffer) {
throw new RuntimeException("Attempt to deserialize a message which is not a CorfuMsg, "
+ "Marker = " + marker + " but expected 0xC0FC0FC0");
}
UUID clientID = new UUID(buffer.readLong(), buffer.readLong());
long requestID = buffer.readLong();
UUID clientId = new UUID(buffer.readLong(), buffer.readLong());
long requestId = buffer.readLong();
long epoch = buffer.readLong();
CorfuMsgType message = typeMap.get(buffer.readByte());
CorfuMsg msg = message.getConstructor().construct();

msg.clientID = clientID;
msg.requestID = requestID;
msg.clientID = clientId;
msg.requestID = requestId;
msg.epoch = epoch;
msg.msgType = message;
msg.fromBuffer(buffer);
Expand Down Expand Up @@ -111,15 +117,13 @@ public void serialize(ByteBuf buffer) {
/**
* Parse the rest of the message from the buffer. Classes that extend CorfuMsg
* should parse their fields in this method.
*
* @param buffer
*/
**/
public void fromBuffer(ByteBuf buffer) {
// we don't do anything here since in the base message, no fields remain.
}

/**
* Copy the base fields over to this message
* Copy the base fields over to this message.
*/
public void copyBaseFields(CorfuMsg msg) {
this.clientID = msg.clientID;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package org.corfudb.protocols.wireprotocol;

import com.google.common.reflect.TypeToken;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.corfudb.runtime.view.Layout;

import java.lang.invoke.LambdaMetafactory;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Constructor;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import org.corfudb.runtime.view.Layout;

/**
* Created by mwei on 8/8/16.
*/
Expand Down Expand Up @@ -101,7 +104,7 @@ interface MessageConstructor<T> {
T construct();
}

@Getter(lazy=true)
@Getter(lazy = true)
private final MessageConstructor<? extends CorfuMsg> constructor = resolveConstructor();

public byte asByte() {
Expand All @@ -120,8 +123,9 @@ private MessageConstructor<? extends CorfuMsg> resolveConstructor() {
MethodHandle mh = lookup.unreflectConstructor(t);
MethodType mt = MethodType.methodType(Object.class);
try {
return (MessageConstructor<? extends CorfuMsg>) LambdaMetafactory.metafactory(lookup,
"construct", MethodType.methodType(MessageConstructor.class),
return (MessageConstructor<? extends CorfuMsg>) LambdaMetafactory.metafactory(
lookup, "construct",
MethodType.methodType(MessageConstructor.class),
mt, mh, mh.type())
.getTarget().invokeExact();
} catch (Throwable th) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.corfudb.protocols.wireprotocol;

import java.lang.annotation.*;
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;

/**
* Created by mwei on 8/8/16.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package org.corfudb.protocols.wireprotocol;

import io.netty.buffer.ByteBuf;

import java.lang.reflect.ParameterizedType;

import lombok.Getter;
import lombok.NoArgsConstructor;

import java.lang.reflect.ParameterizedType;

/**
* A message type which represents an encapsulated Corfu
* payload.
*
* T should be either of a primitive boxed type (Long, Integer, etc)
* or of ICorfuPayload.
* <p>T should be either of a primitive boxed type (Long, Integer, etc)
* or of ICorfuPayload.</p>
*
* NEVER, EVER use this class as a raw type. This class DEPENDS on
* the generic captured at runtime by CorfuMsg (via TypeToken).
* <p>NEVER, EVER use this class as a raw type. This class DEPENDS on
* the generic captured at runtime by CorfuMsg (via TypeToken).</p>
*
* Created by mwei on 8/1/16.
* <p>Created by mwei on 8/1/16.</p>
*/
@NoArgsConstructor
public class CorfuPayloadMsg<T> extends CorfuMsg {
Expand Down Expand Up @@ -48,7 +50,7 @@ public void serialize(ByteBuf buffer) {
* Parse the rest of the message from the buffer. Classes that extend CorfuMsg
* should parse their fields in this method.
*
* @param buffer
* @param buffer contains the message from the buffer
*/
@Override
@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package org.corfudb.protocols.wireprotocol;

import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
* Created by mwei on 8/16/16.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.corfudb.protocols.wireprotocol;

import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Set;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
* Trigger sent to the management server with the failures detected.
* Created by zlokhandwala on 11/8/16.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.corfudb.protocols.wireprotocol;

import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.RequiredArgsConstructor;

import java.util.UUID;

import lombok.Data;
import lombok.RequiredArgsConstructor;

/**
* Created by Maithem on 10/13/2016
* Request sent to fill a hole.
* Created by Maithem on 10/13/2016.
*/
@CorfuPayload
@Data
Expand All @@ -17,18 +19,26 @@ public class FillHoleRequest implements ICorfuPayload<FillHoleRequest> {
final UUID stream;
final Long prefix;

/**
* Constructor to generate a Fill Hole Request Payload.
*
* @param buf The buffer to deserialize.
*/
public FillHoleRequest(ByteBuf buf) {
if (ICorfuPayload.fromBuffer(buf, Boolean.class))
if (ICorfuPayload.fromBuffer(buf, Boolean.class)) {
stream = ICorfuPayload.fromBuffer(buf, UUID.class);
else stream = null;
} else {
stream = null;
}
prefix = ICorfuPayload.fromBuffer(buf, Long.class);
}

@Override
public void doSerialize(ByteBuf buf) {
ICorfuPayload.serialize(buf, stream != null);
if (stream != null)
if (stream != null) {
ICorfuPayload.serialize(buf, stream);
}
ICorfuPayload.serialize(buf, prefix);
}
}

0 comments on commit 4f8bbb4

Please sign in to comment.