View Javadoc

1   package com.atlassian.vcache.internal.guava;
2   
3   import java.time.Duration;
4   
5   import static java.util.Objects.requireNonNull;
6   
7   /**
8    * Builder for {@link GuavaServiceSettings} instances.
9    *
10   * @since 1.0
11   */
12  public class GuavaServiceSettingsBuilder {
13      private boolean serializationHack;
14      @SuppressWarnings("checkstyle:MagicNumber")
15      private Duration lockTimeout = Duration.ofSeconds(30);
16  
17      /**
18       * Returns a new {@link GuavaServiceSettings} instance configured using the supplied settings.
19       *
20       * @return a new {@link GuavaServiceSettings} instance configured using the supplied settings.
21       */
22      public GuavaServiceSettings build() {
23          return new GuavaServiceSettings(serializationHack, lockTimeout);
24      }
25  
26      /**
27       * Enable the serialization hack, whereby if an {@link com.atlassian.vcache.ExternalCache}'s values are
28       * {@link java.io.Serializable}, then the values are not marshalled before they are passed to the delegate
29       * Guava Cache. This is to allow for performance optimisations.
30       */
31      public GuavaServiceSettingsBuilder enableSerializationHack() {
32          serializationHack = true;
33          return this;
34      }
35  
36      /**
37       * Change the timeout that is used when acquiring locks.
38       * @param lockTimeout the timeout that is used when acquiring locks.
39       * @return the current builder
40       */
41      public GuavaServiceSettingsBuilder lockTimeout(Duration lockTimeout) {
42          this.lockTimeout = requireNonNull(lockTimeout);
43          return this;
44      }
45  }