Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add protocol join/leave request/respose.
- Loading branch information
Showing
19 changed files
with
574 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
core/src/main/java/net/kuujo/copycat/raft/protocol/JoinRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright 2015 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package net.kuujo.copycat.raft.protocol; | ||
|
||
import net.kuujo.copycat.util.internal.Assert; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Protocol join request. | ||
* | ||
* @author <a href="http://github.com/kuujo">Jordan Halterman</a> | ||
*/ | ||
public class JoinRequest extends AbstractRequest { | ||
|
||
/** | ||
* Returns a new join request builder. | ||
* | ||
* @return A new join request builder. | ||
*/ | ||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
/** | ||
* Returns a join request builder for an existing request. | ||
* | ||
* @param request The request to build. | ||
* @return The join request builder. | ||
*/ | ||
public static Builder builder(JoinRequest request) { | ||
return new Builder(request); | ||
} | ||
|
||
private String member; | ||
|
||
/** | ||
* Returns the member's address. | ||
* | ||
* @return The member's address. | ||
*/ | ||
public String member() { | ||
return member; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(uri, member); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (object instanceof JoinRequest) { | ||
JoinRequest request = (JoinRequest) object; | ||
return request.uri.equals(uri) | ||
&& request.member.equals(member); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("%s[member=%s]", getClass().getSimpleName(), member); | ||
} | ||
|
||
/** | ||
* Join request builder. | ||
*/ | ||
public static class Builder extends AbstractRequest.Builder<Builder, JoinRequest> { | ||
protected Builder() { | ||
this(new JoinRequest()); | ||
} | ||
|
||
protected Builder(JoinRequest request) { | ||
super(request); | ||
} | ||
|
||
/** | ||
* Sets the request member. | ||
* | ||
* @param member The request member. | ||
* @return The join request builder. | ||
*/ | ||
public Builder withMember(String member) { | ||
request.member = Assert.isNotNull(member, "member"); | ||
return this; | ||
} | ||
|
||
@Override | ||
public JoinRequest build() { | ||
super.build(); | ||
Assert.isNotNull(request.member, "member"); | ||
return request; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(request); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
return object instanceof Builder && ((Builder) object).request.equals(request); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("%s[request=%s]", getClass().getCanonicalName(), request); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.