Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: be0aec99257487c83954711b74ac0e871ce59983 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*******************************************************************************
 * Copyright (c) 2000, 2017 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.core.subscribers;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.core.synchronize.ISyncInfoSetChangeListener;
import org.eclipse.team.core.synchronize.SyncInfoTree;
import org.eclipse.team.internal.core.Policy;

/**
 * The <code>SubscriberSyncInfoSet</code> is a <code>SyncInfoSet</code> that provides the ability to add,
 * remove and change <code>SyncInfo</code> and fires change event notifications to registered listeners.
 * It also provides the ability
 * to batch changes in a single change notification as well as optimizations for sync info retrieval.
 *
 * This class uses synchronized methods and synchronized blocks to protect internal data structures during both access
 * and modify operations and uses an <code>ILock</code> to make modification operations thread-safe. The events
 * are fired while this lock is held so clients responding to these events should not obtain their own internal locks
 * while processing change events.
 *
 * TODO: Override modification methods to enforce use with handler
 *
 */
public class SubscriberSyncInfoSet extends SyncInfoTree {

	protected SubscriberEventHandler handler;

	public SubscriberSyncInfoSet(SubscriberEventHandler handler) {
		this.handler = handler;
	}

	@Override
	public void connect(ISyncInfoSetChangeListener listener, IProgressMonitor monitor) {
		if (handler == null) {
			super.connect(listener, monitor);
		} else {
			connect(listener);
		}
	}

	/**
	 * Variation of connect that does not need progress and does not throw an exception.
	 * Progress is provided by the background event handler and errors are passed through
	 * the chain to the view.
	 * @param listener
	 */
	public void connect(final ISyncInfoSetChangeListener listener) {
		if (handler == null) {
			// Should only use this connect if the set has a handler
			throw new UnsupportedOperationException();
		} else {
			handler.run(monitor -> {
				try {
					beginInput();
					monitor.beginTask(null, 100);
					removeSyncSetChangedListener(listener);
					addSyncSetChangedListener(listener);
					listener.syncInfoSetReset(SubscriberSyncInfoSet.this, Policy.subMonitorFor(monitor, 95));
				} finally {
					endInput(Policy.subMonitorFor(monitor, 5));
					monitor.done();
				}
			}, true /* high priority */);
		}
	}
}

Back to the top