// AddStream adds a new stream.
// If no error is returned, the logdogServ assumes ownership of the supplied
// stream. The stream will be closed when processing is finished.
495051
func (l *logdogServer) AddStream(rc io.ReadCloser, props *streamproto.Properties) error {
	return l.butler.AddStream(rc, props)
}
1169326
func NewStream(ctx context.Context, method string, conn *Conn) (Stream, error) {
	if ctx == nil {
		ctx = context.Background()
	}

	return newStreamClient(ctx, method, conn)
}
62988
func (prod *AwsCloudwatchLogs) createStream() error {
	params := &cloudwatchlogs.CreateLogStreamInput{
		LogGroupName:  &prod.group,
		LogStreamName: &prod.stream,
	}
	_, err := prod.service.CreateLogStream(params)
	if awsErr, ok := err.(awserr.Error); ok {
		if awsErr.Code() == "ResourceAlreadyExistsException" {
			return nil
		}
	}
	return err
}
896197
func (a *Adapter) Stream(logstream chan *router.Message) {
	wg := sync.WaitGroup{}
	wg.Add(1)
	go func() {
		a.subAdapter.Stream(a.out)
		wg.Done()
	}()
	defer func() {
		for _, message := range a.buffers {
			a.out <- message
		}

		close(a.out)
		wg.Wait()
	}()

	for {
		select {
		case message, ok := <-logstream:
			if !ok {
				return
			}

			if !multilineContainer(message.Container, a.enableByDefault) {
				a.out <- message
				continue
			}

			cID := message.Container.ID
			old, oldExists := a.buffers[cID]
			if a.isFirstLine(message) {
				if oldExists {
					a.out <- old
				}

				a.buffers[cID] = message
			} else {
				isLastLine := a.isLastLine(message)
				
				if oldExists {
					old.Data += a.separator + message.Data
					message = old
				}

				if isLastLine {
					a.out <- message
					if oldExists {
						delete(a.buffers, cID)
					}
				} else {
					a.buffers[cID] = message
				}
			}
		case <-a.nextCheck:
			now := time.Now()

			for key, message := range a.buffers {
				if message.Time.Add(a.flushAfter).After(now) {
					a.out <- message
					delete(a.buffers, key)
				}
			}

			a.nextCheck = time.After(a.checkInterval)
		}
	}
}
669925
func (s *GetEventStreamOutput) SetEventStream(v *EventStream) *GetEventStreamOutput {
	s.EventStream = v
	return s
}
1261104
func (as *Step) AddLogdogStreamLink(server, label string, prefix, name types.StreamName) {
	link := as.getOrCreateLinkForLabel(label)
	link.Value = &milo.Link_LogdogStream{&milo.LogdogStream{
		Name:   string(name),
		Server: server,
		Prefix: string(prefix),
	}}
}
1307365
func (m *Mixer) Add(s ...Streamer) {
	m.streamers = append(m.streamers, s...)
}
339377
func NewClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, opts ...CallOption) (ClientStream, error) {
	return cc.NewStream(ctx, desc, method, opts...)
}
1299108
func (l *Log) Stream(header string) Stream {
	return &stream{
		header: header,
		log:    l,
		quiet:  l.quiet,
	}
}
119737
func (m *Middleware) HandleStream(serverStream *transport.ServerStream, h transport.StreamHandler) error {
	call := m.graph.begin(serverStream.Context(), transport.Streaming, _directionInbound, serverStream.Request().Meta.ToRequest())
	err := h.HandleStream(serverStream)
	// TODO(pedge): wrap the *transport.ServerStream?
	call.End(err)
	return err
}
93910
func (c *Client) Stream(serviceMethod string, args interface{}) (io.ReadCloser, error) {
	var buf bytes.Buffer
	if err := json.NewEncoder(&buf).Encode(args); err != nil {
		return nil, err
	}
	return c.callWithRetry(serviceMethod, &buf, true)
}
447709
func (c *cache) RegisterStream(ctx context.Context, st *LogStreamState, desc []byte) (*LogStreamState, error) {
	entry, created := c.getCacheEntry(ctx, cacheEntryKey{
		project: st.Project,
		path:    st.Path,
	})
	tsCache.Add(ctx, 1, !created)

	st, err := entry.registerStream(ctx, c.Coordinator, *st, desc)
	if err != nil {
		log.WithError(err).Errorf(ctx, "Error retrieving stream state.")
		return nil, err
	}

	return st, nil
}
1057222
func AddStreamError(reg *descriptor.Registry) error {
	//load internal protos
	any := fileDescriptorProtoForMessage(&any.Any{})
	streamError := fileDescriptorProtoForMessage(&internal.StreamError{})
	if err := reg.Load(&plugin.CodeGeneratorRequest{
		ProtoFile: []*protocdescriptor.FileDescriptorProto{
			any,
			streamError,
		},
	}); err != nil {
		return err
	}
	return nil
}
646100
func (es *EventStream) AddReceiver(w http.ResponseWriter) (*EventReceiver, error) {
	w.Header().Set("Content-Type", "text/event-stream")
	w.Header().Set("Cache-Control", "no-cache")
	w.Header().Set("Connection", "keep-alive")

	w.WriteHeader(200)

	hj, ok := w.(http.Hijacker)
	if !ok {
		return nil, ErrUnableToHijackRequest
	}

	hjConn, hjBufrw, err := hj.Hijack()
	if err != nil {
		return nil, err
	}

	rec := &EventReceiver{es, hjConn, hjBufrw}

	es.mutex.Lock()
	es.receivers[hjConn] = rec
	es.mutex.Unlock()

	return rec, nil
}
754954
func (s *server) LoadStream(c context.Context, req *logdog.LoadStreamRequest) (*logdog.LoadStreamResponse, error) {
	log.Fields{
		"project": req.Project,
		"id":      req.Id,
	}.Infof(c, "Loading log stream state.")

	id := coordinator.HashID(req.Id)
	if err := id.Normalize(); err != nil {
		log.WithError(err).Errorf(c, "Invalid stream ID.")
		return nil, grpcutil.Errf(codes.InvalidArgument, "Invalid ID (%s): %s", id, err)
	}

	ls := &coordinator.LogStream{ID: coordinator.HashID(req.Id)}
	lst := ls.State(c)

	if err := ds.Get(c, lst, ls); err != nil {
		if anyNoSuchEntity(err) {
			log.WithError(err).Errorf(c, "No such entity in datastore.")

			// The state isn't registered, so this stream does not exist.
			return nil, grpcutil.Errf(codes.NotFound, "Log stream was not found.")
		}

		log.WithError(err).Errorf(c, "Failed to load log stream.")
		return nil, grpcutil.Internal
	}

	// The log stream and state loaded successfully.
	resp := logdog.LoadStreamResponse{
		State: buildLogStreamState(ls, lst),
	}
	if req.Desc {
		resp.Desc = ls.Descriptor
	}
	resp.ArchivalKey = lst.ArchivalKey
	resp.Age = google.NewDuration(ds.RoundTime(clock.Now(c)).Sub(lst.Updated))

	log.Fields{
		"id":              lst.ID(),
		"terminalIndex":   resp.State.TerminalIndex,
		"archived":        resp.State.Archived,
		"purged":          resp.State.Purged,
		"age":             google.DurationFromProto(resp.Age),
		"archivalKeySize": len(resp.ArchivalKey),
	}.Infof(c, "Successfully loaded log stream state.")
	return &resp, nil
}
729570
func (a *Adapter) Stream(logstream chan *router.Message) {
	for message := range logstream {
		m := &Message{message}
		buf, err := m.Render(a.tmpl)
		if err != nil {
			log.Println("syslog:", err)
			return
		}
		if _, err = a.conn.Write(buf); err != nil {
			log.Println("syslog:", err)
			switch a.conn.(type) {
			case *net.UDPConn:
				continue
			default:
				if err = a.retry(buf, err); err != nil {
					log.Panicf("syslog retry err: %+v", err)
					return
				}
			}
		}
	}
}
36237
func (c *Conn) NewStream() (inet.Stream, error) {
	ts, err := c.conn.OpenStream()
	if err != nil {
		return nil, err
	}
	return c.addStream(ts, inet.DirOutbound)
}