Exemple #1
0
func NewLeader(keepAliveMs uint32, client *rpc.Client, stateStore common.StateStore) *Leader {
	l := &Leader{
		keepAliveMs: time.Duration(keepAliveMs) * time.Millisecond,
		client:      client,
		stateStore:  stateStore,
	}

	l.SyncService = common.NewSyncService(l.syncStart, l.startKeepAliveTimer, l.syncStop)

	return l
}
Exemple #2
0
func newGrpcServer(nodeConfig common.NodeConfig, requestHandler RequestHandler,
	stateStore common.StateStore) *grpcServer {
	grpcServer := &grpcServer{
		log:            logrus.WithField("id", nodeConfig.Id),
		nodeConfig:     nodeConfig,
		requestHandler: requestHandler,
		stateStore:     stateStore,
	}

	grpcServer.SyncService = common.NewSyncService(grpcServer.syncStart, grpcServer.asyncStart, grpcServer.syncStop)
	return grpcServer
}
Exemple #3
0
func NewFollower(stateStore common.StateStore, listener common.EventListener, timeout common.LeaderTimeout) *Follower {
	follower := &Follower{
		listener:   listener,
		stateStore: stateStore,
		timeout:    timeout,
		random:     rand.New(rand.NewSource(time.Now().UnixNano())),
	}

	follower.SyncService = common.NewSyncService(follower.syncStart, follower.startBackGroundTimer, follower.syncStop)

	return follower
}
func NewCandidate(stateStore common.StateStore, client *rpc.Client,
	listener common.EventListener, quorumStrategy QuorumStrategy) *Candidate {

	c := &Candidate{
		stateStore:     stateStore,
		listener:       listener,
		client:         client,
		quorumStrategy: quorumStrategy,
	}

	c.SyncService = common.NewSyncService(c.syncStart, c.startVote, c.syncStop)

	return c
}
Exemple #5
0
func NewClient(listener common.EventListener, config common.NodeConfig,
	peers ...common.NodeConfig) *Client {

	client := &Client{
		peers:                peers,
		listener:             listener,
		config:               config,
		grpcConnInfoCh:       make(chan grpcConnInfo),
		sessions:             make(map[*clientSession]*struct{}),
		unhealthyGrpcClients: make(map[string]*grpcClient),
	}

	client.SyncService = common.NewSyncService(client.syncStart, client.manageSessions, client.syncStop)
	return client
}