Skip to content
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

[DROOLS-6683] improve ContextImpl constructor performance (#4012) #4014

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package org.drools.core.command;

import org.drools.core.command.impl.ContextImpl;
import org.kie.api.runtime.Context;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.drools.core.command.impl.ContextImpl;
import org.kie.api.runtime.Context;


public class ConversationContextManager {

private Map<String, Context> conversationContexts;

private long counter;

public ConversationContextManager() {
conversationContexts = new HashMap<String, Context>();
conversationContexts = new HashMap<>();
}

public void startConversation(RequestContextImpl requestContext) {
Expand All @@ -33,10 +31,6 @@ public void joinConversation(RequestContextImpl requestContext, String conversat
requestContext.setConversationContext(ctx);
}

public void leaveConversation(RequestContextImpl requestContext, String conversationId) {
throw new UnsupportedOperationException("Need to implement");
}

public void endConversation(RequestContextImpl requestContext, String conversationId) {
conversationContexts.remove(conversationId);
requestContext.setConversationContext(null);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

import org.drools.core.world.impl.ContextManagerImpl;
import org.kie.api.runtime.Context;
Expand All @@ -28,9 +28,11 @@

public class ContextImpl implements RegistryContext {

public static final AtomicInteger ID_GENERATOR = new AtomicInteger(0);

public static final String REGISTRY = "__REGISTRY__";

private final Map<String, Object> map = new ConcurrentHashMap<String, Object>();
private final Map<String, Object> map = new ConcurrentHashMap<>();

private final ContextManager manager;

Expand All @@ -39,7 +41,7 @@ public class ContextImpl implements RegistryContext {
private final Context delegate;

public ContextImpl() {
this( UUID.randomUUID().toString(), new ContextManagerImpl() );
this( "Context_" + ID_GENERATOR.incrementAndGet(), new ContextManagerImpl() );
}

public ContextImpl(String name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.drools.core.command.EndConversationCommand;
import org.drools.core.command.JoinConversationCommand;
import org.drools.core.command.LeaveConversationCommand;
import org.drools.core.command.OutCommand;
import org.drools.core.command.StartConversationCommand;
import org.kie.api.command.ExecutableCommand;
Expand Down Expand Up @@ -130,12 +129,6 @@ public T joinConversation(String uuid) {
return (T) this;
}

@Override
public T leaveConversation() {
fluentCtx.addCommand(new LeaveConversationCommand());
return (T) this;
}

@Override
public T endConversation(String uuid) {
fluentCtx.addCommand(new EndConversationCommand(uuid));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public <T> T execute(Command<T> command) {

try {
if ( command instanceof BatchExecutionCommand ) {
((RegistryContext) context).register( ExecutionResultImpl.class, new ExecutionResultImpl() );
context.register( ExecutionResultImpl.class, new ExecutionResultImpl() );
}

((StatefulKnowledgeSessionImpl) ksession).startBatchExecution();
Expand All @@ -265,7 +265,7 @@ public <T> T execute(Command<T> command) {
ksession.fireAllRules();
}
if ( command instanceof BatchExecutionCommand ) {
return (T) ((RegistryContext) context).lookup( ExecutionResultImpl.class );
return (T) context.lookup( ExecutionResultImpl.class );
} else {
return (T) o;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,24 @@
import java.util.HashMap;
import java.util.Map;

import org.drools.core.command.GetDefaultValue;
import org.drools.core.command.impl.ContextImpl;
import org.kie.api.command.Command;
import org.kie.api.command.ExecutableCommand;
import org.kie.api.runtime.CommandExecutor;
import org.kie.api.runtime.Context;
import org.kie.internal.command.ContextManager;

public class ContextManagerImpl
implements ContextManager, GetDefaultValue, CommandExecutor {

public class ContextManagerImpl implements ContextManager, CommandExecutor {

private Context root;
private Map<String, Context> contexts;
private final Map<String, Context> contexts;

public static String ROOT = "ROOT";

private CommandExecutionHandler executionHandler = new DefaultCommandExecutionHandler();

private Object lastReturnValue;

public ContextManagerImpl() {
this( new HashMap<String, Context>() );
this( new HashMap<>() );
}

public ContextManagerImpl( Map<String, Context> contexts ) {
Expand Down Expand Up @@ -82,12 +77,8 @@ public Context getRootContext() {
return this.root;
}

public Object getLastReturnValue() {
return this.lastReturnValue;
}

public static interface CommandExecutionHandler {
public Object execute( ExecutableCommand command,
public interface CommandExecutionHandler {
Object execute( ExecutableCommand command,
Context context );
}

Expand All @@ -100,18 +91,6 @@ public Object execute( ExecutableCommand command,
}
}

public Object getObject() {
return lastReturnValue;
}

public ContextManager getContextManager() {
return this;
}

public String getName() {
return root.getName();
}

public Object get( String identifier ) {
return root.get( identifier );
}
Expand Down