Package io.fabric8.api

Examples of io.fabric8.api.LockHandle


            // i need this old logic in case of remote repos
            LOGGER.info("Starting to pull from remote git repository every {} millis", gitRemotePollInterval);
            threadPool.scheduleWithFixedDelay(new Runnable() {
                @Override
                public void run() {
                    LockHandle writeLock = aquireWriteLock();
                    try {
                        LOGGER.trace("Performing timed pull");
                        doPullInternal();
                        LOGGER.debug("Performed timed pull from external git repo");
                    } catch (Throwable e) {
                        LOGGER.debug("Error during performed timed pull/push due " + e.getMessage(), e);
                        LOGGER.warn("Error during performed timed pull/push due " + e.getMessage() + ". This exception is ignored.");
                    } finally {
                        writeLock.unlock();
                    }
                }

                @Override
                public String toString() {
View Full Code Here


            success = writeLock.tryLock() || writeLock.tryLock(AQUIRE_LOCK_TIMEOUT, TimeUnit.MILLISECONDS);
        } catch (InterruptedException ex) {
            success = false;
        }
        IllegalStateAssertion.assertTrue(success, "Cannot obtain profile write lock in time");
        return new LockHandle() {
            @Override
            public void unlock() {
                if (notificationRequired && readWriteLock.getWriteHoldCount() == 1) {
                    try {
                        dataStore.get().fireChangeNotifications();
View Full Code Here

            success = readLock.tryLock() || readLock.tryLock(AQUIRE_LOCK_TIMEOUT, TimeUnit.MILLISECONDS);
        } catch (InterruptedException ex) {
            success = false;
        }
        IllegalStateAssertion.assertTrue(success, "Cannot obtain profile read lock in time");
        return new LockHandle() {
            @Override
            public void unlock() {
                readLock.unlock();
            }
        };
View Full Code Here

            }
        };
    }

    private List<String> getInitialVersions() {
        LockHandle readLock = aquireReadLock();
        try {
            GitOperation<List<String>> gitop = new GitOperation<List<String>>() {
                public List<String> call(Git git, GitContext context) throws Exception {
                    Collection<String> branches = RepositoryUtils.getBranches(git.getRepository());
                    List<String> answer = new ArrayList<String>();
                    for (String branch : branches) {
                        String name = branch;
                        String prefix = "refs/heads/";
                        if (name.startsWith(prefix)) {
                            name = name.substring(prefix.length());
                            if (!name.equals(GitHelpers.MASTER_BRANCH)) {
                                answer.add(name);
                            }
                        }
                    }
                    versions.clear();
                    versions.addAll(answer);
                    return answer;
                }
            };
            return executeRead(gitop);
        } finally {
            readLock.unlock();
        }
    }
View Full Code Here

    public Map<String, String> getDataStoreProperties() {
        return Collections.unmodifiableMap(dataStoreProperties);
    }

    private Version getVersionFromCache(String versionId, String profileId) {
        LockHandle writeLock = aquireWriteLock();
        try {
            assertValid();
            String branch = GitHelpers.getProfileBranch(versionId, profileId);
            if (GitHelpers.localBranchExists(getGit(), branch)) {
                return versionCache.get(versionId);
            } else {
                return null;
            }
        } catch (Exception e) {
            throw FabricException.launderThrowable(e);
        } finally {
            writeLock.unlock();
        }
    }
View Full Code Here

    @Override
    public String createVersion(GitContext context, final String sourceId, final String targetId, final Map<String, String> attributes) {
        IllegalStateAssertion.assertNotNull(sourceId, "sourceId");
        IllegalStateAssertion.assertNotNull(targetId, "targetId");
        LockHandle writeLock = aquireWriteLock();
        try {
            assertValid();
            LOGGER.debug("Create version: {} => {}", sourceId, targetId);
            GitOperation<String> gitop = new GitOperation<String>() {
                public String call(Git git, GitContext context) throws Exception {
                    IllegalStateAssertion.assertNull(checkoutProfileBranch(git, context, targetId, null), "Version already exists: " + targetId);
                    checkoutRequiredProfileBranch(git, context, sourceId, null);
                    createOrCheckoutVersion(git, targetId);
                    if (attributes != null) {
                        setVersionAttributes(git, context, targetId, attributes);
                    }
                    context.commitMessage("Create version: " + sourceId + " => " + targetId);
                    return targetId;
                }
            };
            return executeInternal(context, null, gitop);
        } finally {
            writeLock.unlock();
        }
    }
View Full Code Here

    }

    @Override
    public String createVersion(GitContext context, final Version version) {
        IllegalStateAssertion.assertNotNull(version, "version");
        LockHandle writeLock = aquireWriteLock();
        try {
            assertValid();
            LOGGER.debug("Create version: {}", version);
            GitOperation<String> gitop = new GitOperation<String>() {
                public String call(Git git, GitContext context) throws Exception {
                    String versionId = version.getId();
                    IllegalStateAssertion.assertNull(checkoutProfileBranch(git, context, versionId, null), "Version already exists: " + versionId);
                    GitHelpers.checkoutTag(git, GitHelpers.ROOT_TAG);
                    createOrCheckoutVersion(git, version.getId());
                    setVersionAttributes(git, context, versionId, version.getAttributes());
                    context.commitMessage("Create version: " + version);
                    for (Profile profile : version.getProfiles()) {
                        createOrUpdateProfile(context, null, profile, new HashSet<String>());
                    }
                    return versionId;
                }
            };
            return executeInternal(context, null, gitop);
        } finally {
            writeLock.unlock();
        }
    }
View Full Code Here

        return getVersionIds(newGitReadContext());
    }

    @Override
    public List<String> getVersionIds(GitContext context) {
        LockHandle readLock = aquireReadLock();
        try {
            assertValid();
            GitOperation<List<String>> gitop = new GitOperation<List<String>>() {
                public List<String> call(Git git, GitContext context) throws Exception {
                    List<String> result = new ArrayList<>(versions);
                    // we do not want to expose master branch as a version
                    if (result.contains(GitHelpers.MASTER_BRANCH)) {
                        result.remove(GitHelpers.MASTER_BRANCH);
                    }
                    Collections.sort(result, VersionSequence.getComparator());
                    return Collections.unmodifiableList(result);
                }
            };
            return executeInternal(context, null, gitop);
        } finally {
            readLock.unlock();
        }
    }
View Full Code Here

    }

    @Override
    public boolean hasVersion(GitContext context, final String versionId) {
        IllegalStateAssertion.assertNotNull(versionId, "versionId");
        LockHandle readLock = aquireReadLock();
        try {
            assertValid();
            GitOperation<Boolean> gitop = new GitOperation<Boolean>() {
                public Boolean call(Git git, GitContext context) throws Exception {
                    return versions.contains(versionId);
                }
            };
            return executeInternal(context, null, gitop);
        } finally {
            readLock.unlock();
        }
    }
View Full Code Here

    }

    @Override
    public void deleteVersion(GitContext context, final String versionId) {
        IllegalStateAssertion.assertNotNull(versionId, "versionId");
        LockHandle writeLock = aquireWriteLock();
        try {
            assertValid();
            LOGGER.debug("Delete version: " + versionId);
            GitOperation<Void> gitop = new GitOperation<Void>() {
                public Void call(Git git, GitContext context) throws Exception {
                    removeVersionFromCaches(versionId);
                    GitHelpers.removeBranch(git, versionId);
                    return null;
                }
            };
            executeInternal(context, null, gitop);
        } finally {
            writeLock.unlock();
        }
    }
View Full Code Here

TOP

Related Classes of io.fabric8.api.LockHandle

Copyright © 2018 www.massapicom. 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.