use of javafx.concurrent.Task in project trex-stateless-gui by cisco-system-traffic-generator.
the class PortLayerConfiguration method runPingCmd.
private void runPingCmd(Event event) {
if (model.getPortStatus().equalsIgnoreCase("tx")) {
guiLogger.appendText(LogType.ERROR, "Port " + model.getIndex() + " is in TX mode. Please stop traffic first.");
return;
}
if (Strings.isNullOrEmpty(pingDestination.getText())) {
guiLogger.appendText(LogType.ERROR, "Empty ping destination address.");
return;
}
if (!model.getL3LayerConfiguration().getState().equalsIgnoreCase("resolved")) {
guiLogger.appendText(LogType.ERROR, "ARP resolution required. Configure L3 mode properly.");
return;
}
pingCommandBtn.setDisable(true);
Task<Void> pingTask = new Task<Void>() {
@Override
public Void call() {
TRexClient trexClient = ConnectionManager.getInstance().getTrexClient();
trexClient.serviceMode(model.getIndex(), true);
String savedPingIPv4 = pingDestination.getText();
guiLogger.appendText(LogType.PING, " Start ping " + savedPingIPv4 + ":");
AsyncResponseManager.getInstance().muteLogger();
try {
int icmp_id = new Random().nextInt(100);
for (int icmp_sec = 1; icmp_sec < 6; icmp_sec++) {
EthernetPacket reply = trexClient.sendIcmpEcho(model.getIndex(), savedPingIPv4, icmp_id, icmp_sec, 1000);
if (reply != null) {
IpV4Packet ip = reply.get(IpV4Packet.class);
String ttl = String.valueOf(ip.getHeader().getTtlAsInt());
IcmpV4CommonPacket echoReplyPacket = reply.get(IcmpV4CommonPacket.class);
IcmpV4Type replyType = echoReplyPacket.getHeader().getType();
if (IcmpV4Type.ECHO_REPLY.equals(replyType)) {
guiLogger.appendText(LogType.PING, " Reply from " + savedPingIPv4 + " size=" + reply.getRawData().length + " ttl=" + ttl + " icmp_sec=" + icmp_sec);
} else if (IcmpV4Type.DESTINATION_UNREACHABLE.equals(replyType)) {
guiLogger.appendText(LogType.PING, " Destination host unreachable");
}
} else {
guiLogger.appendText(LogType.PING, " Request timeout for icmp_seq " + icmp_sec);
}
}
guiLogger.appendText(LogType.PING, " Ping finished.");
} catch (UnknownHostException e) {
guiLogger.appendText(LogType.PING, " Unknown host");
} finally {
pingCommandBtn.setDisable(false);
trexClient.serviceMode(model.getIndex(), false);
AsyncResponseManager.getInstance().unmuteLogger();
}
return null;
}
};
pingTask.setOnSucceeded(e -> pingCommandBtn.setDisable(false));
new Thread(pingTask).start();
}
use of javafx.concurrent.Task in project trex-stateless-gui by cisco-system-traffic-generator.
the class ActivePGIDsService method createTask.
@Override
protected Task<Set<Integer>> createTask() {
return new Task<Set<Integer>>() {
@Override
protected Set<Integer> call() {
// TODO: remove when ConnectionManager.isConnected will be returns valid result
if (ConnectionManager.getInstance().getApiH() == null) {
return null;
}
Set<Integer> pgIDs = null;
try {
final ActivePGIdsRPCResult activePGIdsRPCResult = RPCCommands.getActivePGIds();
final int[] flowStats = activePGIdsRPCResult.getIds().getFlowStats();
final int[] latency = activePGIdsRPCResult.getIds().getLatency();
pgIDs = new HashSet<>();
for (final int pgID : flowStats) {
pgIDs.add(pgID);
}
for (final int pgID : latency) {
pgIDs.add(pgID);
}
} catch (Exception exc) {
LOG.error("Failed to get active PGIDs", exc);
}
return pgIDs;
}
};
}
use of javafx.concurrent.Task in project jgnash by ccavanaugh.
the class BudgetViewController method handleExportAction.
@FXML
private void handleExportAction() {
Objects.requireNonNull(budgetTableController);
final Preferences pref = Preferences.userNodeForPackage(BudgetViewController.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.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);
BudgetResultsExport.exportBudgetResultsModel(file.toPath(), budgetTableController.getBudgetResultsModel());
return null;
}
};
new Thread(exportTask).start();
StaticUIMethods.displayTaskProgress(exportTask);
}
}
use of javafx.concurrent.Task in project jgnash by ccavanaugh.
the class DefaultCurrencyAction method showAndWait.
public static void showAndWait() {
final Task<List<CurrencyNode>> task = new Task<List<CurrencyNode>>() {
final ResourceBundle resources = ResourceUtils.getBundle();
private List<CurrencyNode> currencyNodeList;
@Override
protected List<CurrencyNode> call() throws Exception {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
currencyNodeList = engine.getCurrencies();
return currencyNodeList;
}
@Override
protected void succeeded() {
super.succeeded();
Platform.runLater(() -> {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final ChoiceDialog<CurrencyNode> dialog = new ChoiceDialog<>(engine.getDefaultCurrency(), currencyNodeList);
dialog.setTitle(resources.getString("Title.SelDefCurr"));
dialog.getDialogPane().getStylesheets().addAll(MainView.DEFAULT_CSS);
dialog.getDialogPane().getScene().getRoot().styleProperty().bind(ThemeManager.styleProperty());
dialog.getDialogPane().getStyleClass().addAll("form", "dialog");
dialog.setHeaderText(resources.getString("Title.SelDefCurr"));
final Optional<CurrencyNode> optional = dialog.showAndWait();
optional.ifPresent(currencyNode -> {
engine.setDefaultCurrency(currencyNode);
Platform.runLater(() -> StaticUIMethods.displayMessage(resources.getString("Message.CurrChange") + " " + engine.getDefaultCurrency().getSymbol()));
});
});
}
};
new Thread(task).start();
}
use of javafx.concurrent.Task in project jgnash by ccavanaugh.
the class DefaultLocaleAction method showAndWait.
public static void showAndWait() {
final Task<LocaleObject[]> task = new Task<LocaleObject[]>() {
final ResourceBundle resources = ResourceUtils.getBundle();
private LocaleObject[] localeObjects;
@Override
protected LocaleObject[] call() throws Exception {
localeObjects = LocaleObject.getLocaleObjects();
return localeObjects;
}
@Override
protected void succeeded() {
super.succeeded();
Platform.runLater(() -> {
final ChoiceDialog<LocaleObject> dialog = new ChoiceDialog<>(new LocaleObject(Locale.getDefault()), localeObjects);
dialog.setTitle(resources.getString("Title.SelDefLocale"));
dialog.getDialogPane().getStylesheets().addAll(MainView.DEFAULT_CSS);
dialog.getDialogPane().getScene().getRoot().styleProperty().bind(ThemeManager.styleProperty());
dialog.getDialogPane().getStyleClass().addAll("form", "dialog");
dialog.setHeaderText(resources.getString("Title.SelDefLocale"));
final Optional<LocaleObject> optional = dialog.showAndWait();
optional.ifPresent(localeObject -> {
ResourceUtils.setLocale(localeObject.getLocale());
StaticUIMethods.displayMessage(localeObject + "\n" + resources.getString("Message.RestartLocale"));
});
});
}
};
new Thread(task).start();
}
Aggregations