| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package bundler | 5 package bundler |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "container/heap" | 8 "container/heap" |
| 9 "fmt" | 9 "fmt" |
| 10 "sync" | 10 "sync" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // Config is the Bundler configuration. | 23 // Config is the Bundler configuration. |
| 24 type Config struct { | 24 type Config struct { |
| 25 // Clock is the clock instance that will be used for Bundler and stream | 25 // Clock is the clock instance that will be used for Bundler and stream |
| 26 // timing. | 26 // timing. |
| 27 Clock clock.Clock | 27 Clock clock.Clock |
| 28 | 28 |
| 29 // Project is the project to use. | 29 // Project is the project to use. |
| 30 Project config.ProjectName | 30 Project config.ProjectName |
| 31 // Prefix is the common prefix for this set of streams. | 31 // Prefix is the common prefix for this set of streams. |
| 32 Prefix types.StreamName | 32 Prefix types.StreamName |
| 33 // Secret is the prefix secret for this set of streams. | |
| 34 Secret []byte | |
| 35 | 33 |
| 36 // MaxBufferedBytes is the maximum number of bytes to buffer in memory p
er | 34 // MaxBufferedBytes is the maximum number of bytes to buffer in memory p
er |
| 37 // stream. | 35 // stream. |
| 38 MaxBufferedBytes int64 | 36 MaxBufferedBytes int64 |
| 39 | 37 |
| 40 // MaxBundleSize is the maximum bundle size in bytes that may be generat
ed. | 38 // MaxBundleSize is the maximum bundle size in bytes that may be generat
ed. |
| 41 // | 39 // |
| 42 // If this value is zero, no size constraint will be applied to generate
d | 40 // If this value is zero, no size constraint will be applied to generate
d |
| 43 // bundles. | 41 // bundles. |
| 44 MaxBundleSize int | 42 MaxBundleSize int |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 } | 183 } |
| 186 }() | 184 }() |
| 187 | 185 |
| 188 for { | 186 for { |
| 189 bb = &builder{ | 187 bb = &builder{ |
| 190 size: b.c.MaxBundleSize, | 188 size: b.c.MaxBundleSize, |
| 191 template: logpb.ButlerLogBundle{ | 189 template: logpb.ButlerLogBundle{ |
| 192 Timestamp: google.NewTimestamp(b.getClock().Now(
)), | 190 Timestamp: google.NewTimestamp(b.getClock().Now(
)), |
| 193 Project: string(b.c.Project), | 191 Project: string(b.c.Project), |
| 194 Prefix: string(b.c.Prefix), | 192 Prefix: string(b.c.Prefix), |
| 195 Secret: b.c.Secret, | |
| 196 }, | 193 }, |
| 197 } | 194 } |
| 198 var oldestContentTime time.Time | 195 var oldestContentTime time.Time |
| 199 | 196 |
| 200 for { | 197 for { |
| 201 state := b.getStreamStateLocked() | 198 state := b.getStreamStateLocked() |
| 202 | 199 |
| 203 // Attempt to create more bundles. | 200 // Attempt to create more bundles. |
| 204 sendNow := b.bundleRoundLocked(bb, state) | 201 sendNow := b.bundleRoundLocked(bb, state) |
| 205 | 202 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 | 490 |
| 494 func (s *streamState) Push(x interface{}) { | 491 func (s *streamState) Push(x interface{}) { |
| 495 s.streams = append(s.streams, x.(bundlerStream)) | 492 s.streams = append(s.streams, x.(bundlerStream)) |
| 496 } | 493 } |
| 497 | 494 |
| 498 func (s *streamState) Pop() interface{} { | 495 func (s *streamState) Pop() interface{} { |
| 499 last := s.streams[len(s.streams)-1] | 496 last := s.streams[len(s.streams)-1] |
| 500 s.streams = s.streams[:len(s.streams)-1] | 497 s.streams = s.streams[:len(s.streams)-1] |
| 501 return last | 498 return last |
| 502 } | 499 } |
| OLD | NEW |