Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
DropSnorz committed Nov 7, 2018
2 parents 749efa6 + 889c435 commit aaaa718
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 99 deletions.
49 changes: 13 additions & 36 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.dropsnorz</groupId>
<artifactId>owlplug</artifactId>
<version>0.4.0-SNAPSHOT</version>
<version>0.4.2-beta</version>
<packaging>jar</packaging>

<name>owlplug</name>
Expand Down Expand Up @@ -46,27 +46,12 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.190</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>

<dependency>
Expand All @@ -86,36 +71,16 @@
<version>1.20</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>1.0.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>


<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand Down Expand Up @@ -175,6 +140,18 @@
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,10 @@ public TaskExecutionContext createStoreSyncTask() {
return create(task);
}


public TaskExecutionContext create(AbstractTask task) {
bindOnFailHandler(task);
return buildContext(task);
}


private void bindOnFailHandler(AbstractTask task) {
task.setOnFailed(e -> {
taskManager.triggerOnError();
});
}

private void notifyListeners(List<SimpleEventListener> listeners) {
for (SimpleEventListener listener : listeners) {
listener.onAction();
Expand Down
84 changes: 52 additions & 32 deletions src/main/java/com/dropsnorz/owlplug/core/components/TaskRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import com.dropsnorz.owlplug.core.tasks.AbstractTask;
import com.dropsnorz.owlplug.core.tasks.TaskResult;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.LinkedBlockingDeque;
import javafx.application.Platform;
import javafx.concurrent.Worker.State;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -33,74 +33,94 @@ public class TaskRunner {
private TaskBarController taskBarController;

private AsyncListenableTaskExecutor exec;
private CopyOnWriteArrayList<AbstractTask> pendingTasks;
private AbstractTask currentTask= null;
private LinkedBlockingDeque<AbstractTask> taskQueue;
private AbstractTask currentTask = null;

private ArrayList<AbstractTask> taskHistory;

private TaskRunner() {

exec = new SimpleAsyncTaskExecutor();
pendingTasks = new CopyOnWriteArrayList<AbstractTask>();
taskQueue = new LinkedBlockingDeque<AbstractTask>();
taskHistory = new ArrayList<AbstractTask>();

}

/**
* Submit a task at the end of executor queue.
* @param task - the task to submit
*/
public void submitTask(AbstractTask task) {
log.debug("Task submited to queue - {} ", task.getClass().getName());
taskQueue.addLast(task);
scheduleNext();

}

/**
* Submit a task in front of the executor queue.
* @param task - the task to submit
*/
public void submitTaskOnQueueHead(AbstractTask task) {
log.debug("Task submited to queue - {} ", task.getClass().getName());
pendingTasks.add(task);
addInTaskHistory(task);
refresh(false);
taskQueue.addFirst(task);
scheduleNext();

}

/**
* Refresh the task runner by submitting the next pending task for execution.
* @param deleteCurrentTask true if the current running task should be deleted
*/
private synchronized void refresh(boolean deleteCurrentTask) {

if (deleteCurrentTask) {
log.debug("Remove task from queue - {}", currentTask.getClass().getName());
pendingTasks.remove(currentTask);
currentTask = null;
//Unbind progress indicators
taskBarController.taskProgressBar.progressProperty().unbind();
taskBarController.taskLabel.textProperty().unbind();
}
private synchronized void scheduleNext() {

if (!pendingTasks.isEmpty() && currentTask == null) {
if (!taskQueue.isEmpty() && currentTask == null) {
disableError();
//Get the next pending task
this.currentTask = pendingTasks.get(0);
AbstractTask polledTask = taskQueue.pollFirst();
setCurrentTask(polledTask);
addInTaskHistory(currentTask);
log.debug("Task submitted to executor - {} ", currentTask.getClass().getName());
//Bind progress indicators
taskBarController.taskProgressBar.progressProperty().bind(currentTask.progressProperty());
taskBarController.taskLabel.textProperty().bind(currentTask.messageProperty());

ListenableFuture<TaskResult> future = (ListenableFuture<TaskResult>) exec.submitListenable(currentTask);

future.addCallback(new ListenableFutureCallback<TaskResult>() {

@Override
public void onSuccess(TaskResult result) {
Platform.runLater(() -> {
refresh(true);
if (currentTask.getState().equals(State.FAILED)) {
triggerOnError();
}
removeCurrentTask();
scheduleNext();
});
}

@Override
public void onFailure(Throwable ex) {
Platform.runLater(() -> {
refresh(true);
removeCurrentTask();
scheduleNext();
});

}
});
}
}

private void setCurrentTask(AbstractTask task) {
this.currentTask = task;
//Bind progress indicators
taskBarController.taskProgressBar.progressProperty().bind(currentTask.progressProperty());
taskBarController.taskLabel.textProperty().bind(currentTask.messageProperty());
}

private void removeCurrentTask() {
//Unbind progress indicators
taskBarController.taskProgressBar.progressProperty().unbind();
taskBarController.taskLabel.textProperty().unbind();

currentTask = null;

}

private void addInTaskHistory(AbstractTask task) {
if (taskHistory.size() >= 10) {
taskHistory.remove(0);
Expand All @@ -109,14 +129,14 @@ private void addInTaskHistory(AbstractTask task) {
}

public List<AbstractTask> getPendingTasks() {
return Collections.unmodifiableList(pendingTasks);
return new ArrayList<AbstractTask>(taskQueue);
}

public List<AbstractTask> getTaskHistory() {
return Collections.unmodifiableList(taskHistory);
return new ArrayList<AbstractTask>(taskHistory);
}

public void triggerOnError() {
private void triggerOnError() {
taskBarController.taskProgressBar.getStyleClass().add("progress-bar-error");

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public void initialize() {
removeButton.setOnAction(removeEvent -> {
dialog.close();
taskFactory.create(new DirectoryRemoveTask(pluginDirectory))
.setOnSucceeded(x -> taskFactory.createPluginSyncTask().run())
.run();
.setOnSucceeded(x -> taskFactory.createPluginSyncTask().schedule())
.schedule();
});
removeButton.getStyleClass().add("button-danger");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,20 @@ public void initialize() {
Platform.runLater(() -> accountComboBox.setValue(oldValue));

}

if (newValue instanceof UserAccount) {
UserAccount userAccount = (UserAccount) newValue;
prefs.putLong(ApplicationDefaults.SELECTED_ACCOUNT_KEY, userAccount.getId());

}
accountComboBox.hide();
});

accountComboBox.setButtonCell(new AccountCellFactory(imageCache, Pos.CENTER_RIGHT).call(null));
accountComboBox.setCellFactory(new AccountCellFactory(authentificationService,imageCache, true));

JFXComboBoxListViewSkin<AccountItem> accountCBSkin = new JFXComboBoxListViewSkin<AccountItem>(accountComboBox);
accountCBSkin.setHideOnClick(false);
accountComboBox.setSkin(accountCBSkin);

refreshAccounts();

Expand Down Expand Up @@ -166,6 +170,7 @@ public void refreshAccounts() {
accountComboBox.setValue(null);

}

}

public StackPane getRootPane() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void initialize() {
dialog.close();
taskFactory.create(new PluginRemoveTask(currentPlugin, pluginDAO))
.setOnSucceeded(x -> pluginsController.refreshPlugins())
.run();
.schedule();
});
removeButton.getStyleClass().add("button-danger");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.jfoenix.controls.JFXPopup;
import com.jfoenix.controls.JFXPopup.PopupHPosition;
import com.jfoenix.controls.JFXPopup.PopupVPosition;
import java.util.ArrayList;
import javafx.concurrent.Worker.State;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
Expand Down Expand Up @@ -51,7 +52,10 @@ private void openTaskHistory() {
if (!taskRunner.getTaskHistory().isEmpty()) {
JFXListView<AbstractTask> list = new JFXListView<>();
list.setPrefSize(Region.USE_COMPUTED_SIZE, Region.USE_COMPUTED_SIZE);
list.getItems().addAll(taskRunner.getTaskHistory());

ArrayList<AbstractTask> tasks = new ArrayList<>(taskRunner.getTaskHistory());
tasks.addAll(taskRunner.getPendingTasks());
list.getItems().addAll(tasks);

list.setCellFactory(new Callback<ListView<AbstractTask>, ListCell<AbstractTask>>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void initialize() {
if (isDirectoryPathValid()) {
this.close();
prefs.put(ApplicationDefaults.VST_DIRECTORY_KEY, directoryTextField.getText());
taskFactory.createPluginSyncTask().run();
taskFactory.createPluginSyncTask().schedule();
} else {
errorLabel.setVisible(true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.dropsnorz.owlplug.core.services;


import com.dropsnorz.owlplug.core.utils.UrlUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.util.UriUtils;

@Service
public class OwlPlugCentralService {
Expand All @@ -14,7 +14,7 @@ public class OwlPlugCentralService {

public String getPluginImageUrl(String name) {

return owlplugCentralUrl + "/image-registry?name=" + UriUtils.encode(name, "UTF-8");
return owlplugCentralUrl + "/image-registry?name=" + UrlUtils.encodeQuery(name);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public void pull(PluginRepository repository) {

IRepositoryStrategy strategy = repositoryStrategyResolver.getStrategy(repository, parameters);
taskFactory.create(new RepositoryTask(strategy, parameters, repository))
.setOnSucceeded(e -> taskFactory.createPluginSyncTask().run())
.run();
.setOnSucceeded(e -> taskFactory.createPluginSyncTask().schedule())
.schedule();


}
Expand All @@ -96,8 +96,8 @@ public void delete(PluginRepository repository) {

String localPath = getLocalRepositoryPath(repository);
taskFactory.create(new RepositoryRemoveTask(pluginRepositoryDAO, repository, localPath))
.setOnSucceeded(e -> taskFactory.createPluginSyncTask().run())
.run();
.setOnSucceeded(e -> taskFactory.createPluginSyncTask().scheduleNow())
.schedule();
}


Expand Down
Loading

0 comments on commit aaaa718

Please sign in to comment.