func (_ *ListenerSuite) TestListenUnix(c *C) {
	addr, _ := net.ResolveUnixAddr("unix", "/tmp/go_test_socket")
	cfg := &conf.ListenerConf{
		Name: "local",
		Ports: []*conf.PortConf{
			&conf.PortConf{
				Type: "unix",
				Addr: addr,
			},
		},
	}

	ll := listener.NewListener(cfg)
	ll.SetHandler(echoHandler)
	ll.Start()
	time.Sleep(50 * time.Millisecond)

	cc, err := net.DialUnix("unix", nil, addr)
	c.Assert(err, IsNil)

	testEchoConnection(c, cc)

	cc.Close()

	ll.Stop()
}
Exemple #2
0
func (_ *ListenerSuite) TestListenTCP(c *C) {
	addr, _ := net.ResolveTCPAddr("tcp4", "127.0.0.1:12345")
	cfg := &conf.ListenerConf{
		Name: "local",
		Ports: []*conf.PortConf{
			&conf.PortConf{
				Type: "tcp4",
				Addr: addr,
			},
		},
	}

	ll := listener.NewListener(cfg)
	ll.SetHandler(echoHandler)
	ll.Start()
	time.Sleep(50 * time.Millisecond)

	cc, err := net.DialTCP("tcp4", nil, addr)
	c.Assert(err, IsNil)

	testEchoConnection(c, cc)

	cc.Close()

	ll.Stop()
}
Exemple #3
0
func New(cfg *conf.Conf) Bridge {
	b := &bridge{
		listeners:    make(map[string]Listener),
		plugins:      make(map[string]Plugin),
		mediators:    make(map[string]Mediator),
		communicator: comm.NewComm(),
	}

	// Construct listeners
	for lname, lconf := range cfg.Listeners {
		b.listeners[lname] = listener.NewListener(lconf)
	}

	// Construct and configure plugins
	for pname, pconf := range cfg.Plugins {
		plugin := repo.GetPlugin(string(pconf.Plugin))
		if plugin == nil {
			log.Printf("Plugin '%s' of type '%s' not found", pname, pconf.Plugin)
			continue
		}
		if err := plugin.Config(pconf); err != nil {
			log.Printf("Failed to configure '%s' plugin: %v", pname, err)
			continue
		}
		b.plugins[pname] = plugin
	}

	// Construct and configure mediators
	for mname, mconf := range cfg.Mediators {
		mediator := repo.GetMediator(string(mconf.Mediator))
		if mediator == nil {
			log.Printf("Mediator '%s' of type '%s' not found", mname, mconf.Mediator)
			continue
		}
		if err := mediator.Config(mconf); err != nil {
			log.Printf("Failed to configure '%s' mediator: %v", mname, err)
			continue
		}
		b.mediators[mname] = mediator
	}

	// Link plugins and mediators
	for pname, pconf := range cfg.Plugins {
		plugin, ok := b.plugins[pname]
		if !ok {
			continue
		}
		for _, mmap := range pconf.Mediators {
			mediator, ok := b.mediators[mmap.Mediator]
			if !ok {
				continue
			}
			endpoint := mmap.Endpoint
			if err := mediator.Subscribe(endpoint, plugin.Subscriber(endpoint)); err != nil {
				log.Printf("Error subscribing plugin '%s' to endpoint '%s' at mediator '%s': %v",
					pname, endpoint, mediator.Name(), err)
				continue
			}
		}
	}

	return b
}