diff --git a/version5/.idea/.gitignore b/.idea/.gitignore
similarity index 100%
rename from version5/.idea/.gitignore
rename to .idea/.gitignore
diff --git a/.idea/RPC-Java-F.iml b/.idea/RPC-Java-F.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/.idea/RPC-Java-F.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..12548f5
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..0cc3557
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..6f31448
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..cfdc549
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..89ab409
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/consumer/.gitattributes b/consumer/.gitattributes
new file mode 100644
index 0000000..3b41682
--- /dev/null
+++ b/consumer/.gitattributes
@@ -0,0 +1,2 @@
+/mvnw text eol=lf
+*.cmd text eol=crlf
diff --git a/consumer/.gitignore b/consumer/.gitignore
new file mode 100644
index 0000000..549e00a
--- /dev/null
+++ b/consumer/.gitignore
@@ -0,0 +1,33 @@
+HELP.md
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
diff --git a/consumer/.mvn/wrapper/maven-wrapper.properties b/consumer/.mvn/wrapper/maven-wrapper.properties
new file mode 100644
index 0000000..d58dfb7
--- /dev/null
+++ b/consumer/.mvn/wrapper/maven-wrapper.properties
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+wrapperVersion=3.3.2
+distributionType=only-script
+distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
diff --git a/consumer/mvnw b/consumer/mvnw
new file mode 100644
index 0000000..19529dd
--- /dev/null
+++ b/consumer/mvnw
@@ -0,0 +1,259 @@
+#!/bin/sh
+# ----------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ----------------------------------------------------------------------------
+
+# ----------------------------------------------------------------------------
+# Apache Maven Wrapper startup batch script, version 3.3.2
+#
+# Optional ENV vars
+# -----------------
+# JAVA_HOME - location of a JDK home dir, required when download maven via java source
+# MVNW_REPOURL - repo url base for downloading maven distribution
+# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
+# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
+# ----------------------------------------------------------------------------
+
+set -euf
+[ "${MVNW_VERBOSE-}" != debug ] || set -x
+
+# OS specific support.
+native_path() { printf %s\\n "$1"; }
+case "$(uname)" in
+CYGWIN* | MINGW*)
+ [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
+ native_path() { cygpath --path --windows "$1"; }
+ ;;
+esac
+
+# set JAVACMD and JAVACCMD
+set_java_home() {
+ # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
+ if [ -n "${JAVA_HOME-}" ]; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ]; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ JAVACCMD="$JAVA_HOME/jre/sh/javac"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ JAVACCMD="$JAVA_HOME/bin/javac"
+
+ if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
+ echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
+ echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
+ return 1
+ fi
+ fi
+ else
+ JAVACMD="$(
+ 'set' +e
+ 'unset' -f command 2>/dev/null
+ 'command' -v java
+ )" || :
+ JAVACCMD="$(
+ 'set' +e
+ 'unset' -f command 2>/dev/null
+ 'command' -v javac
+ )" || :
+
+ if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
+ echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
+ return 1
+ fi
+ fi
+}
+
+# hash string like Java String::hashCode
+hash_string() {
+ str="${1:-}" h=0
+ while [ -n "$str" ]; do
+ char="${str%"${str#?}"}"
+ h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
+ str="${str#?}"
+ done
+ printf %x\\n $h
+}
+
+verbose() { :; }
+[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
+
+die() {
+ printf %s\\n "$1" >&2
+ exit 1
+}
+
+trim() {
+ # MWRAPPER-139:
+ # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
+ # Needed for removing poorly interpreted newline sequences when running in more
+ # exotic environments such as mingw bash on Windows.
+ printf "%s" "${1}" | tr -d '[:space:]'
+}
+
+# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
+while IFS="=" read -r key value; do
+ case "${key-}" in
+ distributionUrl) distributionUrl=$(trim "${value-}") ;;
+ distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
+ esac
+done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties"
+[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties"
+
+case "${distributionUrl##*/}" in
+maven-mvnd-*bin.*)
+ MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
+ case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
+ *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
+ :Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
+ :Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
+ :Linux*x86_64*) distributionPlatform=linux-amd64 ;;
+ *)
+ echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
+ distributionPlatform=linux-amd64
+ ;;
+ esac
+ distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
+ ;;
+maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
+*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
+esac
+
+# apply MVNW_REPOURL and calculate MAVEN_HOME
+# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/
+[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
+distributionUrlName="${distributionUrl##*/}"
+distributionUrlNameMain="${distributionUrlName%.*}"
+distributionUrlNameMain="${distributionUrlNameMain%-bin}"
+MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
+MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
+
+exec_maven() {
+ unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
+ exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
+}
+
+if [ -d "$MAVEN_HOME" ]; then
+ verbose "found existing MAVEN_HOME at $MAVEN_HOME"
+ exec_maven "$@"
+fi
+
+case "${distributionUrl-}" in
+*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
+*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
+esac
+
+# prepare tmp dir
+if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
+ clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
+ trap clean HUP INT TERM EXIT
+else
+ die "cannot create temp dir"
+fi
+
+mkdir -p -- "${MAVEN_HOME%/*}"
+
+# Download and Install Apache Maven
+verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
+verbose "Downloading from: $distributionUrl"
+verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
+
+# select .zip or .tar.gz
+if ! command -v unzip >/dev/null; then
+ distributionUrl="${distributionUrl%.zip}.tar.gz"
+ distributionUrlName="${distributionUrl##*/}"
+fi
+
+# verbose opt
+__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
+[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
+
+# normalize http auth
+case "${MVNW_PASSWORD:+has-password}" in
+'') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
+has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
+esac
+
+if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
+ verbose "Found wget ... using wget"
+ wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
+elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
+ verbose "Found curl ... using curl"
+ curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
+elif set_java_home; then
+ verbose "Falling back to use Java to download"
+ javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
+ targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
+ cat >"$javaSource" <<-END
+ public class Downloader extends java.net.Authenticator
+ {
+ protected java.net.PasswordAuthentication getPasswordAuthentication()
+ {
+ return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
+ }
+ public static void main( String[] args ) throws Exception
+ {
+ setDefault( new Downloader() );
+ java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
+ }
+ }
+ END
+ # For Cygwin/MinGW, switch paths to Windows format before running javac and java
+ verbose " - Compiling Downloader.java ..."
+ "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
+ verbose " - Running Downloader.java ..."
+ "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
+fi
+
+# If specified, validate the SHA-256 sum of the Maven distribution zip file
+if [ -n "${distributionSha256Sum-}" ]; then
+ distributionSha256Result=false
+ if [ "$MVN_CMD" = mvnd.sh ]; then
+ echo "Checksum validation is not supported for maven-mvnd." >&2
+ echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
+ exit 1
+ elif command -v sha256sum >/dev/null; then
+ if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then
+ distributionSha256Result=true
+ fi
+ elif command -v shasum >/dev/null; then
+ if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
+ distributionSha256Result=true
+ fi
+ else
+ echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
+ echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
+ exit 1
+ fi
+ if [ $distributionSha256Result = false ]; then
+ echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
+ echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
+ exit 1
+ fi
+fi
+
+# unzip and move
+if command -v unzip >/dev/null; then
+ unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
+else
+ tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
+fi
+printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url"
+mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
+
+clean || :
+exec_maven "$@"
diff --git a/consumer/mvnw.cmd b/consumer/mvnw.cmd
new file mode 100644
index 0000000..249bdf3
--- /dev/null
+++ b/consumer/mvnw.cmd
@@ -0,0 +1,149 @@
+<# : batch portion
+@REM ----------------------------------------------------------------------------
+@REM Licensed to the Apache Software Foundation (ASF) under one
+@REM or more contributor license agreements. See the NOTICE file
+@REM distributed with this work for additional information
+@REM regarding copyright ownership. The ASF licenses this file
+@REM to you under the Apache License, Version 2.0 (the
+@REM "License"); you may not use this file except in compliance
+@REM with the License. You may obtain a copy of the License at
+@REM
+@REM http://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing,
+@REM software distributed under the License is distributed on an
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@REM KIND, either express or implied. See the License for the
+@REM specific language governing permissions and limitations
+@REM under the License.
+@REM ----------------------------------------------------------------------------
+
+@REM ----------------------------------------------------------------------------
+@REM Apache Maven Wrapper startup batch script, version 3.3.2
+@REM
+@REM Optional ENV vars
+@REM MVNW_REPOURL - repo url base for downloading maven distribution
+@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
+@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
+@REM ----------------------------------------------------------------------------
+
+@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
+@SET __MVNW_CMD__=
+@SET __MVNW_ERROR__=
+@SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
+@SET PSModulePath=
+@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
+ IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
+)
+@SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
+@SET __MVNW_PSMODULEP_SAVE=
+@SET __MVNW_ARG0_NAME__=
+@SET MVNW_USERNAME=
+@SET MVNW_PASSWORD=
+@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*)
+@echo Cannot start maven from wrapper >&2 && exit /b 1
+@GOTO :EOF
+: end batch / begin powershell #>
+
+$ErrorActionPreference = "Stop"
+if ($env:MVNW_VERBOSE -eq "true") {
+ $VerbosePreference = "Continue"
+}
+
+# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
+$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
+if (!$distributionUrl) {
+ Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
+}
+
+switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
+ "maven-mvnd-*" {
+ $USE_MVND = $true
+ $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
+ $MVN_CMD = "mvnd.cmd"
+ break
+ }
+ default {
+ $USE_MVND = $false
+ $MVN_CMD = $script -replace '^mvnw','mvn'
+ break
+ }
+}
+
+# apply MVNW_REPOURL and calculate MAVEN_HOME
+# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/
+if ($env:MVNW_REPOURL) {
+ $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" }
+ $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')"
+}
+$distributionUrlName = $distributionUrl -replace '^.*/',''
+$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
+$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
+if ($env:MAVEN_USER_HOME) {
+ $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain"
+}
+$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
+$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
+
+if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
+ Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
+ Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
+ exit $?
+}
+
+if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
+ Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
+}
+
+# prepare tmp dir
+$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
+$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
+$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
+trap {
+ if ($TMP_DOWNLOAD_DIR.Exists) {
+ try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
+ catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
+ }
+}
+
+New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
+
+# Download and Install Apache Maven
+Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
+Write-Verbose "Downloading from: $distributionUrl"
+Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
+
+$webclient = New-Object System.Net.WebClient
+if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
+ $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
+}
+[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
+$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
+
+# If specified, validate the SHA-256 sum of the Maven distribution zip file
+$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
+if ($distributionSha256Sum) {
+ if ($USE_MVND) {
+ Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
+ }
+ Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
+ if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
+ Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
+ }
+}
+
+# unzip and move
+Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
+Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null
+try {
+ Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
+} catch {
+ if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
+ Write-Error "fail to move MAVEN_HOME"
+ }
+} finally {
+ try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
+ catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
+}
+
+Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
diff --git a/consumer/pom.xml b/consumer/pom.xml
new file mode 100644
index 0000000..47ad3d7
--- /dev/null
+++ b/consumer/pom.xml
@@ -0,0 +1,95 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.0.0.RELEASE
+
+
+ com.example
+ consumer
+ 0.0.1-SNAPSHOT
+ consumer
+ consumer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 8
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-devtools
+ runtime
+ true
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.example
+ publicInterface
+ 1.0-SNAPSHOT
+
+
+
+ org.example
+ version4
+ 1.0-SNAPSHOT
+ compile
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+ org.projectlombok
+ lombok
+ provided
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 8
+ 8
+
+
+
+
+
+
diff --git a/consumer/src/main/java/com/example/consumer/ConsumerApplication.java b/consumer/src/main/java/com/example/consumer/ConsumerApplication.java
new file mode 100644
index 0000000..b4a0459
--- /dev/null
+++ b/consumer/src/main/java/com/example/consumer/ConsumerApplication.java
@@ -0,0 +1,17 @@
+package com.example.consumer;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ComponentScan;
+import part1.Server.integration.EnableConsumer;
+
+@SpringBootApplication
+@EnableConsumer
+//@ComponentScan(basePackages = {"com.example.consumer.web.controller"})
+public class ConsumerApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(ConsumerApplication.class, args);
+ }
+
+}
diff --git a/consumer/src/main/java/com/example/consumer/web/controller/testController.java b/consumer/src/main/java/com/example/consumer/web/controller/testController.java
new file mode 100644
index 0000000..d64e1c0
--- /dev/null
+++ b/consumer/src/main/java/com/example/consumer/web/controller/testController.java
@@ -0,0 +1,44 @@
+package com.example.consumer.web.controller;
+
+import com.publicInterface.dto.User;
+import com.publicInterface.service.UserService;
+import lombok.extern.slf4j.Slf4j;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import part1.Server.integration.References;
+
+/**
+ * @Author: yty
+ * @Description: TODO
+ * @DateTime: 2024/11/08 15:53
+ **/
+@RestController
+@RequestMapping("/api/consumer/test")
+public class testController {
+
+ Logger log = LoggerFactory.getLogger(testController.class);
+
+ @References(version = "1.2")
+ private UserService userService2;
+
+ @References(version = "1.1")
+ private UserService userService1;
+
+ @GetMapping(value = "/test1")
+ public User page1() {
+ User user = userService1.getUserByUserId(1);
+ log.info(user.toString());
+ return user;
+ }
+
+ @GetMapping(value = "/test2")
+ public User page2() {
+ User user = userService2.getUserByUserId(2);
+ log.info(user.toString());
+ return user;
+ }
+}
diff --git a/consumer/src/main/resources/application.properties b/consumer/src/main/resources/application.properties
new file mode 100644
index 0000000..d11eead
--- /dev/null
+++ b/consumer/src/main/resources/application.properties
@@ -0,0 +1,3 @@
+spring.application.name=consumer
+server.port=9091
+spring.web.resources.static-locations=[]
diff --git a/provider/.gitattributes b/provider/.gitattributes
new file mode 100644
index 0000000..3b41682
--- /dev/null
+++ b/provider/.gitattributes
@@ -0,0 +1,2 @@
+/mvnw text eol=lf
+*.cmd text eol=crlf
diff --git a/provider/.gitignore b/provider/.gitignore
new file mode 100644
index 0000000..549e00a
--- /dev/null
+++ b/provider/.gitignore
@@ -0,0 +1,33 @@
+HELP.md
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
diff --git a/provider/.mvn/wrapper/maven-wrapper.properties b/provider/.mvn/wrapper/maven-wrapper.properties
new file mode 100644
index 0000000..d58dfb7
--- /dev/null
+++ b/provider/.mvn/wrapper/maven-wrapper.properties
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+wrapperVersion=3.3.2
+distributionType=only-script
+distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
diff --git a/provider/mvnw b/provider/mvnw
new file mode 100644
index 0000000..19529dd
--- /dev/null
+++ b/provider/mvnw
@@ -0,0 +1,259 @@
+#!/bin/sh
+# ----------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ----------------------------------------------------------------------------
+
+# ----------------------------------------------------------------------------
+# Apache Maven Wrapper startup batch script, version 3.3.2
+#
+# Optional ENV vars
+# -----------------
+# JAVA_HOME - location of a JDK home dir, required when download maven via java source
+# MVNW_REPOURL - repo url base for downloading maven distribution
+# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
+# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
+# ----------------------------------------------------------------------------
+
+set -euf
+[ "${MVNW_VERBOSE-}" != debug ] || set -x
+
+# OS specific support.
+native_path() { printf %s\\n "$1"; }
+case "$(uname)" in
+CYGWIN* | MINGW*)
+ [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
+ native_path() { cygpath --path --windows "$1"; }
+ ;;
+esac
+
+# set JAVACMD and JAVACCMD
+set_java_home() {
+ # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
+ if [ -n "${JAVA_HOME-}" ]; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ]; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ JAVACCMD="$JAVA_HOME/jre/sh/javac"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ JAVACCMD="$JAVA_HOME/bin/javac"
+
+ if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
+ echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
+ echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
+ return 1
+ fi
+ fi
+ else
+ JAVACMD="$(
+ 'set' +e
+ 'unset' -f command 2>/dev/null
+ 'command' -v java
+ )" || :
+ JAVACCMD="$(
+ 'set' +e
+ 'unset' -f command 2>/dev/null
+ 'command' -v javac
+ )" || :
+
+ if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
+ echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
+ return 1
+ fi
+ fi
+}
+
+# hash string like Java String::hashCode
+hash_string() {
+ str="${1:-}" h=0
+ while [ -n "$str" ]; do
+ char="${str%"${str#?}"}"
+ h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
+ str="${str#?}"
+ done
+ printf %x\\n $h
+}
+
+verbose() { :; }
+[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
+
+die() {
+ printf %s\\n "$1" >&2
+ exit 1
+}
+
+trim() {
+ # MWRAPPER-139:
+ # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
+ # Needed for removing poorly interpreted newline sequences when running in more
+ # exotic environments such as mingw bash on Windows.
+ printf "%s" "${1}" | tr -d '[:space:]'
+}
+
+# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
+while IFS="=" read -r key value; do
+ case "${key-}" in
+ distributionUrl) distributionUrl=$(trim "${value-}") ;;
+ distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
+ esac
+done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties"
+[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties"
+
+case "${distributionUrl##*/}" in
+maven-mvnd-*bin.*)
+ MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
+ case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
+ *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
+ :Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
+ :Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
+ :Linux*x86_64*) distributionPlatform=linux-amd64 ;;
+ *)
+ echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
+ distributionPlatform=linux-amd64
+ ;;
+ esac
+ distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
+ ;;
+maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
+*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
+esac
+
+# apply MVNW_REPOURL and calculate MAVEN_HOME
+# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/
+[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
+distributionUrlName="${distributionUrl##*/}"
+distributionUrlNameMain="${distributionUrlName%.*}"
+distributionUrlNameMain="${distributionUrlNameMain%-bin}"
+MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
+MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
+
+exec_maven() {
+ unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
+ exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
+}
+
+if [ -d "$MAVEN_HOME" ]; then
+ verbose "found existing MAVEN_HOME at $MAVEN_HOME"
+ exec_maven "$@"
+fi
+
+case "${distributionUrl-}" in
+*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
+*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
+esac
+
+# prepare tmp dir
+if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
+ clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
+ trap clean HUP INT TERM EXIT
+else
+ die "cannot create temp dir"
+fi
+
+mkdir -p -- "${MAVEN_HOME%/*}"
+
+# Download and Install Apache Maven
+verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
+verbose "Downloading from: $distributionUrl"
+verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
+
+# select .zip or .tar.gz
+if ! command -v unzip >/dev/null; then
+ distributionUrl="${distributionUrl%.zip}.tar.gz"
+ distributionUrlName="${distributionUrl##*/}"
+fi
+
+# verbose opt
+__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
+[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
+
+# normalize http auth
+case "${MVNW_PASSWORD:+has-password}" in
+'') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
+has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
+esac
+
+if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
+ verbose "Found wget ... using wget"
+ wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
+elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
+ verbose "Found curl ... using curl"
+ curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
+elif set_java_home; then
+ verbose "Falling back to use Java to download"
+ javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
+ targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
+ cat >"$javaSource" <<-END
+ public class Downloader extends java.net.Authenticator
+ {
+ protected java.net.PasswordAuthentication getPasswordAuthentication()
+ {
+ return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
+ }
+ public static void main( String[] args ) throws Exception
+ {
+ setDefault( new Downloader() );
+ java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
+ }
+ }
+ END
+ # For Cygwin/MinGW, switch paths to Windows format before running javac and java
+ verbose " - Compiling Downloader.java ..."
+ "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
+ verbose " - Running Downloader.java ..."
+ "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
+fi
+
+# If specified, validate the SHA-256 sum of the Maven distribution zip file
+if [ -n "${distributionSha256Sum-}" ]; then
+ distributionSha256Result=false
+ if [ "$MVN_CMD" = mvnd.sh ]; then
+ echo "Checksum validation is not supported for maven-mvnd." >&2
+ echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
+ exit 1
+ elif command -v sha256sum >/dev/null; then
+ if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then
+ distributionSha256Result=true
+ fi
+ elif command -v shasum >/dev/null; then
+ if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
+ distributionSha256Result=true
+ fi
+ else
+ echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
+ echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
+ exit 1
+ fi
+ if [ $distributionSha256Result = false ]; then
+ echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
+ echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
+ exit 1
+ fi
+fi
+
+# unzip and move
+if command -v unzip >/dev/null; then
+ unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
+else
+ tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
+fi
+printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url"
+mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
+
+clean || :
+exec_maven "$@"
diff --git a/provider/mvnw.cmd b/provider/mvnw.cmd
new file mode 100644
index 0000000..249bdf3
--- /dev/null
+++ b/provider/mvnw.cmd
@@ -0,0 +1,149 @@
+<# : batch portion
+@REM ----------------------------------------------------------------------------
+@REM Licensed to the Apache Software Foundation (ASF) under one
+@REM or more contributor license agreements. See the NOTICE file
+@REM distributed with this work for additional information
+@REM regarding copyright ownership. The ASF licenses this file
+@REM to you under the Apache License, Version 2.0 (the
+@REM "License"); you may not use this file except in compliance
+@REM with the License. You may obtain a copy of the License at
+@REM
+@REM http://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing,
+@REM software distributed under the License is distributed on an
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@REM KIND, either express or implied. See the License for the
+@REM specific language governing permissions and limitations
+@REM under the License.
+@REM ----------------------------------------------------------------------------
+
+@REM ----------------------------------------------------------------------------
+@REM Apache Maven Wrapper startup batch script, version 3.3.2
+@REM
+@REM Optional ENV vars
+@REM MVNW_REPOURL - repo url base for downloading maven distribution
+@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
+@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
+@REM ----------------------------------------------------------------------------
+
+@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
+@SET __MVNW_CMD__=
+@SET __MVNW_ERROR__=
+@SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
+@SET PSModulePath=
+@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
+ IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
+)
+@SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
+@SET __MVNW_PSMODULEP_SAVE=
+@SET __MVNW_ARG0_NAME__=
+@SET MVNW_USERNAME=
+@SET MVNW_PASSWORD=
+@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*)
+@echo Cannot start maven from wrapper >&2 && exit /b 1
+@GOTO :EOF
+: end batch / begin powershell #>
+
+$ErrorActionPreference = "Stop"
+if ($env:MVNW_VERBOSE -eq "true") {
+ $VerbosePreference = "Continue"
+}
+
+# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
+$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
+if (!$distributionUrl) {
+ Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
+}
+
+switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
+ "maven-mvnd-*" {
+ $USE_MVND = $true
+ $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
+ $MVN_CMD = "mvnd.cmd"
+ break
+ }
+ default {
+ $USE_MVND = $false
+ $MVN_CMD = $script -replace '^mvnw','mvn'
+ break
+ }
+}
+
+# apply MVNW_REPOURL and calculate MAVEN_HOME
+# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/
+if ($env:MVNW_REPOURL) {
+ $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" }
+ $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')"
+}
+$distributionUrlName = $distributionUrl -replace '^.*/',''
+$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
+$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
+if ($env:MAVEN_USER_HOME) {
+ $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain"
+}
+$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
+$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
+
+if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
+ Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
+ Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
+ exit $?
+}
+
+if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
+ Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
+}
+
+# prepare tmp dir
+$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
+$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
+$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
+trap {
+ if ($TMP_DOWNLOAD_DIR.Exists) {
+ try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
+ catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
+ }
+}
+
+New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
+
+# Download and Install Apache Maven
+Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
+Write-Verbose "Downloading from: $distributionUrl"
+Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
+
+$webclient = New-Object System.Net.WebClient
+if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
+ $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
+}
+[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
+$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
+
+# If specified, validate the SHA-256 sum of the Maven distribution zip file
+$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
+if ($distributionSha256Sum) {
+ if ($USE_MVND) {
+ Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
+ }
+ Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
+ if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
+ Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
+ }
+}
+
+# unzip and move
+Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
+Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null
+try {
+ Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
+} catch {
+ if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
+ Write-Error "fail to move MAVEN_HOME"
+ }
+} finally {
+ try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
+ catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
+}
+
+Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
diff --git a/provider/pom.xml b/provider/pom.xml
new file mode 100644
index 0000000..2c7ba04
--- /dev/null
+++ b/provider/pom.xml
@@ -0,0 +1,74 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.0.0.RELEASE
+
+
+ com.example
+ provider
+ 0.0.1-SNAPSHOT
+ provider
+ provider
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 8
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+ org.example
+ publicInterface
+ 1.0-SNAPSHOT
+ compile
+
+
+ org.example
+ version4
+ 1.0-SNAPSHOT
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 8
+ 8
+
+
+
+
+
+
diff --git a/provider/src/main/java/com/example/provider/ProviderApplication.java b/provider/src/main/java/com/example/provider/ProviderApplication.java
new file mode 100644
index 0000000..c2d5a69
--- /dev/null
+++ b/provider/src/main/java/com/example/provider/ProviderApplication.java
@@ -0,0 +1,15 @@
+package com.example.provider;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import part1.Server.integration.EnableProvider;
+
+@SpringBootApplication
+@EnableProvider
+public class ProviderApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(ProviderApplication.class, args);
+ }
+
+}
diff --git a/provider/src/main/java/com/example/provider/web/service/impl/UserServiceImpl1.java b/provider/src/main/java/com/example/provider/web/service/impl/UserServiceImpl1.java
new file mode 100644
index 0000000..74a7c87
--- /dev/null
+++ b/provider/src/main/java/com/example/provider/web/service/impl/UserServiceImpl1.java
@@ -0,0 +1,31 @@
+package com.example.provider.web.service.impl;
+
+import com.publicInterface.service.UserService;
+import com.publicInterface.dto.User;
+import part1.Server.integration.RpcService;
+import java.util.Random;
+import java.util.UUID;
+
+/**
+ * @Author: yty
+ * @Description: TODO
+ * @DateTime: 2024/11/08 15:05
+ **/
+@RpcService(version = "1.1")
+public class UserServiceImpl1 implements UserService {
+ @Override
+ public User getUserByUserId(Integer id) {
+ System.out.println("实现方法1.1:客户端查询了"+id+"的用户");
+ // 模拟从数据库中取用户的行为
+ Random random = new Random();
+ return User.builder().userName(UUID.randomUUID().toString())
+ .id(id)
+ .sex(random.nextBoolean()).build();
+ }
+
+ @Override
+ public Integer insertUserId(User user) {
+ System.out.println("实现方法1.1:插入数据成功"+user.getUserName());
+ return user.getId();
+ }
+}
\ No newline at end of file
diff --git a/provider/src/main/java/com/example/provider/web/service/impl/UserServiceImpl2.java b/provider/src/main/java/com/example/provider/web/service/impl/UserServiceImpl2.java
new file mode 100644
index 0000000..4fcbdb0
--- /dev/null
+++ b/provider/src/main/java/com/example/provider/web/service/impl/UserServiceImpl2.java
@@ -0,0 +1,32 @@
+package com.example.provider.web.service.impl;
+
+import com.publicInterface.dto.User;
+import com.publicInterface.service.UserService;
+import part1.Server.integration.RpcService;
+
+import java.util.Random;
+import java.util.UUID;
+
+/**
+ * @Author: yty
+ * @Description: TODO
+ * @DateTime: 2024/11/08 15:05
+ **/
+@RpcService(version = "1.2")
+public class UserServiceImpl2 implements UserService {
+ @Override
+ public User getUserByUserId(Integer id) {
+ System.out.println("实现方法1.2:客户端查询了"+id+"的用户");
+ // 模拟从数据库中取用户的行为
+ Random random = new Random();
+ return User.builder().userName(UUID.randomUUID().toString())
+ .id(id)
+ .sex(random.nextBoolean()).build();
+ }
+
+ @Override
+ public Integer insertUserId(User user) {
+ System.out.println("实现方法1.2:插入数据成功"+user.getUserName());
+ return user.getId();
+ }
+}
\ No newline at end of file
diff --git a/provider/src/main/resources/application.properties b/provider/src/main/resources/application.properties
new file mode 100644
index 0000000..1b4fe40
--- /dev/null
+++ b/provider/src/main/resources/application.properties
@@ -0,0 +1,3 @@
+spring.application.name=provider
+server.port=9090
+
diff --git a/version1/pom.xml b/publicInterface/pom.xml
similarity index 50%
rename from version1/pom.xml
rename to publicInterface/pom.xml
index 0761b8b..e443676 100644
--- a/version1/pom.xml
+++ b/publicInterface/pom.xml
@@ -5,8 +5,9 @@
4.0.0
org.example
- version1
+ publicInterface
1.0-SNAPSHOT
+
8
8
@@ -14,36 +15,29 @@
- org.projectlombok
- lombok
- 1.18.30
+ org.example
+ version4
+ 1.0-SNAPSHOT
compile
- org.slf4j
- slf4j-log4j12
- 1.7.25
-
-
- org.apache.logging.log4j
- log4j-1.2-api
- 2.8.2
-
-
-
- io.netty
- netty-all
- 4.1.51.Final
+ org.projectlombok
+ lombok
+ 1.18.34
compile
-
-
- org.apache.curator
- curator-recipes
- 5.1.0
-
-
-
-
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 8
+ 8
+
+
+
+
\ No newline at end of file
diff --git a/version1/src/main/java/part3/common/pojo/User.java b/publicInterface/src/main/java/com/publicInterface/dto/User.java
similarity index 90%
rename from version1/src/main/java/part3/common/pojo/User.java
rename to publicInterface/src/main/java/com/publicInterface/dto/User.java
index 46a0a87..09bf50a 100644
--- a/version1/src/main/java/part3/common/pojo/User.java
+++ b/publicInterface/src/main/java/com/publicInterface/dto/User.java
@@ -1,4 +1,5 @@
-package part3.common.pojo;
+package com.publicInterface.dto;
+
import lombok.AllArgsConstructor;
import lombok.Builder;
@@ -8,7 +9,6 @@
import java.io.Serializable;
/**
- * @author wxx
* @version 1.0
* @create 2024/1/28 17:50
*/
diff --git a/version1/src/main/java/part2/common/service/UserService.java b/publicInterface/src/main/java/com/publicInterface/service/UserService.java
similarity index 76%
rename from version1/src/main/java/part2/common/service/UserService.java
rename to publicInterface/src/main/java/com/publicInterface/service/UserService.java
index b6817fe..cce6637 100644
--- a/version1/src/main/java/part2/common/service/UserService.java
+++ b/publicInterface/src/main/java/com/publicInterface/service/UserService.java
@@ -1,10 +1,9 @@
-package part2.common.service;
+package com.publicInterface.service;
-import part2.common.pojo.User;
+import com.publicInterface.dto.User;
/**
- * @author wxx
* @version 1.0
* @create 2024/1/28 16:27
*/
diff --git a/publicInterface/target/classes/com/publicInterface/dto/User$UserBuilder.class b/publicInterface/target/classes/com/publicInterface/dto/User$UserBuilder.class
new file mode 100644
index 0000000..dfbd4a0
Binary files /dev/null and b/publicInterface/target/classes/com/publicInterface/dto/User$UserBuilder.class differ
diff --git a/publicInterface/target/classes/com/publicInterface/dto/User.class b/publicInterface/target/classes/com/publicInterface/dto/User.class
new file mode 100644
index 0000000..756bf33
Binary files /dev/null and b/publicInterface/target/classes/com/publicInterface/dto/User.class differ
diff --git a/publicInterface/target/classes/com/publicInterface/service/UserService.class b/publicInterface/target/classes/com/publicInterface/service/UserService.class
new file mode 100644
index 0000000..939c55e
Binary files /dev/null and b/publicInterface/target/classes/com/publicInterface/service/UserService.class differ
diff --git a/publicInterface/target/maven-archiver/pom.properties b/publicInterface/target/maven-archiver/pom.properties
new file mode 100644
index 0000000..e91d27c
--- /dev/null
+++ b/publicInterface/target/maven-archiver/pom.properties
@@ -0,0 +1,5 @@
+#Generated by Maven
+#Tue Dec 10 10:12:20 CST 2024
+version=1.0-SNAPSHOT
+groupId=org.example
+artifactId=publicInterface
diff --git a/publicInterface/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/publicInterface/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
new file mode 100644
index 0000000..f272055
--- /dev/null
+++ b/publicInterface/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
@@ -0,0 +1,3 @@
+com\publicInterface\dto\User$UserBuilder.class
+com\publicInterface\service\UserService.class
+com\publicInterface\dto\User.class
diff --git a/publicInterface/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/publicInterface/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
new file mode 100644
index 0000000..97d2b08
--- /dev/null
+++ b/publicInterface/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
@@ -0,0 +1,2 @@
+D:\developSoftware\backDev\Code\DEV-RPC-Java\publicInterface\src\main\java\com\publicInterface\service\UserService.java
+D:\developSoftware\backDev\Code\DEV-RPC-Java\publicInterface\src\main\java\com\publicInterface\dto\User.java
diff --git a/publicInterface/target/publicInterface-1.0-SNAPSHOT.jar b/publicInterface/target/publicInterface-1.0-SNAPSHOT.jar
new file mode 100644
index 0000000..b614b97
Binary files /dev/null and b/publicInterface/target/publicInterface-1.0-SNAPSHOT.jar differ
diff --git a/version1/src/main/java/part1/Client/IOClient.java b/version1/src/main/java/part1/Client/IOClient.java
deleted file mode 100644
index 8c7f61f..0000000
--- a/version1/src/main/java/part1/Client/IOClient.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package part1.Client;
-
-
-
-import part1.common.Message.RpcRequest;
-import part1.common.Message.RpcResponse;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.net.Socket;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/4 18:31
- */
-public class IOClient {
- //这里负责底层与服务端的通信,发送request,返回response
- public static RpcResponse sendRequest(String host, int port, RpcRequest request){
- try {
- Socket socket=new Socket(host, port);
- ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
- ObjectInputStream ois=new ObjectInputStream(socket.getInputStream());
-
- oos.writeObject(request);
- oos.flush();
-
- RpcResponse response=(RpcResponse) ois.readObject();
- return response;
- } catch (IOException | ClassNotFoundException e) {
- e.printStackTrace();
- return null;
- }
- }
-}
diff --git a/version1/src/main/java/part1/Client/TestClient.java b/version1/src/main/java/part1/Client/TestClient.java
deleted file mode 100644
index f9b7bab..0000000
--- a/version1/src/main/java/part1/Client/TestClient.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package part1.Client;
-
-
-import part1.Client.proxy.ClientProxy;
-import part1.common.service.UserService;
-import part1.common.pojo.User;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/6 18:39
- */
-public class TestClient {
- public static void main(String[] args) {
- ClientProxy clientProxy=new ClientProxy("127.0.0.1",9999);
- UserService proxy=clientProxy.getProxy(UserService.class);
-
- User user = proxy.getUserByUserId(1);
- System.out.println("从服务端得到的user="+user.toString());
-
- User u=User.builder().id(100).userName("wxx").sex(true).build();
- Integer id = proxy.insertUserId(u);
- System.out.println("向服务端插入user的id"+id);
- }
-}
diff --git a/version1/src/main/java/part1/Client/proxy/ClientProxy.java b/version1/src/main/java/part1/Client/proxy/ClientProxy.java
deleted file mode 100644
index 3701bdf..0000000
--- a/version1/src/main/java/part1/Client/proxy/ClientProxy.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package part1.Client.proxy;
-
-
-import lombok.AllArgsConstructor;
-import part1.Client.IOClient;
-import part1.common.Message.RpcRequest;
-import part1.common.Message.RpcResponse;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/6 16:49
- */
-@AllArgsConstructor
-public class ClientProxy implements InvocationHandler {
- //传入参数service接口的class对象,反射封装成一个request
- private String host;
- private int port;
-
- //jdk动态代理,每一次代理对象调用方法,都会经过此方法增强(反射获取request对象,socket发送到服务端)
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- //构建request
- RpcRequest request=RpcRequest.builder()
- .interfaceName(method.getDeclaringClass().getName())
- .methodName(method.getName())
- .params(args).paramsType(method.getParameterTypes()).build();
- //IOClient.sendRequest 和服务端进行数据传输
- RpcResponse response= IOClient.sendRequest(host,port,request);
- return response.getData();
- }
- public T getProxy(Class clazz){
- Object o = Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, this);
- return (T)o;
- }
-}
diff --git a/version1/src/main/java/part1/Server/TestServer.java b/version1/src/main/java/part1/Server/TestServer.java
deleted file mode 100644
index 682b912..0000000
--- a/version1/src/main/java/part1/Server/TestServer.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package part1.Server;
-
-
-import part1.Server.server.RpcServer;
-import part1.common.service.Impl.UserServiceImpl;
-import part1.common.service.UserService;
-import part1.Server.server.impl.SimpleRPCRPCServer;
-import part1.Server.provider.ServiceProvider;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/11 19:39
- */
-public class TestServer {
- public static void main(String[] args) {
- UserService userService=new UserServiceImpl();
-
- ServiceProvider serviceProvider=new ServiceProvider();
- serviceProvider.provideServiceInterface(userService);
-
- RpcServer rpcServer=new SimpleRPCRPCServer(serviceProvider);
- rpcServer.start(9999);
- }
-}
diff --git a/version1/src/main/java/part1/Server/provider/ServiceProvider.java b/version1/src/main/java/part1/Server/provider/ServiceProvider.java
deleted file mode 100644
index 8864448..0000000
--- a/version1/src/main/java/part1/Server/provider/ServiceProvider.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package part1.Server.provider;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/16 17:35
- */
-//本地服务存放器
-public class ServiceProvider {
- //集合中存放服务的实例
- private Map interfaceProvider;
-
- public ServiceProvider(){
- this.interfaceProvider=new HashMap<>();
- }
- //本地注册服务
-
- public void provideServiceInterface(Object service){
- String serviceName=service.getClass().getName();
- Class>[] interfaceName=service.getClass().getInterfaces();
-
- for (Class> clazz:interfaceName){
- interfaceProvider.put(clazz.getName(),service);
- }
-
- }
- //获取服务实例
- public Object getService(String interfaceName){
- return interfaceProvider.get(interfaceName);
- }
-}
diff --git a/version1/src/main/java/part1/Server/server/RpcServer.java b/version1/src/main/java/part1/Server/server/RpcServer.java
deleted file mode 100644
index 76df981..0000000
--- a/version1/src/main/java/part1/Server/server/RpcServer.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package part1.Server.server;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/12 11:26
- */
-public interface RpcServer {
- //开启监听
- void start(int port);
- void stop();
-}
diff --git a/version1/src/main/java/part1/Server/server/impl/SimpleRPCRPCServer.java b/version1/src/main/java/part1/Server/server/impl/SimpleRPCRPCServer.java
deleted file mode 100644
index 09afdff..0000000
--- a/version1/src/main/java/part1/Server/server/impl/SimpleRPCRPCServer.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package part1.Server.server.impl;
-
-
-import lombok.AllArgsConstructor;
-import part1.Server.server.RpcServer;
-import part1.Server.server.work.WorkThread;
-import part1.Server.provider.ServiceProvider;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/12 11:37
- */
-@AllArgsConstructor
-public class SimpleRPCRPCServer implements RpcServer {
- private ServiceProvider serviceProvide;
- @Override
- public void start(int port) {
- try {
- ServerSocket serverSocket=new ServerSocket(port);
- System.out.println("服务器启动了");
- while (true) {
- //如果没有连接,会堵塞在这里
- Socket socket = serverSocket.accept();
- //有连接,创建一个新的线程执行处理
- new Thread(new WorkThread(socket,serviceProvide)).start();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void stop() {
- }
-}
diff --git a/version1/src/main/java/part1/Server/server/impl/ThreadPoolRPCRPCServer.java b/version1/src/main/java/part1/Server/server/impl/ThreadPoolRPCRPCServer.java
deleted file mode 100644
index 0d32e1f..0000000
--- a/version1/src/main/java/part1/Server/server/impl/ThreadPoolRPCRPCServer.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package part1.Server.server.impl;
-
-
-import part1.Server.server.RpcServer;
-import part1.Server.server.work.WorkThread;
-import part1.Server.provider.ServiceProvider;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/19 15:30
- */
-public class ThreadPoolRPCRPCServer implements RpcServer {
- private final ThreadPoolExecutor threadPool;
- private ServiceProvider serviceProvider;
-
- public ThreadPoolRPCRPCServer(ServiceProvider serviceProvider){
- threadPool=new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(),
- 1000,60, TimeUnit.SECONDS,new ArrayBlockingQueue<>(100));
- this.serviceProvider= serviceProvider;
- }
- public ThreadPoolRPCRPCServer(ServiceProvider serviceProvider, int corePoolSize,
- int maximumPoolSize,
- long keepAliveTime,
- TimeUnit unit,
- BlockingQueue workQueue){
-
- threadPool = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
- this.serviceProvider = serviceProvider;
- }
-
- @Override
- public void start(int port) {
- System.out.println("服务端启动了");
- try {
- ServerSocket serverSocket=new ServerSocket();
- while (true){
- Socket socket= serverSocket.accept();
- threadPool.execute(new WorkThread(socket,serviceProvider));
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void stop() {
-
- }
-}
diff --git a/version1/src/main/java/part1/Server/server/work/WorkThread.java b/version1/src/main/java/part1/Server/server/work/WorkThread.java
deleted file mode 100644
index 064b9c2..0000000
--- a/version1/src/main/java/part1/Server/server/work/WorkThread.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package part1.Server.server.work;
-
-
-import lombok.AllArgsConstructor;
-import part1.Server.provider.ServiceProvider;
-import part1.common.Message.RpcRequest;
-import part1.common.Message.RpcResponse;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.Socket;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/14 17:39
- */
-@AllArgsConstructor
-public class WorkThread implements Runnable{
- private Socket socket;
- private ServiceProvider serviceProvide;
- @Override
- public void run() {
- try {
- ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
- ObjectInputStream ois=new ObjectInputStream(socket.getInputStream());
- //读取客户端传过来的request
- RpcRequest rpcRequest = (RpcRequest) ois.readObject();
- //反射调用服务方法获取返回值
- RpcResponse rpcResponse=getResponse(rpcRequest);
- //向客户端写入response
- oos.writeObject(rpcResponse);
- oos.flush();
- } catch (IOException | ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- private RpcResponse getResponse(RpcRequest rpcRequest){
- //得到服务名
- String interfaceName=rpcRequest.getInterfaceName();
- //得到服务端相应服务实现类
- Object service = serviceProvide.getService(interfaceName);
- //反射调用方法
- Method method=null;
- try {
- method= service.getClass().getMethod(rpcRequest.getMethodName(), rpcRequest.getParamsType());
- Object invoke=method.invoke(service,rpcRequest.getParams());
- return RpcResponse.sussess(invoke);
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
- e.printStackTrace();
- System.out.println("方法执行错误");
- return RpcResponse.fail();
- }
- }
-}
diff --git a/version1/src/main/java/part1/common/Message/RpcRequest.java b/version1/src/main/java/part1/common/Message/RpcRequest.java
deleted file mode 100644
index 0d8f171..0000000
--- a/version1/src/main/java/part1/common/Message/RpcRequest.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package part1.common.Message;
-
-import lombok.Builder;
-import lombok.Data;
-
-import java.io.Serializable;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/1 18:30
- * 定义发送的消息格式
- */
-@Data
-@Builder
-public class RpcRequest implements Serializable {
- //服务类名,客户端只知道接口
- private String interfaceName;
- //调用的方法名
- private String methodName;
- //参数列表
- private Object[] params;
- //参数类型
- private Class>[] paramsType;
-}
diff --git a/version1/src/main/java/part1/common/Message/RpcResponse.java b/version1/src/main/java/part1/common/Message/RpcResponse.java
deleted file mode 100644
index 906ee1c..0000000
--- a/version1/src/main/java/part1/common/Message/RpcResponse.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package part1.common.Message;
-
-import lombok.Builder;
-import lombok.Data;
-
-import java.io.Serializable;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/1 19:18
- */
-@Data
-@Builder
-public class RpcResponse implements Serializable {
- //状态信息
- private int code;
- private String message;
- //具体数据
- private Object data;
- //构造成功信息
- public static RpcResponse sussess(Object data){
- return RpcResponse.builder().code(200).data(data).build();
- }
- //构造失败信息
- public static RpcResponse fail(){
- return RpcResponse.builder().code(500).message("服务器发生错误").build();
- }
-}
-
diff --git a/version1/src/main/java/part1/common/pojo/User.java b/version1/src/main/java/part1/common/pojo/User.java
deleted file mode 100644
index d7cef8c..0000000
--- a/version1/src/main/java/part1/common/pojo/User.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package part1.common.pojo;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-import java.io.Serializable;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/1/28 17:50
- */
-@Builder
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-public class User implements Serializable {
- // 客户端和服务端共有的
- private Integer id;
- private String userName;
- private Boolean sex;
-}
-
diff --git a/version1/src/main/java/part1/common/service/Impl/UserServiceImpl.java b/version1/src/main/java/part1/common/service/Impl/UserServiceImpl.java
deleted file mode 100644
index 373243b..0000000
--- a/version1/src/main/java/part1/common/service/Impl/UserServiceImpl.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package part1.common.service.Impl;
-
-
-import part1.common.pojo.User;
-import part1.common.service.UserService;
-
-import java.util.Random;
-import java.util.UUID;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/1/28 16:28
- */
-public class UserServiceImpl implements UserService {
- @Override
- public User getUserByUserId(Integer id) {
- System.out.println("客户端查询了"+id+"的用户");
- // 模拟从数据库中取用户的行为
- Random random = new Random();
- User user = User.builder().userName(UUID.randomUUID().toString())
- .id(id)
- .sex(random.nextBoolean()).build();
- return user;
- }
-
- @Override
- public Integer insertUserId(User user) {
- System.out.println("插入数据成功"+user.getUserName());
- return user.getId();
- }
-}
\ No newline at end of file
diff --git a/version1/src/main/java/part1/common/service/UserService.java b/version1/src/main/java/part1/common/service/UserService.java
deleted file mode 100644
index 0e539bd..0000000
--- a/version1/src/main/java/part1/common/service/UserService.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package part1.common.service;
-
-
-import part1.common.pojo.User;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/1/28 16:27
- */
-public interface UserService {
- // 客户端通过这个接口调用服务端的实现类
- User getUserByUserId(Integer id);
- //新增一个功能
- Integer insertUserId(User user);
-}
diff --git a/version1/src/main/java/part2/Client/IOClient.java b/version1/src/main/java/part2/Client/IOClient.java
deleted file mode 100644
index 066736a..0000000
--- a/version1/src/main/java/part2/Client/IOClient.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package part2.Client;
-
-
-
-import part2.common.Message.RpcRequest;
-import part2.common.Message.RpcResponse;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.net.Socket;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/4 18:31
- */
-public class IOClient {
- //这里负责底层与服务端的通信,发送request,返回response
- public static RpcResponse sendRequest(String host, int port, RpcRequest request){
- try {
- Socket socket=new Socket(host, port);
- ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
- ObjectInputStream ois=new ObjectInputStream(socket.getInputStream());
-
- oos.writeObject(request);
- oos.flush();
-
- RpcResponse response=(RpcResponse) ois.readObject();
- return response;
- } catch (IOException | ClassNotFoundException e) {
- e.printStackTrace();
- return null;
- }
- }
-}
diff --git a/version1/src/main/java/part2/Client/TestClient.java b/version1/src/main/java/part2/Client/TestClient.java
deleted file mode 100644
index 3ce5d38..0000000
--- a/version1/src/main/java/part2/Client/TestClient.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package part2.Client;
-
-
-import part2.Client.proxy.ClientProxy;
-import part2.common.pojo.User;
-import part2.common.service.UserService;
-
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/6 18:39
- */
-public class TestClient {
- public static void main(String[] args) {
- ClientProxy clientProxy=new ClientProxy("127.0.0.1",9999,0);
- UserService proxy=clientProxy.getProxy(UserService.class);
-
- User user = proxy.getUserByUserId(1);
- System.out.println("从服务端得到的user="+user.toString());
-
- User u=User.builder().id(100).userName("wxx").sex(true).build();
- Integer id = proxy.insertUserId(u);
- System.out.println("向服务端插入user的id"+id);
- }
-}
diff --git a/version1/src/main/java/part2/Client/netty/handler/NettyClientHandler.java b/version1/src/main/java/part2/Client/netty/handler/NettyClientHandler.java
deleted file mode 100644
index 12d5693..0000000
--- a/version1/src/main/java/part2/Client/netty/handler/NettyClientHandler.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package part2.Client.netty.handler;
-
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.SimpleChannelInboundHandler;
-import io.netty.util.AttributeKey;
-import part2.common.Message.RpcResponse;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/26 17:29
- */
-public class NettyClientHandler extends SimpleChannelInboundHandler {
- @Override
- protected void channelRead0(ChannelHandlerContext ctx, RpcResponse response) throws Exception {
- // 接收到response, 给channel设计别名,让sendRequest里读取response
- AttributeKey key = AttributeKey.valueOf("RPCResponse");
- ctx.channel().attr(key).set(response);
- ctx.channel().close();
- }
-
- @Override
- public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
- //异常处理
- cause.printStackTrace();
- ctx.close();
- }
-}
diff --git a/version1/src/main/java/part2/Client/netty/nettyInitializer/NettyClientInitializer.java b/version1/src/main/java/part2/Client/netty/nettyInitializer/NettyClientInitializer.java
deleted file mode 100644
index 5bec33d..0000000
--- a/version1/src/main/java/part2/Client/netty/nettyInitializer/NettyClientInitializer.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package part2.Client.netty.nettyInitializer;
-
-
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelPipeline;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
-import io.netty.handler.codec.LengthFieldPrepender;
-import io.netty.handler.codec.serialization.ClassResolver;
-import io.netty.handler.codec.serialization.ObjectDecoder;
-import io.netty.handler.codec.serialization.ObjectEncoder;
-import part2.Client.netty.handler.NettyClientHandler;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/26 17:26
- */
-public class NettyClientInitializer extends ChannelInitializer {
- @Override
- protected void initChannel(SocketChannel ch) throws Exception {
- ChannelPipeline pipeline = ch.pipeline();
- //消息格式 【长度】【消息体】,解决沾包问题
- pipeline.addLast(
- new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE,0,4,0,4));
- //计算当前待发送消息的长度,写入到前4个字节中
- pipeline.addLast(new LengthFieldPrepender(4));
- //编码器
- //使用Java序列化方式,netty的自带的解码编码支持传输这种结构
- pipeline.addLast(new ObjectEncoder());
- //解码器
- //使用了Netty中的ObjectDecoder,它用于将字节流解码为 Java 对象。
- //在ObjectDecoder的构造函数中传入了一个ClassResolver 对象,用于解析类名并加载相应的类。
- pipeline.addLast(new ObjectDecoder(new ClassResolver() {
- @Override
- public Class> resolve(String className) throws ClassNotFoundException {
- return Class.forName(className);
- }
- }));
-
- pipeline.addLast(new NettyClientHandler());
- }
-}
diff --git a/version1/src/main/java/part2/Client/proxy/ClientProxy.java b/version1/src/main/java/part2/Client/proxy/ClientProxy.java
deleted file mode 100644
index a6b5a4e..0000000
--- a/version1/src/main/java/part2/Client/proxy/ClientProxy.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package part2.Client.proxy;
-
-
-import lombok.AllArgsConstructor;
-import part2.common.Message.RpcRequest;
-import part2.common.Message.RpcResponse;
-import part2.Client.IOClient;
-import part2.Client.rpcClient.RpcClient;
-import part2.Client.rpcClient.impl.NettyRpcClient;
-import part2.Client.rpcClient.impl.SimpleSocketRpcCilent;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/6 16:49
- */
-public class ClientProxy implements InvocationHandler {
- //传入参数service接口的class对象,反射封装成一个request
-
- private RpcClient rpcClient;
- public ClientProxy(String host,int port,int choose){
- switch (choose){
- case 0:
- rpcClient=new NettyRpcClient(host,port);
- break;
- case 1:
- rpcClient=new SimpleSocketRpcCilent(host,port);
- }
- }
- public ClientProxy(String host,int port){
- rpcClient=new NettyRpcClient(host,port);
- }
- //jdk动态代理,每一次代理对象调用方法,都会经过此方法增强(反射获取request对象,socket发送到服务端)
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- //构建request
- RpcRequest request=RpcRequest.builder()
- .interfaceName(method.getDeclaringClass().getName())
- .methodName(method.getName())
- .params(args).paramsType(method.getParameterTypes()).build();
- //数据传输
- RpcResponse response= rpcClient.sendRequest(request);
- return response.getData();
- }
- public T getProxy(Class clazz){
- Object o = Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, this);
- return (T)o;
- }
-}
diff --git a/version1/src/main/java/part2/Client/rpcClient/RpcClient.java b/version1/src/main/java/part2/Client/rpcClient/RpcClient.java
deleted file mode 100644
index 21690b1..0000000
--- a/version1/src/main/java/part2/Client/rpcClient/RpcClient.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package part2.Client.rpcClient;
-
-import part2.common.Message.RpcRequest;
-import part2.common.Message.RpcResponse;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/5/2 18:55
- */
-public interface RpcClient {
-
- //定义底层通信的方法
- RpcResponse sendRequest(RpcRequest request);
-}
diff --git a/version1/src/main/java/part2/Client/rpcClient/impl/NettyRpcClient.java b/version1/src/main/java/part2/Client/rpcClient/impl/NettyRpcClient.java
deleted file mode 100644
index b3dab27..0000000
--- a/version1/src/main/java/part2/Client/rpcClient/impl/NettyRpcClient.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package part2.Client.rpcClient.impl;
-
-import io.netty.bootstrap.Bootstrap;
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.EventLoopGroup;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.channel.socket.nio.NioSocketChannel;
-import io.netty.util.AttributeKey;
-import part2.Client.netty.nettyInitializer.NettyClientInitializer;
-import part2.common.Message.RpcRequest;
-import part2.common.Message.RpcResponse;
-import part2.Client.rpcClient.RpcClient;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/5/2 19:40
- */
-public class NettyRpcClient implements RpcClient {
- private String host;
- private int port;
- private static final Bootstrap bootstrap;
- private static final EventLoopGroup eventLoopGroup;
- public NettyRpcClient(String host,int port){
- this.host=host;
- this.port=port;
- }
- //netty客户端初始化
- static {
- eventLoopGroup = new NioEventLoopGroup();
- bootstrap = new Bootstrap();
- bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class)
- //NettyClientInitializer这里 配置netty对消息的处理机制
- .handler(new NettyClientInitializer());
- }
- @Override
- public RpcResponse sendRequest(RpcRequest request) {
- try {
- //创建一个channelFuture对象,代表这一个操作事件,sync方法表示堵塞直到connect完成
- ChannelFuture channelFuture = bootstrap.connect(host, port).sync();
- //channel表示一个连接的单位,类似socket
- Channel channel = channelFuture.channel();
- // 发送数据
- channel.writeAndFlush(request);
- //sync()堵塞获取结果
- channel.closeFuture().sync();
- // 阻塞的获得结果,通过给channel设计别名,获取特定名字下的channel中的内容(这个在hanlder中设置)
- // AttributeKey是,线程隔离的,不会由线程安全问题。
- // 当前场景下选择堵塞获取结果
- // 其它场景也可以选择添加监听器的方式来异步获取结果 channelFuture.addListener...
- AttributeKey key = AttributeKey.valueOf("RPCResponse");
- RpcResponse response = channel.attr(key).get();
-
- System.out.println(response);
- return response;
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- return null;
- }
-}
diff --git a/version1/src/main/java/part2/Client/rpcClient/impl/SimpleSocketRpcCilent.java b/version1/src/main/java/part2/Client/rpcClient/impl/SimpleSocketRpcCilent.java
deleted file mode 100644
index 7e9f09c..0000000
--- a/version1/src/main/java/part2/Client/rpcClient/impl/SimpleSocketRpcCilent.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package part2.Client.rpcClient.impl;
-
-import part2.common.Message.RpcRequest;
-import part2.common.Message.RpcResponse;
-import part2.Client.rpcClient.RpcClient;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.net.Socket;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/5/2 18:58
- */
-public class SimpleSocketRpcCilent implements RpcClient {
- private String host;
- private int port;
- public SimpleSocketRpcCilent(String host,int port){
- this.host=host;
- this.port=port;
- }
- @Override
- public RpcResponse sendRequest(RpcRequest request) {
- try {
- Socket socket=new Socket(host, port);
- ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
- ObjectInputStream ois=new ObjectInputStream(socket.getInputStream());
-
- oos.writeObject(request);
- oos.flush();
-
- RpcResponse response=(RpcResponse) ois.readObject();
- return response;
- } catch (IOException | ClassNotFoundException e) {
- e.printStackTrace();
- return null;
- }
- }
-}
diff --git a/version1/src/main/java/part2/Server/TestServer.java b/version1/src/main/java/part2/Server/TestServer.java
deleted file mode 100644
index a055f3e..0000000
--- a/version1/src/main/java/part2/Server/TestServer.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package part2.Server;
-
-
-import part2.Server.server.impl.NettyRPCRPCServer;
-import part2.common.service.Impl.UserServiceImpl;
-import part2.common.service.UserService;
-import part2.Server.provider.ServiceProvider;
-import part2.Server.server.RpcServer;
-import part2.Server.server.impl.SimpleRPCRPCServer;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/11 19:39
- */
-public class TestServer {
- public static void main(String[] args) {
- UserService userService=new UserServiceImpl();
-
- ServiceProvider serviceProvider=new ServiceProvider();
- serviceProvider.provideServiceInterface(userService);
-
- RpcServer rpcServer=new NettyRPCRPCServer(serviceProvider);
- rpcServer.start(9999);
- }
-}
diff --git a/version1/src/main/java/part2/Server/netty/handler/NettyRPCServerHandler.java b/version1/src/main/java/part2/Server/netty/handler/NettyRPCServerHandler.java
deleted file mode 100644
index 14948cc..0000000
--- a/version1/src/main/java/part2/Server/netty/handler/NettyRPCServerHandler.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package part2.Server.netty.handler;
-
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.SimpleChannelInboundHandler;
-import lombok.AllArgsConstructor;
-import part2.Server.provider.ServiceProvider;
-import part2.common.Message.RpcRequest;
-import part2.common.Message.RpcResponse;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/26 16:40
- * 因为是服务器端,我们知道接受到请求格式是RPCRequest
- * Object类型也行,强制转型就行
- */
-@AllArgsConstructor
-public class NettyRPCServerHandler extends SimpleChannelInboundHandler {
- private ServiceProvider serviceProvider;
- @Override
- protected void channelRead0(ChannelHandlerContext ctx, RpcRequest request) throws Exception {
- //接收request,读取并调用服务
- RpcResponse response = getResponse(request);
- ctx.writeAndFlush(response);
- ctx.close();
- }
- @Override
- public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
- cause.printStackTrace();
- ctx.close();
- }
- private RpcResponse getResponse(RpcRequest rpcRequest){
- //得到服务名
- String interfaceName=rpcRequest.getInterfaceName();
- //得到服务端相应服务实现类
- Object service = serviceProvider.getService(interfaceName);
- //反射调用方法
- Method method=null;
- try {
- method= service.getClass().getMethod(rpcRequest.getMethodName(), rpcRequest.getParamsType());
- Object invoke=method.invoke(service,rpcRequest.getParams());
- return RpcResponse.sussess(invoke);
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
- e.printStackTrace();
- System.out.println("方法执行错误");
- return RpcResponse.fail();
- }
- }
-}
diff --git a/version1/src/main/java/part2/Server/netty/nettyInitializer/NettyServerInitializer.java b/version1/src/main/java/part2/Server/netty/nettyInitializer/NettyServerInitializer.java
deleted file mode 100644
index 254b04c..0000000
--- a/version1/src/main/java/part2/Server/netty/nettyInitializer/NettyServerInitializer.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package part2.Server.netty.nettyInitializer;
-
-
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelPipeline;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
-import io.netty.handler.codec.LengthFieldPrepender;
-import io.netty.handler.codec.serialization.ClassResolver;
-import io.netty.handler.codec.serialization.ObjectDecoder;
-import io.netty.handler.codec.serialization.ObjectEncoder;
-import lombok.AllArgsConstructor;
-import part2.Server.netty.handler.NettyRPCServerHandler;
-import part2.Server.provider.ServiceProvider;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/26 16:15
- */
-@AllArgsConstructor
-public class NettyServerInitializer extends ChannelInitializer {
- private ServiceProvider serviceProvider;
- @Override
- protected void initChannel(SocketChannel ch) throws Exception {
- ChannelPipeline pipeline = ch.pipeline();
- //消息格式 【长度】【消息体】,解决沾包问题
- pipeline.addLast(
- new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE,0,4,0,4));
- //计算当前待发送消息的长度,写入到前4个字节中
- pipeline.addLast(new LengthFieldPrepender(4));
-
- //使用Java序列化方式,netty的自带的解码编码支持传输这种结构
- pipeline.addLast(new ObjectEncoder());
- //使用了Netty中的ObjectDecoder,它用于将字节流解码为 Java 对象。
- //在ObjectDecoder的构造函数中传入了一个ClassResolver 对象,用于解析类名并加载相应的类。
- pipeline.addLast(new ObjectDecoder(new ClassResolver() {
- @Override
- public Class> resolve(String className) throws ClassNotFoundException {
- return Class.forName(className);
- }
- }));
-
- pipeline.addLast(new NettyRPCServerHandler(serviceProvider));
- }
-}
diff --git a/version1/src/main/java/part2/Server/provider/ServiceProvider.java b/version1/src/main/java/part2/Server/provider/ServiceProvider.java
deleted file mode 100644
index 5cee41f..0000000
--- a/version1/src/main/java/part2/Server/provider/ServiceProvider.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package part2.Server.provider;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/16 17:35
- */
-public class ServiceProvider {
- private Map interfaceProvider;
-
- public ServiceProvider(){
- this.interfaceProvider=new HashMap<>();
- }
-
- public void provideServiceInterface(Object service){
- String serviceName=service.getClass().getName();
- Class>[] interfaceName=service.getClass().getInterfaces();
-
- for (Class> clazz:interfaceName){
- interfaceProvider.put(clazz.getName(),service);
- }
-
- }
-
- public Object getService(String interfaceName){
- return interfaceProvider.get(interfaceName);
- }
-
-}
diff --git a/version1/src/main/java/part2/Server/server/RpcServer.java b/version1/src/main/java/part2/Server/server/RpcServer.java
deleted file mode 100644
index 6abbf2a..0000000
--- a/version1/src/main/java/part2/Server/server/RpcServer.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package part2.Server.server;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/12 11:26
- */
-public interface RpcServer {
- void start(int port);
- void stop();
-}
diff --git a/version1/src/main/java/part2/Server/server/impl/NettyRPCRPCServer.java b/version1/src/main/java/part2/Server/server/impl/NettyRPCRPCServer.java
deleted file mode 100644
index 97632a6..0000000
--- a/version1/src/main/java/part2/Server/server/impl/NettyRPCRPCServer.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package part2.Server.server.impl;
-
-import io.netty.bootstrap.ServerBootstrap;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.channel.socket.nio.NioServerSocketChannel;
-import lombok.AllArgsConstructor;
-import part2.Server.netty.nettyInitializer.NettyServerInitializer;
-import part2.Server.provider.ServiceProvider;
-import part2.Server.server.RpcServer;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/26 14:01
- */
-@AllArgsConstructor
-public class NettyRPCRPCServer implements RpcServer {
- private ServiceProvider serviceProvider;
- @Override
- public void start(int port) {
- // netty 服务线程组boss负责建立连接, work负责具体的请求
- NioEventLoopGroup bossGroup = new NioEventLoopGroup();
- NioEventLoopGroup workGroup = new NioEventLoopGroup();
- System.out.println("netty服务端启动了");
- try {
- //启动netty服务器
- ServerBootstrap serverBootstrap = new ServerBootstrap();
- //初始化
- serverBootstrap.group(bossGroup,workGroup).channel(NioServerSocketChannel.class)
- //NettyClientInitializer这里 配置netty对消息的处理机制
- .childHandler(new NettyServerInitializer(serviceProvider));
- //同步堵塞
- ChannelFuture channelFuture=serverBootstrap.bind(port).sync();
- //死循环监听
- channelFuture.channel().closeFuture().sync();
- }catch (InterruptedException e){
- e.printStackTrace();
- }finally {
- bossGroup.shutdownGracefully();
- workGroup.shutdownGracefully();
- }
- }
-
- @Override
- public void stop() {
-
- }
-}
diff --git a/version1/src/main/java/part2/Server/server/impl/SimpleRPCRPCServer.java b/version1/src/main/java/part2/Server/server/impl/SimpleRPCRPCServer.java
deleted file mode 100644
index 8033bab..0000000
--- a/version1/src/main/java/part2/Server/server/impl/SimpleRPCRPCServer.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package part2.Server.server.impl;
-
-
-import lombok.AllArgsConstructor;
-import part2.Server.provider.ServiceProvider;
-import part2.Server.server.RpcServer;
-import part2.Server.server.work.WorkThread;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/12 11:37
- */
-@AllArgsConstructor
-public class SimpleRPCRPCServer implements RpcServer {
- private ServiceProvider serviceProvide;
- @Override
- public void start(int port) {
- try {
- ServerSocket serverSocket=new ServerSocket(port);
- System.out.println("服务器启动了");
- while (true) {
- Socket socket = serverSocket.accept();
- new Thread(new WorkThread(socket,serviceProvide)).start();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void stop() {
-
- }
-}
diff --git a/version1/src/main/java/part2/Server/server/impl/ThreadPoolRPCRPCServer.java b/version1/src/main/java/part2/Server/server/impl/ThreadPoolRPCRPCServer.java
deleted file mode 100644
index 834c9a5..0000000
--- a/version1/src/main/java/part2/Server/server/impl/ThreadPoolRPCRPCServer.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package part2.Server.server.impl;
-
-
-import part2.Server.provider.ServiceProvider;
-import part2.Server.server.RpcServer;
-import part2.Server.server.work.WorkThread;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/19 15:30
- */
-public class ThreadPoolRPCRPCServer implements RpcServer {
- private final ThreadPoolExecutor threadPool;
- private ServiceProvider serviceProvider;
-
- public ThreadPoolRPCRPCServer(ServiceProvider serviceProvider){
- threadPool=new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(),
- 1000,60, TimeUnit.SECONDS,new ArrayBlockingQueue<>(100));
- this.serviceProvider= serviceProvider;
- }
- public ThreadPoolRPCRPCServer(ServiceProvider serviceProvider, int corePoolSize,
- int maximumPoolSize,
- long keepAliveTime,
- TimeUnit unit,
- BlockingQueue workQueue){
-
- threadPool = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
- this.serviceProvider = serviceProvider;
- }
-
- @Override
- public void start(int port) {
- System.out.println("服务端启动了");
- try {
- ServerSocket serverSocket=new ServerSocket();
- while (true){
- Socket socket= serverSocket.accept();
- threadPool.execute(new WorkThread(socket,serviceProvider));
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void stop() {
-
- }
-}
diff --git a/version1/src/main/java/part2/Server/server/work/WorkThread.java b/version1/src/main/java/part2/Server/server/work/WorkThread.java
deleted file mode 100644
index a3985bf..0000000
--- a/version1/src/main/java/part2/Server/server/work/WorkThread.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package part2.Server.server.work;
-
-
-import lombok.AllArgsConstructor;
-import part2.Server.provider.ServiceProvider;
-import part2.common.Message.RpcRequest;
-import part2.common.Message.RpcResponse;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.Socket;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/14 17:39
- */
-@AllArgsConstructor
-public class WorkThread implements Runnable{
- private Socket socket;
- private ServiceProvider serviceProvide;
- @Override
- public void run() {
- try {
- ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
- ObjectInputStream ois=new ObjectInputStream(socket.getInputStream());
- //读取客户端传过来的request
- RpcRequest rpcRequest = (RpcRequest) ois.readObject();
- //反射调用服务方法获取返回值
- RpcResponse rpcResponse=getResponse(rpcRequest);
- //向客户端写入response
- oos.writeObject(rpcResponse);
- oos.flush();
- } catch (IOException | ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- private RpcResponse getResponse(RpcRequest rpcRequest){
- //得到服务名
- String interfaceName=rpcRequest.getInterfaceName();
- //得到服务端相应服务实现类
- Object service = serviceProvide.getService(interfaceName);
- //反射调用方法
- Method method=null;
- try {
- method= service.getClass().getMethod(rpcRequest.getMethodName(), rpcRequest.getParamsType());
- Object invoke=method.invoke(service,rpcRequest.getParams());
- return RpcResponse.sussess(invoke);
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
- e.printStackTrace();
- System.out.println("方法执行错误");
- return RpcResponse.fail();
- }
- }
-}
diff --git a/version1/src/main/java/part2/common/Message/RpcRequest.java b/version1/src/main/java/part2/common/Message/RpcRequest.java
deleted file mode 100644
index f6f398d..0000000
--- a/version1/src/main/java/part2/common/Message/RpcRequest.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package part2.common.Message;
-
-import lombok.Builder;
-import lombok.Data;
-
-import java.io.Serializable;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/1 18:30
- * 定义发送的消息格式
- */
-@Data
-@Builder
-public class RpcRequest implements Serializable {
- //服务类名,客户端只知道接口
- private String interfaceName;
- //调用的方法名
- private String methodName;
- //参数列表
- private Object[] params;
- //参数类型
- private Class>[] paramsType;
-}
diff --git a/version1/src/main/java/part2/common/Message/RpcResponse.java b/version1/src/main/java/part2/common/Message/RpcResponse.java
deleted file mode 100644
index a681df8..0000000
--- a/version1/src/main/java/part2/common/Message/RpcResponse.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package part2.common.Message;
-
-import lombok.Builder;
-import lombok.Data;
-
-import java.io.Serializable;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/1 19:18
- */
-@Data
-@Builder
-public class RpcResponse implements Serializable {
- //状态信息
- private int code;
- private String message;
- //具体数据
- private Object data;
-
- public static RpcResponse sussess(Object data){
- return RpcResponse.builder().code(200).data(data).build();
- }
- public static RpcResponse fail(){
- return RpcResponse.builder().code(500).message("服务器发生错误").build();
- }
-}
-
diff --git a/version1/src/main/java/part2/common/pojo/User.java b/version1/src/main/java/part2/common/pojo/User.java
deleted file mode 100644
index bf999d7..0000000
--- a/version1/src/main/java/part2/common/pojo/User.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package part2.common.pojo;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-import java.io.Serializable;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/1/28 17:50
- */
-@Builder
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-public class User implements Serializable {
- // 客户端和服务端共有的
- private Integer id;
- private String userName;
- private Boolean sex;
-}
-
diff --git a/version1/src/main/java/part2/common/service/Impl/UserServiceImpl.java b/version1/src/main/java/part2/common/service/Impl/UserServiceImpl.java
deleted file mode 100644
index 37e6262..0000000
--- a/version1/src/main/java/part2/common/service/Impl/UserServiceImpl.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package part2.common.service.Impl;
-
-
-import part2.common.pojo.User;
-import part2.common.service.UserService;
-
-import java.util.Random;
-import java.util.UUID;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/1/28 16:28
- */
-public class UserServiceImpl implements UserService {
- @Override
- public User getUserByUserId(Integer id) {
- System.out.println("客户端查询了"+id+"的用户");
- // 模拟从数据库中取用户的行为
- Random random = new Random();
- User user = User.builder().userName(UUID.randomUUID().toString())
- .id(id)
- .sex(random.nextBoolean()).build();
- return user;
- }
-
- @Override
- public Integer insertUserId(User user) {
- System.out.println("插入数据成功"+user.getUserName());
- return user.getId();
- }
-}
\ No newline at end of file
diff --git a/version1/src/main/java/part3/Client/TestClient.java b/version1/src/main/java/part3/Client/TestClient.java
deleted file mode 100644
index 5408350..0000000
--- a/version1/src/main/java/part3/Client/TestClient.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package part3.Client;
-
-
-import lombok.extern.slf4j.Slf4j;
-import part3.common.pojo.User;
-import part3.common.service.UserService;
-import part3.Client.proxy.ClientProxy;
-
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/6 18:39
- */
-
-public class TestClient {
- public static void main(String[] args) {
- ClientProxy clientProxy=new ClientProxy();
- //ClientProxy clientProxy=new part2.Client.proxy.ClientProxy("127.0.0.1",9999,0);
- UserService proxy=clientProxy.getProxy(UserService.class);
-
- User user = proxy.getUserByUserId(1);
- System.out.println("从服务端得到的user="+user.toString());
-
- User u=User.builder().id(100).userName("wxx").sex(true).build();
- Integer id = proxy.insertUserId(u);
- System.out.println("向服务端插入user的id"+id);
- }
-}
diff --git a/version1/src/main/java/part3/Client/netty/handler/NettyClientHandler.java b/version1/src/main/java/part3/Client/netty/handler/NettyClientHandler.java
deleted file mode 100644
index 28f173e..0000000
--- a/version1/src/main/java/part3/Client/netty/handler/NettyClientHandler.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package part3.Client.netty.handler;
-
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.SimpleChannelInboundHandler;
-import io.netty.util.AttributeKey;
-import part3.common.Message.RpcResponse;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/26 17:29
- */
-public class NettyClientHandler extends SimpleChannelInboundHandler {
- @Override
- protected void channelRead0(ChannelHandlerContext ctx, RpcResponse response) throws Exception {
- // 接收到response, 给channel设计别名,让sendRequest里读取response
- AttributeKey key = AttributeKey.valueOf("RPCResponse");
- ctx.channel().attr(key).set(response);
- ctx.channel().close();
- }
-
- @Override
- public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
- cause.printStackTrace();
- ctx.close();
- }
-}
diff --git a/version1/src/main/java/part3/Client/netty/nettyInitializer/NettyClientInitializer.java b/version1/src/main/java/part3/Client/netty/nettyInitializer/NettyClientInitializer.java
deleted file mode 100644
index bca4a4c..0000000
--- a/version1/src/main/java/part3/Client/netty/nettyInitializer/NettyClientInitializer.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package part3.Client.netty.nettyInitializer;
-
-
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelPipeline;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
-import io.netty.handler.codec.LengthFieldPrepender;
-import io.netty.handler.codec.serialization.ClassResolver;
-import io.netty.handler.codec.serialization.ObjectDecoder;
-import io.netty.handler.codec.serialization.ObjectEncoder;
-import part3.Client.netty.handler.NettyClientHandler;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/26 17:26
- */
-public class NettyClientInitializer extends ChannelInitializer {
- @Override
- protected void initChannel(SocketChannel ch) throws Exception {
- ChannelPipeline pipeline = ch.pipeline();
- //消息格式 【长度】【消息体】,解决沾包问题
- pipeline.addLast(
- new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE,0,4,0,4));
- //计算当前待发送消息的长度,写入到前4个字节中
- pipeline.addLast(new LengthFieldPrepender(4));
-
- //使用Java序列化方式,netty的自带的解码编码支持传输这种结构
- pipeline.addLast(new ObjectEncoder());
- //使用了Netty中的ObjectDecoder,它用于将字节流解码为 Java 对象。
- //在ObjectDecoder的构造函数中传入了一个ClassResolver 对象,用于解析类名并加载相应的类。
- pipeline.addLast(new ObjectDecoder(new ClassResolver() {
- @Override
- public Class> resolve(String className) throws ClassNotFoundException {
- return Class.forName(className);
- }
- }));
-
- pipeline.addLast(new NettyClientHandler());
- }
-}
diff --git a/version1/src/main/java/part3/Client/proxy/ClientProxy.java b/version1/src/main/java/part3/Client/proxy/ClientProxy.java
deleted file mode 100644
index 8cb957e..0000000
--- a/version1/src/main/java/part3/Client/proxy/ClientProxy.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package part3.Client.proxy;
-
-
-import part3.common.Message.RpcRequest;
-import part3.common.Message.RpcResponse;
-import part3.Client.rpcClient.RpcClient;
-import part3.Client.rpcClient.impl.NettyRpcClient;
-import part3.Client.rpcClient.impl.SimpleSocketRpcCilent;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/6 16:49
- */
-public class ClientProxy implements InvocationHandler {
- //传入参数service接口的class对象,反射封装成一个request
-
- private RpcClient rpcClient;
- public ClientProxy(){
- rpcClient=new NettyRpcClient();
- }
-
- //jdk动态代理,每一次代理对象调用方法,都会经过此方法增强(反射获取request对象,socket发送到服务端)
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- //构建request
- RpcRequest request=RpcRequest.builder()
- .interfaceName(method.getDeclaringClass().getName())
- .methodName(method.getName())
- .params(args).paramsType(method.getParameterTypes()).build();
- //数据传输
- RpcResponse response= rpcClient.sendRequest(request);
- return response.getData();
- }
- public T getProxy(Class clazz){
- Object o = Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, this);
- return (T)o;
- }
-}
diff --git a/version1/src/main/java/part3/Client/rpcClient/RpcClient.java b/version1/src/main/java/part3/Client/rpcClient/RpcClient.java
deleted file mode 100644
index 44b702b..0000000
--- a/version1/src/main/java/part3/Client/rpcClient/RpcClient.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package part3.Client.rpcClient;
-
-import part3.common.Message.RpcRequest;
-import part3.common.Message.RpcResponse;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/5/2 18:55
- */
-public interface RpcClient {
-
- //定义底层通信的方法
- RpcResponse sendRequest(RpcRequest request);
-}
diff --git a/version1/src/main/java/part3/Client/rpcClient/impl/NettyRpcClient.java b/version1/src/main/java/part3/Client/rpcClient/impl/NettyRpcClient.java
deleted file mode 100644
index a4fc493..0000000
--- a/version1/src/main/java/part3/Client/rpcClient/impl/NettyRpcClient.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package part3.Client.rpcClient.impl;
-
-import io.netty.bootstrap.Bootstrap;
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.EventLoopGroup;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.channel.socket.nio.NioSocketChannel;
-import io.netty.util.AttributeKey;
-import part3.Client.serviceCenter.ServiceCenter;
-import part3.Client.serviceCenter.ZKServiceCenter;
-import part3.common.Message.RpcRequest;
-import part3.common.Message.RpcResponse;
-import part3.Client.netty.nettyInitializer.NettyClientInitializer;
-import part3.Client.rpcClient.RpcClient;
-
-import java.net.InetSocketAddress;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/5/2 19:40
- */
-public class NettyRpcClient implements RpcClient {
-
- private static final Bootstrap bootstrap;
- private static final EventLoopGroup eventLoopGroup;
-
- private ServiceCenter serviceCenter;
- public NettyRpcClient(){
- this.serviceCenter=new ZKServiceCenter();
- }
-
- //netty客户端初始化
- static {
- eventLoopGroup = new NioEventLoopGroup();
- bootstrap = new Bootstrap();
- bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class)
- .handler(new NettyClientInitializer());
- }
- @Override
- public RpcResponse sendRequest(RpcRequest request) {
- //从注册中心获取host,post
- InetSocketAddress address = serviceCenter.serviceDiscovery(request.getInterfaceName());
- String host = address.getHostName();
- int port = address.getPort();
- try {
- ChannelFuture channelFuture = bootstrap.connect(host, port).sync();
- Channel channel = channelFuture.channel();
- // 发送数据
- channel.writeAndFlush(request);
- //sync()堵塞获取结果
- channel.closeFuture().sync();
- // 阻塞的获得结果,通过给channel设计别名,获取特定名字下的channel中的内容(这个在hanlder中设置)
- // AttributeKey是,线程隔离的,不会由线程安全问题。
- // 当前场景下选择堵塞获取结果
- // 其它场景也可以选择添加监听器的方式来异步获取结果 channelFuture.addListener...
- AttributeKey key = AttributeKey.valueOf("RPCResponse");
- RpcResponse response = channel.attr(key).get();
-
- System.out.println(response);
- return response;
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- return null;
- }
-}
diff --git a/version1/src/main/java/part3/Client/rpcClient/impl/SimpleSocketRpcCilent.java b/version1/src/main/java/part3/Client/rpcClient/impl/SimpleSocketRpcCilent.java
deleted file mode 100644
index b2f6af3..0000000
--- a/version1/src/main/java/part3/Client/rpcClient/impl/SimpleSocketRpcCilent.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package part3.Client.rpcClient.impl;
-
-import part3.common.Message.RpcRequest;
-import part3.common.Message.RpcResponse;
-import part3.Client.rpcClient.RpcClient;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.net.Socket;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/5/2 18:58
- */
-public class SimpleSocketRpcCilent implements RpcClient {
- private String host;
- private int port;
- public SimpleSocketRpcCilent(String host,int port){
- this.host=host;
- this.port=port;
- }
- @Override
- public RpcResponse sendRequest(RpcRequest request) {
- try {
- Socket socket=new Socket(host, port);
- ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
- ObjectInputStream ois=new ObjectInputStream(socket.getInputStream());
-
- oos.writeObject(request);
- oos.flush();
-
- RpcResponse response=(RpcResponse) ois.readObject();
- return response;
- } catch (IOException | ClassNotFoundException e) {
- e.printStackTrace();
- return null;
- }
- }
-}
diff --git a/version1/src/main/java/part3/Client/serviceCenter/ServiceCenter.java b/version1/src/main/java/part3/Client/serviceCenter/ServiceCenter.java
deleted file mode 100644
index 1b2c02e..0000000
--- a/version1/src/main/java/part3/Client/serviceCenter/ServiceCenter.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package part3.Client.serviceCenter;
-
-import java.net.InetSocketAddress;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/5/3 21:42
- */
-//服务中心接口
-public interface ServiceCenter {
- // 查询:根据服务名查找地址
- InetSocketAddress serviceDiscovery(String serviceName);
-}
diff --git a/version1/src/main/java/part3/Client/serviceCenter/ZKServiceCenter.java b/version1/src/main/java/part3/Client/serviceCenter/ZKServiceCenter.java
deleted file mode 100644
index a23ff1c..0000000
--- a/version1/src/main/java/part3/Client/serviceCenter/ZKServiceCenter.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package part3.Client.serviceCenter;
-
-import org.apache.curator.RetryPolicy;
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.CuratorFrameworkFactory;
-import org.apache.curator.retry.ExponentialBackoffRetry;
-
-import java.net.InetSocketAddress;
-import java.util.List;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/5/3 21:41
- */
-public class ZKServiceCenter implements ServiceCenter{
- // curator 提供的zookeeper客户端
- private CuratorFramework client;
- //zookeeper根路径节点
- private static final String ROOT_PATH = "MyRPC";
-
- //负责zookeeper客户端的初始化,并与zookeeper服务端进行连接
- public ZKServiceCenter(){
- // 指数时间重试
- RetryPolicy policy = new ExponentialBackoffRetry(1000, 3);
- // zookeeper的地址固定,不管是服务提供者还是,消费者都要与之建立连接
- // sessionTimeoutMs 与 zoo.cfg中的tickTime 有关系,
- // zk还会根据minSessionTimeout与maxSessionTimeout两个参数重新调整最后的超时值。默认分别为tickTime 的2倍和20倍
- // 使用心跳监听状态
- this.client = CuratorFrameworkFactory.builder().connectString("127.0.0.1:2181")
- .sessionTimeoutMs(40000).retryPolicy(policy).namespace(ROOT_PATH).build();
- this.client.start();
- System.out.println("zookeeper 连接成功");
- }
- //根据服务名(接口名)返回地址
- @Override
- public InetSocketAddress serviceDiscovery(String serviceName) {
- try {
- List strings = client.getChildren().forPath("/" + serviceName);
- // 这里默认用的第一个,后面加负载均衡
- String string = strings.get(0);
- return parseAddress(string);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- // 地址 -> XXX.XXX.XXX.XXX:port 字符串
- private String getServiceAddress(InetSocketAddress serverAddress) {
- return serverAddress.getHostName() +
- ":" +
- serverAddress.getPort();
- }
- // 字符串解析为地址
- private InetSocketAddress parseAddress(String address) {
- String[] result = address.split(":");
- return new InetSocketAddress(result[0], Integer.parseInt(result[1]));
- }
-}
diff --git a/version1/src/main/java/part3/Server/TestServer.java b/version1/src/main/java/part3/Server/TestServer.java
deleted file mode 100644
index 28f7ffd..0000000
--- a/version1/src/main/java/part3/Server/TestServer.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package part3.Server;
-
-
-import lombok.extern.slf4j.Slf4j;
-import part3.Server.server.impl.NettyRPCRPCServer;
-import part3.common.service.Impl.UserServiceImpl;
-import part3.common.service.UserService;
-import part3.Server.provider.ServiceProvider;
-import part3.Server.server.RpcServer;
-import part3.Server.server.impl.SimpleRPCRPCServer;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/11 19:39
- */
-
-public class TestServer {
- public static void main(String[] args) {
- UserService userService=new UserServiceImpl();
-
- ServiceProvider serviceProvider=new ServiceProvider("127.0.0.1",9999);
- serviceProvider.provideServiceInterface(userService);
-
- RpcServer rpcServer=new NettyRPCRPCServer(serviceProvider);
- rpcServer.start(9999);
- }
-}
diff --git a/version1/src/main/java/part3/Server/netty/handler/NettyRPCServerHandler.java b/version1/src/main/java/part3/Server/netty/handler/NettyRPCServerHandler.java
deleted file mode 100644
index aea757f..0000000
--- a/version1/src/main/java/part3/Server/netty/handler/NettyRPCServerHandler.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package part3.Server.netty.handler;
-
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.SimpleChannelInboundHandler;
-import lombok.AllArgsConstructor;
-import part3.Server.provider.ServiceProvider;
-import part3.common.Message.RpcRequest;
-import part3.common.Message.RpcResponse;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/26 16:40
- * 因为是服务器端,我们知道接受到请求格式是RPCRequest
- * Object类型也行,强制转型就行
- */
-@AllArgsConstructor
-public class NettyRPCServerHandler extends SimpleChannelInboundHandler {
- private ServiceProvider serviceProvider;
- @Override
- protected void channelRead0(ChannelHandlerContext ctx, RpcRequest request) throws Exception {
- RpcResponse response = getResponse(request);
- ctx.writeAndFlush(response);
- ctx.close();
- }
- @Override
- public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
- cause.printStackTrace();
- ctx.close();
- }
- private RpcResponse getResponse(RpcRequest rpcRequest){
- //得到服务名
- String interfaceName=rpcRequest.getInterfaceName();
- //得到服务端相应服务实现类
- Object service = serviceProvider.getService(interfaceName);
- //反射调用方法
- Method method=null;
- try {
- method= service.getClass().getMethod(rpcRequest.getMethodName(), rpcRequest.getParamsType());
- Object invoke=method.invoke(service,rpcRequest.getParams());
- return RpcResponse.sussess(invoke);
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
- e.printStackTrace();
- System.out.println("方法执行错误");
- return RpcResponse.fail();
- }
- }
-}
diff --git a/version1/src/main/java/part3/Server/netty/nettyInitializer/NettyServerInitializer.java b/version1/src/main/java/part3/Server/netty/nettyInitializer/NettyServerInitializer.java
deleted file mode 100644
index aff1fdb..0000000
--- a/version1/src/main/java/part3/Server/netty/nettyInitializer/NettyServerInitializer.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package part3.Server.netty.nettyInitializer;
-
-
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelPipeline;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
-import io.netty.handler.codec.LengthFieldPrepender;
-import io.netty.handler.codec.serialization.ClassResolver;
-import io.netty.handler.codec.serialization.ObjectDecoder;
-import io.netty.handler.codec.serialization.ObjectEncoder;
-import lombok.AllArgsConstructor;
-import part3.Server.provider.ServiceProvider;
-import part3.Server.netty.handler.NettyRPCServerHandler;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/26 16:15
- */
-@AllArgsConstructor
-public class NettyServerInitializer extends ChannelInitializer {
- private ServiceProvider serviceProvider;
- @Override
- protected void initChannel(SocketChannel ch) throws Exception {
- ChannelPipeline pipeline = ch.pipeline();
- //消息格式 【长度】【消息体】,解决沾包问题
- pipeline.addLast(
- new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE,0,4,0,4));
- //计算当前待发送消息的长度,写入到前4个字节中
- pipeline.addLast(new LengthFieldPrepender(4));
-
- //使用Java序列化方式,netty的自带的解码编码支持传输这种结构
- pipeline.addLast(new ObjectEncoder());
- //使用了Netty中的ObjectDecoder,它用于将字节流解码为 Java 对象。
- //在ObjectDecoder的构造函数中传入了一个ClassResolver 对象,用于解析类名并加载相应的类。
- pipeline.addLast(new ObjectDecoder(new ClassResolver() {
- @Override
- public Class> resolve(String className) throws ClassNotFoundException {
- return Class.forName(className);
- }
- }));
-
- pipeline.addLast(new NettyRPCServerHandler(serviceProvider));
- }
-}
diff --git a/version1/src/main/java/part3/Server/provider/ServiceProvider.java b/version1/src/main/java/part3/Server/provider/ServiceProvider.java
deleted file mode 100644
index fa39e0a..0000000
--- a/version1/src/main/java/part3/Server/provider/ServiceProvider.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package part3.Server.provider;
-
-import part3.Server.serviceRegister.ServiceRegister;
-import part3.Server.serviceRegister.impl.ZKServiceRegister;
-
-import java.net.InetSocketAddress;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/16 17:35
- */
-public class ServiceProvider {
- private Map interfaceProvider;
-
- private int port;
- private String host;
- //注册服务类
- private ServiceRegister serviceRegister;
-
- public ServiceProvider(String host,int port){
- //需要传入服务端自身的网络地址
- this.host=host;
- this.port=port;
- this.interfaceProvider=new HashMap<>();
- this.serviceRegister=new ZKServiceRegister();
- }
-
- public void provideServiceInterface(Object service){
- String serviceName=service.getClass().getName();
- Class>[] interfaceName=service.getClass().getInterfaces();
-
- for (Class> clazz:interfaceName){
- //本机的映射表
- interfaceProvider.put(clazz.getName(),service);
- //在注册中心注册服务
- serviceRegister.register(clazz.getName(),new InetSocketAddress(host,port));
- }
- }
-
- public Object getService(String interfaceName){
- return interfaceProvider.get(interfaceName);
- }
-
-}
diff --git a/version1/src/main/java/part3/Server/server/RpcServer.java b/version1/src/main/java/part3/Server/server/RpcServer.java
deleted file mode 100644
index d0a0fa5..0000000
--- a/version1/src/main/java/part3/Server/server/RpcServer.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package part3.Server.server;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/12 11:26
- */
-public interface RpcServer {
- void start(int port);
- void stop();
-}
diff --git a/version1/src/main/java/part3/Server/server/impl/NettyRPCRPCServer.java b/version1/src/main/java/part3/Server/server/impl/NettyRPCRPCServer.java
deleted file mode 100644
index 2e4a34b..0000000
--- a/version1/src/main/java/part3/Server/server/impl/NettyRPCRPCServer.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package part3.Server.server.impl;
-
-import io.netty.bootstrap.ServerBootstrap;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.channel.socket.nio.NioServerSocketChannel;
-import lombok.AllArgsConstructor;
-import part3.Server.netty.nettyInitializer.NettyServerInitializer;
-import part3.Server.provider.ServiceProvider;
-import part3.Server.server.RpcServer;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/26 14:01
- */
-@AllArgsConstructor
-public class NettyRPCRPCServer implements RpcServer {
- private ServiceProvider serviceProvider;
- @Override
- public void start(int port) {
- // netty 服务线程组boss负责建立连接, work负责具体的请求
- NioEventLoopGroup bossGroup = new NioEventLoopGroup();
- NioEventLoopGroup workGroup = new NioEventLoopGroup();
- System.out.println("netty服务端启动了");
- try {
- //启动netty服务器
- ServerBootstrap serverBootstrap = new ServerBootstrap();
- //初始化
- serverBootstrap.group(bossGroup,workGroup).channel(NioServerSocketChannel.class)
- .childHandler(new NettyServerInitializer(serviceProvider));
- //同步堵塞
- ChannelFuture channelFuture=serverBootstrap.bind(port).sync();
- //死循环监听
- channelFuture.channel().closeFuture().sync();
- }catch (InterruptedException e){
- e.printStackTrace();
- }finally {
- bossGroup.shutdownGracefully();
- workGroup.shutdownGracefully();
- }
- }
-
- @Override
- public void stop() {
-
- }
-}
diff --git a/version1/src/main/java/part3/Server/server/impl/SimpleRPCRPCServer.java b/version1/src/main/java/part3/Server/server/impl/SimpleRPCRPCServer.java
deleted file mode 100644
index f77262a..0000000
--- a/version1/src/main/java/part3/Server/server/impl/SimpleRPCRPCServer.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package part3.Server.server.impl;
-
-
-import lombok.AllArgsConstructor;
-import part3.Server.provider.ServiceProvider;
-import part3.Server.server.RpcServer;
-import part3.Server.server.work.WorkThread;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/12 11:37
- */
-@AllArgsConstructor
-public class SimpleRPCRPCServer implements RpcServer {
- private ServiceProvider serviceProvide;
- @Override
- public void start(int port) {
- try {
- ServerSocket serverSocket=new ServerSocket(port);
- System.out.println("服务器启动了");
- while (true) {
- Socket socket = serverSocket.accept();
- new Thread(new WorkThread(socket,serviceProvide)).start();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void stop() {
-
- }
-}
diff --git a/version1/src/main/java/part3/Server/server/work/WorkThread.java b/version1/src/main/java/part3/Server/server/work/WorkThread.java
deleted file mode 100644
index 32eb732..0000000
--- a/version1/src/main/java/part3/Server/server/work/WorkThread.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package part3.Server.server.work;
-
-
-import lombok.AllArgsConstructor;
-import part3.common.Message.RpcRequest;
-import part3.common.Message.RpcResponse;
-import part3.Server.provider.ServiceProvider;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.Socket;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/14 17:39
- */
-@AllArgsConstructor
-public class WorkThread implements Runnable{
- private Socket socket;
- private ServiceProvider serviceProvide;
- @Override
- public void run() {
- try {
- ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
- ObjectInputStream ois=new ObjectInputStream(socket.getInputStream());
- //读取客户端传过来的request
- RpcRequest rpcRequest = (RpcRequest) ois.readObject();
- //反射调用服务方法获取返回值
- RpcResponse rpcResponse=getResponse(rpcRequest);
- //向客户端写入response
- oos.writeObject(rpcResponse);
- oos.flush();
- } catch (IOException | ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- private RpcResponse getResponse(RpcRequest rpcRequest){
- //得到服务名
- String interfaceName=rpcRequest.getInterfaceName();
- //得到服务端相应服务实现类
- Object service = serviceProvide.getService(interfaceName);
- //反射调用方法
- Method method=null;
- try {
- method= service.getClass().getMethod(rpcRequest.getMethodName(), rpcRequest.getParamsType());
- Object invoke=method.invoke(service,rpcRequest.getParams());
- return RpcResponse.sussess(invoke);
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
- e.printStackTrace();
- System.out.println("方法执行错误");
- return RpcResponse.fail();
- }
- }
-}
diff --git a/version1/src/main/java/part3/Server/serviceRegister/ServiceRegister.java b/version1/src/main/java/part3/Server/serviceRegister/ServiceRegister.java
deleted file mode 100644
index 65c5be3..0000000
--- a/version1/src/main/java/part3/Server/serviceRegister/ServiceRegister.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package part3.Server.serviceRegister;
-
-import java.net.InetSocketAddress;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/5/3 16:58
- */
-// 服务注册接口
-public interface ServiceRegister {
- // 注册:保存服务与地址。
- void register(String serviceName, InetSocketAddress serviceAddress);
-
-}
diff --git a/version1/src/main/java/part3/Server/serviceRegister/impl/ZKServiceRegister.java b/version1/src/main/java/part3/Server/serviceRegister/impl/ZKServiceRegister.java
deleted file mode 100644
index 9fe332a..0000000
--- a/version1/src/main/java/part3/Server/serviceRegister/impl/ZKServiceRegister.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package part3.Server.serviceRegister.impl;
-
-import org.apache.curator.RetryPolicy;
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.CuratorFrameworkFactory;
-import org.apache.curator.retry.ExponentialBackoffRetry;
-import org.apache.zookeeper.CreateMode;
-import part3.Server.serviceRegister.ServiceRegister;
-
-import java.net.InetSocketAddress;
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/5/3 17:28
- */
-public class ZKServiceRegister implements ServiceRegister {
- // curator 提供的zookeeper客户端
- private CuratorFramework client;
- //zookeeper根路径节点
- private static final String ROOT_PATH = "MyRPC";
-
- //负责zookeeper客户端的初始化,并与zookeeper服务端进行连接
- public ZKServiceRegister(){
- // 指数时间重试
- RetryPolicy policy = new ExponentialBackoffRetry(1000, 3);
- // zookeeper的地址固定,不管是服务提供者还是,消费者都要与之建立连接
- // sessionTimeoutMs 与 zoo.cfg中的tickTime 有关系,
- // zk还会根据minSessionTimeout与maxSessionTimeout两个参数重新调整最后的超时值。默认分别为tickTime 的2倍和20倍
- // 使用心跳监听状态
- this.client = CuratorFrameworkFactory.builder().connectString("127.0.0.1:2181")
- .sessionTimeoutMs(40000).retryPolicy(policy).namespace(ROOT_PATH).build();
- this.client.start();
- System.out.println("zookeeper 连接成功");
- }
- //注册服务到注册中心
- @Override
- public void register(String serviceName, InetSocketAddress serviceAddress) {
- try {
- // serviceName创建成永久节点,服务提供者下线时,不删服务名,只删地址
- if(client.checkExists().forPath("/" + serviceName) == null){
- client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath("/" + serviceName);
- }
- // 路径地址,一个/代表一个节点
- String path = "/" + serviceName +"/"+ getServiceAddress(serviceAddress);
- // 临时节点,服务器下线就删除节点
- client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(path);
- } catch (Exception e) {
- System.out.println("此服务已存在");
- }
- }
- // 地址 -> XXX.XXX.XXX.XXX:port 字符串
- private String getServiceAddress(InetSocketAddress serverAddress) {
- return serverAddress.getHostName() +
- ":" +
- serverAddress.getPort();
- }
- // 字符串解析为地址
- private InetSocketAddress parseAddress(String address) {
- String[] result = address.split(":");
- return new InetSocketAddress(result[0], Integer.parseInt(result[1]));
- }
-}
diff --git a/version1/src/main/java/part3/common/Message/RpcRequest.java b/version1/src/main/java/part3/common/Message/RpcRequest.java
deleted file mode 100644
index 63ba31f..0000000
--- a/version1/src/main/java/part3/common/Message/RpcRequest.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package part3.common.Message;
-
-import lombok.Builder;
-import lombok.Data;
-
-import java.io.Serializable;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/1 18:30
- * 定义发送的消息格式
- */
-@Data
-@Builder
-public class RpcRequest implements Serializable {
- //服务类名,客户端只知道接口
- private String interfaceName;
- //调用的方法名
- private String methodName;
- //参数列表
- private Object[] params;
- //参数类型
- private Class>[] paramsType;
-}
diff --git a/version1/src/main/java/part3/common/Message/RpcResponse.java b/version1/src/main/java/part3/common/Message/RpcResponse.java
deleted file mode 100644
index 537b630..0000000
--- a/version1/src/main/java/part3/common/Message/RpcResponse.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package part3.common.Message;
-
-import lombok.Builder;
-import lombok.Data;
-
-import java.io.Serializable;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/1 19:18
- */
-@Data
-@Builder
-public class RpcResponse implements Serializable {
- //状态信息
- private int code;
- private String message;
- //具体数据
- private Object data;
-
- public static RpcResponse sussess(Object data){
- return RpcResponse.builder().code(200).data(data).build();
- }
- public static RpcResponse fail(){
- return RpcResponse.builder().code(500).message("服务器发生错误").build();
- }
-}
-
diff --git a/version1/src/main/java/part3/common/service/Impl/UserServiceImpl.java b/version1/src/main/java/part3/common/service/Impl/UserServiceImpl.java
deleted file mode 100644
index 6fc44b2..0000000
--- a/version1/src/main/java/part3/common/service/Impl/UserServiceImpl.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package part3.common.service.Impl;
-
-
-import part3.common.pojo.User;
-import part3.common.service.UserService;
-
-import java.util.Random;
-import java.util.UUID;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/1/28 16:28
- */
-public class UserServiceImpl implements UserService {
- @Override
- public User getUserByUserId(Integer id) {
- System.out.println("客户端查询了"+id+"的用户");
- // 模拟从数据库中取用户的行为
- Random random = new Random();
- User user = User.builder().userName(UUID.randomUUID().toString())
- .id(id)
- .sex(random.nextBoolean()).build();
- return user;
- }
-
- @Override
- public Integer insertUserId(User user) {
- System.out.println("插入数据成功"+user.getUserName());
- return user.getId();
- }
-}
\ No newline at end of file
diff --git a/version1/src/main/java/part3/common/service/UserService.java b/version1/src/main/java/part3/common/service/UserService.java
deleted file mode 100644
index 07efce0..0000000
--- a/version1/src/main/java/part3/common/service/UserService.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package part3.common.service;
-
-
-import part3.common.pojo.User;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/1/28 16:27
- */
-public interface UserService {
- // 客户端通过这个接口调用服务端的实现类
- User getUserByUserId(Integer id);
- //新增一个功能
- Integer insertUserId(User user);
-}
diff --git a/version1/target/classes/log4j.properties b/version1/target/classes/log4j.properties
deleted file mode 100644
index 4e012fe..0000000
--- a/version1/target/classes/log4j.properties
+++ /dev/null
@@ -1,8 +0,0 @@
-log4j.rootLogger=ERROR, stdout
-log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-
-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
-log4j.appender.logfile=org.apache.log4j.FileAppender
-log4j.appender.logfile.File=target/spring.log log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
-log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
diff --git a/version1/target/classes/part1/Client/IOClient.class b/version1/target/classes/part1/Client/IOClient.class
deleted file mode 100644
index 3887808..0000000
Binary files a/version1/target/classes/part1/Client/IOClient.class and /dev/null differ
diff --git a/version1/target/classes/part1/Client/TestClient.class b/version1/target/classes/part1/Client/TestClient.class
deleted file mode 100644
index 0ccacd2..0000000
Binary files a/version1/target/classes/part1/Client/TestClient.class and /dev/null differ
diff --git a/version1/target/classes/part1/Client/proxy/ClientProxy.class b/version1/target/classes/part1/Client/proxy/ClientProxy.class
deleted file mode 100644
index 494800e..0000000
Binary files a/version1/target/classes/part1/Client/proxy/ClientProxy.class and /dev/null differ
diff --git a/version1/target/classes/part1/Server/TestServer.class b/version1/target/classes/part1/Server/TestServer.class
deleted file mode 100644
index f5eeb9c..0000000
Binary files a/version1/target/classes/part1/Server/TestServer.class and /dev/null differ
diff --git a/version1/target/classes/part1/Server/provider/ServiceProvider.class b/version1/target/classes/part1/Server/provider/ServiceProvider.class
deleted file mode 100644
index c99abe0..0000000
Binary files a/version1/target/classes/part1/Server/provider/ServiceProvider.class and /dev/null differ
diff --git a/version1/target/classes/part1/Server/server/RpcServer.class b/version1/target/classes/part1/Server/server/RpcServer.class
deleted file mode 100644
index 50b6f39..0000000
Binary files a/version1/target/classes/part1/Server/server/RpcServer.class and /dev/null differ
diff --git a/version1/target/classes/part1/Server/server/impl/SimpleRPCRPCServer.class b/version1/target/classes/part1/Server/server/impl/SimpleRPCRPCServer.class
deleted file mode 100644
index 561ea06..0000000
Binary files a/version1/target/classes/part1/Server/server/impl/SimpleRPCRPCServer.class and /dev/null differ
diff --git a/version1/target/classes/part1/Server/server/impl/ThreadPoolRPCRPCServer.class b/version1/target/classes/part1/Server/server/impl/ThreadPoolRPCRPCServer.class
deleted file mode 100644
index 29a7d90..0000000
Binary files a/version1/target/classes/part1/Server/server/impl/ThreadPoolRPCRPCServer.class and /dev/null differ
diff --git a/version1/target/classes/part1/common/Message/RpcRequest$RpcRequestBuilder.class b/version1/target/classes/part1/common/Message/RpcRequest$RpcRequestBuilder.class
deleted file mode 100644
index e74801c..0000000
Binary files a/version1/target/classes/part1/common/Message/RpcRequest$RpcRequestBuilder.class and /dev/null differ
diff --git a/version1/target/classes/part1/common/Message/RpcRequest.class b/version1/target/classes/part1/common/Message/RpcRequest.class
deleted file mode 100644
index 681fc3d..0000000
Binary files a/version1/target/classes/part1/common/Message/RpcRequest.class and /dev/null differ
diff --git a/version1/target/classes/part1/common/Message/RpcResponse$RpcResponseBuilder.class b/version1/target/classes/part1/common/Message/RpcResponse$RpcResponseBuilder.class
deleted file mode 100644
index 5944e04..0000000
Binary files a/version1/target/classes/part1/common/Message/RpcResponse$RpcResponseBuilder.class and /dev/null differ
diff --git a/version1/target/classes/part1/common/Message/RpcResponse.class b/version1/target/classes/part1/common/Message/RpcResponse.class
deleted file mode 100644
index 1176cbb..0000000
Binary files a/version1/target/classes/part1/common/Message/RpcResponse.class and /dev/null differ
diff --git a/version1/target/classes/part1/common/pojo/User$UserBuilder.class b/version1/target/classes/part1/common/pojo/User$UserBuilder.class
deleted file mode 100644
index 4dad3e5..0000000
Binary files a/version1/target/classes/part1/common/pojo/User$UserBuilder.class and /dev/null differ
diff --git a/version1/target/classes/part1/common/pojo/User.class b/version1/target/classes/part1/common/pojo/User.class
deleted file mode 100644
index 5639736..0000000
Binary files a/version1/target/classes/part1/common/pojo/User.class and /dev/null differ
diff --git a/version1/target/classes/part1/common/service/Impl/UserServiceImpl.class b/version1/target/classes/part1/common/service/Impl/UserServiceImpl.class
deleted file mode 100644
index 4f66e73..0000000
Binary files a/version1/target/classes/part1/common/service/Impl/UserServiceImpl.class and /dev/null differ
diff --git a/version1/target/classes/part1/common/service/UserService.class b/version1/target/classes/part1/common/service/UserService.class
deleted file mode 100644
index 216f6e4..0000000
Binary files a/version1/target/classes/part1/common/service/UserService.class and /dev/null differ
diff --git a/version1/target/classes/part2/Client/IOClient.class b/version1/target/classes/part2/Client/IOClient.class
deleted file mode 100644
index 56de353..0000000
Binary files a/version1/target/classes/part2/Client/IOClient.class and /dev/null differ
diff --git a/version1/target/classes/part2/Client/TestClient.class b/version1/target/classes/part2/Client/TestClient.class
deleted file mode 100644
index 9dae865..0000000
Binary files a/version1/target/classes/part2/Client/TestClient.class and /dev/null differ
diff --git a/version1/target/classes/part2/Client/netty/handler/NettyClientHandler.class b/version1/target/classes/part2/Client/netty/handler/NettyClientHandler.class
deleted file mode 100644
index 1f6f7ec..0000000
Binary files a/version1/target/classes/part2/Client/netty/handler/NettyClientHandler.class and /dev/null differ
diff --git a/version1/target/classes/part2/Client/netty/nettyInitializer/NettyClientInitializer$1.class b/version1/target/classes/part2/Client/netty/nettyInitializer/NettyClientInitializer$1.class
deleted file mode 100644
index 9999e18..0000000
Binary files a/version1/target/classes/part2/Client/netty/nettyInitializer/NettyClientInitializer$1.class and /dev/null differ
diff --git a/version1/target/classes/part2/Client/netty/nettyInitializer/NettyClientInitializer.class b/version1/target/classes/part2/Client/netty/nettyInitializer/NettyClientInitializer.class
deleted file mode 100644
index 9f22eb6..0000000
Binary files a/version1/target/classes/part2/Client/netty/nettyInitializer/NettyClientInitializer.class and /dev/null differ
diff --git a/version1/target/classes/part2/Client/proxy/ClientProxy.class b/version1/target/classes/part2/Client/proxy/ClientProxy.class
deleted file mode 100644
index 994803e..0000000
Binary files a/version1/target/classes/part2/Client/proxy/ClientProxy.class and /dev/null differ
diff --git a/version1/target/classes/part2/Client/rpcClient/RpcClient.class b/version1/target/classes/part2/Client/rpcClient/RpcClient.class
deleted file mode 100644
index 0038bab..0000000
Binary files a/version1/target/classes/part2/Client/rpcClient/RpcClient.class and /dev/null differ
diff --git a/version1/target/classes/part2/Client/rpcClient/impl/NettyRpcClient.class b/version1/target/classes/part2/Client/rpcClient/impl/NettyRpcClient.class
deleted file mode 100644
index 4192d71..0000000
Binary files a/version1/target/classes/part2/Client/rpcClient/impl/NettyRpcClient.class and /dev/null differ
diff --git a/version1/target/classes/part2/Client/rpcClient/impl/SimpleSocketRpcCilent.class b/version1/target/classes/part2/Client/rpcClient/impl/SimpleSocketRpcCilent.class
deleted file mode 100644
index 84f7e0d..0000000
Binary files a/version1/target/classes/part2/Client/rpcClient/impl/SimpleSocketRpcCilent.class and /dev/null differ
diff --git a/version1/target/classes/part2/Server/TestServer.class b/version1/target/classes/part2/Server/TestServer.class
deleted file mode 100644
index 1206f91..0000000
Binary files a/version1/target/classes/part2/Server/TestServer.class and /dev/null differ
diff --git a/version1/target/classes/part2/Server/netty/handler/NettyRPCServerHandler.class b/version1/target/classes/part2/Server/netty/handler/NettyRPCServerHandler.class
deleted file mode 100644
index 465acff..0000000
Binary files a/version1/target/classes/part2/Server/netty/handler/NettyRPCServerHandler.class and /dev/null differ
diff --git a/version1/target/classes/part2/Server/netty/nettyInitializer/NettyServerInitializer$1.class b/version1/target/classes/part2/Server/netty/nettyInitializer/NettyServerInitializer$1.class
deleted file mode 100644
index 9fc3255..0000000
Binary files a/version1/target/classes/part2/Server/netty/nettyInitializer/NettyServerInitializer$1.class and /dev/null differ
diff --git a/version1/target/classes/part2/Server/netty/nettyInitializer/NettyServerInitializer.class b/version1/target/classes/part2/Server/netty/nettyInitializer/NettyServerInitializer.class
deleted file mode 100644
index 7527f69..0000000
Binary files a/version1/target/classes/part2/Server/netty/nettyInitializer/NettyServerInitializer.class and /dev/null differ
diff --git a/version1/target/classes/part2/Server/provider/ServiceProvider.class b/version1/target/classes/part2/Server/provider/ServiceProvider.class
deleted file mode 100644
index 2e22d58..0000000
Binary files a/version1/target/classes/part2/Server/provider/ServiceProvider.class and /dev/null differ
diff --git a/version1/target/classes/part2/Server/server/RpcServer.class b/version1/target/classes/part2/Server/server/RpcServer.class
deleted file mode 100644
index c503b94..0000000
Binary files a/version1/target/classes/part2/Server/server/RpcServer.class and /dev/null differ
diff --git a/version1/target/classes/part2/Server/server/impl/NettyRPCRPCServer.class b/version1/target/classes/part2/Server/server/impl/NettyRPCRPCServer.class
deleted file mode 100644
index c3d4155..0000000
Binary files a/version1/target/classes/part2/Server/server/impl/NettyRPCRPCServer.class and /dev/null differ
diff --git a/version1/target/classes/part2/Server/server/impl/SimpleRPCRPCServer.class b/version1/target/classes/part2/Server/server/impl/SimpleRPCRPCServer.class
deleted file mode 100644
index 8c1adcc..0000000
Binary files a/version1/target/classes/part2/Server/server/impl/SimpleRPCRPCServer.class and /dev/null differ
diff --git a/version1/target/classes/part2/Server/server/impl/ThreadPoolRPCRPCServer.class b/version1/target/classes/part2/Server/server/impl/ThreadPoolRPCRPCServer.class
deleted file mode 100644
index 3ef15ef..0000000
Binary files a/version1/target/classes/part2/Server/server/impl/ThreadPoolRPCRPCServer.class and /dev/null differ
diff --git a/version1/target/classes/part2/Server/server/work/WorkThread.class b/version1/target/classes/part2/Server/server/work/WorkThread.class
deleted file mode 100644
index 99c3e6c..0000000
Binary files a/version1/target/classes/part2/Server/server/work/WorkThread.class and /dev/null differ
diff --git a/version1/target/classes/part2/common/Message/RpcRequest$RpcRequestBuilder.class b/version1/target/classes/part2/common/Message/RpcRequest$RpcRequestBuilder.class
deleted file mode 100644
index fbc702b..0000000
Binary files a/version1/target/classes/part2/common/Message/RpcRequest$RpcRequestBuilder.class and /dev/null differ
diff --git a/version1/target/classes/part2/common/Message/RpcRequest.class b/version1/target/classes/part2/common/Message/RpcRequest.class
deleted file mode 100644
index cb983fd..0000000
Binary files a/version1/target/classes/part2/common/Message/RpcRequest.class and /dev/null differ
diff --git a/version1/target/classes/part2/common/Message/RpcResponse$RpcResponseBuilder.class b/version1/target/classes/part2/common/Message/RpcResponse$RpcResponseBuilder.class
deleted file mode 100644
index eaa4c05..0000000
Binary files a/version1/target/classes/part2/common/Message/RpcResponse$RpcResponseBuilder.class and /dev/null differ
diff --git a/version1/target/classes/part2/common/Message/RpcResponse.class b/version1/target/classes/part2/common/Message/RpcResponse.class
deleted file mode 100644
index 33f74ff..0000000
Binary files a/version1/target/classes/part2/common/Message/RpcResponse.class and /dev/null differ
diff --git a/version1/target/classes/part2/common/pojo/User$UserBuilder.class b/version1/target/classes/part2/common/pojo/User$UserBuilder.class
deleted file mode 100644
index 76e3c45..0000000
Binary files a/version1/target/classes/part2/common/pojo/User$UserBuilder.class and /dev/null differ
diff --git a/version1/target/classes/part2/common/pojo/User.class b/version1/target/classes/part2/common/pojo/User.class
deleted file mode 100644
index c59ad76..0000000
Binary files a/version1/target/classes/part2/common/pojo/User.class and /dev/null differ
diff --git a/version1/target/classes/part2/common/service/Impl/UserServiceImpl.class b/version1/target/classes/part2/common/service/Impl/UserServiceImpl.class
deleted file mode 100644
index 9ed2ee7..0000000
Binary files a/version1/target/classes/part2/common/service/Impl/UserServiceImpl.class and /dev/null differ
diff --git a/version1/target/classes/part2/common/service/UserService.class b/version1/target/classes/part2/common/service/UserService.class
deleted file mode 100644
index 51f12d3..0000000
Binary files a/version1/target/classes/part2/common/service/UserService.class and /dev/null differ
diff --git a/version1/target/classes/part3/Client/TestClient.class b/version1/target/classes/part3/Client/TestClient.class
deleted file mode 100644
index 7e27342..0000000
Binary files a/version1/target/classes/part3/Client/TestClient.class and /dev/null differ
diff --git a/version1/target/classes/part3/Client/netty/handler/NettyClientHandler.class b/version1/target/classes/part3/Client/netty/handler/NettyClientHandler.class
deleted file mode 100644
index 4d07169..0000000
Binary files a/version1/target/classes/part3/Client/netty/handler/NettyClientHandler.class and /dev/null differ
diff --git a/version1/target/classes/part3/Client/netty/nettyInitializer/NettyClientInitializer$1.class b/version1/target/classes/part3/Client/netty/nettyInitializer/NettyClientInitializer$1.class
deleted file mode 100644
index 15ceae6..0000000
Binary files a/version1/target/classes/part3/Client/netty/nettyInitializer/NettyClientInitializer$1.class and /dev/null differ
diff --git a/version1/target/classes/part3/Client/netty/nettyInitializer/NettyClientInitializer.class b/version1/target/classes/part3/Client/netty/nettyInitializer/NettyClientInitializer.class
deleted file mode 100644
index 322f0e7..0000000
Binary files a/version1/target/classes/part3/Client/netty/nettyInitializer/NettyClientInitializer.class and /dev/null differ
diff --git a/version1/target/classes/part3/Client/proxy/ClientProxy.class b/version1/target/classes/part3/Client/proxy/ClientProxy.class
deleted file mode 100644
index 9175c23..0000000
Binary files a/version1/target/classes/part3/Client/proxy/ClientProxy.class and /dev/null differ
diff --git a/version1/target/classes/part3/Client/rpcClient/RpcClient.class b/version1/target/classes/part3/Client/rpcClient/RpcClient.class
deleted file mode 100644
index 5a806b0..0000000
Binary files a/version1/target/classes/part3/Client/rpcClient/RpcClient.class and /dev/null differ
diff --git a/version1/target/classes/part3/Client/rpcClient/impl/NettyRpcClient.class b/version1/target/classes/part3/Client/rpcClient/impl/NettyRpcClient.class
deleted file mode 100644
index ff59289..0000000
Binary files a/version1/target/classes/part3/Client/rpcClient/impl/NettyRpcClient.class and /dev/null differ
diff --git a/version1/target/classes/part3/Client/rpcClient/impl/SimpleSocketRpcCilent.class b/version1/target/classes/part3/Client/rpcClient/impl/SimpleSocketRpcCilent.class
deleted file mode 100644
index 3307eeb..0000000
Binary files a/version1/target/classes/part3/Client/rpcClient/impl/SimpleSocketRpcCilent.class and /dev/null differ
diff --git a/version1/target/classes/part3/Client/serviceCenter/ServiceCenter.class b/version1/target/classes/part3/Client/serviceCenter/ServiceCenter.class
deleted file mode 100644
index 0cace88..0000000
Binary files a/version1/target/classes/part3/Client/serviceCenter/ServiceCenter.class and /dev/null differ
diff --git a/version1/target/classes/part3/Client/serviceCenter/ZKServiceCenter.class b/version1/target/classes/part3/Client/serviceCenter/ZKServiceCenter.class
deleted file mode 100644
index 69e72bb..0000000
Binary files a/version1/target/classes/part3/Client/serviceCenter/ZKServiceCenter.class and /dev/null differ
diff --git a/version1/target/classes/part3/Server/TestServer.class b/version1/target/classes/part3/Server/TestServer.class
deleted file mode 100644
index 9901b75..0000000
Binary files a/version1/target/classes/part3/Server/TestServer.class and /dev/null differ
diff --git a/version1/target/classes/part3/Server/netty/handler/NettyRPCServerHandler.class b/version1/target/classes/part3/Server/netty/handler/NettyRPCServerHandler.class
deleted file mode 100644
index 2d7b34d..0000000
Binary files a/version1/target/classes/part3/Server/netty/handler/NettyRPCServerHandler.class and /dev/null differ
diff --git a/version1/target/classes/part3/Server/netty/nettyInitializer/NettyServerInitializer$1.class b/version1/target/classes/part3/Server/netty/nettyInitializer/NettyServerInitializer$1.class
deleted file mode 100644
index 35a2e4a..0000000
Binary files a/version1/target/classes/part3/Server/netty/nettyInitializer/NettyServerInitializer$1.class and /dev/null differ
diff --git a/version1/target/classes/part3/Server/netty/nettyInitializer/NettyServerInitializer.class b/version1/target/classes/part3/Server/netty/nettyInitializer/NettyServerInitializer.class
deleted file mode 100644
index f6d5010..0000000
Binary files a/version1/target/classes/part3/Server/netty/nettyInitializer/NettyServerInitializer.class and /dev/null differ
diff --git a/version1/target/classes/part3/Server/provider/ServiceProvider.class b/version1/target/classes/part3/Server/provider/ServiceProvider.class
deleted file mode 100644
index de60431..0000000
Binary files a/version1/target/classes/part3/Server/provider/ServiceProvider.class and /dev/null differ
diff --git a/version1/target/classes/part3/Server/server/RpcServer.class b/version1/target/classes/part3/Server/server/RpcServer.class
deleted file mode 100644
index 7aa6e68..0000000
Binary files a/version1/target/classes/part3/Server/server/RpcServer.class and /dev/null differ
diff --git a/version1/target/classes/part3/Server/server/impl/NettyRPCRPCServer.class b/version1/target/classes/part3/Server/server/impl/NettyRPCRPCServer.class
deleted file mode 100644
index 4925c11..0000000
Binary files a/version1/target/classes/part3/Server/server/impl/NettyRPCRPCServer.class and /dev/null differ
diff --git a/version1/target/classes/part3/Server/server/impl/SimpleRPCRPCServer.class b/version1/target/classes/part3/Server/server/impl/SimpleRPCRPCServer.class
deleted file mode 100644
index bd2c8f6..0000000
Binary files a/version1/target/classes/part3/Server/server/impl/SimpleRPCRPCServer.class and /dev/null differ
diff --git a/version1/target/classes/part3/Server/server/work/WorkThread.class b/version1/target/classes/part3/Server/server/work/WorkThread.class
deleted file mode 100644
index 05f64e6..0000000
Binary files a/version1/target/classes/part3/Server/server/work/WorkThread.class and /dev/null differ
diff --git a/version1/target/classes/part3/Server/serviceRegister/ServiceRegister.class b/version1/target/classes/part3/Server/serviceRegister/ServiceRegister.class
deleted file mode 100644
index 95ca80a..0000000
Binary files a/version1/target/classes/part3/Server/serviceRegister/ServiceRegister.class and /dev/null differ
diff --git a/version1/target/classes/part3/Server/serviceRegister/impl/ZKServiceRegister.class b/version1/target/classes/part3/Server/serviceRegister/impl/ZKServiceRegister.class
deleted file mode 100644
index f281b3c..0000000
Binary files a/version1/target/classes/part3/Server/serviceRegister/impl/ZKServiceRegister.class and /dev/null differ
diff --git a/version1/target/classes/part3/common/Message/RpcRequest$RpcRequestBuilder.class b/version1/target/classes/part3/common/Message/RpcRequest$RpcRequestBuilder.class
deleted file mode 100644
index 2b9369e..0000000
Binary files a/version1/target/classes/part3/common/Message/RpcRequest$RpcRequestBuilder.class and /dev/null differ
diff --git a/version1/target/classes/part3/common/Message/RpcRequest.class b/version1/target/classes/part3/common/Message/RpcRequest.class
deleted file mode 100644
index 2b045ea..0000000
Binary files a/version1/target/classes/part3/common/Message/RpcRequest.class and /dev/null differ
diff --git a/version1/target/classes/part3/common/Message/RpcResponse$RpcResponseBuilder.class b/version1/target/classes/part3/common/Message/RpcResponse$RpcResponseBuilder.class
deleted file mode 100644
index 4108421..0000000
Binary files a/version1/target/classes/part3/common/Message/RpcResponse$RpcResponseBuilder.class and /dev/null differ
diff --git a/version1/target/classes/part3/common/Message/RpcResponse.class b/version1/target/classes/part3/common/Message/RpcResponse.class
deleted file mode 100644
index 3321fd0..0000000
Binary files a/version1/target/classes/part3/common/Message/RpcResponse.class and /dev/null differ
diff --git a/version1/target/classes/part3/common/pojo/User$UserBuilder.class b/version1/target/classes/part3/common/pojo/User$UserBuilder.class
deleted file mode 100644
index 08843db..0000000
Binary files a/version1/target/classes/part3/common/pojo/User$UserBuilder.class and /dev/null differ
diff --git a/version1/target/classes/part3/common/pojo/User.class b/version1/target/classes/part3/common/pojo/User.class
deleted file mode 100644
index c6480d7..0000000
Binary files a/version1/target/classes/part3/common/pojo/User.class and /dev/null differ
diff --git a/version1/target/classes/part3/common/service/Impl/UserServiceImpl.class b/version1/target/classes/part3/common/service/Impl/UserServiceImpl.class
deleted file mode 100644
index 1811931..0000000
Binary files a/version1/target/classes/part3/common/service/Impl/UserServiceImpl.class and /dev/null differ
diff --git a/version1/target/classes/part3/common/service/UserService.class b/version1/target/classes/part3/common/service/UserService.class
deleted file mode 100644
index a2e6fc6..0000000
Binary files a/version1/target/classes/part3/common/service/UserService.class and /dev/null differ
diff --git a/version2/pom.xml b/version2/pom.xml
deleted file mode 100644
index 4626ed3..0000000
--- a/version2/pom.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
- 4.0.0
-
- org.example
- version2
- 1.0-SNAPSHOT
-
-
- 8
- 8
- UTF-8
-
-
-
- org.projectlombok
- lombok
- 1.18.30
- compile
-
-
- org.slf4j
- slf4j-log4j12
- 1.7.25
-
-
- org.apache.logging.log4j
- log4j-1.2-api
- 2.8.2
-
-
-
- io.netty
- netty-all
- 4.1.51.Final
- compile
-
-
-
- org.apache.curator
- curator-recipes
- 5.1.0
-
-
- com.alibaba
- fastjson
- 1.2.83
-
-
-
-
-
\ No newline at end of file
diff --git a/version2/src/main/java/part1/Client/TestClient.java b/version2/src/main/java/part1/Client/TestClient.java
deleted file mode 100644
index 6e6715c..0000000
--- a/version2/src/main/java/part1/Client/TestClient.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package part1.Client;
-
-
-import part1.Client.proxy.ClientProxy;
-import part1.common.service.UserService;
-import part1.common.pojo.User;
-
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/6 18:39
- */
-
-public class TestClient {
- public static void main(String[] args) {
- ClientProxy clientProxy=new ClientProxy();
- //ClientProxy clientProxy=new part2.Client.proxy.ClientProxy("127.0.0.1",9999,0);
- UserService proxy=clientProxy.getProxy(UserService.class);
-
- User user = proxy.getUserByUserId(1);
- System.out.println("从服务端得到的user="+user.toString());
-
- User u=User.builder().id(100).userName("wxx").sex(true).build();
- Integer id = proxy.insertUserId(u);
- System.out.println("向服务端插入user的id"+id);
- }
-}
diff --git a/version2/src/main/java/part1/Client/netty/handler/NettyClientHandler.java b/version2/src/main/java/part1/Client/netty/handler/NettyClientHandler.java
deleted file mode 100644
index 31858c6..0000000
--- a/version2/src/main/java/part1/Client/netty/handler/NettyClientHandler.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package part1.Client.netty.handler;
-
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.SimpleChannelInboundHandler;
-import io.netty.util.AttributeKey;
-import part1.common.Message.RpcResponse;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/26 17:29
- */
-public class NettyClientHandler extends SimpleChannelInboundHandler {
- @Override
- protected void channelRead0(ChannelHandlerContext ctx, RpcResponse response) throws Exception {
- // 接收到response, 给channel设计别名,让sendRequest里读取response
- AttributeKey key = AttributeKey.valueOf("RPCResponse");
- ctx.channel().attr(key).set(response);
- ctx.channel().close();
- }
-
- @Override
- public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
- cause.printStackTrace();
- ctx.close();
- }
-}
diff --git a/version2/src/main/java/part1/Client/netty/nettyInitializer/NettyClientInitializer.java b/version2/src/main/java/part1/Client/netty/nettyInitializer/NettyClientInitializer.java
deleted file mode 100644
index 28e781f..0000000
--- a/version2/src/main/java/part1/Client/netty/nettyInitializer/NettyClientInitializer.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package part1.Client.netty.nettyInitializer;
-
-
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelPipeline;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
-import io.netty.handler.codec.LengthFieldPrepender;
-import io.netty.handler.codec.serialization.ClassResolver;
-import io.netty.handler.codec.serialization.ObjectDecoder;
-import io.netty.handler.codec.serialization.ObjectEncoder;
-import part1.Client.netty.handler.NettyClientHandler;
-import part1.common.serializer.myCode.MyDecoder;
-import part1.common.serializer.myCode.MyEncoder;
-import part1.common.serializer.mySerializer.JsonSerializer;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/26 17:26
- */
-public class NettyClientInitializer extends ChannelInitializer {
- @Override
- protected void initChannel(SocketChannel ch) throws Exception {
- ChannelPipeline pipeline = ch.pipeline();
- //使用自定义的编/解码器
- pipeline.addLast(new MyDecoder());
- pipeline.addLast(new MyEncoder(new JsonSerializer()));
- pipeline.addLast(new NettyClientHandler());
- }
-}
diff --git a/version2/src/main/java/part1/Client/proxy/ClientProxy.java b/version2/src/main/java/part1/Client/proxy/ClientProxy.java
deleted file mode 100644
index c4ff57b..0000000
--- a/version2/src/main/java/part1/Client/proxy/ClientProxy.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package part1.Client.proxy;
-
-
-import part1.Client.rpcClient.RpcClient;
-import part1.Client.rpcClient.impl.NettyRpcClient;
-import part1.common.Message.RpcRequest;
-import part1.common.Message.RpcResponse;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/6 16:49
- */
-public class ClientProxy implements InvocationHandler {
- //传入参数service接口的class对象,反射封装成一个request
-
- private RpcClient rpcClient;
- public ClientProxy(){
- rpcClient=new NettyRpcClient();
- }
-
- //jdk动态代理,每一次代理对象调用方法,都会经过此方法增强(反射获取request对象,socket发送到服务端)
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- //构建request
- RpcRequest request=RpcRequest.builder()
- .interfaceName(method.getDeclaringClass().getName())
- .methodName(method.getName())
- .params(args).paramsType(method.getParameterTypes()).build();
- //数据传输
- RpcResponse response= rpcClient.sendRequest(request);
- return response.getData();
- }
- public T getProxy(Class clazz){
- Object o = Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, this);
- return (T)o;
- }
-}
diff --git a/version2/src/main/java/part1/Client/rpcClient/RpcClient.java b/version2/src/main/java/part1/Client/rpcClient/RpcClient.java
deleted file mode 100644
index c665530..0000000
--- a/version2/src/main/java/part1/Client/rpcClient/RpcClient.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package part1.Client.rpcClient;
-
-import part1.common.Message.RpcRequest;
-import part1.common.Message.RpcResponse;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/5/2 18:55
- */
-public interface RpcClient {
-
- //定义底层通信的方法
- RpcResponse sendRequest(RpcRequest request);
-}
diff --git a/version2/src/main/java/part1/Client/rpcClient/impl/NettyRpcClient.java b/version2/src/main/java/part1/Client/rpcClient/impl/NettyRpcClient.java
deleted file mode 100644
index 4cc425c..0000000
--- a/version2/src/main/java/part1/Client/rpcClient/impl/NettyRpcClient.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package part1.Client.rpcClient.impl;
-
-import io.netty.bootstrap.Bootstrap;
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.EventLoopGroup;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.channel.socket.nio.NioSocketChannel;
-import io.netty.util.AttributeKey;
-import part1.Client.rpcClient.RpcClient;
-import part1.common.Message.RpcRequest;
-import part1.Client.netty.nettyInitializer.NettyClientInitializer;
-import part1.Client.serviceCenter.ServiceCenter;
-import part1.Client.serviceCenter.ZKServiceCenter;
-import part1.common.Message.RpcResponse;
-
-import java.net.InetSocketAddress;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/5/2 19:40
- */
-public class NettyRpcClient implements RpcClient {
-
- private static final Bootstrap bootstrap;
- private static final EventLoopGroup eventLoopGroup;
-
- private ServiceCenter serviceCenter;
- public NettyRpcClient(){
- this.serviceCenter=new ZKServiceCenter();
- }
-
- //netty客户端初始化
- static {
- eventLoopGroup = new NioEventLoopGroup();
- bootstrap = new Bootstrap();
- bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class)
- .handler(new NettyClientInitializer());
- }
- @Override
- public RpcResponse sendRequest(RpcRequest request) {
- //从注册中心获取host,post
- InetSocketAddress address = serviceCenter.serviceDiscovery(request.getInterfaceName());
- String host = address.getHostName();
- int port = address.getPort();
- try {
- ChannelFuture channelFuture = bootstrap.connect(host, port).sync();
- Channel channel = channelFuture.channel();
- // 发送数据
- channel.writeAndFlush(request);
- //sync()堵塞获取结果
- channel.closeFuture().sync();
- // 阻塞的获得结果,通过给channel设计别名,获取特定名字下的channel中的内容(这个在hanlder中设置)
- // AttributeKey是,线程隔离的,不会由线程安全问题。
- // 当前场景下选择堵塞获取结果
- // 其它场景也可以选择添加监听器的方式来异步获取结果 channelFuture.addListener...
- AttributeKey key = AttributeKey.valueOf("RPCResponse");
- RpcResponse response = channel.attr(key).get();
-
- System.out.println(response);
- return response;
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- return null;
- }
-}
diff --git a/version2/src/main/java/part1/Client/rpcClient/impl/SimpleSocketRpcCilent.java b/version2/src/main/java/part1/Client/rpcClient/impl/SimpleSocketRpcCilent.java
deleted file mode 100644
index d74af41..0000000
--- a/version2/src/main/java/part1/Client/rpcClient/impl/SimpleSocketRpcCilent.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package part1.Client.rpcClient.impl;
-
-import part1.Client.rpcClient.RpcClient;
-import part1.common.Message.RpcRequest;
-import part1.common.Message.RpcResponse;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.net.Socket;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/5/2 18:58
- */
-public class SimpleSocketRpcCilent implements RpcClient {
- private String host;
- private int port;
- public SimpleSocketRpcCilent(String host,int port){
- this.host=host;
- this.port=port;
- }
- @Override
- public RpcResponse sendRequest(RpcRequest request) {
- try {
- Socket socket=new Socket(host, port);
- ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
- ObjectInputStream ois=new ObjectInputStream(socket.getInputStream());
-
- oos.writeObject(request);
- oos.flush();
-
- RpcResponse response=(RpcResponse) ois.readObject();
- return response;
- } catch (IOException | ClassNotFoundException e) {
- e.printStackTrace();
- return null;
- }
- }
-}
diff --git a/version2/src/main/java/part1/Client/serviceCenter/ServiceCenter.java b/version2/src/main/java/part1/Client/serviceCenter/ServiceCenter.java
deleted file mode 100644
index 1842b94..0000000
--- a/version2/src/main/java/part1/Client/serviceCenter/ServiceCenter.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package part1.Client.serviceCenter;
-
-import java.net.InetSocketAddress;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/5/3 21:42
- */
-//服务中心接口
-public interface ServiceCenter {
- // 查询:根据服务名查找地址
- InetSocketAddress serviceDiscovery(String serviceName);
-}
diff --git a/version2/src/main/java/part1/Client/serviceCenter/ZKServiceCenter.java b/version2/src/main/java/part1/Client/serviceCenter/ZKServiceCenter.java
deleted file mode 100644
index b62de1f..0000000
--- a/version2/src/main/java/part1/Client/serviceCenter/ZKServiceCenter.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package part1.Client.serviceCenter;
-
-import org.apache.curator.RetryPolicy;
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.CuratorFrameworkFactory;
-import org.apache.curator.retry.ExponentialBackoffRetry;
-
-import java.net.InetSocketAddress;
-import java.util.List;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/5/3 21:41
- */
-public class ZKServiceCenter implements ServiceCenter{
- // curator 提供的zookeeper客户端
- private CuratorFramework client;
- //zookeeper根路径节点
- private static final String ROOT_PATH = "MyRPC";
-
- //负责zookeeper客户端的初始化,并与zookeeper服务端进行连接
- public ZKServiceCenter(){
- // 指数时间重试
- RetryPolicy policy = new ExponentialBackoffRetry(1000, 3);
- // zookeeper的地址固定,不管是服务提供者还是,消费者都要与之建立连接
- // sessionTimeoutMs 与 zoo.cfg中的tickTime 有关系,
- // zk还会根据minSessionTimeout与maxSessionTimeout两个参数重新调整最后的超时值。默认分别为tickTime 的2倍和20倍
- // 使用心跳监听状态
- this.client = CuratorFrameworkFactory.builder().connectString("127.0.0.1:2181")
- .sessionTimeoutMs(40000).retryPolicy(policy).namespace(ROOT_PATH).build();
- this.client.start();
- System.out.println("zookeeper 连接成功");
- }
- //根据服务名(接口名)返回地址
- @Override
- public InetSocketAddress serviceDiscovery(String serviceName) {
- try {
- List strings = client.getChildren().forPath("/" + serviceName);
- // 这里默认用的第一个,后面加负载均衡
- String string = strings.get(0);
- return parseAddress(string);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- // 地址 -> XXX.XXX.XXX.XXX:port 字符串
- private String getServiceAddress(InetSocketAddress serverAddress) {
- return serverAddress.getHostName() +
- ":" +
- serverAddress.getPort();
- }
- // 字符串解析为地址
- private InetSocketAddress parseAddress(String address) {
- String[] result = address.split(":");
- return new InetSocketAddress(result[0], Integer.parseInt(result[1]));
- }
-}
diff --git a/version2/src/main/java/part1/Server/TestServer.java b/version2/src/main/java/part1/Server/TestServer.java
deleted file mode 100644
index baaf058..0000000
--- a/version2/src/main/java/part1/Server/TestServer.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package part1.Server;
-
-
-import part1.Server.provider.ServiceProvider;
-import part1.Server.server.impl.NettyRPCRPCServer;
-import part1.Server.server.RpcServer;
-import part1.common.service.Impl.UserServiceImpl;
-import part1.common.service.UserService;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/11 19:39
- */
-
-public class TestServer {
- public static void main(String[] args) {
- UserService userService=new UserServiceImpl();
-
- ServiceProvider serviceProvider=new ServiceProvider("127.0.0.1",9999);
- serviceProvider.provideServiceInterface(userService);
-
- RpcServer rpcServer=new NettyRPCRPCServer(serviceProvider);
- rpcServer.start(9999);
- }
-}
diff --git a/version2/src/main/java/part1/Server/netty/handler/NettyRPCServerHandler.java b/version2/src/main/java/part1/Server/netty/handler/NettyRPCServerHandler.java
deleted file mode 100644
index 5b01246..0000000
--- a/version2/src/main/java/part1/Server/netty/handler/NettyRPCServerHandler.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package part1.Server.netty.handler;
-
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.SimpleChannelInboundHandler;
-import lombok.AllArgsConstructor;
-import part1.Server.provider.ServiceProvider;
-import part1.common.Message.RpcRequest;
-import part1.common.Message.RpcResponse;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/26 16:40
- * 因为是服务器端,我们知道接受到请求格式是RPCRequest
- * Object类型也行,强制转型就行
- */
-@AllArgsConstructor
-public class NettyRPCServerHandler extends SimpleChannelInboundHandler {
- private ServiceProvider serviceProvider;
- @Override
- protected void channelRead0(ChannelHandlerContext ctx, RpcRequest request) throws Exception {
- RpcResponse response = getResponse(request);
- ctx.writeAndFlush(response);
- ctx.close();
- }
- @Override
- public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
- cause.printStackTrace();
- ctx.close();
- }
- private RpcResponse getResponse(RpcRequest rpcRequest){
- //得到服务名
- String interfaceName=rpcRequest.getInterfaceName();
- //得到服务端相应服务实现类
- Object service = serviceProvider.getService(interfaceName);
- //反射调用方法
- Method method=null;
- try {
- method= service.getClass().getMethod(rpcRequest.getMethodName(), rpcRequest.getParamsType());
- Object invoke=method.invoke(service,rpcRequest.getParams());
- return RpcResponse.sussess(invoke);
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
- e.printStackTrace();
- System.out.println("方法执行错误");
- return RpcResponse.fail();
- }
- }
-}
diff --git a/version2/src/main/java/part1/Server/netty/nettyInitializer/NettyServerInitializer.java b/version2/src/main/java/part1/Server/netty/nettyInitializer/NettyServerInitializer.java
deleted file mode 100644
index bb7a4a1..0000000
--- a/version2/src/main/java/part1/Server/netty/nettyInitializer/NettyServerInitializer.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package part1.Server.netty.nettyInitializer;
-
-
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelPipeline;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
-import io.netty.handler.codec.LengthFieldPrepender;
-import io.netty.handler.codec.serialization.ClassResolver;
-import io.netty.handler.codec.serialization.ObjectDecoder;
-import io.netty.handler.codec.serialization.ObjectEncoder;
-import lombok.AllArgsConstructor;
-import part1.Server.netty.handler.NettyRPCServerHandler;
-import part1.Server.provider.ServiceProvider;
-import part1.common.serializer.myCode.MyDecoder;
-import part1.common.serializer.myCode.MyEncoder;
-import part1.common.serializer.mySerializer.JsonSerializer;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/26 16:15
- */
-@AllArgsConstructor
-public class NettyServerInitializer extends ChannelInitializer {
- private ServiceProvider serviceProvider;
- @Override
- protected void initChannel(SocketChannel ch) throws Exception {
- ChannelPipeline pipeline = ch.pipeline();
- //使用自定义的编/解码器
- pipeline.addLast(new MyEncoder(new JsonSerializer()));
- pipeline.addLast(new MyDecoder());
- pipeline.addLast(new NettyRPCServerHandler(serviceProvider));
- }
-}
diff --git a/version2/src/main/java/part1/Server/provider/ServiceProvider.java b/version2/src/main/java/part1/Server/provider/ServiceProvider.java
deleted file mode 100644
index f7355dc..0000000
--- a/version2/src/main/java/part1/Server/provider/ServiceProvider.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package part1.Server.provider;
-
-import part1.Server.serviceRegister.ServiceRegister;
-import part1.Server.serviceRegister.impl.ZKServiceRegister;
-
-import java.net.InetSocketAddress;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/16 17:35
- */
-public class ServiceProvider {
- private Map interfaceProvider;
-
- private int port;
- private String host;
- //注册服务类
- private ServiceRegister serviceRegister;
-
- public ServiceProvider(String host,int port){
- //需要传入服务端自身的网络地址
- this.host=host;
- this.port=port;
- this.interfaceProvider=new HashMap<>();
- this.serviceRegister=new ZKServiceRegister();
- }
-
- public void provideServiceInterface(Object service){
- String serviceName=service.getClass().getName();
- Class>[] interfaceName=service.getClass().getInterfaces();
-
- for (Class> clazz:interfaceName){
- //本机的映射表
- interfaceProvider.put(clazz.getName(),service);
- //在注册中心注册服务
- serviceRegister.register(clazz.getName(),new InetSocketAddress(host,port));
- }
- }
-
- public Object getService(String interfaceName){
- return interfaceProvider.get(interfaceName);
- }
-
-}
diff --git a/version2/src/main/java/part1/Server/server/RpcServer.java b/version2/src/main/java/part1/Server/server/RpcServer.java
deleted file mode 100644
index 7ed9584..0000000
--- a/version2/src/main/java/part1/Server/server/RpcServer.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package part1.Server.server;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/12 11:26
- */
-public interface RpcServer {
- void start(int port);
- void stop();
-}
diff --git a/version2/src/main/java/part1/Server/server/impl/NettyRPCRPCServer.java b/version2/src/main/java/part1/Server/server/impl/NettyRPCRPCServer.java
deleted file mode 100644
index e3022e8..0000000
--- a/version2/src/main/java/part1/Server/server/impl/NettyRPCRPCServer.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package part1.Server.server.impl;
-
-import io.netty.bootstrap.ServerBootstrap;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.channel.socket.nio.NioServerSocketChannel;
-import lombok.AllArgsConstructor;
-import part1.Server.provider.ServiceProvider;
-import part1.Server.netty.nettyInitializer.NettyServerInitializer;
-import part1.Server.server.RpcServer;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/26 14:01
- */
-@AllArgsConstructor
-public class NettyRPCRPCServer implements RpcServer {
- private ServiceProvider serviceProvider;
- @Override
- public void start(int port) {
- // netty 服务线程组boss负责建立连接, work负责具体的请求
- NioEventLoopGroup bossGroup = new NioEventLoopGroup();
- NioEventLoopGroup workGroup = new NioEventLoopGroup();
- System.out.println("netty服务端启动了");
- try {
- //启动netty服务器
- ServerBootstrap serverBootstrap = new ServerBootstrap();
- //初始化
- serverBootstrap.group(bossGroup,workGroup).channel(NioServerSocketChannel.class)
- .childHandler(new NettyServerInitializer(serviceProvider));
- //同步堵塞
- ChannelFuture channelFuture=serverBootstrap.bind(port).sync();
- //死循环监听
- channelFuture.channel().closeFuture().sync();
- }catch (InterruptedException e){
- e.printStackTrace();
- }finally {
- bossGroup.shutdownGracefully();
- workGroup.shutdownGracefully();
- }
- }
-
- @Override
- public void stop() {
-
- }
-}
diff --git a/version2/src/main/java/part1/Server/server/impl/SimpleRPCRPCServer.java b/version2/src/main/java/part1/Server/server/impl/SimpleRPCRPCServer.java
deleted file mode 100644
index 277926e..0000000
--- a/version2/src/main/java/part1/Server/server/impl/SimpleRPCRPCServer.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package part1.Server.server.impl;
-
-
-import lombok.AllArgsConstructor;
-import part1.Server.provider.ServiceProvider;
-import part1.Server.server.work.WorkThread;
-import part1.Server.server.RpcServer;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/12 11:37
- */
-@AllArgsConstructor
-public class SimpleRPCRPCServer implements RpcServer {
- private ServiceProvider serviceProvide;
- @Override
- public void start(int port) {
- try {
- ServerSocket serverSocket=new ServerSocket(port);
- System.out.println("服务器启动了");
- while (true) {
- Socket socket = serverSocket.accept();
- new Thread(new WorkThread(socket,serviceProvide)).start();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void stop() {
-
- }
-}
diff --git a/version2/src/main/java/part1/Server/server/work/WorkThread.java b/version2/src/main/java/part1/Server/server/work/WorkThread.java
deleted file mode 100644
index 064b9c2..0000000
--- a/version2/src/main/java/part1/Server/server/work/WorkThread.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package part1.Server.server.work;
-
-
-import lombok.AllArgsConstructor;
-import part1.Server.provider.ServiceProvider;
-import part1.common.Message.RpcRequest;
-import part1.common.Message.RpcResponse;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.Socket;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/14 17:39
- */
-@AllArgsConstructor
-public class WorkThread implements Runnable{
- private Socket socket;
- private ServiceProvider serviceProvide;
- @Override
- public void run() {
- try {
- ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
- ObjectInputStream ois=new ObjectInputStream(socket.getInputStream());
- //读取客户端传过来的request
- RpcRequest rpcRequest = (RpcRequest) ois.readObject();
- //反射调用服务方法获取返回值
- RpcResponse rpcResponse=getResponse(rpcRequest);
- //向客户端写入response
- oos.writeObject(rpcResponse);
- oos.flush();
- } catch (IOException | ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- private RpcResponse getResponse(RpcRequest rpcRequest){
- //得到服务名
- String interfaceName=rpcRequest.getInterfaceName();
- //得到服务端相应服务实现类
- Object service = serviceProvide.getService(interfaceName);
- //反射调用方法
- Method method=null;
- try {
- method= service.getClass().getMethod(rpcRequest.getMethodName(), rpcRequest.getParamsType());
- Object invoke=method.invoke(service,rpcRequest.getParams());
- return RpcResponse.sussess(invoke);
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
- e.printStackTrace();
- System.out.println("方法执行错误");
- return RpcResponse.fail();
- }
- }
-}
diff --git a/version2/src/main/java/part1/Server/serviceRegister/ServiceRegister.java b/version2/src/main/java/part1/Server/serviceRegister/ServiceRegister.java
deleted file mode 100644
index 54c52b1..0000000
--- a/version2/src/main/java/part1/Server/serviceRegister/ServiceRegister.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package part1.Server.serviceRegister;
-
-import java.net.InetSocketAddress;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/5/3 16:58
- */
-// 服务注册接口
-public interface ServiceRegister {
- // 注册:保存服务与地址。
- void register(String serviceName, InetSocketAddress serviceAddress);
-
-}
diff --git a/version2/src/main/java/part1/Server/serviceRegister/impl/ZKServiceRegister.java b/version2/src/main/java/part1/Server/serviceRegister/impl/ZKServiceRegister.java
deleted file mode 100644
index d569338..0000000
--- a/version2/src/main/java/part1/Server/serviceRegister/impl/ZKServiceRegister.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package part1.Server.serviceRegister.impl;
-
-import org.apache.curator.RetryPolicy;
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.CuratorFrameworkFactory;
-import org.apache.curator.retry.ExponentialBackoffRetry;
-import org.apache.zookeeper.CreateMode;
-import part1.Server.serviceRegister.ServiceRegister;
-
-import java.net.InetSocketAddress;
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/5/3 17:28
- */
-public class ZKServiceRegister implements ServiceRegister {
- // curator 提供的zookeeper客户端
- private CuratorFramework client;
- //zookeeper根路径节点
- private static final String ROOT_PATH = "MyRPC";
-
- //负责zookeeper客户端的初始化,并与zookeeper服务端进行连接
- public ZKServiceRegister(){
- // 指数时间重试
- RetryPolicy policy = new ExponentialBackoffRetry(1000, 3);
- // zookeeper的地址固定,不管是服务提供者还是,消费者都要与之建立连接
- // sessionTimeoutMs 与 zoo.cfg中的tickTime 有关系,
- // zk还会根据minSessionTimeout与maxSessionTimeout两个参数重新调整最后的超时值。默认分别为tickTime 的2倍和20倍
- // 使用心跳监听状态
- this.client = CuratorFrameworkFactory.builder().connectString("127.0.0.1:2181")
- .sessionTimeoutMs(40000).retryPolicy(policy).namespace(ROOT_PATH).build();
- this.client.start();
- System.out.println("zookeeper 连接成功");
- }
- //注册服务到注册中心
- @Override
- public void register(String serviceName, InetSocketAddress serviceAddress) {
- try {
- // serviceName创建成永久节点,服务提供者下线时,不删服务名,只删地址
- if(client.checkExists().forPath("/" + serviceName) == null){
- client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath("/" + serviceName);
- }
- // 路径地址,一个/代表一个节点
- String path = "/" + serviceName +"/"+ getServiceAddress(serviceAddress);
- // 临时节点,服务器下线就删除节点
- client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(path);
- } catch (Exception e) {
- System.out.println("此服务已存在");
- }
- }
- // 地址 -> XXX.XXX.XXX.XXX:port 字符串
- private String getServiceAddress(InetSocketAddress serverAddress) {
- return serverAddress.getHostName() +
- ":" +
- serverAddress.getPort();
- }
- // 字符串解析为地址
- private InetSocketAddress parseAddress(String address) {
- String[] result = address.split(":");
- return new InetSocketAddress(result[0], Integer.parseInt(result[1]));
- }
-}
diff --git a/version2/src/main/java/part1/common/Message/MessageType.java b/version2/src/main/java/part1/common/Message/MessageType.java
deleted file mode 100644
index ebbcc83..0000000
--- a/version2/src/main/java/part1/common/Message/MessageType.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package part1.common.Message;
-
-import lombok.AllArgsConstructor;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/6/2 22:29
- */
-@AllArgsConstructor
-public enum MessageType {
- REQUEST(0),RESPONSE(1);
- private int code;
- public int getCode(){
- return code;
- }
-}
\ No newline at end of file
diff --git a/version2/src/main/java/part1/common/Message/RpcRequest.java b/version2/src/main/java/part1/common/Message/RpcRequest.java
deleted file mode 100644
index 2642f38..0000000
--- a/version2/src/main/java/part1/common/Message/RpcRequest.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package part1.common.Message;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-import java.io.Serializable;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/1 18:30
- * 定义发送的消息格式
- */
-@NoArgsConstructor
-@AllArgsConstructor
-@Data
-@Builder
-public class RpcRequest implements Serializable {
- //服务类名,客户端只知道接口
- private String interfaceName;
- //调用的方法名
- private String methodName;
- //参数列表
- private Object[] params;
- //参数类型
- private Class>[] paramsType;
-}
diff --git a/version2/src/main/java/part1/common/Message/RpcResponse.java b/version2/src/main/java/part1/common/Message/RpcResponse.java
deleted file mode 100644
index 7a44b45..0000000
--- a/version2/src/main/java/part1/common/Message/RpcResponse.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package part1.common.Message;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-import java.io.Serializable;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/2/1 19:18
- */
-@NoArgsConstructor
-@AllArgsConstructor
-@Data
-@Builder
-public class RpcResponse implements Serializable {
- //状态信息
- private int code;
- private String message;
- //更新:加入传输数据的类型,以便在自定义序列化器中解析
- private Class> dataType;
- //具体数据
- private Object data;
-
- public static RpcResponse sussess(Object data){
- return RpcResponse.builder().code(200).dataType(data.getClass()).data(data).build();
- }
- public static RpcResponse fail(){
- return RpcResponse.builder().code(500).message("服务器发生错误").build();
- }
-}
-
diff --git a/version2/src/main/java/part1/common/pojo/User.java b/version2/src/main/java/part1/common/pojo/User.java
deleted file mode 100644
index d7cef8c..0000000
--- a/version2/src/main/java/part1/common/pojo/User.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package part1.common.pojo;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-import java.io.Serializable;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/1/28 17:50
- */
-@Builder
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-public class User implements Serializable {
- // 客户端和服务端共有的
- private Integer id;
- private String userName;
- private Boolean sex;
-}
-
diff --git a/version2/src/main/java/part1/common/serializer/myCode/MyDecoder.java b/version2/src/main/java/part1/common/serializer/myCode/MyDecoder.java
deleted file mode 100644
index 8788c0e..0000000
--- a/version2/src/main/java/part1/common/serializer/myCode/MyDecoder.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package part1.common.serializer.myCode;
-
-import io.netty.buffer.ByteBuf;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.ByteToMessageDecoder;
-import part1.common.Message.MessageType;
-import part1.common.serializer.mySerializer.Serializer;
-
-import java.awt.*;
-import java.util.List;
-
-/**
- * @author wxx
- * @version 1.0
- * @create 2024/6/2 22:24
- * 按照自定义的消息格式解码数据
- */
-public class MyDecoder extends ByteToMessageDecoder {
- @Override
- protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf in, List