// newCircuitBreaker creates a CircuitBreaker with associated Health
430261
func newCircuitBreaker(name string) *CircuitBreaker {
	c := &CircuitBreaker{}
	c.Name = name
	c.metrics = newMetricExchange(name)
	c.executorPool = newExecutorPool(name)
	c.mutex = &sync.RWMutex{}

	return c
}
195258
func NewHTTPClientWithBreaker(breaker *Breaker, timeout time.Duration, client *http.Client) *HTTPClient {
	if client == nil {
		client = &http.Client{}
	}

	panel := NewPanel()
	panel.Add(defaultBreakerName, breaker)

	brclient := &HTTPClient{Client: client, Panel: panel, timeout: timeout}
	brclient.BreakerLookup = func(c *HTTPClient, val interface{}) *Breaker {
		cb, _ := c.Panel.Get(defaultBreakerName)
		return cb
	}

	events := breaker.Subscribe()
	go func() {
		event := <-events
		switch event {
		case BreakerTripped:
			brclient.runBreakerTripped()
		case BreakerReset:
			brclient.runBreakerReset()
		}
	}()

	return brclient
}
248343
func New(s *terraform.InstanceState) (*Communicator, error) {
	connInfo, err := parseConnectionInfo(s)
	if err != nil {
		return nil, err
	}

	endpoint := &winrm.Endpoint{
		Host:     connInfo.Host,
		Port:     connInfo.Port,
		HTTPS:    connInfo.HTTPS,
		Insecure: connInfo.Insecure,
	}
	if len(connInfo.CACert) > 0 {
		endpoint.CACert = []byte(connInfo.CACert)
	}

	comm := &Communicator{
		connInfo: connInfo,
		endpoint: endpoint,
		// Seed our own rand source so that script paths are not deterministic
		rand: rand.New(rand.NewSource(time.Now().UnixNano())),
	}

	return comm, nil
}
171265
func (s *Switch) lookupOpenCircuit(outKey CircuitKey) *PaymentCircuit {
	return s.circuits.LookupOpenCircuit(outKey)
}
829864
func newPaymentCircuit(hash *[32]byte, pkt *htlcPacket) *PaymentCircuit {
	var addRef channeldb.AddRef
	if pkt.sourceRef != nil {
		addRef = *pkt.sourceRef
	}

	return &PaymentCircuit{
		AddRef: addRef,
		Incoming: CircuitKey{
			ChanID: pkt.incomingChanID,
			HtlcID: pkt.incomingHTLCID,
		},
		PaymentHash:    *hash,
		IncomingAmount: pkt.incomingAmount,
		OutgoingAmount: pkt.amount,
		ErrorEncrypter: pkt.obfuscator,
	}
}
647455
func (p *Panel) Add(name string, cb *Breaker) {
	p.panelLock.Lock()
	p.Circuits[name] = cb
	p.panelLock.Unlock()

	events := cb.Subscribe()

	go func() {
		for event := range events {
			for _, receiver := range p.eventReceivers {
				receiver <- PanelEvent{name, event}
			}
			switch event {
			case BreakerTripped:
				p.breakerTripped(name)
			case BreakerReset:
				p.breakerReset(name)
			case BreakerFail:
				p.breakerFail(name)
			case BreakerReady:
				p.breakerReady(name)
			}
		}
	}()
}
1356053
func (cm *circuitMap) LookupCircuit(inKey CircuitKey) *PaymentCircuit {
	cm.mtx.RLock()
	defer cm.mtx.RUnlock()

	return cm.pending[inKey]
}
892048
func NewRateBreaker(rate float64, minSamples int64) *Breaker {
	return NewBreakerWithOptions(&Options{
		ShouldTrip: RateTripFunc(rate, minSamples),
	})
}
711411
func NewDeviceAccounter(n *Node) *DeviceAccounter {
	numDevices := 0
	var devices []*NodeDeviceResource

	// COMPAT(0.11): Remove in 0.11
	if n.NodeResources != nil {
		numDevices = len(n.NodeResources.Devices)
		devices = n.NodeResources.Devices
	}

	d := &DeviceAccounter{
		Devices: make(map[DeviceIdTuple]*DeviceAccounterInstance, numDevices),
	}

	for _, dev := range devices {
		id := *dev.ID()
		d.Devices[id] = &DeviceAccounterInstance{
			Device:    dev,
			Instances: make(map[string]int, len(dev.Instances)),
		}
		for _, instance := range dev.Instances {
			// Skip unhealthy devices as they aren't allocatable
			if !instance.Healthy {
				continue
			}

			d.Devices[id].Instances[instance.ID] = 0
		}
	}

	return d
}
89621
func (cm *circuitMap) FailCircuit(inKey CircuitKey) (*PaymentCircuit, error) {

	cm.mtx.Lock()
	defer cm.mtx.Unlock()

	circuit, ok := cm.pending[inKey]
	if !ok {
		return nil, ErrUnknownCircuit
	}

	_, ok = cm.closed[inKey]
	if ok {
		return nil, ErrCircuitClosing
	}

	cm.closed[inKey] = struct{}{}

	return circuit, nil
}
691975
func New(devEntries []PodDevicesEntry,
	devices map[string][]string) DeviceManagerCheckpoint {
	return &Data{
		Data: checkpointData{
			PodDeviceEntries:  devEntries,
			RegisteredDevices: devices,
		},
	}
}
1222416
func NewMockInstanceConnector(ctrl *gomock.Controller) *MockInstanceConnector {
	mock := &MockInstanceConnector{ctrl: ctrl}
	mock.recorder = &MockInstanceConnectorMockRecorder{mock}
	return mock
}
1251953
func NewMockConnector(ctrl *gomock.Controller) *MockConnector {
	mock := &MockConnector{ctrl: ctrl}
	mock.recorder = &MockConnectorMockRecorder{mock}
	return mock
}
188334
func NewAccelerometerDriver(a ble.BLEConnector) *AccelerometerDriver {
	n := &AccelerometerDriver{
		name:       gobot.DefaultName("Microbit Accelerometer"),
		connection: a,
		Eventer:    gobot.NewEventer(),
	}

	n.AddEvent(Accelerometer)

	return n
}
1323728
func NewCustomClientWrapper(bs gobreaker.Settings, bm BreakerMethod) client.Wrapper {
	return func(c client.Client) client.Client {
		w := &clientWrapper{}
		w.bm = bm
		w.bs = bs
		w.cbs = make(map[string]*gobreaker.TwoStepCircuitBreaker)
		w.Client = c
		return w
	}
}
222140
func NewCertCreator() *CertCreator {
	return &CertCreator{
		Serial:    1,
		NotBefore: time.Now(),
		NotAfter:  time.Date(2049, 12, 31, 23, 59, 59, 0, time.UTC), // end of ASN.1 time
		KeySize:   4096,
	}
}
1085703
func NewConnection(port xspi.PortCloser, conn xspi.Conn) (connection *SpiConnection) {
	return &SpiConnection{port: port, dev: conn}
}