Skip to content

Commit

Permalink
Merge branch 'master-who' of https://github.com/protegeproject/webpro…
Browse files Browse the repository at this point in the history
…tege-gwt-ui into Support_hierarchy_change_operations_#8
  • Loading branch information
soimugeo committed Jun 6, 2024
2 parents 05c39ee + fa94250 commit daef507
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 19 deletions.
11 changes: 5 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
<plugin>
<groupId>net.ltgt.gwt.maven</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<extensions>true</extensions>
<configuration>
<sourceLevel>1.8</sourceLevel>
Expand All @@ -265,11 +265,10 @@
<startupUrls>WebProtege.jsp</startupUrls>
<launcherDir>${project.build.directory}/gwt/launcherDir</launcherDir>
<!-- <style>OBFUSCATED</style>-->
<style>DETAILED</style>
<devmodeArgs>
<arg>-style</arg><arg>DETAILED</arg>
<arg>-port</arg><arg>8765</arg>
</devmodeArgs>
<style>OBFUSCATED</style>
<draftCompile>false</draftCompile>
<optimize>9</optimize>
<logLevel>WARN</logLevel>
</configuration>
</plugin>
<plugin>
Expand Down
4 changes: 4 additions & 0 deletions webprotege-gwt-ui-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@
<classpathScope>compile+runtime</classpathScope>
<moduleTemplate>${project.basedir}/src/main/module-dev.gwt.xml</moduleTemplate>
<extra>target/gwt-extra</extra>
<optimize>0</optimize>
<draftCompile>true</draftCompile>
<style>DETAILED</style>
<logLevel>INFO</logLevel>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ public <A extends Action<R>, R extends Result> void execute(A action, final Disp
}
}

// if(batch > 0) {
// GWT.log("[Dispatch] Batching submitted action: " + action.getClass().getSimpleName());
// AsyncCallbackProxy<R> proxy = new AsyncCallbackProxy(action, callback);
// PendingActionExecution<A, R> actionExecution = PendingActionExecution.get(action, proxy);
// pendingActionExecutions.add(actionExecution);
// }
// else {
if(batch > 0) {
logger.info("Batching submitted action: " + action.getClass().getSimpleName());
AsyncCallbackProxy<R> proxy = new AsyncCallbackProxy(action, callback);
PendingActionExecution<A, R> actionExecution = PendingActionExecution.get(action, proxy);
pendingActionExecutions.add(actionExecution);
}
else {
execAction(action, callback);
// }
}
}

private void checkMakingACallForCurrentProject(ProjectId projectId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package edu.stanford.bmir.protege.web.server.dispatch;

import com.google.common.collect.ImmutableList;
import edu.stanford.bmir.protege.web.server.app.WebProtegeRemoteServiceServlet;
import edu.stanford.bmir.protege.web.server.logging.WebProtegeLogger;
import edu.stanford.bmir.protege.web.shared.dispatch.*;
import edu.stanford.bmir.protege.web.shared.inject.ApplicationSingleton;
import edu.stanford.bmir.protege.web.shared.permissions.PermissionDeniedException;
import edu.stanford.bmir.protege.web.shared.user.UserId;
import org.jetbrains.annotations.NotNull;
import org.keycloak.KeycloakPrincipal;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import javax.inject.Inject;

import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.google.common.base.Preconditions.checkNotNull;

Expand All @@ -24,14 +32,14 @@
*/
@ApplicationSingleton
public class DispatchServlet extends WebProtegeRemoteServiceServlet implements DispatchService {

private final static java.util.logging.Logger logger = Logger.getLogger("DispatchServiceManager");

@Nonnull
private final DispatchServiceExecutor executor;

@Inject
public DispatchServlet(@Nonnull WebProtegeLogger logger,
@Nonnull DispatchServiceExecutor executor) {
public DispatchServlet(@Nonnull DispatchServiceExecutor executor) {
this.executor = checkNotNull(executor);
}

Expand All @@ -44,9 +52,71 @@ public DispatchServiceResultContainer executeAction(Action action) throws Action
var userId = UserId.valueOf(idToken.getPreferredUsername());
var executionContext = new ExecutionContext(userId,
context.getTokenString());
return executor.execute(action, executionContext);
return executeAction(action, executionContext);
}

private DispatchServiceResultContainer executeAction(Action action,
ExecutionContext executionContext) {
if(action instanceof BatchAction) {
return executeBatchAction((BatchAction) action, executionContext);
}
else {
return executor.execute(action, executionContext);
}
}

@NotNull
private DispatchServiceResultContainer executeBatchAction(BatchAction action,
ExecutionContext executionContext) {
// The results are returned in the same order as the actions. This is how results are matched
// up with actions
var individualActions = action.getActions();
logger.info("Executing a batch action that contains " + individualActions.size() + " individual actions");
var resultList = Stream.generate(() -> null)
.limit(individualActions.size())
.map(o -> (ActionExecutionResult) o)
.collect(Collectors.toList());
try {
var future = createCompletableFutureForBatchAction(individualActions, resultList, executionContext);
long t0 = System.currentTimeMillis();
future.get();
long t1 = System.currentTimeMillis();
logger.info("Finished execution of batch action in " + (t1 - t0) + " ms");
} catch (InterruptedException | ExecutionException e) {
logger.log(Level.SEVERE, "Error while waiting for completions", e);
throw new ActionExecutionException("Error: " + e.getMessage());
}
return DispatchServiceResultContainer.create(BatchResult.get(ImmutableList.copyOf(resultList)));
}

private CompletableFuture<Void> createCompletableFutureForBatchAction(ImmutableList<Action<?>> individualActions,
List<ActionExecutionResult> resultList,
ExecutionContext executionContext) {
List<CompletableFuture<Void>> futures = new ArrayList<>();
for (int i = 0; i < individualActions.size(); i++) {
final int index = i;
var future = CompletableFuture.runAsync(() -> {
var innerAction = individualActions.get(index);
try {
long t0 = System.currentTimeMillis();
var innerResult = executeAction(innerAction, executionContext);
long t1 = System.currentTimeMillis();
logger.info(" Executed " + innerAction.getClass().getSimpleName() + " in " + (t1 - t0) + " ms");
var innerExecutionResult = ActionExecutionResult.get(innerResult);
resultList.set(index, innerExecutionResult);
} catch (ActionExecutionException e) {
resultList.add(ActionExecutionResult.get(e));
} catch (PermissionDeniedException e) {
resultList.add(ActionExecutionResult.get(e));
}
});
futures.add(future);
}
var cfs = futures.toArray(new CompletableFuture[0]);
return CompletableFuture.allOf(cfs);
}


@Override
public RpcWhiteList getRpcWhiteList(RpcWhiteList list) {
return new RpcWhiteList();
Expand Down

0 comments on commit daef507

Please sign in to comment.