Skip to content

Commit

Permalink
Fix for #276 [runtime] Add writeOnTimeout API to AtmosphereResource
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Apr 11, 2012
1 parent 8a6331a commit 329b2b9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ void invokeAtmosphereHandler(AtmosphereResourceImpl r) throws IOException {

AtmosphereRequest req = r.getRequest(false);
String disableOnEvent = r.getAtmosphereConfig().getInitParameter(ApplicationConfig.DISABLE_ONSTATE_EVENT);
r.getAtmosphereResourceEvent().setMessage(null);
r.getAtmosphereResourceEvent().setMessage(r.writeOnTimeout());
try {
if (disableOnEvent == null || !disableOnEvent.equals(String.valueOf(true))) {
AtmosphereHandler atmosphereHandler =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,14 @@ enum TRANSPORT {POLLING, LONG_POLLING, STREAMING, WEBSOCKET, JSONP, UNDEFINED}
*/
AtmosphereHandler getAtmosphereHandler();

/**
* Set a message that will be written when the resource times out. Cab be an {@link Object} or {@link java.util.concurrent.Callable}
*/
AtmosphereResource writeOnTimeout(Object o);

/**
* Return the object that will be written when the resource times out;
*/
Object writeOnTimeout();

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public class AtmosphereResourceImpl implements AtmosphereResource {
private boolean isResumed = false;
private boolean isCancelled = false;
private boolean resumeOnBroadcast = false;
private Object writeOnTimeout = null;

private final ConcurrentLinkedQueue<AtmosphereResourceEventListener> listeners =
new ConcurrentLinkedQueue<AtmosphereResourceEventListener>();
Expand Down Expand Up @@ -162,6 +163,23 @@ public AtmosphereHandler getAtmosphereHandler() {
return atmosphereHandler;
}

/**
* {@inheritDoc}
*/
@Override
public AtmosphereResource writeOnTimeout(Object o) {
writeOnTimeout = o;
return this;
}

/**
* {@inheritDoc}
*/
@Override
public Object writeOnTimeout() {
return writeOnTimeout;
}

/**
* {@inheritDoc}
*/
Expand Down

0 comments on commit 329b2b9

Please sign in to comment.