getHostNameList() {
21 | return Lists.newArrayList("demo.beta.com");
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/RPC/dubbo-springboot/dubbo-springboot-provider/src/main/java/org/example/rpc/dubbo/provider/service/ProdResourceService.java:
--------------------------------------------------------------------------------
1 | package org.example.rpc.dubbo.provider.service;
2 |
3 | import com.google.common.collect.Lists;
4 | import org.apache.dubbo.config.annotation.DubboService;
5 | import org.example.rpc.service.ResourceService;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * 通过 group 来区分接口的不同实现
11 | *
12 | * 但往往也用来作为测试环境/生产环境的区分方式
13 | */
14 | @DubboService(
15 | group = "prod"
16 | )
17 | public class ProdResourceService implements ResourceService {
18 |
19 | @Override
20 | public String getName() {
21 | return "prod";
22 | }
23 |
24 | @Override
25 | public List getHostNameList() {
26 | return Lists.newArrayList("pushyzheng.com");
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/RPC/dubbo-springboot/dubbo-springboot-provider/src/main/resources/application.yaml:
--------------------------------------------------------------------------------
1 | dubbo:
2 | application:
3 | name: dubbo-provider
4 | registry:
5 | address: zookeeper://127.0.0.1:2181
6 | scan:
7 | base-packages: org.example.rpc.dubbo.provider
8 | provider:
9 | # 只有请求消息派发到线程池,不含响应,响应和其它连接断开事件,心跳等消息,直接在 IO 线程上执行。
10 | dispatcher: direct
11 | # 类似于自己创建的自定义线程, 使用有界队列, 当队列满时会抛出异常
12 | threadpool: eager
13 | threads: 20
14 | threadname: demo-dubbo-provider
15 |
16 | server:
17 | port: 9001
--------------------------------------------------------------------------------
/RPC/grpc/grpc-provider-api/src/main/proto/route_guide.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | option java_multiple_files = true;
4 | option java_package = "org.example.grpc.proto";
5 | option java_outer_classname = "RouteGuideProto";
6 | option objc_class_prefix = "RTG";
7 |
8 | package routeguide;
9 |
10 | service RouteGuide {
11 | rpc GetFeature(Point) returns (Feature) {}
12 | }
13 |
14 | message Point {
15 | int32 latitude = 1;
16 | int32 longitude = 2;
17 | }
18 |
19 | message Feature {
20 | string name = 1;
21 | Point location = 2;
22 | }
23 |
--------------------------------------------------------------------------------
/RPC/grpc/grpc-springboot-consumer/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 | !**/src/main/**
5 | !**/src/test/**
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /nbbuild/
25 | /dist/
26 | /nbdist/
27 | /.nb-gradle/
28 | build/
29 |
30 | ### VS Code ###
31 | .vscode/
32 |
--------------------------------------------------------------------------------
/RPC/grpc/grpc-springboot-consumer/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/RPC/grpc/grpc-springboot-consumer/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/RPC/grpc/grpc-springboot-consumer/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
3 |
--------------------------------------------------------------------------------
/RPC/grpc/grpc-springboot-consumer/README.md:
--------------------------------------------------------------------------------
1 | # 工程简介
2 |
3 | # 延伸阅读
4 |
5 |
--------------------------------------------------------------------------------
/RPC/grpc/grpc-springboot-consumer/src/main/java/org/example/grpc/consumer/GrpcSpringbootConsumerApplication.java:
--------------------------------------------------------------------------------
1 | package org.example.grpc.consumer;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class GrpcSpringbootConsumerApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(GrpcSpringbootConsumerApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/RPC/grpc/grpc-springboot-consumer/src/main/java/org/example/grpc/consumer/model/FeatureDTO.java:
--------------------------------------------------------------------------------
1 | package org.example.grpc.consumer.model;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 |
6 | @Data
7 | @AllArgsConstructor
8 | public class FeatureDTO {
9 |
10 | private String name;
11 | }
12 |
--------------------------------------------------------------------------------
/RPC/grpc/grpc-springboot-consumer/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: grpc-springboot-consumer
4 |
5 | server:
6 | port: 8081
7 |
8 | grpc:
9 | client:
10 | local-grpc-server:
11 | address: 'static://127.0.0.1:9091'
12 | enableKeepAlive: true
13 | keepAliveWithoutCalls: true
14 | negotiationType: plaintext
15 |
--------------------------------------------------------------------------------
/RPC/grpc/grpc-springboot-consumer/src/test/java/org/example/grpc/consumer/GrpcSpringbootConsumerApplicationTests.java:
--------------------------------------------------------------------------------
1 | package org.example.grpc.consumer;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | class GrpcSpringbootConsumerApplicationTests {
8 |
9 | @Test
10 | void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/RPC/grpc/grpc-springboot-provider/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 | !**/src/main/**
5 | !**/src/test/**
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /nbbuild/
25 | /dist/
26 | /nbdist/
27 | /.nb-gradle/
28 | build/
29 |
30 | ### VS Code ###
31 | .vscode/
32 |
--------------------------------------------------------------------------------
/RPC/grpc/grpc-springboot-provider/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/RPC/grpc/grpc-springboot-provider/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/RPC/grpc/grpc-springboot-provider/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
3 |
--------------------------------------------------------------------------------
/RPC/grpc/grpc-springboot-provider/README.md:
--------------------------------------------------------------------------------
1 | # 工程简介
2 |
3 | # 延伸阅读
4 |
5 |
--------------------------------------------------------------------------------
/RPC/grpc/grpc-springboot-provider/src/main/java/org/example/grpc/provider/GrpcSpringbootProviderApplication.java:
--------------------------------------------------------------------------------
1 | package org.example.grpc.provider;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class GrpcSpringbootProviderApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(GrpcSpringbootProviderApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/RPC/grpc/grpc-springboot-provider/src/main/java/org/example/grpc/provider/service/RouteGuideServiceImpl.java:
--------------------------------------------------------------------------------
1 | package org.example.grpc.provider.service;
2 |
3 | import io.grpc.stub.StreamObserver;
4 | import net.devh.boot.grpc.server.service.GrpcService;
5 | import org.example.grpc.proto.Feature;
6 | import org.example.grpc.proto.Point;
7 | import org.example.grpc.proto.RouteGuideGrpc;
8 |
9 | @GrpcService
10 | public class RouteGuideServiceImpl extends RouteGuideGrpc.RouteGuideImplBase {
11 |
12 | @Override
13 | public void getFeature(Point request, StreamObserver observer) {
14 | Feature result = Feature.newBuilder()
15 | .setName("Jeremy")
16 | .setLocation(request)
17 | .build();
18 |
19 | observer.onNext(result);
20 | observer.onCompleted();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/RPC/grpc/grpc-springboot-provider/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: local-grpc-server
4 | server:
5 | port: 8080
6 | grpc:
7 | server:
8 | port: 9091
9 |
--------------------------------------------------------------------------------
/RPC/grpc/grpc-springboot-provider/src/test/java/org/example/grpc/provider/GrpcSpringbootProviderApplicationTests.java:
--------------------------------------------------------------------------------
1 | package org.example.grpc.provider;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | class GrpcSpringbootProviderApplicationTests {
8 |
9 | @Test
10 | void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/RPC/grpc/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | RPC
7 | org.example
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | grpc
13 | pom
14 |
15 | grpc-provider-api
16 |
17 |
18 |
19 |
20 | com.google.protobuf
21 | protobuf-java
22 | 3.19.1
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/RPC/service-api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | RPC
7 | org.example
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | service-api
13 |
14 |
15 | 11
16 | 11
17 |
18 |
19 |
--------------------------------------------------------------------------------
/RPC/service-api/src/main/java/org/example/rpc/bean/User.java:
--------------------------------------------------------------------------------
1 | package org.example.rpc.bean;
2 |
3 | import lombok.Builder;
4 | import lombok.Data;
5 |
6 | import java.io.Serializable;
7 |
8 | @Data
9 | @Builder
10 | public class User implements Serializable {
11 |
12 | private String id;
13 |
14 | private String name;
15 |
16 | private int age;
17 | }
18 |
--------------------------------------------------------------------------------
/RPC/service-api/src/main/java/org/example/rpc/service/AsyncService.java:
--------------------------------------------------------------------------------
1 | package org.example.rpc.service;
2 |
3 | import java.util.concurrent.CompletableFuture;
4 |
5 | public interface AsyncService {
6 |
7 | /**
8 | * 服务方就提供的异步接口
9 | */
10 | CompletableFuture asyncHello(String name);
11 |
12 | /**
13 | * 服务方提供的同步接口, 但在客户端做异步
14 | */
15 | String syncHello(String name);
16 | }
17 |
--------------------------------------------------------------------------------
/RPC/service-api/src/main/java/org/example/rpc/service/LogService.java:
--------------------------------------------------------------------------------
1 | package org.example.rpc.service;
2 |
3 | public interface LogService {
4 |
5 | void recordOne(String content);
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/RPC/service-api/src/main/java/org/example/rpc/service/ResourceService.java:
--------------------------------------------------------------------------------
1 | package org.example.rpc.service;
2 |
3 | import java.util.List;
4 |
5 | public interface ResourceService {
6 |
7 | /**
8 | * Get the resource name of current environment
9 | */
10 | String getName();
11 |
12 | List getHostNameList();
13 | }
14 |
--------------------------------------------------------------------------------
/RPC/service-api/src/main/java/org/example/rpc/service/UserService.java:
--------------------------------------------------------------------------------
1 | package org.example.rpc.service;
2 |
3 | import org.example.rpc.bean.User;
4 |
5 | public interface UserService {
6 |
7 | boolean saveUser(User user);
8 |
9 | User getUserById(String id);
10 | }
11 |
--------------------------------------------------------------------------------
/Reactor/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %.35logger{30} - %msg%n
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/android-serialport/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/android-serialport/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/android-serialport/app/jni/Android.mk:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2009 Cedric Priscal
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | LOCAL_PATH := $(call my-dir)
18 |
19 | include $(CLEAR_VARS)
20 |
21 | TARGET_PLATFORM := android-3
22 | LOCAL_MODULE := serial_port
23 | LOCAL_SRC_FILES := SerialPort.c
24 | LOCAL_LDLIBS := -llog
25 |
26 | include $(BUILD_SHARED_LIBRARY)
27 |
--------------------------------------------------------------------------------
/android-serialport/app/jni/Application.mk:
--------------------------------------------------------------------------------
1 | APP_ABI := armeabi armeabi-v7a x86
2 |
--------------------------------------------------------------------------------
/android-serialport/app/jni/SerialPort.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class android_serialport_api_SerialPort */
4 |
5 | #ifndef _Included_android_serialport_api_SerialPort
6 | #define _Included_android_serialport_api_SerialPort
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 | /*
11 | * Class: android_serialport_api_SerialPort
12 | * Method: open
13 | * Signature: (Ljava/lang/String;II)Ljava/io/FileDescriptor;
14 | */
15 | JNIEXPORT jobject JNICALL Java_android_1serialport_1api_SerialPort_open
16 | (JNIEnv *, jclass, jstring, jint, jint);
17 |
18 | /*
19 | * Class: android_serialport_api_SerialPort
20 | * Method: close
21 | * Signature: ()V
22 | */
23 | JNIEXPORT void JNICALL Java_android_1serialport_1api_SerialPort_close
24 | (JNIEnv *, jobject);
25 |
26 | #ifdef __cplusplus
27 | }
28 | #endif
29 | #endif
30 |
--------------------------------------------------------------------------------
/android-serialport/app/jni/gen_SerialPort_h.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | javah -o SerialPort.h -jni -classpath ../src android_serialport_api.SerialPort
3 |
4 |
--------------------------------------------------------------------------------
/android-serialport/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/android-serialport/app/src/androidTest/java/com/example/serialport/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.serialport;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.example.serialport", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/android-serialport/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/android-serialport/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
--------------------------------------------------------------------------------
/android-serialport/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/android-serialport/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/android-serialport/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/android-serialport/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android-serialport/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/android-serialport/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/android-serialport/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/android-serialport/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android-serialport/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/android-serialport/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/android-serialport/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/android-serialport/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android-serialport/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/android-serialport/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/android-serialport/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/android-serialport/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android-serialport/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/android-serialport/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/android-serialport/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/android-serialport/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android-serialport/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/android-serialport/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/android-serialport/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/android-serialport/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SerialPort
3 |
4 |
--------------------------------------------------------------------------------
/android-serialport/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/android-serialport/app/src/test/java/com/example/serialport/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.serialport;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/android-serialport/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.2'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/android-serialport/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/android-serialport/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/android-serialport/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/android-serialport/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Nov 01 21:14:58 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/android-serialport/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/async-programming/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level - %msg%n
7 |
8 |
9 |
10 |
11 |
12 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level - %msg%n
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/binary-tree/c/bitree.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/binary-tree/c/bitree.c
--------------------------------------------------------------------------------
/cloud-native/.gitignore:
--------------------------------------------------------------------------------
1 | docker/golang-quickstart/main
2 | docker/nginx/logs
3 | docker-compose/golang-redis-quickstart/main
4 | k8s/projected-volume-example/secret/app/main
--------------------------------------------------------------------------------
/cloud-native/README.md:
--------------------------------------------------------------------------------
1 | # cloud-native
2 |
3 | ## docker
4 |
5 | - [golang-quickstart](docker/golang-quickstart): Golang simple http server
6 | - [java-quickstart](docker/java-quickstart): Java spring boot server
7 | - [python-flask-quickstart](docker/python-flask-quickstart): Python Flask http server
8 | - [nginx](docker/nginx): Nginx
9 |
10 |
11 | ## docker-compose
12 |
13 | - [golang-redis-quickstart](docker-compose/golang-redis-quickstart): compose Golang with redis
14 | - [mysql](docker-compose/mysql): MySQL
15 | - [profiles-example](docker-compose/profiles-example): docker compose profile feature
16 |
17 | ## k8s
18 |
19 | - [Nginx](k8s/nginx):
20 | - [nginx-deployment](k8s/nginx/nginx-deployment.yaml)
21 | - [nginx-service](k8s/nginx/nginx-service.yaml)
22 |
--------------------------------------------------------------------------------
/cloud-native/docker-compose/golang-redis-quickstart/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM alpine
2 |
3 | ENV GO111MODULE=on \
4 | CGO_ENABLED=0 \
5 | GOOS=linux \
6 | GOARCH=amd64
7 |
8 | WORKDIR /build
9 |
10 | COPY main .
11 |
12 | EXPOSE 9000
13 |
14 | CMD ["./main"]
--------------------------------------------------------------------------------
/cloud-native/docker-compose/golang-redis-quickstart/README.md:
--------------------------------------------------------------------------------
1 | # golang-redis-quickstart
2 |
3 | 整合 golang HTTP Server 和 redis server 的 compose。
4 |
5 | 运行:
6 |
7 | ```shell
8 | $ /bin/zsh ./run.sh
9 | ```
--------------------------------------------------------------------------------
/cloud-native/docker-compose/golang-redis-quickstart/build.sh:
--------------------------------------------------------------------------------
1 | docker build -t pushyzheng/golang-redis-quickstart .
--------------------------------------------------------------------------------
/cloud-native/docker-compose/golang-redis-quickstart/docker-compose.yaml:
--------------------------------------------------------------------------------
1 | version: "3.3"
2 |
3 | services:
4 | # 从本地镜像构建的 Web 服务
5 | app:
6 | container_name: golang-app
7 | build: .
8 | ports:
9 | - "9000:9000"
10 |
11 | # 依赖于 golang-redis-quickstart 服务, 所有会等待 golang-redis-quickstart 服务启动完成之后
12 | # 再开始运行
13 | depends_on:
14 | - redis-server
15 |
16 | # 系统环境变量
17 | environment:
18 | env: prod
19 |
20 | # golang-redis-quickstart 服务
21 | redis-server:
22 | image: "redis:alpine"
--------------------------------------------------------------------------------
/cloud-native/docker-compose/golang-redis-quickstart/go.mod:
--------------------------------------------------------------------------------
1 | module golang-redis-docker-compose
2 |
3 | go 1.17
4 |
5 | require (
6 | github.com/cespare/xxhash/v2 v2.1.2 // indirect
7 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
8 | github.com/go-redis/redis/v8 v8.11.5 // indirect
9 | )
10 |
--------------------------------------------------------------------------------
/cloud-native/docker-compose/golang-redis-quickstart/run.sh:
--------------------------------------------------------------------------------
1 | sudo env GOOS=linux GOARCH=amd64 go build main.go
2 |
3 | docker compose up --build
4 |
--------------------------------------------------------------------------------
/cloud-native/docker-compose/mysql/docker-compose.yaml:
--------------------------------------------------------------------------------
1 | version: "3.3"
2 |
3 | services:
4 | mysql-database:
5 | container_name: mysql-database
6 | platform: linux/amd64
7 | image: mysql:5.7
8 | environment:
9 | TZ: Asia/Shanghai
10 | MYSQL_ROOT_PASSWORD: 123456
11 | ports:
12 | - "13306:3306"
13 |
14 | volumes:
15 | # 初始化 SQL
16 | - ./init-sql:/docker-entrypoint-initdb.d
--------------------------------------------------------------------------------
/cloud-native/docker-compose/mysql/init-sql/v1.sql:
--------------------------------------------------------------------------------
1 | CREATE DATABASE demo CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
2 |
3 | use demo;
4 |
5 | CREATE TABLE `user`
6 | (
7 | `id` bigint NOT NULL AUTO_INCREMENT,
8 | `username` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
9 | `password` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
10 | PRIMARY KEY (`id`)
11 | );
--------------------------------------------------------------------------------
/cloud-native/docker-compose/profiles-example/README.md:
--------------------------------------------------------------------------------
1 | # profiles-example
2 |
3 | 通过 profile 来控制有哪些服务要启动和不启动。
4 |
5 | ## debug
6 |
7 | 如这里的 php-redis-admin 只会在 profile 指定 debug 时才会启动。执行:
8 |
9 | ```shell
10 | $ docker compose --profile debug up
11 | or
12 | $ zsh ./run.sh debug
13 | ```
14 |
15 | 
16 |
17 | ## frontend
18 |
19 | 而这里的 frontend 则只在 profile 指定 frontend 时才启动:
20 |
21 | ```shell
22 | $ docker compose --profile frontend
23 | or
24 | $ zsh ./run.sh frontend
25 | ```
26 |
27 | 
--------------------------------------------------------------------------------
/cloud-native/docker-compose/profiles-example/frontend/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/cloud-native/docker-compose/profiles-example/run.sh:
--------------------------------------------------------------------------------
1 | if [ "$1" = "debug" ]; then
2 | echo "Run with debug"
3 | docker compose --profile debug up
4 |
5 | elif [ "$1" = "frontend" ]; then
6 | echo "Run with frontend"
7 | docker compose --profile frontend up
8 |
9 | else
10 | echo "unsupported args"
11 | fi
12 |
--------------------------------------------------------------------------------
/cloud-native/docker-compose/profiles-example/static/WX20220612-000518@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/cloud-native/docker-compose/profiles-example/static/WX20220612-000518@2x.png
--------------------------------------------------------------------------------
/cloud-native/docker-compose/profiles-example/static/WechatIMG681.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/cloud-native/docker-compose/profiles-example/static/WechatIMG681.png
--------------------------------------------------------------------------------
/cloud-native/docker/golang-quickstart/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM alpine
2 |
3 | ENV GO111MODULE=on \
4 | CGO_ENABLED=0 \
5 | GOOS=linux \
6 | GOARCH=amd64
7 |
8 | WORKDIR /build
9 |
10 | COPY main .
11 |
12 | EXPOSE 9000
13 |
14 | CMD ["./main"]
--------------------------------------------------------------------------------
/cloud-native/docker/golang-quickstart/README.md:
--------------------------------------------------------------------------------
1 | # golang-quickstart
2 |
3 | Local:
4 |
5 | ```shell
6 | $ /bin/zsh ./build.sh
7 | $ docker run -p 9000:9000 --rm registry.cn-hangzhou.aliyuncs.com/pushyzheng/golang-quickstart
8 | ```
9 |
10 | publish to Aliyun
11 |
12 | ```shell
13 | $ /bin/zsh ./publish.sh
14 | ```
--------------------------------------------------------------------------------
/cloud-native/docker/golang-quickstart/build.sh:
--------------------------------------------------------------------------------
1 | sudo env GOOS=linux GOARCH=amd64 go build main.go
2 |
3 | docker build --platform linux/x86_64 -t registry.cn-hangzhou.aliyuncs.com/pushyzheng/golang-quickstart .
--------------------------------------------------------------------------------
/cloud-native/docker/golang-quickstart/go.mod:
--------------------------------------------------------------------------------
1 | module golang-quickstart
2 |
3 | go 1.17
4 |
--------------------------------------------------------------------------------
/cloud-native/docker/golang-quickstart/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "net/http"
6 | )
7 |
8 | func main() {
9 | http.HandleFunc("/", func(resp http.ResponseWriter, req *http.Request) {
10 | resp.Write([]byte("Hello World"))
11 | })
12 |
13 | addr := "0.0.0.0:9000"
14 | fmt.Println("Running on http://" + addr)
15 | err := http.ListenAndServe(addr, nil)
16 | if err != nil {
17 | panic(err)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/cloud-native/docker/golang-quickstart/publish.sh:
--------------------------------------------------------------------------------
1 | /bin/zsh ./build.sh
2 |
3 | docker image push registry.cn-hangzhou.aliyuncs.com/pushyzheng/golang-quickstart
--------------------------------------------------------------------------------
/cloud-native/docker/java-quickstart/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8-jdk-alpine
2 |
3 | COPY target/*.jar app.jar
4 |
5 | ENTRYPOINT ["java","-jar","/app.jar"]
--------------------------------------------------------------------------------
/cloud-native/docker/java-quickstart/README.md:
--------------------------------------------------------------------------------
1 | # java-quickstart
2 |
3 | Run:
4 |
5 | ````shell
6 | zsh ./run.sh
7 | ````
--------------------------------------------------------------------------------
/cloud-native/docker/java-quickstart/build.sh:
--------------------------------------------------------------------------------
1 | mvn clean package
2 | docker image build --platform linux/x86_64 -t pushyzheng/java-quickstart .
--------------------------------------------------------------------------------
/cloud-native/docker/java-quickstart/run.sh:
--------------------------------------------------------------------------------
1 | zsh build.sh
2 | docker run -p 8080:8080 --rm pushyzheng/java-quickstart
--------------------------------------------------------------------------------
/cloud-native/docker/java-quickstart/src/main/java/org/example/demo/cloudnative/CloudNativeApplication.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.cloudnative;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | import org.springframework.web.bind.annotation.*;
7 |
8 | @SpringBootApplication
9 | @RestController
10 | public class CloudNativeApplication {
11 |
12 | @RequestMapping("/")
13 | public String index() {
14 | return "Hello World";
15 | }
16 |
17 | public static void main(String[] args) {
18 | SpringApplication.run(CloudNativeApplication.class, args);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/cloud-native/docker/java-quickstart/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | # 应用名称
2 | spring.application.name=cloud-native
3 |
4 | # 应用服务 WEB 访问端口
5 | server.port=8080
6 |
7 |
8 |
--------------------------------------------------------------------------------
/cloud-native/docker/java-quickstart/src/test/java/org/example/demo/cloudnative/CloudNativeApplicationTests.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.cloudnative;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | class CloudNativeApplicationTests {
8 |
9 | @Test
10 | void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/cloud-native/docker/my-htop/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM alpine:latest
2 |
3 | RUN apk add --update htop && rm -rf /var/cache/apk/*
4 |
5 | CMD ["htop"]
--------------------------------------------------------------------------------
/cloud-native/docker/my-htop/run.sh:
--------------------------------------------------------------------------------
1 | # build image
2 | docker build -t myhtop .
3 |
4 | # Run container
5 | docker run -it --rm --pid=host myhtop
--------------------------------------------------------------------------------
/cloud-native/docker/nginx/README.md:
--------------------------------------------------------------------------------
1 | # nginx server
2 |
3 | Run:
4 |
5 | ```shell
6 | $ /bin/zsh ./run.sh
7 | ```
8 |
9 | volumes:
10 | - conf.d: the config of nginx
11 | - logs
12 | - html
13 |
--------------------------------------------------------------------------------
/cloud-native/docker/nginx/html/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 | Hello World
9 |
10 |
--------------------------------------------------------------------------------
/cloud-native/docker/nginx/run.sh:
--------------------------------------------------------------------------------
1 | docker run \
2 | -p 8080:80 \
3 | --name nginx-server \
4 | --rm \
5 | --volume "$PWD/conf.d":/etc/nginx/conf.d \
6 | --volume "$PWD/html":/usr/share/nginx/html \
7 | --volume "$PWD/logs":/var/log/nginx \
8 | nginx
9 |
--------------------------------------------------------------------------------
/cloud-native/docker/python-flask-quickstart/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:3
2 |
3 | WORKDIR /usr/src/app
4 |
5 | COPY requirements.txt ./
6 |
7 | RUN pip install --no-cache-dir -r requirements.txt
8 |
9 | COPY . .
10 |
11 | CMD [ "python", "./app.py" ]
12 |
13 | EXPOSE 5000
--------------------------------------------------------------------------------
/cloud-native/docker/python-flask-quickstart/app.py:
--------------------------------------------------------------------------------
1 | from flask import Flask
2 |
3 | app = Flask(__name__)
4 |
5 | @app.route('/')
6 | def hello():
7 | return 'Hello World'
8 |
9 | if __name__ == '__main__':
10 | app.run(host='0.0.0.0', debug=True)
--------------------------------------------------------------------------------
/cloud-native/docker/python-flask-quickstart/publish.sh:
--------------------------------------------------------------------------------
1 | docker build --platform linux/x86_64 -t registry.cn-hangzhou.aliyuncs.com/pushyzheng/python-flask-quickstart .
2 |
3 | docker image push registry.cn-hangzhou.aliyuncs.com/pushyzheng/python-flask-quickstart
--------------------------------------------------------------------------------
/cloud-native/docker/python-flask-quickstart/requirements.txt:
--------------------------------------------------------------------------------
1 | flask
--------------------------------------------------------------------------------
/cloud-native/k8s/nginx/nginx-deployment.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: nginx-deployment
5 | spec:
6 | selector:
7 | matchLabels:
8 | app: nginx
9 | replicas: 1
10 | template:
11 | metadata:
12 | labels:
13 | app: nginx
14 | spec:
15 | containers:
16 | - name: nginx
17 | image: nginx:alpine
18 | ports:
19 | - containerPort: 80
20 |
--------------------------------------------------------------------------------
/cloud-native/k8s/nginx/nginx-service.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Service
3 | metadata:
4 | name: nginx-service
5 | spec:
6 | selector:
7 | app: nginx
8 | ports:
9 | - protocol: TCP
10 | port: 80
11 | targetPort: 80
12 | nodePort: 30080
13 | type: NodePort
--------------------------------------------------------------------------------
/cloud-native/k8s/projected-volume-example/secret/README.md:
--------------------------------------------------------------------------------
1 | # projected-volume-secret
2 |
3 | Run:
4 |
5 | ```shell
6 | $ zsh secrets/apply-secrets.sh
7 | $ kubectl apply -f application.yaml
8 | ```
--------------------------------------------------------------------------------
/cloud-native/k8s/projected-volume-example/secret/app/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM alpine
2 |
3 | ENV GO111MODULE=on \
4 | CGO_ENABLED=0 \
5 | GOOS=linux \
6 | GOARCH=amd64
7 |
8 | WORKDIR /build
9 |
10 | COPY main .
11 |
12 | CMD ["./main"]
--------------------------------------------------------------------------------
/cloud-native/k8s/projected-volume-example/secret/app/build.sh:
--------------------------------------------------------------------------------
1 | sudo env GOOS=linux GOARCH=amd64 go build main.go
2 |
3 | docker build --platform linux/x86_64 -t pushyzheng/projected-volume-example .
--------------------------------------------------------------------------------
/cloud-native/k8s/projected-volume-example/secret/app/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "os"
6 | "time"
7 | )
8 |
9 | func main() {
10 | username := readFile("/projected-volume/username.txt")
11 | password := readFile("/projected-volume/password.txt")
12 |
13 | fmt.Printf("connection mysql server, username: %s, password: %s",
14 | username, password)
15 |
16 | time.Sleep(30 * time.Minute)
17 | }
18 |
19 | func readFile(filename string) string {
20 | b, err := os.ReadFile(filename)
21 | if err != nil {
22 | panic(err)
23 | }
24 | return string(b)
25 | }
26 |
--------------------------------------------------------------------------------
/cloud-native/k8s/projected-volume-example/secret/application.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Pod
3 | metadata:
4 | name: projected-volume-example
5 |
6 | spec:
7 | containers:
8 | - name: projected-volume-example-app
9 | image: pushyzheng/projected-volume-example:latest
10 | volumeMounts:
11 | - name: mysql-cred
12 | mountPath: "/projected-volume"
13 | readOnly: true
14 |
15 | volumes:
16 | - name: mysql-cred
17 | projected:
18 | sources:
19 | - secret:
20 | name: user
21 | - secret:
22 | name: password
--------------------------------------------------------------------------------
/cloud-native/k8s/projected-volume-example/secret/secrets/apply-secrets.sh:
--------------------------------------------------------------------------------
1 | kubectl create secret generic user --from-file=./username.txt
2 | kubectl create secret generic password --from-file=./password.txt
3 |
--------------------------------------------------------------------------------
/cloud-native/k8s/projected-volume-example/secret/secrets/password.txt:
--------------------------------------------------------------------------------
1 | 123456
--------------------------------------------------------------------------------
/cloud-native/k8s/projected-volume-example/secret/secrets/username.txt:
--------------------------------------------------------------------------------
1 | root
--------------------------------------------------------------------------------
/cloud-native/k8s/war-tomcat-pods/README.md:
--------------------------------------------------------------------------------
1 | # war-tomcat-pods
2 |
3 | ## 介绍
4 |
5 | 定义了一个 java-war 的初始化容器(*initContainers*),和一个标准的 Tomcat Server 容器 tomcat-server。
6 |
7 | 主要目的在于用一种“组合”方式,解决了 WAR 包与 Tomcat 容器之间耦合关系的问题。
8 |
9 | > 如果把 WAR 包直接放在 Tomcat 镜像的 webapps 目录下,做成一个新的镜像运行起来。 可是,这时候,如果你要更新WAR包的内容,或者要升级Tomcat镜像,就要重新制作一个新的 发布镜像,非常麻烦。
10 |
11 | 所以通过 Volume 的方式, 将两个容器进行整合,即定义一个 app-volume:
12 | - **_java-war_**: 将打包好的 war 包 *webapp.war* 文件挂载到 app-volume
13 | - **_tomcat-server_**: 将 app-volume 挂载到 */usr/local/tomcat/webapps* 目录下
14 |
15 | ## 运行
16 |
17 | ```shell
18 | $ zsh webapp/build.sh
19 | $ kubectl apply -f application.yaml
20 | ```
--------------------------------------------------------------------------------
/cloud-native/k8s/war-tomcat-pods/webapp/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM alpine
2 |
3 | COPY target/webapp.war webapp.war
--------------------------------------------------------------------------------
/cloud-native/k8s/war-tomcat-pods/webapp/build.sh:
--------------------------------------------------------------------------------
1 | # build java
2 | mvn clean package
3 |
4 | # build image
5 | docker image build --platform linux/x86_64 -t pushyzheng/webapp-example .
6 |
--------------------------------------------------------------------------------
/cloud-native/k8s/war-tomcat-pods/webapp/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 | Archetype Created Web Application
7 |
8 |
--------------------------------------------------------------------------------
/cloud-native/k8s/war-tomcat-pods/webapp/src/main/webapp/index.jsp:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hello World!
4 |
5 |
6 |
--------------------------------------------------------------------------------
/design-pattern/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.example
8 | design-pattern
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 |
14 | io.reactivex.rxjava2
15 | rxjava
16 | 2.2.3
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/game/AdidasPants.java:
--------------------------------------------------------------------------------
1 | package decorator.game;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2018/11/15 15:08
6 | */
7 | public class AdidasPants extends ClothesDecorator {
8 |
9 | private Component component;
10 |
11 | public AdidasPants(Component component) {
12 | this.component = component;
13 | }
14 |
15 | @Override
16 | public String getName() {
17 | return component.getName() + " 穿着Adidas裤子";
18 | }
19 |
20 | @Override
21 | public double count() {
22 | return component.count() + 10;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/game/ClothesDecorator.java:
--------------------------------------------------------------------------------
1 | package decorator.game;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2018/11/15 14:53
6 | */
7 | public abstract class ClothesDecorator extends Component {
8 |
9 | public abstract String getName();
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/game/Component.java:
--------------------------------------------------------------------------------
1 | package decorator.game;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2018/11/15 14:48
6 | */
7 | public abstract class Component {
8 |
9 | String name = "Unknown Component";
10 |
11 | public String getName() {
12 | return name;
13 | }
14 |
15 | public abstract double count();
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/game/Demo.java:
--------------------------------------------------------------------------------
1 | package decorator.game;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2018/11/15 14:59
6 | */
7 | public class Demo {
8 |
9 | public static void main(String[] args) {
10 |
11 | Component michael = new Michael();
12 |
13 | Component michaelWithCoat = new PumaCoat(michael);
14 |
15 | Component michaelWithCoatPants = new AdidasPants(michaelWithCoat);
16 |
17 | Component michaelWithCoatPantsShoes = new NikeShoes(michaelWithCoatPants);
18 |
19 | System.out.println(michaelWithCoatPantsShoes.getName() + " ,着装度为:" + michaelWithCoatPantsShoes.count());
20 |
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/game/Lucy.java:
--------------------------------------------------------------------------------
1 | package decorator.game;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2018/11/15 14:52
6 | */
7 | public class Lucy extends Component {
8 |
9 | public Lucy() {
10 | this.name = "Lucy";
11 | }
12 |
13 | @Override
14 | public double count() {
15 | return 25;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/game/Michael.java:
--------------------------------------------------------------------------------
1 | package decorator.game;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2018/11/15 14:51
6 | */
7 | public class Michael extends Component {
8 |
9 | public Michael() {
10 | this.name = "Michael";
11 | }
12 |
13 | @Override
14 | public double count() {
15 | return 20;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/game/NikeShoes.java:
--------------------------------------------------------------------------------
1 | package decorator.game;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2018/11/15 14:54
6 | */
7 | public class NikeShoes extends ClothesDecorator {
8 |
9 | private Component component;
10 |
11 | public NikeShoes(Component component) {
12 | this.component = component;
13 | }
14 |
15 | @Override
16 | public String getName() {
17 | return component.getName() + " 穿着Nike鞋";
18 | }
19 |
20 | @Override
21 | public double count() {
22 | return component.count() + 15;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/game/PumaCoat.java:
--------------------------------------------------------------------------------
1 | package decorator.game;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2018/11/15 15:01
6 | */
7 | public class PumaCoat extends ClothesDecorator {
8 |
9 | private Component component;
10 |
11 | public PumaCoat(Component component) {
12 | this.component = component;
13 | }
14 |
15 | @Override
16 | public String getName() {
17 | return component.getName() + " 穿着Puma上衣";
18 | }
19 |
20 | @Override
21 | public double count() {
22 | return component.count() + 8;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/io/FuckIO.java:
--------------------------------------------------------------------------------
1 | package decorator.io;
2 |
3 | import java.io.*;
4 |
5 | /**
6 | * @author Pushy
7 | * @since 2018/11/15 15:18
8 | */
9 | public class FuckIO {
10 |
11 | public static void main(String[] args) throws FileNotFoundException {
12 |
13 | new PushbackInputStream(
14 | new BufferedInputStream(
15 | new FileInputStream(new File("/usr/xxx"))));
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/io/IODemo.java:
--------------------------------------------------------------------------------
1 | package decorator.io;
2 |
3 | import java.io.*;
4 |
5 | /**
6 | * @author Pushy
7 | * @since 2018/11/15 17:22
8 | */
9 | public class IODemo {
10 |
11 | public static void main(String[] args) throws IOException {
12 |
13 | byte[] bytes = {1,2,3};
14 |
15 | InputStream bas = new ByteArrayInputStream(bytes);
16 |
17 | InputStream bfs = new BufferedInputStream(bas);
18 |
19 | PushbackInputStream pushbackInputStream = new PushbackInputStream(bfs);
20 |
21 | int c;
22 | while ((c = pushbackInputStream.read()) > 0) {
23 | System.out.print((char) c);
24 | }
25 | pushbackInputStream.close();
26 |
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/io/custom/lowercase/Test.java:
--------------------------------------------------------------------------------
1 | package decorator.io.custom.lowercase;
2 |
3 | import java.io.*;
4 |
5 | /**
6 | * @author Pushy
7 | * @since 2018/11/15 12:23
8 | */
9 | public class Test {
10 |
11 | public static void main(String[] args) {
12 |
13 | int c;
14 | try {
15 | InputStream in = new LowerCaseInputStream(
16 | new BufferedInputStream(
17 | new FileInputStream(new File("E:\\test.txt"))));
18 |
19 | while ((c = in.read()) > 0) {
20 | System.out.print((char) c);
21 | }
22 | in.close();
23 |
24 | } catch (FileNotFoundException e) {
25 | e.printStackTrace();
26 | } catch (IOException e) {
27 | e.printStackTrace();
28 | }
29 |
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/io/custom/plus/PlusInputStream.java:
--------------------------------------------------------------------------------
1 | package decorator.io.custom.plus;
2 |
3 | import java.io.FilterInputStream;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 |
7 | /**
8 | * @author Pushy
9 | * @since 2018/11/15 17:34
10 | */
11 | public class PlusInputStream extends FilterInputStream {
12 |
13 | protected PlusInputStream(InputStream in) {
14 | super(in);
15 | }
16 |
17 | @Override
18 | public int read() throws IOException {
19 | int c = super.read();
20 | return (c == -1 ? c : c + 1);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/io/custom/plus/Test.java:
--------------------------------------------------------------------------------
1 | package decorator.io.custom.plus;
2 |
3 | import java.io.BufferedInputStream;
4 | import java.io.ByteArrayInputStream;
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 |
8 | /**
9 | * @author Pushy
10 | * @since 2018/11/15 17:35
11 | */
12 | public class Test {
13 |
14 | public static void main(String[] args) throws IOException {
15 | byte[] bytes = {1, 2, 3};
16 |
17 | InputStream is = new PlusInputStream(
18 | new BufferedInputStream(
19 | new ByteArrayInputStream(bytes)));
20 |
21 | int c;
22 | while ((c = is.read()) > 0) {
23 | System.out.print(c);
24 | }
25 | is.close();
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/starbuzz/Beverage.java:
--------------------------------------------------------------------------------
1 | package decorator.starbuzz;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2018/11/15 12:28
6 | */
7 | public abstract class Beverage {
8 |
9 | String description = "Unknown Beverage";
10 |
11 | public String getDescription() {
12 | return description;
13 | }
14 |
15 | public abstract double cost();
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/starbuzz/CondimentDecorator.java:
--------------------------------------------------------------------------------
1 | package decorator.starbuzz;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2018/11/15 12:30
6 | */
7 | public abstract class CondimentDecorator extends Beverage {
8 |
9 | public abstract String getDescription();
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/starbuzz/Espresso.java:
--------------------------------------------------------------------------------
1 | package decorator.starbuzz;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2018/11/15 12:32
6 | */
7 | public class Espresso extends Beverage {
8 |
9 | public Espresso() {
10 | this.description = "Espresso";
11 | }
12 |
13 | @Override
14 | public double cost() {
15 | return 1.99;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/starbuzz/Mocha.java:
--------------------------------------------------------------------------------
1 | package decorator.starbuzz;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2018/11/15 12:32
6 | */
7 | public class Mocha extends CondimentDecorator {
8 |
9 | Beverage beverage;
10 |
11 | public Mocha(Beverage beverage) {
12 | this.beverage = beverage;
13 | }
14 |
15 | @Override
16 | public String getDescription() {
17 | return beverage.getDescription() + ", Mocha";
18 | }
19 |
20 | @Override
21 | public double cost() {
22 | return .20 + beverage.cost();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/starbuzz/StarbuzzStore.java:
--------------------------------------------------------------------------------
1 | package decorator.starbuzz;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2018/11/15 12:33
6 | */
7 | public class StarbuzzStore {
8 |
9 | public static void main(String[] args) {
10 |
11 | Beverage espresso = new Espresso();
12 |
13 | Beverage espressoWithmocha = new Mocha(espresso);
14 | Beverage espressoWithmochaWithwhip = new Whip(espressoWithmocha);
15 |
16 | double cost = espressoWithmochaWithwhip.cost();
17 | String desc = espressoWithmochaWithwhip.getDescription();
18 |
19 | System.out.println(cost);
20 | System.out.println("desc: " + desc);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/decorator/starbuzz/Whip.java:
--------------------------------------------------------------------------------
1 | package decorator.starbuzz;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2018/11/15 12:35
6 | */
7 | public class Whip extends CondimentDecorator {
8 |
9 | Beverage beverage;
10 |
11 | public Whip(Beverage beverage) {
12 | this.beverage = beverage;
13 | }
14 |
15 | @Override
16 | public String getDescription() {
17 | return beverage.getDescription() + ", Whip";
18 | }
19 |
20 | @Override
21 | public double cost() {
22 | return .3 + beverage.cost();
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/observer/Demo.java:
--------------------------------------------------------------------------------
1 | package observer;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2018/11/13 17:51
6 | */
7 | public class Demo {
8 |
9 | public static void main(String[] args) {
10 |
11 | Weather weather = new Weather();
12 |
13 | new Thread(() -> {
14 | float start = 20f;
15 | while (true) {
16 | weather.setTemperature(start++);
17 | try {
18 | Thread.sleep(5000);
19 | } catch (InterruptedException e) {
20 | e.printStackTrace();
21 | }
22 | }
23 | }).start();
24 |
25 | WeatherApplication application = new WeatherApplication(weather);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/observer/Weather.java:
--------------------------------------------------------------------------------
1 | package observer;
2 |
3 | import java.util.Observable;
4 |
5 | /**
6 | * @author Pushy
7 | * @since 2018/11/13 17:16
8 | */
9 | public class Weather extends Observable {
10 |
11 | private float temperature;
12 |
13 | public void setTemperature(float temperature) {
14 | this.temperature = temperature;
15 | handleChange();
16 | }
17 |
18 | public float getTemperature() {
19 | return temperature;
20 | }
21 |
22 | private void handleChange() {
23 | setChanged();
24 | notifyObservers();
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/design-pattern/src/main/java/observer/WeatherApplication.java:
--------------------------------------------------------------------------------
1 | package observer;
2 |
3 | import java.util.Observable;
4 | import java.util.Observer;
5 |
6 | /**
7 | * @author Pushy
8 | * @since 2018/11/13 17:43
9 | */
10 | public class WeatherApplication implements Observer {
11 |
12 | public WeatherApplication(Observable observable) {
13 | observable.addObserver(this);
14 | }
15 |
16 | public void update(Observable o, Object arg) {
17 | if (o instanceof Weather) {
18 | Weather weather = (Weather) o;
19 | float updateTemp = weather.getTemperature();
20 | System.out.println("WeatherApplication got the new temperature => " + updateTemp);
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/disruptor/src/main/java/org/example/demo/disruptor/LongEvent.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.disruptor;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class LongEvent {
7 |
8 | private long value;
9 | }
10 |
--------------------------------------------------------------------------------
/disruptor/src/main/java/org/example/demo/disruptor/LongEventExceptionHandler.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.disruptor;
2 |
3 | import com.lmax.disruptor.ExceptionHandler;
4 |
5 | public class LongEventExceptionHandler implements ExceptionHandler {
6 |
7 | @Override
8 | public void handleEventException(Throwable ex, long sequence, LongEvent event) {
9 | System.out.println("handle event exception: " + sequence);
10 | ex.printStackTrace();
11 | }
12 |
13 | @Override
14 | public void handleOnStartException(Throwable ex) {
15 | }
16 |
17 | @Override
18 | public void handleOnShutdownException(Throwable ex) {
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/disruptor/src/main/java/org/example/demo/disruptor/LongEventHandler.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.disruptor;
2 |
3 | import com.lmax.disruptor.EventHandler;
4 |
5 | public class LongEventHandler implements EventHandler {
6 |
7 | @Override
8 | public void onEvent(LongEvent event, long sequence, boolean endOfBatch) throws Exception {
9 | System.out.println("event: " + event + ", endOfBatch: " + endOfBatch);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/elasticsearch/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 | !**/src/main/**/target/
5 | !**/src/test/**/target/
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /nbbuild/
25 | /dist/
26 | /nbdist/
27 | /.nb-gradle/
28 | build/
29 | !**/src/main/**/build/
30 | !**/src/test/**/build/
31 |
32 | ### VS Code ###
33 | .vscode/
34 |
--------------------------------------------------------------------------------
/elasticsearch/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/elasticsearch/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/elasticsearch/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.3/apache-maven-3.8.3-bin.zip
2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
3 |
--------------------------------------------------------------------------------
/elasticsearch/src/main/java/com/example/elasticsearch/common/FakerUtils.java:
--------------------------------------------------------------------------------
1 | package com.example.elasticsearch.common;
2 |
3 | import com.github.javafaker.Faker;
4 | import lombok.experimental.UtilityClass;
5 |
6 | @UtilityClass
7 | public class FakerUtils {
8 |
9 | private static final Faker FAKER = new Faker();
10 |
11 | public String getFakerName() {
12 | return FAKER.funnyName().name();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/elasticsearch/src/main/java/com/example/elasticsearch/common/JsonUtils.java:
--------------------------------------------------------------------------------
1 | package com.example.elasticsearch.common;
2 |
3 | import com.fasterxml.jackson.databind.ObjectMapper;
4 | import lombok.experimental.UtilityClass;
5 |
6 | @UtilityClass
7 | public class JsonUtils {
8 |
9 | private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
10 |
11 | public String toJson(Object obj) {
12 | try {
13 | return OBJECT_MAPPER.writeValueAsString(obj);
14 | } catch (Exception e) {
15 | return null;
16 | }
17 | }
18 |
19 | public String pretty(Object obj) {
20 | try {
21 | return OBJECT_MAPPER.writerWithDefaultPrettyPrinter()
22 | .writeValueAsString(obj);
23 | } catch (Exception e) {
24 | return null;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/elasticsearch/src/main/java/com/example/elasticsearch/normal/ClientHolder.java:
--------------------------------------------------------------------------------
1 | package com.example.elasticsearch.normal;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.elasticsearch.client.RestHighLevelClient;
5 | import org.springframework.data.elasticsearch.client.ClientConfiguration;
6 | import org.springframework.data.elasticsearch.client.RestClients;
7 |
8 | @Slf4j
9 | public class ClientHolder {
10 |
11 | public static final RestHighLevelClient REST_HIGH_LEVEL_CLIENT;
12 |
13 | static {
14 | REST_HIGH_LEVEL_CLIENT = RestClients
15 | .create(ClientConfiguration.localhost())
16 | .rest();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/elasticsearch/src/main/java/com/example/elasticsearch/spring/ElasticsearchApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.elasticsearch.spring;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class ElasticsearchApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(ElasticsearchApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/elasticsearch/src/main/java/com/example/elasticsearch/spring/bean/Article.java:
--------------------------------------------------------------------------------
1 | package com.example.elasticsearch.spring.bean;
2 |
3 | import lombok.Data;
4 | import org.springframework.data.annotation.Id;
5 | import org.springframework.data.elasticsearch.annotations.Document;
6 | import org.springframework.data.elasticsearch.annotations.Field;
7 | import org.springframework.data.elasticsearch.annotations.FieldType;
8 | import org.springframework.data.elasticsearch.core.Range;
9 |
10 | @Data
11 | @Document(indexName = "articles")
12 | public class Article {
13 |
14 | @Id
15 | private Long id;
16 |
17 | @Field(type = FieldType.Keyword)
18 | public String title;
19 |
20 | @Field(type = FieldType.Keyword)
21 | public String content;
22 |
23 | @Field(type = FieldType.Date)
24 | public Long date;
25 | }
26 |
--------------------------------------------------------------------------------
/elasticsearch/src/main/java/com/example/elasticsearch/spring/bean/User.java:
--------------------------------------------------------------------------------
1 | package com.example.elasticsearch.spring.bean;
2 |
3 | import lombok.Data;
4 | import org.springframework.data.annotation.Id;
5 | import org.springframework.data.elasticsearch.annotations.Document;
6 | import org.springframework.data.elasticsearch.annotations.Field;
7 | import org.springframework.data.elasticsearch.annotations.FieldType;
8 |
9 | @Data
10 | @Document(indexName = "users")
11 | public class User {
12 |
13 | @Id
14 | private Long id;
15 |
16 | @Field(type = FieldType.Keyword)
17 | private String username;
18 |
19 | @Field(type = FieldType.Integer)
20 | private int age;
21 | }
22 |
--------------------------------------------------------------------------------
/elasticsearch/src/main/java/com/example/elasticsearch/spring/controller/UserController.java:
--------------------------------------------------------------------------------
1 | package com.example.elasticsearch.spring.controller;
2 |
3 | import com.example.elasticsearch.spring.bean.User;
4 | import com.example.elasticsearch.spring.repository.UserRepository;
5 | import org.springframework.web.bind.annotation.PathVariable;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | import javax.annotation.Resource;
10 |
11 | @RestController
12 | public class UserController {
13 |
14 | @Resource
15 | private UserRepository userRepository;
16 |
17 | @RequestMapping("/users/{name}")
18 | public User getUserByName(@PathVariable String name) {
19 | return userRepository.findByUsername(name);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/elasticsearch/src/main/java/com/example/elasticsearch/spring/repository/ArticleRepository.java:
--------------------------------------------------------------------------------
1 | package com.example.elasticsearch.spring.repository;
2 |
3 | import com.example.elasticsearch.spring.bean.Article;
4 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | import java.util.List;
8 |
9 | @Repository
10 | public interface ArticleRepository extends ElasticsearchRepository {
11 |
12 | List findAllByDateBetween(long from, long to);
13 |
14 | List findAllByTitleAndContent(String title, String content);
15 | }
16 |
--------------------------------------------------------------------------------
/elasticsearch/src/main/java/com/example/elasticsearch/spring/repository/UserRepository.java:
--------------------------------------------------------------------------------
1 | package com.example.elasticsearch.spring.repository;
2 |
3 | import com.example.elasticsearch.spring.bean.User;
4 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface UserRepository extends ElasticsearchRepository {
9 |
10 | User findByUsername(String username);
11 | }
12 |
--------------------------------------------------------------------------------
/elasticsearch/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/firebase/README.md:
--------------------------------------------------------------------------------
1 | # firebase
2 |
3 | [FirebaseAppRegistry](src/main/java/org/example/demo/firebase/FirebaseAppRegistry.java) 用于注册多个 FirebaseApp
4 |
5 | 发送类:
6 |
7 | - [MessageSender](src/main/java/org/example/demo/firebase/service/MessageSender.java): 消息发送
8 | - [TopicSubscriber](src/main/java/org/example/demo/firebase/service/TopicSubscriber.java): 注册相关操作
9 |
--------------------------------------------------------------------------------
/firebase/src/main/java/org/example/demo/firebase/models/MessageRequest.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.firebase.models;
2 |
3 | import com.google.firebase.messaging.Notification;
4 | import lombok.Builder;
5 | import lombok.Data;
6 |
7 | import java.util.Map;
8 |
9 | /**
10 | * @author zuqin.zheng
11 | */
12 | @Data
13 | @Builder
14 | public class MessageRequest {
15 |
16 | private String token;
17 |
18 | private Notification notification;
19 |
20 | private Map data;
21 | }
22 |
--------------------------------------------------------------------------------
/flyway/flyway/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 | !**/src/main/**
5 | !**/src/test/**
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /nbbuild/
25 | /dist/
26 | /nbdist/
27 | /.nb-gradle/
28 | build/
29 |
30 | ### VS Code ###
31 | .vscode/
32 |
--------------------------------------------------------------------------------
/flyway/flyway/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/flyway/flyway/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/flyway/flyway/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
3 |
--------------------------------------------------------------------------------
/flyway/flyway/README.md:
--------------------------------------------------------------------------------
1 | # 工程简介
2 |
3 | # 延伸阅读
4 |
5 |
--------------------------------------------------------------------------------
/flyway/flyway/src/main/java/com/example/demo/flyway/FlywayApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.flyway;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class FlywayApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(FlywayApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/flyway/flyway/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | datasource:
3 | url: jdbc:mysql://localhost:3306/flyway?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT
4 | username: root
5 | password: 12345678
6 | driver-class-name: com.mysql.cj.jdbc.Driver
7 |
--------------------------------------------------------------------------------
/flyway/flyway/src/main/resources/db/migration/V1__create_user.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE `user`
2 | (
3 | `id` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
4 | `username` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
5 | `password` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
6 | `gender` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
7 | `timestamp` datetime DEFAULT NULL,
8 | PRIMARY KEY (`id`) USING BTREE
9 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC
10 |
--------------------------------------------------------------------------------
/flyway/flyway/src/main/resources/db/migration/V2__user_add_column.sql:
--------------------------------------------------------------------------------
1 | ALTER TABLE `user`
2 | ADD open_id varchar(36) FIRST;
3 |
--------------------------------------------------------------------------------
/flyway/flyway/src/main/resources/flyway.conf:
--------------------------------------------------------------------------------
1 | flyway.url=jdbc:mysql://localhost:3306/flyway?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT
2 | flyway.user=root
3 | flyway.password=12345678
4 | flyway.driver=com.mysql.cj.jdbc.Driver
5 |
--------------------------------------------------------------------------------
/flyway/flyway/src/test/java/com/example/demo/flyway/FlywayApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.flyway;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | class FlywayApplicationTests {
8 |
9 | @Test
10 | void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/java-shell/README.md:
--------------------------------------------------------------------------------
1 | ## Build
2 |
3 | ```shell
4 | $ mvn package assembly:single
5 | ```
6 |
7 | ## Run
8 |
9 | ```shell
10 | $ java -jar target/shell-1.0-SNAPSHOT-jar-with-dependencies.jar
11 | ```
12 |
13 | ## Test
14 |
15 | ```shell
16 | JavaShell $ cat tmp.txt | grep a
17 | ```
--------------------------------------------------------------------------------
/java-shell/src/main/java/com/example/shell/CommandEnum.java:
--------------------------------------------------------------------------------
1 | package com.example.shell;
2 |
3 |
4 | /**
5 | * @author Pushy
6 | */
7 | public enum CommandEnum {
8 |
9 | CAT("cat"),
10 | WC("wc"),
11 | GREP("grep"),
12 | EXIT("exit");
13 |
14 | public String value;
15 |
16 | CommandEnum(String value) {
17 | this.value = value;
18 | }
19 |
20 | public static boolean contains(String cmd) {
21 | for (CommandEnum v : CommandEnum.values()) {
22 | if (cmd.equals(v.value)) {
23 | return true;
24 | }
25 | }
26 | return false;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/java-shell/src/main/java/com/example/shell/Main.java:
--------------------------------------------------------------------------------
1 | package com.example.shell;
2 |
3 | import com.example.shell.exception.CommandNotFoundException;
4 | import com.example.shell.exception.InvalidFileInputException;
5 |
6 | import java.io.IOException;
7 |
8 | /**
9 | * @author Pushy
10 | * @since 2020/6/7
11 | */
12 | public class Main {
13 |
14 | public static void main(String[] args) {
15 | boolean flag = true;
16 | while (flag) {
17 | try {
18 | flag = Controller.handleCommand();
19 | } catch (IOException e) {
20 | e.printStackTrace();
21 | } catch (CommandNotFoundException e) {
22 | System.out.println(e.getCmd() + ": command not found");
23 | } catch (InvalidFileInputException e) {
24 | System.out.println(e.getMessage());
25 | }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/java-shell/src/main/java/com/example/shell/exception/CommandNotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.example.shell.exception;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2020/6/7
6 | */
7 | public class CommandNotFoundException extends RuntimeException {
8 |
9 | private String cmd;
10 |
11 | public CommandNotFoundException(String cmd) {
12 | this.cmd = cmd;
13 | }
14 |
15 | public String getCmd() {
16 | return cmd;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/java-shell/src/main/java/com/example/shell/exception/InvalidFileInputException.java:
--------------------------------------------------------------------------------
1 | package com.example.shell.exception;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2020/6/7
6 | */
7 | public class InvalidFileInputException extends RuntimeException {
8 |
9 | public InvalidFileInputException(String message) {
10 | super(message);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/java-shell/src/main/java/com/example/shell/handler/CatPipeHandler.java:
--------------------------------------------------------------------------------
1 | package com.example.shell.handler;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.PipedInputStream;
6 | import java.io.PipedOutputStream;
7 |
8 | /**
9 | * @author Pushy
10 | * @since 2020/6/6
11 | */
12 | public class CatPipeHandler extends AbstractPipeHandler {
13 |
14 | public CatPipeHandler(PipedInputStream inputStream, PipedOutputStream outputStream) {
15 | super(inputStream, outputStream);
16 | }
17 |
18 | @Override
19 | protected void handle(BufferedReader reader) {
20 | String line;
21 |
22 | try {
23 | while ((line = reader.readLine()) != null) {
24 | writeToStream(line);
25 | }
26 | } catch (IOException e) {
27 | e.printStackTrace();
28 | }
29 | closeOutStream();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/java-shell/src/main/java/com/example/shell/handler/WcPipeHandler.java:
--------------------------------------------------------------------------------
1 | package com.example.shell.handler;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.PipedInputStream;
6 | import java.io.PipedOutputStream;
7 |
8 | /**
9 | * @author Pushy
10 | * @since 2020/6/6
11 | */
12 | public class WcPipeHandler extends AbstractPipeHandler {
13 |
14 | public WcPipeHandler(PipedInputStream inputStream, PipedOutputStream outputStream) {
15 | super(inputStream, outputStream);
16 | }
17 |
18 | @Override
19 | protected void handle(BufferedReader reader) {
20 | int cnt = 0;
21 | try {
22 | while (reader.readLine() != null) {
23 | cnt++;
24 | }
25 | writeToStream(String.valueOf(cnt));
26 | } catch (IOException e) {
27 | e.printStackTrace();
28 | }
29 | closeOutStream();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/java-shell/tmp.txt:
--------------------------------------------------------------------------------
1 | apple
2 | book
3 | action
4 | ack
5 | like
6 | username
7 | This is last
8 | Good
9 | Hello World
--------------------------------------------------------------------------------
/jooq/jooq-demo/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 | !**/src/main/**/target/
5 | !**/src/test/**/target/
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /nbbuild/
25 | /dist/
26 | /nbdist/
27 | /.nb-gradle/
28 | build/
29 | !**/src/main/**/build/
30 | !**/src/test/**/build/
31 |
32 | ### VS Code ###
33 | .vscode/
34 | generated
35 |
--------------------------------------------------------------------------------
/jooq/jooq-demo/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/jooq/jooq-demo/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/jooq/jooq-demo/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip
2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
3 |
--------------------------------------------------------------------------------
/jooq/jooq-demo/README.md:
--------------------------------------------------------------------------------
1 | ## quick start
2 |
3 | 创建本地 DB:
4 |
5 | ```sql
6 | CREATE DATABASE demo CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
7 | ```
8 |
9 | 执行 flyway:
10 |
11 | ```shell
12 | $ mvn flyway:migrate
13 | ```
14 |
15 | 生成 Jooq 代码:
16 |
17 | ```shell
18 | $ mvn jooq-codegen:generate
19 | ```
20 |
21 | 在 IDEA 中, 将生成的 generated 目录标记为 src:
22 |
23 | 
24 |
--------------------------------------------------------------------------------
/jooq/jooq-demo/images/WechatIMG678.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/jooq/jooq-demo/images/WechatIMG678.png
--------------------------------------------------------------------------------
/jooq/jooq-demo/src/main/java/org/example/demo/jooq/JooqDemoApplication.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.jooq;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
6 |
7 | @SpringBootApplication(
8 | exclude = FlywayAutoConfiguration.class
9 | )
10 | public class JooqDemoApplication {
11 |
12 | public static void main(String[] args) {
13 | SpringApplication.run(JooqDemoApplication.class, args);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/jooq/jooq-demo/src/main/java/org/example/demo/jooq/config/JooqConfig.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.jooq.config;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 |
5 | /**
6 | * @author zuqin.zheng
7 | */
8 | @Configuration
9 | public class JooqConfig {
10 | }
11 |
--------------------------------------------------------------------------------
/jooq/jooq-demo/src/main/java/org/example/demo/jooq/config/RepositoryConfig.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.jooq.config;
2 |
3 | import org.example.demo.jooq.dao.tables.daos.TPostDao;
4 | import org.example.demo.jooq.dao.tables.daos.TUserDao;
5 | import org.jooq.DSLContext;
6 | import org.springframework.context.annotation.Bean;
7 | import org.springframework.context.annotation.Configuration;
8 |
9 | import javax.annotation.Resource;
10 |
11 | /**
12 | * @author zuqin.zheng
13 | */
14 | @Configuration
15 | public class RepositoryConfig {
16 |
17 | @Resource
18 | private DSLContext dslContext;
19 |
20 | @Bean
21 | public TUserDao tUserDao() {
22 | return new TUserDao(dslContext.configuration());
23 | }
24 |
25 | @Bean
26 | public TPostDao tPostDao() {
27 | return new TPostDao(dslContext.configuration());
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/jooq/jooq-demo/src/main/java/org/example/demo/jooq/model/dto/PostDTO.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.jooq.model.dto;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Builder;
5 | import lombok.Data;
6 | import lombok.experimental.Accessors;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * @author zuqin.zheng
12 | */
13 | @Data
14 | @Accessors(chain = true)
15 | public class PostDTO {
16 |
17 | private int id;
18 |
19 | private Category category;
20 |
21 | private List tags;
22 |
23 | @Data
24 | @Accessors(chain = true)
25 | public static class Category {
26 |
27 | private String name;
28 |
29 | private String desc;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/jooq/jooq-demo/src/main/java/org/example/demo/jooq/model/dto/UserDTO.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.jooq.model.dto;
2 |
3 | import lombok.Data;
4 | import lombok.experimental.Accessors;
5 |
6 | import java.time.LocalDateTime;
7 |
8 | @Data
9 | @Accessors(chain = true)
10 | public class UserDTO {
11 |
12 | private long id;
13 |
14 | private String username;
15 |
16 | private String password;
17 |
18 | private String gender;
19 |
20 | private LocalDateTime timestamp;
21 | }
22 |
--------------------------------------------------------------------------------
/jooq/jooq-demo/src/main/java/org/example/demo/jooq/service/PostService.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.jooq.service;
2 |
3 | import org.example.demo.jooq.model.dto.PostDTO;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * @author zuqin.zheng
9 | */
10 | public interface PostService {
11 |
12 | boolean savePost(PostDTO postDTO);
13 |
14 | /**
15 | * 查询 JSON 的某个字段
16 | */
17 | List getPostsByCategory(String category);
18 |
19 | boolean updateCategory(int id, String category);
20 |
21 | boolean addTag(int id, String tag);
22 | }
23 |
--------------------------------------------------------------------------------
/jooq/jooq-demo/src/main/java/org/example/demo/jooq/service/UserService.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.jooq.service;
2 |
3 | import org.example.demo.jooq.model.dto.UserDTO;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * @author zuqin.zheng
9 | */
10 | public interface UserService {
11 |
12 | /**
13 | * 处理主键冲突的情况
14 | */
15 | boolean upsert(UserDTO userDTO);
16 |
17 | UserDTO save(UserDTO userDTO);
18 |
19 | UserDTO getUserById(long id);
20 |
21 | List listById(List idList);
22 | }
23 |
--------------------------------------------------------------------------------
/jooq/jooq-demo/src/main/java/org/example/demo/jooq/utils/Jsons.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.jooq.utils;
2 |
3 | import com.fasterxml.jackson.databind.ObjectMapper;
4 | import lombok.experimental.UtilityClass;
5 |
6 | /**
7 | * @author zuqin.zheng
8 | */
9 | @UtilityClass
10 | public class Jsons {
11 |
12 | private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
13 |
14 | public String toJson(Object obj) {
15 | try {
16 | return OBJECT_MAPPER.writeValueAsString(obj);
17 | } catch (Exception e) {
18 | throw new RuntimeException("toJson error", e);
19 | }
20 | }
21 |
22 | public T parse(String s, Class clazz) {
23 | try {
24 | return OBJECT_MAPPER.readValue(s, clazz);
25 | } catch (Exception e) {
26 | throw new RuntimeException("parse error, s: " + s, e);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/jooq/jooq-demo/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | datasource:
3 | username: root
4 | password:
5 | url: jdbc:mysql://localhost:3306/demo?serverTimezone=UTC
6 | driver-class-name: com.mysql.cj.jdbc.Driver
7 |
8 | logging:
9 | level:
10 | # 开启 jooq 的 SQL
11 | org.jooq.tools.LoggerListener: DEBUG
12 |
--------------------------------------------------------------------------------
/jooq/jooq-demo/src/main/resources/db/migration/V1__create_user.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE `t_user`
2 | (
3 | `id` bigint NOT NULL AUTO_INCREMENT,
4 | `username` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
5 | `password` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
6 | `gender` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
7 | `timestamp` datetime DEFAULT NULL,
8 | PRIMARY KEY (`id`) USING BTREE
9 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC
10 |
--------------------------------------------------------------------------------
/jooq/jooq-demo/src/main/resources/db/migration/V2__create_post.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE `t_post`
2 | (
3 | `id` int NOT NULL AUTO_INCREMENT,
4 | `category` json DEFAULT NULL,
5 | `tags` json DEFAULT NULL,
6 | PRIMARY KEY (`id`)
7 | ) ENGINE = InnoDB
8 | AUTO_INCREMENT = 1
9 | DEFAULT CHARSET = utf8mb4
10 | COLLATE = utf8mb4_general_ci
11 |
--------------------------------------------------------------------------------
/jooq/jooq-demo/src/main/resources/flyway.properties:
--------------------------------------------------------------------------------
1 | flyway.url=jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT
2 | flyway.user=root
3 | flyway.password=
4 | flyway.driver=com.mysql.cj.jdbc.Driver
5 |
--------------------------------------------------------------------------------
/jooq/jooq-demo/src/test/java/org/example/demo/jooq/JooqDemoApplicationTests.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.jooq;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | class JooqDemoApplicationTests {
8 |
9 | @Test
10 | void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/message-queue/common/src/main/java/org/example/common/bean/Order.java:
--------------------------------------------------------------------------------
1 | package org.example.common.bean;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 |
6 | @Data
7 | @AllArgsConstructor
8 | public class Order {
9 |
10 | private long id;
11 |
12 | private long datetime;
13 | }
14 |
--------------------------------------------------------------------------------
/message-queue/common/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %.35logger{30} - %msg%n
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/message-queue/kafka/src/main/java/org/example/kafka/common/Constants.java:
--------------------------------------------------------------------------------
1 | package org.example.kafka.common;
2 |
3 | public interface Constants {
4 |
5 | String BROKER_SERVER_ADDRESS = "localhost:9092";
6 |
7 | String SIMPLE_TOPIC = "kafka.top.simple";
8 |
9 | String STRING_SERIALIZER = "org.apache.kafka.common.serialization.StringSerializer";
10 | }
11 |
--------------------------------------------------------------------------------
/message-queue/kafka/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level - %msg%n
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/message-queue/pulsar-springboot/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 | !**/src/main/**/target/
5 | !**/src/test/**/target/
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /nbbuild/
25 | /dist/
26 | /nbdist/
27 | /.nb-gradle/
28 | build/
29 | !**/src/main/**/build/
30 | !**/src/test/**/build/
31 |
32 | ### VS Code ###
33 | .vscode/
34 |
--------------------------------------------------------------------------------
/message-queue/pulsar-springboot/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/message-queue/pulsar-springboot/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/message-queue/pulsar-springboot/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.2/apache-maven-3.8.2-bin.zip
2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
3 |
--------------------------------------------------------------------------------
/message-queue/pulsar-springboot/src/main/java/com/example/mq/pulsar/PulsarSpringbootApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.mq.pulsar;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | import java.io.RandomAccessFile;
7 |
8 | @SpringBootApplication
9 | public class PulsarSpringbootApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(PulsarSpringbootApplication.class, args);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/message-queue/pulsar-springboot/src/main/java/com/example/mq/pulsar/common/MyMsg.java:
--------------------------------------------------------------------------------
1 | package com.example.mq.pulsar.common;
2 |
3 | public class MyMsg {
4 |
5 | private final String data;
6 |
7 | public MyMsg(String data) {
8 | this.data = data;
9 | }
10 |
11 | public String getData() {
12 | return data;
13 | }
14 |
15 | @Override
16 | public String toString() {
17 | return "MyMsg{" +
18 | "data='" + data + '\'' +
19 | '}';
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/message-queue/pulsar-springboot/src/main/java/com/example/mq/pulsar/common/PulsarConfig.java:
--------------------------------------------------------------------------------
1 | package com.example.mq.pulsar.common;
2 |
3 | import io.github.majusko.pulsar.producer.ProducerFactory;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | @Configuration
8 | public class PulsarConfig {
9 |
10 | @Bean
11 | public ProducerFactory producerFactory() {
12 | return new ProducerFactory()
13 | .addProducer("my-topic", MyMsg.class);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/message-queue/pulsar-springboot/src/main/java/com/example/mq/pulsar/consumer/MyConsumer.java:
--------------------------------------------------------------------------------
1 | package com.example.mq.pulsar.consumer;
2 |
3 | import com.example.mq.pulsar.common.MyMsg;
4 | import io.github.majusko.pulsar.annotation.PulsarConsumer;
5 | import org.springframework.stereotype.Service;
6 |
7 | @Service
8 | public class MyConsumer {
9 |
10 | @PulsarConsumer(
11 | topic = "my-topic",
12 | clazz = MyMsg.class
13 | )
14 | public void onMessage(MyMsg myMsg) {
15 | System.out.println(myMsg);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/message-queue/pulsar-springboot/src/main/java/com/example/mq/pulsar/producer/MyProducer.java:
--------------------------------------------------------------------------------
1 | package com.example.mq.pulsar.producer;
2 |
3 | import com.example.mq.pulsar.common.MyMsg;
4 | import io.github.majusko.pulsar.producer.PulsarTemplate;
5 | import org.springframework.stereotype.Service;
6 |
7 | import javax.annotation.Resource;
8 |
9 | @Service
10 | public class MyProducer {
11 |
12 | @Resource
13 | private PulsarTemplate producer;
14 |
15 | public void send() throws Exception {
16 | producer.send("my-topic", new MyMsg("Hello world!"));
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/message-queue/pulsar-springboot/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/message-queue/pulsar-springboot/src/main/resources/application.properties
--------------------------------------------------------------------------------
/message-queue/pulsar-springboot/src/test/java/com/example/mq/pulsar/PulsarSpringbootApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.example.mq.pulsar;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | class PulsarSpringbootApplicationTests {
8 |
9 | @Test
10 | void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/message-queue/pulsar/src/main/java/org/example/mq/pulsar/common/BasePulsarMain.java:
--------------------------------------------------------------------------------
1 | package org.example.mq.pulsar.common;
2 |
3 | import org.apache.pulsar.client.api.PulsarClient;
4 |
5 | public class BasePulsarMain {
6 |
7 | public static PulsarClient createSimpleClient() throws Exception {
8 | return PulsarClient.builder()
9 | .serviceUrl(Constants.BROKER_ADDRESS)
10 | .build();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/message-queue/pulsar/src/main/java/org/example/mq/pulsar/common/Constants.java:
--------------------------------------------------------------------------------
1 | package org.example.mq.pulsar.common;
2 |
3 | public interface Constants {
4 |
5 | String SIMPLE_TOPIC = "pulsar.topic.simple";
6 |
7 | String BROKER_ADDRESS = "pulsar://localhost:6650";
8 | }
9 |
--------------------------------------------------------------------------------
/message-queue/rabbitmq/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level - %msg%n
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/message-queue/rocketmq/src/main/java/org/example/rocketmq/consumer/ConsumerListener.java:
--------------------------------------------------------------------------------
1 | package org.example.rocketmq.consumer;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 |
5 | @Slf4j
6 | public class ConsumerListener {
7 | public static void main(String[] args) {
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/message-queue/rocketmq/src/main/java/org/example/rocketmq/producer/OrderService.java:
--------------------------------------------------------------------------------
1 | package org.example.rocketmq.producer;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.example.common.bean.Order;
5 | import org.example.common.utils.JsonUtils;
6 |
7 | @Slf4j
8 | public class OrderService {
9 |
10 | /**
11 | * 模拟执行本地下单, 需要支持事务.
12 | */
13 | public void placeOrder(Order order) {
14 | log.info("place order, orderNum: {}", JsonUtils.toJson(order));
15 | }
16 |
17 | /**
18 | * 模拟查单
19 | */
20 | public Order queryOrder(long orderNum) {
21 | log.info("query order, orderNum: {}", orderNum);
22 | return new Order(orderNum, System.currentTimeMillis());
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/micrometer/micrometer/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 | !**/src/main/**
5 | !**/src/test/**
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /nbbuild/
25 | /dist/
26 | /nbdist/
27 | /.nb-gradle/
28 | build/
29 |
30 | ### VS Code ###
31 | .vscode/
32 |
--------------------------------------------------------------------------------
/micrometer/micrometer/README.md:
--------------------------------------------------------------------------------
1 | # 工程简介
2 |
3 |
4 |
5 | # 延伸阅读
6 |
7 | [Spring Boot (十九):使用 Spring Boot Actuator 监控应用](http://www.ityouknow.com/springboot/2018/02/06/spring-boot-actuator.html)
8 |
--------------------------------------------------------------------------------
/micrometer/micrometer/src/main/java/com/example/micrometer/ExecutorServiceHolder.java:
--------------------------------------------------------------------------------
1 | package com.example.micrometer;
2 |
3 | import java.util.concurrent.ExecutorService;
4 | import java.util.concurrent.LinkedBlockingDeque;
5 | import java.util.concurrent.ThreadPoolExecutor;
6 | import java.util.concurrent.TimeUnit;
7 |
8 | /**
9 | * @author zuqin.zheng
10 | */
11 | public class ExecutorServiceHolder {
12 |
13 | private static final ExecutorService common;
14 |
15 | static {
16 | common = new ThreadPoolExecutor(
17 | 5,
18 | 10,
19 | 30,
20 | TimeUnit.MICROSECONDS,
21 | new LinkedBlockingDeque<>(100)
22 | );
23 | }
24 |
25 | public static ExecutorService getCommon() {
26 | return common;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/micrometer/micrometer/src/main/java/com/example/micrometer/MicrometerApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.micrometer;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class MicrometerApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(MicrometerApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/micrometer/micrometer/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: micrometer-demo
4 | profiles:
5 | active: dev
6 |
7 | management:
8 | endpoints:
9 | web:
10 | exposure:
11 | # 打开所有的监控点
12 | # 详细可暴露的名称参考: https://docs.spring.io/spring-boot/docs/current/actuator-api/htmlsingle/#overview
13 | include: "*"
14 |
15 | # 配置路径 URI 的前缀
16 | base-path: /actuator
17 |
18 | metrics:
19 | # 一些通用的 tags
20 | tags:
21 | application: ${spring.application.name}
22 | export:
23 | prometheus:
24 | enabled: true
25 | endpoint:
26 | shutdown:
27 | # 启用接口关闭 Spring Boot
28 | enabled: true
29 |
--------------------------------------------------------------------------------
/micrometer/micrometer/src/test/java/com/example/micrometer/MicrometerApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.example.micrometer;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | class MicrometerApplicationTests {
8 |
9 | @Test
10 | void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/mockito/mockito/src/main/java/org/example/demo/mockito/models/User.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.mockito.models;
2 |
3 | /**
4 | * @author zuqin.zheng
5 | */
6 | public class User {
7 |
8 | private int id;
9 |
10 | private String name;
11 |
12 | public User(int id, String name) {
13 | this.id = id;
14 | this.name = name;
15 | }
16 |
17 | public int getId() {
18 | return id;
19 | }
20 |
21 | public void setId(int id) {
22 | this.id = id;
23 | }
24 |
25 | public String getName() {
26 | return name;
27 | }
28 |
29 | public void setName(String name) {
30 | this.name = name;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/mockito/mockito/src/main/java/org/example/demo/mockito/service/UserService.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.mockito.service;
2 |
3 | import org.example.demo.mockito.models.User;
4 |
5 | /**
6 | * @author zuqin.zheng
7 | */
8 | public interface UserService {
9 |
10 | User getUserById(int id);
11 | }
12 |
--------------------------------------------------------------------------------
/mockito/mockito/src/test/java/org/example/demo/mockito/SpyTest.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.mockito;
2 |
3 | import org.junit.jupiter.api.Assertions;
4 | import org.junit.jupiter.api.Test;
5 | import org.mockito.Mockito;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | /**
11 | * @author zuqin.zheng
12 | */
13 | public class SpyTest {
14 |
15 | /**
16 | * 只代理部分的方法
17 | *
18 | * 其实没代理的方法委托给原对象
19 | */
20 | @Test
21 | public void spyArrayList() {
22 | List list = new ArrayList<>();
23 | List mockList = Mockito.spy(list);
24 |
25 | Mockito.when(mockList.size()).thenReturn(100);
26 |
27 | Assertions.assertEquals(100, mockList.size());
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/mvp-architecture/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/mvp-architecture/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/mvp-architecture/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/mvp-architecture/app/src/androidTest/java/site/pushy/mvp/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package site.pushy.mvp;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("site.pushy.mvp", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/java/site/pushy/mvp/base/BaseModel.java:
--------------------------------------------------------------------------------
1 | package site.pushy.mvp.base;
2 |
3 | import io.reactivex.Observable;
4 | import io.reactivex.android.schedulers.AndroidSchedulers;
5 | import io.reactivex.schedulers.Schedulers;
6 |
7 | public class BaseModel {
8 |
9 | protected Observable observe(Observable observable){
10 | return observable
11 | .subscribeOn(Schedulers.io())
12 | .unsubscribeOn(Schedulers.io())
13 | .observeOn(AndroidSchedulers.mainThread());
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/java/site/pushy/mvp/bean/BaseResponse.java:
--------------------------------------------------------------------------------
1 | package site.pushy.mvp.bean;
2 |
3 | public class BaseResponse {
4 |
5 | public int code;
6 |
7 | public String message;
8 |
9 | public T data;
10 |
11 | public boolean isSuccess() {
12 | return code == 200;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/java/site/pushy/mvp/bean/LoginBody.java:
--------------------------------------------------------------------------------
1 | package site.pushy.mvp.bean;
2 |
3 | public class LoginBody {
4 |
5 | public String name;
6 |
7 | public String password;
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/java/site/pushy/mvp/http/PayLoad.java:
--------------------------------------------------------------------------------
1 | package site.pushy.mvp.http;
2 |
3 | import io.reactivex.functions.Function;
4 | import site.pushy.mvp.bean.BaseResponse;
5 |
6 | public class PayLoad implements Function, BaseResponse> {
7 |
8 | private static final String TAG = "PayLoad";
9 |
10 | @Override
11 | public BaseResponse apply(BaseResponse response) throws Exception {
12 | if (!response.isSuccess()) {
13 | /* 服务器端返回errno失败 */
14 | throw new ServerException(response.code, response.message);
15 | }
16 | /* 成功获取 */
17 | return response;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/java/site/pushy/mvp/http/ServerError.java:
--------------------------------------------------------------------------------
1 | package site.pushy.mvp.http;
2 |
3 | public class ServerError {
4 |
5 | public static final int UNAUTHORIZED = 4010;
6 |
7 | public static final int NO_USER = 4041;
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/java/site/pushy/mvp/http/ServerException.java:
--------------------------------------------------------------------------------
1 | package site.pushy.mvp.http;
2 |
3 | public class ServerException extends RuntimeException {
4 |
5 | public int code;
6 |
7 | public String message;
8 |
9 | public ServerException(int code, String message) {
10 | super(message);
11 | this.code = code;
12 | this.message = message;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/java/site/pushy/mvp/login/LoginContract.java:
--------------------------------------------------------------------------------
1 | package site.pushy.mvp.login;
2 |
3 | import site.pushy.mvp.http.ServerException;
4 |
5 | public class LoginContract {
6 |
7 | interface View {
8 |
9 | void setLoading(boolean v);
10 |
11 | void callback(boolean v);
12 |
13 | void errorCallback(ServerException e);
14 |
15 | }
16 |
17 | interface Presenter {
18 |
19 | void login(String name, String password);
20 |
21 | }
22 |
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
16 |
17 |
23 |
24 |
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/mvp-architecture/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/mvp-architecture/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/mvp-architecture/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/mvp-architecture/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/mvp-architecture/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/mvp-architecture/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/mvp-architecture/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/mvp-architecture/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/mvp-architecture/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/mvp-architecture/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Demo MVP Architecture
3 |
4 |
--------------------------------------------------------------------------------
/mvp-architecture/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/mvp-architecture/app/src/test/java/site/pushy/mvp/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package site.pushy.mvp;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/mvp-architecture/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.2'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/mvp-architecture/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/mvp-architecture/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/mvp-architecture/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/mvp-architecture/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Oct 25 16:15:21 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/mvp-architecture/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/netty-http/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.example
8 | netty-http-demo
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 |
14 | io.netty
15 | netty-all
16 | 4.1.31.Final
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/netty-http/src/main/java/com/example/TestHandler.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import io.netty.channel.ChannelHandlerContext;
4 | import io.netty.channel.ChannelInboundHandlerAdapter;
5 |
6 | /**
7 | * @author Pushy
8 | * @since 2018/11/6 20:29
9 | */
10 | public class TestHandler extends ChannelInboundHandlerAdapter {
11 |
12 | @Override
13 | public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
14 | System.out.println("ChannelRead::" + msg);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/netty-protobuf/pushy.dt:
--------------------------------------------------------------------------------
1 | Pushy1437876073@qq.com
--------------------------------------------------------------------------------
/netty-protobuf/src/main/java/site/pushy/protobuf/basic/CreatePerson.java:
--------------------------------------------------------------------------------
1 | package site.pushy.protobuf.basic;
2 |
3 | import site.pushy.protobuf.PersonEntity;
4 |
5 | /**
6 | * @author Pushy
7 | * @since 2018/11/18 19:16
8 | */
9 | public class CreatePerson {
10 |
11 | public static PersonEntity.Person create() {
12 | PersonEntity.Person person = PersonEntity.Person.newBuilder()
13 | .setId(1)
14 | .setName("Pushy")
15 | .setEmail("1437876073@qq.com")
16 | .build();
17 | //System.out.println(person);
18 | return person;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/netty-protobuf/src/main/java/site/pushy/protobuf/handler/ClientHandler.java:
--------------------------------------------------------------------------------
1 | package site.pushy.protobuf.handler;
2 |
3 | import io.netty.channel.ChannelHandlerContext;
4 | import io.netty.channel.ChannelInboundHandlerAdapter;
5 | import io.netty.channel.ChannelOutboundHandlerAdapter;
6 | import io.netty.channel.SimpleChannelInboundHandler;
7 | import site.pushy.protobuf.PersonEntity;
8 |
9 | /**
10 | * @author Pushy
11 | * @since 2018/11/17 19:54
12 | */
13 | public class ClientHandler extends ChannelInboundHandlerAdapter {
14 |
15 | @Override
16 | public void channelActive(ChannelHandlerContext ctx) throws Exception {
17 | ctx.writeAndFlush(getPerson());
18 | }
19 |
20 | private PersonEntity.Person getPerson() {
21 | return PersonEntity.Person.newBuilder()
22 | .setName("Pushy")
23 | .setEmail("1437876073@qq.com")
24 | .build();
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/netty-protobuf/src/main/java/site/pushy/protobuf/handler/ServerHandler.java:
--------------------------------------------------------------------------------
1 | package site.pushy.protobuf.handler;
2 |
3 | import io.netty.channel.ChannelHandlerContext;
4 | import io.netty.channel.SimpleChannelInboundHandler;
5 | import site.pushy.protobuf.PersonEntity;
6 |
7 | /**
8 | * @author Pushy
9 | * @since 2018/11/17 19:51
10 | */
11 | public class ServerHandler extends SimpleChannelInboundHandler {
12 |
13 | @Override
14 | protected void channelRead0(ChannelHandlerContext ctx, PersonEntity.Person person) throws Exception {
15 | System.out.println("chanelRead0 =>" + person.getName() );
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/netty-protobuf/src/main/resources/command.bat:
--------------------------------------------------------------------------------
1 | protoc -I=E:\Java\Netty\sample\NettyProtobuf --java_out=E:\Java\Netty\sample\NettyProtobuf\src\main\java E:\Java\Netty\sample\NettyProtobuf\src\main\resources\person.proto
2 |
--------------------------------------------------------------------------------
/netty-protobuf/src/main/resources/person.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | option java_package = "site.pushy.protobuf"; // 指定包名
3 | option java_outer_classname = "PersonEntity"; //生成的数据访问类的类名
4 | message Person {
5 | int32 id = 1; //同上
6 | string name = 2; //必须字段,在后面的使用中必须为该段设置值
7 | string email = 3; //可选字段,在后面的使用中可以自由决定是否为该字段设置值
8 | }
--------------------------------------------------------------------------------
/netty-session/src/main/java/com/example/session/HttpSession.java:
--------------------------------------------------------------------------------
1 | package com.example.session;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | /**
7 | * @author Pushy
8 | * @since 2019/3/19 20:37
9 | */
10 | public class HttpSession {
11 |
12 | private String id;
13 |
14 | private Map attributes = new HashMap<>();
15 |
16 | public HttpSession(String id) {
17 | this.id = id;
18 | }
19 |
20 | public Object getAttribute(String name) {
21 | return attributes.get(name);
22 | }
23 |
24 | public void addAttribute(String name, Object value) {
25 | attributes.put(name, value);
26 | }
27 |
28 | public String getId() {
29 | return id;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/netty-start/src/main/java/com/exmaple/handler/EchoChannelHandler.java:
--------------------------------------------------------------------------------
1 | package com.exmaple.handler;
2 |
3 | import io.netty.channel.ChannelHandlerAdapter;
4 | import io.netty.channel.ChannelHandlerContext;
5 | import io.netty.channel.ChannelInboundHandlerAdapter;
6 | import io.netty.channel.ChannelOutboundHandlerAdapter;
7 |
8 | /**
9 | * @author Pushy
10 | * @since 2018/11/9 19:30
11 | */
12 | public class EchoChannelHandler extends ChannelHandlerAdapter {
13 |
14 | @Override
15 | public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
16 | System.out.println("EchoChannelHandler received => " + msg);
17 | ctx.fireChannelRead(msg);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/netty-start/src/main/java/com/exmaple/handler/HttpChannelHandler.java:
--------------------------------------------------------------------------------
1 | package com.exmaple.handler;
2 |
3 | import io.netty.buffer.Unpooled;
4 | import io.netty.channel.ChannelHandlerContext;
5 | import io.netty.channel.SimpleChannelInboundHandler;
6 | import io.netty.handler.codec.http.FullHttpRequest;
7 | import io.netty.util.CharsetUtil;
8 |
9 | /**
10 | * @author Pushy
11 | * @since 2018/11/9 19:39
12 | */
13 | public class HttpChannelHandler extends SimpleChannelInboundHandler {
14 |
15 | @Override
16 | protected void messageReceived(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception {
17 | System.out.println("HttpChannelHandler Request =>" + msg.uri() + msg.method());
18 |
19 | ctx.writeAndFlush(Unpooled.copiedBuffer("hello", CharsetUtil.UTF_8));
20 |
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/netty-start/src/main/java/com/exmaple/pool/ServerHandler.java:
--------------------------------------------------------------------------------
1 | package com.exmaple.pool;
2 |
3 | import java.io.IOException;
4 | import java.io.OutputStream;
5 | import java.io.PrintStream;
6 | import java.net.Socket;
7 |
8 | /**
9 | * @author Pushy
10 | * @since 2018/11/8 20:23
11 | */
12 | public class ServerHandler {
13 |
14 | public static void handlerRequest(Socket client) throws IOException, InterruptedException {
15 | System.out.println("Handle the client => " + client.getRemoteSocketAddress());
16 |
17 | OutputStream os = client.getOutputStream();
18 | PrintStream out = new PrintStream(os);
19 |
20 | /* 模拟耗时的IO操作 */
21 | Thread.sleep(2000);
22 |
23 | System.out.println("Send data to client");
24 |
25 | out.println("Hello World");
26 | out.flush();
27 | }
28 |
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/netty-start/src/main/java/com/exmaple/socket/SocketServer.java:
--------------------------------------------------------------------------------
1 | package com.exmaple.socket;
2 |
3 | import java.io.IOException;
4 | import java.net.ServerSocket;
5 | import java.net.Socket;
6 |
7 | /**
8 | * @author Pushy
9 | * @since 2018/11/8 20:16
10 | */
11 | public class SocketServer {
12 |
13 | public static void main(String[] args) {
14 | try {
15 | ServerSocket serverSocket = new ServerSocket(8080);
16 | while (true) {
17 | Socket socket = serverSocket.accept();
18 | // 创建新的线程处理客户端连接
19 | new ServerSockThread(socket).start();
20 | }
21 | } catch (IOException e) {
22 | e.printStackTrace();
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/netty-start/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %.35logger{30} - %msg%n
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/netty-websocket/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.example
8 | netty-websocket
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 | io.netty
14 | netty-all
15 | 4.1.31.Final
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/netty/common/src/main/java/org/example/netty/common/utils/NettyUtils.java:
--------------------------------------------------------------------------------
1 | package org.example.netty.common.utils;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import io.netty.buffer.Unpooled;
5 | import io.netty.util.CharsetUtil;
6 | import lombok.experimental.UtilityClass;
7 |
8 | @UtilityClass
9 | public class NettyUtils {
10 |
11 | public String toString(ByteBuf byteBuf) {
12 | return byteBuf.toString(CharsetUtil.UTF_8);
13 | }
14 |
15 | public ByteBuf toByteBuf(String s) {
16 | return Unpooled.copiedBuffer(s, CharsetUtil.UTF_8);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/netty/common/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %.35logger{30} - %msg%n
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/protobuf/README.md:
--------------------------------------------------------------------------------
1 | # protobuf
2 |
3 | 执行:
4 |
5 | ```shell
6 | $ mvn clean compile
7 | ```
8 |
9 | 就能在 *target/classes/org/example/demo/protobuf* 中找到生成的文件了
10 |
11 | 
12 |
--------------------------------------------------------------------------------
/protobuf/images/img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pushyzheng/demo/738be4b2a320515c3dca0e6b1c83b644365690aa/protobuf/images/img.png
--------------------------------------------------------------------------------
/protobuf/src/main/java/org/example/demo/protobuf/Main.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.protobuf;
2 |
3 | public class Main {
4 | public static void main(String[] args) {
5 |
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/protobuf/src/main/java/org/example/demo/protobuf/ProtobufFileStream.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.protobuf;
2 |
3 | import java.io.FileOutputStream;
4 |
5 | /**
6 | * 将 Person 写入到文件中
7 | */
8 | public class ProtobufFileStream {
9 | public static void main(String[] args) throws Exception {
10 | Person person = Person.newBuilder()
11 | .setId(1)
12 | .setName("Mark Miller")
13 | .setEmail("aaronlong@gmail.com")
14 | .build();
15 |
16 | FileOutputStream fos = new FileOutputStream("person.dt");
17 | person.writeTo(fos);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/protobuf/src/main/proto/person.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | package org.example.demo.protobuf;
4 |
5 | option java_package = "org.example.demo.protobuf"; // 指定包名
6 | option java_outer_classname = "PersonProto";
7 | option java_multiple_files = true; // 将会生成多个文件
8 |
9 | message Person {
10 | int32 id = 1;
11 | string name = 2;
12 | string email = 3;
13 | LanguageType motherTongue = 4;
14 |
15 | enum LanguageType {
16 | ENGLISH = 0;
17 | CHINESE = 1;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/redis-distributed-lock/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.example
8 | redis-distributed-lock
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 | redis.clients
14 | jedis
15 | 2.9.0
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/redis-distributed-lock/src/main/java/com/example/redislock/jdk/ReentrantLockSingleton.java:
--------------------------------------------------------------------------------
1 | package com.example.redislock.jdk;
2 |
3 | import java.util.concurrent.locks.ReentrantLock;
4 |
5 | /**
6 | * @author Pushy
7 | * @since 2018/12/12 14:40
8 | */
9 | public class ReentrantLockSingleton {
10 |
11 | private ReentrantLock reentrantLock = new ReentrantLock();
12 | private ReentrantLockSingleton INSTANCE;
13 |
14 | public ReentrantLockSingleton getINSTANCE() {
15 | if (INSTANCE == null) {
16 | reentrantLock.lock();
17 | if (INSTANCE == null) {
18 | return new ReentrantLockSingleton();
19 | }
20 | reentrantLock.unlock();
21 | }
22 | return INSTANCE;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/redis-distributed-lock/src/main/java/com/example/redislock/jdk/SynchronizedLock.java:
--------------------------------------------------------------------------------
1 | package com.example.redislock.jdk;
2 |
3 | /**
4 | * @author Pushy
5 | * @since 2018/12/12 14:23
6 | */
7 | public class SynchronizedLock {
8 |
9 | private static SynchronizedLock INSTANCE;
10 |
11 | public static SynchronizedLock getINSTANCE() {
12 | if (INSTANCE == null) {
13 | synchronized (SynchronizedLock.class) {
14 | if (INSTANCE == null) {
15 | return new SynchronizedLock();
16 | }
17 | }
18 | }
19 | return INSTANCE;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/redisson/src/main/java/org/example/demo/redisson/Times.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.redisson;
2 |
3 | import lombok.experimental.UtilityClass;
4 |
5 | import java.util.concurrent.TimeUnit;
6 |
7 | @UtilityClass
8 | public class Times {
9 |
10 | public void sleepSeconds(int s) {
11 | sleep(s * 1000);
12 | }
13 |
14 | public void sleep(int ms) {
15 | try {
16 | TimeUnit.MILLISECONDS.sleep(ms);
17 | } catch (InterruptedException e) {
18 | Thread.currentThread().interrupt();
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/redisson/src/main/java/org/example/demo/redisson/map/RMapCacheExample.java:
--------------------------------------------------------------------------------
1 | package org.example.demo.redisson.map;
2 |
3 | import org.example.demo.redisson.Redissons;
4 | import org.redisson.api.RMapCache;
5 |
6 | import java.util.concurrent.TimeUnit;
7 |
8 | /**
9 | * 让 field 具备驱逐的能力
10 | */
11 | public class RMapCacheExample {
12 |
13 | public static void main(String[] args) {
14 | Redissons.executeThenDestroy(client -> {
15 | RMapCache