List of usage examples for java.util.concurrent.atomic AtomicReference AtomicReference
public AtomicReference()
From source file:com.microsoft.tfs.client.clc.commands.Command.java
/** * Displays a merge event./*w w w . j a v a 2 s .c o m*/ * * @param e * the event to display */ private void displayMergingEvent(final MergingEvent e) { final AtomicReference<String> errorHolder = new AtomicReference<String>(); final String message = e.getMessage(errorHolder); // Display the merge info. if (e.getStatus() == OperationStatus.CONFLICT) { getDisplay().printErrorLine(message); setExitCode(ExitCode.PARTIAL_SUCCESS); } else { getDisplay().printLine(message); } if (e.getStatus() == OperationStatus.GETTING || e.getStatus() == OperationStatus.REPLACING || e.getStatus() == OperationStatus.DELETING || e.getStatus() == OperationStatus.CONFLICT) { // Nothing to do } else if (e.getStatus() == OperationStatus.SOURCE_DIRECTORY_NOT_EMPTY || e.getStatus() == OperationStatus.SOURCE_WRITABLE || e.getStatus() == OperationStatus.TARGET_IS_DIRECTORY || e.getStatus() == OperationStatus.TARGET_LOCAL_PENDING || e.getStatus() == OperationStatus.TARGET_WRITABLE) { getDisplay().printErrorLine(errorHolder.get()); setExitCode(ExitCode.PARTIAL_SUCCESS); } }
From source file:com.microsoft.tfs.client.clc.commands.Command.java
/** * Displays a {@link GetEvent}.//from w w w .j a v a 2 s .c om * * @param e * the event to display (must not be <code>null</code>) * @param targetName * the target name to use (may be <code>null</code> to use an item * name from the event) */ private void displayGetEvent(final GetEvent e, final String targetName) { final AtomicReference<String> errorHolder = new AtomicReference<String>(); final String message = e.getMessage(targetName, errorHolder); if (e.getStatus() == OperationStatus.CONFLICT || e.getStatus() == OperationStatus.SOURCE_WRITABLE || e.getStatus() == OperationStatus.TARGET_LOCAL_PENDING || e.getStatus() == OperationStatus.TARGET_WRITABLE || e.getStatus() == OperationStatus.SOURCE_DIRECTORY_NOT_EMPTY || e.getStatus() == OperationStatus.TARGET_IS_DIRECTORY || e.getStatus() == OperationStatus.UNABLE_TO_REFRESH) { getDisplay().printErrorLine(errorHolder.get()); setExitCode(ExitCode.PARTIAL_SUCCESS); } else if (e.getStatus() == OperationStatus.GETTING || e.getStatus() == OperationStatus.REPLACING || e.getStatus() == OperationStatus.DELETING) { getDisplay().printLine(message); } }
From source file:de.schildbach.pte.AbstractEfaProvider.java
protected QueryDeparturesResult queryDeparturesMobile(final String stationId, final @Nullable Date time, final int maxDepartures, final boolean equivs) throws IOException { final HttpUrl.Builder url = departureMonitorEndpoint.newBuilder(); appendXsltDepartureMonitorRequestParameters(url, stationId, time, maxDepartures, equivs); final AtomicReference<QueryDeparturesResult> result = new AtomicReference<>(); final HttpClient.Callback callback = new HttpClient.Callback() { @Override/* w ww . j a v a2 s.c om*/ public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException { try { final XmlPullParser pp = parserFactory.newPullParser(); pp.setInput(body.byteStream(), null); // Read encoding from XML declaration final ResultHeader header = enterEfa(pp); final QueryDeparturesResult r = new QueryDeparturesResult(header); XmlPullUtil.require(pp, "dps"); if (XmlPullUtil.optEnter(pp, "dps")) { final Calendar plannedDepartureTime = new GregorianCalendar(timeZone); final Calendar predictedDepartureTime = new GregorianCalendar(timeZone); while (XmlPullUtil.optEnter(pp, "dp")) { // misc /* final String stationName = */normalizeLocationName(XmlPullUtil.valueTag(pp, "n")); /* final boolean isRealtime = */XmlPullUtil.valueTag(pp, "realtime").equals("1"); XmlPullUtil.optSkip(pp, "dt"); // time parseMobileSt(pp, plannedDepartureTime, predictedDepartureTime); final LineDestination lineDestination = parseMobileM(pp, true); XmlPullUtil.enter(pp, "r"); final String assignedId = XmlPullUtil.valueTag(pp, "id"); XmlPullUtil.valueTag(pp, "a"); final Position position = parsePosition(XmlPullUtil.optValueTag(pp, "pl", null)); XmlPullUtil.skipExit(pp, "r"); /* final Point positionCoordinate = */parseCoord( XmlPullUtil.optValueTag(pp, "c", null)); // TODO messages StationDepartures stationDepartures = findStationDepartures(r.stationDepartures, assignedId); if (stationDepartures == null) { stationDepartures = new StationDepartures( new Location(LocationType.STATION, assignedId), new ArrayList<Departure>(maxDepartures), null); r.stationDepartures.add(stationDepartures); } stationDepartures.departures.add(new Departure(plannedDepartureTime.getTime(), predictedDepartureTime.isSet(Calendar.HOUR_OF_DAY) ? predictedDepartureTime.getTime() : null, lineDestination.line, position, lineDestination.destination, null, null)); XmlPullUtil.skipExit(pp, "dp"); } XmlPullUtil.skipExit(pp, "dps"); result.set(r); } else { result.set(new QueryDeparturesResult(header, QueryDeparturesResult.Status.INVALID_STATION)); } } catch (final XmlPullParserException x) { throw new ParserException("cannot parse xml: " + bodyPeek, x); } } }; if (httpPost) httpClient.getInputStream(callback, url.build(), url.build().encodedQuery(), "application/x-www-form-urlencoded", httpReferer); else httpClient.getInputStream(callback, url.build(), httpReferer); return result.get(); }
From source file:com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Workspace.java
/** * @equivalence get(requests, options, null, false, new AtomicReference * <Conflict[]>())//from w w w . j a v a 2 s . c o m */ public GetStatus get(final GetRequest[] requests, final GetOptions options) { return get(requests, options, null, false, new AtomicReference<Conflict[]>()); }
From source file:de.schildbach.pte.AbstractEfaProvider.java
@Override public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to, final Date date, final boolean dep, final @Nullable Set<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed, final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException { final HttpUrl.Builder url = tripEndpoint.newBuilder(); appendXsltTripRequestParameters(url, from, via, to, date, dep, products, optimize, walkSpeed, accessibility, options);/* w ww .ja v a 2 s.co m*/ final AtomicReference<QueryTripsResult> result = new AtomicReference<>(); final HttpClient.Callback callback = new HttpClient.Callback() { @Override public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException { try { result.set(queryTrips(url.build(), body.byteStream())); } catch (final XmlPullParserException x) { throw new ParserException("cannot parse xml: " + bodyPeek, x); } catch (final RuntimeException x) { throw new RuntimeException("uncategorized problem while processing " + url, x); } } }; if (httpPost) httpClient.getInputStream(callback, url.build(), url.build().encodedQuery(), "application/x-www-form-urlencoded", httpRefererTrip); else httpClient.getInputStream(callback, url.build(), httpRefererTrip); return result.get(); }
From source file:de.schildbach.pte.AbstractEfaProvider.java
protected QueryTripsResult queryTripsMobile(final Location from, final @Nullable Location via, final Location to, final Date date, final boolean dep, final @Nullable Collection<Product> products, final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed, final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException { final HttpUrl.Builder url = tripEndpoint.newBuilder(); appendXsltTripRequestParameters(url, from, via, to, date, dep, products, optimize, walkSpeed, accessibility, options);// w w w.ja v a 2 s . co m final AtomicReference<QueryTripsResult> result = new AtomicReference<>(); final HttpClient.Callback callback = new HttpClient.Callback() { @Override public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException { try { result.set(queryTripsMobile(url.build(), from, via, to, body.byteStream())); } catch (final XmlPullParserException x) { throw new ParserException("cannot parse xml: " + bodyPeek, x); } catch (final RuntimeException x) { throw new RuntimeException("uncategorized problem while processing " + url, x); } } }; if (httpPost) httpClient.getInputStream(callback, url.build(), url.build().encodedQuery(), "application/x-www-form-urlencoded", httpRefererTrip); else httpClient.getInputStream(callback, url.build(), httpRefererTrip); return result.get(); }
From source file:de.schildbach.pte.AbstractEfaProvider.java
@Override public QueryTripsResult queryMoreTrips(final QueryTripsContext contextObj, final boolean later) throws IOException { final Context context = (Context) contextObj; final HttpUrl commandUrl = HttpUrl.parse(context.context); final HttpUrl.Builder url = commandUrl.newBuilder(); url.addEncodedQueryParameter("command", later ? "tripNext" : "tripPrev"); final AtomicReference<QueryTripsResult> result = new AtomicReference<>(); final HttpClient.Callback callback = new HttpClient.Callback() { @Override//w w w .j a v a 2s .c o m public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException { try { result.set(queryTrips(url.build(), body.byteStream())); } catch (final XmlPullParserException x) { throw new ParserException("cannot parse xml: " + bodyPeek, x); } catch (final RuntimeException x) { throw new RuntimeException("uncategorized problem while processing " + url, x); } } }; httpClient.getInputStream(callback, url.build(), httpRefererTrip); return result.get(); }
From source file:com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Workspace.java
/** * Pends a change that reverts the contents of one or more items to a * previous version's contents. <!-- Event Origination Info --> * <p>//from www . ja v a2s . c o m * This method is an <b>core event origination point</b>. The * {@link EventSource} object that accompanies each event fired by this * method describes the execution context (current thread, etc.) when and * where this method was invoked. * * @param itemSpecs * the items to roll back (must not be <code>null</code>) * @param itemVersionSpec * the version of the given item specs (may be null) * @param versionFrom * the version to rollback from (not sure) (must not be * <code>null</code>) * @param versionTo * the version to rollback to (not sure) (must not be * <code>null</code>) * @param lockLevel * the lock level for the pending change (must not be * <code>null</code>) * @param options * rollback options (must not be <code>null</code>) * @param itemPropertyFilters * a list of versioned item properties to return with each get * operation (may be <code>null</code>) * @since TFS 2010 */ public GetStatus rollback(final ItemSpec[] itemSpecs, final VersionSpec itemVersionSpec, final VersionSpec versionFrom, final VersionSpec versionTo, final LockLevel lockLevel, final RollbackOptions options, String[] itemPropertyFilters) { Check.notNull(versionFrom, "versionFrom"); //$NON-NLS-1$ Check.notNull(versionTo, "versionTo"); //$NON-NLS-1$ Check.notNull(lockLevel, "lockLevel"); //$NON-NLS-1$ Check.notNull(options, "options"); //$NON-NLS-1$ client.getEventEngine().fireOperationStarted( new RollbackOperationStartedEvent(EventSource.newFromHere(), this, itemSpecs, options)); GetStatus status = null; try { // Using web service directly so merge filters configured on client itemPropertyFilters = client.mergeWithDefaultItemPropertyFilters(itemPropertyFilters); final AtomicReference<Failure[]> failuresHolder = new AtomicReference<Failure[]>(); final AtomicReference<Conflict[]> conflictsHolder = new AtomicReference<Conflict[]>(); final AtomicReference<ChangePendedFlags> changePendedFlagsHolder = new AtomicReference<ChangePendedFlags>(); final GetOperation[] operations = getClient().getWebServiceLayer().rollback(getName(), getOwnerName(), itemSpecs, itemVersionSpec, versionFrom, versionTo, options, lockLevel, conflictsHolder, failuresHolder, null, itemPropertyFilters, changePendedFlagsHolder); final Failure[] failures = failuresHolder.get(); Conflict[] conflicts = conflictsHolder.get(); int nonResolvedConflicts = 0; int resolvedConflicts = 0; final ChangePendedFlags changePendedFlags = changePendedFlagsHolder.get(); /* * Match up these getOps and rollback details (returned as Conflict * objects). The conflicts with matching getOps have already been * resolved. */ final Map<Integer, Conflict> itemIDConflictMap = new HashMap<Integer, Conflict>(); final List<String> conflictPaths = new ArrayList<String>(); for (final Conflict conflict : conflicts) { if (conflict.isResolved()) { itemIDConflictMap.put(new Integer(conflict.getYourItemID()), conflict); } else { conflictPaths.add(conflict.getServerPath()); } } /* * Set the merge details for each of the resolved conflicts we found * previously. */ for (final GetOperation operation : operations) { final Conflict conflict = itemIDConflictMap.get(new Integer(operation.getItemID())); if (conflict != null) { operation.setMergeDetails(conflict); } } if (isLocal()) { // We want to auto resolve conflicts if the option is set if (!options.contains(RollbackOptions.NO_AUTO_RESOLVE)) { if (getClient().getServiceLevel().getValue() < WebServiceLevel.TFS_2012_1.getValue()) { /* * The download urls for base files were not populated * on conflicts in pre 2012 servers. Let's call * QueryConflicts now so that we have that information */ conflicts = queryConflicts(conflictPaths.toArray(new String[conflictPaths.size()]), false); } /* * Try to resolve any AutoResolve candidates and add * failures to the unresolved conflicts list. */ final Conflict[] remainingConflicts = getClient().autoResolveValidConflicts(this, conflicts, AutoResolveOptions.ALL_SILENT); resolvedConflicts = conflicts.length - remainingConflicts.length; conflicts = remainingConflicts; } /* * Fire events for rollback operations that did not get resolved * by the server. The others will get fired in get.cs as they * are processed. */ for (final Conflict conflict : conflicts) { if (conflict.getResolution() == Resolution.NONE) { // The pending change arg is null because of the // conflict. getClient().getEventEngine() .fireMerging(new MergingEvent(EventSource.newFromHere(), conflict, this, false, null, OperationStatus.CONFLICT, ChangeType.NONE, true, new PropertyValue[0])); nonResolvedConflicts++; } } final GetEngine getEngine = new GetEngine(getClient()); status = getEngine.processGetOperations(this, ProcessType.ROLLBACK, operations, GetOptions.NONE, changePendedFlags); status.setNumConflicts(status.getNumConflicts() + nonResolvedConflicts); status.setNumResolvedConflicts(resolvedConflicts); } else if (operations.length > 0) { getClient().getEventEngine() .fireNonFatalError(new NonFatalErrorEvent(EventSource.newFromHere(), getClient(), new Exception(MessageFormat.format(Messages.getString( "Workspace.OperationCompletedForRemoteWorkspaceButGetRequiredFormat"), //$NON-NLS-1$ getDisplayName())))); } if (status == null) { status = new GetStatus(); status.setNumOperations(operations.length); } if (changePendedFlags.contains(ChangePendedFlags.WORKING_FOLDER_MAPPINGS_UPDATED)) { invalidateMappings(); } getClient().reportFailures(this, failures); for (final Failure failure : failures) { status.addFailure(failure); } } finally { getClient().getEventEngine().fireOperationCompleted(new RollbackOperationCompletedEvent( EventSource.newFromHere(), this, itemSpecs, options, status)); Workstation.getCurrent(getClient().getConnection().getPersistenceStoreProvider()) .notifyForWorkspace(this, Notification.VERSION_CONTROL_PENDING_CHANGES_CHANGED); } return status; }
From source file:de.schildbach.pte.AbstractEfaProvider.java
protected QueryTripsResult queryMoreTripsMobile(final QueryTripsContext contextObj, final boolean later) throws IOException { final Context context = (Context) contextObj; final HttpUrl commandUrl = HttpUrl.parse(context.context); final HttpUrl.Builder url = commandUrl.newBuilder(); url.addEncodedQueryParameter("command", later ? "tripNext" : "tripPrev"); final AtomicReference<QueryTripsResult> result = new AtomicReference<>(); final HttpClient.Callback callback = new HttpClient.Callback() { @Override//from www . j a v a 2 s. com public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException { try { result.set(queryTripsMobile(url.build(), null, null, null, body.byteStream())); } catch (final XmlPullParserException x) { throw new ParserException("cannot parse xml: " + bodyPeek, x); } catch (final RuntimeException x) { throw new RuntimeException("uncategorized problem while processing " + url, x); } } }; httpClient.getInputStream(callback, url.build(), httpRefererTrip); return result.get(); }
From source file:com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Workspace.java
/** * Reconciles a local workspace with the server. * * * @param reconcileMissingLocalItems//from w w w. j a v a2 s . co m * True to remove local version rows for items that no longer exist * on disk * @param AtomicBboolean */ public void reconcile(final boolean reconcileMissingLocalItems, final AtomicBoolean pendingChangesUpdatedByServer) { pendingChangesUpdatedByServer.set(false); if (WorkspaceLocation.LOCAL != this.getLocation()) { // No work to do. return; } final AtomicReference<Failure[]> failures = new AtomicReference<Failure[]>(); LocalDataAccessLayer.reconcileLocalWorkspace(this, client.getWebServiceLayer(), false, reconcileMissingLocalItems, failures, pendingChangesUpdatedByServer); client.reportFailures(this, failures.get()); }