当前位置: 首页>>代码示例>>Java>>正文


Java GlobalLock类代码示例

本文整理汇总了Java中com.cloud.utils.db.GlobalLock的典型用法代码示例。如果您正苦于以下问题:Java GlobalLock类的具体用法?Java GlobalLock怎么用?Java GlobalLock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GlobalLock类属于com.cloud.utils.db包,在下文中一共展示了GlobalLock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runInContext

import com.cloud.utils.db.GlobalLock; //导入依赖的package包/类
@Override
protected void runInContext() {
    try {
        final GlobalLock scanLock = GlobalLock.getInternLock("uploadmonitor.storageGC");
        try {
            if (scanLock.lock(3)) {
                try {
                    cleanupStorage();
                } finally {
                    scanLock.unlock();
                }
            }
        } finally {
            scanLock.releaseRef();
        }
    } catch (final Exception e) {
        s_logger.error("Caught the following Exception", e);
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:20,代码来源:UploadMonitorImpl.java

示例2: check

import com.cloud.utils.db.GlobalLock; //导入依赖的package包/类
@Override
public void check() {
    GlobalLock lock = GlobalLock.getInternLock("DatabaseIntegrity");
    try {
        s_logger.info("Grabbing lock to check for database integrity.");
        if (!lock.lock(20 * 60)) {
            throw new CloudRuntimeException("Unable to acquire lock to check for database integrity.");
        }

        try {
            s_logger.info("Performing database integrity check");
            if (!checkDuplicateHostWithTheSameLocalStorage()) {
                throw new CloudRuntimeException("checkDuplicateHostWithTheSameLocalStorage detected error");
            }

            if (!checkMissedPremiumUpgradeFor228()) {
                s_logger.error("Your current database version is 2.2.8, management server detected some missed premium upgrade, please contact CloudStack support and attach log file. Thank you!");
                throw new CloudRuntimeException("Detected missed premium upgrade");
            }
        } finally {
            lock.unlock();
        }
    } finally {
        lock.releaseRef();
    }
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:27,代码来源:DatabaseIntegrityChecker.java

示例3: runInContext

import com.cloud.utils.db.GlobalLock; //导入依赖的package包/类
@Override
protected void runInContext() {

    // Check if there are any external devices
    // Skip external device usage collection if none exist

    if(_hostDao.listByType(Host.Type.ExternalFirewall).isEmpty() && _hostDao.listByType(Host.Type.ExternalLoadBalancer).isEmpty()){
        s_logger.debug("External devices are not used. Skipping external device usage collection");
        return;
    }

    GlobalLock scanLock = GlobalLock.getInternLock("ExternalDeviceNetworkUsageManagerImpl");
    try {
        if (scanLock.lock(20)) {
            try {
                runExternalDeviceNetworkUsageTask();
            } finally {
                scanLock.unlock();
            }
        }
    } catch (Exception e) {
        s_logger.warn("Problems while getting external device usage", e);
    } finally {
        scanLock.releaseRef();
    }
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:27,代码来源:ExternalDeviceUsageManagerImpl.java

示例4: freeFirewallForNetwork

import com.cloud.utils.db.GlobalLock; //导入依赖的package包/类
@DB
protected boolean freeFirewallForNetwork(Network network) {
    GlobalLock deviceMapLock = GlobalLock.getInternLock("NetworkFirewallDeviceMap");
    try {
        if (deviceMapLock.lock(120)) {
            try {
                NetworkExternalFirewallVO fwDeviceForNetwork = _networkExternalFirewallDao.findByNetworkId(network.getId());
                if (fwDeviceForNetwork != null) {
                    _networkExternalFirewallDao.remove(fwDeviceForNetwork.getId());
                }
            } catch (Exception exception) {
                s_logger.error("Failed to release firewall device for the network" + network.getId() + " due to " + exception.getMessage());
                return false;
            } finally {
                deviceMapLock.unlock();
            }
        }
    } finally {
        deviceMapLock.releaseRef();
    }
    return true;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:23,代码来源:ExternalFirewallDeviceManagerImpl.java

示例5: runInContext

import com.cloud.utils.db.GlobalLock; //导入依赖的package包/类
@Override
protected void runInContext() {
    try {
        GlobalLock scanLock = GlobalLock.getInternLock("uploadmonitor.storageGC");
        try {
            if (scanLock.lock(3)) {
                try {
                    cleanupStorage();
                } finally {
                    scanLock.unlock();
                }
            }
        } finally {
            scanLock.releaseRef();
        }

    } catch (Exception e) {
        s_logger.error("Caught the following Exception", e);
    }
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:21,代码来源:UploadMonitorImpl.java

示例6: configure

import com.cloud.utils.db.GlobalLock; //导入依赖的package包/类
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    super.configure(name, params);
    Security.addProvider(new BouncyCastleProvider());
    final GlobalLock caLock = GlobalLock.getInternLock("RootCAProviderSetup");
    try {
        if (caLock.lock(5 * 60)) {
            try {
                return setupCA();
            } finally {
                caLock.unlock();
            }
        } else {
            LOG.error("Failed to grab lock and setup CA, startup method will try to load the CA certificate and keypair.");
        }
    } finally {
        caLock.releaseRef();
    }
    return true;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:21,代码来源:RootCAProvider.java

示例7: cancelWorkItems

import com.cloud.utils.db.GlobalLock; //导入依赖的package包/类
protected void cancelWorkItems(final long nodeId) {
    final GlobalLock scanLock = GlobalLock.getInternLock("vmmgr.cancel.workitem");

    try {
        if (scanLock.lock(3)) {
            try {
                final List<ItWorkVO> works = _workDao.listWorkInProgressFor(nodeId);
                for (final ItWorkVO work : works) {
                    s_logger.info("Handling unfinished work item: " + work);
                    try {
                        final VMInstanceVO vm = _vmDao.findById(work.getInstanceId());
                        if (vm != null) {
                            if (work.getType() == State.Starting) {
                                _haMgr.scheduleRestart(vm, true);
                                work.setManagementServerId(_nodeId);
                                work.setStep(Step.Done);
                                _workDao.update(work.getId(), work);
                            } else if (work.getType() == State.Stopping) {
                                _haMgr.scheduleStop(vm, vm.getHostId(), WorkType.CheckStop);
                                work.setManagementServerId(_nodeId);
                                work.setStep(Step.Done);
                                _workDao.update(work.getId(), work);
                            } else if (work.getType() == State.Migrating) {
                                _haMgr.scheduleMigration(vm);
                                work.setStep(Step.Done);
                                _workDao.update(work.getId(), work);
                            }
                        }
                    } catch (final Exception e) {
                        s_logger.error("Error while handling " + work, e);
                    }
                }
            } finally {
                scanLock.unlock();
            }
        }
    } finally {
        scanLock.releaseRef();
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:41,代码来源:VirtualMachineManagerImpl.java

示例8: runInContext

import com.cloud.utils.db.GlobalLock; //导入依赖的package包/类
@Override
protected void runInContext() {
    final GlobalLock lock = GlobalLock.getInternLock("TransitionChecking");
    if (lock == null) {
        s_logger.debug("Couldn't get the global lock");
        return;
    }

    if (!lock.lock(30)) {
        s_logger.debug("Couldn't lock the db");
        return;
    }
    try {
        scanStalledVMInTransitionStateOnDisconnectedHosts();

        final List<VMInstanceVO> instances = _vmDao.findVMInTransition(new Date(new Date().getTime() - AgentManager.Wait.value() * 1000), State.Starting, State.Stopping);
        for (final VMInstanceVO instance : instances) {
            final State state = instance.getState();
            if (state == State.Stopping) {
                _haMgr.scheduleStop(instance, instance.getHostId(), WorkType.CheckStop);
            } else if (state == State.Starting) {
                _haMgr.scheduleRestart(instance, true);
            }
        }
    } catch (final Exception e) {
        s_logger.warn("Caught the following exception on transition checking", e);
    } finally {
        lock.unlock();
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:31,代码来源:VirtualMachineManagerImpl.java

示例9: runInContext

import com.cloud.utils.db.GlobalLock; //导入依赖的package包/类
@Override
protected void runInContext() {
    final GlobalLock gcLock = GlobalLock.getInternLock("Network.GC.Lock");
    try {
        if (gcLock.lock(3)) {
            try {
                reallyRun();
            } finally {
                gcLock.unlock();
            }
        }
    } finally {
        gcLock.releaseRef();
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:16,代码来源:NetworkOrchestrator.java

示例10: runInContext

import com.cloud.utils.db.GlobalLock; //导入依赖的package包/类
@Override
protected void runInContext() {
    GlobalLock replacementLock = null;
    try {
        replacementLock = GlobalLock.getInternLock("storageCacheMgr.replacement");
        if (replacementLock.lock(3)) {
            final List<DataStore> stores = getCacheStores();
            Collections.shuffle(stores);
            DataObject object = null;
            DataStore findAStore = null;
            for (final DataStore store : stores) {
                object = cacheReplacementAlgorithm.chooseOneToBeReplaced(store);
                findAStore = store;
                if (object != null) {
                    break;
                }
            }

            if (object == null) {
                return;
            }

            while (object != null) {
                object.delete();
                object = cacheReplacementAlgorithm.chooseOneToBeReplaced(findAStore);
            }
        }
    } catch (final Exception e) {
        s_logger.debug("Failed to execute CacheReplacementRunner: " + e.toString());
    } finally {
        if (replacementLock != null) {
            replacementLock.unlock();
        }
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:36,代码来源:StorageCacheManagerImpl.java

示例11: runInContext

import com.cloud.utils.db.GlobalLock; //导入依赖的package包/类
@Override
protected void runInContext() {
    GlobalLock gcLock = GlobalLock.getInternLock("ContainerCluster.GC.Lock");
    try {
        if (gcLock.lock(3)) {
            try {
                reallyRun();
            } finally {
                gcLock.unlock();
            }
        }
    } finally {
        gcLock.releaseRef();
    }
}
 
开发者ID:shapeblue,项目名称:ccs,代码行数:16,代码来源:ContainerClusterManagerImpl.java

示例12: runInContext

import com.cloud.utils.db.GlobalLock; //导入依赖的package包/类
@Override
protected void runInContext() {
    final GlobalLock lock = GlobalLock.getInternLock("TransitionChecking");
    if (lock == null) {
        s_logger.debug("Couldn't get the global lock");
        return;
    }

    if (!lock.lock(30)) {
        s_logger.debug("Couldn't lock the db");
        return;
    }
    try {
        scanStalledVMInTransitionStateOnDisconnectedHosts();

        final List<VMInstanceVO> instances = _vmDao.findVMInTransition(new Date(DateUtil.currentGMTTime().getTime() - AgentManager.Wait.value() * 1000), State.Starting, State.Stopping);
        for (final VMInstanceVO instance : instances) {
            final State state = instance.getState();
            if (state == State.Stopping) {
                _haMgr.scheduleStop(instance, instance.getHostId(), WorkType.CheckStop);
            } else if (state == State.Starting) {
                _haMgr.scheduleRestart(instance, true);
            }
        }
    } catch (final Exception e) {
        s_logger.warn("Caught the following exception on transition checking", e);
    } finally {
        lock.unlock();
    }
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:31,代码来源:VirtualMachineManagerImpl.java

示例13: runInContext

import com.cloud.utils.db.GlobalLock; //导入依赖的package包/类
@Override
protected void runInContext() {
    GlobalLock replacementLock = null;
    try {
        replacementLock = GlobalLock.getInternLock("storageCacheMgr.replacement");
        if (replacementLock.lock(3)) {
            List<DataStore> stores = getCacheStores();
            Collections.shuffle(stores);
            DataObject object = null;
            DataStore findAStore = null;
            for (DataStore store : stores) {
                object = cacheReplacementAlgorithm.chooseOneToBeReplaced(store);
                findAStore = store;
                if (object != null) {
                    break;
                }
            }

            if (object == null) {
                return;
            }

            while (object != null) {
                object.delete();
                object = cacheReplacementAlgorithm.chooseOneToBeReplaced(findAStore);
            }
        }
    } catch (Exception e) {
        s_logger.debug("Failed to execute CacheReplacementRunner: " + e.toString());
    } finally {
        if (replacementLock != null) {
            replacementLock.unlock();
        }
    }
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:36,代码来源:StorageCacheManagerImpl.java

示例14: check

import com.cloud.utils.db.GlobalLock; //导入依赖的package包/类
@Override
public void check() {
    GlobalLock lock = GlobalLock.getInternLock("DatabaseUpgrade");
    try {
        s_logger.info("Grabbing lock to check for database upgrade.");
        if (!lock.lock(20 * 60)) {
            throw new CloudRuntimeException("Unable to acquire lock to check for database integrity.");
        }

        try {

            final CloudStackVersion dbVersion = CloudStackVersion.parse(_dao.getCurrentVersion());
            final String currentVersionValue = this.getClass().getPackage().getImplementationVersion();

            if (StringUtils.isBlank(currentVersionValue)) {
                return;
            }

            final CloudStackVersion currentVersion = CloudStackVersion.parse(currentVersionValue);
            s_logger.info("DB version = " + dbVersion + " Code Version = " + currentVersion);

            if (dbVersion.compareTo(currentVersion) > 0) {
                throw new CloudRuntimeException("Database version " + dbVersion + " is higher than management software version " + currentVersionValue);
            }

            if (dbVersion.compareTo(currentVersion) == 0) {
                s_logger.info("DB version and code version matches so no upgrade needed.");
                return;
            }

            upgrade(dbVersion, currentVersion);
        } finally {
            lock.unlock();
        }
    } finally {
        lock.releaseRef();
    }
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:39,代码来源:DatabaseUpgradeChecker.java

示例15: releasePortableIpAddress

import com.cloud.utils.db.GlobalLock; //导入依赖的package包/类
@DB
@Override
public boolean releasePortableIpAddress(final long addrId) {
    final GlobalLock portableIpLock = GlobalLock.getInternLock("PortablePublicIpRange");

    try {
        return Transaction.execute(new TransactionCallback<Boolean>() {
            @Override
            public Boolean doInTransaction(TransactionStatus status) {
                portableIpLock.lock(5);
                IPAddressVO ip = _ipAddressDao.findById(addrId);

                // unassign portable IP
                PortableIpVO portableIp = _portableIpDao.findByIpAddress(ip.getAddress().addr());
                _portableIpDao.unassignIpAddress(portableIp.getId());

                // removed the provisioned vlan
                VlanVO vlan = _vlanDao.findById(ip.getVlanId());
                _vlanDao.remove(vlan.getId());

                // remove the provisioned public ip address
                _ipAddressDao.remove(ip.getId());

                return true;
            }
        });
    } finally {
        portableIpLock.releaseRef();
    }
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:31,代码来源:IpAddressManagerImpl.java


注:本文中的com.cloud.utils.db.GlobalLock类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。