Commit dfe849ef authored by Matija Obreza's avatar Matija Obreza

Added Pause/Resume button

parent 85ab4a9a
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* 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:
* Google, Inc. - initial API and implementation
*******************************************************************************/
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* 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:
* Google, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.swt;
import java.io.FileInputStream;
......
......@@ -29,6 +29,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.stream.Collectors;
......@@ -109,6 +110,7 @@ public class PushDialog extends Dialog {
private IDataSource dataSource;
private List<Future<?>> futures = new ArrayList<Future<?>>();
private ToolBar toolBar;
private AtomicBoolean doPushPaused = new AtomicBoolean(true); // paused by default
static {
deleteDataIcon = ImageDescriptor.createFromURL(PushDialog.class.getResource("/icon/delete.png")).createImage();
......@@ -238,6 +240,17 @@ public class PushDialog extends Dialog {
});
tltmRemove.setText("Remove");
tltmRemove.setImage(PushDialog.deleteDataIcon);
ToolItem tltmPause = new ToolItem(toolBar, SWT.NONE);
tltmPause.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doPushPaused.set(! doPushPaused.get());
_log.warn("Reading data source is " + (doPushPaused.get() ? "paused" : "resumed"));
tltmPause.setText(doPushPaused.get() ? "Resume" : "Pause");
}
});
tltmPause.setText("Pause");
ToolItem tltmRadioItemDebug = new ToolItem(toolBar, SWT.RADIO);
tltmRadioItemDebug.addSelectionListener(new SelectionAdapter() {
......@@ -348,6 +361,9 @@ public class PushDialog extends Dialog {
_log.info("Starting push to " + oauthSettings.getServerUrl());
final GenesysClient genesysClient = SpringConfig.createGenesysClient(oauthSettings);
// Manages pause/resume
doPushPaused.set(false);
Future<?> future = executorService.submit(() -> {
try {
List<String> instCodesOrder = new ArrayList<>();
......@@ -360,6 +376,10 @@ public class PushDialog extends Dialog {
List<Object[]> rows = null;
int count = 0;
do {
while (doPushPaused.get()) {
// Pause reading
Thread.sleep(500);
}
rows = rowReader1.readRows(1000);
for (Object[] row : rows) {
count++;
......@@ -400,6 +420,25 @@ public class PushDialog extends Dialog {
try {
do {
if (doPushPaused.get()) {
while (doPushPaused.get()) {
// Pause reading
Thread.sleep(500);
}
try {
genesysClient.me();
} catch (OAuthAuthenticationException e) {
_log.error("Trying reauthentication using refresh token.");
try {
genesysClient.refreshAccessToken();
} catch (OAuthAuthenticationException e1) {
_log.error("Trying Oauth client authentication.");
genesysClient.authenticate();
}
}
}
List<Object[]> rows = rowReader.readRows(100);
if (rows.size() == 0) {
......@@ -509,6 +548,9 @@ public class PushDialog extends Dialog {
_log.warn("PUSH FINISHED.");
_log.warn("Really.");
// Interrupt the thread so it stops logging
uploadMonitor.interrupt();
} catch (OAuthAuthenticationException e) {
_log.error(e.getMessage(), e);
} catch (PleaseRetryException e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment