Skip to content

Commit

Permalink
Final fixes for #1620
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Sep 10, 2014
1 parent 0f30d9f commit baf4b5b
Showing 1 changed file with 30 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,39 +198,41 @@ public void onStateChange(AtmosphereResourceEvent event) throws IOException {
r.getRequest(false).setAttribute(ApplicationConfig.RESUME_ON_BROADCAST, false);
}

if (event.isCancelled() || event.isClosedByClient()) {
invoke(onDisconnectMethod, event);
} else if (event.isResumedOnTimeout() || event.isResuming()) {
invoke(onTimeoutMethod, event);
} else {
Object o;
if (msg != null) {
if (Managed.class.isAssignableFrom(msg.getClass())) {
Object newMsg = Managed.class.cast(msg).o;
event.setMessage(newMsg);
// No method matched. Give a last chance by trying to decode the proxiedInstance.
// This makes application development more simpler.
// Chaining of encoder is not supported.
// TODO: This could be problematic with String + method
for (MethodInfo m : onRuntimeMethod) {
o = Invoker.encode(encoders.get(m.method), newMsg);
try {
if (event.isCancelled() || event.isClosedByClient()) {
invoke(onDisconnectMethod, event);
} else if (event.isResumedOnTimeout() || event.isResuming()) {
invoke(onTimeoutMethod, event);
} else {
Object o;
if (msg != null) {
if (Managed.class.isAssignableFrom(msg.getClass())) {
Object newMsg = Managed.class.cast(msg).o;
event.setMessage(newMsg);
// No method matched. Give a last chance by trying to decode the proxiedInstance.
// This makes application development more simpler.
// Chaining of encoder is not supported.
// TODO: This could be problematic with String + method
for (MethodInfo m : onRuntimeMethod) {
o = Invoker.encode(encoders.get(m.method), newMsg);
if (o != null) {
event.setMessage(o);
break;
}
}
} else {
logger.trace("BroadcasterFactory has been used, this may produce recursion if encoder/decoder match the broadcasted message");
final MethodInfo.EncoderObject e = message(r, msg);
o = e == null ? null : e.encodedObject;
if (o != null) {
event.setMessage(o);
break;
}
}
} else {
logger.trace("BroadcasterFactory has been used, this may produce recursion if encoder/decoder match the broadcasted message");
final MethodInfo.EncoderObject e = message(r, msg);
o = e == null ? null : e.encodedObject;
if (o != null) {
event.setMessage(o);
}
}
super.onStateChange(event);
}

} finally {
r.getRequest().removeAttribute(getClass().getName());
super.onStateChange(event);
}

if (resumeOnBroadcast && r.isSuspended()) {
Expand Down Expand Up @@ -474,7 +476,7 @@ public MethodInfo(Method method) {
* Creates a new {@link org.atmosphere.config.managed.ManagedAtmosphereHandler.MethodInfo.EncoderObject} which encodes the given object and wraps the result.
* </p>
*
* @param encoders the encoders
* @param encoders the encoders
* @param objectToEncode the object to encode and wrap
* @return the resulting object encoder
*/
Expand Down Expand Up @@ -506,7 +508,7 @@ class EncoderObject {
* Builds a new instance.
* </p>
*
* @param encoders the encoders
* @param encoders the encoders
* @param objectToEncode the object to encode
*/
public EncoderObject(final Map<Method, List<Encoder<?, ?>>> encoders, final Object objectToEncode) {
Expand Down

0 comments on commit baf4b5b

Please sign in to comment.