Examples of OwnableReentrantLock


Examples of org.infinispan.util.concurrent.locks.OwnableReentrantLock

      OwnableReentrantLock l = getLockFromMap(key);
      return l != null && owner.equals(l.getOwner());
   }

   public boolean isLocked(Object key) {
      OwnableReentrantLock l = getLockFromMap(key);
      return l != null && l.isLocked();
   }
View Full Code Here

Examples of org.infinispan.util.concurrent.locks.OwnableReentrantLock

      Future<Void> f = fork(new Callable<Void>() {
         @Override
         public Void call() throws InterruptedException, TimeoutException {
            final Object otherOwner = new Object();
            for (int i =0; i < 10; i++) {
               final OwnableReentrantLock ownableReentrantLock = lc.acquireLock(otherOwner, k2, 500, TimeUnit.MILLISECONDS);
               log.trace("ownableReentrantLock = " + ownableReentrantLock);
               if (ownableReentrantLock != null) return null;
            }
            throw new TimeoutException("We should have acquired lock!");
         }
View Full Code Here

Examples of org.infinispan.util.concurrent.locks.OwnableReentrantLock

      return new OwnableRefCountingReentrantLock();
   }

   @Override
   public boolean ownsLock(Object key, Object owner) {
      OwnableReentrantLock l = getLockFromMap(key);
      return l != null && owner.equals(l.getOwner());
   }
View Full Code Here

Examples of org.infinispan.util.concurrent.locks.OwnableReentrantLock

      return l != null && owner.equals(l.getOwner());
   }

   @Override
   public boolean isLocked(Object key) {
      OwnableReentrantLock l = getLockFromMap(key);
      return l != null && l.isLocked();
   }
View Full Code Here

Examples of org.infinispan.util.concurrent.locks.OwnableReentrantLock

   }

   @Override
   protected void initLocks(int numLocks) {
      sharedLocks = new OwnableReentrantLock[numLocks];
      for (int i = 0; i < numLocks; i++) sharedLocks[i] = new OwnableReentrantLock();
   }
View Full Code Here

Examples of org.infinispan.util.concurrent.locks.OwnableReentrantLock

      return sharedLocks[hashToIndex(object)];
   }

   @Override
   public final boolean ownsLock(Object object, Object owner) {
      OwnableReentrantLock lock = getLock(object);
      return owner.equals(lock.getOwner());
   }
View Full Code Here

Examples of org.infinispan.util.concurrent.locks.OwnableReentrantLock

      return owner.equals(lock.getOwner());
   }

   @Override
   public final boolean isLocked(Object object) {
      OwnableReentrantLock lock = getLock(object);
      return lock.isLocked();
   }
View Full Code Here

Examples of org.infinispan.util.concurrent.locks.OwnableReentrantLock

      initLocks(calculateNumberOfSegments(concurrencyLevel));
   }

   protected void initLocks(int numLocks) {
      sharedLocks = new OwnableReentrantLock[numLocks];
      for (int i = 0; i < numLocks; i++) sharedLocks[i] = new OwnableReentrantLock(icc);
   }
View Full Code Here

Examples of org.infinispan.util.concurrent.locks.OwnableReentrantLock

   public final OwnableReentrantLock getLock(Object object) {
      return sharedLocks[hashToIndex(object)];
   }

   public final boolean ownsLock(Object object, Object owner) {
      OwnableReentrantLock lock = getLock(object);
      return owner.equals(lock.getOwner());
   }
View Full Code Here

Examples of org.jboss.as.ejb3.tx.OwnableReentrantLock

public class EntityBeanSynchronizationInterceptor extends AbstractEJBInterceptor {
    @Override
    public Object processInvocation(InterceptorContext context) throws Exception {
        final EntityBeanComponent component = getComponent(context, EntityBeanComponent.class);
        final EntityBeanComponentInstance instance = (EntityBeanComponentInstance) context.getPrivateData(ComponentInstance.class);
        final OwnableReentrantLock lock = instance.getLock();
        //we do not synchronize for instances that are not associated with an identity
        if (instance.getPrimaryKey() == null) {
            return context.proceed();
        }

        final TransactionSynchronizationRegistry transactionSynchronizationRegistry = component.getTransactionSynchronizationRegistry();
        if (ROOT_LOGGER.isTraceEnabled()) {
            ROOT_LOGGER.trace("Trying to acquire lock: " + lock + " for entity bean " + instance + " during invocation: " + context);
        }
        // we obtain a lock in this synchronization interceptor because the lock needs to be tied to the synchronization
        // so that it can released on the tx synchronization callbacks
        final Object lockOwner = getLockOwner(transactionSynchronizationRegistry);
        lock.pushOwner(lockOwner);
        try {
            lock.lock();
            boolean syncRegistered = false;
            synchronized (lock) {

                //if the previous transaction was rolled back we re-load the entity bean state in the current TX
                if(instance.isReloadRequired()) {
                    instance.reload();
                }

                if (ROOT_LOGGER.isTraceEnabled()) {
                    ROOT_LOGGER.trace("Acquired lock: " + lock + " for entity bean instance: " + instance + " during invocation: " + context);
                }

                if (context.getPrivateData(InternalInvocationMarker.class) == null) {
                    if (instance.isRemoved() || instance.isDiscarded()) {
                        final Object primaryKey = context.getPrivateData(EntityBeanComponent.PRIMARY_KEY_CONTEXT_KEY);
                        component.getCache().release(instance, true);
                        lock.unlock();
                        throw EjbLogger.ROOT_LOGGER.instanceWasRemoved(component.getComponentName(), primaryKey);
                    }
                }

                Object currentTransactionKey = null;
                try {
                    // get the key to current transaction associated with this thread
                    currentTransactionKey = transactionSynchronizationRegistry.getTransactionKey();
                    if (!instance.isSynchronizeRegistered()) {
                        // if this entity instance is already associated with a different transaction, then it's an error

                        // if the thread is currently associated with a tx, then register a tx synchronization
                        if (currentTransactionKey != null) {
                            // register a tx synchronization for this entity instance
                            final Synchronization entitySynchronization = new EntityBeanSynchronization(instance, lockOwner);
                            transactionSynchronizationRegistry.registerInterposedSynchronization(entitySynchronization);
                            syncRegistered = true;
                            if (ROOT_LOGGER.isTraceEnabled()) {
                                ROOT_LOGGER.trace("Registered tx synchronization: " + entitySynchronization + " for tx: " + currentTransactionKey +
                                        " associated with stateful component instance: " + instance);
                            }
                        }
                        instance.setSynchronizationRegistered(true);
                    }
                    // proceed with the invocation
                    return context.proceed();

                } finally {
                    // if the current call did *not* register a tx SessionSynchronization, then we have to explicitly mark the
                    // entity instance as "no longer in use". If it registered a tx EntityBeanSynchronization, then releasing the lock is
                    // taken care off by a tx synchronization callbacks.
                    //if is important to note that we increase the lock count on every invocation
                    //which means we need to release it on every invocation except for the one where we actually registered the TX synchronization
                    if (currentTransactionKey == null) {
                        instance.store();
                        releaseInstance(instance, true);
                    } else if (!syncRegistered) {
                        component.getCache().release(instance, true);
                        lock.unlock();
                    }
                }
            }
        } finally {
            lock.popOwner();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.