Skip to content

Commit

Permalink
Replace ClientRequest/ClientResponse with SessionRequest/SessionRespo…
Browse files Browse the repository at this point in the history
…nse.
  • Loading branch information
kuujo committed Aug 1, 2015
1 parent 006df05 commit 3314a0d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 103 deletions.

This file was deleted.

Expand Up @@ -31,7 +31,7 @@
* @author <a href="http://github.com/kuujo">Jordan Halterman</a> * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
*/ */
@SerializeWith(id=259) @SerializeWith(id=259)
public class CommandResponse extends ClientResponse<CommandResponse> { public class CommandResponse extends SessionResponse<CommandResponse> {
private static final BuilderPool<Builder, CommandResponse> POOL = new BuilderPool<>(Builder::new); private static final BuilderPool<Builder, CommandResponse> POOL = new BuilderPool<>(Builder::new);


/** /**
Expand Down Expand Up @@ -118,7 +118,7 @@ public String toString() {
/** /**
* Command response builder. * Command response builder.
*/ */
public static class Builder extends ClientResponse.Builder<Builder, CommandResponse> { public static class Builder extends SessionResponse.Builder<Builder, CommandResponse> {


protected Builder(BuilderPool<Builder, CommandResponse> pool) { protected Builder(BuilderPool<Builder, CommandResponse> pool) {
super(pool, CommandResponse::new); super(pool, CommandResponse::new);
Expand Down
Expand Up @@ -32,7 +32,7 @@
* @author <a href="http://github.com/kuujo">Jordan Halterman</a> * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
*/ */
@SerializeWith(id=263) @SerializeWith(id=263)
public class KeepAliveResponse extends ClientResponse<KeepAliveResponse> { public class KeepAliveResponse extends SessionResponse<KeepAliveResponse> {
private static final BuilderPool<Builder, KeepAliveResponse> POOL = new BuilderPool<>(Builder::new); private static final BuilderPool<Builder, KeepAliveResponse> POOL = new BuilderPool<>(Builder::new);


/** /**
Expand Down Expand Up @@ -142,7 +142,7 @@ public String toString() {
/** /**
* Status response builder. * Status response builder.
*/ */
public static class Builder extends ClientResponse.Builder<Builder, KeepAliveResponse> { public static class Builder extends SessionResponse.Builder<Builder, KeepAliveResponse> {


protected Builder(BuilderPool<Builder, KeepAliveResponse> pool) { protected Builder(BuilderPool<Builder, KeepAliveResponse> pool) {
super(pool, KeepAliveResponse::new); super(pool, KeepAliveResponse::new);
Expand Down
Expand Up @@ -15,12 +15,12 @@
*/ */
package net.kuujo.copycat.raft.protocol; package net.kuujo.copycat.raft.protocol;


import net.kuujo.copycat.util.BuilderPool;
import net.kuujo.copycat.raft.RaftError;
import net.kuujo.copycat.io.BufferInput; import net.kuujo.copycat.io.BufferInput;
import net.kuujo.copycat.io.BufferOutput; import net.kuujo.copycat.io.BufferOutput;
import net.kuujo.copycat.io.serializer.SerializeWith; import net.kuujo.copycat.io.serializer.SerializeWith;
import net.kuujo.copycat.io.serializer.Serializer; import net.kuujo.copycat.io.serializer.Serializer;
import net.kuujo.copycat.raft.RaftError;
import net.kuujo.copycat.util.BuilderPool;
import net.kuujo.copycat.util.ReferenceManager; import net.kuujo.copycat.util.ReferenceManager;


import java.util.Objects; import java.util.Objects;
Expand All @@ -31,7 +31,7 @@
* @author <a href="http://github.com/kuujo">Jordan Halterman</a> * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
*/ */
@SerializeWith(id=269) @SerializeWith(id=269)
public class PublishResponse extends AbstractResponse<PublishResponse> { public class PublishResponse extends SessionResponse<PublishResponse> {
private static final BuilderPool<Builder, PublishResponse> POOL = new BuilderPool<>(Builder::new); private static final BuilderPool<Builder, PublishResponse> POOL = new BuilderPool<>(Builder::new);


/** /**
Expand Down Expand Up @@ -102,7 +102,7 @@ public String toString() {
/** /**
* Publish response builder. * Publish response builder.
*/ */
public static class Builder extends AbstractResponse.Builder<Builder, PublishResponse> { public static class Builder extends SessionResponse.Builder<Builder, PublishResponse> {


protected Builder(BuilderPool<Builder, PublishResponse> pool) { protected Builder(BuilderPool<Builder, PublishResponse> pool) {
super(pool, PublishResponse::new); super(pool, PublishResponse::new);
Expand Down
Expand Up @@ -31,7 +31,7 @@
* @author <a href="http://github.com/kuujo">Jordan Halterman</a> * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
*/ */
@SerializeWith(id=271) @SerializeWith(id=271)
public class QueryResponse extends ClientResponse<QueryResponse> { public class QueryResponse extends SessionResponse<QueryResponse> {
private static final BuilderPool<Builder, QueryResponse> POOL = new BuilderPool<>(Builder::new); private static final BuilderPool<Builder, QueryResponse> POOL = new BuilderPool<>(Builder::new);


/** /**
Expand Down Expand Up @@ -118,7 +118,7 @@ public String toString() {
/** /**
* Query response builder. * Query response builder.
*/ */
public static class Builder extends ClientResponse.Builder<Builder, QueryResponse> { public static class Builder extends SessionResponse.Builder<Builder, QueryResponse> {


protected Builder(BuilderPool<Builder, QueryResponse> pool) { protected Builder(BuilderPool<Builder, QueryResponse> pool) {
super(pool, QueryResponse::new); super(pool, QueryResponse::new);
Expand Down
Expand Up @@ -15,10 +15,10 @@
*/ */
package net.kuujo.copycat.raft.protocol; package net.kuujo.copycat.raft.protocol;


import net.kuujo.copycat.util.BuilderPool;
import net.kuujo.copycat.io.BufferInput; import net.kuujo.copycat.io.BufferInput;
import net.kuujo.copycat.io.BufferOutput; import net.kuujo.copycat.io.BufferOutput;
import net.kuujo.copycat.io.serializer.Serializer; import net.kuujo.copycat.io.serializer.Serializer;
import net.kuujo.copycat.util.BuilderPool;
import net.kuujo.copycat.util.ReferenceFactory; import net.kuujo.copycat.util.ReferenceFactory;
import net.kuujo.copycat.util.ReferenceManager; import net.kuujo.copycat.util.ReferenceManager;


Expand All @@ -27,8 +27,9 @@
* *
* @author <a href="http://github.com/kuujo">Jordan Halterman</a> * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
*/ */
public abstract class SessionRequest<T extends SessionRequest<T>> extends ClientRequest<T> { public abstract class SessionRequest<T extends SessionRequest<T>> extends AbstractRequest<T> {
protected long session; protected long session;
protected long version;


public SessionRequest(ReferenceManager<T> referenceManager) { public SessionRequest(ReferenceManager<T> referenceManager) {
super(referenceManager); super(referenceManager);
Expand All @@ -43,22 +44,31 @@ public long session() {
return session; return session;
} }


/**
* Returns the response version.
*
* @return The response version.
*/
public long version() {
return version;
}

@Override @Override
public void readObject(BufferInput buffer, Serializer serializer) { public void readObject(BufferInput buffer, Serializer serializer) {
super.readObject(buffer, serializer);
session = buffer.readLong(); session = buffer.readLong();
version = buffer.readLong();
} }


@Override @Override
public void writeObject(BufferOutput buffer, Serializer serializer) { public void writeObject(BufferOutput buffer, Serializer serializer) {
super.writeObject(buffer, serializer);
buffer.writeLong(session); buffer.writeLong(session);
buffer.writeLong(version);
} }


/** /**
* Client request builder. * Client request builder.
*/ */
public static abstract class Builder<T extends Builder<T, U>, U extends SessionRequest<U>> extends ClientRequest.Builder<T, U> { public static abstract class Builder<T extends Builder<T, U>, U extends SessionRequest<U>> extends AbstractRequest.Builder<T, U> {


protected Builder(BuilderPool<T, U> pool, ReferenceFactory<U> factory) { protected Builder(BuilderPool<T, U> pool, ReferenceFactory<U> factory) {
super(pool, factory); super(pool, factory);
Expand All @@ -68,6 +78,7 @@ protected Builder(BuilderPool<T, U> pool, ReferenceFactory<U> factory) {
protected void reset() { protected void reset() {
super.reset(); super.reset();
request.session = 0; request.session = 0;
request.version = 0;
} }


/** /**
Expand All @@ -83,6 +94,20 @@ public T withSession(long session) {
request.session = session; request.session = session;
return (T) this; return (T) this;
} }

/**
* Sets the request version.
*
* @param version The request version.
* @return The request builder.
*/
@SuppressWarnings("unchecked")
public T withVersion(long version) {
if (version < 0)
throw new IllegalArgumentException("version must be positive");
request.version = version;
return (T) this;
}
} }


} }
Expand Up @@ -20,20 +20,20 @@
import net.kuujo.copycat.util.ReferenceManager; import net.kuujo.copycat.util.ReferenceManager;


/** /**
* Client response. * Session response.
* *
* @author <a href="http://github.com/kuujo">Jordan Halterman</a> * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
*/ */
public abstract class ClientResponse<T extends ClientResponse<T>> extends AbstractResponse<T> { public abstract class SessionResponse<T extends SessionResponse<T>> extends AbstractResponse<T> {


public ClientResponse(ReferenceManager<T> referenceManager) { public SessionResponse(ReferenceManager<T> referenceManager) {
super(referenceManager); super(referenceManager);
} }


/** /**
* Client response builder. * Session response builder.
*/ */
public static abstract class Builder<T extends Builder<T, U>, U extends ClientResponse<U>> extends AbstractResponse.Builder<T, U> { public static abstract class Builder<T extends Builder<T, U>, U extends SessionResponse<U>> extends AbstractResponse.Builder<T, U> {
protected Builder(BuilderPool<T, U> pool, ReferenceFactory<U> factory) { protected Builder(BuilderPool<T, U> pool, ReferenceFactory<U> factory) {
super(pool, factory); super(pool, factory);
} }
Expand Down

0 comments on commit 3314a0d

Please sign in to comment.