// Copyright 2017 The Nomulus Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package google.registry.request.lock; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Throwables.throwIfUnchecked; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Strings; import com.google.common.collect.ImmutableSortedSet; import com.google.common.util.concurrent.UncheckedExecutionException; import google.registry.model.server.Lock; import google.registry.util.AppEngineTimeLimiter; import google.registry.util.FormattingLogger; import google.registry.util.RequestStatusChecker; import java.util.HashSet; import java.util.Optional; import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; import javax.inject.Inject; import org.joda.time.Duration; /** Implementation of {@link LockHandler} that uses the datastore lock. */ public class LockHandlerImpl implements LockHandler { private static final long serialVersionUID = 6551645164118637767L; private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); /** Fudge factor to make sure we kill threads before a lock actually expires. */ private static final Duration LOCK_TIMEOUT_FUDGE = Duration.standardSeconds(5); @Inject RequestStatusChecker requestStatusChecker; @Inject public LockHandlerImpl() {} /** * Acquire one or more locks and execute a Void {@link Callable}. * *
Thread will be killed if it doesn't complete before the lease expires. * *
Note that locks are specific either to a given tld or to the entire system (in which case
* tld should be passed as null).
*
* @return whether all locks were acquired and the callable was run.
*/
@Override
public boolean executeWithLocks(
final Callable