func (t *HTTPTransporter) Send(ctx context.Context, msg *Message) (sendError error) {
	return t.getState().Send(ctx, msg)
}
Send sends the message to its specified upid.
package messenger
import (
	"bytes"
	"crypto/tls"
	"encoding/hex"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"net"
	"net/http"
	"os"
	"strings"
	"sync"
	"time"
	log "github.com/golang/glog"
	"github.com/mesos/mesos-go/api/v0/upid"
	"golang.org/x/net/context"
)
const (
	DefaultReadTimeout  = 10 * time.Second
	DefaultWriteTimeout = 10 * time.Second
)
var (
	ReadTimeout  = DefaultReadTimeout
	WriteTimeout = DefaultWriteTimeout
	discardOnStopError = fmt.Errorf("discarding message because transport is shutting down")
	errNotStarted      = errors.New("HTTP transport has not been started")
	errTerminal        = errors.New("HTTP transport is terminated")
	errAlreadyRunning  = errors.New("HTTP transport is already running")
	httpTransport = http.Transport{
		Dial: (&net.Dialer{
			Timeout:   10 * time.Second,
			KeepAlive: 30 * time.Second,
		}).Dial,
		TLSHandshakeTimeout:   10 * time.Second,
		ResponseHeaderTimeout: DefaultReadTimeout,
	}
	HttpClient = http.Client{
		Timeout: DefaultReadTimeout,
	}
)
type httpTransporter interface {
	Send(ctx context.Context, msg *Message) error
	Recv() (*Message, error)
	Install(messageName string)
	Start() (upid.UPID, <-chan error)
	Stop(graceful bool) error
}
type notStartedState struct {
	h *HTTPTransporter
}
type stoppedState struct{}
type runningState struct {
	*notStartedState
}
func (s *notStartedState) Send(ctx context.Context, msg *Message) error { return errNotStarted }
func (s *notStartedState) Recv() (*Message, error)                      { return nil, errNotStarted }
func (s *notStartedState) Stop(graceful bool) error                     { return errNotStarted }
func (s *notStartedState) Install(messageName string)                   { s.h.install(messageName) }
func (s *notStartedState) Start() (upid.UPID, <-chan error) {
	s.h.state = &runningState{s}
	return s.h.start()
}
func (s *stoppedState) Send(ctx context.Context, msg *Message) error { return errTerminal }
func (s *stoppedState) Recv() (*Message, error)                      { return nil, errTerminal }
func (s *stoppedState) Stop(graceful bool) error                     { return errTerminal }
func (s *stoppedState) Install(messageName string)                   {}
func (s *stoppedState) Start() (upid.UPID, <-chan error) {
	ch := make(chan error, 1)
	ch <- errTerminal
	return upid.UPID{}, ch
}
func (s *runningState) Send(ctx context.Context, msg *Message) error { return s.h.send(ctx, msg) }
func (s *runningState) Recv() (*Message, error)                      { return s.h.recv() }
func (s *runningState) Stop(graceful bool) error {
	s.h.state = &stoppedState{}
	return s.h.stop(graceful)
}
func (s *runningState) Start() (upid.UPID, <-chan error) {
	ch := make(chan error, 1)
	ch <- errAlreadyRunning
	return upid.UPID{}, ch
}
type httpOpt func(*HTTPTransporter)
type HTTPTransporter struct {
	upid         upid.UPID
	listener     net.Listener  
	mux          *http.ServeMux
	tr           *http.Transport
	client       *http.Client
	messageQueue chan *Message
	address      net.IP  
	shouldQuit   chan struct{}
	stateLock    sync.RWMutex  
	state        httpTransporter
	server       *http.Server
}
func NewHTTPTransporter(upid upid.UPID, address net.IP, opts ...httpOpt) *HTTPTransporter {
	transport := httpTransport
	client := HttpClient
	client.Transport = &transport
	mux := http.NewServeMux()
	result := &HTTPTransporter{
		upid:         upid,
		messageQueue: make(chan *Message, defaultQueueSize),
		mux:          mux,
		client:       &client,
		tr:           &transport,
		address:      address,
		shouldQuit:   make(chan struct{}),
		server: &http.Server{
			ReadTimeout:  ReadTimeout,
			WriteTimeout: WriteTimeout,
			Handler:      mux,
		},
	}
	for _, f := range opts {
		f(result)
	}
	result.state = &notStartedState{result}
	return result
}
func ServerTLSConfig(config *tls.Config, nextProto map[string]func(*http.Server, *tls.Conn, http.Handler)) httpOpt {
	return func(transport *HTTPTransporter) {
		transport.server.TLSConfig = config
		transport.server.TLSNextProto = nextProto
	}
}
func ClientTLSConfig(config *tls.Config, handshakeTimeout time.Duration) httpOpt {
	return func(transport *HTTPTransporter) {
		transport.tr.TLSClientConfig = config
		transport.tr.TLSHandshakeTimeout = handshakeTimeout
	}
}
func (t *HTTPTransporter) getState() httpTransporter {
	t.stateLock.RLock()
	defer t.stateLock.RUnlock()
	return t.state
}