Search in sources :

Example 6 with Task

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();
}
Also used : Task(javafx.concurrent.Task) TRexClient(com.cisco.trex.stateless.TRexClient) AssignedProfile(com.exalttech.trex.ui.views.models.AssignedProfile)

Example 7 with Task

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();
}
Also used : Task(javafx.concurrent.Task) TRexClient(com.cisco.trex.stateless.TRexClient) Optional(java.util.Optional) UnknownHostException(java.net.UnknownHostException)

Example 8 with Task

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));
    });
}
Also used : VoidVisitorAdapter(com.github.javaparser.ast.visitor.VoidVisitorAdapter) TreeItem(javafx.scene.control.TreeItem) Parameter(com.github.javaparser.ast.body.Parameter) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) Function(java.util.function.Function) ArrayList(java.util.ArrayList) FileWrapper(com.kyj.fx.voeditor.visual.component.FileWrapper) Task(javafx.concurrent.Task) MethodDVO(com.kyj.fx.voeditor.visual.words.spec.auto.msword.vo.MethodDVO) Type(com.github.javaparser.ast.type.Type) JavaProjectFileTreeItem(com.kyj.fx.voeditor.visual.component.JavaProjectFileTreeItem) FileUtil(com.kyj.fx.voeditor.visual.util.FileUtil) SpecResource(com.kyj.fx.voeditor.visual.words.spec.auto.msword.ui.model.SpecResource) MethodParameterDVO(com.kyj.fx.voeditor.visual.words.spec.auto.msword.vo.MethodParameterDVO) VariableDeclaratorId(com.github.javaparser.ast.body.VariableDeclaratorId) SystemUtils(org.apache.commons.lang.SystemUtils) TextField(javafx.scene.control.TextField) Logger(org.slf4j.Logger) GargoyleJavaParser(com.kyj.fx.voeditor.visual.framework.parser.GargoyleJavaParser) FXMLController(com.kyj.fx.voeditor.visual.framework.annotation.FXMLController) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) NameExpr(com.github.javaparser.ast.expr.NameExpr) Service(javafx.concurrent.Service) Collectors(java.util.stream.Collectors) File(java.io.File) Consumer(java.util.function.Consumer) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) List(java.util.List) Stream(java.util.stream.Stream) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Comment(com.github.javaparser.ast.comments.Comment) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) Collections(java.util.Collections) AbstractSpecTab(com.kyj.fx.voeditor.visual.words.spec.auto.msword.ui.tabs.AbstractSpecTab) Task(javafx.concurrent.Task) NameExpr(com.github.javaparser.ast.expr.NameExpr) Service(javafx.concurrent.Service)

Example 9 with Task

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();
}
Also used : Task(javafx.concurrent.Task) Rectangle(javafx.scene.shape.Rectangle) Data(javafx.scene.chart.XYChart.Data) Date(java.util.Date) Series(javafx.scene.chart.XYChart.Series) FXML(javafx.fxml.FXML)

Example 10 with Task

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);
    }
}
Also used : Task(javafx.concurrent.Task) FileChooser(javafx.stage.FileChooser) ResourceBundle(java.util.ResourceBundle) OfxExport(jgnash.convert.exports.ofx.OfxExport) Preferences(java.util.prefs.Preferences) File(java.io.File)

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