Esempio n. 1
0
// newReferenceGateway returns a default gateway
func newReferenceGateway(t *testing.T, region string) *gateway.Gateway {
	gtw := gateway.NewGateway(GetLogger(t, "ReferenceGateway"), "eui-0102030405060708")
	gtw.Status.Update(&pb_gateway.Status{
		Region: region,
	})
	return gtw
}
Esempio n. 2
0
// getGateway gets or creates a Gateway
func (r *router) getGateway(id string) *gateway.Gateway {
	// We're going to be optimistic and guess that the gateway is already active
	r.gatewaysLock.RLock()
	gtw, ok := r.gateways[id]
	r.gatewaysLock.RUnlock()
	if ok {
		return gtw
	}
	// If it doesn't we still have to lock
	r.gatewaysLock.Lock()
	defer r.gatewaysLock.Unlock()

	gtw, ok = r.gateways[id]
	if !ok {
		gtw = gateway.NewGateway(r.Ctx, id)

		if r.Component.Monitors != nil {
			gtw.Monitors = make(map[string]pb_monitor.GatewayClient)
			for name, cl := range r.Component.Monitors {
				gtw.Monitors[name] = cl.GatewayClient(gtw.ID)
			}
		}

		r.gateways[id] = gtw
	}

	return gtw
}