Skip to content

Commit

Permalink
基于pull-stream重建scuttlebutt
Browse files Browse the repository at this point in the history
  • Loading branch information
zman committed Nov 17, 2019
1 parent 04e19aa commit 30d793b
Show file tree
Hide file tree
Showing 23 changed files with 798 additions and 342 deletions.
23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Travis Build](https://api.travis-ci.org/zman2013/scuttlebutt.svg?branch=master)](https://api.travis-ci.org/zman2013/scuttlebutt.svg?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/zman2013/scuttlebutt/badge.svg?branch=master)](https://coveralls.io/github/zman2013/scuttlebutt?branch=master)
# scuttlebutt
## Overview
scuttlebutt的java版实现,用来验证该方案落地的可行性,提供了一套基础库,能够便捷的实现自定义数据结构。
Expand All @@ -19,7 +21,7 @@ public class Model extends Scuttlebutt {

if( store.computeIfAbsent(key,(k)->new Update()).timestamp > update.timestamp ){
log.info("I have a more recent one: {}", update);
return true;
return false;
}

store.put(key, update);
Expand All @@ -32,15 +34,9 @@ public class Model extends Scuttlebutt {
public Update[] history(Map<String, Long> sources) {

return store.values().stream()
.filter( update -> {
if( sources.computeIfAbsent(update.sourceId, (s)->0L) < update.timestamp ){
return true;
}else{
return false;
}
})
.filter( update -> sources.computeIfAbsent(update.sourceId, (s) -> 0L) < update.timestamp)
.sorted((a, b) -> (int)(a.timestamp - b.timestamp))
.toArray(Update[]::new);

}

...
Expand All @@ -67,11 +63,12 @@ log.info(b.toString());
log.info("");
log.info("######## link ########");

Duplex sa = a.createSbStream();
Duplex sb = b.createSbStream();
IDuplex sa = a.createSbStream();
IDuplex sb = b.createSbStream();

Pull.link(sa, sb);

sa.sink(sb::source);
sb.sink(sa::source);
a.set("a-key2", "hahaha");

log.info("");
log.info("######## finally ########");
Expand Down
189 changes: 175 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,78 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.zman.scuttlebutt</groupId>
<groupId>com.zmannotes</groupId>
<artifactId>scuttlebutt</artifactId>
<version>0.0.1</version>
<version>0.0.3-SNAPSHOT</version>

<name>scuttlebutt</name>
<description>peer-to-peer replicable data structure.</description>
<url>https://github.com/zman2013/scuttlebutt</url>

<licenses>
<license>
<name>MIT License</name>
<url>https://opensource.org/licenses/MIT</url>
</license>
</licenses>

<developers>
<developer>
<name>Zhiyuan Man</name>
<email>vsmingren@qq.com</email>
<organization>zman</organization>
<organizationUrl>https://github.com/zman2013</organizationUrl>
<timezone>UTC+08:00</timezone>
</developer>
</developers>

<properties>
<version.maven-release-plugin>2.5.3</version.maven-release-plugin>
<version.maven-scm-provider-gitexe>1.9.5</version.maven-scm-provider-gitexe>
</properties>


<dependencies>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.16</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<groupId>com.zmannotes.stream</groupId>
<artifactId>pull-stream</artifactId>
<version>0.0.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.29</version>
</dependency>

<!-- test -->
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.42.Final</version>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
<!-- test end -->

</dependencies>

Expand All @@ -48,6 +84,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>8</source>
<target>8</target>
Expand All @@ -59,9 +96,13 @@
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.3.0</version>
<configuration>
<sourceEncoding>utf-8</sourceEncoding>
</configuration>
</plugin>
<!-- coveralls end -->

<!-- jacoco -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand All @@ -75,8 +116,128 @@
</execution>
</executions>
</plugin>
<!-- jacoco end -->

<!-- deploy -->
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>${version.maven-release-plugin}</version>
<configuration>
<localCheckout>true</localCheckout>
<pushChanges>false</pushChanges>
<mavenExecutorId>forked-path</mavenExecutorId>
<arguments>-Dgpg.passphrase=${gpg.passphrase}</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-gitexe</artifactId>
<version>${version.maven-scm-provider-gitexe}</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<!-- deploy end -->

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

</plugins>
</build>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/
</url>
</repository>
</distributionManagement>

<scm>
<connection>scm:git:git@github.com:zman2013/pull-stream.git</connection>
<developerConnection>scm:git:git@github.com:zman2013/pull-stream.git</developerConnection>
<url>https://github.com/zman2013/pull-stream</url>
<tag>HEAD</tag>
</scm>

<profiles>
<!-- GPG Signature on release -->
<profile>
<id>release-sign-artifacts</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>



</project>
83 changes: 0 additions & 83 deletions src/main/java/com/zman/scuttlebutt/Duplex.java

This file was deleted.

Loading

0 comments on commit 30d793b

Please sign in to comment.