CAP理论和BASE理论
This commit is contained in:
@ -1,54 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>stream-tutorial</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/org.redisson/redisson -->
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
<version>3.12.5</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>3.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-framework</artifactId>
|
||||
<version>4.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-recipes</artifactId>
|
||||
<version>4.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.zookeeper</groupId>
|
||||
<artifactId>zookeeper</artifactId>
|
||||
<version>3.4.14</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -1,41 +0,0 @@
|
||||
package com.heibaiying;
|
||||
|
||||
import org.apache.curator.RetryPolicy;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.CuratorFrameworkFactory;
|
||||
import org.apache.curator.framework.recipes.locks.InterProcessMutex;
|
||||
import org.apache.curator.retry.RetryNTimes;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DistributedLock {
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
|
||||
RetryPolicy retryPolicy = new RetryNTimes(3, 5000);
|
||||
CuratorFramework client = CuratorFrameworkFactory.builder()
|
||||
.connectString("192.168.0.105:2181")
|
||||
.sessionTimeoutMs(10000).retryPolicy(retryPolicy)
|
||||
.namespace("mySpace").build();
|
||||
client.start();
|
||||
|
||||
// 1. 创建分布式锁
|
||||
InterProcessMutex lock = new InterProcessMutex(client, "/distributed/myLock");
|
||||
|
||||
// 2.尝试获取分布式锁
|
||||
if (lock.acquire(10, TimeUnit.SECONDS)) {
|
||||
try {
|
||||
System.out.println("模拟业务耗时");
|
||||
Thread.sleep(3 * 1000);
|
||||
} finally {
|
||||
// 3.释放锁
|
||||
lock.release();
|
||||
}
|
||||
}
|
||||
|
||||
client.close();
|
||||
}
|
||||
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
package com.heibaiying;
|
||||
|
||||
public class Employee {
|
||||
private String name;
|
||||
private String gender;
|
||||
private String company;
|
||||
private int age;
|
||||
private boolean isOfficial;
|
||||
|
||||
public Employee(String name, String gender, String company, int age) {
|
||||
this.name = name;
|
||||
this.gender = gender;
|
||||
this.company = company;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
Employee(String name, int age,boolean isOfficial) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.isOfficial = isOfficial;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Employee{" +
|
||||
"name='" + name + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public boolean isOfficial() {
|
||||
return isOfficial;
|
||||
}
|
||||
|
||||
public void setOfficial(boolean official) {
|
||||
isOfficial = official;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public void setGender(String gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
public String getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
public void setCompany(String company) {
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package com.heibaiying;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.IntConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class StreamTest {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(UUID.randomUUID() + ":" + Thread.currentThread().getId());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 进行求和
|
||||
*
|
||||
* @param list
|
||||
* @param initValue
|
||||
* @param binaryOperator
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> T reduce(List<T> list, T initValue, BinaryOperator<T> binaryOperator) {
|
||||
for (T t : list) {
|
||||
initValue = binaryOperator.apply(initValue, t);
|
||||
}
|
||||
return initValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 集合过滤
|
||||
*
|
||||
* @param list 待过滤的集合
|
||||
* @param predicate 函数式接口
|
||||
* @param <T> 集合中元素的类型
|
||||
* @return 满足条件的元素的集合
|
||||
*/
|
||||
public static <T> List<T> filter(List<T> list, CustomPredicate<T> predicate) {
|
||||
ArrayList<T> result = new ArrayList<>();
|
||||
for (T t : list) {
|
||||
if (predicate.test(t)) result.add(t);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 定义接口
|
||||
*
|
||||
* @param <T> 参数类型
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface CustomPredicate<T> {
|
||||
// 判断是否满足过滤标准
|
||||
boolean test(T t);
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
log4j.rootLogger=INFO, SYSLOG
|
||||
|
||||
log4j.appender.SYSLOG=org.apache.log4j.net.SyslogAppender
|
||||
log4j.appender.SYSLOG.syslogHost=127.0.0.1
|
||||
log4j.appender.SYSLOG.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.SYSLOG.layout.conversionPattern=%d{ISO8601} %-5p [%t] %c{2} %x - %m%n
|
||||
log4j.appender.SYSLOG.Facility=LOCAL1
|
Reference in New Issue
Block a user