Example #1
0
// Listens for connections and starts a proton.Engine for each one.
func (b *broker) run() error {
	listener, err := net.Listen("tcp", *addr)
	if err != nil {
		return err
	}
	defer listener.Close()
	fmt.Printf("Listening on %s\n", listener.Addr())
	for {
		conn, err := listener.Accept()
		if err != nil {
			util.Debugf("Accept error: %v", err)
			continue
		}
		adapter := proton.NewMessagingAdapter(newHandler(&b.queues))
		// We want to accept messages when they are enqueued, not just when they
		// are received, so we turn off auto-accept and prefetch by the adapter.
		adapter.Prefetch = 0
		adapter.AutoAccept = false
		engine, err := proton.NewEngine(conn, adapter)
		if err != nil {
			util.Debugf("Connection error: %v", err)
			continue
		}
		engine.Server() // Enable server-side protocol negotiation.
		util.Debugf("Accepted connection %s", engine)
		go func() { // Start goroutine to run the engine event loop
			engine.Run()
			util.Debugf("Closed %s", engine)
		}()
	}
}
Example #2
0
func newConnection(conn net.Conn, cont *container) (*connection, error) {
	c := &connection{container: cont, conn: conn}
	c.handler = newHandler(c)
	var err error
	c.engine, err = proton.NewEngine(c.conn, c.handler.delegator)
	if err != nil {
		return nil, err
	}
	c.str = c.engine.String()
	c.eConnection = c.engine.Connection()
	return c, nil
}
Example #3
0
func newConnection(conn net.Conn, cont *container, setting ...ConnectionOption) (*connection, error) {
	c := &connection{container: cont, conn: conn}
	c.handler = newHandler(c)
	var err error
	c.engine, err = proton.NewEngine(c.conn, c.handler.delegator)
	if err != nil {
		return nil, err
	}
	for _, set := range setting {
		set(c)
	}
	c.endpoint.init(c.engine.String())
	c.pConnection = c.engine.Connection()
	go c.run()
	return c, nil
}
Example #4
0
func newConnection(conn net.Conn, cont *container, setting ...ConnectionOption) (*connection, error) {
	c := &connection{container: cont, conn: conn, accept: func(Incoming) {}, done: make(chan struct{})}
	c.handler = newHandler(c)
	var err error
	c.engine, err = proton.NewEngine(c.conn, c.handler.delegator)
	if err != nil {
		return nil, err
	}
	for _, set := range setting {
		set(c)
	}
	c.str = c.engine.String()
	c.eConnection = c.engine.Connection()
	go func() { c.engine.Run(); close(c.done) }()
	return c, nil
}
Example #5
0
// NewConnection creates a connection with the given options.
func NewConnection(conn net.Conn, opts ...ConnectionOption) (*connection, error) {
	c := &connection{
		conn: conn,
	}
	c.handler = newHandler(c)
	var err error
	c.engine, err = proton.NewEngine(c.conn, c.handler.delegator)
	if err != nil {
		return nil, err
	}
	c.pConnection = c.engine.Connection()
	for _, set := range opts {
		set(c)
	}
	if c.container == nil {
		c.container = NewContainer("").(*container)
	}
	c.pConnection.SetContainer(c.container.Id())
	globalSASLInit(c.engine)

	c.endpoint.init(c.engine.String())
	go c.run()
	return c, nil
}