List of usage examples for java.util.concurrent.locks Lock lock
lock
From source file:org.codehaus.wadi.location.partitionmanager.local.BasicLocalPartition.java
public void onMessage(Envelope message, EvacuateIMToPM request) { Lock readLock = readWriteLock.readLock(); readLock.lock(); try {/* w ww . jav a 2 s . c o m*/ LocalPartitionEvacuateIMToPMAction action = new LocalPartitionEvacuateIMToPMAction(dispatcher, nameToLocation, log); action.onMessage(message, request); } finally { readLock.unlock(); } }
From source file:com.ignorelist.kassandra.steam.scraper.FileCache.java
@Override public InputStream getIfPresent(Object key) { final Lock readLock = stripedLock.get(key).readLock(); readLock.lock(); try {/* w w w . j a v a 2s . c o m*/ return getIfPresentNonBlocking(key); } finally { readLock.unlock(); } }
From source file:com.ignorelist.kassandra.steam.scraper.FileCache.java
@Override public void put(String key, InputStream value) { final Lock writeLock = stripedLock.get(key).writeLock(); writeLock.lock(); try {//ww w. j a v a 2 s . c om putNonBlocking(key, value); } catch (IOException ex) { Logger.getLogger(FileCache.class.getName()).log(Level.SEVERE, null, ex); } finally { writeLock.unlock(); } }
From source file:gridool.db.sql.ParallelSQLExecJob.java
private static String invokeCsvOutputReduce(final Connection conn, final String reduceQuery, final String outputTableName, final ReadWriteLock rwlock, final Timings timings) throws GridException { File colDir = GridUtils.getWorkDir(true); final File outFile = new File(colDir, outputTableName + ".csv"); final CsvWriter writer = new CsvWriter(outFile); final MutableBoolean first = new MutableBoolean(true); final MutableLong ansGenStart = new MutableLong(-1L); final ResultSetHandler rsh = new ResultSetHandler() { public Object handle(ResultSet rs) throws SQLException { if (first.getBoolean()) { ansGenStart.setValue(System.currentTimeMillis()); first.setBoolean(false); }/* ww w .j a v a 2 s .c om*/ int numRows = writer.writeAll(rs, MONETDB_NULL_STRING, false); if (LOG.isInfoEnabled()) { LOG.info("Result row count: " + numRows); } return null; } }; if (LOG.isInfoEnabled()) { LOG.info("Executing a Reduce SQL query: \n" + reduceQuery); } final Lock rlock = rwlock.readLock(); try { rlock.lock(); conn.setReadOnly(true); JDBCUtils.query(conn, reduceQuery, rsh); } catch (SQLException e) { String errmsg = "failed running a reduce query: " + reduceQuery; LOG.error(errmsg, e); try { conn.rollback(); } catch (SQLException rbe) { LOG.warn("Rollback failed", rbe); } throw new GridException(errmsg, e); } finally { rlock.unlock(); writer.close(); } long answerGenStart = ansGenStart.getValue(); long answerGenTime = (answerGenStart == -1L) ? 0L : System.currentTimeMillis() - answerGenStart; timings.setAnswerGenerationTime(answerGenTime); if (!outFile.exists()) { throw new IllegalStateException("Output file does not exist:" + outFile.getAbsolutePath()); } return outFile.getAbsolutePath(); }
From source file:net.sf.fakenames.fddemo.BaseDirLayout.java
public MountInfo.Mount getFs(long dev_t) { final Lock lock = mountInfo.getLock(); lock.lock(); try {/*from w ww . j av a2 s.c o m*/ return mountInfo.mountMap.get(dev_t); } finally { lock.unlock(); } }
From source file:de.taimos.daemon.spring.SpringDaemonAdapter.java
@Override public final void doStop() throws Exception { try {//from ww w.j a va 2s.c om this.doBeforeSpringStop(); } catch (Exception e) { throw new RuntimeException("Before spring stop failed", e); } Lock writeLock = this.rwLock.writeLock(); try { writeLock.lock(); if (this.context.get() == null) { throw new RuntimeException("Not yet started"); } this.context.get().stop(); this.context.get().close(); this.context.set(null); } catch (Exception e) { throw new RuntimeException("spring stop failed", e); } finally { writeLock.unlock(); } try { this.doAfterSpringStop(); } catch (Exception e) { throw new RuntimeException("After spring stop failed", e); } super.doStop(); }
From source file:be.fgov.kszbcss.rhq.websphere.connector.security.TrustStoreManager.java
public void execute(TrustStoreAction action, boolean readOnly) throws Exception { Lock lock = readOnly ? truststoreLock.readLock() : truststoreLock.writeLock(); lock.lock(); try {/*from w ww . j ava 2 s .c o m*/ KeyStore truststore = loadTrustStore(); action.execute(truststore); if (!readOnly) { if (log.isDebugEnabled()) { log.debug("Writing trust store with " + truststore.size() + " entries to " + truststoreFile); } OutputStream out = new FileOutputStream(truststoreFile); try { truststore.store(out, new char[0]); } finally { out.close(); } reloadTrustManager(); } } finally { lock.unlock(); } }
From source file:org.mule.transport.ConcurrentWorkTracker.java
public void addWork(Runnable work) { Lock lock = registryLock.writeLock(); try {//from w w w . j ava2 s . c om if (logger.isDebugEnabled()) { logger.debug("Tracking work: " + work); } lock.lock(); works.add(work); } finally { lock.unlock(); } }
From source file:edu.internet2.middleware.shibboleth.common.relyingparty.provider.SAMLMDRelyingPartyConfigurationManager.java
/** {@inheritDoc} */ public RelyingPartyConfiguration getAnonymousRelyingConfiguration() { Lock readLock = getReadWriteLock().readLock(); readLock.lock(); try {// ww w .java2 s .com return rpConfigs.get(ANONYMOUS_RP_NAME); } finally { readLock.unlock(); } }
From source file:edu.internet2.middleware.shibboleth.common.relyingparty.provider.SAMLMDRelyingPartyConfigurationManager.java
/** {@inheritDoc} */ public RelyingPartyConfiguration getDefaultRelyingPartyConfiguration() { Lock readLock = getReadWriteLock().readLock(); readLock.lock(); try {/* w w w . ja v a 2 s. c om*/ return rpConfigs.get(DEFAULT_RP_NAME); } finally { readLock.unlock(); } }