Compare commits
No commits in common. "4bb276a755498d54013408a49d3c597d31e3bd55" and "c14d77400d58ef124bff4c4b37ccf443f5834451" have entirely different histories.
4bb276a755
...
c14d77400d
27
.github/workflows/build-and-release.yml
vendored
27
.github/workflows/build-and-release.yml
vendored
|
|
@ -3,13 +3,16 @@ name: Build and Release
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- "rebuild-develop" # develop 分支只构建
|
- "rebuild-develop" # develop分支
|
||||||
- "rebuild-release" # release 分支构建 + 发布
|
- "rebuild-release" # release 分支
|
||||||
|
tags:
|
||||||
|
- 'build-*' # 打 tag 时跑 build + release
|
||||||
workflow_dispatch: # 允许手动触发
|
workflow_dispatch: # 允许手动触发
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
@ -41,38 +44,40 @@ jobs:
|
||||||
release:
|
release:
|
||||||
needs: build
|
needs: build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.ref_name == 'rebuild-release' # 仅在 release 分支执行 release job
|
if: startsWith(github.ref, 'refs/tags/build-') # 只有打 tag 才执行 release
|
||||||
steps:
|
steps:
|
||||||
# 下载构建产物
|
# 下载 Common JAR
|
||||||
- name: Download Common artifact
|
- name: Download Common artifact
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: Common
|
name: Common
|
||||||
path: ./build-artifacts/Common
|
path: ./build-artifacts/Common
|
||||||
|
|
||||||
|
# 下载 CommonApi JAR
|
||||||
- name: Download CommonApi artifact
|
- name: Download CommonApi artifact
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: CommonApi
|
name: CommonApi
|
||||||
path: ./build-artifacts/CommonApi
|
path: ./build-artifacts/CommonApi
|
||||||
|
|
||||||
# 创建 GitHub Release
|
# 创建 Release
|
||||||
- name: Create GitHub Release
|
- name: Create GitHub Release
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
with:
|
with:
|
||||||
tag_name: "release-${{ github.run_number }}" # 可用 run_number 或自定义版本号
|
tag_name: ${{ github.ref_name }}
|
||||||
name: Release ${{ github.run_number }}
|
name: Release ${{ github.ref_name }}
|
||||||
body: 自动发布所有子项目构建产物
|
body: |
|
||||||
|
自动发布所有子项目构建产物。
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
# 上传子项目 JAR
|
# 上传各子项目 JAR 到 Release
|
||||||
- name: Upload jars to Release
|
- name: Upload jars to Release separately
|
||||||
run: |
|
run: |
|
||||||
for file in ./build-artifacts/**/*.jar; do
|
for file in ./build-artifacts/**/*.jar; do
|
||||||
echo "Uploading $file"
|
echo "Uploading $file"
|
||||||
gh release upload "release-${GITHUB_RUN_NUMBER}" "$file" --repo "${GITHUB_REPOSITORY}" --clobber
|
gh release upload "${GITHUB_REF_NAME}" "$file" --repo "${GITHUB_REPOSITORY}" --clobber
|
||||||
done
|
done
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
|
||||||
|
|
@ -1,204 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="JavaDocConfiguration">
|
|
||||||
<GENERAL>
|
|
||||||
<MODE>UPDATE</MODE>
|
|
||||||
<OVERRIDDEN_METHODS>false</OVERRIDDEN_METHODS>
|
|
||||||
<SPLITTED_CLASS_NAME>true</SPLITTED_CLASS_NAME>
|
|
||||||
<LEVELS>
|
|
||||||
<LEVEL>TYPE</LEVEL>
|
|
||||||
<LEVEL>METHOD</LEVEL>
|
|
||||||
<LEVEL>FIELD</LEVEL>
|
|
||||||
</LEVELS>
|
|
||||||
<VISIBILITIES>
|
|
||||||
<VISIBILITY>PUBLIC</VISIBILITY>
|
|
||||||
<VISIBILITY>DEFAULT</VISIBILITY>
|
|
||||||
<VISIBILITY>PROTECTED</VISIBILITY>
|
|
||||||
</VISIBILITIES>
|
|
||||||
</GENERAL>
|
|
||||||
<TEMPLATES>
|
|
||||||
<CLASSES>
|
|
||||||
<CLASS>
|
|
||||||
<KEY>^.*(public|protected|private)*.+interface\s+\w+.*</KEY>
|
|
||||||
<VALUE>/**\n
|
|
||||||
* The interface ${name}.\n
|
|
||||||
<#if element.typeParameters?has_content> * \n
|
|
||||||
</#if>
|
|
||||||
<#list element.typeParameters as typeParameter>
|
|
||||||
* @param <${typeParameter.name}> the type parameter\n
|
|
||||||
</#list>
|
|
||||||
*/</VALUE>
|
|
||||||
</CLASS>
|
|
||||||
<CLASS>
|
|
||||||
<KEY>^.*(public|protected|private)*.+enum\s+\w+.*</KEY>
|
|
||||||
<VALUE>/**\n
|
|
||||||
* The enum ${name}.\n
|
|
||||||
*/</VALUE>
|
|
||||||
</CLASS>
|
|
||||||
<CLASS>
|
|
||||||
<KEY>^.*(public|protected|private)*.+class\s+\w+.*</KEY>
|
|
||||||
<VALUE>/**\n
|
|
||||||
* The type ${name}.\n
|
|
||||||
<#if element.typeParameters?has_content> * \n
|
|
||||||
</#if>
|
|
||||||
<#list element.typeParameters as typeParameter>
|
|
||||||
* @param <${typeParameter.name}> the type parameter\n
|
|
||||||
</#list>
|
|
||||||
*/</VALUE>
|
|
||||||
</CLASS>
|
|
||||||
<CLASS>
|
|
||||||
<KEY>.+</KEY>
|
|
||||||
<VALUE>/**\n
|
|
||||||
* The type ${name}.\n
|
|
||||||
*/</VALUE>
|
|
||||||
</CLASS>
|
|
||||||
</CLASSES>
|
|
||||||
<CONSTRUCTORS>
|
|
||||||
<CONSTRUCTOR>
|
|
||||||
<KEY>.+</KEY>
|
|
||||||
<VALUE>/**\n
|
|
||||||
* Instantiates a new ${name}.\n
|
|
||||||
<#if element.parameterList.parameters?has_content>
|
|
||||||
*\n
|
|
||||||
</#if>
|
|
||||||
<#list element.parameterList.parameters as parameter>
|
|
||||||
* @param ${parameter.name} the ${paramNames[parameter.name]}\n
|
|
||||||
</#list>
|
|
||||||
<#if element.throwsList.referenceElements?has_content>
|
|
||||||
*\n
|
|
||||||
</#if>
|
|
||||||
<#list element.throwsList.referenceElements as exception>
|
|
||||||
* @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n
|
|
||||||
</#list>
|
|
||||||
*/</VALUE>
|
|
||||||
</CONSTRUCTOR>
|
|
||||||
</CONSTRUCTORS>
|
|
||||||
<METHODS>
|
|
||||||
<METHOD>
|
|
||||||
<KEY>^.*(public|protected|private)*\s*.*(\w(\s*<.+>)*)+\s+get\w+\s*\(.*\).+</KEY>
|
|
||||||
<VALUE>/**\n
|
|
||||||
* Gets ${partName}.\n
|
|
||||||
<#if element.typeParameters?has_content> * \n
|
|
||||||
</#if>
|
|
||||||
<#list element.typeParameters as typeParameter>
|
|
||||||
* @param <${typeParameter.name}> the type parameter\n
|
|
||||||
</#list>
|
|
||||||
<#if element.parameterList.parameters?has_content>
|
|
||||||
*\n
|
|
||||||
</#if>
|
|
||||||
<#list element.parameterList.parameters as parameter>
|
|
||||||
* @param ${parameter.name} the ${paramNames[parameter.name]}\n
|
|
||||||
</#list>
|
|
||||||
<#if isNotVoid>
|
|
||||||
*\n
|
|
||||||
* @return the ${partName}\n
|
|
||||||
</#if>
|
|
||||||
<#if element.throwsList.referenceElements?has_content>
|
|
||||||
*\n
|
|
||||||
</#if>
|
|
||||||
<#list element.throwsList.referenceElements as exception>
|
|
||||||
* @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n
|
|
||||||
</#list>
|
|
||||||
*/</VALUE>
|
|
||||||
</METHOD>
|
|
||||||
<METHOD>
|
|
||||||
<KEY>^.*(public|protected|private)*\s*.*(void|\w(\s*<.+>)*)+\s+set\w+\s*\(.*\).+</KEY>
|
|
||||||
<VALUE>/**\n
|
|
||||||
* Sets ${partName}.\n
|
|
||||||
<#if element.typeParameters?has_content> * \n
|
|
||||||
</#if>
|
|
||||||
<#list element.typeParameters as typeParameter>
|
|
||||||
* @param <${typeParameter.name}> the type parameter\n
|
|
||||||
</#list>
|
|
||||||
<#if element.parameterList.parameters?has_content>
|
|
||||||
*\n
|
|
||||||
</#if>
|
|
||||||
<#list element.parameterList.parameters as parameter>
|
|
||||||
* @param ${parameter.name} the ${paramNames[parameter.name]}\n
|
|
||||||
</#list>
|
|
||||||
<#if isNotVoid>
|
|
||||||
*\n
|
|
||||||
* @return the ${partName}\n
|
|
||||||
</#if>
|
|
||||||
<#if element.throwsList.referenceElements?has_content>
|
|
||||||
*\n
|
|
||||||
</#if>
|
|
||||||
<#list element.throwsList.referenceElements as exception>
|
|
||||||
* @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n
|
|
||||||
</#list>
|
|
||||||
*/</VALUE>
|
|
||||||
</METHOD>
|
|
||||||
<METHOD>
|
|
||||||
<KEY>^.*((public\s+static)|(static\s+public))\s+void\s+main\s*\(\s*String\s*(\[\s*\]|\.\.\.)\s+\w+\s*\).+</KEY>
|
|
||||||
<VALUE>/**\n
|
|
||||||
* The entry point of application.\n
|
|
||||||
|
|
||||||
<#if element.parameterList.parameters?has_content>
|
|
||||||
*\n
|
|
||||||
</#if>
|
|
||||||
* @param ${element.parameterList.parameters[0].name} the input arguments\n
|
|
||||||
<#if element.throwsList.referenceElements?has_content>
|
|
||||||
*\n
|
|
||||||
</#if>
|
|
||||||
<#list element.throwsList.referenceElements as exception>
|
|
||||||
* @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n
|
|
||||||
</#list>
|
|
||||||
*/</VALUE>
|
|
||||||
</METHOD>
|
|
||||||
<METHOD>
|
|
||||||
<KEY>.+</KEY>
|
|
||||||
<VALUE>/**\n
|
|
||||||
* ${name}<#if isNotVoid> ${return}</#if>.\n
|
|
||||||
<#if element.typeParameters?has_content> * \n
|
|
||||||
</#if>
|
|
||||||
<#list element.typeParameters as typeParameter>
|
|
||||||
* @param <${typeParameter.name}> the type parameter\n
|
|
||||||
</#list>
|
|
||||||
<#if element.parameterList.parameters?has_content>
|
|
||||||
*\n
|
|
||||||
</#if>
|
|
||||||
<#list element.parameterList.parameters as parameter>
|
|
||||||
* @param ${parameter.name} the ${paramNames[parameter.name]}\n
|
|
||||||
</#list>
|
|
||||||
<#if isNotVoid>
|
|
||||||
*\n
|
|
||||||
* @return the ${return}\n
|
|
||||||
</#if>
|
|
||||||
<#if element.throwsList.referenceElements?has_content>
|
|
||||||
*\n
|
|
||||||
</#if>
|
|
||||||
<#list element.throwsList.referenceElements as exception>
|
|
||||||
* @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n
|
|
||||||
</#list>
|
|
||||||
*/</VALUE>
|
|
||||||
</METHOD>
|
|
||||||
</METHODS>
|
|
||||||
<FIELDS>
|
|
||||||
<FIELD>
|
|
||||||
<KEY>^.*(public|protected|private)*.+static.*(\w\s\w)+.+</KEY>
|
|
||||||
<VALUE>/**\n
|
|
||||||
* The constant ${element.getName()}.\n
|
|
||||||
*/</VALUE>
|
|
||||||
</FIELD>
|
|
||||||
<FIELD>
|
|
||||||
<KEY>^.*(public|protected|private)*.*(\w\s\w)+.+</KEY>
|
|
||||||
<VALUE>/**\n
|
|
||||||
<#if element.parent.isInterface()>
|
|
||||||
* The constant ${element.getName()}.\n
|
|
||||||
<#else>
|
|
||||||
* The ${name}.\n
|
|
||||||
</#if> */</VALUE>
|
|
||||||
</FIELD>
|
|
||||||
<FIELD>
|
|
||||||
<KEY>.+</KEY>
|
|
||||||
<VALUE>/**\n
|
|
||||||
<#if element.parent.isEnum()>
|
|
||||||
*${name} ${typeName}.\n
|
|
||||||
<#else>
|
|
||||||
* The ${name}.\n
|
|
||||||
</#if>*/</VALUE>
|
|
||||||
</FIELD>
|
|
||||||
</FIELDS>
|
|
||||||
</TEMPLATES>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ASMIdeaPluginConfiguration">
|
<component name="ASMIdeaPluginConfiguration">
|
||||||
<asm skipDebug="false" skipFrames="false" skipCode="false" expandFrames="false" />
|
<asm skipDebug="false" skipFrames="false" skipCode="false" expandFrames="false" />
|
||||||
|
|
|
||||||
|
|
@ -1,124 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="Palette2">
|
|
||||||
<group name="Swing">
|
|
||||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
|
||||||
</item>
|
|
||||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
|
||||||
<initial-values>
|
|
||||||
<property name="text" value="Button" />
|
|
||||||
</initial-values>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
|
||||||
<initial-values>
|
|
||||||
<property name="text" value="RadioButton" />
|
|
||||||
</initial-values>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
|
||||||
<initial-values>
|
|
||||||
<property name="text" value="CheckBox" />
|
|
||||||
</initial-values>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
|
||||||
<initial-values>
|
|
||||||
<property name="text" value="Label" />
|
|
||||||
</initial-values>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
|
||||||
<preferred-size width="150" height="-1" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
|
||||||
<preferred-size width="150" height="-1" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
|
||||||
<preferred-size width="150" height="-1" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
|
||||||
<preferred-size width="150" height="50" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
|
||||||
<preferred-size width="150" height="50" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
|
||||||
<preferred-size width="150" height="50" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
|
||||||
<preferred-size width="150" height="50" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
|
||||||
<preferred-size width="150" height="50" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
|
||||||
<preferred-size width="150" height="50" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
|
||||||
<preferred-size width="200" height="200" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
|
||||||
<preferred-size width="200" height="200" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
|
||||||
<preferred-size width="-1" height="20" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
|
||||||
</item>
|
|
||||||
</group>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
|
|
@ -25,6 +25,19 @@ repositories {
|
||||||
dependencies {
|
dependencies {
|
||||||
// Common 依赖 CommonApi
|
// Common 依赖 CommonApi
|
||||||
api project(':CommonApi')
|
api project(':CommonApi')
|
||||||
|
|
||||||
|
implementation 'org.apache.logging.log4j:log4j-core:2.23.1'
|
||||||
|
implementation 'org.apache.logging.log4j:log4j-api:2.23.1'
|
||||||
|
implementation 'org.apache.logging.log4j:log4j-slf4j2-impl:2.23.1'
|
||||||
|
implementation 'org.realityforge.org.jetbrains.annotations:org.jetbrains.annotations:1.7.0'
|
||||||
|
implementation 'org.apache.commons:commons-lang3:3.17.0'
|
||||||
|
implementation 'com.google.guava:guava:33.3.0-jre'
|
||||||
|
implementation 'io.netty:netty-all:4.1.109.Final'
|
||||||
|
implementation 'com.google.code.gson:gson:2.10.1'
|
||||||
|
implementation 'org.slf4j:slf4j-api:2.0.16'
|
||||||
|
|
||||||
|
testImplementation platform('org.junit:junit-bom:5.10.0')
|
||||||
|
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sources JAR
|
// Sources JAR
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,9 @@
|
||||||
|
|
||||||
package com.r3944realms.dg_lab.manager;
|
package com.r3944realms.dg_lab.manager;
|
||||||
|
|
||||||
import com.r3944realms.dg_lab.api.manager.IDGLabManager;
|
|
||||||
import com.r3944realms.dg_lab.api.manager.Status;
|
import com.r3944realms.dg_lab.api.manager.Status;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.Message;
|
|
||||||
import com.r3944realms.dg_lab.websocket.PowerBoxWSClient;
|
import com.r3944realms.dg_lab.websocket.PowerBoxWSClient;
|
||||||
|
import com.r3944realms.dg_lab.api.websocket.message.Message;
|
||||||
import com.r3944realms.dg_lab.websocket.sharedData.ClientPowerBoxSharedData;
|
import com.r3944realms.dg_lab.websocket.sharedData.ClientPowerBoxSharedData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ package com.r3944realms.dg_lab.manager;
|
||||||
|
|
||||||
import com.r3944realms.dg_lab.api.manager.IDGLabManager;
|
import com.r3944realms.dg_lab.api.manager.IDGLabManager;
|
||||||
import com.r3944realms.dg_lab.api.manager.Status;
|
import com.r3944realms.dg_lab.api.manager.Status;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.Message;
|
|
||||||
import com.r3944realms.dg_lab.websocket.PowerBoxWSServer;
|
import com.r3944realms.dg_lab.websocket.PowerBoxWSServer;
|
||||||
|
import com.r3944realms.dg_lab.api.websocket.message.Message;
|
||||||
import com.r3944realms.dg_lab.websocket.sharedData.ServerPowerBoxSharedData;
|
import com.r3944realms.dg_lab.websocket.sharedData.ServerPowerBoxSharedData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,11 @@
|
||||||
package com.r3944realms.dg_lab.utils.timeTask;
|
package com.r3944realms.dg_lab.utils.timeTask;
|
||||||
|
|
||||||
|
|
||||||
|
import com.r3944realms.dg_lab.utils.annoation.NeedCompletedInFuture;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.Message;
|
import com.r3944realms.dg_lab.api.websocket.message.Message;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.PowerBoxMessage;
|
import com.r3944realms.dg_lab.api.websocket.message.PowerBoxMessage;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.role.PlaceholderRole;
|
import com.r3944realms.dg_lab.api.websocket.message.role.PlaceholderRole;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.role.WebSocketClientRole;
|
import com.r3944realms.dg_lab.api.websocket.message.role.WebSocketClientRole;
|
||||||
import com.r3944realms.dg_lab.utils.annoation.NeedCompletedInFuture;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,9 @@ package com.r3944realms.dg_lab.websocket;
|
||||||
|
|
||||||
import com.r3944realms.dg_lab.DgLab;
|
import com.r3944realms.dg_lab.DgLab;
|
||||||
import com.r3944realms.dg_lab.api.manager.Status;
|
import com.r3944realms.dg_lab.api.manager.Status;
|
||||||
import com.r3944realms.dg_lab.api.websocket.IWebsocketClient;
|
|
||||||
import com.r3944realms.dg_lab.utils.stringUtils.StringHandlerUtil;
|
import com.r3944realms.dg_lab.utils.stringUtils.StringHandlerUtil;
|
||||||
import com.r3944realms.dg_lab.utils.stringUtils.UrlValidator;
|
import com.r3944realms.dg_lab.utils.stringUtils.UrlValidator;
|
||||||
|
import com.r3944realms.dg_lab.api.websocket.message.Message;
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.channel.*;
|
import io.netty.channel.*;
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
|
|
@ -32,14 +32,9 @@ import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
|
||||||
import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler;
|
import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler;
|
||||||
import io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator;
|
import io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator;
|
||||||
import io.netty.handler.codec.http.websocketx.WebSocketVersion;
|
import io.netty.handler.codec.http.websocketx.WebSocketVersion;
|
||||||
import io.netty.handler.ssl.SslContext;
|
|
||||||
import io.netty.handler.ssl.SslContextBuilder;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.net.ssl.SSLException;
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
@ -48,7 +43,7 @@ import java.util.concurrent.CompletableFuture;
|
||||||
/**
|
/**
|
||||||
* 主要是处理netty逻辑以建立客户端
|
* 主要是处理netty逻辑以建立客户端
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractWebSocketClient implements IWebsocketClient {
|
public abstract class AbstractWebSocketClient {
|
||||||
/**
|
/**
|
||||||
* 日志
|
* 日志
|
||||||
*/
|
*/
|
||||||
|
|
@ -56,61 +51,29 @@ public abstract class AbstractWebSocketClient implements IWebsocketClient {
|
||||||
/**
|
/**
|
||||||
* 地址
|
* 地址
|
||||||
*/
|
*/
|
||||||
protected volatile String address;
|
protected volatile String Address;
|
||||||
/**
|
/**
|
||||||
* 端口
|
* 端口
|
||||||
*/
|
*/
|
||||||
protected volatile int port;
|
protected volatile int Port;
|
||||||
|
|
||||||
/**
|
|
||||||
* 启用 SSL
|
|
||||||
*/
|
|
||||||
public void enableSSL() {
|
|
||||||
enableSSL(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 启用 SSL
|
|
||||||
* @param certFile 可选证书文件
|
|
||||||
*/
|
|
||||||
public void enableSSL(@Nullable File certFile) {
|
|
||||||
this.sslEnabled = true;
|
|
||||||
this.certFile = certFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 禁用SSL
|
|
||||||
*/
|
|
||||||
public void disableSSL() {
|
|
||||||
this.sslEnabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否启用 SSL
|
|
||||||
*/
|
|
||||||
boolean sslEnabled;
|
|
||||||
/**
|
|
||||||
* 客户端可选信任证书
|
|
||||||
*/
|
|
||||||
File certFile;
|
|
||||||
/**
|
/**
|
||||||
* 客户端启动类
|
* 客户端启动类
|
||||||
*/
|
*/
|
||||||
private Bootstrap clientBootstrap;
|
private Bootstrap ClientBootstrap;
|
||||||
/**
|
/**
|
||||||
* 客户端事件线程组
|
* 客户端事件线程组
|
||||||
*/
|
*/
|
||||||
private EventLoopGroup clientEventLoopGroup;
|
private EventLoopGroup ClientEventLoopGroup;
|
||||||
/**
|
/**
|
||||||
* The Client channel.
|
* The Client channel.
|
||||||
*/
|
*/
|
||||||
protected Channel clientChannel;
|
protected Channel ClientChannel;
|
||||||
|
|
||||||
private Thread webSocketClientThread;
|
private Thread WebSocketClientThread;
|
||||||
/**
|
/**
|
||||||
* The Client status.
|
* The Client status.
|
||||||
*/
|
*/
|
||||||
protected volatile Status clientStatus = Status.WAITING_FOR_INIT;
|
protected volatile Status ClientStatus = Status.WAITING_FOR_INIT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets status.
|
* Gets status.
|
||||||
|
|
@ -118,17 +81,7 @@ public abstract class AbstractWebSocketClient implements IWebsocketClient {
|
||||||
* @return the status
|
* @return the status
|
||||||
*/
|
*/
|
||||||
public Status getStatus() {
|
public Status getStatus() {
|
||||||
return this.clientStatus;
|
return this.ClientStatus;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否启用 SSL
|
|
||||||
*
|
|
||||||
* @return enable
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isSSLEnabled() {
|
|
||||||
return sslEnabled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -137,7 +90,7 @@ public abstract class AbstractWebSocketClient implements IWebsocketClient {
|
||||||
* @param status the status
|
* @param status the status
|
||||||
*/
|
*/
|
||||||
public void setStatus(Status status) {
|
public void setStatus(Status status) {
|
||||||
this.clientStatus = status;
|
this.ClientStatus = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -145,8 +98,8 @@ public abstract class AbstractWebSocketClient implements IWebsocketClient {
|
||||||
*/
|
*/
|
||||||
protected AbstractWebSocketClient() {
|
protected AbstractWebSocketClient() {
|
||||||
try {
|
try {
|
||||||
this.address = InetAddress.getLocalHost().getHostAddress();
|
this.Address = InetAddress.getLocalHost().getHostAddress();
|
||||||
this.port = 9000;
|
this.Port = 9000;
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
@ -160,8 +113,8 @@ public abstract class AbstractWebSocketClient implements IWebsocketClient {
|
||||||
protected AbstractWebSocketClient(int port) {
|
protected AbstractWebSocketClient(int port) {
|
||||||
try {
|
try {
|
||||||
InetAddress localHost = InetAddress.getLocalHost();
|
InetAddress localHost = InetAddress.getLocalHost();
|
||||||
this.address = localHost.getHostAddress();
|
this.Address = localHost.getHostAddress();
|
||||||
this.port = UrlValidator.isValidPort(port) ? port : 9000;
|
this.Port = UrlValidator.isValidPort(port) ? port : 9000;
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
@ -175,35 +128,24 @@ public abstract class AbstractWebSocketClient implements IWebsocketClient {
|
||||||
*/
|
*/
|
||||||
protected AbstractWebSocketClient(String address, int port) {
|
protected AbstractWebSocketClient(String address, int port) {
|
||||||
try {
|
try {
|
||||||
this.address = UrlValidator.isValidAddress(address) ? address : InetAddress.getLocalHost().getHostAddress();
|
this.Address = UrlValidator.isValidAddress(address) ? address : InetAddress.getLocalHost().getHostAddress();
|
||||||
this.port = UrlValidator.isValidPort(port) ? port : 9000;
|
this.Port = UrlValidator.isValidPort(port) ? port : 9000;
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPort() {
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets port.
|
* Sets port.
|
||||||
*
|
*
|
||||||
* @param port the port
|
* @param port the port
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void setPort(int port) {
|
public void setPort(int port) {
|
||||||
if (this.clientStatus != Status.WAITING_FOR_INIT && this.clientStatus != Status.STOPPED) {
|
if (this.ClientStatus != Status.WAITING_FOR_INIT && this.ClientStatus != Status.STOPPED) {
|
||||||
logger.error("Unable to change port to {}", port);
|
logger.error("Unable to change port to {}", port);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.port = UrlValidator.isValidPort(port) ? port : 9000;
|
this.Port = UrlValidator.isValidPort(port) ? port : 9000;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAddress() {
|
|
||||||
return address;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -212,12 +154,12 @@ public abstract class AbstractWebSocketClient implements IWebsocketClient {
|
||||||
* @param address the address
|
* @param address the address
|
||||||
*/
|
*/
|
||||||
public void setAddress(String address) {
|
public void setAddress(String address) {
|
||||||
if (this.clientStatus != Status.WAITING_FOR_INIT && this.clientStatus != Status.STOPPED) {
|
if (this.ClientStatus != Status.WAITING_FOR_INIT && this.ClientStatus != Status.STOPPED) {
|
||||||
logger.error("Unable to change address to {}", address);
|
logger.error("Unable to change address to {}", address);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.address = UrlValidator.isValidAddress(address) ? address : InetAddress.getLocalHost().getHostAddress();
|
this.Address = UrlValidator.isValidAddress(address) ? address : InetAddress.getLocalHost().getHostAddress();
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
@ -244,7 +186,7 @@ public abstract class AbstractWebSocketClient implements IWebsocketClient {
|
||||||
* @return the url
|
* @return the url
|
||||||
*/
|
*/
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return StringHandlerUtil.buildWebSocketURL(address, port, false);
|
return StringHandlerUtil.buildWebSocketURL(Address, Port, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -263,36 +205,22 @@ public abstract class AbstractWebSocketClient implements IWebsocketClient {
|
||||||
* Init thread.
|
* Init thread.
|
||||||
*/
|
*/
|
||||||
protected final void initThread() {
|
protected final void initThread() {
|
||||||
init();
|
ClientEventLoopGroup = new NioEventLoopGroup();
|
||||||
clientEventLoopGroup = new NioEventLoopGroup();
|
WebSocketClientThread = new Thread(() -> {
|
||||||
webSocketClientThread = new Thread(() -> {
|
ClientStatus = Status.STARTING;
|
||||||
clientStatus = Status.STARTING;
|
ClientBootstrap = new Bootstrap();
|
||||||
clientBootstrap = new Bootstrap();
|
ClientBootstrap.group(ClientEventLoopGroup);
|
||||||
clientBootstrap.group(clientEventLoopGroup);
|
ClientBootstrap.channel(NioSocketChannel.class);
|
||||||
clientBootstrap.channel(NioSocketChannel.class);
|
ClientBootstrap.handler(new ChannelInitializer<NioSocketChannel>() {
|
||||||
clientBootstrap.handler(new ChannelInitializer<NioSocketChannel>() {
|
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(NioSocketChannel ch) throws SSLException {
|
protected void initChannel(NioSocketChannel ch) {
|
||||||
ChannelPipeline pipeline = ch.pipeline();
|
ChannelPipeline pipeline = ch.pipeline();
|
||||||
// SSL 支持
|
|
||||||
if (sslEnabled) {
|
|
||||||
SslContext sslCtx;
|
|
||||||
if (certFile != null && certFile.exists()) {
|
|
||||||
sslCtx = SslContextBuilder.forClient()
|
|
||||||
.trustManager(certFile)
|
|
||||||
.build();
|
|
||||||
} else {
|
|
||||||
// 默认信任所有受信任的 CA
|
|
||||||
sslCtx = SslContextBuilder.forClient().build();
|
|
||||||
}
|
|
||||||
pipeline.addFirst(sslCtx.newHandler(ch.alloc(), address, port));
|
|
||||||
}
|
|
||||||
pipeline.addLast(DgLab.LOGGING_HANDLER,
|
pipeline.addLast(DgLab.LOGGING_HANDLER,
|
||||||
new HttpClientCodec(),
|
new HttpClientCodec(),
|
||||||
new HttpObjectAggregator(65536),
|
new HttpObjectAggregator(65536),
|
||||||
new WebSocketClientProtocolHandler(
|
new WebSocketClientProtocolHandler(
|
||||||
WebSocketClientHandshakerFactory.newHandshaker(
|
WebSocketClientHandshakerFactory.newHandshaker(
|
||||||
URI.create(StringHandlerUtil.buildWebSocketURL(address, port, false)),
|
URI.create(StringHandlerUtil.buildWebSocketURL(Address, Port, false)),
|
||||||
WebSocketVersion.V13,
|
WebSocketVersion.V13,
|
||||||
null,
|
null,
|
||||||
false,
|
false,
|
||||||
|
|
@ -304,17 +232,17 @@ public abstract class AbstractWebSocketClient implements IWebsocketClient {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
ChannelFuture channelFuture = clientBootstrap.connect(address, port);
|
ChannelFuture channelFuture = ClientBootstrap.connect(Address, Port);
|
||||||
clientStatus = Status.RUNNING;
|
ClientStatus = Status.RUNNING;
|
||||||
onStarted();
|
started();
|
||||||
clientChannel = channelFuture.sync().channel();
|
ClientChannel = channelFuture.sync().channel();
|
||||||
clientChannel.closeFuture().sync();
|
ClientChannel.closeFuture().sync();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
onStartingError("Catch Exception: " + e.getMessage());
|
startingError();
|
||||||
clientStatus = Status.ERROR;
|
ClientStatus = Status.ERROR;
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
if(clientStatus == Status.ERROR || clientStatus == Status.RUNNING) stop();
|
if(ClientStatus == Status.ERROR || ClientStatus == Status.RUNNING) stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
}, "WebSocketClient");
|
}, "WebSocketClient");
|
||||||
|
|
@ -330,23 +258,23 @@ public abstract class AbstractWebSocketClient implements IWebsocketClient {
|
||||||
* Start.
|
* Start.
|
||||||
*/
|
*/
|
||||||
public final void start() {
|
public final void start() {
|
||||||
onStarting();
|
starting();
|
||||||
switch (clientStatus) {
|
switch (ClientStatus) {
|
||||||
case STARTING -> {
|
case STARTING -> {
|
||||||
onStartingError("Client is already onStarting");
|
startingError();
|
||||||
logger.info("Client is already onStarting.");
|
logger.info("Client is already starting.");
|
||||||
}
|
}
|
||||||
case RUNNING -> {
|
case RUNNING -> {
|
||||||
onStartingError("Client is already running.");
|
startingError();
|
||||||
logger.info("Client is already running.");
|
logger.info("Client is already running.");
|
||||||
}
|
}
|
||||||
case STOPPING -> {
|
case STOPPING -> {
|
||||||
onStartingError("Client is onStopping");
|
startingError();
|
||||||
logger.info("Client is onStopping");
|
logger.info("Client is stopping");
|
||||||
}
|
}
|
||||||
case STOPPED, WAITING_FOR_INIT -> {
|
case STOPPED, WAITING_FOR_INIT -> {
|
||||||
initThread();
|
initThread();
|
||||||
webSocketClientThread.start();
|
WebSocketClientThread.start();
|
||||||
start0();
|
start0();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -361,58 +289,96 @@ public abstract class AbstractWebSocketClient implements IWebsocketClient {
|
||||||
return CompletableFuture.runAsync(() -> {});
|
return CompletableFuture.runAsync(() -> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starting.
|
||||||
|
*/
|
||||||
|
protected abstract void starting();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starting error.
|
||||||
|
*/
|
||||||
|
protected abstract void startingError();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Started.
|
||||||
|
*/
|
||||||
|
protected abstract void started();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stopping.
|
||||||
|
*/
|
||||||
|
protected abstract void stopping();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stopping error.
|
||||||
|
*/
|
||||||
|
protected abstract void stoppingError();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stopped.
|
||||||
|
*/
|
||||||
|
protected abstract void stopped();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop.
|
* Stop.
|
||||||
*/
|
*/
|
||||||
public final void stop() {
|
public final void stop() {
|
||||||
onStopping();
|
stopping();
|
||||||
switch (clientStatus) {
|
switch (ClientStatus) {
|
||||||
|
case WAITING_FOR_INIT -> {
|
||||||
|
stoppingError();
|
||||||
|
logger.warn("Not Init. (It shouldn't be happened)");
|
||||||
|
}
|
||||||
case STARTING -> {
|
case STARTING -> {
|
||||||
onStoppingError("Client is already onStarting.");
|
stoppingError();
|
||||||
logger.info("Client is onStarting, please waiting.");
|
logger.info("Client is starting, please waiting.");
|
||||||
}
|
}
|
||||||
case RUNNING, ERROR -> {
|
case RUNNING, ERROR -> {
|
||||||
clientStatus = Status.STOPPING;
|
ClientStatus = Status.STOPPING;
|
||||||
CompletableFuture<Void> CliChanClose = CompletableFuture.runAsync(() -> {
|
CompletableFuture<Void> CliChanClose = CompletableFuture.runAsync(() -> {
|
||||||
if (clientChannel != null && clientChannel.isOpen()) {
|
if (ClientChannel != null && ClientChannel.isOpen()) {
|
||||||
try {
|
try {
|
||||||
clientChannel.close().sync();
|
ClientChannel.close().sync();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
clientChannel = null;
|
ClientChannel = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
CompletableFuture<Void> CliEvenClose = CliChanClose.thenRunAsync(() -> {
|
CompletableFuture<Void> CliEvenClose = CliChanClose.thenRunAsync(() -> {
|
||||||
if (clientEventLoopGroup != null) {
|
if (ClientEventLoopGroup != null) {
|
||||||
try {
|
try {
|
||||||
clientEventLoopGroup.shutdownGracefully().sync();
|
ClientEventLoopGroup.shutdownGracefully().sync();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
clientEventLoopGroup = null;
|
ClientEventLoopGroup = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
CliEvenClose.thenCombineAsync(stop0(), (a, b) -> {
|
CliEvenClose.thenCombineAsync(stop0(), (a, b) -> {
|
||||||
clientStatus = Status.STOPPED;
|
ClientStatus = Status.STOPPED;
|
||||||
clientBootstrap = null;
|
ClientBootstrap = null;
|
||||||
onStopped();
|
stopped();
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
case STOPPING -> {
|
case STOPPING -> {
|
||||||
onStoppingError("Client is already onStopping.");
|
stoppingError();
|
||||||
logger.info("Client is already onStopping");
|
logger.info("Client is already stopping");
|
||||||
}
|
}
|
||||||
case STOPPED, WAITING_FOR_INIT -> {
|
case STOPPED -> {
|
||||||
onStoppingError("Client has been onStopped.");
|
stoppingError();
|
||||||
logger.info("Client has onStopped");
|
logger.info("Client has stopped");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向所连接的服务器发送消息
|
||||||
|
*
|
||||||
|
* @param message 消息
|
||||||
|
*/
|
||||||
|
public abstract void send(Message message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,9 @@ package com.r3944realms.dg_lab.websocket;
|
||||||
|
|
||||||
import com.r3944realms.dg_lab.DgLab;
|
import com.r3944realms.dg_lab.DgLab;
|
||||||
import com.r3944realms.dg_lab.api.manager.Status;
|
import com.r3944realms.dg_lab.api.manager.Status;
|
||||||
import com.r3944realms.dg_lab.api.websocket.IWebSocketServer;
|
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.Message;
|
|
||||||
import com.r3944realms.dg_lab.utils.stringUtils.UrlValidator;
|
import com.r3944realms.dg_lab.utils.stringUtils.UrlValidator;
|
||||||
import com.r3944realms.dg_lab.websocket.handler.server.HttpRequestHandler;
|
import com.r3944realms.dg_lab.websocket.handler.server.HttpRequestHandler;
|
||||||
|
import com.r3944realms.dg_lab.api.websocket.message.Message;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.channel.*;
|
import io.netty.channel.*;
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
|
|
@ -32,81 +31,55 @@ import io.netty.handler.codec.http.HttpObjectAggregator;
|
||||||
import io.netty.handler.codec.http.HttpServerCodec;
|
import io.netty.handler.codec.http.HttpServerCodec;
|
||||||
import io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator;
|
import io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator;
|
||||||
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
|
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
|
||||||
import io.netty.handler.ssl.SslContext;
|
|
||||||
import io.netty.handler.ssl.SslContextBuilder;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.net.ssl.SSLException;
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主要是处理netty逻辑以建立服务端
|
* 主要是处理netty逻辑以建立服务端
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"DuplicatedCode", "LoggingSimilarMessage"})
|
@SuppressWarnings({"DuplicatedCode", "LoggingSimilarMessage"})
|
||||||
public abstract class AbstractWebSocketServer implements IWebSocketServer {
|
public abstract class AbstractWebSocketServer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constant logger.
|
* The constant logger.
|
||||||
*/
|
*/
|
||||||
protected static final Logger logger = LoggerFactory.getLogger(AbstractWebSocketServer.class);
|
protected static final Logger logger = LoggerFactory.getLogger(AbstractWebSocketServer.class);
|
||||||
|
|
||||||
/**
|
private int Port;
|
||||||
* Should enable SSL
|
|
||||||
*/
|
|
||||||
boolean sslEnabled;
|
|
||||||
/**
|
|
||||||
* SSL 密码
|
|
||||||
*/
|
|
||||||
String sslPassword;
|
|
||||||
/**
|
|
||||||
* 证书文件
|
|
||||||
*/
|
|
||||||
File certFile;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 私钥文件
|
|
||||||
*/
|
|
||||||
File keyFile;
|
|
||||||
|
|
||||||
private String listenAddress;
|
|
||||||
|
|
||||||
private int port;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Server bootstrap.
|
* The Server bootstrap.
|
||||||
*/
|
*/
|
||||||
protected ServerBootstrap serverBootstrap;
|
protected ServerBootstrap ServerBootstrap;
|
||||||
/**
|
/**
|
||||||
* The Boss group.
|
* The Boss group.
|
||||||
*/
|
*/
|
||||||
protected EventLoopGroup bossGroup,
|
protected EventLoopGroup BossGroup,
|
||||||
/**
|
/**
|
||||||
* The Worker group.
|
* The Worker group.
|
||||||
*/
|
*/
|
||||||
workerGroup;
|
WorkerGroup;
|
||||||
/**
|
/**
|
||||||
* The Server channel.
|
* The Server channel.
|
||||||
*/
|
*/
|
||||||
protected Channel serverChannel;
|
protected Channel ServerChannel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Websocket server thread.
|
* The Websocket server thread.
|
||||||
*/
|
*/
|
||||||
protected Thread websocketServerThread;
|
protected Thread WebsocketServerThread;
|
||||||
/**
|
/**
|
||||||
* The Server status.
|
* The Server status.
|
||||||
*/
|
*/
|
||||||
protected volatile Status serverStatus = Status.WAITING_FOR_INIT;
|
protected volatile Status ServerStatus = Status.WAITING_FOR_INIT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Abstract web socket server.
|
* Instantiates a new Abstract web socket server.
|
||||||
*/
|
*/
|
||||||
protected AbstractWebSocketServer() {
|
protected AbstractWebSocketServer() {
|
||||||
port = 9000;
|
Port = 9000;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -115,61 +88,47 @@ public abstract class AbstractWebSocketServer implements IWebSocketServer {
|
||||||
* @param port the port
|
* @param port the port
|
||||||
*/
|
*/
|
||||||
protected AbstractWebSocketServer(int port) {
|
protected AbstractWebSocketServer(int port) {
|
||||||
this.port = port;
|
Port = port;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setListenedAddress(String address) {
|
|
||||||
this.listenAddress = address;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getListenedAddress() {
|
|
||||||
return listenAddress == null ? "0.0.0.0" : listenAddress;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets status.
|
||||||
|
*
|
||||||
|
* @return the status
|
||||||
|
*/
|
||||||
public Status getStatus() {
|
public Status getStatus() {
|
||||||
return this.serverStatus;
|
return this.ServerStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets status.
|
||||||
|
*
|
||||||
|
* @param status the status
|
||||||
|
*/
|
||||||
public void setStatus(Status status) {
|
public void setStatus(Status status) {
|
||||||
this.serverStatus = status;
|
this.ServerStatus = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets port.
|
||||||
|
*
|
||||||
|
* @param port the port
|
||||||
|
*/
|
||||||
public void setPort(int port) {
|
public void setPort(int port) {
|
||||||
if(this.serverStatus != Status.WAITING_FOR_INIT && this.serverStatus != Status.STOPPED) {
|
if(this.ServerStatus != Status.WAITING_FOR_INIT && this.ServerStatus != Status.STOPPED) {
|
||||||
logger.error("Unable to Change Port to {}", port);
|
logger.error("Unable to Change Port to {}", port);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.port = UrlValidator.isValidPort(port) ? port : 9000;
|
this.Port = UrlValidator.isValidPort(port) ? port : 9000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets port.
|
||||||
|
*
|
||||||
|
* @return the port
|
||||||
|
*/
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
return port;
|
return Port;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSSLEnabled() {
|
|
||||||
return sslEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void enableSSL(@NotNull File certFile, @NotNull File keyFile) {
|
|
||||||
enableSSL(certFile, keyFile, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void enableSSL(@NotNull File certFile, @NotNull File keyFile, @Nullable String password) {
|
|
||||||
this.sslEnabled = true;
|
|
||||||
this.certFile = certFile;
|
|
||||||
this.keyFile = keyFile;
|
|
||||||
this.sslPassword = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void disableSSL() {
|
|
||||||
this.sslEnabled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -188,26 +147,20 @@ public abstract class AbstractWebSocketServer implements IWebSocketServer {
|
||||||
* Init thread.
|
* Init thread.
|
||||||
*/
|
*/
|
||||||
protected final void initThread() {
|
protected final void initThread() {
|
||||||
init();
|
BossGroup = new NioEventLoopGroup();
|
||||||
bossGroup = new NioEventLoopGroup();
|
WorkerGroup = new NioEventLoopGroup();
|
||||||
workerGroup = new NioEventLoopGroup();
|
WebsocketServerThread = new Thread(() ->{
|
||||||
websocketServerThread = new Thread(() ->{
|
|
||||||
try {
|
try {
|
||||||
serverBootstrap = new ServerBootstrap();
|
ServerBootstrap = new ServerBootstrap();
|
||||||
serverStatus = Status.STARTING;
|
ServerStatus = Status.STARTING;
|
||||||
serverBootstrap.option(ChannelOption.SO_BACKLOG, 1024)
|
ServerBootstrap.option(ChannelOption.SO_BACKLOG, 1024)
|
||||||
.childOption(ChannelOption.SO_KEEPALIVE, true);
|
.childOption(ChannelOption.SO_KEEPALIVE, true);
|
||||||
serverBootstrap.group(bossGroup, workerGroup);
|
ServerBootstrap.group(BossGroup, WorkerGroup);
|
||||||
serverBootstrap.channel(NioServerSocketChannel.class);
|
ServerBootstrap.channel(NioServerSocketChannel.class);
|
||||||
serverBootstrap.childHandler(new ChannelInitializer<NioSocketChannel>() {
|
ServerBootstrap.childHandler(new ChannelInitializer<NioSocketChannel>() {
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(NioSocketChannel ch) throws SSLException {
|
protected void initChannel(NioSocketChannel ch) {
|
||||||
ChannelPipeline pipeline = ch.pipeline();
|
ChannelPipeline pipeline = ch.pipeline();
|
||||||
// 根据配置启用 SSL
|
|
||||||
if (sslEnabled) {
|
|
||||||
SslContext sslCtx = SslContextBuilder.forServer(certFile, keyFile, sslPassword).build();
|
|
||||||
pipeline.addFirst(sslCtx.newHandler(ch.alloc()));
|
|
||||||
}
|
|
||||||
pipeline.addLast(DgLab.LOGGING_HANDLER);
|
pipeline.addLast(DgLab.LOGGING_HANDLER);
|
||||||
pipeline.addLast(new HttpServerCodec());
|
pipeline.addLast(new HttpServerCodec());
|
||||||
pipeline.addLast(new HttpObjectAggregator(65536));
|
pipeline.addLast(new HttpObjectAggregator(65536));
|
||||||
|
|
@ -218,25 +171,55 @@ public abstract class AbstractWebSocketServer implements IWebSocketServer {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
logger.debug("WebSocketServer try binding port ... ");
|
logger.debug("WebSocketServer try binding port ... ");
|
||||||
ChannelFuture channelFuture = serverBootstrap.bind(getListenedAddress(), port);
|
ChannelFuture channelFuture = ServerBootstrap.bind("0.0.0.0",Port);
|
||||||
channelFuture.sync();
|
channelFuture.sync();
|
||||||
serverChannel = channelFuture.channel();
|
ServerChannel = channelFuture.channel();
|
||||||
serverStatus = Status.RUNNING;
|
ServerStatus = Status.RUNNING;
|
||||||
onStarted();
|
started();
|
||||||
logger.info("WebSocketServer start on the port of {}{}", port, sslEnabled ? " (SSL)" : "");
|
logger.info("WebSocketServer start on the port of {}", Port);
|
||||||
logger.debug("WebSocketServer listening on port {}", port);
|
logger.debug("WebSocketServer listening on port {}", Port);
|
||||||
channelFuture.channel().closeFuture().sync();
|
channelFuture.channel().closeFuture().sync();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
serverStatus = Status.ERROR;
|
ServerStatus = Status.ERROR;
|
||||||
onStoppingError("Catch Exception:" + e.getMessage());
|
stoppingError();
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
if(serverStatus == Status.ERROR || serverStatus == Status.RUNNING) stop();
|
if(ServerStatus == Status.ERROR || ServerStatus == Status.RUNNING) stop();
|
||||||
}
|
}
|
||||||
}, "WebSocketServer");
|
}, "WebSocketServer");
|
||||||
initThread0();
|
initThread0();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starting.
|
||||||
|
*/
|
||||||
|
protected abstract void starting();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starting error.
|
||||||
|
*/
|
||||||
|
protected abstract void startingError();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Started.
|
||||||
|
*/
|
||||||
|
protected abstract void started();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stopping.
|
||||||
|
*/
|
||||||
|
protected abstract void stopping();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stopping error.
|
||||||
|
*/
|
||||||
|
protected abstract void stoppingError();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stopped.
|
||||||
|
*/
|
||||||
|
protected abstract void stopped();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义Start后续逻辑
|
* 自定义Start后续逻辑
|
||||||
*/
|
*/
|
||||||
|
|
@ -248,23 +231,23 @@ public abstract class AbstractWebSocketServer implements IWebSocketServer {
|
||||||
* Start.
|
* Start.
|
||||||
*/
|
*/
|
||||||
public final void start() {
|
public final void start() {
|
||||||
onStarting();
|
starting();
|
||||||
switch (serverStatus) {
|
switch (ServerStatus) {
|
||||||
case STARTING -> {
|
case STARTING -> {
|
||||||
onStartingError("Server is already onStarting.");
|
startingError();
|
||||||
logger.info("Server is already onStarting.");
|
logger.info("Server is already starting.");
|
||||||
}
|
}
|
||||||
case RUNNING -> {
|
case RUNNING -> {
|
||||||
onStartingError("Server is already running.");
|
startingError();
|
||||||
logger.info("Server is already running.");
|
logger.info("Server is already running.");
|
||||||
}
|
}
|
||||||
case STOPPING -> {
|
case STOPPING -> {
|
||||||
onStartingError("Server is onStopping");
|
startingError();
|
||||||
logger.info("Server is onStopping");
|
logger.info("Server is stopping");
|
||||||
}
|
}
|
||||||
case STOPPED, WAITING_FOR_INIT -> {
|
case STOPPED, WAITING_FOR_INIT -> {
|
||||||
initThread();
|
initThread();
|
||||||
websocketServerThread.start();
|
WebsocketServerThread.start();
|
||||||
start0();
|
start0();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -283,68 +266,80 @@ public abstract class AbstractWebSocketServer implements IWebSocketServer {
|
||||||
* Stop.
|
* Stop.
|
||||||
*/
|
*/
|
||||||
public final void stop() {
|
public final void stop() {
|
||||||
onStopping();
|
stopping();
|
||||||
switch (serverStatus) {
|
switch (ServerStatus) {
|
||||||
|
case WAITING_FOR_INIT -> {
|
||||||
|
stoppingError();
|
||||||
|
logger.warn("Not Init. (It shouldn't be happened)");
|
||||||
|
}
|
||||||
case STARTING -> {
|
case STARTING -> {
|
||||||
onStoppingError("Server is onStarting, please waiting.");
|
stoppingError();
|
||||||
logger.info("Server is onStarting, please waiting.");
|
logger.info("Server is starting, please waiting.");
|
||||||
}
|
}
|
||||||
case RUNNING -> {
|
case RUNNING -> {
|
||||||
serverStatus = Status.STOPPING;
|
ServerStatus = Status.STOPPING;
|
||||||
// Close the server channel if it's open
|
// Close the server channel if it's open
|
||||||
CompletableFuture<Void> SerChanClose = CompletableFuture.runAsync(() -> {
|
CompletableFuture<Void> SerChanClose = CompletableFuture.runAsync(() -> {
|
||||||
if (serverChannel != null && serverChannel.isOpen()) {
|
if (ServerChannel != null && ServerChannel.isOpen()) {
|
||||||
try {
|
try {
|
||||||
serverChannel.close().sync();
|
ServerChannel.close().sync();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
serverChannel = null;
|
ServerChannel = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Shutdown the event loop groups
|
// Shutdown the event loop groups
|
||||||
CompletableFuture<Void> BosGroClose = SerChanClose.thenRunAsync(() -> {
|
CompletableFuture<Void> BosGroClose = SerChanClose.thenRunAsync(() -> {
|
||||||
if (bossGroup != null) {
|
if (BossGroup != null) {
|
||||||
try {
|
try {
|
||||||
bossGroup.shutdownGracefully().sync();
|
BossGroup.shutdownGracefully().sync();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
bossGroup = null;
|
BossGroup = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
CompletableFuture<Void> WorGroClose = SerChanClose.thenRunAsync(() -> {
|
CompletableFuture<Void> WorGroClose = SerChanClose.thenRunAsync(() -> {
|
||||||
if (workerGroup != null) {
|
if (WorkerGroup != null) {
|
||||||
try {
|
try {
|
||||||
workerGroup.shutdownGracefully().sync();
|
WorkerGroup.shutdownGracefully().sync();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
workerGroup = null;
|
WorkerGroup = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
BosGroClose.thenCombineAsync(WorGroClose, (a,b) -> {
|
BosGroClose.thenCombineAsync(WorGroClose, (a,b) -> {
|
||||||
stop0().thenRunAsync(() -> {
|
stop0().thenRunAsync(() -> {
|
||||||
serverStatus = Status.STOPPED;
|
ServerStatus = Status.STOPPED;
|
||||||
serverBootstrap = null;
|
ServerBootstrap = null;
|
||||||
onStopped();
|
stopped();
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
case STOPPING -> {
|
case STOPPING -> {
|
||||||
onStoppingError("Server is already onStopping");
|
stoppingError();
|
||||||
logger.info("Server is already onStopping");
|
logger.info("Server is already stopping");
|
||||||
}
|
}
|
||||||
case STOPPED -> {
|
case STOPPED -> {
|
||||||
onStoppingError("Server has onStopped");
|
stoppingError();
|
||||||
logger.info("Server has onStopped");
|
logger.info("Server has stopped");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向指定的客户端发送消息
|
||||||
|
*
|
||||||
|
* @param clientId 客户端UUID
|
||||||
|
* @param message 消息
|
||||||
|
*/
|
||||||
|
public abstract void send(String clientId, Message message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,12 @@
|
||||||
package com.r3944realms.dg_lab.websocket;
|
package com.r3944realms.dg_lab.websocket;
|
||||||
|
|
||||||
import com.r3944realms.dg_lab.api.operation.ClientOperation;
|
import com.r3944realms.dg_lab.api.operation.ClientOperation;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.Message;
|
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.PowerBoxMessage;
|
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.role.WebSocketClientRole;
|
|
||||||
import com.r3944realms.dg_lab.websocket.handler.client.ClientDLPBHandler;
|
import com.r3944realms.dg_lab.websocket.handler.client.ClientDLPBHandler;
|
||||||
import com.r3944realms.dg_lab.websocket.handler.client.ClientDLPBHandlerContextWrapper;
|
import com.r3944realms.dg_lab.websocket.handler.client.ClientDLPBHandlerContextWrapper;
|
||||||
import com.r3944realms.dg_lab.websocket.handler.client.DefaultClientOperation;
|
import com.r3944realms.dg_lab.websocket.handler.client.DefaultClientOperation;
|
||||||
|
import com.r3944realms.dg_lab.api.websocket.message.Message;
|
||||||
|
import com.r3944realms.dg_lab.api.websocket.message.PowerBoxMessage;
|
||||||
|
import com.r3944realms.dg_lab.api.websocket.message.role.WebSocketClientRole;
|
||||||
import com.r3944realms.dg_lab.websocket.sharedData.ClientPowerBoxSharedData;
|
import com.r3944realms.dg_lab.websocket.sharedData.ClientPowerBoxSharedData;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||||
|
|
@ -62,8 +62,8 @@ public class PowerBoxWSClient extends AbstractWebSocketClient {
|
||||||
this.sharedData = sharedData;
|
this.sharedData = sharedData;
|
||||||
this.operation = operation;
|
this.operation = operation;
|
||||||
this.role = role;
|
this.role = role;
|
||||||
sharedData.address = this.address;
|
sharedData.address = this.Address;
|
||||||
sharedData.port = this.port;
|
sharedData.port = this.Port;
|
||||||
contextWrapper = new ClientDLPBHandlerContextWrapper(sharedData, role, operation, false);
|
contextWrapper = new ClientDLPBHandlerContextWrapper(sharedData, role, operation, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,8 +82,8 @@ public class PowerBoxWSClient extends AbstractWebSocketClient {
|
||||||
this.sharedData = sharedData;
|
this.sharedData = sharedData;
|
||||||
this.operation = operation;
|
this.operation = operation;
|
||||||
this.role = role;
|
this.role = role;
|
||||||
sharedData.address = this.address;
|
sharedData.address = this.Address;
|
||||||
sharedData.port = this.port;
|
sharedData.port = this.Port;
|
||||||
contextWrapper = new ClientDLPBHandlerContextWrapper(sharedData, role, operation, false);
|
contextWrapper = new ClientDLPBHandlerContextWrapper(sharedData, role, operation, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,8 +123,8 @@ public class PowerBoxWSClient extends AbstractWebSocketClient {
|
||||||
this.sharedData = sharedData;
|
this.sharedData = sharedData;
|
||||||
this.operation = operation;
|
this.operation = operation;
|
||||||
this.role = role;
|
this.role = role;
|
||||||
sharedData.address = this.address;
|
sharedData.address = this.Address;
|
||||||
sharedData.port = this.port;
|
sharedData.port = this.Port;
|
||||||
contextWrapper = new ClientDLPBHandlerContextWrapper(sharedData, role, operation, useRoleMsgMode);
|
contextWrapper = new ClientDLPBHandlerContextWrapper(sharedData, role, operation, useRoleMsgMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,8 +144,8 @@ public class PowerBoxWSClient extends AbstractWebSocketClient {
|
||||||
this.sharedData = sharedData;
|
this.sharedData = sharedData;
|
||||||
this.operation = operation;
|
this.operation = operation;
|
||||||
this.role = role;
|
this.role = role;
|
||||||
sharedData.address = this.address;
|
sharedData.address = this.Address;
|
||||||
sharedData.port = this.port;
|
sharedData.port = this.Port;
|
||||||
contextWrapper = new ClientDLPBHandlerContextWrapper(sharedData, role, operation, useRoleMsgMode);
|
contextWrapper = new ClientDLPBHandlerContextWrapper(sharedData, role, operation, useRoleMsgMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -178,59 +178,39 @@ public class PowerBoxWSClient extends AbstractWebSocketClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
protected void starting() {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStarting() {
|
|
||||||
operation.ClientStartingHandler();
|
operation.ClientStartingHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStartingError(String msg) {
|
protected void startingError() {
|
||||||
operation.ClientStartingErrorHandler(msg);
|
operation.ClientStartingErrorHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStarted() {
|
protected void started() {
|
||||||
operation.ClientStartedHandler();
|
operation.ClientStartedHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStopping() {
|
protected void stopping() {
|
||||||
operation.ClientStoppingHandler();
|
operation.ClientStoppingHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStoppingError(String msg) {
|
protected void stoppingError() {
|
||||||
operation.ClientStoppingErrorHandler(msg);
|
operation.ClientStoppingErrorHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStopped() {
|
protected void stopped() {
|
||||||
operation.ClientStoppedHandler();
|
operation.ClientStoppedHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enableSSL() {
|
|
||||||
super.enableSSL();
|
|
||||||
sharedData.isEnableSsl = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disableSSL() {
|
|
||||||
super.disableSSL();
|
|
||||||
sharedData.isEnableSsl = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(Message message) {
|
public void send(Message message) {
|
||||||
if(message instanceof PowerBoxMessage PBMessage) {
|
if(message instanceof PowerBoxMessage PBMessage) {
|
||||||
this.clientChannel.writeAndFlush(new TextWebSocketFrame(PBMessage.getMsgJson()));
|
this.ClientChannel.writeAndFlush(new TextWebSocketFrame(PBMessage.getMsgJson()));
|
||||||
} else {
|
} else {
|
||||||
logger.error("Message is not a PowerBoxMessage");
|
logger.error("Message is not a PowerBoxMessage");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,12 @@
|
||||||
package com.r3944realms.dg_lab.websocket;
|
package com.r3944realms.dg_lab.websocket;
|
||||||
|
|
||||||
import com.r3944realms.dg_lab.api.operation.ServerOperation;
|
import com.r3944realms.dg_lab.api.operation.ServerOperation;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.Message;
|
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.PowerBoxMessage;
|
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.data.type.PowerBoxDataType;
|
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.role.WebSocketServerRole;
|
|
||||||
import com.r3944realms.dg_lab.websocket.handler.server.DefaultServerOperation;
|
import com.r3944realms.dg_lab.websocket.handler.server.DefaultServerOperation;
|
||||||
import com.r3944realms.dg_lab.websocket.handler.server.ServerDLPBHandler;
|
import com.r3944realms.dg_lab.websocket.handler.server.ServerDLPBHandler;
|
||||||
import com.r3944realms.dg_lab.websocket.handler.server.ServerDLPBHandlerContextWrapper;
|
import com.r3944realms.dg_lab.websocket.handler.server.ServerDLPBHandlerContextWrapper;
|
||||||
|
import com.r3944realms.dg_lab.api.websocket.message.Message;
|
||||||
|
import com.r3944realms.dg_lab.api.websocket.message.PowerBoxMessage;
|
||||||
|
import com.r3944realms.dg_lab.api.websocket.message.role.WebSocketServerRole;
|
||||||
import com.r3944realms.dg_lab.websocket.sharedData.ServerPowerBoxSharedData;
|
import com.r3944realms.dg_lab.websocket.sharedData.ServerPowerBoxSharedData;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
|
|
@ -39,7 +38,7 @@ public class PowerBoxWSServer extends AbstractWebSocketServer {
|
||||||
/**
|
/**
|
||||||
* The Shared data.
|
* The Shared data.
|
||||||
*/
|
*/
|
||||||
protected final ServerPowerBoxSharedData sharedData;
|
protected final ServerPowerBoxSharedData SharedData;
|
||||||
/**
|
/**
|
||||||
* The Role.
|
* The Role.
|
||||||
*/
|
*/
|
||||||
|
|
@ -58,7 +57,7 @@ public class PowerBoxWSServer extends AbstractWebSocketServer {
|
||||||
* @param operation the operation
|
* @param operation the operation
|
||||||
*/
|
*/
|
||||||
public PowerBoxWSServer(ServerPowerBoxSharedData sharedData, WebSocketServerRole role, ServerOperation operation) {
|
public PowerBoxWSServer(ServerPowerBoxSharedData sharedData, WebSocketServerRole role, ServerOperation operation) {
|
||||||
this.sharedData = sharedData;
|
this.SharedData = sharedData;
|
||||||
this.role = role;
|
this.role = role;
|
||||||
this.operation = operation;
|
this.operation = operation;
|
||||||
contextWrapper = new ServerDLPBHandlerContextWrapper(
|
contextWrapper = new ServerDLPBHandlerContextWrapper(
|
||||||
|
|
@ -78,7 +77,7 @@ public class PowerBoxWSServer extends AbstractWebSocketServer {
|
||||||
*/
|
*/
|
||||||
public PowerBoxWSServer(ServerPowerBoxSharedData sharedData, WebSocketServerRole role, ServerOperation operation, int port) {
|
public PowerBoxWSServer(ServerPowerBoxSharedData sharedData, WebSocketServerRole role, ServerOperation operation, int port) {
|
||||||
super(port);
|
super(port);
|
||||||
this.sharedData = sharedData;
|
this.SharedData = sharedData;
|
||||||
this.role = role;
|
this.role = role;
|
||||||
this.operation = operation;
|
this.operation = operation;
|
||||||
contextWrapper = new ServerDLPBHandlerContextWrapper(
|
contextWrapper = new ServerDLPBHandlerContextWrapper(
|
||||||
|
|
@ -115,64 +114,52 @@ public class PowerBoxWSServer extends AbstractWebSocketServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
protected void starting() {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStarting() {
|
|
||||||
operation.ServerStartingHandler();
|
operation.ServerStartingHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStartingError(String error) {
|
protected void startingError() {
|
||||||
operation.ServerStartingErrorHandler(error);
|
operation.ServerStartingErrorHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStarted() {
|
protected void started() {
|
||||||
operation.ServerStartedHandler();
|
operation.ServerStartedHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStopping() {
|
protected void stopping() {
|
||||||
operation.ServerStoppingHandler();
|
operation.ServerStoppingHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStoppingError(String error) {
|
protected void stoppingError() {
|
||||||
operation.ServerStoppingErrorHandler(error);
|
operation.ServerStoppingErrorHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStopped() {
|
protected void stopped() {
|
||||||
operation.ServerStoppedHandler();
|
operation.ServerStoppedHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(String connectId, Message message) {
|
public void send(String connectId, Message message) {
|
||||||
if(message instanceof PowerBoxMessage PBMessage) {
|
if(message instanceof PowerBoxMessage PBMessage) {
|
||||||
ChannelHandlerContext context = sharedData.connections.get(connectId);//获取连接连接的Context
|
ChannelHandlerContext context = SharedData.connections.get(connectId);//获取连接连接的Context
|
||||||
if(context != null) {
|
if(context != null) {
|
||||||
String targetId = sharedData.relations.get(connectId);
|
String targetId = SharedData.relations.get(connectId);
|
||||||
if(targetId != null) {
|
|
||||||
if(targetId.isEmpty()) { //该上下文为客户端
|
if(targetId.isEmpty()) { //该上下文为客户端
|
||||||
context.writeAndFlush(new TextWebSocketFrame(PBMessage.getMsgJson()));//发送给客户端
|
context.writeAndFlush(new TextWebSocketFrame(PBMessage.getMsgJson()));//发送给客户端
|
||||||
ChannelHandlerContext appContext = sharedData.connections.get(targetId);
|
ChannelHandlerContext appContext = SharedData.connections.get(targetId);
|
||||||
appContext.writeAndFlush(new TextWebSocketFrame(PBMessage.getDataJson()));//发送给APP端
|
appContext.writeAndFlush(new TextWebSocketFrame(PBMessage.getDataJson()));//发送给APP端
|
||||||
} else if(sharedData.relations.containsValue(targetId)){ // 绑定状态的APP端
|
} else if(SharedData.relations.containsValue(targetId)){ // 绑定状态的APP端
|
||||||
//仅对APP发信息
|
//仅对APP发信息
|
||||||
context.writeAndFlush(new TextWebSocketFrame(PBMessage.getDataJson()));
|
context.writeAndFlush(new TextWebSocketFrame(PBMessage.getDataJson()));
|
||||||
|
|
||||||
} else { // 未绑定状态(不可发送消息)
|
} else { // 未绑定状态(不可发送消息)
|
||||||
logger.error("Can't send Msg to no relationship obj.");
|
logger.error("Can't send Msg to no relationship obj.");
|
||||||
}
|
}
|
||||||
} else if (PBMessage.commandType == PowerBoxDataType._NC_BIND_) {
|
|
||||||
//客户端写入绑定消息
|
|
||||||
context.writeAndFlush(new TextWebSocketFrame(PBMessage.getMsgJson()));
|
|
||||||
} else { // 未绑定状态(不可发送消息)
|
|
||||||
logger.error("Can't send Non-Binding Msg to no relationship obj.");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
logger.error("Find that Target is invalid.");
|
logger.error("Find that Target is invalid.");
|
||||||
}
|
}
|
||||||
|
|
@ -187,7 +174,7 @@ public class PowerBoxWSServer extends AbstractWebSocketServer {
|
||||||
* @return the shared data
|
* @return the shared data
|
||||||
*/
|
*/
|
||||||
public ServerPowerBoxSharedData getSharedData() {
|
public ServerPowerBoxSharedData getSharedData() {
|
||||||
return sharedData;
|
return SharedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,9 @@
|
||||||
|
|
||||||
package com.r3944realms.dg_lab.websocket.handler.client;
|
package com.r3944realms.dg_lab.websocket.handler.client;
|
||||||
|
|
||||||
import com.r3944realms.dg_lab.api.websocket.sharedData.ISharedData;
|
|
||||||
import com.r3944realms.dg_lab.websocket.handler.AbstractDgLabPowerBoxHandler;
|
import com.r3944realms.dg_lab.websocket.handler.AbstractDgLabPowerBoxHandler;
|
||||||
import com.r3944realms.dg_lab.websocket.handler.IAttachSharedData;
|
import com.r3944realms.dg_lab.websocket.handler.IAttachSharedData;
|
||||||
|
import com.r3944realms.dg_lab.api.websocket.sharedData.ISharedData;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -18,15 +18,15 @@ package com.r3944realms.dg_lab.websocket.handler.client;
|
||||||
|
|
||||||
import com.r3944realms.dg_lab.api.operation.ClientOperation;
|
import com.r3944realms.dg_lab.api.operation.ClientOperation;
|
||||||
import com.r3944realms.dg_lab.api.operation.IOperation;
|
import com.r3944realms.dg_lab.api.operation.IOperation;
|
||||||
|
import com.r3944realms.dg_lab.websocket.handler.AbstractDgLabPowerBoxHandlerContextWrapper;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.PowerBoxMessage;
|
import com.r3944realms.dg_lab.api.websocket.message.PowerBoxMessage;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.data.PowerBoxData;
|
import com.r3944realms.dg_lab.api.websocket.message.data.PowerBoxData;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.role.Role;
|
import com.r3944realms.dg_lab.api.websocket.message.role.Role;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.role.WebSocketClientRole;
|
import com.r3944realms.dg_lab.api.websocket.message.role.WebSocketClientRole;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.role.WebSocketServerRole;
|
import com.r3944realms.dg_lab.api.websocket.message.role.WebSocketServerRole;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.role.type.RoleType;
|
import com.r3944realms.dg_lab.api.websocket.message.role.type.RoleType;
|
||||||
import com.r3944realms.dg_lab.api.websocket.sharedData.ISharedData;
|
|
||||||
import com.r3944realms.dg_lab.websocket.handler.AbstractDgLabPowerBoxHandlerContextWrapper;
|
|
||||||
import com.r3944realms.dg_lab.websocket.sharedData.ClientPowerBoxSharedData;
|
import com.r3944realms.dg_lab.websocket.sharedData.ClientPowerBoxSharedData;
|
||||||
|
import com.r3944realms.dg_lab.api.websocket.sharedData.ISharedData;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||||
|
|
||||||
|
|
@ -145,7 +145,6 @@ public class ClientDLPBHandlerContextWrapper extends AbstractDgLabPowerBoxHandle
|
||||||
((ClientPowerBoxSharedData)sharedData).connectionId = data.getClientId();
|
((ClientPowerBoxSharedData)sharedData).connectionId = data.getClientId();
|
||||||
logger.info("收到clientId: {}", ConnectionId());
|
logger.info("收到clientId: {}", ConnectionId());
|
||||||
String qrCodeContext = "https://www.dungeon-lab.com/app-download.php#DGLAB-SOCKET#" + ((ClientPowerBoxSharedData)sharedData).getUrl() + ConnectionId();
|
String qrCodeContext = "https://www.dungeon-lab.com/app-download.php#DGLAB-SOCKET#" + ((ClientPowerBoxSharedData)sharedData).getUrl() + ConnectionId();
|
||||||
((ClientPowerBoxSharedData) sharedData).rqCodeUrl = qrCodeContext;
|
|
||||||
TryCatch(i -> ((ClientOperation)operation).QrCodeUrlHandler(qrCodeContext));
|
TryCatch(i -> ((ClientOperation)operation).QrCodeUrlHandler(qrCodeContext));
|
||||||
TryCatch(i -> ((ClientOperation)operation).ShowQrCodeHandler());
|
TryCatch(i -> ((ClientOperation)operation).ShowQrCodeHandler());
|
||||||
logger.debug("重新生成QrCodeContext: {}",qrCodeContext);
|
logger.debug("重新生成QrCodeContext: {}",qrCodeContext);
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,8 @@ public class DefaultClientOperation implements ClientOperation {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ClientStartingErrorHandler(String errorMsg) {
|
public void ClientStartingErrorHandler() {
|
||||||
|
//NOOP
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -43,13 +43,11 @@ public class DefaultClientOperation implements ClientOperation {
|
||||||
//NOOP
|
//NOOP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ClientStoppingErrorHandler(String errorMsg) {
|
public void ClientStoppingErrorHandler() {
|
||||||
//NOOP
|
//NOOP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ClientStoppedHandler() {
|
public void ClientStoppedHandler() {
|
||||||
//NOOP
|
//NOOP
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,8 @@ public class DefaultServerOperation implements ServerOperation {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ServerStartingErrorHandler(String errorMessage) {
|
public void ServerStartingErrorHandler() {
|
||||||
//NOOP
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -89,8 +89,8 @@ public class DefaultServerOperation implements ServerOperation {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ServerStoppingErrorHandler(String errorMessage) {
|
public void ServerStoppingErrorHandler() {
|
||||||
//NOOP
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -98,11 +98,6 @@ public class DefaultServerOperation implements ServerOperation {
|
||||||
//NOOP
|
//NOOP
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void ClientSessionBuildInHandler(String clientId) {
|
|
||||||
//NOOP
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void InactiveConnectionRemoveHandler(String clientId) {
|
public void InactiveConnectionRemoveHandler(String clientId) {
|
||||||
//NOOP
|
//NOOP
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,10 @@
|
||||||
|
|
||||||
package com.r3944realms.dg_lab.websocket.handler.server;
|
package com.r3944realms.dg_lab.websocket.handler.server;
|
||||||
|
|
||||||
import com.r3944realms.dg_lab.api.websocket.sharedData.ISharedData;
|
|
||||||
import com.r3944realms.dg_lab.websocket.handler.AbstractDgLabPowerBoxHandler;
|
import com.r3944realms.dg_lab.websocket.handler.AbstractDgLabPowerBoxHandler;
|
||||||
import com.r3944realms.dg_lab.websocket.handler.AbstractDgLabPowerBoxHandlerContextWrapper;
|
import com.r3944realms.dg_lab.websocket.handler.AbstractDgLabPowerBoxHandlerContextWrapper;
|
||||||
import com.r3944realms.dg_lab.websocket.handler.IAttachSharedData;
|
import com.r3944realms.dg_lab.websocket.handler.IAttachSharedData;
|
||||||
|
import com.r3944realms.dg_lab.api.websocket.sharedData.ISharedData;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,17 +18,17 @@ package com.r3944realms.dg_lab.websocket.handler.server;
|
||||||
|
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
import com.r3944realms.dg_lab.api.operation.ServerOperation;
|
import com.r3944realms.dg_lab.api.operation.ServerOperation;
|
||||||
|
import com.r3944realms.dg_lab.api.websocket.message.role.*;
|
||||||
|
import com.r3944realms.dg_lab.utils.stringUtils.StringHandlerUtil;
|
||||||
|
import com.r3944realms.dg_lab.utils.timeTask.DgLabTimerTask;
|
||||||
|
import com.r3944realms.dg_lab.websocket.handler.AbstractDgLabPowerBoxHandlerContextWrapper;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.Message;
|
import com.r3944realms.dg_lab.api.websocket.message.Message;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.PowerBoxMessage;
|
import com.r3944realms.dg_lab.api.websocket.message.PowerBoxMessage;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.data.PowerBoxData;
|
import com.r3944realms.dg_lab.api.websocket.message.data.PowerBoxData;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.data.PowerBoxDataWithSingleAttachment;
|
import com.r3944realms.dg_lab.api.websocket.message.data.PowerBoxDataWithSingleAttachment;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.data.type.PowerBoxDataType;
|
import com.r3944realms.dg_lab.api.websocket.message.data.type.PowerBoxDataType;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.data.type.PowerBoxStatusCode;
|
import com.r3944realms.dg_lab.api.websocket.message.data.type.PowerBoxStatusCode;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.role.*;
|
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.role.type.RoleType;
|
import com.r3944realms.dg_lab.api.websocket.message.role.type.RoleType;
|
||||||
import com.r3944realms.dg_lab.utils.stringUtils.StringHandlerUtil;
|
|
||||||
import com.r3944realms.dg_lab.utils.timeTask.DgLabTimerTask;
|
|
||||||
import com.r3944realms.dg_lab.websocket.handler.AbstractDgLabPowerBoxHandlerContextWrapper;
|
|
||||||
import com.r3944realms.dg_lab.websocket.sharedData.ServerPowerBoxSharedData;
|
import com.r3944realms.dg_lab.websocket.sharedData.ServerPowerBoxSharedData;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
|
@ -78,8 +78,6 @@ public class ServerDLPBHandlerContextWrapper extends AbstractDgLabPowerBoxHandle
|
||||||
Channel().add(session.channel());
|
Channel().add(session.channel());
|
||||||
Connections().put(clientId, session);
|
Connections().put(clientId, session);
|
||||||
logger.info("新的 webSocket 连接已建立, 标识符为{}", clientId);
|
logger.info("新的 webSocket 连接已建立, 标识符为{}", clientId);
|
||||||
String finalClientId = clientId;
|
|
||||||
TryCatch(n -> ((ServerOperation)operation).ClientSessionBuildInHandler(finalClientId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@
|
||||||
|
|
||||||
package com.r3944realms.dg_lab.websocket.sharedData;
|
package com.r3944realms.dg_lab.websocket.sharedData;
|
||||||
|
|
||||||
import com.r3944realms.dg_lab.api.websocket.sharedData.ISharedData;
|
|
||||||
import com.r3944realms.dg_lab.utils.stringUtils.StringHandlerUtil;
|
import com.r3944realms.dg_lab.utils.stringUtils.StringHandlerUtil;
|
||||||
|
import com.r3944realms.dg_lab.api.websocket.sharedData.ISharedData;
|
||||||
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
|
|
||||||
|
|
@ -34,7 +34,6 @@ public class ClientPowerBoxSharedData implements ISharedData {
|
||||||
clone.delay = delay;
|
clone.delay = delay;
|
||||||
clone.address = address;
|
clone.address = address;
|
||||||
clone.port = port;
|
clone.port = port;
|
||||||
clone.rqCodeUrl = rqCodeUrl;
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,14 +70,6 @@ public class ClientPowerBoxSharedData implements ISharedData {
|
||||||
* The Follow b strength.
|
* The Follow b strength.
|
||||||
*/
|
*/
|
||||||
public final boolean followBStrength = false;
|
public final boolean followBStrength = false;
|
||||||
/**
|
|
||||||
* 二维码
|
|
||||||
*/
|
|
||||||
public String rqCodeUrl = "";
|
|
||||||
/**
|
|
||||||
* 是否启用 SSL
|
|
||||||
*/
|
|
||||||
public boolean isEnableSsl = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Client power box shared data.
|
* Instantiates a new Client power box shared data.
|
||||||
|
|
@ -100,7 +91,7 @@ public class ClientPowerBoxSharedData implements ISharedData {
|
||||||
* @return the url
|
* @return the url
|
||||||
*/
|
*/
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return StringHandlerUtil.buildWebSocketURL(address, port, isEnableSsl);
|
return StringHandlerUtil.buildWebSocketURL(address, port, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,18 @@ sourceSets {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation 'org.apache.logging.log4j:log4j-core:2.23.1'
|
||||||
|
implementation 'org.apache.logging.log4j:log4j-api:2.23.1'
|
||||||
|
implementation 'org.apache.logging.log4j:log4j-slf4j2-impl:2.23.1'
|
||||||
|
implementation group: 'org.realityforge.org.jetbrains.annotations', name: 'org.jetbrains.annotations', version: '1.7.0'
|
||||||
|
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.17.0'
|
||||||
|
implementation group: 'com.google.guava', name: 'guava', version: '33.3.0-jre'
|
||||||
|
implementation group: 'io.netty', name: 'netty-all', version: '4.1.109.Final'
|
||||||
|
implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
|
||||||
|
testImplementation platform('org.junit:junit-bom:5.10.0')
|
||||||
|
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||||
|
implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.16'
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register('sourcesJar', Jar) {
|
tasks.register('sourcesJar', Jar) {
|
||||||
archiveClassifier.set('sources')
|
archiveClassifier.set('sources')
|
||||||
from sourceSets.main.allSource
|
from sourceSets.main.allSource
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ public interface IDGLabManager {
|
||||||
* @return the shared data
|
* @return the shared data
|
||||||
*/
|
*/
|
||||||
ISharedData getSharedData();
|
ISharedData getSharedData();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前单例实例运行
|
* 获取当前单例实例运行
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ import com.r3944realms.dg_lab.api.message.data.PulseWaveList;
|
||||||
import com.r3944realms.dg_lab.api.message.data.PulseWaveListGenerator;
|
import com.r3944realms.dg_lab.api.message.data.PulseWaveListGenerator;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.MessageDirection;
|
import com.r3944realms.dg_lab.api.websocket.message.MessageDirection;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.PowerBoxMessage;
|
import com.r3944realms.dg_lab.api.websocket.message.PowerBoxMessage;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.data.PowerBoxData;
|
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.data.PowerBoxDataWithSingleAttachment;
|
import com.r3944realms.dg_lab.api.websocket.message.data.PowerBoxDataWithSingleAttachment;
|
||||||
|
import com.r3944realms.dg_lab.api.websocket.message.data.PowerBoxData;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.data.type.PowerBoxDataType;
|
import com.r3944realms.dg_lab.api.websocket.message.data.type.PowerBoxDataType;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.role.Role;
|
import com.r3944realms.dg_lab.api.websocket.message.role.Role;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,8 @@ public interface ClientOperation extends IOperation {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客户端启动遇到错误后处理
|
* 客户端启动遇到错误后处理
|
||||||
*
|
|
||||||
* @param errorMsg 错误消息
|
|
||||||
*/
|
*/
|
||||||
void ClientStartingErrorHandler(String errorMsg);
|
void ClientStartingErrorHandler();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客户端线程关闭中处理
|
* 客户端线程关闭中处理
|
||||||
|
|
@ -46,10 +44,8 @@ public interface ClientOperation extends IOperation {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客户端线程关闭中遇到错误后处理
|
* 客户端线程关闭中遇到错误后处理
|
||||||
*
|
|
||||||
* @param errorMsg 错误消息
|
|
||||||
*/
|
*/
|
||||||
void ClientStoppingErrorHandler(String errorMsg);
|
void ClientStoppingErrorHandler();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客户端线程完全关闭后处理
|
* 客户端线程完全关闭后处理
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,8 @@ public interface ServerOperation extends IOperation {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务器线程开启中遇到错误后处理
|
* 服务器线程开启中遇到错误后处理
|
||||||
*
|
|
||||||
* @param errorMessage 错误消息
|
|
||||||
*/
|
*/
|
||||||
void ServerStartingErrorHandler(String errorMessage);
|
void ServerStartingErrorHandler();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务器线程开启后处理
|
* 服务器线程开启后处理
|
||||||
|
|
@ -48,23 +46,14 @@ public interface ServerOperation extends IOperation {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务器线程关闭中遇到错误后处理
|
* 服务器线程关闭中遇到错误后处理
|
||||||
*
|
|
||||||
* @param errorMessage 错误消息
|
|
||||||
*/
|
*/
|
||||||
void ServerStoppingErrorHandler(String errorMessage);
|
void ServerStoppingErrorHandler();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务器线程完全关闭后处理
|
* 服务器线程完全关闭后处理
|
||||||
*/
|
*/
|
||||||
void ServerStoppedHandler();
|
void ServerStoppedHandler();
|
||||||
|
|
||||||
/**
|
|
||||||
* 客户端会话连接触发器
|
|
||||||
*
|
|
||||||
* @param clientId the client id
|
|
||||||
*/
|
|
||||||
void ClientSessionBuildInHandler(String clientId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在定时器里即将被移除的UUID处理
|
* 在定时器里即将被移除的UUID处理
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,79 +0,0 @@
|
||||||
package com.r3944realms.dg_lab.api.websocket;
|
|
||||||
|
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.Message;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The interface Web socket server.
|
|
||||||
*/
|
|
||||||
public interface IWebSocketServer extends IWebsocketSide {
|
|
||||||
/**
|
|
||||||
* Gets listened address.
|
|
||||||
*
|
|
||||||
* @return the listened address
|
|
||||||
*/
|
|
||||||
String getListenedAddress();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets listened address.
|
|
||||||
*
|
|
||||||
* @param address the address
|
|
||||||
*/
|
|
||||||
void setListenedAddress(String address);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取监听端口
|
|
||||||
*
|
|
||||||
* @return 端口 port
|
|
||||||
*/
|
|
||||||
int getPort();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置监听端口
|
|
||||||
*
|
|
||||||
* @param port 端口
|
|
||||||
*/
|
|
||||||
void setPort(int port);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 启用SSL
|
|
||||||
*
|
|
||||||
* @param certificateFile 证书文件
|
|
||||||
* @param keyFile 私钥文件
|
|
||||||
*/
|
|
||||||
default void enableSSL(@NotNull File certificateFile, @NotNull File keyFile) {
|
|
||||||
enableSSL(certificateFile, keyFile,null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 启用SSL
|
|
||||||
*
|
|
||||||
* @param certificateFile 证书文件
|
|
||||||
* @param keyFile 私钥文件
|
|
||||||
* @param password ssl密码
|
|
||||||
*/
|
|
||||||
void enableSSL(@NotNull File certificateFile, @NotNull File keyFile, @Nullable String password);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 禁用SSL
|
|
||||||
*/
|
|
||||||
void disableSSL();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取SSL是否开启
|
|
||||||
*
|
|
||||||
* @return enable boolean
|
|
||||||
*/
|
|
||||||
boolean isSSLEnabled();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 向指定的客户端发送消息
|
|
||||||
*
|
|
||||||
* @param connectId 客户端UUID
|
|
||||||
* @param message 消息
|
|
||||||
*/
|
|
||||||
void send(String connectId, Message message);
|
|
||||||
}
|
|
||||||
|
|
@ -1,72 +0,0 @@
|
||||||
package com.r3944realms.dg_lab.api.websocket;
|
|
||||||
|
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.Message;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The interface Websocket client.
|
|
||||||
*/
|
|
||||||
public interface IWebsocketClient extends IWebsocketSide {
|
|
||||||
/**
|
|
||||||
* Gets address.
|
|
||||||
*
|
|
||||||
* @return the address
|
|
||||||
*/
|
|
||||||
String getAddress();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets address.
|
|
||||||
*
|
|
||||||
* @param address the address
|
|
||||||
*/
|
|
||||||
void setAddress(String address);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets port.
|
|
||||||
*
|
|
||||||
* @return the port
|
|
||||||
*/
|
|
||||||
int getPort();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets port.
|
|
||||||
*
|
|
||||||
* @param port the port
|
|
||||||
*/
|
|
||||||
void setPort(int port);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable ssl.
|
|
||||||
*/
|
|
||||||
default void enableSSL() {
|
|
||||||
enableSSL(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable ssl.
|
|
||||||
*
|
|
||||||
* @param certificateFile the certificate file
|
|
||||||
*/
|
|
||||||
void enableSSL(@Nullable File certificateFile);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disable ssl.
|
|
||||||
*/
|
|
||||||
void disableSSL();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is ssl enabled boolean.
|
|
||||||
*
|
|
||||||
* @return the boolean
|
|
||||||
*/
|
|
||||||
boolean isSSLEnabled();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 向所连接的服务器发送消息
|
|
||||||
*
|
|
||||||
* @param message 消息
|
|
||||||
*/
|
|
||||||
void send(Message message);
|
|
||||||
}
|
|
||||||
|
|
@ -1,72 +0,0 @@
|
||||||
package com.r3944realms.dg_lab.api.websocket;
|
|
||||||
|
|
||||||
import com.r3944realms.dg_lab.api.manager.Status;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The interface Websocket side.
|
|
||||||
*/
|
|
||||||
public interface IWebsocketSide {
|
|
||||||
/**
|
|
||||||
* 获取状态
|
|
||||||
*
|
|
||||||
* @return the status
|
|
||||||
*/
|
|
||||||
Status getStatus();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置状态
|
|
||||||
*
|
|
||||||
* @param status 状态
|
|
||||||
*/
|
|
||||||
void setStatus(Status status);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Init.
|
|
||||||
*/
|
|
||||||
void init();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start.
|
|
||||||
*/
|
|
||||||
void start();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop.
|
|
||||||
*/
|
|
||||||
void stop();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* On starting.
|
|
||||||
*/
|
|
||||||
void onStarting();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* On stopping.
|
|
||||||
*/
|
|
||||||
void onStopping();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* On starting error.
|
|
||||||
*
|
|
||||||
* @param msg the msg
|
|
||||||
*/
|
|
||||||
void onStartingError(String msg);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* On stopping error.
|
|
||||||
*
|
|
||||||
* @param msg the msg
|
|
||||||
*/
|
|
||||||
void onStoppingError(String msg);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* On started.
|
|
||||||
*/
|
|
||||||
void onStarted();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* On stopped.
|
|
||||||
*/
|
|
||||||
void onStopped();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -19,19 +19,14 @@ package com.r3944realms.dg_lab.api.websocket.message;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.TypeAdapter;
|
|
||||||
import com.google.gson.annotations.Expose;
|
import com.google.gson.annotations.Expose;
|
||||||
import com.google.gson.stream.JsonReader;
|
|
||||||
import com.google.gson.stream.JsonWriter;
|
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.data.IData;
|
import com.r3944realms.dg_lab.api.websocket.message.data.IData;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.data.adapter.IDataTypeAdapterFactory;
|
import com.r3944realms.dg_lab.api.websocket.message.data.adapter.IDataTypeAdapterFactory;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.role.Role;
|
import com.r3944realms.dg_lab.api.websocket.message.role.Role;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.role.RoleDeserializer;
|
import com.r3944realms.dg_lab.api.websocket.message.role.RoleDeserializer;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息,带有方向和有效负载消息
|
* 消息,带有方向和有效负载消息
|
||||||
|
|
@ -57,24 +52,6 @@ public abstract class Message implements Serializable {
|
||||||
gsonBuilder.registerTypeAdapter(Role.class, new RoleDeserializer());
|
gsonBuilder.registerTypeAdapter(Role.class, new RoleDeserializer());
|
||||||
gsonBuilder.registerTypeAdapter(MessageDirection.class, new MessageDirectionDeserializer());
|
gsonBuilder.registerTypeAdapter(MessageDirection.class, new MessageDirectionDeserializer());
|
||||||
gsonBuilder.registerTypeAdapterFactory(new IDataTypeAdapterFactory());
|
gsonBuilder.registerTypeAdapterFactory(new IDataTypeAdapterFactory());
|
||||||
// 注册 AtomicReference 的适配器
|
|
||||||
gsonBuilder.registerTypeAdapter(AtomicReference.class, new TypeAdapter<AtomicReference<?>>() {
|
|
||||||
@Override
|
|
||||||
public void write(JsonWriter out, AtomicReference<?> value) throws IOException {
|
|
||||||
if (value == null || value.get() == null) {
|
|
||||||
out.nullValue();
|
|
||||||
} else {
|
|
||||||
gson.toJson(value.get(), value.get().getClass(), out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AtomicReference<?> read(JsonReader in) throws IOException {
|
|
||||||
Object obj = gson.fromJson(in, Object.class);
|
|
||||||
return new AtomicReference<>(obj);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
gson = gsonBuilder.create();
|
gson = gsonBuilder.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package com.r3944realms.dg_lab.api.websocket.message;
|
||||||
|
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.role.*;
|
import com.r3944realms.dg_lab.api.websocket.message.role.*;
|
||||||
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -38,14 +38,7 @@ public class PowerBoxMessage extends Message {
|
||||||
/**
|
/**
|
||||||
* The Invalid message json.
|
* The Invalid message json.
|
||||||
*/
|
*/
|
||||||
|
static final String INVALID_MESSAGE_JSON = gson.toJson(PowerBoxData.createPowerBoxData("error","","",""));
|
||||||
private static class LazyInvalidJsonHolder {
|
|
||||||
/**
|
|
||||||
* The Value.
|
|
||||||
*/
|
|
||||||
static final String VALUE =
|
|
||||||
gson.toJson(PowerBoxData.createPowerBoxData("error", "", "", ""));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Power box message.
|
* Instantiates a new Power box message.
|
||||||
|
|
@ -175,7 +168,7 @@ public class PowerBoxMessage extends Message {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInvalidMessageJson() {
|
public String getInvalidMessageJson() {
|
||||||
return LazyInvalidJsonHolder.VALUE;
|
return INVALID_MESSAGE_JSON;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,6 @@
|
||||||
|
|
||||||
package com.r3944realms.dg_lab.api.websocket.message.data;
|
package com.r3944realms.dg_lab.api.websocket.message.data;
|
||||||
|
|
||||||
/**
|
|
||||||
* The enum Data type.
|
|
||||||
*/
|
|
||||||
public enum DataType {
|
public enum DataType {
|
||||||
/**
|
/**
|
||||||
* Power box att data type.
|
* Power box att data type.
|
||||||
|
|
@ -32,7 +29,6 @@ public enum DataType {
|
||||||
* Power box data type.
|
* Power box data type.
|
||||||
*/
|
*/
|
||||||
POWER_BOX;
|
POWER_BOX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets type from string.
|
* Gets type from string.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,6 @@
|
||||||
|
|
||||||
package com.r3944realms.dg_lab.api.websocket.message.data;
|
package com.r3944realms.dg_lab.api.websocket.message.data;
|
||||||
|
|
||||||
/**
|
|
||||||
* The interface Data.
|
|
||||||
*/
|
|
||||||
public interface IData {
|
public interface IData {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package com.r3944realms.dg_lab.api.websocket.message.data;
|
package com.r3944realms.dg_lab.api.websocket.message.data;
|
||||||
|
|
||||||
import com.google.gson.annotations.Expose;
|
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.data.type.PowerBoxDataType;
|
import com.r3944realms.dg_lab.api.websocket.message.data.type.PowerBoxDataType;
|
||||||
import com.r3944realms.dg_lab.api.websocket.message.data.type.PowerBoxStatusCode;
|
import com.r3944realms.dg_lab.api.websocket.message.data.type.PowerBoxStatusCode;
|
||||||
|
|
||||||
|
|
@ -36,9 +35,7 @@ public class PowerBoxData implements IData {
|
||||||
private final String clientId;
|
private final String clientId;
|
||||||
private final String targetId;
|
private final String targetId;
|
||||||
private final String message;
|
private final String message;
|
||||||
@Expose(serialize = false, deserialize = false)
|
AtomicReference<String> inValidReason = new AtomicReference<>(getInvalidReason());
|
||||||
private final transient AtomicReference<String> inValidReason = new AtomicReference<>(getInvalidReason());
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Power box data.
|
* Instantiates a new Power box data.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
14
build.gradle
14
build.gradle
|
|
@ -25,18 +25,8 @@ subprojects {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.realityforge.org.jetbrains.annotations:org.jetbrains.annotations:1.7.0'
|
testImplementation(platform("org.junit:junit-bom:5.10.0"))
|
||||||
implementation 'org.apache.logging.log4j:log4j-core:2.23.1'
|
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||||
implementation 'org.apache.logging.log4j:log4j-api:2.23.1'
|
|
||||||
implementation 'org.apache.logging.log4j:log4j-slf4j2-impl:2.23.1'
|
|
||||||
implementation 'org.apache.commons:commons-lang3:3.17.0'
|
|
||||||
implementation 'com.google.guava:guava:33.3.0-jre'
|
|
||||||
implementation 'io.netty:netty-all:4.1.109.Final'
|
|
||||||
implementation 'com.google.code.gson:gson:2.10.1'
|
|
||||||
implementation 'org.slf4j:slf4j-api:2.0.16'
|
|
||||||
|
|
||||||
testImplementation platform('org.junit:junit-bom:5.10.0')
|
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.test {
|
tasks.test {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ org.gradle.configuration-cache=true
|
||||||
org.gradle.configuration-cache.problems=warn
|
org.gradle.configuration-cache.problems=warn
|
||||||
# ROOT
|
# ROOT
|
||||||
project_name=DgLab
|
project_name=DgLab
|
||||||
project_version=4.4.14.18
|
project_version=4.2.8.16
|
||||||
project_group=top.r3944realms.dg_lab
|
project_group=top.r3944realms.dg_lab
|
||||||
|
|
||||||
# API
|
# API
|
||||||
|
|
|
||||||
|
|
@ -2,39 +2,6 @@
|
||||||
统一用4位版本,对于测试性更新统一在其后加-Beta。
|
统一用4位版本,对于测试性更新统一在其后加-Beta。
|
||||||
修复问题更新为加0.0.0.1,添加/移除新特性加0.0.1.0,小部分重构更新加0.1.0.0,大量重构加1.0.0.0
|
修复问题更新为加0.0.0.1,添加/移除新特性加0.0.1.0,小部分重构更新加0.1.0.0,大量重构加1.0.0.0
|
||||||
|
|
||||||
2025-09-29-1
|
|
||||||
project_version=4.4.14.18
|
|
||||||
* 提取Server/Client接口
|
|
||||||
* 重命名方法starting 变为 onStarting等
|
|
||||||
* Server添加设置监听地址功能
|
|
||||||
|
|
||||||
2025-09-29-1
|
|
||||||
project_version=4.3.12.18
|
|
||||||
* 新增操作ServerOperation类中方法会话建立Handler,已在与客户端会话创建后可进行操作
|
|
||||||
* 修改错误消息提醒
|
|
||||||
|
|
||||||
2025-09-23-1
|
|
||||||
project_version=4.3.11.18
|
|
||||||
* 添加操作Operation类的Error方法错误的参数,同时移除无参方法
|
|
||||||
|
|
||||||
2025-09-21-4
|
|
||||||
project_version=4.2.11.18
|
|
||||||
* 添加服务器对SSL密码参数支持
|
|
||||||
|
|
||||||
2025-09-21-3
|
|
||||||
project_version=4.2.10.18
|
|
||||||
* 添加ClientPowerBoxSharedData添加新字段 isEnableSsl,用于WS地址协议头判断
|
|
||||||
* 让PowerBoxWSClient继承了父类的#enableSSL #disableSSL方法以适配添加ClientPowerBoxSharedData添加新字段的字段 isEnableSsl
|
|
||||||
|
|
||||||
2025-09-21-2
|
|
||||||
project_version=4.2.10.17
|
|
||||||
* 修正 DGPBClientManager 的实现接口为com.r3944realms.dg_lab.api.manager.IDGLabManager
|
|
||||||
* 在ClientPowerBoxSharedData添加新字段rqCodeUrl用于辅助访问二维码Url
|
|
||||||
|
|
||||||
2025-09-21-1
|
|
||||||
project_version=4.2.9.16
|
|
||||||
* 添加了SSL支持
|
|
||||||
|
|
||||||
2025-09-13-1
|
2025-09-13-1
|
||||||
project_version=4.2.8.16
|
project_version=4.2.8.16
|
||||||
* 重构项目结构
|
* 重构项目结构
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user