示例#1
0
func newSyncClient(selfID cluster.MemberID, member cluster.Member, httpclient *http.Client, eventsChan chan<- *InMessage, logger *log.Entry) error {
	client := &syncClient{
		selfID:     selfID,
		member:     member,
		httpclient: httpclient,
		evChan:     eventsChan,
		logger:     logger.WithFields(log.Fields{"peer": member.ID()}),
	}

	client.logger.Info("Creating a sync client to peer")

	r, err := client.connect()
	if err != nil {
		return err
	}
	client.readEvents(r)
	return nil
}
示例#2
0
// Invoked when a member leaves a cluster.
func (s *server) OnLeave(m cluster.Member) {
	if s.selfID == m.ID() {
		return
	}

	s.clientsLock.Lock()
	defer s.clientsLock.Unlock()

	s.logger.Infof("Member %s left the cluster", m)

	if client, exists := s.clients[m.ID()]; exists {
		client.close()
		delete(s.clients, m.ID())
		s.health.RemoveClient(m.ID())
	}
}
示例#3
0
// Invoked when a member joins a cluster.
func (s *server) OnJoin(m cluster.Member) {
	if s.selfID == m.ID() {
		return
	}

	s.clientsLock.Lock()
	defer s.clientsLock.Unlock()

	s.logger.Infof("Peer Member %s joined the cluster", m)

	if client, exists := s.clients[m.ID()]; exists {
		client.close()
		delete(s.clients, m.ID())
		s.health.RemoveClient(m.ID())
	}

	client, err := newClient(s.selfID, m, s.httpclient, s.notifyChannel, s.logger)
	if err != nil {
		s.logger.WithFields(log.Fields{
			"error": err,
		}).Errorf("Failed to add the member %s", m)

		return
	}
	s.clients[m.ID()] = client
	s.health.AddClient(m.ID(), client)
}