Skip to content

Commit

Permalink
Fixes #2091
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Nov 23, 2015
1 parent 333fd01 commit 4191190
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,6 @@ public interface ApplicationConfig {
* Value: org.atmosphere.cpr.AsynchronousProcessor.closeOnCancel
*/
String CLOSE_STREAM_ON_CANCEL = "org.atmosphere.cpr.AsynchronousProcessor.closeOnCancel";

/**
* Use init parameters specified for servlet context in addition to servlet config
* Default: false
Expand All @@ -917,12 +916,21 @@ public interface ApplicationConfig {
* Writes the given data to the given outputstream in two steps with extra flushes to make servers notice if the connection has been closed.
* This enables caching the message instead of losing it, if the client is in the progress of reconnecting via a Proxy where
* the server fails to detect the connection has been closed.
*
* <p/>
* This value only apply to LONG-POLLING transport
*
* <p/>
* Default: false
* Value: org.atmosphere.cpr.AbstractReflectorAtmosphereHandler.twoStepsWrite
*/
String TWO_STEPS_WRITE = "org.atmosphere.cpr.AbstractReflectorAtmosphereHandler.twoStepsWrite";
/**
* How many times the {@link org.atmosphere.inject.InjectableObjectFactory} will try to construct and inject an object
* from an {@link org.atmosphere.inject.Injectable}. This happens when an Injectable returns null instead of the
* expected Injection
* <p/>
* Default: 5
* Value: org.atmosphere.cpr.InjectableObjectFactory.maxTry
*/
String INJECTION_TRY = "org.atmosphere.cpr.InjectableObjectFactory.maxTry";
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.atmosphere.inject;

import com.sun.org.apache.bcel.internal.generic.FLOAD;
import org.atmosphere.cpr.ApplicationConfig;
import org.atmosphere.cpr.AtmosphereConfig;
import org.atmosphere.cpr.AtmosphereFramework;
import org.atmosphere.cpr.AtmosphereObjectFactory;
Expand Down Expand Up @@ -54,6 +54,7 @@ public class InjectableObjectFactory implements AtmosphereObjectFactory<Injectab
private final LinkedList<InjectIntrospector<?>> introspectors = new LinkedList<InjectIntrospector<?>>();
private final LinkedList<InjectIntrospector<?>> requestScopedIntrospectors = new LinkedList<InjectIntrospector<?>>();
private final LinkedBlockingDeque<Object> pushBackInjection = new LinkedBlockingDeque();
private int maxTry;

private AtmosphereConfig config;

Expand All @@ -64,6 +65,7 @@ public InjectableObjectFactory() {
@Override
public void configure(AtmosphereConfig config) {
this.config = config;
this.maxTry = config.getInitParameter(ApplicationConfig.INJECTION_TRY, 5);
for (Injectable<?> i : injectableServiceLoader) {
try {
logger.debug("Adding class {} as injectable", i.getClass());
Expand Down Expand Up @@ -103,19 +105,28 @@ public void started(AtmosphereFramework framework) {
// dependency between Injectable, e.g one depend on other, or if the Injectable is not defined at the right place
// in META-INF/services/org/atmosphere/inject.Injectable
Set<Field> fields = new HashSet<Field>();
try {
for (Object instance : pushBackInjection) {
Object instance = null;
while (pushBackInjection.size() > 0 & maxTry-- > 0) {
java.util.Iterator<Object> t = pushBackInjection.iterator();
pushBackInjection.clear();
while (t.hasNext())
instance = t.next();
fields.addAll(getInheritedPrivateFields(instance.getClass()));
try {
injectFields(fields, instance, framework, injectables);
} catch (IllegalAccessException e) {
logger.warn("", e);
}
try {
injectFields(fields, instance, framework, injectables);
applyMethods(instance, (Class<Object>) instance.getClass());
} catch (IllegalAccessException e) {
logger.warn("", e);
} finally {
fields.clear();
}
} finally {
pushBackInjection.clear();
}

if (pushBackInjection.size() > 0) {
logger.warn("Injection failed for {}", pushBackInjection);
}


}
});
}
Expand Down

0 comments on commit 4191190

Please sign in to comment.