|
@ -15,27 +15,35 @@ var _ Client = (*localClient)(nil) |
|
|
type localClient struct { |
|
|
type localClient struct { |
|
|
service.BaseService |
|
|
service.BaseService |
|
|
|
|
|
|
|
|
mtx *tmsync.Mutex |
|
|
|
|
|
|
|
|
mtx *tmsync.RWMutex |
|
|
types.Application |
|
|
types.Application |
|
|
Callback |
|
|
Callback |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func NewLocalClient(mtx *tmsync.Mutex, app types.Application) Client { |
|
|
|
|
|
|
|
|
var _ Client = (*localClient)(nil) |
|
|
|
|
|
|
|
|
|
|
|
// NewLocalClient creates a local client, which will be directly calling the
|
|
|
|
|
|
// methods of the given app.
|
|
|
|
|
|
//
|
|
|
|
|
|
// Both Async and Sync methods ignore the given context.Context parameter.
|
|
|
|
|
|
func NewLocalClient(mtx *tmsync.RWMutex, app types.Application) Client { |
|
|
if mtx == nil { |
|
|
if mtx == nil { |
|
|
mtx = new(tmsync.Mutex) |
|
|
|
|
|
|
|
|
mtx = &tmsync.RWMutex{} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
cli := &localClient{ |
|
|
cli := &localClient{ |
|
|
mtx: mtx, |
|
|
mtx: mtx, |
|
|
Application: app, |
|
|
Application: app, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
cli.BaseService = *service.NewBaseService(nil, "localClient", cli) |
|
|
cli.BaseService = *service.NewBaseService(nil, "localClient", cli) |
|
|
return cli |
|
|
return cli |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (app *localClient) SetResponseCallback(cb Callback) { |
|
|
func (app *localClient) SetResponseCallback(cb Callback) { |
|
|
app.mtx.Lock() |
|
|
app.mtx.Lock() |
|
|
|
|
|
defer app.mtx.Unlock() |
|
|
app.Callback = cb |
|
|
app.Callback = cb |
|
|
app.mtx.Unlock() |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TODO: change types.Application to include Error()?
|
|
|
// TODO: change types.Application to include Error()?
|
|
@ -59,8 +67,8 @@ func (app *localClient) EchoAsync(msg string) *ReqRes { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (app *localClient) InfoAsync(req types.RequestInfo) *ReqRes { |
|
|
func (app *localClient) InfoAsync(req types.RequestInfo) *ReqRes { |
|
|
app.mtx.Lock() |
|
|
|
|
|
defer app.mtx.Unlock() |
|
|
|
|
|
|
|
|
app.mtx.RLock() |
|
|
|
|
|
defer app.mtx.RUnlock() |
|
|
|
|
|
|
|
|
res := app.Application.Info(req) |
|
|
res := app.Application.Info(req) |
|
|
return app.callback( |
|
|
return app.callback( |
|
@ -103,8 +111,8 @@ func (app *localClient) CheckTxAsync(req types.RequestCheckTx) *ReqRes { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (app *localClient) QueryAsync(req types.RequestQuery) *ReqRes { |
|
|
func (app *localClient) QueryAsync(req types.RequestQuery) *ReqRes { |
|
|
app.mtx.Lock() |
|
|
|
|
|
defer app.mtx.Unlock() |
|
|
|
|
|
|
|
|
app.mtx.RLock() |
|
|
|
|
|
defer app.mtx.RUnlock() |
|
|
|
|
|
|
|
|
res := app.Application.Query(req) |
|
|
res := app.Application.Query(req) |
|
|
return app.callback( |
|
|
return app.callback( |
|
@ -212,8 +220,8 @@ func (app *localClient) EchoSync(msg string) (*types.ResponseEcho, error) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (app *localClient) InfoSync(req types.RequestInfo) (*types.ResponseInfo, error) { |
|
|
func (app *localClient) InfoSync(req types.RequestInfo) (*types.ResponseInfo, error) { |
|
|
app.mtx.Lock() |
|
|
|
|
|
defer app.mtx.Unlock() |
|
|
|
|
|
|
|
|
app.mtx.RLock() |
|
|
|
|
|
defer app.mtx.RUnlock() |
|
|
|
|
|
|
|
|
res := app.Application.Info(req) |
|
|
res := app.Application.Info(req) |
|
|
return &res, nil |
|
|
return &res, nil |
|
@ -244,8 +252,8 @@ func (app *localClient) CheckTxSync(req types.RequestCheckTx) (*types.ResponseCh |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (app *localClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery, error) { |
|
|
func (app *localClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery, error) { |
|
|
app.mtx.Lock() |
|
|
|
|
|
defer app.mtx.Unlock() |
|
|
|
|
|
|
|
|
app.mtx.RLock() |
|
|
|
|
|
defer app.mtx.RUnlock() |
|
|
|
|
|
|
|
|
res := app.Application.Query(req) |
|
|
res := app.Application.Query(req) |
|
|
return &res, nil |
|
|
return &res, nil |
|
|