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

LocatorServiceLayer not always using ServiceLocator for create Locators #9594

Open
guinamen opened this issue Feb 2, 2018 · 2 comments
Open

Comments

@guinamen
Copy link

guinamen commented Feb 2, 2018

**GWT version: 2.8.2
**Browser (with version): All
**Operating System: All


Hi.

I am working in a integration GWT2.8.2 an Weld 2.4.6.Final to inject Locator class in process context.
For doing this job i created a ServiceLocator instance that return a injected Locator, simple like this:

@OverRide
public Object getInstance(Class<?> clazz) {
return WeldUtility.getBean(clazz);
}
But...
Some times the class LocatorServiceLayer use the function newInstance to create new Locator's instance.
For me the correct way to work is the LocatorServiceLayer class create only an instance of ServiceLocator and than use getInstance to get a Locator. But sometimes it use the ServiceLocator others it use newInstance to get Locator.

Steps to reproduce

Put a break point in newInstance a LocatorServiceLayer's method and verifies that a Locator class is one parameters

Known workarounds

@OverRide
public <T extends Locator> T createLocator(Class clazz) {
//return newInstance(clazz, Locator.class);
ServiceLocator serviceLocatorClazz = resolveServiceLocator(requestContext);
if (clazz != null)
return newInstance(serviceLocatorClazz, ServiceLocator.class ).getInstance(clazz);
else
return newInstance(clazz, Locator.class);
}

Links to further discussions
@niloc132
Copy link
Contributor

niloc132 commented Feb 2, 2018

If this is specific to weld and the rest of your environment, we may need a more comprehensive example.

That said, a ServiceLayerDecorator is almost certainly needed to customize creation of your Locators and ServiceLocators, especially if you have a custom way to get a Locator based on the ServiceLocator (as the ServiceLocator is written to locate Services, and not entity locators). If that is your criticism, then as I understand it this is by design.

Implementing a ServiceLayerDecorator is pretty easy, then you just pass an instance of it to the RequestFactoryServlet's constructor (or to the SimpleRequestProcessor, if that is what you are creating instead). https://github.com/niloc132/tvguide-sample-parent/blob/master/tvguide-client/src/main/java/com/acme/gwt/server/InjectableServiceLayerDecorator.java shows a sample that delegates to Guice, it would likely be very similar to how you could do this in Weld.

Your note "some times" does confuse me though, without overriding this, Locators should always be created via LocatorServiceLayer.createLocator. My best guess is that you are encountering the caching mechanism described in ServiceLayer.ENABLE_CACHE.

@guinamen
Copy link
Author

guinamen commented Feb 2, 2018

Hi niloc132 first, thanks a lot.
Is better i explain why i am doing this integration. My critic of GWT's architecture is two:

  1. There are to much new objects bean creating all time.

  2. There are no "save state" objects between requests.

To resolve problems i proposed a integration with Weld.

After some debug i discovered that the problem is in createReturnOperations of SimpleRequestProcessor class.
In processInvocationMessages there is a if that verify if the service requires a service locator at line 457. So during the process of processInvocationMessages method from SimpleRequestProcessor class, it uses Locators from ServiceLocator by passing it in args, but during the process of createReturnOperations and others operation it does not verify the need of ServiceLocator. It delegate the locator to LocatorServiceLayer that create a new instance calling newInstance.

I disable cache by setting gwt.rf.ServiceLayerCache=false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants