blob: 9c1255dab034fca2ed844d4f3c3797f7556e5efe [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2009, 2018 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.rj.servi.rcpdemo;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.statet.internal.rj.servi.rcpdemo.Activator;
import org.eclipse.statet.rj.servi.RServi;
import org.eclipse.statet.rj.services.RService;
public abstract class RJob extends Job {
private final RServiManager rServiManager;
public RJob(final String name) {
super(name);
this.rServiManager= Activator.getInstance().getRServiManager();
setRule(this.rServiManager.getSchedulingRule());
}
@Override
protected IStatus run(final IProgressMonitor monitor) {
RServi servi= null;
try {
servi= this.rServiManager.getRServi(getName());
runRTask(servi, monitor);
}
catch (final CoreException e) {
return new Status(IStatus.ERROR, Activator.BUNDLE_ID,
"An error occurred when running " + getName() + ".", e);
}
finally {
if (servi != null) {
try {
servi.close();
} catch (final CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return Status.OK_STATUS;
}
@Override
public boolean belongsTo(final Object family) {
return this.rServiManager == family;
}
protected abstract void runRTask(RService r, IProgressMonitor monitor) throws CoreException;
}