client

package
v0.0.0-...-aad241e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2014 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Job type
	// JOB_NORMAL | JOB_BG means a normal level job run in background
	// normal level
	JOB_NORMAL = 0
	// background job
	JOB_BG = 1
	// low level
	JOB_LOW = 2
	// high level
	JOB_HIGH = 4
)
View Source
const (
	PoolSize = 10
)

Variables

View Source
var (
	ErrNotFound = errors.New("Server Not Found")
)

Functions

func SelectRandom

func SelectRandom(pool map[string]*poolClient,
	last string) (addr string)

func SelectWithRate

func SelectWithRate(pool map[string]*poolClient,
	last string) (addr string)

Types

type Client

type Client struct {
	ErrHandler common.ErrorHandler
	TimeOut    time.Duration
	// contains filtered or unexported fields
}

The client side api for gearman

usage: c := client.New("tcp4", "127.0.0.1:4730") handle := c.Do("foobar", []byte("data here"), JOB_LOW | JOB_BG)

func New

func New(addr string) (client *Client, err error)

Create a new client. Connect to "addr" through "network" Eg.

client, err := client.New("127.0.0.1:4730")

func (*Client) Close

func (client *Client) Close() (err error)

Close

func (*Client) Do

func (client *Client) Do(funcname string, data []byte,
	flag byte, jobhandler JobHandler) (handle string)

Do the function. funcname is a string with function name. data is encoding to byte array. flag set the job type, include running level: JOB_LOW, JOB_NORMAL, JOB_HIGH, and if it is background job: JOB_BG. JOB_LOW | JOB_BG means the job is running with low level in background.

func (*Client) DoBg

func (client *Client) DoBg(funcname string, data []byte,
	flag byte) (handle string)

func (*Client) Echo

func (client *Client) Echo(data []byte, timeout time.Duration) (r []byte, err error)

Send a something out, get the samething back.

func (*Client) Status

func (client *Client) Status(handle string, timeout time.Duration) (status *Status, err error)

Get job status from job server. !!!Not fully tested.!!!

type ErrorHandler

type ErrorHandler func(error)

An error handler

type IdGenerator

type IdGenerator interface {
	Id() string
}
var (
	IdGen IdGenerator
)

func NewAutoIncId

func NewAutoIncId() IdGenerator

func NewObjectId

func NewObjectId() IdGenerator

type Job

type Job struct {
	Data             []byte
	Handle, UniqueId string
	DataType         uint32
	// contains filtered or unexported fields
}

Client side job

func (*Job) Encode

func (job *Job) Encode() (data []byte)

Encode a job to byte slice

func (*Job) Result

func (job *Job) Result() (data []byte, err error)

Extract the job's result.

func (*Job) Update

func (job *Job) Update() (data []byte, err error)

Extract the job's update

type JobHandler

type JobHandler func(*Job)

Job handler

type Pool

type Pool struct {
	SelectionHandler SelectionHandler
	ErrHandler       common.ErrorHandler
	// contains filtered or unexported fields
}

func NewPool

func NewPool() (pool *Pool)

Create a new pool.

func (*Pool) Add

func (pool *Pool) Add(addr string, rate int) (err error)

Add a server with rate.

func (*Pool) Close

func (pool *Pool) Close() (err map[string]error)

Close

func (*Pool) Do

func (pool *Pool) Do(funcname string, data []byte,
	flag byte, h JobHandler) (addr, handle string)

func (*Pool) DoBg

func (pool *Pool) DoBg(funcname string, data []byte,
	flag byte) (addr, handle string)

func (*Pool) Echo

func (pool *Pool) Echo(addr string, data []byte, timeout time.Duration) (r []byte, err error)

Send a something out, get the samething back.

func (*Pool) Remove

func (pool *Pool) Remove(addr string)

Remove a server.

func (*Pool) Status

func (pool *Pool) Status(addr, handle string, timeout time.Duration) (status *Status, err error)

Get job status from job server. !!!Not fully tested.!!!

type SelectionHandler

type SelectionHandler func(map[string]*poolClient, string) string

type Status

type Status struct {
	Handle                 string
	Known, Running         bool
	Numerator, Denominator uint64
}

type StatusHandler

type StatusHandler func(string, bool, bool, uint64, uint64)

Status handler handle, known, running, numerator, denominator

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL