View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.named;
20  
21  import java.util.Collection;
22  import java.util.Collections;
23  
24  import static java.util.Objects.requireNonNull;
25  
26  /**
27   * A factory of {@link NamedLock}s.
28   */
29  public interface NamedLockFactory {
30      /**
31       * Creates or reuses existing {@link NamedLock}. Returns instance MUST BE treated as "resource", best in
32       * try-with-resource block.
33       *
34       * @param key the lock key, must not be {@code null}.
35       * @return named lock instance, never {@code null}.
36       */
37      default NamedLock getLock(NamedLockKey key) {
38          requireNonNull(key, "key");
39          return getLock(Collections.singleton(key));
40      }
41  
42      /**
43       * Creates or reuses existing {@link NamedLock}. Returns instance MUST BE treated as "resource", best in
44       * try-with-resource block.
45       *
46       * @param keys the lock keys, must not be {@code null} and must not be empty collection.
47       * @return named lock instance, never {@code null}.
48       * @since 2.0.0
49       */
50      NamedLock getLock(Collection<NamedLockKey> keys);
51  
52      /**
53       * Performs a clean shut down of the factory.
54       */
55      void shutdown();
56  
57      /**
58       * Method to notify factory about locking failure, to make it possible to provide more (factory specific)
59       * information about factory state when a locking operation failed. Factory may alter provided failure or
60       * provide information via some other side effect (for example via logging).
61       * <p>
62       * The default implementation merely does what happened before: adds no extra information.
63       *
64       * @since 1.9.11
65       */
66      default <E extends Throwable> E onFailure(E failure) {
67          return failure;
68      }
69  }