distributed/src/main/java/com/orientechnologies/orient/server/distributed/impl/ODistributedAbstractPlugin.java
public <T> T executeInDistributedDatabaseLock(final String databaseName, final long timeoutLocking,
      OModifiableDistributedConfiguration lastCfg, final OCallable<T, OModifiableDistributedConfiguration> iCallback) {

    boolean updated;
    T result;
    lockManagerRequester.acquireExclusiveLock(databaseName, nodeName, timeoutLocking);
    try {

      if (lastCfg == null)
        // ACQUIRE CFG INSIDE THE LOCK
        lastCfg = getDatabaseConfiguration(databaseName).modify();

      if (ODistributedServerLog.isDebugEnabled())
        ODistributedServerLog
            .debug(this, nodeName, null, DIRECTION.NONE, "Current distributed configuration for database '%s': %s", databaseName,
                lastCfg.getDocument().toJSON());

      try {

        result = iCallback.call(lastCfg);

      } finally {
        if (ODistributedServerLog.isDebugEnabled())
          ODistributedServerLog
              .debug(this, nodeName, null, DIRECTION.NONE, "New distributed configuration for database '%s': %s", databaseName,
                  lastCfg.getDocument().toJSON());

        // CONFIGURATION CHANGED, UPDATE IT ON THE CLUSTER AND DISK
        updated = updateCachedDatabaseConfiguration(databaseName, lastCfg, true);

      }

    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw new RuntimeException(e);

    } finally {
      lockManagerRequester.releaseExclusiveLock(databaseName, nodeName);
    }
    if (updated) {
      // SEND NEW CFG TO ALL THE CONNECTED CLIENTS
      notifyClients(databaseName);
      serverInstance.getClientConnectionManager().pushDistribCfg2Clients(getClusterConfiguration());
    }
    return result;
  }
public <T> T executeInDistributedDatabaseLock(final String databaseName, final long timeoutLocking,
      OModifiableDistributedConfiguration lastCfg, final OCallable<T, OModifiableDistributedConfiguration> iCallback) {

    boolean updated;
    T result;
    lockManagerRequester.acquireExclusiveLock(databaseName, nodeName, timeoutLocking);
    try {

      if (lastCfg == null)
        // ACQUIRE CFG INSIDE THE LOCK
        lastCfg = getDatabaseConfiguration(databaseName).modify();

      if (ODistributedServerLog.isDebugEnabled())
        ODistributedServerLog
            .debug(this, nodeName, null, DIRECTION.NONE, "Current distributed configuration for database '%s': %s", databaseName,
                lastCfg.getDocument().toJSON());

      try {

        result = iCallback.call(lastCfg);

      } finally {
        if (ODistributedServerLog.isDebugEnabled())
          ODistributedServerLog
              .debug(this, nodeName, null, DIRECTION.NONE, "New distributed configuration for database '%s': %s", databaseName,
                  lastCfg.getDocument().toJSON());

        // CONFIGURATION CHANGED, UPDATE IT ON THE CLUSTER AND DISK
        updated = updateCachedDatabaseConfiguration(databaseName, lastCfg, true);

      }

    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw new RuntimeException(e);

    } finally {
      lockManagerRequester.releaseExclusiveLock(databaseName, nodeName);
    }
    if (updated) {
      // SEND NEW CFG TO ALL THE CONNECTED CLIENTS
      notifyClients(databaseName);
      serverInstance.getClientConnectionManager().pushDistribCfg2Clients(getClusterConfiguration());
    }
    return result;
  }
public < T > T executeInDistributedDatabaseLock ( final String databaseName , final long timeoutLocking , OModifiableDistributedConfiguration lastCfg , final OCallable < T , OModifiableDistributedConfiguration > iCallback ) { boolean updated ; T result ; lockManagerRequester . acquireExclusiveLock ( databaseName , nodeName , timeoutLocking ) ; try { if ( lastCfg == null ) // ACQUIRE CFG INSIDE THE LOCK lastCfg = getDatabaseConfiguration ( databaseName ) . modify ( ) ; if ( ODistributedServerLog . isDebugEnabled ( ) ) ODistributedServerLog . debug ( this , nodeName , null , DIRECTION . NONE , "Current distributed configuration for database '%s': %s" , databaseName , lastCfg . getDocument ( ) . toJSON ( ) ) ; try { result = iCallback . call ( lastCfg ) ; } finally { if ( ODistributedServerLog . isDebugEnabled ( ) ) ODistributedServerLog . debug ( this , nodeName , null , DIRECTION . NONE , "New distributed configuration for database '%s': %s" , databaseName , lastCfg . getDocument ( ) . toJSON ( ) ) ; // CONFIGURATION CHANGED, UPDATE IT ON THE CLUSTER AND DISK updated = updateCachedDatabaseConfiguration ( databaseName , lastCfg , true ) ; } } catch ( RuntimeException e ) { throw e ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } finally { lockManagerRequester . releaseExclusiveLock ( databaseName , nodeName ) ; } if ( updated ) { // SEND NEW CFG TO ALL THE CONNECTED CLIENTS notifyClients ( databaseName ) ; serverInstance . getClientConnectionManager ( ) . pushDistribCfg2Clients ( getClusterConfiguration ( ) ) ; } return result ; }
Executes an operation protected by a distributed lock (one per database).

@param <T>          Return type
@param databaseName Database name
@param iCallback    Operation @return The operation's result of type T
Executes an operation protected by a distributed lock ( one per database ) .