/** * For a given Enum type, creates an immutable map from each of the Enum's values to a * corresponding LockGraphNode, with the {@code allowedPriorLocks} and {@code * disallowedPriorLocks} prepopulated with nodes according to the natural ordering of the * associated Enum values. */ @VisibleForTesting static <E extends Enum<E>> Map<E, LockGraphNode> createNodes(Class<E> clazz) { EnumMap<E, LockGraphNode> map = Maps.newEnumMap(clazz); E[] keys = clazz.getEnumConstants(); final int numKeys = keys.length; ArrayList<LockGraphNode> nodes = Lists.newArrayListWithCapacity(numKeys); // Create a LockGraphNode for each enum value. for (E key : keys) { LockGraphNode node = new LockGraphNode(getLockName(key)); nodes.add(node); map.put(key, node); } // Pre-populate all allowedPriorLocks with nodes of smaller ordinal. for (int i = 1; i < numKeys; i++) { nodes.get(i).checkAcquiredLocks(Policies.THROW, nodes.subList(0, i)); } // Pre-populate all disallowedPriorLocks with nodes of larger ordinal. for (int i = 0; i < numKeys - 1; i++) { nodes.get(i).checkAcquiredLocks(Policies.DISABLED, nodes.subList(i + 1, numKeys)); } return Collections.unmodifiableMap(map); }
/** * For a given Enum type, creates an immutable map from each of the Enum's values to a * corresponding LockGraphNode, with the {@code allowedPriorLocks} and {@code * disallowedPriorLocks} prepopulated with nodes according to the natural ordering of the * associated Enum values. */ @VisibleForTesting static <E extends Enum<E>> Map<E, LockGraphNode> createNodes(Class<E> clazz) { EnumMap<E, LockGraphNode> map = Maps.newEnumMap(clazz); E[] keys = clazz.getEnumConstants(); final int numKeys = keys.length; ArrayList<LockGraphNode> nodes = Lists.newArrayListWithCapacity(numKeys); // Create a LockGraphNode for each enum value. for (E key : keys) { LockGraphNode node = new LockGraphNode(getLockName(key)); nodes.add(node); map.put(key, node); } // Pre-populate all allowedPriorLocks with nodes of smaller ordinal. for (int i = 1; i < numKeys; i++) { nodes.get(i).checkAcquiredLocks(Policies.THROW, nodes.subList(0, i)); } // Pre-populate all disallowedPriorLocks with nodes of larger ordinal. for (int i = 0; i < numKeys - 1; i++) { nodes.get(i).checkAcquiredLocks(Policies.DISABLED, nodes.subList(i + 1, numKeys)); } return Collections.unmodifiableMap(map); }
/** * For a given Enum type, creates an immutable map from each of the Enum's values to a * corresponding LockGraphNode, with the {@code allowedPriorLocks} and {@code * disallowedPriorLocks} prepopulated with nodes according to the natural ordering of the * associated Enum values. */ @VisibleForTesting static <E extends Enum<E>> Map<E, LockGraphNode> createNodes(Class<E> clazz) { EnumMap<E, LockGraphNode> map = Maps.newEnumMap(clazz); E[] keys = clazz.getEnumConstants(); final int numKeys = keys.length; ArrayList<LockGraphNode> nodes = Lists.newArrayListWithCapacity(numKeys); // Create a LockGraphNode for each enum value. for (E key : keys) { LockGraphNode node = new LockGraphNode(getLockName(key)); nodes.add(node); map.put(key, node); } // Pre-populate all allowedPriorLocks with nodes of smaller ordinal. for (int i = 1; i < numKeys; i++) { nodes.get(i).checkAcquiredLocks(Policies.THROW, nodes.subList(0, i)); } // Pre-populate all disallowedPriorLocks with nodes of larger ordinal. for (int i = 0; i < numKeys - 1; i++) { nodes.get(i).checkAcquiredLocks(Policies.DISABLED, nodes.subList(i + 1, numKeys)); } return Collections.unmodifiableMap(map); }
/** * Creates a {@link ReentrantReadWriteLock} with the given fairness policy. * The {@code lockName} is used in the warning or exception output to help * identify the locks involved in the detected deadlock. */ public ReentrantReadWriteLock newReentrantReadWriteLock( String lockName, boolean fair) { return policy == Policies.DISABLED ? new ReentrantReadWriteLock(fair) : new CycleDetectingReentrantReadWriteLock( new LockGraphNode(lockName), fair); }
/** * Creates a {@link ReentrantLock} with the given fairness policy. The * {@code lockName} is used in the warning or exception output to help * identify the locks involved in the detected deadlock. */ public ReentrantLock newReentrantLock(String lockName, boolean fair) { return policy == Policies.DISABLED ? new ReentrantLock(fair) : new CycleDetectingReentrantLock( new LockGraphNode(lockName), fair); }
/** * Creates a {@link ReentrantReadWriteLock} with the given fairness policy. * The {@code lockName} is used in the warning or exception output to help * identify the locks involved in the detected deadlock. */ public ReentrantReadWriteLock newReentrantReadWriteLock( String lockName, boolean fair) { return policy == Policies.DISABLED ? new ReentrantReadWriteLock(fair) : new CycleDetectingReentrantReadWriteLock( new LockGraphNode(lockName), fair); }
/** * Creates a {@link ReentrantReadWriteLock} with the given fairness policy. * The {@code lockName} is used in the warning or exception output to help * identify the locks involved in the detected deadlock. */ public ReentrantReadWriteLock newReentrantReadWriteLock( String lockName, boolean fair) { return policy == Policies.DISABLED ? new ReentrantReadWriteLock(fair) : new CycleDetectingReentrantReadWriteLock( new LockGraphNode(lockName), fair); }
/** * Creates a {@link ReentrantReadWriteLock} with the given fairness policy. * The {@code lockName} is used in the warning or exception output to help * identify the locks involved in the detected deadlock. */ public ReentrantReadWriteLock newReentrantReadWriteLock( String lockName, boolean fair) { return policy == Policies.DISABLED ? new ReentrantReadWriteLock(fair) : new CycleDetectingReentrantReadWriteLock( new LockGraphNode(lockName), fair); }
/** * Creates a {@link ReentrantLock} with the given fairness policy. The * {@code lockName} is used in the warning or exception output to help * identify the locks involved in the detected deadlock. */ public ReentrantLock newReentrantLock(String lockName, boolean fair) { return policy == Policies.DISABLED ? new ReentrantLock(fair) : new CycleDetectingReentrantLock( new LockGraphNode(lockName), fair); }
/** * Creates a {@link ReentrantLock} with the given fairness policy. The * {@code lockName} is used in the warning or exception output to help * identify the locks involved in the detected deadlock. */ public ReentrantLock newReentrantLock(String lockName, boolean fair) { return policy == Policies.DISABLED ? new ReentrantLock(fair) : new CycleDetectingReentrantLock( new LockGraphNode(lockName), fair); }
/** * Creates a {@link ReentrantReadWriteLock} with the given fairness policy. * The {@code lockName} is used in the warning or exception output to help * identify the locks involved in the detected deadlock. */ public ReentrantReadWriteLock newReentrantReadWriteLock( String lockName, boolean fair) { return policy == Policies.DISABLED ? new ReentrantReadWriteLock(fair) : new CycleDetectingReentrantReadWriteLock( new LockGraphNode(lockName), fair); }
/** * Creates a {@link ReentrantLock} with the given fairness policy. The {@code lockName} is used in * the warning or exception output to help identify the locks involved in the detected deadlock. */ public ReentrantLock newReentrantLock(String lockName, boolean fair) { return policy == Policies.DISABLED ? new ReentrantLock(fair) : new CycleDetectingReentrantLock(new LockGraphNode(lockName), fair); }
/** * Creates a {@link ReentrantReadWriteLock} with the given fairness policy. * The {@code lockName} is used in the warning or exception output to help * identify the locks involved in the detected deadlock. */ public ReentrantReadWriteLock newReentrantReadWriteLock( String lockName, boolean fair) { return policy == Policies.DISABLED ? new ReentrantReadWriteLock(fair) : new CycleDetectingReentrantReadWriteLock( new LockGraphNode(lockName), fair); }
/** * Creates a {@link ReentrantLock} with the given fairness policy. The * {@code lockName} is used in the warning or exception output to help * identify the locks involved in the detected deadlock. */ public ReentrantLock newReentrantLock(String lockName, boolean fair) { return policy == Policies.DISABLED ? new ReentrantLock(fair) : new CycleDetectingReentrantLock( new LockGraphNode(lockName), fair); }
/** * Creates a {@link ReentrantLock} with the given fairness policy. The {@code lockName} is used in * the warning or exception output to help identify the locks involved in the detected deadlock. */ public ReentrantLock newReentrantLock(String lockName, boolean fair) { return policy == Policies.DISABLED ? new ReentrantLock(fair) : new CycleDetectingReentrantLock(new LockGraphNode(lockName), fair); }
/** * Creates a {@link ReentrantReadWriteLock} with the given fairness policy. The {@code lockName} * is used in the warning or exception output to help identify the locks involved in the detected * deadlock. */ public ReentrantReadWriteLock newReentrantReadWriteLock(String lockName, boolean fair) { return policy == Policies.DISABLED ? new ReentrantReadWriteLock(fair) : new CycleDetectingReentrantReadWriteLock(new LockGraphNode(lockName), fair); }
/** * Creates a {@link ReentrantReadWriteLock} with the given fairness policy. The {@code lockName} * is used in the warning or exception output to help identify the locks involved in the detected * deadlock. */ public ReentrantReadWriteLock newReentrantReadWriteLock(String lockName, boolean fair) { return policy == Policies.DISABLED ? new ReentrantReadWriteLock(fair) : new CycleDetectingReentrantReadWriteLock(new LockGraphNode(lockName), fair); }
/** * Creates a {@link ReentrantLock} with the given fairness policy. The {@code lockName} is used in * the warning or exception output to help identify the locks involved in the detected deadlock. */ public ReentrantLock newReentrantLock(String lockName, boolean fair) { return policy == Policies.DISABLED ? new ReentrantLock(fair) : new CycleDetectingReentrantLock(new LockGraphNode(lockName), fair); }
/** * Creates a {@link ReentrantLock} with the given fairness policy. The {@code lockName} is used in * the warning or exception output to help identify the locks involved in the detected deadlock. */ public ReentrantLock newReentrantLock(String lockName, boolean fair) { return policy == Policies.DISABLED ? new ReentrantLock(fair) : new CycleDetectingReentrantLock(new LockGraphNode(lockName), fair); }
/** * Creates a {@link ReentrantReadWriteLock} with the given fairness policy. The {@code lockName} * is used in the warning or exception output to help identify the locks involved in the detected * deadlock. */ public ReentrantReadWriteLock newReentrantReadWriteLock(String lockName, boolean fair) { return policy == Policies.DISABLED ? new ReentrantReadWriteLock(fair) : new CycleDetectingReentrantReadWriteLock(new LockGraphNode(lockName), fair); }