Eclipse plugin Eclipse-找到工作
我想找到特定的作业,停止它,然后再次运行。作业是在Eclipse启动之后安排的,并重新安排。下面:给定文章的示例3,我重写了belongsTo方法,但是当我使用jobManager查找作业时,它找不到它。 工作类别:Eclipse plugin Eclipse-找到工作,eclipse-plugin,Eclipse Plugin,我想找到特定的作业,停止它,然后再次运行。作业是在Eclipse启动之后安排的,并重新安排。下面:给定文章的示例3,我重写了belongsTo方法,但是当我使用jobManager查找作业时,它找不到它。 工作类别: public class PollFeedJob extends Job implements IPollFeedJob { private final String jobId; private final NotificationEnvironment environment;
public class PollFeedJob extends Job implements IPollFeedJob {
private final String jobId;
private final NotificationEnvironment environment;
private final Map<FeedDescriptor, List<IFeedMessage>> groupedMessages = Maps.newHashMap();
private final Map<FeedDescriptor, Date> pollDates = Maps.newHashMap();
private Set<FeedDescriptor> feeds = Sets.newHashSet();
public PollFeedJob(String jobId, Collection<FeedDescriptor> feeds) {
super(jobId);
Preconditions.checkNotNull(jobId);
Preconditions.checkNotNull(feeds);
this.jobId = jobId;
this.environment = new NotificationEnvironment();
this.feeds.addAll(feeds);
setSystem(true);
setPriority(DECORATE);
setRule(new MutexRule());
}
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
for (FeedDescriptor feed : feeds) {
List<IFeedMessage> messages;
HttpURLConnection connection = (HttpURLConnection) feed.getUrl().openConnection();
try {
connection.connect();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK && !monitor.isCanceled()) {
InputStream in = new BufferedInputStream(connection.getInputStream());
try {
messages = Lists.newArrayList(readMessages(in, monitor, feed.getId()));
groupedMessages.put(feed, messages);
} finally {
in.close();
}
}
} finally {
connection.disconnect();
}
pollDates.put(feed, new Date());
}
} catch (Exception e) {
System.out.println(e.getCause());
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
@Override
public boolean belongsTo(Object job) {
if (job == null) {
return false;
}
return jobId.equals(job);
}
private List<? extends IFeedMessage> readMessages(InputStream in, IProgressMonitor monitor, String eventId)
throws IOException {
//not related code
}
@Override
public Map<FeedDescriptor, List<IFeedMessage>> getMessages() {
return groupedMessages;
}
@Override
public Map<FeedDescriptor, Date> getPollDates() {
return pollDates;
}
public String getJobId() {
return jobId;
}
class MutexRule implements ISchedulingRule {
@Override
public boolean contains(ISchedulingRule rule) {
return rule == this;
}
@Override
public boolean isConflicting(ISchedulingRule rule) {
return rule == this;
}
}
@Override
public void setFeeds(Set<FeedDescriptor> feeds) {
this.feeds = feeds;
}
}
但是,它的计算结果始终为0 要使此代码正常工作,PollFeedJob中的belongsTo()方法应如下所示:
@Override
public boolean belongsTo(Object job) {
return Objects.equals(Constants.POLL_FEED_JOB_FAMILY, job);
}
由于JobManager查找常量。POLL\u FEED\u JOB\u FAMILY,belongsTo()方法应基于该值返回。作业是否仍然存在?一旦它完成了
find
将不再找到它。@greg-449它不是。jobDone()方法重新调度作业,因此再次调度作业。我的目标是在满足条件时,取消计划的作业并再次运行它(在计划很长时间之前,有时需要立即执行)。有办法吗?
IJobManager manager = Job.getJobManager();
System.out.println(manager.find(Constants.JOB_FAMILY).length);
@Override
public boolean belongsTo(Object job) {
return Objects.equals(Constants.POLL_FEED_JOB_FAMILY, job);
}