Skip to content

Commit

Permalink
JUZU-48 : Remove unnecessary bottleneck when retrieving Requests
Browse files Browse the repository at this point in the history
Actually, there a big bottleneck JUZU applications
Each time a JUZU application is displayed in a page, all other HTTP requests that wants to display any other page that uses JUZU will be blocked because of one operation in JUZU application lifecycle.
In fact, inside the "retrieve the response" phase, the operation "get the filters beans associated to the Stage type(Unmarshaling, Handler, Lifecycle, Invoke)" is synchronized (blocker, one operation at a time).
The filters are SINGLETON beans, so we should put those beans in the JUZU controller context once for all.
  • Loading branch information
boubaker authored and Thomas Delhoménie committed Oct 14, 2016
1 parent 827dbca commit 8a37cfb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Expand Up @@ -24,6 +24,7 @@
import juzu.impl.request.ContextualParameter;
import juzu.impl.request.ControlParameter;
import juzu.impl.request.ControllerHandler;
import juzu.impl.request.RequestFilter;
import juzu.impl.value.ValueType;
import juzu.request.Phase;
import juzu.io.UndeclaredIOException;
Expand All @@ -36,11 +37,13 @@
import juzu.request.RequestParameter;

import javax.inject.Inject;

import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/** @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a> */
public class ControllerService extends ApplicationService {
Expand All @@ -51,6 +54,9 @@ public class ControllerService extends ApplicationService {
/** . */
final ArrayList<ValueType<?>> valueTypes = new ArrayList<ValueType<?>>();

/** . */
final List<RequestFilter<?>> filters = new ArrayList<RequestFilter<?>>();

/** . */
@Inject
private Application application;
Expand Down Expand Up @@ -83,6 +89,20 @@ public ServiceDescriptor init(ServiceContext context) throws Exception {
public InjectionContext<?, ?> getInjectionContext() {
return application.getInjectionContext();
}

public List<RequestFilter<?>> getFilters() {
if (filters.isEmpty()) {
synchronized (filters) {
if (filters.isEmpty()) {
// Build the filter list
for (RequestFilter<?> filter : getInjectionContext().resolveInstances(RequestFilter.class)) {
filters.add(filter);
}
}
}
}
return filters;
}

public <T> ValueType<T> resolveValueType(Class<T> type) {
for (int i = 0;i < valueTypes.size();i++) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/juzu/impl/request/Stage.java
Expand Up @@ -64,7 +64,7 @@ public Stage(Request request) {

// Build the filter list
List<RequestFilter<?>> filters = new ArrayList<RequestFilter<?>>();
for (RequestFilter<?> filter : request.controllerPlugin.getInjectionContext().resolveInstances(RequestFilter.class)) {
for (RequestFilter<?> filter : request.controllerPlugin.getFilters()) {
if (getClass().isAssignableFrom(filter.getStageType())) {
filters.add(filter);
}
Expand Down

0 comments on commit 8a37cfb

Please sign in to comment.