|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2026 Simeon Andreev and others. |
| 3 | + * |
| 4 | + * This program and the accompanying materials |
| 5 | + * are made available under the terms of the Eclipse Public License 2.0 |
| 6 | + * which accompanies this distribution, and is available at |
| 7 | + * https://www.eclipse.org/legal/epl-2.0/ |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: EPL-2.0 |
| 10 | + * |
| 11 | + * Contributors: |
| 12 | + * Simeon Andreev - initial API and implementation |
| 13 | + *******************************************************************************/ |
| 14 | +package org.eclipse.jdt.debug.tests; |
| 15 | + |
| 16 | +import org.eclipse.core.runtime.IProgressMonitor; |
| 17 | + |
| 18 | +/** |
| 19 | + * A progress monitor which reports that the task is cancelled if a timeout occurs. The starting time for the timeout is the creation of the monitor. |
| 20 | + */ |
| 21 | +public class TimeoutMonitor implements IProgressMonitor { |
| 22 | + |
| 23 | + private final long timeoutMs; |
| 24 | + private final long startMs; |
| 25 | + |
| 26 | + TimeoutMonitor(long timeoutMs) { |
| 27 | + this.timeoutMs = timeoutMs; |
| 28 | + this.startMs = System.currentTimeMillis(); |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + public void beginTask(String name, int totalWork) { |
| 33 | + } |
| 34 | + |
| 35 | + @Override |
| 36 | + public void done() { |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public void internalWorked(double work) { |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public boolean isCanceled() { |
| 45 | + return System.currentTimeMillis() - startMs > timeoutMs; |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public void setCanceled(boolean value) { |
| 50 | + throw new UnsupportedOperationException(); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public void setTaskName(String name) { |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public void subTask(String name) { |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public void worked(int work) { |
| 63 | + } |
| 64 | + |
| 65 | +} |
0 commit comments