Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 368854
Collapse All | Expand All

(-)a/bundles/org.eclipse.orion.server.core/src/org/eclipse/orion/internal/server/core/tasks/TaskService.java (-19 / +19 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
2
 * Copyright (c) 2011, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 85-104 Link Here
85
85
86
		private String userId;
86
		private String userId;
87
		private Date deletionDate;
87
		private Date deletionDate;
88
		private Collection<String> tasks;
89
88
90
		public DeletedTasksNotificationJob(String userId, Date deletionDate, Collection<String> tasks) {
89
		public DeletedTasksNotificationJob(String userId, Date deletionDate) {
91
			super("Notyfing task listeners");
90
			super("Notyfing task listeners");
92
			this.userId = userId;
91
			this.userId = userId;
93
			this.deletionDate = deletionDate;
92
			this.deletionDate = deletionDate;
94
			this.tasks = tasks;
95
		}
93
		}
96
94
97
		@Override
95
		@Override
98
		protected IStatus run(IProgressMonitor monitor) {
96
		protected IStatus run(IProgressMonitor monitor) {
99
			synchronized (taskListeners) {
97
			synchronized (taskListeners) {
100
				for (TaskModificationListener listener : taskListeners) {
98
				for (TaskModificationListener listener : taskListeners) {
101
					listener.tasksDeleted(userId, tasks, deletionDate);
99
					listener.tasksDeleted(userId, deletionDate);
102
				}
100
				}
103
			}
101
			}
104
			return Status.OK_STATUS;
102
			return Status.OK_STATUS;
Lines 137-143 Link Here
137
		return createTask(taskName, userId, null, isIdempotent);
135
		return createTask(taskName, userId, null, isIdempotent);
138
	}
136
	}
139
137
140
	private TaskInfo internalRemoveTask(String userId, String id) throws TaskOperationException {
138
	private TaskInfo internalRemoveTask(String userId, String id, Date dateRemoved) throws TaskOperationException {
141
		TaskInfo task = getTask(userId, id);
139
		TaskInfo task = getTask(userId, id);
142
		if (task == null)
140
		if (task == null)
143
			throw new TaskDoesNotExistException(id);
141
			throw new TaskDoesNotExistException(id);
Lines 149-178 Link Here
149
		if (!taskDeletions.containsKey(userId)) {
147
		if (!taskDeletions.containsKey(userId)) {
150
			taskDeletions.put(userId, new ArrayList<TaskService.TaskDeletion>());
148
			taskDeletions.put(userId, new ArrayList<TaskService.TaskDeletion>());
151
		}
149
		}
152
		taskDeletions.get(userId).add(new TaskDeletion(new Date(), id));
150
		int i = taskDeletions.get(userId).size();
151
		while(i>0 && taskDeletions.get(userId).get(i-1).deletionDate.after(dateRemoved)){
152
			i--;
153
		}
154
		taskDeletions.get(userId).add(i, new TaskDeletion(dateRemoved, id));
153
		return task;
155
		return task;
154
	}
156
	}
155
157
156
	public void removeTask(String userId, String id) throws TaskOperationException {
158
	public void removeTask(String userId, String id) throws TaskOperationException {
157
		internalRemoveTask(userId, id);
159
		Date date = new Date();
158
		Set<String> tasks = new HashSet<String>();
160
		internalRemoveTask(userId, id, date);
159
		tasks.add(id);
161
		notifyDeletionListeners(userId, date);
160
		notifyDeletionListeners(userId, new Date(), tasks);
161
	}
162
	}
162
163
163
	public void removeCompletedTasks(String userId) {
164
	public void removeCompletedTasks(String userId) {
164
		Set<String> tasks = new HashSet<String>();
165
		Date date = new Date();
165
		for (TaskInfo task : getTasks(userId)) {
166
		for (TaskInfo task : getTasks(userId)) {
166
			if (!task.isRunning()) {
167
			if (!task.isRunning()) {
167
				try {
168
				try {
168
					internalRemoveTask(userId, task.getTaskId());
169
					internalRemoveTask(userId, task.getTaskId(), date);
169
					tasks.add(task.getTaskId());
170
				} catch (TaskOperationException e) {
170
				} catch (TaskOperationException e) {
171
					LogHelper.log(e);
171
					LogHelper.log(e);
172
				}
172
				}
173
			}
173
			}
174
		}
174
		}
175
		notifyDeletionListeners(userId, new Date(), tasks);
175
		notifyDeletionListeners(userId, date);
176
	}
176
	}
177
177
178
	public TaskInfo createTask(String taskName, String userId, ITaskCanceler taskCanceler, boolean isIdempotent) {
178
	public TaskInfo createTask(String taskName, String userId, ITaskCanceler taskCanceler, boolean isIdempotent) {
Lines 191-198 Link Here
191
		new TasksNotificationJob(userId, modificationDate).schedule();
191
		new TasksNotificationJob(userId, modificationDate).schedule();
192
	}
192
	}
193
193
194
	private void notifyDeletionListeners(String userId, Date deletionDate, Collection<String> tasks) {
194
	private void notifyDeletionListeners(String userId, Date deletionDate) {
195
		new DeletedTasksNotificationJob(userId, deletionDate, tasks).schedule();
195
		new DeletedTasksNotificationJob(userId, deletionDate).schedule();
196
	}
196
	}
197
197
198
	public TaskInfo getTask(String userId, String id) {
198
	public TaskInfo getTask(String userId, String id) {
Lines 256-265 Link Here
256
		}
256
		}
257
	}
257
	}
258
258
259
	public Collection<String> getTasksDeletedSince(String userId, Date deletedSince) {
259
	public synchronized Collection<String> getTasksDeletedSince(String userId, Date deletedSince) {
260
		Set<String> deletedTasks = new HashSet<String>();
260
		Set<String> deletedTasks = new HashSet<String>();
261
		List<TaskDeletion> taskDeletionsList = taskDeletions.get(userId);
261
		List<TaskDeletion> taskDeletionsList = taskDeletions.get(userId);
262
		if (taskDeletionsList == null) {
262
		if (taskDeletionsList == null || deletedSince==null) {
263
			return deletedTasks;
263
			return deletedTasks;
264
		}
264
		}
265
		for (int i = taskDeletionsList.size() - 1; i > 0; i--) {
265
		for (int i = taskDeletionsList.size() - 1; i > 0; i--) {
(-)a/bundles/org.eclipse.orion.server.core/src/org/eclipse/orion/server/core/tasks/TaskModificationListener.java (-3 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
2
 * Copyright (c) 2011, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.orion.server.core.tasks;
11
package org.eclipse.orion.server.core.tasks;
12
12
13
import java.util.Collection;
14
import java.util.Date;
13
import java.util.Date;
15
14
16
/**
15
/**
Lines 30-35 Link Here
30
	 * Called {@link ITaskService} when tasks are deleted.
29
	 * Called {@link ITaskService} when tasks are deleted.
31
	 * @param tasks a list of tasks that where deleted
30
	 * @param tasks a list of tasks that where deleted
32
	 */
31
	 */
33
	public void tasksDeleted(String userId, Collection<String> taskIds, Date deletedDate);
32
	public void tasksDeleted(String userId, Date deletedDate);
34
33
35
}
34
}
(-)a/bundles/org.eclipse.orion.server.servlets/src/org/eclipse/orion/internal/server/servlets/task/TaskNonotificationRegistry.java (-23 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
2
 * Copyright (c) 2011, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 94-119 Link Here
94
				return;
94
				return;
95
			if (!this.userId.equals(userId))
95
			if (!this.userId.equals(userId))
96
				return;
96
				return;
97
			notify(modificationDate, service.getTasks(userId, lastNodifications.get(getName()), false), new HashSet<String>());
97
			Date lastNotification = lastNodifications.get(getName());
98
			notify(modificationDate, service.getTasks(userId, lastNotification, false), service.getTasksDeletedSince(userId, lastNotification));
98
99
99
		}
100
		}
100
101
101
		public synchronized void tasksDeleted(String userId, Collection<String> taskIds, Date timestamp) {
102
		public synchronized void tasksDeleted(String userId, Date timestamp) {
102
			if (wasNotified)
103
			if (wasNotified)
103
				return;
104
				return;
104
			if (!this.userId.equals(userId))
105
			if (!this.userId.equals(userId))
105
				return;
106
				return;
106
			wasNotified = true;
107
			notify(timestamp, new ArrayList<TaskInfo>(), service.getTasksDeletedSince(userId, lastNodifications.get(getName())));
107
			listeners.remove(getName());
108
			try {
109
				TaskServlet.writeJSONResponse(req, resp, servlet.getTasksList(new ArrayList<TaskInfo>(), taskIds, timestamp, req, resp));
110
				lastNodifications.put(getName(), timestamp);
111
			} catch (Exception e) {
112
				this.done(new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e));
113
				return;
114
			}
115
116
			this.done(Status.OK_STATUS);
117
		}
108
		}
118
	}
109
	}
119
110
Lines 158-174 Link Here
158
		if (notifyNow) {
149
		if (notifyNow) {
159
			Date timestamp = new Date();
150
			Date timestamp = new Date();
160
			List<TaskInfo> tasks = service.getTasks(userId, lastNodifications.get(longpollingId) == null ? null : lastNodifications.get(longpollingId), false);
151
			List<TaskInfo> tasks = service.getTasks(userId, lastNodifications.get(longpollingId) == null ? null : lastNodifications.get(longpollingId), false);
161
			if (!tasks.isEmpty()) {
152
			Collection<String> tasksDeleted = service.getTasksDeletedSince(userId, lastNodifications.get(longpollingId));
162
				listenerJob.notify(timestamp, tasks, new HashSet<String>());
153
			if (!tasks.isEmpty() || !tasksDeleted.isEmpty()) {
154
				listenerJob.notify(timestamp, tasks, tasksDeleted);
163
				listenerJob.schedule();
155
				listenerJob.schedule();
164
				return listenerJob;
156
				return listenerJob;
165
			}
166
		}
167
168
		if (lastNodifications.get(longpollingId) != null) {
169
			Collection<String> tasksDeleted = service.getTasksDeletedSince(userId, lastNodifications.get(longpollingId));
170
			if (tasksDeleted.size() > 0) {
171
				listenerJob.notify(new Date(), new ArrayList<TaskInfo>(), tasksDeleted);
172
			}
157
			}
173
		}
158
		}
174
159

Return to bug 368854