Example usage for java.util.concurrent.atomic AtomicReference AtomicReference

List of usage examples for java.util.concurrent.atomic AtomicReference AtomicReference

Introduction

In this page you can find the example usage for java.util.concurrent.atomic AtomicReference AtomicReference.

Prototype

public AtomicReference() 

Source Link

Document

Creates a new AtomicReference with null initial value.

Usage

From source file:com.microsoft.tfs.core.clients.versioncontrol.VersionControlClient.java

/**
 * Creates a branch of the given source path at the given version to the
 * given target path.//w  w w  .ja  va2 s .  c  o  m
 * <p>
 * <b>Note</b>
 * <p>
 * This method exists as a fast alternative to the standard method of
 * creating a branch: by pending a branch change, then checking in those
 * changes.
 * </p>
 * <p>
 * Only server paths are accepted.
 * </p>
 * <p>
 * <em>This method is only supported by Team Foundation Server 2008 SP1 and
 * later.</em>
 * </p>
 *
 * @param sourceServerPath
 *        the server path to an existing item which will be branched (must
 *        not be <code>null</code>)
 * @param targetServerPath
 *        the server path to the destination where the branch will be made
 *        (not null).
 * @param version
 *        the version of the source item to branch into the target item (not
 *        null).
 * @param owner
 *        the owner of the changeset that creates the branch (may be null)
 * @param comment
 *        the comment for the changeset that creates the branch (may be
 *        null)
 * @param checkinNote
 *        the checkin note provided with the changeset that creates the
 *        branch (may be null)
 * @param policyOverride
 *        the check-in policy override information for the changeset that
 *        creates the branch (may be null)
 * @param mappings
 *        the mappings to use for the branch (may be null)
 * @return the changeset identifier that resulted from the check-in.
 * @throws UnsupportedOperationException
 *         if this method is used when connected to a server that does not
 *         support branch creation without pending changes.
 */
public int createBranch(final String sourceServerPath, final String targetServerPath, final VersionSpec version,
        final String owner, final String comment, final CheckinNote checkinNote,
        final PolicyOverrideInfo policyOverride, final Mapping[] mappings) {
    Check.notNull(sourceServerPath, "sourcePath"); //$NON-NLS-1$
    Check.notNull(targetServerPath, "targetPath"); //$NON-NLS-1$
    Check.notNull(version, "version"); //$NON-NLS-1$
    Check.isTrue(ServerPath.isServerPath(sourceServerPath), "source path must be a server path"); //$NON-NLS-1$
    Check.isTrue(ServerPath.isServerPath(targetServerPath), "target path must be a server path"); //$NON-NLS-1$

    final Changeset changeset = new Changeset(owner, comment, checkinNote, policyOverride);

    final AtomicReference<Failure[]> failures = new AtomicReference<Failure[]>();

    /*
     * TODO test the wrapper for mappings for 2010. This needs testing
     * because _Mapping is a base class and has a private
     * getWebServiceObject(), but since it's abstract, all derived classes
     * will have a real getWebServiceObject() and the wrapper utils should
     * invoke the derived method.
     */
    final CheckinResult result = getWebServiceLayer().createBranch(sourceServerPath, targetServerPath, version,
            changeset, null, mappings, failures);

    // TODO call ReportCheckinConflictsFailuresAndThrow

    if (result.getChangeset() > 0) {
        eventEngine.fireBranchCommitted(
                new BranchCommittedEvent(EventSource.newFromHere(), sourceServerPath, targetServerPath, version,
                        owner, comment, checkinNote, policyOverride, mappings, result.getChangeset()));

        Workstation.getCurrent(getConnection().getPersistenceStoreProvider())
                .notifyForFolderContentChanged(this, result.getChangeset());
    }

    return result.getChangeset();
}

From source file:com.microsoft.tfs.core.clients.versioncontrol.VersionControlClient.java

/**
 * Create or update a label for items in this workspace.
 *
 * @param label//from  w w w . j  a v  a 2 s  . c  o  m
 *        the label to create or update (must not be <code>null</code>)
 * @param items
 *        the items to be included in the label creation or update (not
 *        null).
 * @param options
 *        options that affect the processing of the label creation or update
 *        (must not be <code>null</code> or empty).
 * @return the label results, null if none were returned. May be empty but
 *         never null.
 */
public LabelResult[] createLabel(final VersionControlLabel label, final LabelItemSpec[] items,
        final LabelChildOption options) {
    Check.notNull(label, "label"); //$NON-NLS-1$
    Check.notNull(items, "items"); //$NON-NLS-1$
    Check.notNull(options, "options"); //$NON-NLS-1$

    final AtomicReference<String> workspaceName = new AtomicReference<String>();
    final AtomicReference<String> workspaceOwner = new AtomicReference<String>();

    determineWorkspaceNameAndOwner(items, workspaceName, workspaceOwner);

    /*
     * Resolve authorized user name (bug 5743)
     */
    label.setOwner(IdentityHelper.getUniqueNameIfCurrentUser(getConnection().getAuthorizedIdentity(),
            label.getOwner()));

    final AtomicReference<Failure[]> failuresHolder = new AtomicReference<Failure[]>();

    final LabelResult[] ret = getWebServiceLayer().labelItem(workspaceName.get(), workspaceOwner.get(), label,
            items, options, failuresHolder);

    reportFailures(failuresHolder.get());

    return ret;
}

From source file:com.microsoft.tfs.core.clients.versioncontrol.VersionControlClient.java

/**
 * Removes a label that was applied to an item.
 *
 * @param label/*  w w  w . ja  v  a2 s .  co m*/
 *        the label to remove (must not be <code>null</code>)
 * @param scope
 *        the scope of the label to remove (must not be <code>null</code>)
 * @param items
 *        the items to remove from the label (must not be <code>null</code>
 *        or empty)
 * @param version
 *        the version of the items to remove to match (may be
 *        <code>null</code>)
 * @return the label results, null if none were returned. May be empty but
 *         never null.
 */
public LabelResult[] unlabelItem(final String label, final String scope, final ItemSpec[] items,
        final VersionSpec version) {
    Check.notNull(label, "label"); //$NON-NLS-1$
    Check.notNullOrEmpty(items, "items"); //$NON-NLS-1$
    Check.notNull(version, "version"); //$NON-NLS-1$

    final AtomicReference<String> workspaceName = new AtomicReference<String>();
    final AtomicReference<String> workspaceOwner = new AtomicReference<String>();

    determineWorkspaceNameAndOwner(items, workspaceName, workspaceOwner);

    final AtomicReference<Failure[]> failuresHolder = new AtomicReference<Failure[]>();

    final LabelResult[] results = getWebServiceLayer().unlabelItem(workspaceName.get(), workspaceOwner.get(),
            label, scope, items, version, failuresHolder);

    reportFailures(failuresHolder.get());

    return results;
}

From source file:com.microsoft.tfs.core.clients.versioncontrol.VersionControlClient.java

/**
 * Query the collection of labels that match the given specifications.
 *
 * @param label/*  w w w.  j  a va2  s.  c  o m*/
 *        the label name to match (may be null?).
 * @param scope
 *        the scope of the label to match (may be null?).
 * @param owner
 *        the owner of the label to match (may be null?).
 * @param includeItemDetails
 *        if true, details about the labeled items are included in the
 *        results, otherwise only general label information is included.
 * @param filterItem
 *        if not <code>null</code>, only labels containing this item are
 *        returned.
 * @param filterItemVersion
 *        if filterItem was supplied, only labels that include this version
 *        of the filterItem are returned, otherwise may be null.
 * @return the label items that matched the query. May be empty but never
 *         null.
 */
public VersionControlLabel[] queryLabels(final String label, final String scope, final String owner,
        final boolean includeItemDetails, final String filterItem, final VersionSpec filterItemVersion) {
    final AtomicReference<String> workspaceName = new AtomicReference<String>();
    final AtomicReference<String> workspaceOwner = new AtomicReference<String>();

    determineWorkspaceNameAndOwner(filterItem, workspaceName, workspaceOwner);

    if (filterItem != null && (workspaceName.get() == null || workspaceOwner.get() == null)
            && ServerPath.isServerPath(filterItem) == false) {
        Check.isTrue(false,
                MessageFormat.format("Could not determine the workspace for local path {0}", filterItem)); //$NON-NLS-1$
    }

    return getWebServiceLayer().queryLabels(workspaceName.get(), workspaceOwner.get(), label, scope, owner,
            filterItem, filterItemVersion, includeItemDetails, true);
}

From source file:com.microsoft.tfs.core.clients.versioncontrol.VersionControlClient.java

/**
 * Get pending changes for the given item specs, even from another user's
 * workspace.//ww w  . j  ava2 s .  c o m
 *
 * @param itemSpecs
 *        the ItemSpecs to get pending changes for (must not be
 *        <code>null</code> or empty)
 * @param queryWorkspaceName
 *        the name of the workspace to query for pending changes. Pass null
 *        to match all.
 * @param queryWorkspaceOwner
 *        the owner of the workspace to query for pending changes. Pass null
 *        to match all.
 * @param includeCandidates
 *        if <code>true</code> for a local workspace, candidate changes will
 *        be populated on the pending set. A pending set will be returned if
 *        the workspace contains pending changes or candidate changes
 * @param itemPropertyFilters
 *        a list of property names to return on the pending change object if
 *        they exist (may be <code>null</code>)
 * @return a pending set including all the pending changes. May be empty but
 *         never null.
 */
public PendingSet[] queryPendingSets(final ItemSpec[] itemSpecs, final boolean includeDownloadInfo,
        final String queryWorkspaceName, final String queryWorkspaceOwner, final boolean includeCandidates,
        String[] itemPropertyFilters) {
    Check.notNullOrEmpty(itemSpecs, "itemSpecs"); //$NON-NLS-1$

    itemPropertyFilters = mergeWithDefaultItemPropertyFilters(itemPropertyFilters);

    final AtomicReference<String> workspaceName = new AtomicReference<String>();
    final AtomicReference<String> workspaceOwner = new AtomicReference<String>();

    determineWorkspaceNameAndOwner(itemSpecs, workspaceName, workspaceOwner);

    final AtomicReference<Failure[]> failures = new AtomicReference<Failure[]>();

    final PendingSet[] ret = getWebServiceLayer().queryPendingSets(workspaceName.get(), workspaceOwner.get(),
            queryWorkspaceName, queryWorkspaceOwner, itemSpecs, includeDownloadInfo, failures,
            includeCandidates, itemPropertyFilters);

    reportFailures(failures.get());

    return ret;
}

From source file:com.microsoft.tfs.core.clients.versioncontrol.VersionControlClient.java

/**
 * Gets the shelved changes for the given item specs.
 *
 * @param shelvesetName/*from  www.  ja  v a  2s . c  o  m*/
 *        the shelveset name (may be null)
 * @param shelvesetOwner
 *        the user name (may be null), which is the shelveset owner if the
 *        shelveset name is not <code>null</code>
 * @param itemSpecs
 *        the items to query changes for (null for all).
 * @param includeDownloadInfo
 *        If true, the server will include the information needed to
 *        download files. Only set this to true if you are going to be
 *        downloading the files using the objects that are returned. The
 *        call will be faster and require less bandwidth when this parameter
 *        is false (default for overloads that don't specify it)
 * @param itemPropertyFilters
 *        a list of property names to return on the pending change object if
 *        they exist (may be <code>null</code>)
 * @return an array of pending sets with the pending changes for the shelved
 *         changes. May be empty but never null.
 */
public PendingSet[] queryShelvedChanges(final String shelvesetName, final String shelvesetOwner,
        final ItemSpec[] itemSpecs, final boolean includeDownloadInfo, String[] itemPropertyFilters) {
    final AtomicReference<String> workspaceName = new AtomicReference<String>();
    final AtomicReference<String> workspaceOwner = new AtomicReference<String>();

    determineWorkspaceNameAndOwner(itemSpecs, workspaceName, workspaceOwner);

    itemPropertyFilters = mergeWithDefaultItemPropertyFilters(itemPropertyFilters);

    return queryShelvedChanges(workspaceName.get(), workspaceOwner.get(), shelvesetName, shelvesetOwner,
            itemSpecs, includeDownloadInfo, itemPropertyFilters);
}

From source file:com.microsoft.tfs.core.clients.versioncontrol.VersionControlClient.java

/**
 * Gets the shelved changes for the given item specs.
 *
 * @param workspaceName// w  w w.j a va 2  s. co m
 *        the name of the workspace to query for (may be <code>null</code>)
 * @param workspaceOwner
 *        the owner of the workspace to query for (may be <code>null</code>)
 * @param shelvesetName
 *        the shelveset name (may be null)
 * @param shelvesetOwner
 *        the user name (may be null), which is the shelveset owner if the
 *        shelveset name is not <code>null</code>
 * @param itemSpecs
 *        the items to query changes for (null for all).
 * @param includeDownloadInfo
 *        If true, the server will include the information needed to
 *        download files. Only set this to true if you are going to be
 *        downloading the files using the objects that are returned. The
 *        call will be faster and require less bandwidth when this parameter
 *        is false (default for overloads that don't specify it)
 * @param itemPropertyFilters
 *        a list of property names to return on the pending change object if
 *        they exist (may be <code>null</code>)
 * @return an array of pending sets with the pending changes for the shelved
 *         changes. May be empty but never null.
 */
public PendingSet[] queryShelvedChanges(final String workspaceName, final String workspaceOwner,
        final String shelvesetName, final String shelvesetOwner, final ItemSpec[] itemSpecs,
        final boolean includeDownloadInfo, String[] itemPropertyFilters) {
    final AtomicReference<Failure[]> failures = new AtomicReference<Failure[]>();

    itemPropertyFilters = mergeWithDefaultItemPropertyFilters(itemPropertyFilters);

    final PendingSet[] ret = getWebServiceLayer().queryShelvedChanges(workspaceName, workspaceOwner,
            shelvesetName, shelvesetOwner, itemSpecs, includeDownloadInfo, failures, itemPropertyFilters);

    reportFailures(failures.get());

    return ret;
}

From source file:com.microsoft.tfs.core.clients.versioncontrol.VersionControlClient.java

/**
 * Look up the merge candidates for merging between the requested items.
 *
 * @param sourcePath/*w  w w  . j a va  2s  .  com*/
 *        the local or server path of the source of the potential merge
 *        (must not be <code>null</code> or empty)
 * @param targetPath
 *        the local or server path of the target of the potential merge
 *        (must not be <code>null</code> or empty)
 * @param recursion
 *        what level of recursion we should apply to the candidate search
 *        (may be <code>null</code>).
 * @param mergeFlags
 *        merge command option(s) compatible with the /cadidate option (must
 *        not be <code>null</code>).
 * @return the array of merge candidates returned by the server. May be
 *         empty but never <code>null</code>.
 */
public MergeCandidate[] getMergeCandidates(final String sourcePath, final String targetPath,
        final RecursionType recursion, final MergeFlags mergeFlags) {
    Check.notNullOrEmpty(sourcePath, "sourcePath"); //$NON-NLS-1$
    Check.notNullOrEmpty(targetPath, "targetPath"); //$NON-NLS-1$
    Check.notNull(mergeFlags, "mergeFlags"); //$NON-NLS-1$

    final AtomicReference<String> workspaceName = new AtomicReference<String>();
    final AtomicReference<String> workspaceOwner = new AtomicReference<String>();

    determineWorkspaceNameAndOwner(new String[] { sourcePath, targetPath }, workspaceName, workspaceOwner);

    return getWebServiceLayer().queryMergeCandidates(workspaceName.get(), workspaceOwner.get(),
            new ItemSpec(sourcePath, recursion), new ItemSpec(targetPath, recursion), mergeFlags);
}

From source file:com.microsoft.tfs.core.clients.versioncontrol.VersionControlClient.java

/**
 * Gets information about merges performed on the given target item (and
 * version), optionally qualified by a source item (which can be null).
 *
 * @param sourceItem/*from ww w.  jav  a2  s . co  m*/
 *        the item that is the source of merges to be returned (may be
 *        <code>null</code>)
 * @param sourceVersion
 *        the version of the source item for the merges (may be
 *        <code>null</code> if sourceItem is <code>null</code>)
 * @param targetItem
 *        the item that is the target of merges to be returned (must not be
 *        <code>null</code> or empty)
 *
 * @param targetVersion
 *        the version of the target item for the merges (must not be
 *        <code>null</code>)
 * @param versionFrom
 *        the oldest version to be included in the results (may be
 *        <code>null</code>)
 * @param versionTo
 *        the most recent version to be included in the results (may be
 *        <code>null</code>)
 * @param recursion
 *        the type of recursion to apply to the given items (must not be
 *        <code>null</code>)
 * @return the {@link ChangesetMerge}s returned by the server. May be empty
 *         but never <code>null</code>.
 */
public ChangesetMerge[] queryMerges(final String sourceItem, final VersionSpec sourceVersion,
        final String targetItem, final VersionSpec targetVersion, final VersionSpec versionFrom,
        final VersionSpec versionTo, final RecursionType recursion) {
    Check.notNull(targetItem, "targetItem"); //$NON-NLS-1$
    Check.notNull(targetVersion, "targetVersion"); //$NON-NLS-1$
    Check.notNull(recursion, "recursion"); //$NON-NLS-1$

    final List<String> allPaths = new ArrayList<String>(2);

    ItemSpec sourceItemSpec = null;
    if (sourceItem != null) {
        sourceItemSpec = new ItemSpec(sourceItem, recursion);
        allPaths.add(sourceItem);
    }

    final ItemSpec targetItemSpec = new ItemSpec(targetItem, recursion);
    allPaths.add(targetItem);

    final AtomicReference<String> workspaceName = new AtomicReference<String>();
    final AtomicReference<String> workspaceOwner = new AtomicReference<String>();

    determineWorkspaceNameAndOwner(allPaths.toArray(new String[allPaths.size()]), workspaceName,
            workspaceOwner);

    final AtomicReference<Changeset[]> changesetsHolder = new AtomicReference<Changeset[]>();

    final ChangesetMerge[] merges = getWebServiceLayer().queryMerges(workspaceName.get(), workspaceOwner.get(),
            sourceItemSpec, sourceVersion, targetItemSpec, targetVersion, versionFrom, versionTo,
            VersionControlConstants.MAX_MERGES_RESULTS, true, changesetsHolder);

    /*
     * Hook up the changesets that came back into the merge objects this
     * method returns.
     */
    if (merges != null) {
        final Map<Integer, Changeset> changesetIDToChangesetMap = new HashMap<Integer, Changeset>();

        /*
         * Map all the changesets by ID so we can hook them into the merges
         * that have matching target versions.
         */
        final Changeset[] changesets = changesetsHolder.get();
        if (changesets != null && changesets.length > 0) {
            for (int i = 0; i < changesets.length; i++) {
                changesetIDToChangesetMap.put(new Integer(changesets[i].getChangesetID()), changesets[i]);
            }
        }

        for (int i = 0; i < merges.length; i++) {
            merges[i].setTargetChangeset(
                    changesetIDToChangesetMap.get(new Integer(merges[i].getTargetVersion())));
        }
    }

    return merges;
}

From source file:com.microsoft.tfs.core.clients.versioncontrol.VersionControlClient.java

/**
 * Gets detailed information about merges performed on the given target item
 * (and version), optionally qualified by a source item (which can be null).
 *
 * @param sourceItem//from  w  ww.  jav a 2 s  .  c  om
 *        the item that is the source of merges to be returned (may be null)
 * @param sourceVersion
 *        the version of the source item for the merges (may be null if
 *        sourceItem is null)
 * @param sourceDeletionID
 *        the deletion ID for the source item, if a specific deletion is
 *        being queried.
 * @param targetItem
 *        the item that is the target of merges to be returned (must not be
 *        <code>null</code> or empty)
 * @param targetVersion
 *        the version of the target item for the merges (must not be
 *        <code>null</code>)
 * @param targetDeletionID
 *        the deletion ID for the target item, if a specific deletion is
 *        being queried.
 * @param versionFrom
 *        the oldest version to be included in the results (may be null)
 * @param versionTo
 *        the most recent version to be included in the results (may be
 *        null)
 * @param recursion
 *        the type of recursion to apply to the given items (must not be
 *        <code>null</code>)
 * @return the {@link ChangesetMergeDetails} returned by the server.
 */
public ChangesetMergeDetails queryMergesWithDetails(final String sourceItem, final VersionSpec sourceVersion,
        final int sourceDeletionID, final String targetItem, final VersionSpec targetVersion,
        final int targetDeletionID, final VersionSpec versionFrom, final VersionSpec versionTo,
        final RecursionType recursion) {
    Check.notNull(targetItem, "targetItem"); //$NON-NLS-1$
    Check.notNull(targetVersion, "targetVersion"); //$NON-NLS-1$
    Check.notNull(recursion, "recursion"); //$NON-NLS-1$

    final List<String> allPaths = new ArrayList<String>(2);
    ItemSpec sourceItemSpec = null;
    if (sourceItem != null) {
        sourceItemSpec = new ItemSpec(sourceItem, recursion, sourceDeletionID);
        allPaths.add(sourceItem);
    }

    final ItemSpec targetItemSpec = new ItemSpec(targetItem, recursion, targetDeletionID);
    allPaths.add(targetItem);

    final AtomicReference<String> workspaceName = new AtomicReference<String>();
    final AtomicReference<String> workspaceOwner = new AtomicReference<String>();

    determineWorkspaceNameAndOwner(allPaths.toArray(new String[allPaths.size()]), workspaceName,
            workspaceOwner);

    return getWebServiceLayer().queryMergesWithDetails(workspaceName.get(), workspaceOwner.get(),
            sourceItemSpec, sourceVersion, targetItemSpec, targetVersion, versionFrom, versionTo,
            VersionControlConstants.MAX_MERGES_RESULTS, true);
}