Skip to content

Commit

Permalink
add engine channels
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Martinez committed Aug 10, 2018
1 parent 0cdd532 commit 7d11eee
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ type Config struct {
Type string `json:"type"`
Version string `json:"version"`
Description string `json:"description"`

Properties []*data.Attribute `json:"properties"`
Channels []string `json:"channels"`
Triggers []*trigger.Config `json:"triggers"`
Resources []*resource.Config `json:"resources"`
Actions []*action.Config `json:"actions"`
Expand Down
26 changes: 26 additions & 0 deletions engine/channels/channels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package channels

var channels = make(map[string]chan interface{})

// Count returns the number of channels
func Count() int {
return len(channels)
}

// Add adds an engine channel, assumes these are created before startup
func Add(name string){
//todo add size?
channels[name] = make(chan interface{})
}

// Get gets the named channel
func Get(name string) chan interface{} {
return channels[name]
}

//Close closes all the channels, assumes it is called on shutdown
func Close() {
for _, value := range channels {
close(value)
}
}
16 changes: 16 additions & 0 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/TIBCOSoftware/flogo-lib/util"
"github.com/TIBCOSoftware/flogo-lib/util/managed"
"sync"
"github.com/TIBCOSoftware/flogo-lib/engine/channels"
)

var managedServices []managed.Managed
Expand Down Expand Up @@ -110,6 +111,16 @@ func (e *engineImpl) Init(directRunner bool) error {
}
}

//add engine channels
channelNames := e.app.Channels
if len(channelNames) > 0 {
for _, channelName := range channelNames {

logger.Debugf("Creating Engine Channel '%s'", channelName)
channels.Add(channelName)
}
}

err = app.RegisterResources(e.app.Resources)
if err != nil {
return err
Expand Down Expand Up @@ -225,6 +236,11 @@ func (e *engineImpl) Start() error {
func (e *engineImpl) Stop() error {
logger.Info("Engine Stopping...")

if channels.Count() > 0 {
logger.Info("Closing Engine Channels...")
channels.Close()
}

logger.Info("Stopping Triggers...")

// Stop Triggers
Expand Down

0 comments on commit 7d11eee

Please sign in to comment.