Example #1
0
func (exchange *Exchange) AddBinding(b *binding.Binding, connId int64) error {
	exchange.bindingsLock.Lock()
	defer exchange.bindingsLock.Unlock()

	for _, b2 := range exchange.bindings {
		if b.Equals(b2) {
			return nil
		}
	}

	if exchange.AutoDelete {
		exchange.deleteActive = time.Unix(0, 0)
	}
	exchange.bindings = append(exchange.bindings, b)
	return nil
}
Example #2
0
func (exchange *Exchange) RemoveBinding(binding *binding.Binding) error {
	exchange.bindingsLock.Lock()
	defer exchange.bindingsLock.Unlock()

	// Delete binding
	for i, b := range exchange.bindings {
		if binding.Equals(b) {
			exchange.bindings = append(exchange.bindings[:i], exchange.bindings[i+1:]...)
			if exchange.AutoDelete && len(exchange.bindings) == 0 {
				go exchange.autodeleteTimeout()
			}
			return nil
		}
	}
	return nil
}