Browse Source

Modify Class Note......

tags/1.0.0
shaozhuguang 6 years ago
parent
commit
469c23fef8
28 changed files with 111 additions and 32 deletions
  1. +20
    -2
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/MessageExecutor.java
  2. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/RemoteSession.java
  3. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/callback/CallBackBarrier.java
  4. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/callback/CallBackDataListener.java
  5. +2
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/callback/CallBackLauncher.java
  6. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/AbstractAsyncExecutor.java
  7. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/AsyncExecutor.java
  8. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/Connection.java
  9. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/Receiver.java
  10. +37
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/Sender.java
  11. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/handler/HeartBeatReceiverHandler.java
  12. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/handler/HeartBeatReceiverTrigger.java
  13. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/handler/HeartBeatSenderHandler.java
  14. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/handler/HeartBeatSenderTrigger.java
  15. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/handler/ReceiverHandler.java
  16. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/handler/SenderHandler.java
  17. +26
    -4
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/handler/WatchDogHandler.java
  18. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/listener/ReplyListener.java
  19. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/manager/ConnectionManager.java
  20. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/manager/RemoteSessionManager.java
  21. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/message/AbstractMessage.java
  22. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/message/HeartBeatMessage.java
  23. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/message/IMessage.java
  24. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/message/LoadMessage.java
  25. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/message/SessionMessage.java
  26. +1
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/message/TransferMessage.java
  27. +2
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/node/LocalNode.java
  28. +2
    -1
      source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/node/RemoteNode.java

+ 20
- 2
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/MessageExecutor.java View File

@@ -1,8 +1,8 @@
/**
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.MessageExecute
* FileName: com.jd.blockchain.stp.communication.MessageExecutor
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/11 上午10:59
* Description:
*/
@@ -19,8 +19,26 @@ package com.jd.blockchain.stp.communication;

public interface MessageExecutor {

/**
* 接收到receive消息如何处理
*
* @param key
* 请求消息的Key,调用者需要在应答时通过该Key应答远端
* @param data
* 请求消息的内容
* @param session
* 远端Session,描述该消息是从哪发送来的
* @return
* 应答结果
*/
byte[] receive(String key, byte[] data, RemoteSession session);

/**
* 应答方式
*
* @return
* 参考:{@link REPLY}
*/
REPLY replyType();

// 应答方式


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/RemoteSession.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.RemoteSession
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/11 上午11:15
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/callback/CallBackBarrier.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.CallBackBarrier
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/12 上午10:22
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/callback/CallBackDataListener.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.callback.CallBackDataListener
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/15 下午4:40
* Description:
*/


+ 2
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/callback/CallBackLauncher.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.callback.CallBackLauncher
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/17 下午6:27
* Description:
*/
@@ -15,6 +15,7 @@ import java.util.concurrent.Semaphore;
* @author shaozhuguang
* @create 2019/4/17
* @since 1.0.0
* @date 2019-04-19 09:53
*/

public class CallBackLauncher {


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/AbstractAsyncExecutor.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.connection.AbstractAsyncExecutor
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/17 上午11:16
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/AsyncExecutor.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.connection.AsyncExecutor
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/17 上午11:14
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/Connection.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.connection.Connection
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/11 下午5:39
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/Receiver.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.inner.Receiver
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/11 上午10:59
* Description:
*/


+ 37
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/Sender.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.inner.Sender
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/11 上午10:58
* Description:
*/
@@ -101,6 +101,7 @@ public class Sender extends AbstractAsyncExecutor implements Closeable {

ThreadPoolExecutor runThread = initRunThread();

// 单独线程进行连接,防止当前调用线程阻塞
runThread.execute(() -> {
try {
// 发起连接请求
@@ -126,10 +127,28 @@ public class Sender extends AbstractAsyncExecutor implements Closeable {
});
}

/**
* 初始化相关配置
*
* @param remoteNode
* 远端节点
* @param sessionMessage
* 本地节点连接到远端节点后发送的SessionMessage
*/
private void init(RemoteNode remoteNode, SessionMessage sessionMessage) {
init(remoteNode.getHostName(), remoteNode.getPort(), sessionMessage);
}

/**
* 初始化相关配置
*
* @param remoteHost
* 远端HOST
* @param remotePort
* 远端端口
* @param sessionMessage
* 本地节点连接到远端节点后发送的SessionMessage
*/
private void init(String remoteHost, int remotePort, SessionMessage sessionMessage) {
this.remoteHost = remoteHost;
this.remotePort = remotePort;
@@ -149,7 +168,9 @@ public class Sender extends AbstractAsyncExecutor implements Closeable {

/**
* 发送消息
*
* @param message
* 消息统一接口
*/
public void send(IMessage message) {
watchDogHandler.channelFuture().channel().writeAndFlush(message.toTransferByteBuf());
@@ -161,15 +182,30 @@ public class Sender extends AbstractAsyncExecutor implements Closeable {
// loopGroup.shutdownGracefully();
}

/**
* ChannelHandler集合管理类
*/
public static class ChannelHandlers {

private List<ChannelHandler> channelHandlers = new ArrayList<>();

/**
* 添加指定的ChannelHandler
*
* @param channelHandler
* 需要加入的ChannelHandler
* @return
*/
public ChannelHandlers addHandler(ChannelHandler channelHandler) {
channelHandlers.add(channelHandler);
return this;
}

/**
* List集合转换为数组
*
* @return
*/
public ChannelHandler[] toArray() {
ChannelHandler[] channelHandlerArray = new ChannelHandler[channelHandlers.size()];
return channelHandlers.toArray(channelHandlerArray);


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/handler/HeartBeatReceiverHandler.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.connection.handler.HeartBeatSenderHandler
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/15 上午10:10
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/handler/HeartBeatReceiverTrigger.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.connection.handler.HeartBeatSenderTrigger
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/15 上午10:11
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/handler/HeartBeatSenderHandler.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.connection.handler.HeartBeatSenderHandler
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/15 上午10:10
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/handler/HeartBeatSenderTrigger.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.connection.handler.HeartBeatSenderTrigger
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/15 上午10:11
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/handler/ReceiverHandler.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.connection.handler.ReceiverHandler
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/12 上午11:14
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/handler/SenderHandler.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.connection.handler.SenderHandler
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/16 下午2:00
* Description:
*/


+ 26
- 4
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/handler/WatchDogHandler.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.connection.SenderWatchDog
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/12 下午4:56
* Description:
*/
@@ -27,6 +27,7 @@ import java.util.concurrent.locks.ReentrantLock;
* @author shaozhuguang
* @create 2019/4/12
* @since 1.0.0
* @date 2019-04-19 09:21
*/
@ChannelHandler.Sharable
public class WatchDogHandler extends ChannelInboundHandlerAdapter implements Runnable, Closeable {
@@ -42,13 +43,19 @@ public class WatchDogHandler extends ChannelInboundHandlerAdapter implements Run
*/
private final Lock reconnectLock = new ReentrantLock();

// 默认的最多重连次数
/**
* 默认的最多重连次数
*/
private final int maxReconnectSize = 16;

// 默认重连的时间
/**
* 默认重连的时间,下次重连时间会变长
*/
private final int defaultReconnectSeconds = 2;

// 标识是否正常工作中,假设不再工作则不再重连
/**
* 标识是否正常工作中,假设不再工作则不再重连
*/
private boolean isWorking = true;

/**
@@ -121,12 +128,27 @@ public class WatchDogHandler extends ChannelInboundHandlerAdapter implements Run
initTimer();
}

/**
* 初始化ChannelFuture
*
* @param channelFuture
*/
public void initChannelFuture(ChannelFuture channelFuture) {
this.channelFuture = channelFuture;
}

/**
* 返回ChannelFuture
*
* @return
* 该返回对象目前未处理是否连接成功的情况
* 调用者可直接使用,但假设发送不成功的话会存在异常抛出
* 调用者可手动处理异常
*/
public ChannelFuture channelFuture() {
try {
// 使用锁防止在重连进行过程中互相竞争
// 一定是等待本次重连完成才返回
reconnectLock.lock();
return this.channelFuture;
} finally {


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/connection/listener/ReplyListener.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.connection.listener.ReplyListener
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/12 上午10:36
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/manager/ConnectionManager.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.ConnectionManager
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/11 下午6:11
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/manager/RemoteSessionManager.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.RemoteSessionManager
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/11 上午11:22
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/message/AbstractMessage.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.message.AbstractMessage
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/17 下午4:00
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/message/HeartBeatMessage.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.message.HeartBeatMessage
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/12 下午4:55
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/message/IMessage.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.message.IMessage
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/16 下午1:58
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/message/LoadMessage.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.message.LoadMessage
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/11 上午10:59
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/message/SessionMessage.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.message.SessionMessage
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/16 上午10:40
* Description:
*/


+ 1
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/message/TransferMessage.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.message.TransferMessage
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/11 上午11:00
* Description:
*/


+ 2
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/node/LocalNode.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.node.LocalNode
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/16 下午3:12
* Description:
*/
@@ -15,6 +15,7 @@ import com.jd.blockchain.stp.communication.MessageExecutor;
* @author shaozhuguang
* @create 2019/4/16
* @since 1.0.0
* @date 2019-04-19 09:28
*/

public class LocalNode extends RemoteNode {


+ 2
- 1
source/stp/stp-communication/src/main/java/com/jd/blockchain/stp/communication/node/RemoteNode.java View File

@@ -2,7 +2,7 @@
* Copyright: Copyright 2016-2020 JD.COM All Right Reserved
* FileName: com.jd.blockchain.stp.communication.RemoteNode
* Author: shaozhuguang
* Department: Y事业部
* Department: Jingdong Digits Technology
* Date: 2019/4/11 下午3:40
* Description:
*/
@@ -13,6 +13,7 @@ package com.jd.blockchain.stp.communication.node;
* @author shaozhuguang
* @create 2019/4/11
* @since 1.0.0
* @date 2019-04-19 09:28
*/

public class RemoteNode {


Loading…
Cancel
Save