Exemple #1
0
// Validate verifies user options for correctness.
func (this *Options) Validate() (status error) {
	if this.MaxReadSize < 8 {
		err := errs.NewErrInvalid("minimum read size must be at least 8 bytes")
		status = errs.MergeErrors(status, err)
	}
	if this.MaxWriteSize < 8 {
		err := errs.NewErrInvalid("minimum write size must be at least 8 bytes")
		status = errs.MergeErrors(status, err)
	}
	if this.MaxFileSize < 8 {
		err := errs.NewErrInvalid("minimum file size must be at least 8 bytes")
		status = errs.MergeErrors(status, err)
	}
	if this.MaxReadDirNames < 1 {
		err := errs.NewErrInvalid("readier must read at least one name per call")
		status = errs.MergeErrors(status, err)
	}
	return status
}
Exemple #2
0
// Validate checks user configuration options for invalid settings.
func (this *Options) Validate() (status error) {
	if this.MaxElectionHistory < 0 {
		err := errs.NewErrInvalid("election round history size cannot be -ve")
		status = errs.MergeErrors(status, err)
	}
	if err := this.PaxosOptions.Validate(); err != nil {
		status = errs.MergeErrors(status, err)
	}
	return status
}
Exemple #3
0
// Validate checks if user configuration items are all valid.
func (this *Options) Validate() (status error) {
	if this.ProposeRetryInterval < time.Millisecond {
		err := errs.NewErrInvalid("propose retry should wait for at least a " +
			"millisecond")
		status = errs.MergeErrors(status, err)
	}
	if this.NumExtraPhase1Acceptors < 0 {
		err := errs.NewErrInvalid("number of extra phase1 acceptors cannot be -ve")
		status = errs.MergeErrors(status, err)
	}
	if this.LearnTimeout < time.Millisecond {
		err := errs.NewErrInvalid("learn timeout must be at least a millisecond")
		status = errs.MergeErrors(status, err)
	}
	if this.LearnRetryInterval < time.Millisecond {
		err := errs.NewErrInvalid("learn notfication retry interval is too small")
		status = errs.MergeErrors(status, err)
	}
	return status
}
Exemple #4
0
// Validate checks for invalid user configuration settings.
func (this *Options) Validate() (status error) {
	if this.ResponseQueueSize < 1 {
		err := errs.NewErrInvalid("response queue size should be at least one")
		status = errs.MergeErrors(status, err)
	}
	if this.SendQueueSize < 1 {
		err := errs.NewErrInvalid("outbox queue size should at least one")
		status = errs.MergeErrors(status, err)
	}
	if this.NegotiationTimeout < time.Millisecond {
		err := errs.NewErrInvalid("connection negotiation timeout is too small")
		status = errs.MergeErrors(status, err)
	}
	if this.SendRetryTimeout < 10*time.Millisecond {
		err := errs.NewErrInvalid("send retry timeout is too small")
		status = errs.MergeErrors(status, err)
	}
	if this.MaxDispatchRequests < 1 {
		err := errs.NewErrInvalid("at least one request should be dispatched")
		status = errs.MergeErrors(status, err)
	}
	return status
}
Exemple #5
0
// DispatchRequest invokes the target (exported) function identified in the
// request message.
//
// header: Message header for the request.
//
// data: User data in the request.
//
// Returns dispatch operation status and the handler status.
func (this *Messenger) DispatchRequest(header *msgpb.Header,
	data []byte) (msnStatus, appStatus error) {

	defer func() {
		if msnStatus != nil || appStatus != nil {
			failure := this.NewResponse(header)
			if msnStatus != nil {
				failure.Response.MessengerStatus = errs.MakeProtoFromError(msnStatus)
			} else {
				failure.Response.HandlerStatus = errs.MakeProtoFromError(appStatus)
			}

			sourceID := header.GetMessengerId()
			if err := this.Send(sourceID, failure, nil); err != nil {
				this.Errorf("could not reply failure %s for %s from %s (ignored)",
					failure, header, sourceID)
			}
		}
	}()

	lock, errLock := this.ctlr.Lock("this.exportMap")
	if errLock != nil {
		return errLock, nil
	}
	defer lock.Unlock()

	request := header.GetRequest()
	classID := request.GetClassId()
	methodName := request.GetMethodName()
	if len(classID) == 0 || len(methodName) == 0 {
		this.Errorf("header %s is invalid because class id and/or method name "+
			"are empty", header)
		msnStatus = errs.NewErrInvalid("class id and/or method name cannot be " +
			"empty")
		return msnStatus, nil
	}

	methodMap, found := this.exportMap[classID]
	if !found {
		this.Errorf("no class with id %s was registered", classID)
		msnStatus = errs.NewErrNotExist("no class with id %s was registered",
			classID)
		return msnStatus, nil
	}

	handler, found := methodMap[methodName]
	if !found {
		this.Errorf("class %s has no method named %s", classID, methodName)
		msnStatus = errs.NewErrNotExist("class %s has no method named %s", classID,
			methodName)
		return msnStatus, nil
	}

	// Close the lock early to release the resources.
	lock.Unlock()

	appStatus = handler.Dispatch(header, data)
	if appStatus != nil {
		this.Warningf("request %s failed with status %v", header, appStatus)
	}
	return nil, appStatus
}