New issue 598 by michal.g...@gmail.com: Persist Extension:
PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598
The PersistService.start() method claims that it is possible to call this
method multiple times. The implementation however
throws "java.lang.IllegalStateException: Persistence service was already
initialized." on second call.
This is a problem since it is not possible to determine if the service was
already started. Moreover the PersistFilter starts the PersistService in
initialization. Therefore it is not possible to use the persistence in any
ServletContextListener!
We can add a simple isActive() method, would that solve the issue for you?
Well that would be nice. However this will not solve the problem when the
PersistService is already started in some ServletContextListener. What
about adding this check to the PersistFilter:
public void init(FilterConfig filterConfig) throws ServletException {
if (! persistService.isActive()) { // <--
persistService.start();
}
}
Issue 605 has been merged into this issue.
Comment #4 on issue 598 by sberlin: Persist Extension:
PersistService.start() cannot be called multiple times
http://code.google.com/p/google-guice/issues/detail?id=598
(No comment was entered for this change.)
There is another related problem:
Sequence start() -> stop() -> start() throws the same exception even if the
restart should be possible.
The reason is that start checks for the emFactory to be null but it is
never reset on stop().
public synchronized void start() {
Preconditions.checkState(null == emFactory, "Persistence service was
already initialized.");
...
}
public synchronized void stop() {
Preconditions.checkState(emFactory.isOpen(), "Persistence service was
already shut down.");
emFactory.close();
}