From 201bf2374bba6f381040ce3b7059f32a9f1a1d9f Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Mon, 16 Nov 2015 15:50:26 -0800 Subject: [PATCH] Update README; Remove GetEvents() from Application --- README.md | 13 +++++++++++-- example/main.go | 8 ++------ server/server.go | 9 +-------- types/application.go | 5 +---- types/events.go | 9 ++++----- 5 files changed, 19 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 2e5b5652..b1790e03 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,7 @@ TMSP is an asynchronous streaming protocol: message responses are written back a * __Arguments__: * `EventsMode (int8)`: * `EventsModeOff (0)`: Events are not reported. Used for mempool. - * `EventsModeCached (1)`: Events are cached. - * `EventsModeOn (2)`: Flush cache and report events. + * `EventsModeOn (1)`: Report events that are listened on. * __Returns__: * `RetCode (int8)` * __Usage__:
@@ -61,3 +60,13 @@ TMSP is an asynchronous streaming protocol: message responses are written back a * __Usage__:
Remove event listener callback for events with given key. +#### Flush + * __Usage__:
+ Flush the response queue. Applications that implement `types.Application` need not implement this message -- it's handled by the project. + +#### Info + * __Returns__: + * `Data ([]string)` + * __Usage__:
+ Return an array of strings about the application state. Application specific. + diff --git a/example/main.go b/example/main.go index a86535d4..dabb486e 100644 --- a/example/main.go +++ b/example/main.go @@ -51,9 +51,9 @@ func (dapp *DummyApplication) Info() []string { return []string{Fmt("size:%v", dapp.state.Size())} } -func (dapp *DummyApplication) AppendTx(tx []byte) types.RetCode { +func (dapp *DummyApplication) AppendTx(tx []byte) ([]types.Event, types.RetCode) { dapp.state.Set(tx, tx) - return 0 + return nil, 0 } func (dapp *DummyApplication) GetHash() ([]byte, types.RetCode) { @@ -82,7 +82,3 @@ func (dapp *DummyApplication) AddListener(key string) types.RetCode { func (dapp *DummyApplication) RemListener(key string) types.RetCode { return 0 } - -func (dapp *DummyApplication) GetEvents() []types.Event { - return nil -} diff --git a/server/server.go b/server/server.go index 73c27d0e..27faa1d3 100644 --- a/server/server.go +++ b/server/server.go @@ -78,9 +78,8 @@ func handleRequest(app types.Application, req types.Request, responses chan<- ty data := app.Info() responses <- types.ResponseInfo{data} case types.RequestAppendTx: - retCode := app.AppendTx(req.TxBytes) + events, retCode := app.AppendTx(req.TxBytes) responses <- types.ResponseAppendTx{retCode} - events := app.GetEvents() for _, event := range events { responses <- types.ResponseEvent{event} } @@ -96,12 +95,6 @@ func handleRequest(app types.Application, req types.Request, responses chan<- ty case types.RequestSetEventsMode: retCode := app.SetEventsMode(req.EventsMode) responses <- types.ResponseSetEventsMode{retCode} - if req.EventsMode == types.EventsModeOn { - events := app.GetEvents() - for _, event := range events { - responses <- types.ResponseEvent{event} - } - } case types.RequestAddListener: retCode := app.AddListener(req.EventKey) responses <- types.ResponseAddListener{retCode} diff --git a/types/application.go b/types/application.go index ce9a6670..2b4e942f 100644 --- a/types/application.go +++ b/types/application.go @@ -9,7 +9,7 @@ type Application interface { Info() []string // Append a tx, which may or may not get committed - AppendTx(tx []byte) RetCode + AppendTx(tx []byte) ([]Event, RetCode) // Return the application Merkle root hash GetHash() ([]byte, RetCode) @@ -28,7 +28,4 @@ type Application interface { // Remove event listener RemListener(key string) RetCode - - // Get all events - GetEvents() []Event } diff --git a/types/events.go b/types/events.go index 8a7fa237..37f51a44 100644 --- a/types/events.go +++ b/types/events.go @@ -3,12 +3,11 @@ package types type EventsMode int8 const ( - EventsModeOff = EventsMode(0) - EventsModeCached = EventsMode(1) - EventsModeOn = EventsMode(2) + EventsModeOff = EventsMode(0) + EventsModeOn = EventsMode(1) ) type Event struct { - Key string - TxBytes []byte + Key string + Data []byte }