Class LocalBucketBuilder

java.lang.Object
io.github.bucket4j.local.LocalBucketBuilder

public class LocalBucketBuilder extends Object
This builder creates in-memory buckets (LockFreeBucket).
  • Constructor Details

    • LocalBucketBuilder

      public LocalBucketBuilder()
  • Method Details

    • addLimit

      public LocalBucketBuilder addLimit(Bandwidth bandwidth)
      Adds limited bandwidth for all buckets which will be constructed by this builder.
      Parameters:
      bandwidth - limitation
      Returns:
      this builder instance
    • addLimit

    • withNanosecondPrecision

      public LocalBucketBuilder withNanosecondPrecision()
      Specifies TimeMeter.SYSTEM_NANOTIME as time meter for buckets that will be created by this builder.
      Returns:
      this builder instance
    • withMillisecondPrecision

      public LocalBucketBuilder withMillisecondPrecision()
      Specifies TimeMeter.SYSTEM_MILLISECONDS as time meter for buckets that will be created by this builder.
      Returns:
      this builder instance
    • withCustomTimePrecision

      public LocalBucketBuilder withCustomTimePrecision(TimeMeter customTimeMeter)
      Specifies customTimeMeter time meter for buckets that will be created by this builder.
      Parameters:
      customTimeMeter - object which will measure time.
      Returns:
      this builder instance
    • withSynchronizationStrategy

      public LocalBucketBuilder withSynchronizationStrategy(SynchronizationStrategy synchronizationStrategy)
      Specifies synchronizationStrategy for buckets that will be created by this builder.
      Parameters:
      synchronizationStrategy - the strategy of synchronization which need to be applied to prevent data-races in multi-threading usage scenario.
      Returns:
      this builder instance
    • withListener

      public LocalBucketBuilder withListener(BucketListener listener)
      Specifies listener for buckets that will be created by this builder.
      Parameters:
      listener - the listener of bucket events.
      Returns:
      this builder instance
    • build

      public LocalBucket build()
      Constructs the bucket.
      Returns:
      the new bucket