Skip to content

Commit

Permalink
注释补充
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghanzheng committed Jul 14, 2023
1 parent 7033166 commit b62f088
Show file tree
Hide file tree
Showing 33 changed files with 168 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,13 @@ public void send(@NonNull Message message, Runnable onSuccess, Consumer<Throwabl
//Send and retry if failure
Consumer<Consumer<Throwable>> send = consumer ->
doSend(encode, onSuccess, consumer, onComplete);
send.accept(e -> messageRetryStrategy.retry(e, send, onError));
send.accept(e -> {
if (e instanceof MessageTransportException) {
messageRetryStrategy.retry(e, send, onError);
} else {
onError.accept(e);
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ default boolean isObservableType() {
List<MessageSendInterceptor> getMessageSendInterceptors();

/**
* 设置 {@link ConnectionLoadBalanceConcept}
* 设置 Concept
* <p>
* Set {@link ConnectionLoadBalanceConcept}.
* Set Concept.
*/
void setConcept(@NonNull ConnectionLoadBalanceConcept concept);

/**
* 获得 {@link ConnectionLoadBalanceConcept}
* 获得 Concept
* <p>
* Get {@link ConnectionLoadBalanceConcept}.
* Get Concept.
*/
ConnectionLoadBalanceConcept getConcept();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import com.github.linyuzai.connection.loadbalance.core.message.encode.MessageEncoder;
import com.github.linyuzai.connection.loadbalance.core.scope.AbstractScoped;


/**
* 消息编解码适配器的抽象类
* 消息编解码适配器的抽象类。
* <p>
* Abstract adapter of codec for message.
*/
public abstract class AbstractMessageCodecAdapter extends AbstractScoped implements MessageCodecAdapter {

Expand Down Expand Up @@ -39,54 +42,54 @@ public MessageDecoder getMessageDecoder(String type, MessageDecoder decoder) {
}

/**
* 发消息给客户端时的消息编码器
*
* @return 消息编码器
* 获得客户端连接的消息编码器。
* <p>
* Get encoder for message of client connection.
*/
public MessageEncoder getClientMessageEncoder(MessageEncoder encoder) {
return encoder;
}

/**
* 接收客户端消息的消息解码器
*
* @return 消息解码器
* 获得客户端连接的消息解码器。
* <p>
* Get decoder for message of client connection.
*/
public MessageDecoder getClientMessageDecoder(MessageDecoder decoder) {
return decoder;
}

/**
* 订阅时发送服务信息的消息编码器
*
* @return 消息编码器
* 获得订阅连接的消息编码器。
* <p>
* Get encoder for message of subscription.
*/
public MessageEncoder getSubscribeMessageEncoder(MessageEncoder encoder) {
return encoder;
}

/**
* 订阅时接收服务信息的消息解码器
*
* @return 消息解码器
* 获得订阅连接的消息解码器。
* <p>
* Get decoder for message of subscription.
*/
public MessageDecoder getSubscribeMessageDecoder(MessageDecoder decoder) {
return decoder;
}

/**
* 转发消息的消息编码器
*
* @return 消息编码器
* 获得转发连接的消息编码器。
* <p>
* Get encoder for message of forward.
*/
public MessageEncoder getForwardMessageEncoder(MessageEncoder encoder) {
return encoder;
}

/**
* 接收消息转发的消息解码器
*
* @return 消息解码器
* 获得转发连接的消息解码器。
* <p>
* Get decoder for message of forward.
*/
public MessageDecoder getForwardMessageDecoder(MessageDecoder decoder) {
return decoder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
import com.github.linyuzai.connection.loadbalance.core.message.encode.MessageEncoder;
import com.github.linyuzai.connection.loadbalance.core.subscribe.JacksonSubscribeMessageDecoder;

/**
* 基础编解码适配器。
* 提供最基础的编解码器。
* <p>
* Adapter for message codec to provider basic encoder and decoder.
*/
public class BaseMessageCodecAdapter extends AbstractMessageCodecAdapter {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.nio.ByteBuffer;

/**
* 二进制消息
* 二进制消息。
* <p>
* Message has binary payload.
*/
@NoArgsConstructor
public class BinaryMessage extends AbstractMessage<ByteBuffer> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.nio.ByteBuffer;

/**
* 二进制的 ping 消息
* 二进制的 ping 消息。
* <p>
* Ping message has binary payload.
*/
public class BinaryPingMessage extends BinaryMessage implements PingMessage {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.nio.ByteBuffer;

/**
* 二进制的 pong 消息
* 二进制的 pong 消息。
* <p>
* Pong message has binary payload.
*/
public class BinaryPongMessage extends BinaryMessage implements PongMessage {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import lombok.Getter;

/**
* 死亡消息事件
* 死亡消息事件。
* 当该消息不会发送给任何连接时发布。
* <p>
* 当该消息不会发送给任何连接时发布
* Event will be published when no connection to send.
*/
@Getter
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@
import com.github.linyuzai.connection.loadbalance.core.scope.Scoped;

/**
* 消息编解码适配器
* 消息编解码适配器
* <p>
* 统一管理编解码器,不然很混乱
* Adapter of codec for message.
*/
public interface MessageCodecAdapter extends Scoped {

/**
* 通过连接类型获得消息编码器
*
* @param type 连接类型
* @return 消息编码器
* 根据连接类型获得消息编码器。
* <p>
* Get encoder for message by connection's type.
*/
MessageEncoder getMessageEncoder(String type, MessageEncoder encoder);

/**
* 通过连接类型获得消息解码器
*
* @param type 连接类型
* @return 消息解码器
* 根据连接类型获得消息解码器。
* <p>
* Get decoder for message by connection's type.
*/
MessageDecoder getMessageDecoder(String type, MessageDecoder decoder);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

import java.util.List;

/**
* 消息编解码适配链。
* <p>
* A chain to adapt message codec.
*/
@Getter
@RequiredArgsConstructor
public class MessageCodecAdapterChain extends AbstractScoped implements MessageCodecAdapter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package com.github.linyuzai.connection.loadbalance.core.message;

/**
* 消息条件。
* 给消息添加条件。
* <p>
* Condition of message.
* Add some conditions to the message.
*/
public interface MessageCondition {

void apply(Message message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import lombok.RequiredArgsConstructor;

/**
* 消息丢弃事件
* 消息丢弃事件。
* <p>
* Event will be published when message discard.
*/
@Getter
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.github.linyuzai.connection.loadbalance.core.message;

/**
* 消息事件
* 消息事件。
* <p>
* Message's event.
*/
public interface MessageEvent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,49 @@
import java.util.stream.Collectors;

/**
* 消息工厂
* 消息工厂。
* <p>
* Factory of message.
*/
public interface MessageFactory extends Scoped {

/**
* 是否支持。
* <p>
* Use this factory to create message if return true.
*/
boolean support(Object message, ConnectionLoadBalanceConcept concept);

/**
* 是否支持。
* <p>
* Use this factory to create message if return true.
*/
default boolean support(Object message) {
return support(message, null);
}

/**
* 创建消息。
* <p>
* Create the message with input.
*/
Message create(Object message, ConnectionLoadBalanceConcept concept);

/**
* 创建消息。
* <p>
* Create the message with input.
*/
default Message create(Object message) {
return create(message, null);
}

/**
* 消息工厂代理。
* <p>
* Delegate of factory for message.
*/
@Getter
@RequiredArgsConstructor
class Delegate implements MessageFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import lombok.RequiredArgsConstructor;

/**
* 消息转发异常事件
* 消息转发异常事件。
* <p>
* Event will be published when message forward error.
*/
@Getter
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import lombok.RequiredArgsConstructor;

/**
* 消息转发事件
* 消息转发事件。
* <p>
* Event will be published when message forwarded.
*/
@Getter
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import com.github.linyuzai.connection.loadbalance.core.concept.ConnectionLoadBalanceConcept;

/**
* 消息转发处理器
* 消息转发处理器。
* 当服务实例收到转发的消息后发送给自己的客户端连接。
* <p>
* 当服务实例的客户端收到转发的消息后发送给自己真实的客户端连接
* Forward messages to clients which connected by this server instance
* when received message from other service instance.
*/
public class MessageForwardHandler implements MessageReceiveEventListener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import com.github.linyuzai.connection.loadbalance.core.concept.Connection;

/**
* 消息处理器
* 消息处理器。
* 用于接收客户端的消息。
* <p>
* 用于接收客户端的消息
* Handler to handle messages from clients.
*/
public interface MessageHandler extends MessageReceiveEventListener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import java.util.Collection;

/**
* 消息准备事件
* 消息准备事件
* <p>
* 在消息还未发送时发布
* Event will be published when message preparing.
*/
@Getter
public class MessagePrepareEvent extends TimestampEvent implements MessageEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import lombok.RequiredArgsConstructor;

/**
* 消息接收事件
* 消息接收事件。
* <p>
* Event will be published when message received.
*/
@Getter
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import com.github.linyuzai.connection.loadbalance.core.event.ConnectionEventListener;

/**
* 消息接收事件监听器
* 消息接收事件监听器。
* <p>
* To listen message receive event.
*/
public interface MessageReceiveEventListener extends ConnectionEventListener {

Expand Down
Loading

0 comments on commit b62f088

Please sign in to comment.