Commit 630edfeb authored by AlexStocks's avatar AlexStocks

use getty Session interface

parent e61e9aae
......@@ -63,7 +63,7 @@ func (this *EchoClient) close() {
client.lock.Unlock()
}
func (this *EchoClient) selectSession() *getty.Session {
func (this *EchoClient) selectSession() getty.Session {
// get route server session
this.lock.RLock()
defer this.lock.RUnlock()
......@@ -76,7 +76,7 @@ func (this *EchoClient) selectSession() *getty.Session {
return this.sessions[rand.Int31n(int32(count))].session
}
func (this *EchoClient) addSession(session *getty.Session) {
func (this *EchoClient) addSession(session getty.Session) {
log.Debug("add session{%s}", session.Stat())
if session == nil {
return
......@@ -87,7 +87,7 @@ func (this *EchoClient) addSession(session *getty.Session) {
this.lock.Unlock()
}
func (this *EchoClient) removeSession(session *getty.Session) {
func (this *EchoClient) removeSession(session getty.Session) {
if session == nil {
return
}
......@@ -106,7 +106,7 @@ func (this *EchoClient) removeSession(session *getty.Session) {
this.lock.Unlock()
}
func (this *EchoClient) updateSession(session *getty.Session) {
func (this *EchoClient) updateSession(session getty.Session) {
if session == nil {
return
}
......@@ -123,7 +123,7 @@ func (this *EchoClient) updateSession(session *getty.Session) {
this.lock.Unlock()
}
func (this *EchoClient) getClientEchoSession(session *getty.Session) (clientEchoSession, error) {
func (this *EchoClient) getClientEchoSession(session getty.Session) (clientEchoSession, error) {
var (
err error
echoSession clientEchoSession
......@@ -145,7 +145,7 @@ func (this *EchoClient) getClientEchoSession(session *getty.Session) (clientEcho
return echoSession, err
}
func (this *EchoClient) heartbeat(session *getty.Session) {
func (this *EchoClient) heartbeat(session getty.Session) {
var pkg EchoPackage
pkg.H.Magic = echoPkgMagic
pkg.H.LogID = (uint32)(src.Int63())
......
......@@ -28,7 +28,7 @@ var (
////////////////////////////////////////////
type clientEchoSession struct {
session *getty.Session
session getty.Session
reqNum int32
}
......@@ -39,23 +39,23 @@ func newEchoMessageHandler() *EchoMessageHandler {
return &EchoMessageHandler{}
}
func (this *EchoMessageHandler) OnOpen(session *getty.Session) error {
func (this *EchoMessageHandler) OnOpen(session getty.Session) error {
client.addSession(session)
return nil
}
func (this *EchoMessageHandler) OnError(session *getty.Session, err error) {
func (this *EchoMessageHandler) OnError(session getty.Session, err error) {
log.Info("session{%s} got error{%v}, will be closed.", session.Stat(), err)
client.removeSession(session)
}
func (this *EchoMessageHandler) OnClose(session *getty.Session) {
func (this *EchoMessageHandler) OnClose(session getty.Session) {
log.Info("session{%s} is closing......", session.Stat())
client.removeSession(session)
}
func (this *EchoMessageHandler) OnMessage(session *getty.Session, pkg interface{}) {
func (this *EchoMessageHandler) OnMessage(session getty.Session, pkg interface{}) {
p, ok := pkg.(*EchoPackage)
if !ok {
log.Error("illegal packge{%#v}", pkg)
......@@ -66,7 +66,7 @@ func (this *EchoMessageHandler) OnMessage(session *getty.Session, pkg interface{
client.updateSession(session)
}
func (this *EchoMessageHandler) OnCron(session *getty.Session) {
func (this *EchoMessageHandler) OnCron(session getty.Session) {
clientEchoSession, err := client.getClientEchoSession(session)
if err != nil {
log.Error("client.getClientSession(session{%s}) = error{%#v}", session.Stat(), err)
......
......@@ -69,7 +69,7 @@ func initProfiling() {
}()
}
func newSession(session *getty.Session) error {
func newSession(session getty.Session) error {
var (
ok bool
tcpConn *net.TCPConn
......
......@@ -27,7 +27,7 @@ func NewEchoPackageHandler() *EchoPackageHandler {
return &EchoPackageHandler{}
}
func (this *EchoPackageHandler) Read(ss *getty.Session, data []byte) (interface{}, int, error) {
func (this *EchoPackageHandler) Read(ss getty.Session, data []byte) (interface{}, int, error) {
var (
err error
len int
......@@ -48,7 +48,7 @@ func (this *EchoPackageHandler) Read(ss *getty.Session, data []byte) (interface{
return &pkg, len, nil
}
func (this *EchoPackageHandler) Write(ss *getty.Session, pkg interface{}) error {
func (this *EchoPackageHandler) Write(ss getty.Session, pkg interface{}) error {
var (
ok bool
err error
......
......@@ -25,7 +25,7 @@ var (
)
type PackageHandler interface {
Handle(*getty.Session, *EchoPackage) error
Handle(getty.Session, *EchoPackage) error
}
////////////////////////////////////////////
......@@ -34,7 +34,7 @@ type PackageHandler interface {
type HeartbeatHandler struct{}
func (this *HeartbeatHandler) Handle(session *getty.Session, pkg *EchoPackage) error {
func (this *HeartbeatHandler) Handle(session getty.Session, pkg *EchoPackage) error {
log.Debug("get echo heartbeat package{%s}", pkg)
var rspPkg EchoPackage
......@@ -51,7 +51,7 @@ func (this *HeartbeatHandler) Handle(session *getty.Session, pkg *EchoPackage) e
type MessageHandler struct{}
func (this *MessageHandler) Handle(session *getty.Session, pkg *EchoPackage) error {
func (this *MessageHandler) Handle(session getty.Session, pkg *EchoPackage) error {
log.Debug("get echo package{%s}", pkg)
return session.WritePkg(pkg)
}
......@@ -61,7 +61,7 @@ func (this *MessageHandler) Handle(session *getty.Session, pkg *EchoPackage) err
////////////////////////////////////////////
type clientEchoSession struct {
session *getty.Session
session getty.Session
active time.Time
reqNum int32
}
......@@ -70,7 +70,7 @@ type EchoMessageHandler struct {
handlers map[uint32]PackageHandler
rwlock sync.RWMutex
sessionMap map[*getty.Session]*clientEchoSession
sessionMap map[getty.Session]*clientEchoSession
}
func newEchoMessageHandler() *EchoMessageHandler {
......@@ -78,10 +78,10 @@ func newEchoMessageHandler() *EchoMessageHandler {
handlers[heartbeatCmd] = &HeartbeatHandler{}
handlers[echoCmd] = &MessageHandler{}
return &EchoMessageHandler{sessionMap: make(map[*getty.Session]*clientEchoSession), handlers: handlers}
return &EchoMessageHandler{sessionMap: make(map[getty.Session]*clientEchoSession), handlers: handlers}
}
func (this *EchoMessageHandler) OnOpen(session *getty.Session) error {
func (this *EchoMessageHandler) OnOpen(session getty.Session) error {
var (
err error
)
......@@ -102,21 +102,21 @@ func (this *EchoMessageHandler) OnOpen(session *getty.Session) error {
return nil
}
func (this *EchoMessageHandler) OnError(session *getty.Session, err error) {
func (this *EchoMessageHandler) OnError(session getty.Session, err error) {
log.Info("session{%s} got error{%v}, will be closed.", session.Stat(), err)
this.rwlock.Lock()
delete(this.sessionMap, session)
this.rwlock.Unlock()
}
func (this *EchoMessageHandler) OnClose(session *getty.Session) {
func (this *EchoMessageHandler) OnClose(session getty.Session) {
log.Info("session{%s} is closing......", session.Stat())
this.rwlock.Lock()
delete(this.sessionMap, session)
this.rwlock.Unlock()
}
func (this *EchoMessageHandler) OnMessage(session *getty.Session, pkg interface{}) {
func (this *EchoMessageHandler) OnMessage(session getty.Session, pkg interface{}) {
p, ok := pkg.(*EchoPackage)
if !ok {
log.Error("illegal packge{%#v}", pkg)
......@@ -139,7 +139,7 @@ func (this *EchoMessageHandler) OnMessage(session *getty.Session, pkg interface{
}
}
func (this *EchoMessageHandler) OnCron(session *getty.Session) {
func (this *EchoMessageHandler) OnCron(session getty.Session) {
var (
flag bool
active time.Time
......
......@@ -27,7 +27,7 @@ func NewEchoPackageHandler() *EchoPackageHandler {
return &EchoPackageHandler{}
}
func (this *EchoPackageHandler) Read(ss *getty.Session, data []byte) (interface{}, int, error) {
func (this *EchoPackageHandler) Read(ss getty.Session, data []byte) (interface{}, int, error) {
var (
err error
len int
......@@ -48,7 +48,7 @@ func (this *EchoPackageHandler) Read(ss *getty.Session, data []byte) (interface{
return &pkg, len, nil
}
func (this *EchoPackageHandler) Write(ss *getty.Session, pkg interface{}) error {
func (this *EchoPackageHandler) Write(ss getty.Session, pkg interface{}) error {
var (
ok bool
err error
......
......@@ -74,7 +74,7 @@ func initProfiling() {
}()
}
func newSession(session *getty.Session) error {
func newSession(session getty.Session) error {
var (
ok bool
tcpConn *net.TCPConn
......
......@@ -62,7 +62,7 @@ func (this *EchoClient) close() {
client.lock.Unlock()
}
func (this *EchoClient) selectSession() *getty.Session {
func (this *EchoClient) selectSession() getty.Session {
// get route server session
this.lock.RLock()
defer this.lock.RUnlock()
......@@ -75,7 +75,7 @@ func (this *EchoClient) selectSession() *getty.Session {
return this.sessions[rand.Int31n(int32(count))].session
}
func (this *EchoClient) addSession(session *getty.Session) {
func (this *EchoClient) addSession(session getty.Session) {
log.Debug("add session{%s}", session.Stat())
if session == nil {
return
......@@ -86,7 +86,7 @@ func (this *EchoClient) addSession(session *getty.Session) {
this.lock.Unlock()
}
func (this *EchoClient) removeSession(session *getty.Session) {
func (this *EchoClient) removeSession(session getty.Session) {
if session == nil {
return
}
......@@ -105,7 +105,7 @@ func (this *EchoClient) removeSession(session *getty.Session) {
this.lock.Unlock()
}
func (this *EchoClient) updateSession(session *getty.Session) {
func (this *EchoClient) updateSession(session getty.Session) {
if session == nil {
return
}
......@@ -122,7 +122,7 @@ func (this *EchoClient) updateSession(session *getty.Session) {
this.lock.Unlock()
}
func (this *EchoClient) getClientEchoSession(session *getty.Session) (clientEchoSession, error) {
func (this *EchoClient) getClientEchoSession(session getty.Session) (clientEchoSession, error) {
var (
err error
echoSession clientEchoSession
......
......@@ -28,7 +28,7 @@ var (
////////////////////////////////////////////
type clientEchoSession struct {
session *getty.Session
session getty.Session
reqNum int32
}
......@@ -39,23 +39,23 @@ func newEchoMessageHandler() *EchoMessageHandler {
return &EchoMessageHandler{}
}
func (this *EchoMessageHandler) OnOpen(session *getty.Session) error {
func (this *EchoMessageHandler) OnOpen(session getty.Session) error {
client.addSession(session)
return nil
}
func (this *EchoMessageHandler) OnError(session *getty.Session, err error) {
func (this *EchoMessageHandler) OnError(session getty.Session, err error) {
log.Info("session{%s} got error{%v}, will be closed.", session.Stat(), err)
client.removeSession(session)
}
func (this *EchoMessageHandler) OnClose(session *getty.Session) {
func (this *EchoMessageHandler) OnClose(session getty.Session) {
log.Info("session{%s} is closing......", session.Stat())
client.removeSession(session)
}
func (this *EchoMessageHandler) OnMessage(session *getty.Session, pkg interface{}) {
func (this *EchoMessageHandler) OnMessage(session getty.Session, pkg interface{}) {
p, ok := pkg.(*EchoPackage)
if !ok {
log.Error("illegal packge{%#v}", pkg)
......@@ -66,7 +66,7 @@ func (this *EchoMessageHandler) OnMessage(session *getty.Session, pkg interface{
client.updateSession(session)
}
func (this *EchoMessageHandler) OnCron(session *getty.Session) {
func (this *EchoMessageHandler) OnCron(session getty.Session) {
clientEchoSession, err := client.getClientEchoSession(session)
if err != nil {
log.Error("client.getClientSession(session{%s}) = error{%#v}", session.Stat(), err)
......
......@@ -69,7 +69,7 @@ func initProfiling() {
}()
}
func newSession(session *getty.Session) error {
func newSession(session getty.Session) error {
var (
ok bool
tcpConn *net.TCPConn
......
......@@ -27,7 +27,7 @@ func NewEchoPackageHandler() *EchoPackageHandler {
return &EchoPackageHandler{}
}
func (this *EchoPackageHandler) Read(ss *getty.Session, data []byte) (interface{}, int, error) {
func (this *EchoPackageHandler) Read(ss getty.Session, data []byte) (interface{}, int, error) {
var (
err error
len int
......@@ -48,7 +48,7 @@ func (this *EchoPackageHandler) Read(ss *getty.Session, data []byte) (interface{
return &pkg, len, nil
}
func (this *EchoPackageHandler) Write(ss *getty.Session, pkg interface{}) error {
func (this *EchoPackageHandler) Write(ss getty.Session, pkg interface{}) error {
var (
ok bool
err error
......
......@@ -25,7 +25,7 @@ var (
)
type PackageHandler interface {
Handle(*getty.Session, *EchoPackage) error
Handle(getty.Session, *EchoPackage) error
}
////////////////////////////////////////////
......@@ -34,7 +34,7 @@ type PackageHandler interface {
type MessageHandler struct{}
func (this *MessageHandler) Handle(session *getty.Session, pkg *EchoPackage) error {
func (this *MessageHandler) Handle(session getty.Session, pkg *EchoPackage) error {
log.Debug("get echo package{%s}", pkg)
return session.WritePkg(pkg)
}
......@@ -44,7 +44,7 @@ func (this *MessageHandler) Handle(session *getty.Session, pkg *EchoPackage) err
////////////////////////////////////////////
type clientEchoSession struct {
session *getty.Session
session getty.Session
reqNum int32
}
......@@ -52,17 +52,17 @@ type EchoMessageHandler struct {
handlers map[uint32]PackageHandler
rwlock sync.RWMutex
sessionMap map[*getty.Session]*clientEchoSession
sessionMap map[getty.Session]*clientEchoSession
}
func newEchoMessageHandler() *EchoMessageHandler {
handlers := make(map[uint32]PackageHandler)
handlers[echoCmd] = &MessageHandler{}
return &EchoMessageHandler{sessionMap: make(map[*getty.Session]*clientEchoSession), handlers: handlers}
return &EchoMessageHandler{sessionMap: make(map[getty.Session]*clientEchoSession), handlers: handlers}
}
func (this *EchoMessageHandler) OnOpen(session *getty.Session) error {
func (this *EchoMessageHandler) OnOpen(session getty.Session) error {
var (
err error
)
......@@ -83,21 +83,21 @@ func (this *EchoMessageHandler) OnOpen(session *getty.Session) error {
return nil
}
func (this *EchoMessageHandler) OnError(session *getty.Session, err error) {
func (this *EchoMessageHandler) OnError(session getty.Session, err error) {
log.Info("session{%s} got error{%v}, will be closed.", session.Stat(), err)
this.rwlock.Lock()
delete(this.sessionMap, session)
this.rwlock.Unlock()
}
func (this *EchoMessageHandler) OnClose(session *getty.Session) {
func (this *EchoMessageHandler) OnClose(session getty.Session) {
log.Info("session{%s} is closing......", session.Stat())
this.rwlock.Lock()
delete(this.sessionMap, session)
this.rwlock.Unlock()
}
func (this *EchoMessageHandler) OnMessage(session *getty.Session, pkg interface{}) {
func (this *EchoMessageHandler) OnMessage(session getty.Session, pkg interface{}) {
p, ok := pkg.(*EchoPackage)
if !ok {
log.Error("illegal packge{%#v}, %s", pkg, string(pkg.([]byte)))
......@@ -119,7 +119,7 @@ func (this *EchoMessageHandler) OnMessage(session *getty.Session, pkg interface{
}
}
func (this *EchoMessageHandler) OnCron(session *getty.Session) {
func (this *EchoMessageHandler) OnCron(session getty.Session) {
var (
flag bool
active time.Time
......
......@@ -28,7 +28,7 @@ func NewEchoPackageHandler() *EchoPackageHandler {
return &EchoPackageHandler{}
}
func (this *EchoPackageHandler) Read(ss *getty.Session, data []byte) (interface{}, int, error) {
func (this *EchoPackageHandler) Read(ss getty.Session, data []byte) (interface{}, int, error) {
// log.Debug("get client package:%s", gxstrings.String(data))
var (
err error
......@@ -52,7 +52,7 @@ func (this *EchoPackageHandler) Read(ss *getty.Session, data []byte) (interface{
// return data, len(data), nil
}
func (this *EchoPackageHandler) Write(ss *getty.Session, pkg interface{}) error {
func (this *EchoPackageHandler) Write(ss getty.Session, pkg interface{}) error {
var (
ok bool
err error
......
......@@ -74,7 +74,7 @@ func initProfiling() {
}()
}
func newSession(session *getty.Session) error {
func newSession(session getty.Session) error {
var (
ok bool
tcpConn *net.TCPConn
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment