Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ func initTmClient(cfg *Config) {
})
}

// initRemoting init rpc client
// initRemoting init remoting
func initRemoting(cfg *Config) {
getty.InitRpcClient(&cfg.GettyConfig, &remoteConfig.SeataConfig{
SeataConfig := remoteConfig.SeataConfig{
ApplicationID: cfg.ApplicationID,
TxServiceGroup: cfg.TxServiceGroup,
ServiceVgroupMapping: cfg.ServiceConfig.VgroupMapping,
ServiceGrouplist: cfg.ServiceConfig.Grouplist,
LoadBalanceType: cfg.GettyConfig.LoadBalanceType,
})
}

getty.InitGetty(&cfg.GettyConfig, &SeataConfig)
}

// InitRmClient init client rm client
Expand Down
2 changes: 1 addition & 1 deletion pkg/remoting/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type SeataConfig struct {
LoadBalanceType string
}

func IniConfig(seataConf *SeataConfig) {
func InitConfig(seataConf *SeataConfig) {
seataConfig = seataConf
}

Expand Down
29 changes: 29 additions & 0 deletions pkg/remoting/getty/getty_init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package getty

import (
"seata.apache.org/seata-go/pkg/protocol/codec"
"seata.apache.org/seata-go/pkg/remoting/config"
)

func InitGetty(gettyConfig *config.Config, seataConfig *config.SeataConfig) {
config.InitConfig(seataConfig)
codec.Init()
initSessionManager(gettyConfig, seataConfig)
}
28 changes: 13 additions & 15 deletions pkg/remoting/getty/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,20 @@ var (
)

type gettyClientHandler struct {
idGenerator *atomic.Uint32
msgFutures *sync.Map
mergeMsgMap *sync.Map
sessionManager *SessionManager
processorMap map[message.MessageType]processor.RemotingProcessor
idGenerator *atomic.Uint32
msgFutures *sync.Map
mergeMsgMap *sync.Map
processorMap map[message.MessageType]processor.RemotingProcessor
}

func GetGettyClientHandlerInstance() *gettyClientHandler {
if clientHandler == nil {
onceClientHandler.Do(func() {
clientHandler = &gettyClientHandler{
idGenerator: &atomic.Uint32{},
msgFutures: &sync.Map{},
mergeMsgMap: &sync.Map{},
sessionManager: sessionManager,
processorMap: make(map[message.MessageType]processor.RemotingProcessor, 0),
idGenerator: &atomic.Uint32{},
msgFutures: &sync.Map{},
mergeMsgMap: &sync.Map{},
processorMap: make(map[message.MessageType]processor.RemotingProcessor, 0),
}
})
}
Expand All @@ -62,7 +60,7 @@ func GetGettyClientHandlerInstance() *gettyClientHandler {

func (g *gettyClientHandler) OnOpen(session getty.Session) error {
log.Infof("Open new getty session ")
g.sessionManager.registerSession(session)
sessionManager.registerSession(session)
conf := config.GetSeataConfig()
go func() {
request := message.RegisterTMRequest{AbstractIdentifyRequest: message.AbstractIdentifyRequest{
Expand All @@ -73,7 +71,7 @@ func (g *gettyClientHandler) OnOpen(session getty.Session) error {
err := GetGettyRemotingClient().SendAsyncRequest(request)
if err != nil {
log.Errorf("OnOpen error: {%#v}", err.Error())
g.sessionManager.releaseSession(session)
sessionManager.releaseSession(session)
return
}
}()
Expand All @@ -83,12 +81,12 @@ func (g *gettyClientHandler) OnOpen(session getty.Session) error {

func (g *gettyClientHandler) OnError(session getty.Session, err error) {
log.Infof("session{%s} got error{%v}, will be closed.", session.Stat(), err)
g.sessionManager.releaseSession(session)
sessionManager.releaseSession(session)
}

func (g *gettyClientHandler) OnClose(session getty.Session) {
log.Infof("session{%s} is closing......", session.Stat())
g.sessionManager.releaseSession(session)
sessionManager.releaseSession(session)
}

func (g *gettyClientHandler) OnMessage(session getty.Session, pkg interface{}) {
Expand Down Expand Up @@ -118,7 +116,7 @@ func (g *gettyClientHandler) OnCron(session getty.Session) {
err := g.transferHeartBeat(session, message.HeartBeatMessagePing)
if err != nil {
log.Errorf("failed to send heart beat: {%#v}", err.Error())
g.sessionManager.releaseSession(session)
sessionManager.releaseSession(session)
}
}

Expand Down
138 changes: 0 additions & 138 deletions pkg/remoting/getty/rpc_client.go

This file was deleted.

Loading
Loading