Example usage for java.util.concurrent.locks Lock unlock

List of usage examples for java.util.concurrent.locks Lock unlock

Introduction

In this page you can find the example usage for java.util.concurrent.locks Lock unlock.

Prototype

void unlock();

Source Link

Document

Releases the lock.

Usage

From source file:gridool.db.sql.ParallelSQLExecJob.java

private static void createMergeView(@Nonnull final Connection conn, @Nonnull final String ddl,
        @Nonnull final ReadWriteLock rwlock) throws GridException {
    if (LOG.isInfoEnabled()) {
        LOG.info("Create a merge view: \n" + ddl);
    }/* www . j  a v  a  2s  .  com*/
    final Lock wlock = rwlock.writeLock();
    try {
        wlock.lock();
        JDBCUtils.update(conn, ddl);
    } catch (SQLException e) {
        String errmsg = "failed running a reduce query: " + ddl;
        LOG.error(errmsg, e);
        try {
            conn.rollback();
        } catch (SQLException rbe) {
            LOG.warn("Rollback failed", rbe);
        }
        throw new GridException(errmsg, e);
    } finally {
        wlock.unlock();
    }
}

From source file:jp.aegif.nemaki.cmis.service.impl.VersioningServiceImpl.java

@Override
public void cancelCheckOut(CallContext callContext, String repositoryId, String objectId,
        ExtensionsData extension) {//from   ww w . j  a v  a  2  s .  c  o  m

    exceptionService.invalidArgumentRequiredString("objectId", objectId);

    Lock lock = threadLockService.getWriteLock(repositoryId, objectId);

    try {
        lock.lock();
        nemakiCachePool.get(repositoryId).removeCmisCache(objectId);
        // //////////////////
        // General Exception
        // //////////////////
        Document document = contentService.getDocument(repositoryId, objectId);
        exceptionService.objectNotFound(DomainType.OBJECT, document, objectId);
        exceptionService.permissionDenied(callContext, repositoryId, PermissionMapping.CAN_CHECKIN_DOCUMENT,
                document);

        // //////////////////
        // Specific Exception
        // //////////////////
        exceptionService.constraintVersionable(repositoryId, document.getObjectType());

        // //////////////////
        // Body of the method
        // //////////////////
        contentService.cancelCheckOut(callContext, repositoryId, objectId, extension);

        //remove cache

        Document latest = contentService.getDocumentOfLatestVersion(repositoryId,
                document.getVersionSeriesId());
        //Latest document does not exit when pwc is created as the first version
        if (latest != null) {
            Lock latestLock = threadLockService.getWriteLock(repositoryId, latest.getId());
            try {
                latestLock.lock();
                nemakiCachePool.get(repositoryId).removeCmisCache(latest.getId());
            } finally {
                latestLock.unlock();
            }
        }
    } finally {
        lock.unlock();
    }
}

From source file:com.cloudera.oryx.ml.serving.als.model.ALSServingModel.java

private ObjSet<String> doGetKnownItems(String user) {
    Lock lock = xLock.readLock();
    lock.lock();/*from   ww w.  j  a v a  2s  . com*/
    try {
        return knownItems.get(user);
    } finally {
        lock.unlock();
    }
}

From source file:com.iternox.piggate.samples.PiggateLogin.Activity_Logged.java

public ArrayList<PiggateOffers> getOffers() {
    Lock l = rwLock2.readLock();
    ArrayList<PiggateOffers> result = new ArrayList<PiggateOffers>();
    l.lock();//from   w w  w .jav  a 2  s . c  o m
    try {
        result.addAll(this.internal_offers);
    } catch (Exception ex) {
    } finally {
        l.unlock();
    }
    return result;
}

From source file:jp.aegif.nemaki.cmis.service.impl.VersioningServiceImpl.java

@Override
public void checkIn(CallContext callContext, String repositoryId, Holder<String> objectId, Boolean major,
        Properties properties, ContentStream contentStream, String checkinComment, List<String> policies,
        Acl addAces, Acl removeAces, ExtensionsData extension) {

    exceptionService.invalidArgumentRequiredHolderString("objectId", objectId);

    Lock lock = threadLockService.getWriteLock(repositoryId, objectId.getValue());

    try {//from   w  w  w .j av  a  2 s.  c  om
        lock.lock();

        // //////////////////
        // General Exception
        // //////////////////

        Document pwc = contentService.getDocument(repositoryId, objectId.getValue());
        nemakiCachePool.get(repositoryId).removeCmisCache(pwc.getId());

        exceptionService.objectNotFound(DomainType.OBJECT, pwc, objectId.getValue());
        exceptionService.permissionDenied(callContext, repositoryId,
                PermissionMapping.CAN_CANCEL_CHECKOUT_DOCUMENT, pwc);

        // //////////////////
        // Specific Exception
        // //////////////////
        exceptionService.constraintVersionable(repositoryId, pwc.getObjectType());
        // TODO implement
        // exceptionService.streamNotSupported(documentTypeDefinition,
        // contentStream);

        // //////////////////
        // Body of the method
        // //////////////////
        Document checkedIn = contentService.checkIn(callContext, repositoryId, objectId, major, properties,
                contentStream, checkinComment, policies, addAces, removeAces, extension);
        objectId.setValue(checkedIn.getId());

        //refresh latest version
        Document latest = contentService.getDocumentOfLatestVersion(repositoryId, pwc.getVersionSeriesId());
        if (latest != null) {
            Lock latestLock = threadLockService.getWriteLock(repositoryId, latest.getId());
            try {
                latestLock.lock();
                nemakiCachePool.get(repositoryId).removeCmisCache(latest.getId());
            } finally {
                latestLock.unlock();
            }
        }
    } finally {
        lock.unlock();
    }
}

From source file:gridool.db.sql.ParallelSQLExecJob.java

private static void runPreparation(@Nonnull final DBAccessor dba, @Nonnull final String mapQuery,
        @Nonnull final GridNode[] masters, @Nonnull final GridNode localNode,
        @Nonnull final ReadWriteLock rwlock, @Nonnull final String outputName) throws GridException {
    final String prepareQuery = constructTaskResultTablesDDL(mapQuery, masters, localNode, outputName);
    final Connection conn;
    try {//from  w w w .ja  v  a 2  s .  c o m
        conn = dba.getPrimaryDbConnection();
        conn.setAutoCommit(false);
    } catch (SQLException e) {
        LOG.error("An error caused in the preparation phase", e);
        throw new GridException(e);
    }
    final Lock wlock = rwlock.writeLock();
    try {
        wlock.lock();
        JDBCUtils.update(conn, prepareQuery);
        conn.commit();
    } catch (SQLException e) {
        LOG.error("An error caused in the preparation phase", e);
        try {
            conn.rollback();
        } catch (SQLException sqle) {
            LOG.warn("Failed to rollback", sqle);
        }
        throw new GridException(e);
    } finally {
        wlock.unlock();
        JDBCUtils.closeQuietly(conn);
    }
}

From source file:com.cip.crane.agent.deploy.UndeploymentThread.java

@Override
public void run() {
    Lock lock = LockHelper.getLock(taskID);
    try {//from w ww  .  j  a  v  a 2  s  .  c  o  m
        lock.lock();
        DeploymentConf conf = (DeploymentConf) cs.getConf(localIp, taskID);
        DeploymentStatus status = (DeploymentStatus) cs.getStatus(localIp, taskID);
        if (status == null || status.getStatus() == DeploymentStatus.DELETE_SUCCESS) {
            return;
        }

        undeployTask(conf, status);
        cs.updateStatus(localIp, taskID, status);
    } catch (Exception e) {
        LOGGER.error(e, e);
    } finally {
        lock.unlock();
    }
}

From source file:gridool.db.sql.ParallelSQLExecJob.java

private static String invokeReduceDDL(final Connection conn, final String reduceQuery,
        final String outputTableName, final OutputMethod outputMethod, final ReadWriteLock rwlock)
        throws GridException {
    final String query;
    if (outputMethod == OutputMethod.view) {
        query = "CREATE VIEW \"" + outputTableName + "\" AS (\n" + reduceQuery + ')';
    } else if (outputMethod == OutputMethod.table) {
        query = "CREATE TABLE \"" + outputTableName + "\" AS (\n" + reduceQuery + ") WITH DATA";
    } else {//from w w w .ja  va  2s  . c  o  m
        throw new IllegalStateException("Unexpected OutputMethod: " + outputMethod);
    }
    if (LOG.isInfoEnabled()) {
        LOG.info("Executing a Reduce SQL query: \n" + query);
    }
    final Lock wlock = rwlock.writeLock();
    try {
        wlock.lock();
        JDBCUtils.update(conn, query);
    } catch (SQLException e) {
        String errmsg = "failed running a reduce query: " + query;
        LOG.error(errmsg, e);
        try {
            conn.rollback();
        } catch (SQLException rbe) {
            LOG.warn("Rollback failed", rbe);
        }
        throw new GridException(errmsg, e);
    } finally {
        wlock.unlock();
    }
    return outputTableName;
}

From source file:org.mule.util.queue.DualRandomAccessFileQueueStoreDelegate.java

@Override
public boolean contains(Serializable value) {
    Lock lock = filesLock.readLock();
    lock.lock();/*  w w  w.  ja  v  a 2 s.  c o  m*/
    try {
        final RawDataSelector dataSelector = createDataSelector(value);
        if (!randomAccessFileQueueStore1.contains(dataSelector)) {
            return randomAccessFileQueueStore2.contains(dataSelector);
        }
    } finally {
        lock.unlock();
    }
    return true;
}

From source file:com.cloudera.oryx.ml.serving.als.model.ALSServingModel.java

public float[] getItemVector(String item) {
    int partition = partition(item);
    Lock lock = yLocks[partition].readLock();
    lock.lock();//  w  ww  .java 2  s . c  om
    try {
        return Y[partition].get(item);
    } finally {
        lock.unlock();
    }
}