//  The "titanic.request" task waits for requests to this service. It writes
//  each request to disk and returns a UUID to the client. The client picks
//  up the reply asynchronously using the "titanic.reply" service:
483218
func TitanicRequest(chRequest chan<- string) {
	worker, _ := mdapi.NewMdwrk("tcp://localhost:5555", "titanic.request", false)

	reply := []string{}
	for {
		//  Send reply if it's not null
		//  And then get next request from broker
		request, err := worker.Recv(reply)
		if err != nil {
			break //  Interrupted, exit
		}

		//  Ensure message directory exists
		os.MkdirAll(TITANIC_DIR, 0700)

		//  Generate UUID and save message to disk
		uuid := uuid.New()
		file, err := os.Create(RequestFilename(uuid))
		fmt.Fprint(file, strings.Join(request, "\n"))
		file.Close()

		//  Send UUID through to message queue
		chRequest <- uuid

		//  Now send UUID back to client
		//  Done by the mdwrk_recv() at the top of the loop
		reply = []string{"200", uuid}
	}
}
379027
func (s *server) Fetch(ctx context.Context, req *v2.DiscoveryRequest) (*v2.DiscoveryResponse, error) {
	if s.callbacks != nil {
		if err := s.callbacks.OnFetchRequest(ctx, req); err != nil {
			return nil, err
		}
	}
	resp, err := s.cache.Fetch(ctx, *req)
	if err != nil {
		return nil, err
	}
	out, err := createResponse(resp, req.TypeUrl)
	if s.callbacks != nil {
		s.callbacks.OnFetchResponse(req, out)
	}
	return out, err
}
321723
func (o *FlushInactiveOAuth2TokensParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {

	if err := r.SetTimeout(o.timeout); err != nil {
		return err
	}
	var res []error

	if o.Body != nil {
		if err := r.SetBodyParam(o.Body); err != nil {
			return err
		}
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}
585429
func (api *TasksAPI) Wait(id string) (task *Task, err error) {
	return api.WaitTimeout(id, api.client.options.TaskPollTimeout)
}
462734
func NewWaitingTask(msg string) *WaitingTask {
	ch := make(chan *Update, 1)
	ch <- &Update{
		S:  fmt.Sprintf("%s: ...", msg),
		At: time.Now(),
	}

	return &WaitingTask{ch: ch}
}
798850
func (n *Nats) Request(subject string, data PayloadWithContext, responsePtr interface{}, timeout time.Duration) error {
	dead := time.Now().Add(timeout)
	n.updateContext(data, RequestType_REQ, &dead)
	return n.EncCon.Request(subject, data, responsePtr, timeout)
}
1324604
func (s *IndicesAnalyzeService) Request(request *IndicesAnalyzeRequest) *IndicesAnalyzeService {
	if request == nil {
		s.request = new(IndicesAnalyzeRequest)
	} else {
		s.request = request
	}
	return s
}
464414
func (c Client) request(method, url string, payload interface{}) (*http.Response, error) {
	var (
		b   []byte
		err error
	)

	if method == "POST" { // Just allow payload on POST
		b, err = json.Marshal(payload)
		if err != nil {
			return nil, err
		}
	}

	req, err := http.NewRequest(method, url, bytes.NewBuffer(b))
	if err != nil {
		return nil, err
	}
	req.Header.Set("Content-Type", "application/json")

	// REMEMBER TO CLOSE THE BODY IN THE OUTSIDE FUNCTION
	return c.Do(req)
}
477825
func (r *TasksService) Requests() *TasksRequestsCall {
	c := &TasksRequestsCall{s: r.s, urlParams_: make(gensupport.URLParams)}
	return c
}
743786
func Request(requests ...mesos.Request) *scheduler.Call {
	return &scheduler.Call{
		Type: scheduler.Call_REQUEST,
		Request: &scheduler.Call_Request{
			Requests: requests,
		},
	}
}
795794
func (self *Notifications) Post(request *gottp.Request) {
	pending_item := new(db.PendingItem)
	request.ConvertArguments(pending_item)

	if request.GetArgument("topic") == nil {
		request.Raise(gottp.HttpError{
			http.StatusBadRequest,
			"Please provide topic for notification.",
		})

		return
	}

	if pending.Throttled(pending_item) {
		MSG := "Repeated Notifications are Blocked. Skipping."

		log.Println(MSG)
		request.Raise(gottp.HttpError{http.StatusBadRequest, MSG})
		return
	}

	pending_item.Topic = request.GetArgument("topic").(string)
	pending_item.IsRead = false

	pending_item.PrepareSave()

	if !utils.ValidateAndRaiseError(request, pending_item) {
		return
	}

	if !pending_item.IsValid() {
		request.Raise(gottp.HttpError{
			http.StatusBadRequest,
			"Context is required for sending notification.",
		})

		return
	}

	core.SendNotification(pending_item)
	request.Write(utils.R{StatusCode: http.StatusNoContent,
		Data: nil, Message: "true"})
	return
}
53481
func (server *Server) SendTask(signature *tasks.Signature) (*result.AsyncResult, error) {
	return server.SendTaskWithContext(context.Background(), signature)
}
80024
func lookupTask(id string, responsec responder) task {
	return func(c *cache) error {
		b, ok := c.buckets[id]
		switch {
		case !ok:
			// ID is unknown.
			c.buckets[id] = &bucket{
				status:  statusLoading,
				waiters: []responder{responsec},
			}
			go loading(c, id)
		case ok && b.status == statusLoading:
			// ID is known but Cacheable is not yet retrieved.
			b.waiters = append(b.waiters, responsec)
		case ok && b.status == statusLoaded:
			// ID is known and Cacheable is loaded.
			outdated, err := b.cacheable.IsOutdated()
			if err != nil {
				// Error during check if outdated.
				responsec <- func() (Cacheable, error) {
					return nil, errors.Annotate(err, ErrCheckOutdated, errorMessages, id)
				}
				delete(c.buckets, id)
				return nil
			}
			if outdated {
				// Outdated, so reload.
				c.buckets[id].status = statusLoading
				c.buckets[id].waiters = []responder{responsec}
				go loading(c, id)
			}
			// Everything fine.
			b.lastUsed = time.Now()
			responsec <- func() (Cacheable, error) {
				return b.cacheable, nil
			}
		}
		return nil
	}
}
930875
func request(core *vault.Core, w http.ResponseWriter, rawReq *http.Request, r *logical.Request) (*logical.Response, bool, bool) {
	resp, err := core.HandleRequest(rawReq.Context(), r)
	if r.LastRemoteWAL() > 0 && !vault.WaitUntilWALShipped(rawReq.Context(), core, r.LastRemoteWAL()) {
		if resp == nil {
			resp = &logical.Response{}
		}
		resp.AddWarning("Timeout hit while waiting for local replicated cluster to apply primary's write; this client may encounter stale reads of values written during this operation.")
	}
	if errwrap.Contains(err, consts.ErrStandby.Error()) {
		respondStandby(core, w, rawReq.URL)
		return resp, false, false
	}
	if err != nil && errwrap.Contains(err, logical.ErrPerfStandbyPleaseForward.Error()) {
		return nil, false, true
	}

	if resp != nil && len(resp.Headers) > 0 {
		// Set this here so it will take effect regardless of any other type of
		// response processing
		header := w.Header()
		for k, v := range resp.Headers {
			for _, h := range v {
				header.Add(k, h)
			}
		}

		switch {
		case resp.Secret != nil,
			resp.Auth != nil,
			len(resp.Data) > 0,
			resp.Redirect != "",
			len(resp.Warnings) > 0,
			resp.WrapInfo != nil:
			// Nothing, resp has data

		default:
			// We have an otherwise totally empty response except for headers,
			// so nil out the response now that the headers are written out
			resp = nil
		}
	}

	if respondErrorCommon(w, r, resp, err) {
		return resp, false, false
	}

	return resp, true, false
}
255512
func TitanicClose() {
	worker, _ := mdapi.NewMdwrk("tcp://localhost:5555", "titanic.close", false)

	ok := []string{"200"}
	reply := []string{}
	for {
		request, err := worker.Recv(reply)
		if err != nil {
			break //  Interrupted, exit
		}

		uuid := request[0]
		os.Remove(RequestFilename(uuid))
		os.Remove(ReplyFilename(uuid))

		reply = ok
	}

}
1329977
func client_task() {
	client, _ := zmq.NewSocket(zmq.REQ)
	defer client.Close()
	client.Connect("ipc://frontend.ipc")

	//  Send request, get reply
	for {
		client.SendMessage("HELLO")
		reply, _ := client.RecvMessage(0)
		if len(reply) == 0 {
			break
		}
		fmt.Println("Client:", strings.Join(reply, "\n\t"))
		time.Sleep(time.Second)
	}
}
1155446
func (cn *connection) request(r request, mw messageWriter) bool {
	if _, ok := cn.requests[r]; ok {
		panic("chunk already requested")
	}
	if !cn.PeerHasPiece(pieceIndex(r.Index)) {
		panic("requesting piece peer doesn't have")
	}
	if _, ok := cn.t.conns[cn]; !ok {
		panic("requesting but not in active conns")
	}
	if cn.closed.IsSet() {
		panic("requesting when connection is closed")
	}
	if cn.PeerChoked {
		if cn.peerAllowedFast.Get(int(r.Index)) {
			torrent.Add("allowed fast requests sent", 1)
		} else {
			panic("requesting while choked and not allowed fast")
		}
	}
	if cn.t.hashingPiece(pieceIndex(r.Index)) {
		panic("piece is being hashed")
	}
	if cn.t.pieceQueuedForHash(pieceIndex(r.Index)) {
		panic("piece is queued for hash")
	}
	if cn.requests == nil {
		cn.requests = make(map[request]struct{})
	}
	cn.requests[r] = struct{}{}
	if cn.validReceiveChunks == nil {
		cn.validReceiveChunks = make(map[request]struct{})
	}
	cn.validReceiveChunks[r] = struct{}{}
	cn.t.pendingRequests[r]++
	cn.t.lastRequested[r] = time.AfterFunc(cn.t.duplicateRequestTimeout, func() {
		torrent.Add("duplicate request timeouts", 1)
		cn.mu().Lock()
		defer cn.mu().Unlock()
		delete(cn.t.lastRequested, r)
		for cn := range cn.t.conns {
			if cn.PeerHasPiece(pieceIndex(r.Index)) {
				cn.updateRequests()
			}
		}
	})
	cn.updateExpectingChunks()
	return mw(pp.Message{
		Type:   pp.Request,
		Index:  r.Index,
		Begin:  r.Begin,
		Length: r.Length,
	})
}