blob: 594c9cd4f8ff87a6529821ccf0138a886a483426 (
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*******************************************************************************
* Copyright (c) 2004, 2009 Tasktop Technologies 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:
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.tasks.core.sync;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.commons.net.Policy;
import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.RepositoryResponse;
/**
* @author Steffen Pingel
* @since 3.0
* @noextend This class is not intended to be subclassed by clients.
*/
public abstract class SubmitJob extends TaskJob {
private final List<SubmitJobListener> submitJobListeners = Collections.synchronizedList(new ArrayList<SubmitJobListener>());
/**
* @since 3.0
*/
public SubmitJob(String name) {
super(name);
}
/**
* @since 3.0
*/
public void addSubmitJobListener(SubmitJobListener listener) {
submitJobListeners.add(listener);
}
/**
* @since 3.0
*/
public void removeSubmitJobListener(SubmitJobListener listener) {
submitJobListeners.remove(listener);
}
/**
* @since 3.0
*/
protected SubmitJobListener[] getSubmitJobListeners() {
return submitJobListeners.toArray(new SubmitJobListener[0]);
}
/**
* @since 3.0
*/
protected void fireTaskSubmitted(final IProgressMonitor monitor) throws CoreException {
SubmitJobListener[] listeners = submitJobListeners.toArray(new SubmitJobListener[0]);
if (listeners.length > 0) {
final SubmitJobEvent event = new SubmitJobEvent(this);
for (final SubmitJobListener listener : listeners) {
listener.taskSubmitted(event, Policy.subMonitorFor(monitor, 100));
}
}
}
/**
* @since 3.0
*/
protected void fireTaskSynchronized(final IProgressMonitor monitor) throws CoreException {
SubmitJobListener[] listeners = submitJobListeners.toArray(new SubmitJobListener[0]);
if (listeners.length > 0) {
final SubmitJobEvent event = new SubmitJobEvent(this);
for (final SubmitJobListener listener : listeners) {
listener.taskSynchronized(event, Policy.subMonitorFor(monitor, 100));
}
}
}
/**
* @since 3.0
*/
protected void fireDone() {
SubmitJobListener[] listeners = submitJobListeners.toArray(new SubmitJobListener[0]);
if (listeners.length > 0) {
final SubmitJobEvent event = new SubmitJobEvent(this);
for (final SubmitJobListener listener : listeners) {
SafeRunner.run(new ISafeRunnable() {
public void handleException(Throwable e) {
StatusHandler.log(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN, "Listener failed", e)); //$NON-NLS-1$
}
public void run() throws Exception {
listener.done(event);
}
});
}
}
}
/**
* @since 3.0
*/
public abstract ITask getTask();
/**
* Returns the connector specific result of the submission.
*
* @return the response from the repository, null if no response was received or the submission failed
* @since 3.2
*/
public abstract RepositoryResponse getResponse();
}
|