Skip to content

Commit

Permalink
RAFT: leader election start
Browse files Browse the repository at this point in the history
  • Loading branch information
mdogan committed Nov 6, 2017
1 parent b9cdf2c commit 6b3992b
Show file tree
Hide file tree
Showing 16 changed files with 1,006 additions and 0 deletions.
208 changes: 208 additions & 0 deletions hazelcast-raft/pom.xml
@@ -0,0 +1,208 @@
<!--
~ Copyright (c) 2008-2017, Hazelcast, Inc. All Rights Reserved.
~
~ 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<name>hazelcast raft</name>
<artifactId>hazelcast-raft</artifactId>
<description>Hazelcast Raft Module</description>
<packaging>jar</packaging>

<parent>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-root</artifactId>
<version>3.10-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<properties>
<!-- needed for checkstyle/findbugs -->
<main.basedir>${project.parent.basedir}</main.basedir>
</properties>

<build>
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>${maven.git.commit.id.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<useNativeGit>false</useNativeGit>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
<abbrevLength>7</abbrevLength>
<gitDescribe>
<skip>true</skip>
</gitDescribe>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>${maven.animal.sniffer.plugin.version}</version>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java16</artifactId>
<version>1.0</version>
</signature>
<ignores>
<ignore>sun.misc.Unsafe</ignore>
</ignores>
</configuration>
<executions>
<execution>
<id>source-java6-check</id>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven.source.plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${maven.bundle.plugin.version}</version>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<instructions>
<Bundle-Activator>com.hazelcast.osgi.impl.Activator</Bundle-Activator>
<Export-Package>
com.hazelcast.*
</Export-Package>
<Import-Package>
!org.junit,
!com.hazelcast.*,
!com.eclipsesource.json,
sun.misc;resolution:=optional,
javax.cache;resolution:=optional,
javax.cache.*;resolution:=optional,
org.apache.log4j;resolution:=optional,
org.apache.log4j.spi;resolution:=optional,
org.apache.logging.log4j;resolution:=optional,
org.apache.logging.log4j.spi;resolution:=optional,
org.slf4j;resolution:=optional,
org.codehaus.groovy.jsr223;resolution:=optional,
org.jruby.embed.jsr223;resolution:=optional,
*
</Import-Package>
</instructions>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven.jar.plugin.version}</version>
<configuration>
<archive>
<index>true</index>
<compress>true</compress>
<manifest>
<mainClass>com.hazelcast.core.server.StartServer</mainClass>
<!--<addClasspath>true</addClasspath>-->
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
<excludes>
<exclude>**/*.html</exclude>
<exclude>**/*.sh</exclude>
<exclude>**/*.bat</exclude>
<exclude>META-INF/services/javax.annotation.processing.Processor</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
<!--Need to add sources for this test jar to Maven central. partic TestHazelcastInstanceFactory. Brian request. -->
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<filesets>
<fileset>
<directory>src/main/java</directory>
<includes>
<include>**/Generated*</include>
</includes>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
21 changes: 21 additions & 0 deletions hazelcast-raft/src/main/java/com/hazelcast/raft/RaftConfig.java
@@ -0,0 +1,21 @@
package com.hazelcast.raft;

import java.util.Collection;

/**
* TODO: Javadoc Pending...
*
* @author mdogan 30.10.2017
*/
public class RaftConfig {

private Collection<String> addresses;

public Collection<String> getAddresses() {
return addresses;
}

public void setAddresses(Collection<String> addresses) {
this.addresses = addresses;
}
}
84 changes: 84 additions & 0 deletions hazelcast-raft/src/main/java/com/hazelcast/raft/RaftContext.java
@@ -0,0 +1,84 @@
package com.hazelcast.raft;

import com.hazelcast.nio.Address;

import java.util.Collection;

/**
* TODO: Javadoc Pending...
*
*/
public class RaftContext {

final String name;
final Collection<Address> members;

private RaftRole role = RaftRole.FOLLOWER;
private int term;
private Address leader;

private Address votedFor;
private int lastVoteTerm;

public RaftContext(String name, Collection<Address> members) {
this.name = name;
this.members = members;
}

public String name() {
return name;
}

public void role(RaftRole role) {
this.role = role;
}

public Collection<Address> members() {
return members;
}

public RaftRole role() {
return role;
}

public int term() {
return term;
}

public int incTerm() {
return ++term;
}

public Address leader() {
return leader;
}

public void persistVote(int term, Address address) {
this.lastVoteTerm = term;
this.votedFor = address;
}

public void term(int term) {
this.term = term;
}

public int lastVoteTerm() {
return lastVoteTerm;
}

public Address votedFor() {
return votedFor;
}

public int lastLogTerm() {
return 0;
}

public int lastLogIndex() {
return 0;
}

public void leader(Address address) {
leader = address;
}
}
9 changes: 9 additions & 0 deletions hazelcast-raft/src/main/java/com/hazelcast/raft/RaftLog.java
@@ -0,0 +1,9 @@
package com.hazelcast.raft;

/**
* TODO: Javadoc Pending...
*
* @author mdogan 30.10.2017
*/
public class RaftLog {
}

0 comments on commit 6b3992b

Please sign in to comment.