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

SLING-5668 - Leverage ServletRequestListener.requestDestroyed for cal… #1

Merged
merged 2 commits into from Dec 8, 2017

Conversation

justinedelson
Copy link
Contributor

…ling DisposalCallback in case the model was created from a request

…ling DisposalCallback in case the model was created from a request
Copy link
Member

@kwin kwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need an IT for this modified behaviour. Having a mistake in it or breaking this stuff in future commits would be really painful.

@@ -1046,11 +1075,22 @@ protected ThreadInvocationCounter initialValue() {

this.configPrinterRegistration = bundleContext.registerService(Object.class.getName(),
new ModelConfigurationPrinter(this, bundleContext, adapterImplementations), printerProps);

Hashtable<Object, Object> listenerProps = new Hashtable<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about registering this service via DS? Seems easier and requires less code IMHO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with DS in this case (which is already true of the ConfigurationPrinter right above this) is that it needs access to internal data structures of the ModelAdapterFactory, so I'd rather keep that all internal and manage the lifecycle manually.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly all service properties are constants. If you add the ServletRequestListener to the Service annotation from above, the same component (i.e. object/instance) would be used for both the ModelAdapterFactory and the ServletRequestListener so you would not have any problems access internal data structure of ModelAdapterFactory from ServletRequestListener.onDispose. The only drawback I see is that you need to combine/expose the properties for both services (i.e. ModelAdapterFactory and ServletRequestListener) in this single component.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what you mean now. Yeah, that might work.

@@ -1256,4 +1300,16 @@ private Object handleBoundModelResult(Result<?> result) {
scriptEngineFactory, bindingsValuesProvidersByContext).adaptTo(targetClass);
}

@Override
public void requestDestroyed(ServletRequestEvent sre) {
ServletRequest request = unwrapRequest(sre.getServletRequest());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also find it weird, that this event does still contained a wrapped servlet request. But unwrapping does not do any harm (in no case).

@@ -1046,11 +1075,22 @@ protected ThreadInvocationCounter initialValue() {

this.configPrinterRegistration = bundleContext.registerService(Object.class.getName(),
new ModelConfigurationPrinter(this, bundleContext, adapterImplementations), printerProps);

Hashtable<Object, Object> listenerProps = new Hashtable<>();
listenerProps.put("osgi.http.whiteboard.context.select", "(osgi.http.whiteboard.context.name=*)");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not without bumping the dependency. But maybe that should be done anyway since (as far as I know), this functionality will effectively depend upon a 6.0 HttpService implementation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, bumping the dependency is reasonable as HTTP whiteboard is only available since OSGi Comp R6.

@justinedelson
Copy link
Contributor Author

An IT is a good idea, although I'm not sure how to do it since the request would be synthetic and thus not fire the listener. A unit test should be possible. I'll look into that.

@justinedelson
Copy link
Contributor Author

I've made the requested changes.

@justinedelson justinedelson merged commit 7dce056 into apache:master Dec 8, 2017
@justinedelson justinedelson deleted the issue/SLING-5668 branch December 8, 2017 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants