Package com.netflix.curator.framework.recipes.locks

Examples of com.netflix.curator.framework.recipes.locks.InterProcessReadWriteLock


  //Get a reference to the lock
  //Needs to be synched in case new lock isn't yet stored
  //when another thread asks for the same lock
  private static synchronized InterProcessReadWriteLock getLock(String filename){
    //Lock container
    InterProcessReadWriteLock lock;
   
    //Check if the lock is already created and in the store
    //Otherwise generate a new lock and store it
    if(lockStore.containsKey(filename)){
      lock = lockStore.get(filename);
      logger.debug("Reused an old lock");
    }else{
      lock = new InterProcessReadWriteLock(ZKSynch.client,filename);
      lockStore.put(filename, lock);
      logger.debug("Made a new lock");
    }
   
    //Return the pointer to the lock
View Full Code Here


   
    //Sanitize the filename
    filename = "/" + filename;
   
    //Get the lock
    InterProcessReadWriteLock lock = getLock(filename);
   
    //Acquire/release the read/write lock based on parameters
    try{
      if(type == 'R'){
        if(op == 'A'){
          lock.readLock().acquire();
        }else{
          lock.readLock().release();
        }
      }else{
        if(op == 'A'){
          lock.writeLock().acquire();
        }else{
          lock.writeLock().release();
        }
      }
    }catch(Exception e){
      logger.error("Could not {} the specified {} lock",type,op);
      return false;
View Full Code Here

TOP

Related Classes of com.netflix.curator.framework.recipes.locks.InterProcessReadWriteLock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.