Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not easy to customize DefaultWebSocketProcessor #1714

Closed
flowersinthesand opened this issue Sep 13, 2014 · 0 comments
Closed

Not easy to customize DefaultWebSocketProcessor #1714

flowersinthesand opened this issue Sep 13, 2014 · 0 comments

Comments

@flowersinthesand
Copy link
Member

First it may be a uncommon case to customize WebSocketProcessor but anyway I found these problems in doing that.

  1. WebSocketProcessorFactory swallows java.lang.InstantiationException

I couldn't know why my customized WebSocketProcessor extending DefaultWebSocketProcessor doesn't work. After the debugging, I found that WebSocketProcessorFactory swallows java.lang.InstantiationException occurred due to constructor arguments mismatch and provides an instance of the default one instead without any log.

} catch (Exception ex) {
processor = new DefaultWebSocketProcessor(framework);
}

  1. DefaultWebSocketProcessor doesn't have empty constructor.

If a given class is not the default one, WebSocketProcessorFactory creates a customized processor using ObjectFactory from AtmosphereFramework. But it can't handle constructor args so it's not possible to extend DefaultWebSocketProcessor directly and use it. In other words, ObjectFactory requires empty constructor but DefaultWebSocketProcessor doesn't provide it so its sub class can't have it.

processor = framework.newClassInstance(WebSocketProcessor.class,
(Class<WebSocketProcessor>) IOUtils.loadClass(getClass(), webSocketProcessorName));

  1. A customized WebSocketProcessor can't access to AtmosphereFramework

For the above reason, a customized WebSocketProcessor must have empty constructor and not extend DefaultWebSocketProcessor (and can create DefaultWebSocketProcessor internally to delegate methods calls) but in this case it can't get the corresponding AtmosphereFramework unless it uses a special object factory or something other way allowing injecting AtmosphereFramework.

Finally I solved it by creating my own object factory to intercept a method call to provide my customized processor when it's required.
https://github.com/vibe-project/vibe-java-platform/blob/9b8fc1bb6ddb276135422d5fb77a0ca7f9f8582f/atmosphere2/src/main/java/org/atmosphere/vibe/platform/server/atmosphere2/AtmosphereBridge.java#L76-L78

jfarcand added a commit that referenced this issue Sep 15, 2014
@jfarcand jfarcand added the 2.3.0 label Sep 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants