Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 17dcc8fbac4849c9b878df740422e76a1868801b (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
/*******************************************************************************
 * Copyright (c) 2012, 2013 Oracle. 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:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.common.core.internal.utility.command;

import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jpt.common.core.utility.command.CombinedCommandContext;
import org.eclipse.jpt.common.core.utility.command.JobCommand;
import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.common.utility.command.StatefulCommandContext;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.common.utility.internal.command.AbstractSingleUseQueueingCommandExecutor;

/**
 * This job command context wraps and extends an
 * {@link AbstractSingleUseQueueingCommandExecutor},
 * adding support for executing {@link JobCommand}s.
 * <p>
 * <strong>NB:</strong> This context <em>ignores</em> any
 * {@link ISchedulingRule scheduling rules}.
 */
public abstract class AbstractSingleUseQueueingJobCommandContext<E1 extends AbstractSingleUseQueueingCommandExecutor<E2>, E2 extends StatefulCommandContext>
	implements CombinedCommandContext, StatefulCommandContext
{
	/**
	 * Since the {@link JobCommand}s are simply converted into {@link Command}s,
	 * we can delegate to an {@link AbstractSingleUseQueueingCommandExecutor}.
	 */
	protected final E1 commandExecutor;


	protected AbstractSingleUseQueueingJobCommandContext(E1 commandExecutor) {
		super();
		this.commandExecutor = commandExecutor;
	}

	/**
	 * @see AbstractSingleUseQueueingCommandExecutor#start()
	 */
	public void start() {
		this.commandExecutor.start();
	}

	/**
	 * @see AbstractSingleUseQueueingCommandExecutor#execute(Command)
	 */
	public void execute(Command command) {
		this.commandExecutor.execute(command);
	}

	/**
	 * @see AbstractSingleUseQueueingCommandExecutor#execute(Command)
	 */
	public void execute(JobCommand command) {
		this.commandExecutor.execute(new JobCommandCommandAdapter(command));
	}

	/**
	 * @see AbstractSingleUseQueueingCommandExecutor#execute(Command)
	 */
	public void execute(JobCommand command, String jobName) {
		// ignore 'jobName'
		this.commandExecutor.execute(new JobCommandCommandAdapter(command));
	}

	/**
	 * @see AbstractSingleUseQueueingCommandExecutor#execute(Command)
	 */
	public void execute(JobCommand command, String jobName, ISchedulingRule rule) {
		// ignore 'jobName' and 'rule'
		this.commandExecutor.execute(new JobCommandCommandAdapter(command));
	}

	/**
	 * @see AbstractSingleUseQueueingCommandExecutor#suspend()
	 */
	public void suspend() {
		this.commandExecutor.suspend();
	}

	/**
	 * @see AbstractSingleUseQueueingCommandExecutor#resume()
	 */
	public void resume() {
		this.commandExecutor.resume();
	}

	/**
	 * @see AbstractSingleUseQueueingCommandExecutor#stop()
	 */
	public void stop() throws InterruptedException {
		this.commandExecutor.stop();
	}

	@Override
	public String toString() {
		return ObjectTools.toString(this, this.commandExecutor);
	}
}

Back to the top