/** {@inheritDoc} */ @Override public synchronized boolean replace(K key, V oldVal, V newVal) { return super.replace(key, oldVal, newVal); }
/** {@inheritDoc} */ @Override public synchronized V replace(K key, V val) { return super.replace(key, val); }
public boolean replace(final K key, final V oldValue, final V newValue) { return backingMap.replace(key, oldValue, newValue); }
public V replace(final K key, final V value) { return backingMap.replace(key, value); }
/** * If {@code (key, expectedOldValue)} is currently in the map, this method replaces {@code * expectedOldValue} with {@code newValue} and returns true; otherwise, this method returns false. * * <p>If {@code expectedOldValue} is zero, this method will succeed if {@code (key, zero)} is * currently in the map, or if {@code key} is not in the map at all. */ boolean replace(K key, long expectedOldValue, long newValue) { if (expectedOldValue == 0L) { return putIfAbsent(key, newValue) == 0L; } else { return map.replace(key, expectedOldValue, newValue); } } }
void updateTaskAttempt(TezTaskAttemptID attemptId, boolean isGuaranteed) { Boolean oldVal = tasks.replace(attemptId, isGuaranteed); if (oldVal == null) { LOG.warn("Task " + attemptId + " is no longer registered"); tasks.remove(attemptId); } }
/** * If {@code (key, expectedOldValue)} is currently in the map, this method replaces {@code * expectedOldValue} with {@code newValue} and returns true; otherwise, this method returns false. * * <p>If {@code expectedOldValue} is zero, this method will succeed if {@code (key, zero)} is * currently in the map, or if {@code key} is not in the map at all. */ boolean replace(K key, long expectedOldValue, long newValue) { if (expectedOldValue == 0L) { return putIfAbsent(key, newValue) == 0L; } else { return map.replace(key, expectedOldValue, newValue); } } }
private void addMethodTime(Method method, long timeTaken) { String methodStr = getMethodString(method); while (true) { Long curTime = metaCallTimeMap.get(methodStr), newTime = timeTaken; if (curTime != null && metaCallTimeMap.replace(methodStr, curTime, newTime + curTime)) break; if (curTime == null && (null == metaCallTimeMap.putIfAbsent(methodStr, newTime))) break; } }
/** * Resets (reloads) the properties for a specified subdomain. * * @param subdomain the subdomain of the service to reload properties for. */ public static void refreshProperties(String subdomain) { propertyMaps.replace(subdomain, new MUCServiceProperties(subdomain)); }
/** * If {@code key} is not already associated with a value or if {@code key} is associated with * zero, associate it with {@code newValue}. Returns the previous value associated with * {@code key}, or zero if there was no mapping for {@code key}. */ long putIfAbsent(K key, long newValue) { for (; ; ) { AtomicLong atomic = map.get(key); if (atomic == null) { atomic = map.putIfAbsent(key, new AtomicLong(newValue)); if (atomic == null) { return 0L; } // atomic is now non-null; fall through } long oldValue = atomic.get(); if (oldValue == 0L) { // don't compareAndSet a zero if (map.replace(key, atomic, new AtomicLong(newValue))) { return 0L; } // atomic replaced continue; } return oldValue; } }
/** * If {@code (key, expectedOldValue)} is currently in the map, this method replaces {@code * expectedOldValue} with {@code newValue} and returns true; otherwise, this method returns false. * * <p>If {@code expectedOldValue} is zero, this method will succeed if {@code (key, zero)} is * currently in the map, or if {@code key} is not in the map at all. */ boolean replace(K key, long expectedOldValue, long newValue) { if (expectedOldValue == 0L) { return putIfAbsent(key, newValue) == 0L; } else { return map.replace(key, expectedOldValue, newValue); } } }
/** * If {@code key} is not already associated with a value or if {@code key} is associated with * zero, associate it with {@code newValue}. Returns the previous value associated with {@code * key}, or zero if there was no mapping for {@code key}. */ long putIfAbsent(K key, long newValue) { while (true) { AtomicLong atomic = map.get(key); if (atomic == null) { atomic = map.putIfAbsent(key, new AtomicLong(newValue)); if (atomic == null) { return 0L; } // atomic is now non-null; fall through } long oldValue = atomic.get(); if (oldValue == 0L) { // don't compareAndSet a zero if (map.replace(key, atomic, new AtomicLong(newValue))) { return 0L; } // atomic replaced continue; } return oldValue; } }
void stepped(int chunk) { assert (_trainer != null) == _key.home(); if( _trainer != null ) _trainer._counts.incrementAndGet(chunk); else { for( ;; ) { Integer n = _counters.get(chunk); if( n == null ) { if( _counters.putIfAbsent(chunk, 1) == null ) break; } else { if( _counters.replace(chunk, n, n + 1) ) break; } } } }
@Override public V replace(K key, V value) { V priorValue = super.replace(key, value); if (priorValue != null) { syncGroups(value, VALUES, ADD); syncGroups(priorValue, VALUES, REMOVE); } return priorValue; }
@Override public boolean replace(K key, V oldValue, V newValue) { boolean replaced = super.replace(key, oldValue, newValue); if (replaced) { syncGroups(oldValue, VALUES, REMOVE); syncGroups(newValue, VALUES, ADD); } return replaced; }
protected void setPublicKey(byte[] publickey, InternalDistributedMember mbr) { try { memberToPublicKey.put(new InternalDistributedMemberWrapper(mbr), publickey); peerEncryptors.replace(mbr, new GMSEncryptionCipherPool(this, generateSecret(publickey))); } catch (Exception e) { throw new RuntimeException("Unable to create peer encryptor " + mbr, e); } }
if(value==null ? core.putIfAbsent(key,l)!=null : !core.replace(key,value,l)) {
@Override public long release( long id, TransactionHandle transactionHandle ) { TransactionMarker marker = registry.get( id ); if ( null == marker ) { throw new IllegalStateException( "Trying to suspend unregistered transaction" ); } if ( marker.isSuspended() ) { throw new IllegalStateException( "Trying to suspend transaction that was already suspended" ); } SuspendedTransaction suspendedTx = new SuspendedTransaction( marker.getActiveTransaction(), transactionHandle ); if ( !registry.replace( id, marker, suspendedTx ) ) { throw new IllegalStateException( "Trying to suspend transaction that has been concurrently suspended" ); } return computeNewExpiryTime( suspendedTx.getLastActiveTimestamp() ); }
@Override public TransactionHandle acquire( long id ) throws TransactionLifecycleException { TransactionMarker marker = registry.get( id ); if ( null == marker ) { throw new InvalidTransactionId(); } SuspendedTransaction transaction = marker.getSuspendedTransaction(); if ( registry.replace( id, marker, marker.getActiveTransaction() ) ) { return transaction.transactionHandle; } else { throw new InvalidConcurrentTransactionAccess(); } }
@Override public TransactionHandle terminate( long id ) throws TransactionLifecycleException { TransactionMarker marker = registry.get( id ); if ( null == marker ) { throw new InvalidTransactionId(); } TransactionTerminationHandle handle = marker.getActiveTransaction().getTerminationHandle(); handle.terminate(); try { SuspendedTransaction transaction = marker.getSuspendedTransaction(); if ( registry.replace( id, marker, marker.getActiveTransaction() ) ) { return transaction.transactionHandle; } } catch ( InvalidConcurrentTransactionAccess exception ) { // We could not acquire the transaction. Let the other request clean up. } return null; }