Skip to content

Commit

Permalink
Text input (#285)
Browse files Browse the repository at this point in the history
* use separated input service collection

* removed text input service package for separation

* added text input collection to vendor deps

* updated spec package in vendor deps

* updated collection package in vendor deps

* updated glide files
  • Loading branch information
xh3b4sd authored Nov 19, 2016
1 parent 2dabcab commit 7b4dfb2
Show file tree
Hide file tree
Showing 23 changed files with 198 additions and 189 deletions.
8 changes: 4 additions & 4 deletions annactl/annactl_interface_text_read_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/spf13/cobra"
"golang.org/x/net/context"

"github.com/xh3b4sd/anna/object/textinput"
textinputobject "github.com/the-anna-project/input/object/text"
)

func (a *annactl) InitAnnactlInterfaceTextReadFileCmd() *cobra.Command {
Expand Down Expand Up @@ -45,13 +45,13 @@ func (a *annactl) ExecAnnactlInterfaceTextReadFileCmd(cmd *cobra.Command, args [
a.Service().Log().Line("msg", "%#v", maskAny(err))
}

textRequest := textinput.MustNew()
err = json.Unmarshal(b, &textRequest)
textInputObject := textinputobject.New()
err = json.Unmarshal(b, &textInputObject)
if err != nil {
a.Service().Log().Line("msg", "%#v", maskAny(err))
}

a.Service().TextInput().Channel() <- textRequest
a.Service().Input().Text().Channel() <- textInputObject

go func() {
err = a.textInterface.StreamText(ctx)
Expand Down
18 changes: 7 additions & 11 deletions annactl/annactl_interface_text_read_plain.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/spf13/cobra"
"golang.org/x/net/context"

"github.com/xh3b4sd/anna/object/textinput"
textinputobject "github.com/the-anna-project/input/object/text"
)

func (a *annactl) InitAnnactlInterfaceTextReadPlainCmd() *cobra.Command {
Expand Down Expand Up @@ -44,18 +44,14 @@ func (a *annactl) ExecAnnactlInterfaceTextReadPlainCmd(cmd *cobra.Command, args

scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
newTextInputConfig := textinput.DefaultConfig()
newTextInputConfig.Echo = a.flags.InterfaceTextReadPlain.Echo
newTextInputConfig.Input = scanner.Text()
newTextInputConfig.SessionID = a.sessionID
newTextInput, err := textinput.New(newTextInputConfig)
if err != nil {
a.Service().Log().Line("msg", "%#v", maskAny(err))
}
textInputObject := textinputobject.New()
textInputObject.SetEcho(a.flags.InterfaceTextReadPlain.Echo)
textInputObject.SetInput(scanner.Text())
textInputObject.SetSessionID(a.sessionID)

a.Service().TextInput().Channel() <- newTextInput
a.Service().Input().Text().Channel() <- textInputObject

err = scanner.Err()
err := scanner.Err()
if err != nil {
a.Service().Log().Line("msg", "%#v", maskAny(err))
}
Expand Down
19 changes: 12 additions & 7 deletions annactl/service_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"github.com/the-anna-project/collection"
"github.com/the-anna-project/fs/memory"
"github.com/the-anna-project/id"
inputcollection "github.com/the-anna-project/input/collection"
textinputservice "github.com/the-anna-project/input/service/text"
"github.com/the-anna-project/log"
servicespec "github.com/the-anna-project/spec/service"
"github.com/xh3b4sd/anna/service/permutation"
"github.com/xh3b4sd/anna/service/textinput"
"github.com/xh3b4sd/anna/service/textoutput"
)

Expand All @@ -21,16 +22,16 @@ func (a *annactl) newServiceCollection() servicespec.ServiceCollection {

collection.SetFSService(a.newFSService())
collection.SetIDService(a.newIDService())
collection.SetInputCollection(a.newInputCollection())
collection.SetLogService(a.newLogService())
collection.SetPermutationService(a.newPermutationService())
collection.SetTextInputService(a.newTextInputService())
collection.SetTextOutputService(a.newTextOutputService())

collection.FS().SetServiceCollection(collection)
collection.ID().SetServiceCollection(collection)
collection.Input().Text().SetServiceCollection(collection)
collection.Log().SetServiceCollection(collection)
collection.Permutation().SetServiceCollection(collection)
collection.TextInput().SetServiceCollection(collection)
collection.TextOutput().SetServiceCollection(collection)

return collection
Expand All @@ -45,6 +46,14 @@ func (a *annactl) newIDService() servicespec.IDService {
return id.New()
}

func (a *annactl) newInputCollection() servicespec.InputCollection {
newCollection := inputcollection.New()

newCollection.SetTextService(textinputservice.New())

return newCollection
}

func (a *annactl) newLogService() servicespec.LogService {
newService := log.New()

Expand All @@ -57,10 +66,6 @@ func (a *annactl) newPermutationService() servicespec.PermutationService {
return permutation.New()
}

func (a *annactl) newTextInputService() servicespec.TextInputService {
return textinput.New()
}

func (a *annactl) newTextOutputService() servicespec.TextOutputService {
return textoutput.New()
}
2 changes: 1 addition & 1 deletion client/interface/text/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (c *client) StreamText(ctx context.Context) error {
select {
case <-done:
return
case textInput := <-c.Service().TextInput().Channel():
case textInput := <-c.Service().Input().Text().Channel():
streamTextRequest := c.EncodeRequest(textInput)
err := stream.Send(streamTextRequest)
if err != nil {
Expand Down
19 changes: 12 additions & 7 deletions command/boot/service_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/the-anna-project/collection"
memoryfs "github.com/the-anna-project/fs/memory"
"github.com/the-anna-project/id"
inputcollection "github.com/the-anna-project/input/collection"
textinputservice "github.com/the-anna-project/input/service/text"
"github.com/the-anna-project/instrumentor/prometheus"
"github.com/the-anna-project/log"
"github.com/the-anna-project/random"
Expand All @@ -26,7 +28,6 @@ import (
"github.com/xh3b4sd/anna/service/storage"
memorystorage "github.com/xh3b4sd/anna/service/storage/memory"
"github.com/xh3b4sd/anna/service/storage/redis"
"github.com/xh3b4sd/anna/service/textinput"
"github.com/xh3b4sd/anna/service/textoutput"
"github.com/xh3b4sd/anna/service/tracker"
)
Expand All @@ -42,13 +43,13 @@ func (c *Command) newServiceCollection() servicespec.ServiceCollection {
collection.SetForwarderService(c.newForwarderService())
collection.SetFSService(c.newFSService())
collection.SetIDService(c.newIDService())
collection.SetInputCollection(c.newInputCollection())
collection.SetInstrumentorService(c.newInstrumentorService())
collection.SetLogService(c.newLogService())
collection.SetNetworkService(c.newNetworkService())
collection.SetPermutationService(c.newPermutationService())
collection.SetRandomService(c.newRandomService())
collection.SetStorageCollection(c.newStorageCollection())
collection.SetTextInputService(c.newTextInputService())
collection.SetTextOutputService(c.newTextOutputService())
collection.SetTrackerService(c.newTrackerService())

Expand All @@ -60,6 +61,7 @@ func (c *Command) newServiceCollection() servicespec.ServiceCollection {
collection.Forwarder().SetServiceCollection(collection)
collection.FS().SetServiceCollection(collection)
collection.ID().SetServiceCollection(collection)
collection.Input().Text().SetServiceCollection(collection)
collection.Instrumentor().SetServiceCollection(collection)
collection.Log().SetServiceCollection(collection)
collection.Network().SetServiceCollection(collection)
Expand All @@ -68,7 +70,6 @@ func (c *Command) newServiceCollection() servicespec.ServiceCollection {
collection.Storage().Connection().SetServiceCollection(collection)
collection.Storage().Feature().SetServiceCollection(collection)
collection.Storage().General().SetServiceCollection(collection)
collection.TextInput().SetServiceCollection(collection)
collection.TextOutput().SetServiceCollection(collection)
collection.Tracker().SetServiceCollection(collection)

Expand Down Expand Up @@ -127,6 +128,14 @@ func (c *Command) newIDService() servicespec.IDService {
return id.New()
}

func (c *Command) newInputCollection() servicespec.InputCollection {
newCollection := inputcollection.New()

newCollection.SetTextService(textinputservice.New())

return newCollection
}

func (c *Command) newInstrumentorService() servicespec.InstrumentorService {
return prometheus.New()
}
Expand Down Expand Up @@ -203,10 +212,6 @@ func (c *Command) newStorageCollection() servicespec.StorageCollection {
return newCollection
}

func (c *Command) newTextInputService() servicespec.TextInputService {
return textinput.New()
}

func (c *Command) newTextOutputService() servicespec.TextOutputService {
return textoutput.New()
}
Expand Down
12 changes: 9 additions & 3 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 0 additions & 30 deletions object/textinput/error.go

This file was deleted.

8 changes: 4 additions & 4 deletions service/endpoint/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ func (c *collection) Metric() servicespec.EndpointService {
return c.metric
}

func (c *collection) Text() servicespec.EndpointService {
return c.text
}

func (c *collection) SetMetric(metric servicespec.EndpointService) {
c.metric = metric
}
Expand Down Expand Up @@ -62,3 +58,7 @@ func (c *collection) Shutdown() {
wg.Wait()
})
}

func (c *collection) Text() servicespec.EndpointService {
return c.text
}
20 changes: 8 additions & 12 deletions service/endpoint/text/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (

"google.golang.org/grpc"

textinputobject "github.com/the-anna-project/input/object/text"
apispec "github.com/the-anna-project/spec/api"
objectspec "github.com/the-anna-project/spec/object"
servicespec "github.com/the-anna-project/spec/service"
"github.com/xh3b4sd/anna/object/textinput"
)

// New creates a new text endpoint service.
Expand Down Expand Up @@ -100,17 +100,13 @@ func (s *service) DecodeResponse(textOutput objectspec.TextOutput) *StreamTextRe
}

func (s *service) EncodeRequest(streamTextRequest *StreamTextRequest) (objectspec.TextInput, error) {
textInputConfig := textinput.DefaultConfig()
textInputConfig.Echo = streamTextRequest.Echo
//textInputConfig.Expectation = streamTextRequest.Expectation
textInputConfig.Input = streamTextRequest.Input
textInputConfig.SessionID = streamTextRequest.SessionID
textInput, err := textinput.New(textInputConfig)
if err != nil {
return nil, maskAny(err)
}
textInputObject := textinputobject.New()
textInputObject.SetEcho(streamTextRequest.Echo)
//textInputObject.SetExpectation(streamTextRequest.Expectation)
textInputObject.SetInput(streamTextRequest.Input)
textInputObject.SetSessionID(streamTextRequest.SessionID)

return textInput, nil
return textInputObject, nil
}

func (s *service) Metadata() map[string]string {
Expand Down Expand Up @@ -176,7 +172,7 @@ func (s *service) StreamText(stream TextEndpoint_StreamTextServer) error {
fail <- maskAny(err)
return
}
s.Service().TextInput().Channel() <- textRequest
s.Service().Input().Text().Channel() <- textRequest
}
}()

Expand Down
2 changes: 1 addition & 1 deletion service/network/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (s *service) InputListener(canceler <-chan struct{}) error {
select {
case <-canceler:
return maskAny(workerCanceledError)
case textInput := <-s.Service().TextInput().Channel():
case textInput := <-s.Service().Input().Text().Channel():
err := s.InputHandler(CLG, textInput)
if err != nil {
s.Service().Log().Line("msg", "%#v", maskAny(err))
Expand Down
30 changes: 0 additions & 30 deletions service/textinput/error.go

This file was deleted.

Loading

0 comments on commit 7b4dfb2

Please sign in to comment.