Example usage for java.util.concurrent.locks ReentrantLock ReentrantLock

List of usage examples for java.util.concurrent.locks ReentrantLock ReentrantLock

Introduction

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

Prototype

public ReentrantLock() 

Source Link

Document

Creates an instance of ReentrantLock .

Usage

From source file:org.apache.cxf.transport.http.asyncclient.SharedOutputBuffer.java

public SharedOutputBuffer(int buffersize, final ByteBufferAllocator allocator) {
    super(buffersize, allocator);
    this.lock = new ReentrantLock();
    this.condition = this.lock.newCondition();
}

From source file:com.shigengyu.hyperion.cache.LocalWorkflowInstanceCache.java

private synchronized ReentrantLock getLock(final Integer workflowInstanceId) {
    ReentrantLock lock = locks.get(workflowInstanceId);
    if (lock == null) {
        lock = new ReentrantLock();
        locks.put(workflowInstanceId, lock);
    }//from   w  w  w  . j ava 2s  .c o  m
    return lock;
}

From source file:com.subgraph.vega.internal.model.alerts.ScanInstance.java

void setTransientState(ObjectContainer database, ScanAlertFactory alertFactory) {
    this.database = database;
    this.alertFactory = alertFactory;
    this.lock = new ReentrantLock();
    this.eventManager = new EventListenerManager();
}

From source file:org.apache.cxf.transport.http.asyncclient.SharedInputBuffer.java

public SharedInputBuffer(int buffersize, final ByteBufferAllocator allocator) {
    super(buffersize, allocator);
    this.lock = new ReentrantLock();
    this.condition = this.lock.newCondition();
    //if the buffer become 3/4 empty, we'll turn on the input
    //events again to hopefully get more data before the next 
    //the buffer fully empties and we have to wait to read
    this.requestInputSize = buffersize * 3 / 4;
}

From source file:org.jactr.core.production.action.SleepAction.java

/**
 * wait until the goal buffer isn't empty
 * /* w  w  w. ja va 2  s  . c  o m*/
 * @see org.jactr.core.production.action.IAction#fire(org.jactr.core.production.IInstantiation, double)
 */
public double fire(IInstantiation instantiation, double firingTime) {
    IActivationBuffer goalBuffer = instantiation.getModel().getActivationBuffer(IActivationBuffer.GOAL);

    if (goalBuffer.getSourceChunk() == null) {
        final Lock goalLock = new ReentrantLock();
        final Condition gotAGoal = goalLock.newCondition();

        /*
         * merely signal when the goal buffer gets something
         */
        IActivationBufferListener listener = new ActivationBufferListenerAdaptor() {
            @Override
            public void sourceChunkAdded(ActivationBufferEvent event) {
                try {
                    goalLock.lock();
                    if (LOGGER.isDebugEnabled())
                        LOGGER.debug("Signaling goal insertion");
                    gotAGoal.signalAll();
                } finally {
                    goalLock.unlock();
                }
            }
        };

        /*
         * attach the listener with the inline executor - this ensures that
         * regardless of what thread adds the source chunk to the buffer we will
         * be notified
         */
        goalBuffer.addListener(listener, ExecutorServices.INLINE_EXECUTOR);

        try {
            goalLock.lock();
            while (goalBuffer.getSourceChunk() == null) {
                if (LOGGER.isDebugEnabled())
                    LOGGER.debug("Waiting for goal");
                gotAGoal.await();
            }
        } catch (Exception e) {
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("Could not wait for goal ", e);
        }

        if (LOGGER.isDebugEnabled())
            LOGGER.debug("Resuming from wait");

        goalLock.unlock();

        /*
         * remove the listener
         */
        goalBuffer.removeListener(listener);
    } else if (LOGGER.isDebugEnabled())
        LOGGER.debug("Goal is already present, no need to sleep");

    return 0;
}

From source file:com.vmware.identity.session.impl.SessionManagerImpl.java

/**
 * Construct the object//from w  w w  . j  av a  2s . c o m
 */
public SessionManagerImpl() {
    log.debug("SessionManagerImpl created");

    this.sessions = new HashMap<String, Session>();
    this.sessionParticipants = new HashMap<String, String>();
    this.sessionRequests = new HashMap<String, String>();
    this.lock = new ReentrantLock();
}

From source file:org.nuxeo.nike.UpdateANikeDirectory.java

@OperationMethod
public void run() {
    Session directorySession = null;//w w  w.  j av a2s.  co  m
    CoreSession coreSession = null;

    Lock lock = new ReentrantLock();
    lock.lock();
    try {
        directorySession = directoryService.open(directoryName);

        // Delete all entries in the directory
        DocumentModelList entries = directorySession.getEntries();
        for (DocumentModel entry : entries) {
            directorySession.deleteEntry(entry);
        }

        // Query the documents and create unique entries
        coreSession = ctx.getCoreSession();
        String nxql = "SELECT * FROM " + docType;
        nxql += " WHERE ecm:currentLifeCycleState != 'deleted'";
        DocumentModelList allDocs = coreSession.query(nxql);

        List<String> titles = new ArrayList<String>();
        for (DocumentModel oneDoc : allDocs) {
            String title = oneDoc.getTitle();
            if (!titles.contains(title)) {
                titles.add(title);

                Map<String, Object> entry = new HashMap<String, Object>();
                entry.put("id", title);
                entry.put("label", title);
                entry.put("obsolete", 0);
                entry.put("ordering", 10000);

                directorySession.createEntry(entry);
            }
        }
        directorySession.close();

    } catch (Exception e) {
        log.error("Error creating the directory", e);
    } finally {
        lock.unlock();
    }
}

From source file:org.springframework.boot.actuate.metrics.ambari.buffer.MetricBuffer.java

public MetricBuffer() {
    this.bufferLock = new ReentrantLock();
    this.bufferedMetricCount = new AtomicLong(0);
    this.metricBuffer = new HashMap<String, Map<Long, Double>>();
    this.metricTypeMap = new ConcurrentHashMap<String, String>();
}

From source file:com.ery.ertc.estorm.util.ByteBufferArray.java

/**
 * We allocate a number of byte buffers as the capacity. In order not to out of the array bounds for the last byte(see
 * {@link ByteBufferArray#multiple}), we will allocate one additional buffer with capacity 0;
 * /*from  ww w .  ja v  a 2s  . c  om*/
 * @param capacity
 *            total size of the byte buffer array
 * @param directByteBuffer
 *            true if we allocate direct buffer
 */
public ByteBufferArray(long capacity, boolean directByteBuffer) {
    this.bufferSize = DEFAULT_BUFFER_SIZE;
    if (this.bufferSize > (capacity / 16))
        this.bufferSize = (int) roundUp(capacity / 16, 32768);
    this.bufferCount = (int) (roundUp(capacity, bufferSize) / bufferSize);
    LOG.info("Allocating buffers total=" + StringUtils.byteDesc(capacity) + " , sizePerBuffer="
            + StringUtils.byteDesc(bufferSize) + ", count=" + bufferCount);
    buffers = new ByteBuffer[bufferCount + 1];
    locks = new Lock[bufferCount + 1];
    for (int i = 0; i <= bufferCount; i++) {
        locks[i] = new ReentrantLock();
        if (i < bufferCount) {
            buffers[i] = directByteBuffer ? ByteBuffer.allocateDirect(bufferSize)
                    : ByteBuffer.allocate(bufferSize);
        } else {
            buffers[i] = ByteBuffer.allocate(0);
        }

    }
}

From source file:com.callidusrobotics.droptables.configuration.MongoFactory.java

public MongoFactory() {
    for (int i = 0; i < locks.length; i++) {
        locks[i] = new ReentrantLock();
    }
}