Search in sources :

Example 11 with Task

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();
}
Also used : Task(javafx.concurrent.Task) IcmpV4CommonPacket(org.pcap4j.packet.IcmpV4CommonPacket) TRexClient(com.cisco.trex.stateless.TRexClient) UnknownHostException(java.net.UnknownHostException) EthernetPacket(org.pcap4j.packet.EthernetPacket) IcmpV4Type(org.pcap4j.packet.namednumber.IcmpV4Type) Random(java.util.Random) IpV4Packet(org.pcap4j.packet.IpV4Packet)

Example 12 with Task

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;
        }
    };
}
Also used : Task(javafx.concurrent.Task) ActivePGIdsRPCResult(com.cisco.trex.stateless.model.stats.ActivePGIdsRPCResult)

Example 13 with Task

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);
    }
}
Also used : Task(javafx.concurrent.Task) FileChooser(javafx.stage.FileChooser) Preferences(java.util.prefs.Preferences) File(java.io.File) FXML(javafx.fxml.FXML)

Example 14 with Task

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();
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) ChoiceDialog(javafx.scene.control.ChoiceDialog) Task(javafx.concurrent.Task) ResourceBundle(java.util.ResourceBundle) List(java.util.List) Engine(jgnash.engine.Engine)

Example 15 with Task

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();
}
Also used : ChoiceDialog(javafx.scene.control.ChoiceDialog) Task(javafx.concurrent.Task) ResourceBundle(java.util.ResourceBundle) LocaleObject(jgnash.util.LocaleObject)

Aggregations

Task (javafx.concurrent.Task)15 FXML (javafx.fxml.FXML)6 File (java.io.File)4 List (java.util.List)4 TRexClient (com.cisco.trex.stateless.TRexClient)3 FxUtil (com.kyj.fx.voeditor.visual.util.FxUtil)3 ValueUtil (com.kyj.fx.voeditor.visual.util.ValueUtil)3 ResourceBundle (java.util.ResourceBundle)3 Platform (javafx.application.Platform)3 ObservableList (javafx.collections.ObservableList)3 FXMLController (com.kyj.fx.voeditor.visual.framework.annotation.FXMLController)2 DialogUtil (com.kyj.fx.voeditor.visual.util.DialogUtil)2 FileUtil (com.kyj.fx.voeditor.visual.util.FileUtil)2 CodeGenFile (ilargia.entitas.codeGeneration.data.CodeGenFile)2 ICodeGenerator (ilargia.entitas.codeGeneration.interfaces.ICodeGenerator)2 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Optional (java.util.Optional)2