use of javafx.concurrent.Task in project trex-stateless-gui by cisco-system-traffic-generator.
the class MainViewController method unloadProfile.
private void unloadProfile() {
if (currentSelectedProfile == null) {
return;
}
Task<Void> unloadProfileTask = new Task<Void>() {
@Override
protected Void call() throws Exception {
TRexClient trexClient = ConnectionManager.getInstance().getTrexClient();
trexClient.stopTraffic(lastLoadedPortPtofileIndex);
trexClient.removeAllStreams(lastLoadedPortPtofileIndex);
return null;
}
};
unloadProfileTask.setOnSucceeded(event -> {
LogsController.getInstance().appendText(LogType.INFO, currentSelectedProfile + " profile unloaded");
currentSelectedProfile = Constants.SELECT_PROFILE;
assignedPortProfileMap.put(lastLoadedPortPtofileIndex, new AssignedProfile());
trafficProfileLoadedProperty.set(false);
portManager.updatedPorts(Arrays.asList(lastLoadedPortPtofileIndex));
});
LogsController.getInstance().appendText(LogType.INFO, "Unloading " + currentSelectedProfile + " profile");
new Thread(unloadProfileTask).start();
}
use of javafx.concurrent.Task in project trex-stateless-gui by cisco-system-traffic-generator.
the class PortLayerConfiguration method saveConfiguration.
private void saveConfiguration(Event event) {
if (model.getPortStatus().equalsIgnoreCase("tx")) {
guiLogger.appendText(LogType.ERROR, "Port " + model.getIndex() + " is in TX mode. Please stop traffic first.");
return;
}
if (l2Mode.isSelected()) {
if (Strings.isNullOrEmpty(l2Destination.getText())) {
guiLogger.appendText(LogType.ERROR, "Destination MAC is empty. ");
return;
}
} else {
if (!validateIpAddress(l3Source.getText())) {
return;
}
if (!validateIpAddress(l3Destination.getText())) {
return;
}
}
saveBtn.setDisable(true);
saveBtn.setText("Applying...");
Task saveConfigurationTask = new Task<Optional<String>>() {
@Override
public Optional<String> call() {
TRexClient trexClient = ConnectionManager.getInstance().getTrexClient();
if (l2Mode.isSelected()) {
String dstMac = l2Destination.getText();
try {
serverRPCMethods.setSetL2(model.getIndex(), dstMac);
guiLogger.appendText(LogType.INFO, "L2 mode configured for " + model.getIndex());
} catch (Exception e1) {
logger.error("Failed to set L2 mode: " + e1.getMessage());
}
} else if (l3Mode.isSelected()) {
try {
AsyncResponseManager.getInstance().muteLogger();
String portSrcIP = l3Source.getText();
String portDstIP = l3Destination.getText();
trexClient.serviceMode(model.getIndex(), true);
trexClient.setL3Mode(model.getIndex(), null, portSrcIP, portDstIP);
String nextHopMac = trexClient.resolveArp(model.getIndex(), portSrcIP, portDstIP);
if (nextHopMac != null) {
trexClient.setL3Mode(model.getIndex(), nextHopMac, portSrcIP, portDstIP);
AsyncResponseManager.getInstance().unmuteLogger();
}
return nextHopMac == null ? Optional.empty() : Optional.of(nextHopMac);
} catch (Exception e) {
logger.error("Failed to set L3 mode: " + e.getMessage());
} finally {
trexClient.serviceMode(model.getIndex(), false);
}
}
return Optional.empty();
}
};
saveConfigurationTask.setOnSucceeded(e -> {
saveBtn.setText("Apply");
saveBtn.setDisable(false);
Optional result = (Optional) (saveConfigurationTask.getValue());
if (l3Mode.isSelected()) {
String status = "unresolved";
if (result.isPresent()) {
status = "resolved";
guiLogger.appendText(LogType.INFO, "ARP resolution for " + l3Destination.getText() + " is " + result.get());
} else {
guiLogger.appendText(LogType.ERROR, "ARP resolution status: FAILED");
}
arpStatus.setText(status);
}
});
new Thread(saveConfigurationTask).start();
}
use of javafx.concurrent.Task in project Gargoyle by callakrsos.
the class BaseInfoComposite method start.
/**
*
* 코드 분석 시작 처리.
* @작성자 : KYJ
* @작성일 : 2017. 2. 3.
*/
public void start() {
// 동적처리에 따라 API 함수 수정.
FileUtil.consumeJavaParser(targetFile, cu -> {
NameExpr name = cu.getPackage().getName();
lblPackage.setText(name.toString());
String importStatement = cu.getImports().stream().map(im -> im.getName().toString()).collect(Collectors.joining(","));
lblImports.setText(importStatement);
Service<Void> service = new Service<Void>() {
@Override
protected Task<Void> createTask() {
return new Task<Void>() {
@Override
protected Void call() throws Exception {
new MethodVisitor(v -> {
methodData.add(v);
}).visit(cu, null);
return null;
}
};
}
};
service.start();
}, err -> {
LOGGER.error(ValueUtil.toString(err));
});
}
use of javafx.concurrent.Task in project Gargoyle by callakrsos.
the class ScheduleTimeLineComposite method initialize.
@FXML
public void initialize() {
Monitors.addListener(this);
Main.addPrimaryStageCloseListener(this);
chartTimeLine.setVerticalGridLinesVisible(false);
ObservableList<Series<String, Number>> data = chartTimeLine.getData();
// allJvmProcessSeries = new Series<String, Number>();
// allJvmProcessSeries.setName("All JVM Process");
// data.add(allJvmProcessSeries);
passBatchProcessSeries = new Series<String, Number>();
passBatchProcessSeries.setName("Java Process");
data.add(passBatchProcessSeries);
// monitorService.setOnRunning(ev ->{
// System.err.println("running~~~~~~~~~~~~~~~~~~~");
// });
// monitorService.setOnScheduled(ev ->{
// System.err.println("service schedule.....");
// });
monitorService = new Service<Void>() {
@Override
protected Task<Void> createTask() {
return new Task<Void>() {
@Override
protected Void call() throws Exception {
Thread.sleep(1000);
String mmss = format.format(new Date());
updateMessage(mmss);
return null;
}
};
}
};
monitorService.messageProperty().addListener((oba, oldval, newval) -> {
if (newval == null || newval.isEmpty())
return;
ObservableList<Data<String, Number>> seriesData = passBatchProcessSeries.getData();
Data<String, Number> e = new Data<String, Number>(newval, Monitors.getActivedJavaProcessCount());
e.setNode(new Rectangle(1, 1));
seriesData.add(e);
if (seriesData.size() > CHART_SHOWING_ITEM_COUNT) {
seriesData.remove(0);
}
});
monitorService.setOnSucceeded(ev -> {
if (running.get()) {
monitorService.restart();
onTickTock();
}
});
monitorService.start();
}
use of javafx.concurrent.Task in project jgnash by ccavanaugh.
the class RegisterActions method exportTransactions.
static void exportTransactions(final Account account, final LocalDate startDate, final LocalDate endDate) {
final ResourceBundle resources = ResourceUtils.getBundle();
final Preferences pref = Preferences.userNodeForPackage(RegisterActions.class);
final FileChooser fileChooser = new FileChooser();
fileChooser.setInitialDirectory(new File(pref.get(EXPORT_DIR, System.getProperty("user.home"))));
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter(resources.getString("Label.CsvFiles") + " (*.csv)", "*.csv"), new FileChooser.ExtensionFilter(resources.getString("Label.OfxFiles") + " (*.ofx)", "*.ofx"), new FileChooser.ExtensionFilter(resources.getString("Label.SpreadsheetFiles") + " (*.xls, *.xlsx)", "*.xls", "*.xlsx"));
final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
if (file != null) {
pref.put(EXPORT_DIR, file.getParentFile().getAbsolutePath());
final Task<Void> exportTask = new Task<Void>() {
@Override
protected Void call() throws Exception {
updateMessage(resources.getString("Message.PleaseWait"));
updateProgress(-1, Long.MAX_VALUE);
if (OFX.equals(FileUtils.getFileExtension(file.getName()))) {
OfxExport export = new OfxExport(account, startDate, endDate, file);
export.exportAccount();
} else if (FileUtils.getFileExtension(file.getName()).contains(XLS)) {
AccountExport.exportAccount(account, RegisterFactory.getColumnNames(account.getAccountType()), startDate, endDate, file);
} else {
CsvExport.exportAccount(account, startDate, endDate, file);
}
return null;
}
};
new Thread(exportTask).start();
StaticUIMethods.displayTaskProgress(exportTask);
}
}
Aggregations