shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.walker.tcp.netty;
 
import com.walker.infrastructure.ServerId;
import com.walker.infrastructure.utils.NumberGenerator;
import com.walker.infrastructure.utils.StringUtils;
import io.netty.channel.Channel;
import io.netty.channel.ChannelId;
import io.netty.channel.socket.nio.NioSocketChannel;
 
/**
 * 生成长连接通道ID。自定义该对象。
 * @author 时克英
 * @date 2023-09-29
 */
@Deprecated
public class GenIdClientSocketChannel extends NioSocketChannel {
 
    public GenIdClientSocketChannel(){}
 
    public GenIdClientSocketChannel(Channel parent, java.nio.channels.SocketChannel socket) {
        super(parent, socket);
//        this.config = new NioSocketChannelConfig(this, socket.socket());
    }
 
    @Override
    protected ChannelId newId() {
        ChannelId channelId = new ChannelId() {
            @Override
            public String asShortText() {
                return new StringBuilder(ServerId.getId())
                        .append(StringUtils.STRING_UNDERLINE).append(NumberGenerator.getSequenceNumber())
                        .append(StringUtils.STRING_UNDERLINE).append(StringUtils.generateRandomNumber(8)).toString();
//                return UUID.randomUUID().toString();
            }
 
            @Override
            public String asLongText() {
//                return UUID.randomUUID().toString();
                return new StringBuilder(ServerId.getId())
                        .append(StringUtils.STRING_UNDERLINE).append(NumberGenerator.getLongSequenceNumber())
                        .append(StringUtils.STRING_UNDERLINE).append(StringUtils.generateRandomNumber(8)).toString();
            }
 
            @Override
            public int compareTo(ChannelId o) {
                return 0;
            }
        };
        return channelId;
    }
}