Skip to content

Commit

Permalink
More fixes for #1785
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Nov 21, 2014
1 parent ba4c76a commit c50d9ee
Show file tree
Hide file tree
Showing 11 changed files with 444 additions and 399 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public AtmosphereResourceFactory resourcesFactory(){
}

/**
* Return the {@link org.atmosphere.cpr.MetaBroadcaster}
* Return the {@link DefaultMetaBroadcaster}
* @return the MetaBroadcaster
*/
public MetaBroadcaster metaBroadcaster(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ public Enumeration<String> getInitParameterNames() {
configureAnnotationPackages();

configureBroadcasterFactory();
configureMetaBroadcaster();
configureScanningPackage(scFacade, ApplicationConfig.ANNOTATION_PACKAGE);
configureScanningPackage(scFacade, FrameworkConfig.JERSEY2_SCANNING_PACKAGE);
configureScanningPackage(scFacade, FrameworkConfig.JERSEY_SCANNING_PACKAGE);
Expand All @@ -885,7 +886,6 @@ public Enumeration<String> getInitParameterNames() {

// Reconfigure in case an annotation changed the default.
configureBroadcasterFactory();
configureMetaBroadcaster();
patchContainer();
configureBroadcaster();
loadConfiguration(scFacade);
Expand Down Expand Up @@ -3011,14 +3011,17 @@ private AtmosphereFramework configureAtmosphereResourceFactory() {
}

public MetaBroadcaster metaBroadcaster() {
if (metaBroadcaster == null) {
metaBroadcaster = new MetaBroadcaster(config);
}
return metaBroadcaster;
}

private AtmosphereFramework configureMetaBroadcaster() {
if (metaBroadcaster == null) {
try {
metaBroadcaster = newClassInstance(MetaBroadcaster.class, DefaultMetaBroadcaster.class);
metaBroadcaster.configure(config);
} catch (InstantiationException e) {
logger.error("", e);
} catch (IllegalAccessException e) {
logger.error("", e);
}
return this;
}
Expand Down Expand Up @@ -3082,7 +3085,13 @@ private void initDefaultSerializer() {
*/
public synchronized AtmosphereResourceSessionFactory sessionFactory() {
if (sessionFactory == null) {
sessionFactory = new DefaultAtmosphereResourceSessionFactory();
try {
sessionFactory = newClassInstance(AtmosphereResourceSessionFactory.class, DefaultAtmosphereResourceSessionFactory.class);
} catch (InstantiationException e) {
logger.error("", e);
} catch (IllegalAccessException e) {
logger.error("", e);
}
}
return sessionFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author uklance (https://github.com/uklance)
*/
public abstract class AtmosphereResourceSessionFactory {
public interface AtmosphereResourceSessionFactory {

/**
* Returns the current session associated with the
Expand All @@ -36,7 +36,7 @@ public abstract class AtmosphereResourceSessionFactory {
* @return the session associated with this request or null if create is
* false and the resource has no valid session
*/
public abstract AtmosphereResourceSession getSession(AtmosphereResource resource, boolean create);
AtmosphereResourceSession getSession(AtmosphereResource resource, boolean create);

/**
* Returns the current session associated with the
Expand All @@ -47,9 +47,7 @@ public abstract class AtmosphereResourceSessionFactory {
* {@link AtmosphereResource}, or creates one if it does not yet
* exist.
*/
public AtmosphereResourceSession getSession(AtmosphereResource resource) {
return getSession(resource, true);
}
AtmosphereResourceSession getSession(AtmosphereResource resource);

public abstract void destroy();
void destroy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* @author uklance (https://github.com/uklance)
*/
public class DefaultAtmosphereResourceSessionFactory extends AtmosphereResourceSessionFactory {
public class DefaultAtmosphereResourceSessionFactory implements AtmosphereResourceSessionFactory {
private final ConcurrentMap<String, AtmosphereResourceSession> sessions = new ConcurrentHashMap<String, AtmosphereResourceSession>();

private final AtmosphereResourceEventListener disconnectListener = new AtmosphereResourceEventListenerAdapter() {
Expand Down Expand Up @@ -54,6 +54,11 @@ public AtmosphereResourceSession getSession(AtmosphereResource r, boolean create
return session;
}

@Override
public AtmosphereResourceSession getSession(AtmosphereResource resource) {
return getSession(resource, true);
}

@Override
public void destroy() {
sessions.clear();
Expand Down
Loading

0 comments on commit c50d9ee

Please sign in to comment.