-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathabstract_bootstrap.go
57 lines (47 loc) · 1.35 KB
/
abstract_bootstrap.go
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
52
53
54
55
56
57
//Created by zhbinary on 2019-04-20.
//Email: [email protected]
package netty4go
import (
"github.com/zhbinary/heng/types"
"net"
"reflect"
)
type AbstractBootstrap struct {
group types.EventLoopGroup
handler types.ChannelHandler
opts *Options
attrs map[string]interface{}
channelType reflect.Type
initChannel func(channel types.Channel)
}
func (this *AbstractBootstrap) Bind(remote net.Addr) {
regFuture := this.initAndRegister()
channel := regFuture.Channel()
addr := &net.TCPAddr{IP: net.IP{}, Port: 8280}
if regFuture.IsDone() {
channel.Bind(addr)
} else {
regFuture.AddListener(&types.FutureListenerAdapter{OperationCompleteCb: func(future types.Future) {
channel.Bind(addr)
}})
}
}
func (this *AbstractBootstrap) Bind0(local net.Addr, remote net.Addr) {
}
func (this *AbstractBootstrap) Channel(t reflect.Type) {
this.channelType = t
}
func (this *AbstractBootstrap) newChannel() types.Channel {
return reflect.New(this.channelType).Interface().(types.Channel)
}
func (this *AbstractBootstrap) Group(group types.EventLoopGroup) {
this.group = group
}
func (this *AbstractBootstrap) Handler(handler types.ChannelHandler) {
this.handler = handler
}
func (this *AbstractBootstrap) initAndRegister() types.ChannelFutrue {
channel := this.newChannel()
this.initChannel(channel)
return this.group.Register(channel)
}