List of usage examples for java.util.concurrent.locks Lock unlock
void unlock();
From source file:org.apache.hadoop.hbase.util.ConnectionCache.java
/** * Caller doesn't close the admin afterwards. * We need to manage it and close it properly. *//*from ww w. ja va 2 s . c o m*/ public Admin getAdmin() throws IOException { ConnectionInfo connInfo = getCurrentConnection(); if (connInfo.admin == null) { Lock lock = locker.acquireLock(getEffectiveUser()); try { if (connInfo.admin == null) { connInfo.admin = connInfo.connection.getAdmin(); } } finally { lock.unlock(); } } return connInfo.admin; }
From source file:org.codehaus.wadi.location.partitionmanager.local.BasicLocalPartition.java
public void onMessage(Envelope message, InsertIMToPM request) { Lock readLock = readWriteLock.readLock(); readLock.lock();// w w w .j av a 2s . com try { LocalPartitionInsertIMToPMAction action = new LocalPartitionInsertIMToPMAction(dispatcher, nameToLocation, log); action.onMessage(message, request); } finally { readLock.unlock(); } }
From source file:org.codehaus.wadi.location.partitionmanager.local.BasicLocalPartition.java
public void onMessage(Envelope message, DeleteIMToPM request) { Lock readLock = readWriteLock.readLock(); readLock.lock();//from w ww. jav a 2 s . c o m try { LocalPartitionDeleteIMToPMAction action = new LocalPartitionDeleteIMToPMAction(dispatcher, nameToLocation, log); action.onMessage(message, request); } finally { readLock.unlock(); } }
From source file:org.codehaus.wadi.location.partitionmanager.local.BasicLocalPartition.java
public void onMessage(Envelope message, EvacuateIMToPM request) { Lock readLock = readWriteLock.readLock(); readLock.lock();/* www . j a va 2s . co m*/ try { LocalPartitionEvacuateIMToPMAction action = new LocalPartitionEvacuateIMToPMAction(dispatcher, nameToLocation, log); action.onMessage(message, request); } finally { readLock.unlock(); } }
From source file:com.mg.framework.service.DatabaseAuditServiceImpl.java
public void stop() { Lock lock = entityAuditSetupLock.writeLock(); lock.lock();/* ww w . j a v a 2s. c om*/ try { entityAuditSetup.clear(); } finally { lock.unlock(); } }
From source file:info.pancancer.arch3.worker.WorkerHeartbeat.java
@Override public void run() { Channel reportingChannel = null; try {/*from ww w. j a v a2 s .c om*/ try { reportingChannel = Utilities.setupExchange(settings, this.queueName); } catch (IOException | TimeoutException | AlreadyClosedException e) { LOG.error("Exception caught! Queue channel could not be opened, waiting. Exception is: " + e.getMessage(), e); // retry after a minute, do not die simply because the launcher is unavailable, it may come back Thread.sleep(Base.ONE_MINUTE_IN_MILLISECONDS); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); LOG.info("Caught interrupt signal, heartbeat shutting down.", e); return; } LOG.info("starting heartbeat thread, will send heartbeat message ever " + secondsDelay + " seconds."); while (!Thread.interrupted()) { // byte[] stdOut = this.getMessageBody().getBytes(StandardCharsets.UTF_8); try { try { Status heartbeatStatus = new Status(); heartbeatStatus.setJobUuid(this.jobUuid); heartbeatStatus.setMessage("job is running; IP address: " + networkID); heartbeatStatus.setState(StatusState.RUNNING); heartbeatStatus.setType(Utilities.JOB_MESSAGE_TYPE); heartbeatStatus.setVmUuid(this.vmUuid); heartbeatStatus.setIpAddress(networkID); // String stdOut = this.statusSource.getStdOut(); Lock lock = new ReentrantLock(); lock.lock(); String stdOut = this.statusSource.getStdOut(stdoutSnipSize); String stdErr = this.statusSource.getStdErr(); lock.unlock(); heartbeatStatus.setStdout(stdOut); heartbeatStatus.setStderr(stdErr); String heartBeatMessage = heartbeatStatus.toJSON(); LOG.debug("Sending heartbeat message to " + queueName + ", with body: " + heartBeatMessage); reportingChannel.basicPublish(queueName, queueName, MessageProperties.PERSISTENT_TEXT_PLAIN, heartBeatMessage.getBytes(StandardCharsets.UTF_8)); reportingChannel.waitForConfirms(); Thread.sleep((long) (secondsDelay * MILLISECONDS_PER_SECOND)); } catch (IOException | AlreadyClosedException e) { LOG.error("IOException caught! Message may not have been published. Exception is: " + e.getMessage(), e); // retry after a minute, do not die simply because the launcher is unavailable, it may come back Thread.sleep(Base.ONE_MINUTE_IN_MILLISECONDS); } } catch (InterruptedException e) { LOG.info("Heartbeat shutting down."); if (reportingChannel.getConnection().isOpen()) { try { reportingChannel.getConnection().close(); } catch (IOException e1) { LOG.error("Error closing reportingChannel connection: " + e1.getMessage(), e1); } } if (reportingChannel.isOpen()) { try { reportingChannel.close(); } catch (IOException e1) { LOG.error("Error (IOException) closing reportingChannel: " + e1.getMessage(), e1); } catch (TimeoutException e1) { LOG.error("Error (TimeoutException) closing reportingChannel: " + e1.getMessage(), e1); } } LOG.debug("reporting channel open: " + reportingChannel.isOpen()); LOG.debug("reporting channel connection open: " + reportingChannel.getConnection().isOpen()); Thread.currentThread().interrupt(); } } }
From source file:org.eclipse.gyrex.monitoring.metrics.BaseMetric.java
/** * Returns a map of attribute values contained in the metric. * <p>//w w w .j ava 2 s . c o m * Although public this method must not be called by clients. The framework * uses this method to obtain further information about a metric for * processing purposes. * </p> * * @return an unmodifiable map of metric attribute values * @noreference This method is not intended to be referenced by clients. */ public final Map<String, ?> getAttributeValues() { final Map<String, Object> attributeValues = new HashMap<String, Object>(); final Lock lock = getReadLock(); lock.lock(); try { populateAttributeValues(attributeValues); } finally { lock.unlock(); } return Collections.unmodifiableMap(attributeValues); }
From source file:com.dp.bigdata.taurus.agent.sheduler.KillTaskThread.java
@Override public void run() { Lock lock = LockHelper.getLock(jobInstanceId); try {//w w w .ja va 2s .com lock.lock(); ScheduleConf conf = (ScheduleConf) cs.getConf(localIp, jobInstanceId); ScheduleStatus status = (ScheduleStatus) cs.getStatus(localIp, jobInstanceId); killTask(localIp, conf, status); } catch (Exception e) { LOGGER.error(e, e); } finally { lock.unlock(); } }
From source file:org.mule.util.queue.DualRandomAccessFileQueueStoreDelegate.java
@Override protected boolean doAddAll(Collection<? extends Serializable> items) { Lock lock = filesLock.readLock(); lock.lock();/*from w w w . j a v a 2s . c om*/ try { for (Serializable item : items) { add(item); } } finally { lock.unlock(); } return true; }
From source file:org.mule.util.queue.DualRandomAccessFileQueueStoreDelegate.java
@Override public int size() { Lock lock = filesLock.readLock(); lock.lock();//from www . ja va2 s. c om try { return randomAccessFileQueueStore1.getSize() + randomAccessFileQueueStore2.getSize(); } finally { lock.unlock(); } }