Java Code Examples for java.util.concurrent.locks.ReadWriteLock

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project azkaban, under directory /azkaban/src/java/azkaban/jobcontrol/impl/jobs/locks/.

Source file: ReadWriteLockManager.java

  22 
vote

public ReadWriteResourceLock getReadLock(Object resource){
  ReadWriteLock rwl=_readWriteLockMap.get(resource);
  if (rwl == null) {
    rwl=new ReentrantReadWriteLock(_isFair);
    _readWriteLockMap.put(resource,rwl);
  }
  return new ReadWriteResourceLock(resource,rwl,false);
}
 

Example 2

From project azkaban, under directory /azkaban/src/java/azkaban/jobcontrol/impl/jobs/locks/.

Source file: ReadWriteLockManager.java

  22 
vote

public ReadWriteResourceLock getWriteLock(Object resource){
  ReadWriteLock rwl=_readWriteLockMap.get(resource);
  if (rwl == null) {
    rwl=new ReentrantReadWriteLock(_isFair);
    _readWriteLockMap.put(resource,rwl);
  }
  return new ReadWriteResourceLock(resource,rwl,true);
}
 

Example 3

From project ha-jdbc, under directory /src/main/java/net/sf/hajdbc/lock/semaphore/.

Source file: SemaphoreLockManager.java

  22 
vote

private synchronized ReadWriteLock getReadWriteLock(String object){
  String key=(object != null) ? object : "";
  ReadWriteLock lock=this.lockMap.get(key);
  if (lock == null) {
    lock=new SemaphoreReadWriteLock(new Semaphore(Integer.MAX_VALUE,this.fair));
    ReadWriteLock existing=this.lockMap.putIfAbsent(key,lock);
    if (existing != null) {
      lock=existing;
    }
  }
  return lock;
}
 

Example 4

From project james-mailbox, under directory /store/src/main/java/org/apache/james/mailbox/store/.

Source file: JVMMailboxPathLocker.java

  22 
vote

/** 
 * @see org.apache.james.mailbox.store.AbstractMailboxPathLocker#lock(org.apache.james.mailbox.MailboxSession,org.apache.james.mailbox.model.MailboxPath,boolean)
 */
protected void lock(MailboxSession session,MailboxPath path,boolean writeLock) throws MailboxException {
  ReadWriteLock lock=paths.get(path);
  if (lock == null) {
    lock=new ReentrantReadWriteLock();
    ReadWriteLock storedLock=paths.putIfAbsent(path,lock);
    if (storedLock != null) {
      lock=storedLock;
    }
  }
  getLock(lock,writeLock).lock();
}
 

Example 5

From project james-mailbox, under directory /store/src/main/java/org/apache/james/mailbox/store/.

Source file: JVMMailboxPathLocker.java

  22 
vote

/** 
 * @see org.apache.james.mailbox.store.AbstractMailboxPathLocker#unlock(MailboxSession,MailboxPath,boolean)
 */
protected void unlock(MailboxSession session,MailboxPath path,boolean writeLock) throws MailboxException {
  ReadWriteLock lock=paths.get(path);
  if (lock != null) {
    getLock(lock,writeLock).unlock();
  }
}
 

Example 6

From project menagerie, under directory /src/test/java/org/menagerie/locks/.

Source file: ReentrantZkReadWriteLock2ReadLockTest.java

  22 
vote

@Test(timeout=1000l) public void testReadLockAcquiresThenReleases() throws Exception {
  ReadWriteLock rwLock=new ReentrantZkReadWriteLock2(baseLockPath,zkSessionManager);
  Lock readLock=rwLock.readLock();
  readLock.lock();
  try {
    assertEquals("A Read lock node was not created!",1,ZkUtils.filterByPrefix(zkSessionManager.getZooKeeper().getChildren(baseLockPath,false),"readLock").size());
  }
  finally {
    readLock.unlock();
  }
  assertEquals("A Read lock node was not deleted!",0,ZkUtils.filterByPrefix(zkSessionManager.getZooKeeper().getChildren(baseLockPath,false),"readLock").size());
}
 

Example 7

From project menagerie, under directory /src/test/java/org/menagerie/locks/.

Source file: ReentrantZkReadWriteLock2WriteLockTest.java

  22 
vote

@Test(timeout=1000l) public void testWriteLockCanDowngradeToReadLockIfOnSameThread() throws Exception {
  ReadWriteLock rwLock=new ReentrantZkReadWriteLock2(baseLockPath,zkSessionManager);
  Lock writeLock=rwLock.writeLock();
  writeLock.lock();
  Lock readLock=rwLock.readLock();
  boolean acquired=readLock.tryLock();
  assertTrue("read lock was not acquired!",acquired);
  writeLock.unlock();
  readLock.unlock();
}
 

Example 8

From project org.openscada.atlantis, under directory /org.openscada.ae.server.http/src/org/openscada/ae/server/http/filter/.

Source file: EventFilterImpl.java

  22 
vote

public EventFilterImpl(final BundleContext context,final String factoryId){
  final Dictionary<String,Object> properties=new Hashtable<String,Object>();
  properties.put(Constants.SERVICE_VENDOR,"TH4 SYSTEMS GmbH");
  properties.put(Constants.SERVICE_DESCRIPTION,"A configurable event filter");
  properties.put(ConfigurationAdministrator.FACTORY_ID,factoryId);
  this.handle=context.registerService(ConfigurationFactory.class,this,properties);
  final ReadWriteLock lock=new ReentrantReadWriteLock(false);
  this.readLock=lock.readLock();
  this.writeLock=lock.writeLock();
}
 

Example 9

From project org.openscada.aurora, under directory /org.openscada.sec.provider.script/src/org/openscada/sec/provider/script/.

Source file: ScriptAuthorizationProvider.java

  22 
vote

public ScriptAuthorizationProvider(){
  final ReadWriteLock lock=new ReentrantReadWriteLock();
  this.readLock=lock.readLock();
  this.writeLock=lock.writeLock();
  this.classLoader=getClass().getClassLoader();
  final ClassLoader currentClassLoader=Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(this.classLoader);
    this.manager=new ScriptEngineManager(this.classLoader);
  }
  finally {
    Thread.currentThread().setContextClassLoader(currentClassLoader);
  }
}
 

Example 10

From project rate-limit, under directory /src/main/java/com/eternus/ratelimit/.

Source file: MemoryTokenStore.java

  22 
vote

/** 
 * Creates a new  {@link MemoryTokenStore}.
 */
public MemoryTokenStore(){
  this.cache=new MapMaker().softValues().expiration(120,TimeUnit.SECONDS).makeMap();
  ReadWriteLock lock=new ReentrantReadWriteLock();
  this.r=lock.readLock();
  this.w=lock.writeLock();
}
 

Example 11

From project Solbase-Solr, under directory /src/java/org/apache/solr/update/.

Source file: DirectUpdateHandler2.java

  22 
vote

public DirectUpdateHandler2(SolrCore core) throws IOException {
  super(core);
  ReadWriteLock rwl=new ReentrantReadWriteLock();
  iwAccess=rwl.readLock();
  iwCommit=rwl.writeLock();
  tracker=new CommitTracker();
}
 

Example 12

From project dragon, under directory /hadoop-dragon-core/src/main/java/org/apache/hadoop/realtime/job/.

Source file: JobInAppMaster.java

  21 
vote

public JobInAppMaster(JobId jobId,Configuration conf,AppContext appContext){
  this.applicationAttemptId=appContext.getApplicationAttemptId();
  this.jobId=jobId;
  this.jobName=conf.get(DragonJobConfig.JOB_NAME,"<missing job name>");
  this.conf=new Configuration(conf);
  this.metrics=appContext.getMetrics();
  this.clock=appContext.getClock();
  this.amInfos=appContext.getAmInfos();
  this.appContext=appContext;
  this.userName=appContext.getUser();
  this.queueName=conf.get(DragonJobConfig.QUEUE_NAME,"default");
  this.appSubmitTime=appContext.getStartTime();
  this.eventHandler=appContext.getEventHandler();
  ReadWriteLock readWriteLock=new ReentrantReadWriteLock();
  this.readLock=readWriteLock.readLock();
  this.writeLock=readWriteLock.writeLock();
  this.fsTokens=appContext.getFsTokens();
  this.jobTokenSecretManager=appContext.getJobTokenSecretManager();
  this.username=conf.get(DragonJobConfig.USER_NAME);
  this.mapNumTasks=conf.getInt(DragonJobConfig.MAP_PARALLELISM,1);
  this.reduceNumTasks=conf.getInt(DragonJobConfig.REDUCE_PARALLELISM,1);
  stateMachine=stateMachineFactory.make(this);
}
 

Example 13

From project dragon, under directory /hadoop-dragon-core/src/main/java/org/apache/hadoop/realtime/job/.

Source file: TaskAttemptInAppMaster.java

  21 
vote

TaskAttemptInAppMaster(TaskId taskId,int attempt,EventHandler eventHandler,Path jobFile,int partition,Configuration conf,TaskType type,Token<JobTokenIdentifier> jobToken,Credentials credentials,Clock clock,AppContext appContext){
  this.attemptId=recordFactory.newRecordInstance(TaskAttemptId.class);
  this.attemptId.setTaskId(taskId);
  this.attemptId.setId(attempt);
  this.jobId=taskId.getJobId();
  this.conf=conf;
  this.type=type;
  this.jobFile=jobFile;
  this.partition=partition;
  this.appContext=appContext;
  this.reportedStatus=new TaskAttemptStatus();
  ReadWriteLock readWriteLock=new ReentrantReadWriteLock();
  readLock=readWriteLock.readLock();
  writeLock=readWriteLock.writeLock();
  this.credentials=credentials;
  this.jobToken=jobToken;
  this.eventHandler=eventHandler;
  this.clock=clock;
  this.resourceCapability=recordFactory.newRecordInstance(Resource.class);
  this.resourceCapability.setMemory(getMemoryRequired(conf));
  RackResolver.init(conf);
  stateMachine=stateMachineFactory.make(this);
}
 

Example 14

From project EMF-IncQuery, under directory /plugins/org.eclipse.viatra2.gtasm.patternmatcher.incremental.rete/src/org/eclipse/viatra2/gtasm/patternmatcher/incremental/rete/network/.

Source file: Network.java

  21 
vote

/** 
 * @param threads the number of threads to operate the network with; 0 means single-threaded operation,  1 starts an asynchronous thread to operate the RETE net,  >1 uses multiple RETE containers.
 */
public Network(int threads,IPatternMatcherRuntimeContext<?> context){
  super();
  this.threads=threads;
  this.context=context;
  containers=new ArrayList<ReteContainer>();
  firstContainer=(threads > 1) ? Options.firstFreeContainer : 0;
  nextContainer=firstContainer;
  if (threads > 0) {
    globalTerminationCriteria=new HashMap<ReteContainer,Long>();
    reportedClocks=new HashMap<ReteContainer,Long>();
    ReadWriteLock rwl=new ReentrantReadWriteLock();
    updateLock=rwl.readLock();
    structuralChangeLock=rwl.writeLock();
    for (int i=0; i < threads; ++i)     containers.add(new ReteContainer(this,true));
  }
 else   containers.add(new ReteContainer(this,false));
  headContainer=containers.get(0);
}
 

Example 15

From project CalendarPortlet, under directory /src/main/java/org/jasig/portlet/calendar/spring/.

Source file: DoubleCheckedCreator.java

  19 
vote

public DoubleCheckedCreator(ReadWriteLock readWriteLock){
  Validate.notNull(readWriteLock,"readWriteLock can not be null");
  this.readWriteLock=readWriteLock;
  this.readLock=this.readWriteLock.readLock();
  this.writeLock=this.readWriteLock.writeLock();
}
 

Example 16

From project hank, under directory /src/java/com/rapleaf/hank/loadtest/.

Source file: RandomSaturator.java

  19 
vote

public LoadThread(HankSmartClient client,String domainName,int threadNum,int numReqs,int keyLength,ReadWriteLock lock) throws Exception {
  super("LoadThread #" + threadNum);
  this.domainName=domainName;
  this.numReqs=numReqs;
  this.keyLength=keyLength;
  this.lock=lock;
  this.client=client;
}
 

Example 17

From project NewsReaderPortlet, under directory /src/main/java/org/jasig/portlet/newsreader/spring/.

Source file: DoubleCheckedCreator.java

  19 
vote

public DoubleCheckedCreator(ReadWriteLock readWriteLock){
  Validate.notNull(readWriteLock,"readWriteLock can not be null");
  this.readWriteLock=readWriteLock;
  this.readLock=this.readWriteLock.readLock();
  this.writeLock=this.readWriteLock.writeLock();
}
 

Example 18

From project SpoutAPI, under directory /src/main/java/org/spout/api/util/map/concurrent/.

Source file: TSyncIntIntHashMap.java

  19 
vote

/** 
 * Creates a synchronised map based on the Trove int object map
 * @param mapCount the number of sub-maps
 * @param initialCapacity the initial capacity of the map
 * @param loadFactor the load factor for the map
 * @param noEntryKey the key used to indicate a null key
 * @param noEntryValue the value used to indicate a null value
 */
public TSyncIntIntHashMap(int mapCount,int initialCapacity,float loadFactor,int noEntryKey,int noEntryValue){
  if (mapCount > 0x100000) {
    throw new IllegalArgumentException("Map count exceeds valid range");
  }
  mapCount=MathHelper.roundUpPow2(mapCount);
  mapMask=mapCount - 1;
  this.mapCount=mapCount;
  this.hashScramble=(mapCount << 8) + 1;
  mapArray=new TIntIntHashMap[mapCount];
  lockArray=new ReadWriteLock[mapCount];
  for (int i=0; i < mapCount; i++) {
    mapArray[i]=new TIntIntHashMap(initialCapacity / mapCount,loadFactor,noEntryKey,noEntryValue);
    lockArray[i]=new ReentrantReadWriteLock();
  }
  this.noEntryKey=noEntryKey;
  this.noEntryValue=noEntryValue;
}
 

Example 19

From project SpoutAPI, under directory /src/main/java/org/spout/api/util/map/concurrent/.

Source file: TSyncIntObjectHashMap.java

  19 
vote

/** 
 * Creates a synchronised map based on the Trove int object map
 * @param mapCount the number of sub-maps
 * @param initialCapacity the initial capacity of the map
 * @param loadFactor the load factor for the map
 * @param noEntryKey the key used to indicate a null key
 */
@SuppressWarnings("unchecked") public TSyncIntObjectHashMap(int mapCount,int initialCapacity,float loadFactor,int noEntryKey){
  if (mapCount > 0x100000) {
    throw new IllegalArgumentException("Map count exceeds valid range");
  }
  mapCount=MathHelper.roundUpPow2(mapCount);
  mapMask=mapCount - 1;
  this.mapCount=mapCount;
  this.hashScramble=(mapCount << 8) + 1;
  mapArray=new TIntObjectHashMap[mapCount];
  lockArray=new ReadWriteLock[mapCount];
  for (int i=0; i < mapCount; i++) {
    mapArray[i]=new TIntObjectHashMap<V>(initialCapacity / mapCount,loadFactor,noEntryKey);
    lockArray[i]=new ReentrantReadWriteLock();
  }
  this.no_entry_key=noEntryKey;
}