Java 类java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock 实例源码

项目:fuck_zookeeper    文件:ZKDatabase.java   
/**
 * clear the zkdatabase. 
 * Note to developers - be careful to see that 
 * the clear method does clear out all the
 * data structures in zkdatabase.
 */
public void clear() {
    minCommittedLog = 0;
    maxCommittedLog = 0;
    /* to be safe we just create a new 
     * datatree.
     */
    dataTree = new DataTree();
    sessionsWithTimeouts.clear();
    WriteLock lock = logLock.writeLock();
    try {            
        lock.lock();
        committedLog.clear();
    } finally {
        lock.unlock();
    }
    initialized = false;
}
项目:k8s-proxy    文件:K8sReverseProxy.java   
@RequestMapping("/redirect_uri")
public void callback(@RequestParam String code, HttpServletRequest request, HttpServletResponse response)
        throws ClientProtocolException,
            IOException
{
    WriteLock writeLock = lock.writeLock();
    try {
        writeLock.lock();
        googleToken = googleTokenRetriever.postForRefreshAndAccessToken(code, request.getRequestURL().toString());

        jweToken = jweTokenRetriever.fetchJweToken(googleToken.getIdToken());

        try (PrintWriter out = new PrintWriter(REFRESH_TOKEN_FILENAME)) {
            out.println(googleToken.getRefreshToken());
        }
    } finally {
        writeLock.unlock();
    }

    scheduleRefreshTask(googleToken.getExpiresIn());

    response.sendRedirect(initialRedirect);
}
项目:k8s-proxy    文件:K8sReverseProxy.java   
@Override
public void run()
{
    GoogleIdAndRefreshToken newGoogleIdToken = null;
    WriteLock writeLock = lock.writeLock();
    try {
        newGoogleIdToken = googleTokenRetriever.refreshToken(googleToken.getRefreshToken());
        writeLock.lock();
        googleToken.setIdToken(newGoogleIdToken.getIdToken());

        jweToken = jweTokenRetriever.fetchJweToken(newGoogleIdToken.getIdToken());
    } catch (Throwable e) {
        logger.error("Error while refreshing the id token.", e);
    } finally {
        writeLock.unlock();
        scheduleRefreshTask(newGoogleIdToken == null ? DEFAULT_REFRESH_TASK_FREQUENCY_IN_SECONDS
                                                     : newGoogleIdToken.getExpiresIn());
    }
}
项目:https-github.com-apache-zookeeper    文件:ZKDatabase.java   
/**
 * clear the zkdatabase.
 * Note to developers - be careful to see that
 * the clear method does clear out all the
 * data structures in zkdatabase.
 */
public void clear() {
    minCommittedLog = 0;
    maxCommittedLog = 0;
    /* to be safe we just create a new
     * datatree.
     */
    dataTree = new DataTree();
    sessionsWithTimeouts.clear();
    WriteLock lock = logLock.writeLock();
    try {
        lock.lock();
        committedLog.clear();
    } finally {
        lock.unlock();
    }
    initialized = false;
}
项目:ZooKeeper    文件:ZKDatabase.java   
/**
 * clear the zkdatabase. 
 * Note to developers - be careful to see that 
 * the clear method does clear out all the
 * data structures in zkdatabase.
 */
public void clear() {
    minCommittedLog = 0;
    maxCommittedLog = 0;
    /* to be safe we just create a new 
     * datatree.
     */
    dataTree = new DataTree();
    sessionsWithTimeouts.clear();
    WriteLock lock = logLock.writeLock();
    try {            
        lock.lock();
        committedLog.clear();
    } finally {
        lock.unlock();
    }
    initialized = false;
}
项目:StreamProcessingInfrastructure    文件:ZKDatabase.java   
/**
 * clear the zkdatabase. 
 * Note to developers - be careful to see that 
 * the clear method does clear out all the
 * data structures in zkdatabase.
 */
public void clear() {
    minCommittedLog = 0;
    maxCommittedLog = 0;
    /* to be safe we just create a new 
     * datatree.
     */
    dataTree = new DataTree();
    sessionsWithTimeouts.clear();
    WriteLock lock = logLock.writeLock();
    try {            
        lock.lock();
        committedLog.clear();
    } finally {
        lock.unlock();
    }
    initialized = false;
}
项目:bigstreams    文件:ZKDatabase.java   
/**
 * clear the zkdatabase. 
 * Note to developers - be careful to see that 
 * the clear method does clear out all the
 * data structures in zkdatabase.
 */
public void clear() {
    minCommittedLog = 0;
    maxCommittedLog = 0;
    /* to be safe we just create a new 
     * datatree.
     */
    dataTree = new DataTree();
    sessionsWithTimeouts.clear();
    WriteLock lock = logLock.writeLock();
    try {            
        lock.lock();
        committedLog.clear();
    } finally {
        lock.unlock();
    }
    initialized = false;
}
项目:bigstreams    文件:ZKDatabase.java   
/**
 * clear the zkdatabase. 
 * Note to developers - be careful to see that 
 * the clear method does clear out all the
 * data structures in zkdatabase.
 */
public void clear() {
    minCommittedLog = 0;
    maxCommittedLog = 0;
    /* to be safe we just create a new 
     * datatree.
     */
    dataTree = new DataTree();
    sessionsWithTimeouts.clear();
    WriteLock lock = logLock.writeLock();
    try {            
        lock.lock();
        committedLog.clear();
    } finally {
        lock.unlock();
    }
    initialized = false;
}
项目:zookeeper-src-learning    文件:ZKDatabase.java   
/**
 * clear the zkdatabase. 
 * Note to developers - be careful to see that 
 * the clear method does clear out all the
 * data structures in zkdatabase.
 */
public void clear() {
    minCommittedLog = 0;
    maxCommittedLog = 0;
    /* to be safe we just create a new 
     * datatree.
     */
    dataTree = new DataTree();
    sessionsWithTimeouts.clear();
    WriteLock lock = logLock.writeLock();
    try {            
        lock.lock();
        committedLog.clear();
    } finally {
        lock.unlock();
    }
    initialized = false;
}
项目:zookeeper    文件:ZKDatabase.java   
/**
 * clear the zkdatabase. 
 * Note to developers - be careful to see that 
 * the clear method does clear out all the
 * data structures in zkdatabase.
 */
public void clear() {
    minCommittedLog = 0;
    maxCommittedLog = 0;
    /* to be safe we just create a new 
     * datatree.
     */
    dataTree = new DataTree();
    sessionsWithTimeouts.clear();
    WriteLock lock = logLock.writeLock();
    try {            
        lock.lock();
        committedLog.clear();
    } finally {
        lock.unlock();
    }
    initialized = false;
}
项目:SecureKeeper    文件:ZKDatabase.java   
/**
 * clear the zkdatabase.
 * Note to developers - be careful to see that
 * the clear method does clear out all the
 * data structures in zkdatabase.
 */
public void clear() {
    minCommittedLog = 0;
    maxCommittedLog = 0;
    /* to be safe we just create a new
     * datatree.
     */
    dataTree = new DataTree();
    sessionsWithTimeouts.clear();
    WriteLock lock = logLock.writeLock();
    try {
        lock.lock();
        committedLog.clear();
    } finally {
        lock.unlock();
    }
    initialized = false;
}
项目:SecureKeeper    文件:ZKDatabase.java   
/**
 * clear the zkdatabase.
 * Note to developers - be careful to see that
 * the clear method does clear out all the
 * data structures in zkdatabase.
 */
public void clear() {
    minCommittedLog = 0;
    maxCommittedLog = 0;
    /* to be safe we just create a new
     * datatree.
     */
    dataTree = new DataTree();
    sessionsWithTimeouts.clear();
    WriteLock lock = logLock.writeLock();
    try {
        lock.lock();
        committedLog.clear();
    } finally {
        lock.unlock();
    }
    initialized = false;
}
项目:StreamBench    文件:ZKDatabase.java   
/**
 * clear the zkdatabase. 
 * Note to developers - be careful to see that 
 * the clear method does clear out all the
 * data structures in zkdatabase.
 */
public void clear() {
    minCommittedLog = 0;
    maxCommittedLog = 0;
    /* to be safe we just create a new 
     * datatree.
     */
    dataTree = new DataTree();
    sessionsWithTimeouts.clear();
    WriteLock lock = logLock.writeLock();
    try {            
        lock.lock();
        committedLog.clear();
    } finally {
        lock.unlock();
    }
    initialized = false;
}
项目:ACaZoo    文件:ZKDatabase.java   
/**
 * clear the zkdatabase. Note to developers - be careful to see that the
 * clear method does clear out all the data structures in zkdatabase.
 */
public void clear() {
    minCommittedLog = 0;
    maxCommittedLog = 0;
    /*
     * to be safe we just create a new datatree.
     */
    dataTree = new DataTree();
    sessionsWithTimeouts.clear();
    WriteLock lock = logLock.writeLock();
    try {
        lock.lock();
        committedLog.clear();
    } finally {
        lock.unlock();
    }
    initialized = false;
}
项目:cloud-bigtable-client    文件:ReconnectingChannel.java   
@Override
public void close() throws IOException {
  CloseableChannel toClose = null;

  WriteLock writeLock = delegateLock.writeLock();
  writeLock.lock();
  try {
    toClose = delegate;
    delegate = null;
  } finally {
    writeLock.unlock();
  }
  if (toClose != null) {
    toClose.close();
  }
  synchronized (closingAsynchronously) {
    while (closingAsynchronously.get() > 0) {
      try {
        closingAsynchronously.wait(CLOSE_WAIT_TIME);
      } catch (InterruptedException ignored){
        // TODO(angusdavis): rework this to allow the thread
        // interrupted state to propagate.
      }
    }
  }
}
项目:hawkular-agent    文件:EndpointService.java   
/**
 * Remove resources matching the given {@code location} and all their direct and indirect descendant resources.
 *
 * Note that this method may block if a discovery scan is currently in progress. The removal will occur when
 * the discovery scan finishes - only then will this method return.
 *
 * @param location a location that can contain wildcards
 */
public void removeResources(L location) {
    status.assertRunning(getClass(), "removeResources()");
    try (S session = openSession()) {
        // we must not alter the resource manager while a discovery scan is in progress
        WriteLock lock = EndpointService.this.discoveryScanRWLock.writeLock();
        lock.lock();
        try {
            List<Resource<L>> removed = getResourceManager().removeResources(location,
                    session.getLocationResolver());
            inventoryListenerSupport.fireResourcesRemoved(removed);
        } finally {
            lock.unlock();
        }
    } catch (Exception e) {
        LOG.errorCouldNotAccess(this, e);
    }
}
项目:osgi-capability-collector    文件:AbstractCapabilityCollector.java   
/**
 * Closing the capability collector and frees up all resources. During the call of this method,
 * the tracker will be closed (and by closing the tracker, the consumer will be called with the
 * unsatisfied flag even if there are no requirements).
 */
public void close() {
  WriteLock writeLock = readWriteLock.writeLock();
  writeLock.lock();

  try {
    if (!opened) {
      throw new IllegalStateException(
          "Close was called on a Capability Collector that was already closed.");
    }
    opened = false;

    closeTracker();
    if (noItems()) {
      satisfied = false;
      notifyConsumer();
    }
  } finally {
    writeLock.unlock();
  }
}
项目:osgi-capability-collector    文件:AbstractCapabilityCollector.java   
/**
 * Opens the capability collector. The tracker that is implemented by the subclass is also opened.
 */
public void open() {
  WriteLock writeLock = readWriteLock.writeLock();
  writeLock.lock();

  try {
    if (opened) {
      throw new IllegalStateException(
          "Open was called on a CapabilityCollector that was already opened.");
    }
    opened = true;

    if (noItems()) {
      this.satisfied = true;
    }
    notifyConsumer();
    openTracker();
  } finally {
    writeLock.unlock();
  }
}
项目:bigbase    文件:OffHeapCache.java   
/**
 * Execute operation with in-memory data update.
 *
 * @param key the key
 * @param op the op
 * @return the for update
 * @throws NativeMemoryException the j emalloc exception
 * @throws IOException Signals that an I/O exception has occurred.
 */

public boolean executeForUpdate(ByteBuffer key, Command<?> op) throws NativeMemoryException, IOException
{
    SpinReadWriteLock lock = getLockForKey(key);        

    WriteLock writeLock = null;

    if(lock != null){
        writeLock = lock.writeLock();       
        writeLock.lock();
    }

    try{
        return op.execute(key, this);

    }finally{
        if(writeLock != null) writeLock.unlock();
    }

}
项目:bigbase    文件:OffHeapCache.java   
private boolean touch(ByteBuffer key, long bufPtr) {
  key.position(0);
  int index = Math.abs(Utils.hash_murmur3(key, 4, key.getInt(), 0)) % mBucketNumber;

  // Get Bucket Read Lock
  SpinReadWriteLock lock = getLock(index);
  WriteLock writeLock = null;
  if(lock != null){
    writeLock = lock.writeLock();
    writeLock.lock();
  }
  try{
    long ptr = IOUtils.getLong(mMemPointer, ((long)index) * 8);
    if(ptr == 0){
      return false;
    } else{       
      long resultPtr = getPtr(bufPtr, getRealAddress(ptr));
      if(resultPtr == 0) return false;
      mEvictionAlgo.hitEntry(resultPtr, lock != null? lock.getSpinLock(): null);
      return true;
    }
  }finally{
    if(writeLock != null) writeLock.unlock();

  }
}
项目:bigbase    文件:OffHeapCache.java   
/**
 * Removes the value.
 *
 * @param key the key
 * @return the object
 * @throws NativeMemoryException the native memory exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
public Object removeValue(Object key) throws NativeMemoryException, IOException
{
    ReentrantReadWriteLock lock = getLockForKey(key);
    WriteLock writeLock = null;
    if(lock != null){
        writeLock = lock.writeLock();
        writeLock.lock();
    }

    try{
        Object value = get(key);            
        if(value == null) return null;
        remove(key);
        return value;
    }finally{
        if(writeLock != null) writeLock.unlock();
    }

}
项目:fabric8poc    文件:ProfileRegistry.java   
LockHandle aquireWriteLock(VersionIdentity version) {
    final WriteLock writeLock = readWriteLock.writeLock();
    boolean success;
    try {
        success = writeLock.tryLock() || writeLock.tryLock(10, TimeUnit.SECONDS);
    } catch (InterruptedException ex) {
        success = false;
    }
    IllegalStateAssertion.assertTrue(success, "Cannot obtain profile write lock in time for: " + version);
    return new LockHandle() {
        @Override
        public void unlock() {
            writeLock.unlock();
        }
    };
}
项目:fabric8poc    文件:AgentTopologyMBean.java   
private LockHandle aquireWriteLock() {
    final WriteLock writeLock = readWriteLock.writeLock();
    boolean success;
    try {
        success = writeLock.tryLock() || writeLock.tryLock(100, TimeUnit.MILLISECONDS);
    } catch (InterruptedException ex) {
        success = false;
    }
    IllegalStateAssertion.assertTrue(success, "Cannot obtain topology write lock in time");
    return new LockHandle() {
        @Override
        public void unlock() {
            writeLock.unlock();
        }
    };
}
项目:incubator-blur    文件:StreamProcessor.java   
private <T> StreamWriter<T> getWriter(final ObjectOutputStream objectOutputStream) {
  final WriteLock writeLock = new ReentrantReadWriteLock(true).writeLock();
  return new StreamWriter<T>() {
    @Override
    public void write(T obj) throws IOException {
      writeLock.lock();
      try {
        objectOutputStream.writeObject(obj);
      } finally {
        writeLock.unlock();
      }
    }

    @Override
    public void write(Iterable<T> it) throws IOException {
      writeLock.lock();
      try {
        for (T t : it) {
          objectOutputStream.writeObject(t);
        }
      } finally {
        writeLock.unlock();
      }
    }
  };
}
项目:LoadBalanced_zk    文件:ZKDatabase.java   
/**
 * clear the zkdatabase. 
 * Note to developers - be careful to see that 
 * the clear method does clear out all the
 * data structures in zkdatabase.
 */
public void clear() {
    minCommittedLog = 0;
    maxCommittedLog = 0;
    /* to be safe we just create a new 
     * datatree.
     */
    dataTree = new DataTree();
    sessionsWithTimeouts.clear();
    WriteLock lock = logLock.writeLock();
    try {            
        lock.lock();
        committedLog.clear();
    } finally {
        lock.unlock();
    }
    initialized = false;
}
项目:LoadBalanced_zk    文件:ZKDatabase.java   
/**
 * clear the zkdatabase. 
 * Note to developers - be careful to see that 
 * the clear method does clear out all the
 * data structures in zkdatabase.
 */
public void clear() {
    minCommittedLog = 0;
    maxCommittedLog = 0;
    /* to be safe we just create a new 
     * datatree.
     */
    dataTree = new DataTree();
    sessionsWithTimeouts.clear();
    WriteLock lock = logLock.writeLock();
    try {            
        lock.lock();
        committedLog.clear();
    } finally {
        lock.unlock();
    }
    initialized = false;
}
项目:zookeeper.dsc    文件:ZKDatabase.java   
/**
 * clear the zkdatabase. 
 * Note to developers - be careful to see that 
 * the clear method does clear out all the
 * data structures in zkdatabase.
 */
public void clear() {
    minCommittedLog = 0;
    maxCommittedLog = 0;
    /* to be safe we just create a new 
     * datatree.
     */
    dataTree = new DataTree();
    sessionsWithTimeouts.clear();
    WriteLock lock = logLock.writeLock();
    try {            
        lock.lock();
        committedLog.clear();
    } finally {
        lock.unlock();
    }
    initialized = false;
}
项目:zookeeper-pkg    文件:ZKDatabase.java   
/**
 * clear the zkdatabase. 
 * Note to developers - be careful to see that 
 * the clear method does clear out all the
 * data structures in zkdatabase.
 */
public void clear() {
    minCommittedLog = 0;
    maxCommittedLog = 0;
    /* to be safe we just create a new 
     * datatree.
     */
    dataTree = new DataTree();
    sessionsWithTimeouts.clear();
    WriteLock lock = logLock.writeLock();
    try {            
        lock.lock();
        committedLog.clear();
    } finally {
        lock.unlock();
    }
    initialized = false;
}
项目:waqtsalat-eclipse-plugin    文件:WaqtSalatView.java   
@Override
public void propertyChange(PropertyChangeEvent event) {
    WriteLock writeLock = propertyChangeLock.writeLock();
    writeLock.lock();
    try {
        this.propertyChanded = true;
    } finally {
        writeLock.unlock();
    }
    updateCurrentDate(); // IMPORTANT : this method must be called first (the date must be updated first) !!!
    updateLabelSelectedTimezone();
    updatePrayInputs();
    triggerUpdatePrayTableFilters();
    if (praysTableViewer != null) {
        praysTableViewer.refresh();
    }
}
项目:fuck_zookeeper    文件:ZKDatabase.java   
/**
 * maintains a list of last <i>committedLog</i>
 *  or so committed requests. This is used for
 * fast follower synchronization.
 * @param request committed request
 */
public void addCommittedProposal(Request request) {
    WriteLock wl = logLock.writeLock();
    try {
        wl.lock();
        if (committedLog.size() > commitLogCount) {
            committedLog.removeFirst();
            minCommittedLog = committedLog.getFirst().packet.getZxid();
        }
        if (committedLog.size() == 0) {
            minCommittedLog = request.zxid;
            maxCommittedLog = request.zxid;
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
        try {
            request.hdr.serialize(boa, "hdr");
            if (request.txn != null) {
                request.txn.serialize(boa, "txn");
            }
            baos.close();
        } catch (IOException e) {
            LOG.error("This really should be impossible", e);
        }
        QuorumPacket pp = new QuorumPacket(Leader.PROPOSAL, request.zxid,
                baos.toByteArray(), null);
        Proposal p = new Proposal();
        p.packet = pp;
        p.request = request;
        committedLog.add(p);
        maxCommittedLog = p.packet.getZxid();
    } finally {
        wl.unlock();
    }
}
项目:https-github.com-apache-zookeeper    文件:ZKDatabase.java   
/**
 * maintains a list of last <i>committedLog</i>
 *  or so committed requests. This is used for
 * fast follower synchronization.
 * @param request committed request
 */
public void addCommittedProposal(Request request) {
    WriteLock wl = logLock.writeLock();
    try {
        wl.lock();
        if (committedLog.size() > commitLogCount) {
            committedLog.removeFirst();
            minCommittedLog = committedLog.getFirst().packet.getZxid();
        }
        if (committedLog.isEmpty()) {
            minCommittedLog = request.zxid;
            maxCommittedLog = request.zxid;
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
        try {
            request.getHdr().serialize(boa, "hdr");
            if (request.getTxn() != null) {
                request.getTxn().serialize(boa, "txn");
            }
            baos.close();
        } catch (IOException e) {
            LOG.error("This really should be impossible", e);
        }
        QuorumPacket pp = new QuorumPacket(Leader.PROPOSAL, request.zxid,
                baos.toByteArray(), null);
        Proposal p = new Proposal();
        p.packet = pp;
        p.request = request;
        committedLog.add(p);
        maxCommittedLog = p.packet.getZxid();
    } finally {
        wl.unlock();
    }
}
项目:AeroStory    文件:Channel.java   
public void closeAllMerchants() {
    WriteLock wlock = merchant_lock.writeLock();
    wlock.lock();
    try {
        final Iterator<HiredMerchant> hmit = hiredMerchants.values().iterator();
        while (hmit.hasNext()) {
            hmit.next().forceClose();
            hmit.remove();
        }
    } catch (Exception e) {
    } finally {
        wlock.unlock();
    }
}
项目:AeroStory    文件:Channel.java   
public void addHiredMerchant(int chrid, HiredMerchant hm) {
    WriteLock wlock = merchant_lock.writeLock();
    wlock.lock();
    try {
        hiredMerchants.put(chrid, hm);
    } finally {
        wlock.unlock();
    }
}
项目:AeroStory    文件:Channel.java   
public void removeHiredMerchant(int chrid) {
WriteLock wlock = merchant_lock.writeLock();
wlock.lock();
try {        
    hiredMerchants.remove(chrid);
} finally {
    wlock.unlock();
}
}
项目:ZooKeeper    文件:ZKDatabase.java   
/**
 * maintains a list of last <i>committedLog</i>
 *  or so committed requests. This is used for
 * fast follower synchronization.
 * @param request committed request
 */
public void addCommittedProposal(Request request) {
    WriteLock wl = logLock.writeLock();
    try {
        wl.lock();
        if (committedLog.size() > commitLogCount) {
            committedLog.removeFirst();
            minCommittedLog = committedLog.getFirst().packet.getZxid();
        }
        if (committedLog.size() == 0) {
            minCommittedLog = request.zxid;
            maxCommittedLog = request.zxid;
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
        try {
            request.hdr.serialize(boa, "hdr");
            if (request.txn != null) {
                request.txn.serialize(boa, "txn");
            }
            baos.close();
        } catch (IOException e) {
            LOG.error("This really should be impossible", e);
        }
        QuorumPacket pp = new QuorumPacket(Leader.PROPOSAL, request.zxid,
                baos.toByteArray(), null);
        Proposal p = new Proposal();
        p.packet = pp;
        p.request = request;
        committedLog.add(p);
        maxCommittedLog = p.packet.getZxid();
    } finally {
        wl.unlock();
    }
}
项目:diorite-configs-java8    文件:ActionsRegistry.java   
/**
 * Register own config action.
 *
 * @param action
 *         action to register.
 * @param priority
 *         priority of action.
 */
public static void registerAction(ConfigPropertyAction action, double priority)
{
    WriteLock writeLock = lock.writeLock();
    try
    {
        writeLock.lock();
        actions.add(new ConfigPropertyActionEntry(action, priority));
    }
    finally
    {
        writeLock.unlock();
    }
}
项目:BUbiNG    文件:ConcurrentCountingMap.java   
/** Adds a value to the counter associated with a given key.
 *
 * @param array a byte array.
 * @param offset the first valid byte in {@code array}.
 * @param length the number of valid elements in {@code array}.
 * @param delta a value to be added to the counter associated with the specified key.
 * @return the previous value of the counter associated with the specified key.
 */
public int addTo(final byte[] array, final int offset, final int length, final int delta) {
    final long hash = MurmurHash3.hash(array, offset, length);
    final WriteLock writeLock = lock[(int)(hash >>> shift)].writeLock();
    try {
        writeLock.lock();
        return stripe[(int)(hash >>> shift)].addTo(array, offset, length, hash, delta);
    }
    finally {
        writeLock.unlock();
    }
}
项目:BUbiNG    文件:ConcurrentCountingMap.java   
/** Sets the value associated with a given key.
 *
 * @param array a byte array.
 * @param offset the first valid byte in {@code array}.
 * @param length the number of valid elements in {@code array}.
 * @param value a value to be associated with the specified key.
 * @return the previous value of the counter associated with the specified key.
 */
public int put(final byte[] array, final int offset, final int length, final int value) {
    final long hash = MurmurHash3.hash(array, offset, length);
    final WriteLock writeLock = lock[(int)(hash >>> shift)].writeLock();
    try {
        writeLock.lock();
        return stripe[(int)(hash >>> shift)].put(array, offset, length, hash, value);
    }
    finally {
        writeLock.unlock();
    }
}
项目:StreamProcessingInfrastructure    文件:ZKDatabase.java   
/**
 * maintains a list of last <i>committedLog</i>
 *  or so committed requests. This is used for
 * fast follower synchronization.
 * @param request committed request
 */
public void addCommittedProposal(Request request) {
    WriteLock wl = logLock.writeLock();
    try {
        wl.lock();
        if (committedLog.size() > commitLogCount) {
            committedLog.removeFirst();
            minCommittedLog = committedLog.getFirst().packet.getZxid();
        }
        if (committedLog.size() == 0) {
            minCommittedLog = request.zxid;
            maxCommittedLog = request.zxid;
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
        try {
            request.hdr.serialize(boa, "hdr");
            if (request.txn != null) {
                request.txn.serialize(boa, "txn");
            }
            baos.close();
        } catch (IOException e) {
            LOG.error("This really should be impossible", e);
        }
        QuorumPacket pp = new QuorumPacket(Leader.PROPOSAL, request.zxid,
                baos.toByteArray(), null);
        Proposal p = new Proposal();
        p.packet = pp;
        p.request = request;
        committedLog.add(p);
        maxCommittedLog = p.packet.getZxid();
    } finally {
        wl.unlock();
    }
}
项目:metasfresh-webui-api    文件:Document.java   
public IAutoCloseable lockForWriting()
{
    // assume _lock is not null
    final WriteLock writeLock = _lock.writeLock();
    logger.debug("Acquiring write lock for {}: {}", this, writeLock);
    writeLock.lock();
    logger.debug("Acquired write lock for {}: {}", this, writeLock);

    return () -> {
        writeLock.unlock();
        logger.debug("Released write lock for {}: {}", this, writeLock);
    };
}