func (h *Impl) GetFrontendClient() workflowservice.WorkflowServiceClient {
	return h.frontendClient
}
GetFrontendClient return frontend client with retry policy
package resource
import (
	"math/rand"
	"net"
	"os"
	"sync/atomic"
	"time"
	"github.com/uber-go/tally"
	"github.com/uber/tchannel-go"
	"go.temporal.io/api/workflowservice/v1"
	sdkclient "go.temporal.io/sdk/client"
	"go.temporal.io/server/common/namespace"
	"go.temporal.io/server/common/persistence/visibility/manager"
	"go.temporal.io/server/common/persistence/serialization"
	"go.temporal.io/server/common/searchattribute"
	"go.temporal.io/server/api/adminservice/v1"
	"go.temporal.io/server/api/historyservice/v1"
	"go.temporal.io/server/api/matchingservice/v1"
	"go.temporal.io/server/client"
	"go.temporal.io/server/client/frontend"
	"go.temporal.io/server/client/history"
	"go.temporal.io/server/client/matching"
	"go.temporal.io/server/common"
	"go.temporal.io/server/common/archiver"
	"go.temporal.io/server/common/archiver/provider"
	"go.temporal.io/server/common/clock"
	"go.temporal.io/server/common/cluster"
	"go.temporal.io/server/common/dynamicconfig"
	"go.temporal.io/server/common/log"
	"go.temporal.io/server/common/log/tag"
	"go.temporal.io/server/common/membership"
	"go.temporal.io/server/common/metrics"
	"go.temporal.io/server/common/persistence"
	persistenceClient "go.temporal.io/server/common/persistence/client"
)
type (
	VisibilityManagerInitializer func(
		persistenceBean persistenceClient.Bean,
		searchAttributesProvider searchattribute.Provider,
		logger log.Logger,
	) (manager.VisibilityManager, error)
	Impl struct {
		status int32
		numShards       int32
		serviceName     string
		hostName        string
		hostInfo        *membership.HostInfo
		metricsScope    tally.Scope
		clusterMetadata cluster.Metadata
		saProvider      searchattribute.Provider
		saManager       searchattribute.Manager
		saMapper        searchattribute.Mapper
		namespaceRegistry namespace.Registry
		timeSource        clock.TimeSource
		payloadSerializer serialization.Serializer
		metricsClient     metrics.Client
		archivalMetadata  archiver.ArchivalMetadata
		archiverProvider  provider.ArchiverProvider
		membershipMonitor       membership.Monitor
		frontendServiceResolver membership.ServiceResolver
		matchingServiceResolver membership.ServiceResolver
		historyServiceResolver  membership.ServiceResolver
		workerServiceResolver   membership.ServiceResolver
		sdkClient         sdkclient.Client
		frontendRawClient workflowservice.WorkflowServiceClient
		frontendClient    workflowservice.WorkflowServiceClient
		matchingRawClient matchingservice.MatchingServiceClient
		matchingClient    matchingservice.MatchingServiceClient
		historyRawClient  historyservice.HistoryServiceClient
		historyClient     historyservice.HistoryServiceClient
		clientBean        client.Bean
		persistenceBean           persistenceClient.Bean
		persistenceFaultInjection *persistenceClient.FaultInjectionDataStoreFactory
		logger          log.Logger
		throttledLogger log.Logger
		grpcListener net.Listener
		ringpopChannel *tchannel.Channel
		runtimeMetricsReporter *metrics.RuntimeMetricsReporter
		rpcFactory             common.RPCFactory
	}
)
var _ Resource = (*Impl)(nil)
func New(
	pLogger log.Logger,
	params *BootstrapParams,
	serviceName string,
	dcClient dynamicconfig.Client,
	persistenceMaxQPS dynamicconfig.IntPropertyFn,
	persistenceGlobalMaxQPS dynamicconfig.IntPropertyFn,
	throttledLoggerMaxRPS dynamicconfig.IntPropertyFn,
) (impl *Impl, retError error) {
	logger := log.With(pLogger, tag.Service(serviceName))
	throttledLogger := log.NewThrottledLogger(logger,
		func() float64 { return float64(throttledLoggerMaxRPS()) })
	numShards := params.PersistenceConfig.NumHistoryShards
	hostName, err := os.Hostname()
	if err != nil {
		return nil, err
	}
	grpcListener := params.RPCFactory.GetGRPCListener()
	ringpopChannel := params.RPCFactory.GetRingpopChannel()
	factory := persistenceClient.NewFactoryImpl(
		&params.PersistenceConfig,
		params.PersistenceServiceResolver,
		func(...dynamicconfig.FilterOption) int {
			if persistenceGlobalMaxQPS() > 0 {
			}
			return persistenceMaxQPS()
		},
		params.AbstractDatastoreFactory,
		params.ClusterMetadataConfig.CurrentClusterName,
		params.MetricsClient,
		logger,
	)
	persistenceBean, err := persistenceClient.NewBeanFromFactory(factory)
	if err != nil {
		return nil, err
	}
	clusterMetadata := cluster.NewMetadata(
		params.ClusterMetadataConfig.EnableGlobalNamespace,
		params.ClusterMetadataConfig.FailoverVersionIncrement,
		params.ClusterMetadataConfig.MasterClusterName,
		params.ClusterMetadataConfig.CurrentClusterName,
		params.ClusterMetadataConfig.ClusterInformation,
	)
	membershipFactory, err := params.MembershipFactoryInitializer(persistenceBean, logger)
	if err != nil {
		return nil, err
	}
	membershipMonitor, err := membershipFactory.GetMembershipMonitor()
	if err != nil {
		return nil, err
	}
	dynamicCollection := dynamicconfig.NewCollection(dcClient, logger)
	factoryProvider := params.ClientFactoryProvider
	if factoryProvider == nil {
		factoryProvider = client.NewFactoryProvider()
	}
	clientBean, err := client.NewClientBean(
		factoryProvider.NewFactory(
			params.RPCFactory,
			membershipMonitor,
			params.MetricsClient,
			dynamicCollection,
			numShards,
			logger,
		),
		clusterMetadata,
	)
	if err != nil {
		return nil, err
	}
	frontendServiceResolver, err := membershipMonitor.GetResolver(common.FrontendServiceName)
	if err != nil {
		return nil, err
	}
	matchingServiceResolver, err := membershipMonitor.GetResolver(common.MatchingServiceName)
	if err != nil {
		return nil, err
	}
	historyServiceResolver, err := membershipMonitor.GetResolver(common.HistoryServiceName)
	if err != nil {
		return nil, err
	}
	workerServiceResolver, err := membershipMonitor.GetResolver(common.WorkerServiceName)
	if err != nil {
		return nil, err
	}
	saProvider := searchattribute.NewManager(clock.NewRealTimeSource(), persistenceBean.GetClusterMetadataManager())
	saManager := searchattribute.NewManager(clock.NewRealTimeSource(), persistenceBean.GetClusterMetadataManager())
	namespaceRegistry := namespace.NewRegistry(
		persistenceBean.GetMetadataManager(),
		clusterMetadata.IsGlobalNamespaceEnabled(),
		params.MetricsClient,
		logger,
	)
	frontendRawClient := clientBean.GetFrontendClient()
	frontendClient := frontend.NewRetryableClient(
		frontendRawClient,
		common.CreateFrontendServiceRetryPolicy(),
		common.IsWhitelistServiceTransientError,
	)
	matchingRawClient, err := clientBean.GetMatchingClient(namespaceRegistry.GetNamespaceName)
	if err != nil {
		return nil, err
	}
	matchingClient := matching.NewRetryableClient(
		matchingRawClient,
		common.CreateMatchingServiceRetryPolicy(),
		common.IsWhitelistServiceTransientError,
	)
	historyRawClient := clientBean.GetHistoryClient()
	historyClient := history.NewRetryableClient(
		historyRawClient,
		common.CreateHistoryServiceRetryPolicy(),
		common.IsWhitelistServiceTransientError,
	)
	historyArchiverBootstrapContainer := &archiver.HistoryBootstrapContainer{
		ExecutionManager: persistenceBean.GetExecutionManager(),
		Logger:           logger,
		MetricsClient:    params.MetricsClient,
		ClusterMetadata:  clusterMetadata,
	}
	visibilityArchiverBootstrapContainer := &archiver.VisibilityBootstrapContainer{
		Logger:          logger,
		MetricsClient:   params.MetricsClient,
		ClusterMetadata: clusterMetadata,
	}
	if err := params.ArchiverProvider.RegisterBootstrapContainer(
		serviceName,
		historyArchiverBootstrapContainer,
		visibilityArchiverBootstrapContainer,
	); err != nil {
		return nil, err
	}
	impl = &Impl{
		status: common.DaemonStatusInitialized,
		numShards:       numShards,
		serviceName:     params.Name,
		hostName:        hostName,
		metricsScope:    params.MetricsScope,
		clusterMetadata: clusterMetadata,
		saProvider:      saProvider,
		saManager:       saManager,
		saMapper:        params.SearchAttributesMapper,
		namespaceRegistry: namespaceRegistry,
		timeSource:        clock.NewRealTimeSource(),
		payloadSerializer: serialization.NewSerializer(),
		metricsClient:     params.MetricsClient,
		archivalMetadata:  params.ArchivalMetadata,
		archiverProvider:  params.ArchiverProvider,
		membershipMonitor:       membershipMonitor,
		frontendServiceResolver: frontendServiceResolver,
		matchingServiceResolver: matchingServiceResolver,
		historyServiceResolver:  historyServiceResolver,
		workerServiceResolver:   workerServiceResolver,
		sdkClient:         params.SdkClient,
		frontendRawClient: frontendRawClient,
		frontendClient:    frontendClient,
		matchingRawClient: matchingRawClient,
		matchingClient:    matchingClient,
		historyRawClient:  historyRawClient,
		historyClient:     historyClient,
		clientBean:        clientBean,
		persistenceBean:           persistenceBean,
		persistenceFaultInjection: factory.FaultInjection(),
		logger:          logger,
		throttledLogger: throttledLogger,
		grpcListener: grpcListener,
		ringpopChannel: ringpopChannel,
		runtimeMetricsReporter: metrics.NewRuntimeMetricsReporter(
			params.MetricsScope,
			time.Minute,
			logger,
			params.InstanceID,
		),
		rpcFactory: params.RPCFactory,
	}
	return impl, nil
}
func (h *Impl) Start() {
	if !atomic.CompareAndSwapInt32(
		&h.status,
		common.DaemonStatusInitialized,
		common.DaemonStatusStarted,
	) {
		return
	}
	h.metricsScope.Counter(metrics.RestartCount).Inc(1)
	h.runtimeMetricsReporter.Start()
	h.membershipMonitor.Start()
	h.namespaceRegistry.Start()
	hostInfo, err := h.membershipMonitor.WhoAmI()
	if err != nil {
		h.logger.Fatal("fail to get host info from membership monitor", tag.Error(err))
	}
	h.hostInfo = hostInfo
	h.logger.Info("Service resources started", tag.Address(hostInfo.GetAddress()))
	rand.Seed(time.Now().UnixNano())
}
func (h *Impl) Stop() {
	if !atomic.CompareAndSwapInt32(
		&h.status,
		common.DaemonStatusStarted,
		common.DaemonStatusStopped,
	) {
		return
	}
	h.namespaceRegistry.Stop()
	h.membershipMonitor.Stop()
	h.ringpopChannel.Close()
	h.runtimeMetricsReporter.Stop()
	h.persistenceBean.Close()
}
func (h *Impl) GetServiceName() string {
	return h.serviceName
}
func (h *Impl) GetHostName() string {
	return h.hostName
}
func (h *Impl) GetHostInfo() *membership.HostInfo {
	return h.hostInfo
}
func (h *Impl) GetClusterMetadata() cluster.Metadata {
	return h.clusterMetadata
}
func (h *Impl) GetNamespaceRegistry() namespace.Registry {
	return h.namespaceRegistry
}
func (h *Impl) GetTimeSource() clock.TimeSource {
	return h.timeSource
}
func (h *Impl) GetPayloadSerializer() serialization.Serializer {
	return h.payloadSerializer
}
func (h *Impl) GetMetricsClient() metrics.Client {
	return h.metricsClient
}
func (h *Impl) GetArchivalMetadata() archiver.ArchivalMetadata {
	return h.archivalMetadata
}
func (h *Impl) GetArchiverProvider() provider.ArchiverProvider {
	return h.archiverProvider
}
func (h *Impl) GetMembershipMonitor() membership.Monitor {
	return h.membershipMonitor
}
func (h *Impl) GetFrontendServiceResolver() membership.ServiceResolver {
	return h.frontendServiceResolver
}
func (h *Impl) GetMatchingServiceResolver() membership.ServiceResolver {
	return h.matchingServiceResolver
}
func (h *Impl) GetHistoryServiceResolver() membership.ServiceResolver {
	return h.historyServiceResolver
}
func (h *Impl) GetWorkerServiceResolver() membership.ServiceResolver {
	return h.workerServiceResolver
}
func (h *Impl) GetSDKClient() sdkclient.Client {
	return h.sdkClient
}