本文整理匯總了Golang中github.com/Symantec/Dominator/lib/srpc.Client類的典型用法代碼示例。如果您正苦於以下問題:Golang Client類的具體用法?Golang Client怎麽用?Golang Client使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Client類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: sendUpdate
// Returns true if no update needs to be performed.
func (sub *Sub) sendUpdate(srpcClient *srpc.Client) (bool, subStatus) {
logger := sub.herd.logger
if !sub.pendingSafetyClear {
// Perform a cheap safety check.
if sub.requiredImage.Filter != nil &&
len(sub.fileSystem.InodeTable)>>1 >
len(sub.requiredImage.FileSystem.InodeTable) {
return false, statusUnsafeUpdate
}
}
var request subproto.UpdateRequest
var reply subproto.UpdateResponse
if idle, missing := sub.buildUpdateRequest(&request); missing {
return false, statusMissingComputedFile
} else if idle {
return true, statusSynced
}
if sub.mdb.DisableUpdates || sub.herd.updatesDisabledReason != "" {
return false, statusUpdatesDisabled
}
sub.status = statusSendingUpdate
sub.lastUpdateTime = time.Now()
if err := client.CallUpdate(srpcClient, request, &reply); err != nil {
srpcClient.Close()
logger.Printf("Error calling %s:Subd.Update(): %s\n", sub, err)
if err == srpc.ErrorAccessToMethodDenied {
return false, statusUpdateDenied
}
return false, statusFailedToUpdate
}
sub.pendingSafetyClear = false
return false, statusUpdating
}
示例2: deleteUnreferencedObjects
func deleteUnreferencedObjects(client *srpc.Client, percentage uint8,
bytes uint64) error {
request := imageserver.DeleteUnreferencedObjectsRequest{percentage, bytes}
var reply imageserver.DeleteUnreferencedObjectsResponse
return client.RequestReply("ImageServer.DeleteUnreferencedObjects",
request, &reply)
}
示例3: callPoll
func callPoll(client *srpc.Client, request sub.PollRequest,
reply *sub.PollResponse) error {
conn, err := client.Call("Subd.Poll")
if err != nil {
return err
}
defer conn.Close()
encoder := gob.NewEncoder(conn)
if err := encoder.Encode(request); err != nil {
return err
}
conn.Flush()
str, err := conn.ReadString('\n')
if err != nil {
return err
}
if str != "\n" {
return errors.New(str)
}
if err := gob.NewDecoder(conn).Decode(reply); err != nil {
return err
}
if reply.FileSystemFollows {
reply.FileSystem, err = filesystem.Decode(conn)
if err != nil {
return err
}
reply.ObjectCache, err = objectcache.Decode(conn)
if err != nil {
return err
}
}
return nil
}
示例4: fetch
func fetch(srpcClient *srpc.Client, hashesFilename string) error {
hashesFile, err := os.Open(hashesFilename)
if err != nil {
return err
}
defer hashesFile.Close()
scanner := bufio.NewScanner(hashesFile)
serverAddress := fmt.Sprintf("%s:%d",
*objectServerHostname, *objectServerPortNum)
hashes := make([]hash.Hash, 0)
for scanner.Scan() {
hashval, err := objectcache.FilenameToHash(scanner.Text())
if err != nil {
return err
}
hashes = append(hashes, hashval)
}
if err := scanner.Err(); err != nil {
return err
}
return srpcClient.RequestReply("Subd.Fetch", sub.FetchRequest{
ServerAddress: serverAddress,
Wait: true,
Hashes: hashes},
&sub.FetchResponse{})
}
示例5: configureSubs
func configureSubs(client *srpc.Client) error {
var request dominator.ConfigureSubsRequest
var reply dominator.ConfigureSubsResponse
request.ScanSpeedPercent = *scanSpeedPercent
request.NetworkSpeedPercent = *networkSpeedPercent
request.ScanExclusionList = scanExcludeList
return client.RequestReply("Dominator.ConfigureSubs", request, &reply)
}
示例6: disableUpdates
func disableUpdates(client *srpc.Client, reason string) error {
if reason == "" {
return errors.New("cannot disable updates: no reason given")
}
var request dominator.DisableUpdatesRequest
var reply dominator.DisableUpdatesResponse
request.Reason = reason
return client.RequestReply("Dominator.DisableUpdates", request, &reply)
}
示例7: checkImage
func checkImage(client *srpc.Client, name string) (bool, error) {
request := imageserver.CheckImageRequest{name}
var reply imageserver.CheckImageResponse
err := client.RequestReply("ImageServer.CheckImage", request, &reply)
if err != nil {
return false, err
}
return reply.ImageExists, nil
}
示例8: pollSubcommand
func pollSubcommand(getSubClient getSubClientFunc, args []string) {
var err error
var srpcClient *srpc.Client
for iter := 0; *numPolls < 0 || iter < *numPolls; iter++ {
if iter > 0 {
time.Sleep(time.Duration(*interval) * time.Second)
}
if srpcClient == nil {
srpcClient = getSubClient()
}
var request sub.PollRequest
var reply sub.PollResponse
request.ShortPollOnly = *shortPoll
pollStartTime := time.Now()
err = client.CallPoll(srpcClient, request, &reply)
fmt.Printf("Poll duration: %s\n", time.Since(pollStartTime))
if err != nil {
fmt.Fprintf(os.Stderr, "Error calling: %s\n", err)
os.Exit(1)
}
if *newConnection {
srpcClient.Close()
srpcClient = nil
}
fs := reply.FileSystem
if fs == nil {
if !*shortPoll {
fmt.Println("No FileSystem pointer")
}
} else {
fs.RebuildInodePointers()
if *debug {
fs.List(os.Stdout)
} else {
fmt.Println(fs)
}
fmt.Printf("Num objects: %d\n", len(reply.ObjectCache))
if *file != "" {
f, err := os.Create(*file)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating: %s: %s\n",
*file, err)
os.Exit(1)
}
encoder := gob.NewEncoder(f)
encoder.Encode(fs)
f.Close()
}
}
if reply.LastSuccessfulImageName != "" {
fmt.Printf("Last successful image: \"%s\"\n",
reply.LastSuccessfulImageName)
}
}
time.Sleep(time.Duration(*wait) * time.Second)
}
示例9: setDefaultImage
func setDefaultImage(client *srpc.Client, imageName string) error {
var request dominator.SetDefaultImageRequest
var reply dominator.SetDefaultImageResponse
request.ImageName = imageName
if err := client.RequestReply("Dominator.SetDefaultImage", request,
&reply); err != nil {
return err
}
return nil
}
示例10: getSubsConfiguration
func getSubsConfiguration(client *srpc.Client) error {
var request dominator.GetSubsConfigurationRequest
var reply dominator.GetSubsConfigurationResponse
if err := client.RequestReply("Dominator.GetSubsConfiguration", request,
&reply); err != nil {
return err
}
fmt.Println(sub.Configuration(reply))
return nil
}
示例11: getDefaultImage
func getDefaultImage(client *srpc.Client) error {
var request dominator.GetDefaultImageRequest
var reply dominator.GetDefaultImageResponse
if err := client.RequestReply("Dominator.GetDefaultImage", request,
&reply); err != nil {
return err
}
if reply.ImageName != "" {
fmt.Println(reply.ImageName)
}
return nil
}
示例12: pollSubcommand
func pollSubcommand(srpcClient *srpc.Client, args []string) {
var err error
clientName := fmt.Sprintf("%s:%d", *subHostname, *subPortNum)
for iter := 0; *numPolls < 0 || iter < *numPolls; iter++ {
if iter > 0 {
time.Sleep(time.Duration(*interval) * time.Second)
}
if srpcClient == nil {
srpcClient, err = srpc.DialHTTP("tcp", clientName)
if err != nil {
fmt.Fprintf(os.Stderr, "Error dialing\t%s\n", err)
os.Exit(1)
}
}
var request sub.PollRequest
var reply sub.PollResponse
pollStartTime := time.Now()
err = client.CallPoll(srpcClient, request, &reply)
fmt.Printf("Poll duration: %s\n", time.Since(pollStartTime))
if err != nil {
fmt.Fprintf(os.Stderr, "Error calling\t%s\n", err)
os.Exit(1)
}
if *newConnection {
srpcClient.Close()
srpcClient = nil
}
fs := reply.FileSystem
if fs == nil {
fmt.Println("No FileSystem pointer")
} else {
fs.RebuildInodePointers()
if *debug {
fs.List(os.Stdout)
} else {
fmt.Println(fs)
}
fmt.Printf("Num objects: %d\n", len(reply.ObjectCache))
if *file != "" {
f, err := os.Create(*file)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating: %s\t%s\n",
*file, err)
os.Exit(1)
}
encoder := gob.NewEncoder(f)
encoder.Encode(fs)
f.Close()
}
}
}
time.Sleep(time.Duration(*wait) * time.Second)
}
示例13: newObjectAdderQueue
func newObjectAdderQueue(client *srpc.Client) (*ObjectAdderQueue, error) {
var objQ ObjectAdderQueue
var err error
objQ.conn, err = client.Call("ObjectServer.AddObjects")
if err != nil {
return nil, err
}
objQ.encoder = gob.NewEncoder(objQ.conn)
getResponseChan := make(chan bool, 65536)
errorChan := make(chan error, 1024)
objQ.getResponseChan = getResponseChan
objQ.errorChan = errorChan
objQ.sendSemaphore = make(chan bool, 1)
go readResponses(objQ.conn, getResponseChan, errorChan)
return &objQ, nil
}
示例14: updateConfiguration
func (sub *Sub) updateConfiguration(srpcClient *srpc.Client,
pollReply subproto.PollResponse) {
if pollReply.ScanCount < 1 {
return
}
sub.herd.RLock()
newConf := sub.herd.configurationForSubs
sub.herd.RUnlock()
if compareConfigs(pollReply.CurrentConfiguration, newConf) {
return
}
if err := client.SetConfiguration(srpcClient, newConf); err != nil {
srpcClient.Close()
logger := sub.herd.logger
logger.Printf("Error setting configuration for sub: %s: %s\n",
sub, err)
return
}
}
示例15: listDirectories
func listDirectories(client *srpc.Client) ([]image.Directory, error) {
conn, err := client.Call("ImageServer.ListDirectories")
if err != nil {
return nil, err
}
defer conn.Close()
directories := make([]image.Directory, 0)
decoder := gob.NewDecoder(conn)
for {
var directory image.Directory
if err := decoder.Decode(&directory); err != nil {
return nil, err
}
if directory.Name == "" {
break
}
directories = append(directories, directory)
}
return directories, nil
}