Example #1
0
// Dispatch handles all incoming rpc requests for this object.
func (this *Election) Dispatch(header *msgpb.Header, data []byte) error {
	request := header.GetRequest()
	objectID := request.GetObjectId()

	// Dispatch classic paxos rpcs to the paxos instances.
	if objectID != this.uid {
		if this.IsPaxosUID(objectID) {
			return this.DispatchPaxos(header, data)
		}
		this.Errorf("rpc request %s doesn't belong to this instance", header)
		return errs.ErrInvalid
	}

	message := thispb.ElectionMessage{}
	if err := proto.Unmarshal(data, &message); err != nil {
		this.Errorf("could not parse incoming message %s", header)
		return err
	}

	switch {
	case message.ElectRequest != nil:
		return this.ElectRPC(header, message.GetElectRequest())

	case message.StatusRequest != nil:
		return this.StatusRPC(header, message.GetStatusRequest())

	default:
		this.Errorf("unknown/invalid rpc reqest %s", header)
		return errs.ErrInvalid
	}
}