-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kie-issues#1669: jBPM Quarkus DevUI seems to not update the # of items #2814
Open
bncriju
wants to merge
11
commits into
apache:main
Choose a base branch
from
bncriju:kie-issues#1669
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
63a31f1
Changes to make counters dynamic
bncriju 4295790
introducing Intermediate class
bncriju 064c91c
fixing broken build and chnaged refreshData logic
bncriju db4eaa6
Merge branch 'apache:main' into kie-issues#1669
bncriju be1aeca
Merge branch 'main' into kie-issues#1669
bncriju 57d1685
Changes to make counters dynamic
bncriju 3049e49
introducing Intermediate class
bncriju 73856dd
fixing broken build and chnaged refreshData logic
bncriju 0585ce9
publishing logic modified
bncriju 335c344
Merge branch 'kie-issues#1669' of github.com:bncriju/incubator-kie-to…
bncriju 45b9171
review comments incorporated, reformatted code and adjusted delay
bncriju File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...rkus-devui-runtime/src/main/java/org/jbpm/quarkus/devui/runtime/rpc/DataIndexCounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.jbpm.quarkus.devui.runtime.rpc; | ||
|
||
import io.smallrye.mutiny.Multi; | ||
import io.smallrye.mutiny.subscription.MultiEmitter; | ||
import io.vertx.core.Future; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.json.JsonObject; | ||
import io.vertx.ext.web.client.WebClient; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class DataIndexCounter { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(DataIndexCounter.class); | ||
private final Vertx vertx; | ||
private final Multi<String> multi; | ||
private final WebClient dataIndexWebClient; | ||
|
||
private String query; | ||
private String field; | ||
private String count = "-"; | ||
private MultiEmitter<? super String> emitter; | ||
private long vertxTimer; | ||
|
||
public DataIndexCounter(String query, String graphField, WebClient dataIndexWebClient) { | ||
if (dataIndexWebClient == null) { | ||
throw new IllegalArgumentException("dataIndexWebClient is null"); | ||
} | ||
this.query = query; | ||
this.field = graphField; | ||
this.dataIndexWebClient = dataIndexWebClient; | ||
this.vertx = Vertx.vertx(); | ||
|
||
this.multi = Multi.createFrom().emitter(emitter -> { | ||
this.emitter = emitter; | ||
vertxTimer = vertx.setPeriodic(500, id -> { | ||
this.emit(); | ||
}); | ||
this.emit(); | ||
}); | ||
refreshCount(); | ||
} | ||
|
||
public void refresh() { | ||
vertx.setTimer(500, id -> { | ||
refreshCount(); | ||
}); | ||
} | ||
|
||
public void stop() { | ||
vertx.cancelTimer(vertxTimer); | ||
} | ||
|
||
private void emit() { | ||
emitter.emit(count); | ||
} | ||
|
||
private void refreshCount() { | ||
LOGGER.info("Refreshing data for query: {}", query); | ||
|
||
doQuery(query, field).toCompletionStage() | ||
.thenAccept(result -> { | ||
this.count = result; | ||
this.emit(); | ||
}); | ||
} | ||
|
||
private Future<String> doQuery(String query, String graphModelName) { | ||
return this.dataIndexWebClient.post("/graphql") | ||
.putHeader("content-type", "application/json") | ||
.sendJson(new JsonObject(query)) | ||
.map(response -> { | ||
if (response.statusCode() == 200) { | ||
JsonObject responseData = response.bodyAsJsonObject().getJsonObject("data"); | ||
return String.valueOf(responseData.getJsonArray(graphModelName).size()); | ||
} | ||
return "-"; | ||
}); | ||
} | ||
|
||
public Multi<String> getMulti() { | ||
return multi; | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...vui-runtime/src/main/java/org/jbpm/quarkus/devui/runtime/rpc/JBPMDevUIEventPublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.jbpm.quarkus.devui.runtime.rpc; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import org.kie.kogito.event.DataEvent; | ||
import org.kie.kogito.event.EventPublisher; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import io.quarkus.arc.profile.IfBuildProfile; | ||
|
||
import java.util.Collection; | ||
import java.util.Objects; | ||
|
||
@ApplicationScoped | ||
@IfBuildProfile("dev") | ||
public class JBPMDevUIEventPublisher implements EventPublisher { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(JBPMDevUIEventPublisher.class); | ||
private Runnable onProcessEvent; | ||
private Runnable onTaskEvent; | ||
private Runnable onJobEvent; | ||
|
||
@Override | ||
public void publish(DataEvent<?> event) { | ||
switch (event.getType()) { | ||
case "ProcessInstanceStateDataEvent": | ||
maybeRun(onProcessEvent); | ||
break; | ||
case "UserTaskInstanceStateDataEvent": | ||
maybeRun(onTaskEvent); | ||
break; | ||
case "JobEvent": | ||
maybeRun(onJobEvent); | ||
break; | ||
default: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we can get rid of the default |
||
LOGGER.debug("Unknown type of event '{}', ignoring for this publisher", event.getType()); | ||
} | ||
} | ||
|
||
@Override | ||
public void publish(Collection<DataEvent<?>> events) { | ||
events.forEach(this::publish); | ||
} | ||
|
||
private void maybeRun(Runnable runnable) { | ||
if (Objects.nonNull(runnable)) { | ||
runnable.run(); | ||
} | ||
} | ||
|
||
public void setOnProcessEventListener(Runnable onProcessEvent) { | ||
this.onProcessEvent = onProcessEvent; | ||
} | ||
|
||
public void setOnTaskEventListener(Runnable onTaskEvent) { | ||
this.onTaskEvent = onTaskEvent; | ||
} | ||
|
||
public void setOnJobEventListener(Runnable onJobEvent) { | ||
this.onJobEvent = onJobEvent; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This timer looks like to short, in slow laptops (like main) this may not work, but I think we can go with it for now.