Skip to content

Commit

Permalink
More fixes for #1451
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed May 20, 2014
1 parent 873217e commit 3f45200
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public String getInitParameter(String closedAtmosphereThinkTime, String defaultV
}

public AtmosphereResourceFactory resourcesFactory(){
return framework.arFactory;
return framework.atmosphereFactory();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public class AtmosphereFramework {
protected final List<String> excludedInterceptors = new ArrayList<String>();
protected final LinkedList<BroadcasterCacheListener> broadcasterCacheListeners = new LinkedList<BroadcasterCacheListener>();
protected final List<BroadcasterConfig.FilterManipulator> filterManipulators = new ArrayList<BroadcasterConfig.FilterManipulator>();
protected final AtmosphereResourceFactory arFactory = new AtmosphereResourceFactory();
protected AtmosphereResourceFactory arFactory;
protected final Class<? extends AtmosphereInterceptor>[] defaultInterceptors = new Class[]{
// Add CORS support
CorsInterceptor.class,
Expand Down Expand Up @@ -297,8 +297,8 @@ public String toString() {
* </p>
*
* @author Guillaume DROUET
* @since 2.2.0
* @version 1.0
* @since 2.2.0
*/
public static enum MetaServiceAction {

Expand Down Expand Up @@ -333,7 +333,7 @@ private MetaServiceAction(final MetaServiceProcedure p) {
* Applies this action to given class.
* </p>
*
* @param fwk the framework
* @param fwk the framework
* @param clazz the class
* @throws Exception if procedure fails
*/
Expand All @@ -348,8 +348,8 @@ public void apply(final AtmosphereFramework fwk, final Class<?> clazz) throws Ex
* </p>
*
* @author Guillaume DROUET
* @since 2.2.0
* @version 1.0
* @since 2.2.0
*/
private static interface MetaServiceProcedure {

Expand All @@ -358,7 +358,7 @@ private static interface MetaServiceProcedure {
* Processes an action.
* </p>
*
* @param fwk the framework
* @param fwk the framework
* @param clazz the class to use during processing
* @throws Exception if procedure fails
*/
Expand All @@ -371,8 +371,8 @@ private static interface MetaServiceProcedure {
* </p>
*
* @author Guillaume DROUET
* @since 2.2.0
* @version 1.0
* @since 2.2.0
*/
private static class InstallMetaServiceProcedure implements MetaServiceProcedure {

Expand Down Expand Up @@ -417,8 +417,8 @@ public void apply(final AtmosphereFramework fwk, final Class c) throws Exception
* </p>
*
* @author Guillaume DROUET
* @since 2.2.0
* @version 1.0
* @since 2.2.0
*/
private static class ExcludeMetaServiceProcedure implements MetaServiceProcedure {

Expand Down Expand Up @@ -621,7 +621,7 @@ public AtmosphereFramework addAtmosphereHandler(String mapping, AtmosphereHandle
if (!isInit) {
logger.info("Installed AtmosphereHandler {} mapped to context-path {} and Broadcaster Class {}",
new String[]{h.getClass().getName(), mapping, broadcaster.getClass().getName()});
} else {
} else {
logger.debug("Installed AtmosphereHandler {} mapped to context-path {} and Broadcaster Class {}",
new String[]{h.getClass().getName(), mapping, broadcaster.getClass().getName()});
}
Expand Down Expand Up @@ -1144,7 +1144,7 @@ protected void configureScanningPackage(ServletConfig sc, String value) {
}
}

protected void defaultPackagesToScan(){
protected void defaultPackagesToScan() {
// Atmosphere HA/Pro
packages.add("io.async.control");
packages.add("io.async.satellite");
Expand Down Expand Up @@ -1173,6 +1173,7 @@ public void configureBroadcasterFactory() {
}

BroadcasterFactory.setBroadcasterFactory(broadcasterFactory, config);
configureAtmosphereResourceFactory();
} catch (Exception ex) {
logger.error("Unable to configure Broadcaster/Factory/Cache", ex);
}
Expand Down Expand Up @@ -1578,14 +1579,13 @@ public AtmosphereFramework destroy() {
}

arFactory.destroy();
AtmosphereResourceFactory.getDefault().destroy();
WebSocketProcessorFactory.getDefault().destroy();

resetStates();
return this;
}

public AtmosphereFramework resetStates(){
public AtmosphereFramework resetStates() {
isInit = false;
executeFirstSet = false;

Expand All @@ -1607,7 +1607,7 @@ public AtmosphereFramework resetStates(){

broadcasterFactory = null;
annotationFound = false;
return this;
return this;
}

protected void loadMetaService() {
Expand Down Expand Up @@ -2158,7 +2158,7 @@ public AtmosphereFramework addBroadcasterType(String broadcasterTypeString) {
return this;
}

public ConcurrentLinkedQueue<String> broadcasterTypes(){
public ConcurrentLinkedQueue<String> broadcasterTypes() {
return broadcasterTypes;
}

Expand Down Expand Up @@ -2363,7 +2363,7 @@ protected void positionInterceptor(InvokationOrder.PRIORITY p, AtmosphereInterce
}

private boolean checkDuplicate(AtmosphereInterceptor c) {
for (AtmosphereInterceptor i: interceptors) {
for (AtmosphereInterceptor i : interceptors) {
if (i.getClass().equals(c.getClass()))
return false;
}
Expand Down Expand Up @@ -2428,7 +2428,7 @@ public AtmosphereFramework addBroadcasterCacheListener(BroadcasterCacheListener
}

public List<BroadcasterCacheListener> broadcasterCacheListeners() {
return broadcasterCacheListeners;
return broadcasterCacheListeners;
}

/**
Expand Down Expand Up @@ -2694,6 +2694,7 @@ public AtmosphereFramework annotationScanned(boolean b) {

/**
* Return true if the {@link #init()} has been sucessfully executed.
*
* @return true if the {@link #init()} has been sucessfully executed.
*/
public boolean initialized() {
Expand Down Expand Up @@ -2727,7 +2728,7 @@ public AtmosphereFramework addCustomAnnotationPackage(Class p) {
/**
* Instantiate a class
*
* @param classType The Required Class's Type
* @param classType The Required Class's Type
* @param defaultType The default implementation of the Class's Type.
* @return the an instance of defaultType
* @throws InstantiationException
Expand Down Expand Up @@ -2813,19 +2814,19 @@ public AtmosphereFramework filterManipulator(BroadcasterConfig.FilterManipulator
return this;
}

public List<BroadcasterConfig.FilterManipulator> filterManipulators(){
public List<BroadcasterConfig.FilterManipulator> filterManipulators() {
return filterManipulators;
}

public boolean isAServletFilter() {
return isFilter;
}

public ConcurrentLinkedQueue<String> objectFactoryType(){
public ConcurrentLinkedQueue<String> objectFactoryType() {
return objectFactoryType;
}

public String mappingRegex(){
public String mappingRegex() {
return mappingRegex;
}

Expand All @@ -2838,7 +2839,7 @@ public void setUseServlet30(boolean useServlet30) {
this.useServlet30 = useServlet30;
}

public boolean webSocketEnabled(){
public boolean webSocketEnabled() {
return webSocketEnabled;
}

Expand All @@ -2847,20 +2848,20 @@ public AtmosphereFramework webSocketEnabled(boolean webSocketEnabled) {
return this;
}

public String broadcasterLifeCyclePolicy(){
public String broadcasterLifeCyclePolicy() {
return broadcasterLifeCyclePolicy;
}

public AtmosphereFramework broadcasterLifeCyclePolicy(String broadcasterLifeCyclePolicy){
public AtmosphereFramework broadcasterLifeCyclePolicy(String broadcasterLifeCyclePolicy) {
this.broadcasterLifeCyclePolicy = broadcasterLifeCyclePolicy;
return this;
}

public List<BroadcasterListener> broadcasterListeners(){
public List<BroadcasterListener> broadcasterListeners() {
return broadcasterListeners;
}

public boolean sharedThreadPools(){
public boolean sharedThreadPools() {
return sharedThreadPools;
}

Expand All @@ -2869,28 +2870,42 @@ public AtmosphereFramework sharedThreadPools(boolean sharedThreadPools) {
return this;
}

public boolean allowAllClassesScan(){
public boolean allowAllClassesScan() {
return allowAllClassesScan;
}

public AtmosphereFramework allowAllClassesScan(boolean b) {
public AtmosphereFramework allowAllClassesScan(boolean allowAllClassesScan) {
this.allowAllClassesScan = allowAllClassesScan;
return this;
}

public AtmosphereObjectFactory objectFactory(){
public AtmosphereObjectFactory objectFactory() {
return objectFactory;
}

public boolean externalizeDestroy(){
public boolean externalizeDestroy() {
return externalizeDestroy;
}

public List<String> excludedInterceptors(){
public List<String> excludedInterceptors() {
return excludedInterceptors;
}

public Class<? extends AtmosphereInterceptor>[] defaultInterceptors(){
public Class<? extends AtmosphereInterceptor>[] defaultInterceptors() {
return defaultInterceptors;
}


public AtmosphereResourceFactory atmosphereFactory() {
if (arFactory == null) {
configureAtmosphereResourceFactory();
}
return arFactory;
}

private AtmosphereFramework configureAtmosphereResourceFactory() {
arFactory = new AtmosphereResourceFactory(broadcasterFactory);
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ public void onRequest(AtmosphereResource resource) throws IOException {
public void destroy() {
}
};
private final BroadcasterFactory broadcasterFactory;

public AtmosphereResourceFactory(){
public AtmosphereResourceFactory(BroadcasterFactory broadcasterFactory){
this.broadcasterFactory = broadcasterFactory;
// This is quite ugly, but here for legacy reason.
factory = this;
}
Expand Down Expand Up @@ -131,13 +133,13 @@ public final AtmosphereResource create(AtmosphereConfig config,
AtmosphereResponse response,
AsyncSupport<?> a,
AtmosphereHandler handler,
AtmosphereResource.TRANSPORT T) {
AtmosphereResource.TRANSPORT t) {
AtmosphereResource r = null;
try {
r = config.framework().newClassInstance(AtmosphereResource.class, AtmosphereResourceImpl.class);

if (request.getHeader(X_ATMOSPHERE_TRANSPORT) == null) {
request.header(X_ATMOSPHERE_TRANSPORT, T.name());
request.header(X_ATMOSPHERE_TRANSPORT, t.name());
}
r.initialize(config, broadcaster, request, response, a, handler);
} catch (Exception e) {
Expand Down Expand Up @@ -248,7 +250,7 @@ public final AtmosphereResource find(String uuid) {
* @return all {@link Broadcaster} associated with a {@link AtmosphereResource#uuid}
*/
public final Set<Broadcaster> broadcasters(String uuid) {
Collection<Broadcaster> l = BroadcasterFactory.getDefault().lookupAll();
Collection<Broadcaster> l = broadcasterFactory.lookupAll();
Set<Broadcaster> h = new HashSet<Broadcaster>();
for (Broadcaster b : l) {
for (AtmosphereResource r : b.getAtmosphereResources()) {
Expand All @@ -262,13 +264,9 @@ public final Set<Broadcaster> broadcasters(String uuid) {

/**
* Use {@link AtmosphereConfig#resourcesFactory() instead}
* @deprecated
* @deprecated Use {@link org.atmosphere.cpr.AtmosphereConfig#resourcesFactory()}
*/
public final static AtmosphereResourceFactory getDefault() {
// Ugly, for legacy reason
if (factory == null) {
new AtmosphereResourceFactory();
}
return factory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public abstract class BroadcasterFactory {
* Return the default {@link BroadcasterFactory}.
*
* @return the default {@link BroadcasterFactory}.
* @deprecated Use {@link org.atmosphere.cpr.AtmosphereConfig#resourcesFactory()}
*/
public synchronized static BroadcasterFactory getDefault() {
return factory;
Expand Down

0 comments on commit 3f45200

Please sign in to comment.