func initBus() (bus *EventBus.EventBus) {
	bus = EventBus.New()
	bus.Subscribe(lib.NEW_MESSAGE_EVENT, persistMessage)
	bus.Subscribe(lib.NEW_MESSAGE_EVENT, countMessage)
	bus.Subscribe(lib.NEW_MESSAGE_EVENT, logMessage)
	bus.Subscribe(lib.NEW_DEVICE_EVENT, logNewDevice)

	return
}
Esempio n. 2
0
func initEventBus() {
	bus = EventBus.New()
	log.Printf("Eventbus Initialized\n")
}
Esempio n. 3
0
func main() {
	bus := EventBus.New()
	bus.Subscribe("main:calculator", calculator)
	bus.Publish("main:calculator", 20, 40)
	bus.Unsubscribe("main:calculator", calculator)
}
Esempio n. 4
0
func main() {
	if os.Getenv("DEBUG") == strconv.Itoa(1) {
		log.SetStdoutThreshold(log.LevelDebug)
	} else {
		log.SetStdoutThreshold(log.LevelInfo)
	}
	log.INFO.Println("== Artemide - the docker building system ==")
	log.INFO.Println("Engines starting")
	var c int
	var configurationFile string
	var unpackImage string
	var context *context.Context
	var outputDir string

	bus := evbus.New()
	OptErr = 0
	for {
		if c = Getopt("o:u:c:h"); c == EOF {
			break
		}
		switch c {
		case 'u':
			unpackImage = OptArg
		case 'o':
			outputDir = OptArg
		case 'c':
			configurationFile = OptArg
		case 'h':
			println("usage: " + os.Args[0] + " [-c config.toml -h]")
			println("to just extract a docker image: " + os.Args[0] + " -u docker/image -o /my/uncompressed_rootfs")
			os.Exit(1)
		}
	}

	// Register hooks and recipes to the eventbus
	for i := range plugin.Hooks {
		log.DEBUG.Println("Registering", i, "hook to eventbus")
		plugin.Hooks[i].Register(bus, context)
	}

	for i := range plugin.Recipes {
		log.DEBUG.Println("Registering", i, "recipe to eventbus")
		plugin.Recipes[i].Register(bus, context)
	}

	// Starting the bus show!
	bus.Publish("artemide:start") // Emitting artemide:start event thru Recipes and Hooks.

	// unpack mode.
	if unpackImage != "" && outputDir != "" {
		// Unpack mode, just unpack the image and exits.
		log.INFO.Println("Unpack mode. Unpacking", unpackImage, "to", outputDir)
		bus.Publish("artemide:source:docker", unpackImage, outputDir)
		os.Exit(0)
	}

	// Halting if no configuration file is supplied
	if configurationFile == "" {
		log.ERROR.Fatalln("I can't work without a configuration file")
	}

	configuration, _ := config.LoadConfig(configurationFile)

	log.DEBUG.Printf("%v\n", configuration)

	//bus.Publish("artemide:source:"+configuration.Source.Type, configuration.Source.Image)

	for artifactName, artifact := range configuration.Artifacts {
		log.DEBUG.Printf("Artifact: %s \n", artifactName)
		for recipeName, recipe := range artifact.Recipe {
			log.DEBUG.Printf("Signaling -> Recipe %s <- to bus\n", recipeName)
			bus.Publish("artemide:artifact:recipe:" + recipeName)
			for eventsName, event := range recipe {
				log.DEBUG.Printf("Signaling -> Event %s : (%s.%s)\n", eventsName, event.Name, event.Action)
				//bus.Publish("artemide:artifact:recipe:"+recipeName+":event:"+event.Name, event.Action)
			}
		}
	}
	//bus.Publish("artemide:recipe:type", recipe_type)

}
Esempio n. 5
0
// package pubsub provides a global publish and subscribe infrastructure
// for lantern
package pubsub

import (
	"strconv"

	"github.com/asaskevich/EventBus"
)

var (
	bus = EventBus.New()
)

// The constant topics to publish and subscribe to. All topics should
// be defined here directly.
const (
	Location = iota
	// Someothertopic = iota
)

// Pub publishes the given interface to any listeners for that interface.
func Pub(topic int, data interface{}) {
	bus.Publish(strconv.Itoa(topic), data)
}

// Sub subscribes to specific interfaces with the specified callback
// function.
func Sub(topic int, fn interface{}) error {
	return bus.SubscribeAsync(strconv.Itoa(topic), fn, true)
}