Esempio n. 1
0
// NewEngine initializes a engine with a connection and handlers. To start it running:
//    eng := NewEngine(...)
//    go run eng.Run()
// The goroutine will exit when the engine is closed or disconnected.
// You can check for errors on Engine.Error.
//
func NewEngine(conn net.Conn, handlers ...EventHandler) (*Engine, error) {
	eng := &Engine{
		inject:   make(chan func()),
		conn:     conn,
		handlers: handlers,
		running:  make(chan struct{}),
		timer:    time.NewTimer(0),
	}
	if pnErr := C.pn_connection_engine_init(&eng.engine); pnErr != 0 {
		return nil, fmt.Errorf("cannot setup engine: %s", PnErrorCode(pnErr))
	}
	return eng, nil
}
Esempio n. 2
0
// NewEngine initializes a engine with a connection and handlers. To start it running:
//    eng := NewEngine(...)
//    go run eng.Run()
// The goroutine will exit when the engine is closed or disconnected.
// You can check for errors on Engine.Error.
//
func NewEngine(conn net.Conn, handlers ...EventHandler) (*Engine, error) {
	eng := &Engine{
		inject:   make(chan func()),
		conn:     conn,
		handlers: handlers,
		running:  make(chan struct{}),
	}
	if pnErr := C.pn_connection_engine_init(&eng.engine); pnErr != 0 {
		return nil, fmt.Errorf("cannot setup engine: %s", PnErrorCode(pnErr))
	}
	// Unique container-id by default.
	eng.Connection().SetContainer(UUID4().String()) // FIXME aconway 2016-06-21:
	eng.Connection().Open()
	return eng, nil
}