Search in sources :

Example 1 with Service

use of javafx.concurrent.Service in project Gargoyle by callakrsos.

the class NrchRealtimeSrchFlowComposite method defineService.

private void defineService() {
    /*
		 * 비동기 실시간 검색어 조회 처리가 기술.
		 */
    service = new Service<List<RealtimeSearchVO>>() {

        @Override
        protected Task<List<RealtimeSearchVO>> createTask() {
            return new Task<List<RealtimeSearchVO>>() {

                @Override
                protected List<RealtimeSearchVO> call() throws Exception {
                    List<RealtimeSearchVO> meta = Collections.emptyList();
                    try {
                        meta = NaverRealtimeSrchSupplier.getInstance().getMeta();
                    } catch (Exception e) {
                        DialogUtil.showExceptionDailog(e);
                    }
                    return meta;
                }
            };
        }
    };
    service.setOnCancelled(stat -> {
        if (State.CANCELLED == stat.getSource().getState()) {
            LOGGER.debug("Cancel Requested");
        }
    });
    service.setOnSucceeded(stat -> {
        applyResponseTime(DateUtil.getCurrentDateString());
        FlowCardComposite value = new FlowCardComposite();
        flowCardComposite.set(value);
        this.getParent().setCenter(flowCardComposite.get());
        FlowCardComposite tmp = flowCardComposite.get();
        ObservableList<Node> flowChildrens = tmp.getFlowChildrens();
        tmp.setLimitColumn(20);
        data.setAll((List<RealtimeSearchVO>) stat.getSource().getValue());
        List<VBox> collect = data.stream().map(nodeConverter::apply).flatMap(v -> v.stream()).collect(Collectors.toList());
        flowChildrens.setAll(collect);
        if (isRecycle.get()) {
            WaitThread waitThread = new WaitThread(THREAD_RUNNER_GROUP, choWaitItems.getValue()) {

                @Override
                public boolean isContinue() {
                    return isRecycle.get();
                }

                @Override
                public void execute() {
                    Platform.runLater(() -> {
                        if (isContinue())
                            service.restart();
                    });
                }

                @Override
                public boolean isRecycle() {
                    return isRecycle.get();
                }
            };
            waitThread.setDaemon(true);
            waitThread.start();
        }
    });
}
Also used : IntStream(java.util.stream.IntStream) Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) MouseButton(javafx.scene.input.MouseButton) RealtimeSearchVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchVO) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) DialogUtil(com.kyj.fx.voeditor.visual.util.DialogUtil) VBox(javafx.scene.layout.VBox) Function(java.util.function.Function) RealtimeSearchItemVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchItemVO) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Task(javafx.concurrent.Task) Insets(javafx.geometry.Insets) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextMenu(javafx.scene.control.ContextMenu) State(javafx.concurrent.Worker.State) ExecutorService(java.util.concurrent.ExecutorService) HBox(javafx.scene.layout.HBox) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) MenuItem(javafx.scene.control.MenuItem) TitledPane(javafx.scene.control.TitledPane) CloseableParent(com.kyj.fx.voeditor.visual.main.layout.CloseableParent) Node(javafx.scene.Node) IOException(java.io.IOException) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) Service(javafx.concurrent.Service) Collectors(java.util.stream.Collectors) ChoiceBox(javafx.scene.control.ChoiceBox) GoogleTrendComposite(com.kyj.fx.voeditor.visual.component.google.trend.GoogleTrendComposite) Platform(javafx.application.Platform) Cursor(javafx.scene.Cursor) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) NaverRealtimeSrchSupplier(com.kyj.fx.voeditor.visual.suppliers.NaverRealtimeSrchSupplier) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) FlowCardComposite(com.kyj.fx.voeditor.visual.component.FlowCardComposite) DateUtil(com.kyj.fx.voeditor.visual.util.DateUtil) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) Collections(java.util.Collections) ExecutorDemons(com.kyj.fx.voeditor.visual.framework.thread.ExecutorDemons) SharedMemory(com.kyj.fx.voeditor.visual.momory.SharedMemory) Task(javafx.concurrent.Task) Node(javafx.scene.Node) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) RealtimeSearchVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchVO) FlowCardComposite(com.kyj.fx.voeditor.visual.component.FlowCardComposite) List(java.util.List) ObservableList(javafx.collections.ObservableList) VBox(javafx.scene.layout.VBox)

Example 2 with Service

use of javafx.concurrent.Service 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)

Aggregations

FxUtil (com.kyj.fx.voeditor.visual.util.FxUtil)2 ValueUtil (com.kyj.fx.voeditor.visual.util.ValueUtil)2 Collections (java.util.Collections)2 List (java.util.List)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Platform (javafx.application.Platform)2 FXCollections (javafx.collections.FXCollections)2 ObservableList (javafx.collections.ObservableList)2 Service (javafx.concurrent.Service)2 Task (javafx.concurrent.Task)2 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1 Parameter (com.github.javaparser.ast.body.Parameter)1 VariableDeclaratorId (com.github.javaparser.ast.body.VariableDeclaratorId)1 Comment (com.github.javaparser.ast.comments.Comment)1 NameExpr (com.github.javaparser.ast.expr.NameExpr)1 Type (com.github.javaparser.ast.type.Type)1 VoidVisitorAdapter (com.github.javaparser.ast.visitor.VoidVisitorAdapter)1 FileWrapper (com.kyj.fx.voeditor.visual.component.FileWrapper)1 FlowCardComposite (com.kyj.fx.voeditor.visual.component.FlowCardComposite)1