github.com/Axway/agent-sdk@v1.1.101/pkg/agent/poller/options.go (about)

     1  package poller
     2  
     3  import (
     4  	"github.com/Axway/agent-sdk/pkg/agent/events"
     5  	"github.com/Axway/agent-sdk/pkg/harvester"
     6  	"github.com/Axway/agent-sdk/pkg/util"
     7  	hc "github.com/Axway/agent-sdk/pkg/util/healthcheck"
     8  )
     9  
    10  // ClientOpt func for setting fields on the PollClient
    11  type ClientOpt func(pc *PollClient)
    12  
    13  // WithHarvester configures the polling client to use harvester
    14  func WithHarvester(hClient harvester.Harvest, sequence events.SequenceProvider, topicSelfLink string) ClientOpt {
    15  	return func(pc *PollClient) {
    16  		pc.harvesterConfig.hClient = hClient
    17  		pc.harvesterConfig.topicSelfLink = topicSelfLink
    18  		pc.harvesterConfig.sequence = sequence
    19  	}
    20  }
    21  
    22  // WithOnClientStop func to execute when the client shuts down
    23  func WithOnClientStop(cb func()) ClientOpt {
    24  	return func(pc *PollClient) {
    25  		pc.onClientStop = cb
    26  	}
    27  }
    28  
    29  // WithOnConnect func to execute when a connection to central is made
    30  func WithOnConnect() ClientOpt {
    31  	return func(pc *PollClient) {
    32  		pc.onStreamConnection = func() {
    33  			hc.RegisterHealthcheck(util.AmplifyCentral, util.CentralHealthCheckEndpoint, pc.Healthcheck)
    34  		}
    35  	}
    36  }
    37  
    38  type executorOpt func(m *pollExecutor)
    39  
    40  func withHarvester(cfg harvesterConfig) executorOpt {
    41  	return func(m *pollExecutor) {
    42  		m.harvester = cfg.hClient
    43  		m.sequence = cfg.sequence
    44  		m.topicSelfLink = cfg.topicSelfLink
    45  	}
    46  }
    47  
    48  func withOnStop(cb onClientStopCb) executorOpt {
    49  	return func(m *pollExecutor) {
    50  		m.onStop = cb
    51  	}
    52  }