View Javadoc

1   package com.atlassian.vcache.internal.legacy;
2   
3   import java.time.Duration;
4   
5   import static java.util.Objects.requireNonNull;
6   
7   /**
8    * Builder for {@link LegacyServiceSettings} instances.
9    *
10   * @since 1.0
11   */
12  public class LegacyServiceSettingsBuilder {
13      private boolean avoidCasOps;
14      private boolean serializationHack;
15      @SuppressWarnings("checkstyle:MagicNumber")
16      private Duration lockTimeout = Duration.ofSeconds(30);
17  
18      /**
19       * Returns a new {@link LegacyServiceSettings} instance configured using the supplied settings.
20       *
21       * @return a new {@link LegacyServiceSettings} instance configured using the supplied settings.
22       */
23      public LegacyServiceSettings build() {
24          return new LegacyServiceSettings(avoidCasOps, serializationHack, lockTimeout);
25      }
26  
27      /**
28       * Enable avoiding the use of <tt>CAS-style</tt> operations. Really, really do not turn this setting on.
29       */
30      public LegacyServiceSettingsBuilder enableAvoidCasOperations() {
31          avoidCasOps = true;
32          return this;
33      }
34  
35      /**
36       * Enable the serialization hack, whereby if an {@link com.atlassian.vcache.ExternalCache}'s values are
37       * {@link java.io.Serializable}, then the values are not marshalled before they are passed to the delegate
38       * Atlassian Cache. This is to allow for performance optimisations.
39       */
40      public LegacyServiceSettingsBuilder enableSerializationHack() {
41          serializationHack = true;
42          return this;
43      }
44  
45      /**
46       * Change the timeout that is used when acquiring locks.
47       * @param lockTimeout the timeout that is used when acquiring locks.
48       * @return the current builder
49       */
50      public LegacyServiceSettingsBuilder lockTimeout(Duration lockTimeout) {
51          this.lockTimeout = requireNonNull(lockTimeout);
52          return this;
53      }
54  }