Revision 7e488d1b
Added by Andreas Kohlbecker over 6 years ago
- ID 7e488d1bb2f09a0bc4c282c8694b3c1e54bd04ba
- Parent 475ec4ee
src/main/java/eu/etaxonomy/cdm/vaadin/session/ViewScopeConversationHolder.java | ||
---|---|---|
14 | 14 |
|
15 | 15 |
import org.hibernate.FlushMode; |
16 | 16 |
import org.hibernate.SessionFactory; |
17 |
import org.springframework.beans.factory.DisposableBean; |
|
17 | 18 |
import org.springframework.orm.hibernate5.support.OpenSessionInViewFilter; |
18 | 19 |
import org.springframework.transaction.PlatformTransactionManager; |
19 | 20 |
import org.springframework.transaction.TransactionDefinition; |
... | ... | |
48 | 49 |
*/ |
49 | 50 |
@SpringComponent |
50 | 51 |
@ViewScope |
51 |
public class ViewScopeConversationHolder extends ConversationHolder implements Serializable { |
|
52 |
public class ViewScopeConversationHolder extends ConversationHolder implements Serializable, DisposableBean {
|
|
52 | 53 |
|
53 | 54 |
|
54 | 55 |
private static final long serialVersionUID = 1001768184000981106L; |
... | ... | |
80 | 81 |
setDefinition(definition ); |
81 | 82 |
} |
82 | 83 |
|
84 |
/** |
|
85 |
* {@inheritDoc} |
|
86 |
*/ |
|
87 |
@Override |
|
88 |
public void destroy() throws Exception { |
|
89 |
close(); |
|
90 |
} |
|
91 |
|
|
83 | 92 |
|
84 | 93 |
|
85 | 94 |
|
src/main/java/eu/etaxonomy/cdm/vaadin/ui/DistributionStatusUI.java | ||
---|---|---|
1 | 1 |
package eu.etaxonomy.cdm.vaadin.ui; |
2 | 2 |
|
3 | 3 |
import org.apache.log4j.Logger; |
4 |
import org.springframework.beans.factory.DisposableBean; |
|
4 | 5 |
import org.springframework.beans.factory.annotation.Autowired; |
5 | 6 |
import org.springframework.context.ApplicationEventPublisher; |
6 | 7 |
|
... | ... | |
8 | 9 |
import com.vaadin.annotations.Title; |
9 | 10 |
import com.vaadin.annotations.Widgetset; |
10 | 11 |
import com.vaadin.navigator.Navigator; |
11 |
import com.vaadin.navigator.View; |
|
12 | 12 |
import com.vaadin.navigator.ViewDisplay; |
13 | 13 |
import com.vaadin.server.Page; |
14 | 14 |
import com.vaadin.server.Responsive; |
... | ... | |
17 | 17 |
import com.vaadin.spring.navigator.SpringViewProvider; |
18 | 18 |
import com.vaadin.ui.UI; |
19 | 19 |
|
20 |
import eu.etaxonomy.cdm.vaadin.security.ReleasableResourcesView; |
|
21 | 20 |
import eu.etaxonomy.cdm.vaadin.view.RedirectToLoginView; |
22 | 21 |
import eu.etaxonomy.cdm.vaadin.view.distributionStatus.DistributionTableViewBean; |
23 | 22 |
import eu.etaxonomy.vaadin.ui.UIInitializedEvent; |
... | ... | |
28 | 27 |
@SpringUI(path="distribution") |
29 | 28 |
@Widgetset("eu.etaxonomy.cdm.vaadin.AppWidgetSet") |
30 | 29 |
@SuppressWarnings("serial") |
31 |
public class DistributionStatusUI extends UI{ |
|
30 |
public class DistributionStatusUI extends UI implements DisposableBean {
|
|
32 | 31 |
|
33 | 32 |
private final static Logger logger = Logger.getLogger(DistributionStatusUI.class); |
34 | 33 |
|
... | ... | |
75 | 74 |
@Override |
76 | 75 |
protected void init(VaadinRequest request) { |
77 | 76 |
|
78 |
addDetachListener(e -> { |
|
79 |
for(String viewName : viewProvider.getViewNamesForCurrentUI()){ |
|
80 |
View view = viewProvider.getView(viewName); |
|
81 |
if(view != null && view instanceof ReleasableResourcesView) { |
|
82 |
((ReleasableResourcesView)view).releaseResourcesOnAccessDenied(); |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
}); |
|
87 |
|
|
88 | 77 |
configureAccessDeniedView(); |
89 | 78 |
|
90 | 79 |
Responsive.makeResponsive(this); |
... | ... | |
102 | 91 |
navigator.setDefaultViewName(INITIAL_VIEW); |
103 | 92 |
|
104 | 93 |
} |
94 |
|
|
95 |
/** |
|
96 |
* {@inheritDoc} |
|
97 |
*/ |
|
98 |
@Override |
|
99 |
public void destroy() throws Exception { |
|
100 |
navigator.setDefaultViewName(null); |
|
101 |
viewDisplay = null; |
|
102 |
} |
|
105 | 103 |
} |
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPresenter.java | ||
---|---|---|
5 | 5 |
import org.apache.log4j.Logger; |
6 | 6 |
import org.hibernate.Session; |
7 | 7 |
import org.hibernate.engine.spi.SessionImplementor; |
8 |
import org.springframework.beans.factory.DisposableBean; |
|
8 | 9 |
import org.springframework.beans.factory.annotation.Autowired; |
9 | 10 |
import org.springframework.beans.factory.annotation.Qualifier; |
10 | 11 |
import org.springframework.security.core.context.SecurityContext; |
... | ... | |
37 | 38 |
* @param <V> |
38 | 39 |
* type of the view this presenter governs |
39 | 40 |
*/ |
40 |
public abstract class AbstractPresenter<V extends ApplicationView> implements Serializable, IntraViewConversationDirector, RequestStartListener { |
|
41 |
public abstract class AbstractPresenter<V extends ApplicationView> implements Serializable, IntraViewConversationDirector, |
|
42 |
RequestStartListener, DisposableBean { |
|
41 | 43 |
|
42 | 44 |
|
43 | 45 |
private static final long serialVersionUID = 5260910510283481832L; |
... | ... | |
272 | 274 |
logger.trace(String.format("%s onViewExit()", _toString())); |
273 | 275 |
handleViewExit(); |
274 | 276 |
// un-register as request start and end listener |
275 |
if(conversationBound){ |
|
276 |
logger.trace(String.format("<<<<< %s onViewExit() unbind()", _toString())); |
|
277 |
conversationHolder.unbind(); |
|
278 |
conversationBound = false; |
|
279 |
} |
|
280 |
logger.trace(String.format("<<<<< %s onViewExit() close()", _toString())); |
|
281 |
conversationHolder.close(); |
|
277 |
cleanupConversation(); |
|
278 |
cleanupRequestListeners(); |
|
279 |
} |
|
280 |
|
|
281 |
@Override |
|
282 |
public void destroy() { |
|
283 |
cleanupConversation(); |
|
284 |
cleanupRequestListeners(); |
|
285 |
view = null; |
|
286 |
} |
|
287 |
|
|
288 |
/** |
|
289 |
* |
|
290 |
*/ |
|
291 |
protected void cleanupRequestListeners() { |
|
282 | 292 |
VaadinService service = UI.getCurrent().getSession().getService(); |
283 | 293 |
if(service instanceof CdmSpringVaadinServletService){ |
284 | 294 |
logger.trace(String.format("~~~~~ %s un-register as request listener", _toString())); |
... | ... | |
289 | 299 |
} else { |
290 | 300 |
throw new RuntimeException("Using the CdmSpringVaadinServletService is required for proper per view conversation handling"); |
291 | 301 |
} |
292 |
} |
|
302 |
} |
|
303 |
|
|
304 |
/** |
|
305 |
* |
|
306 |
*/ |
|
307 |
protected void cleanupConversation() { |
|
308 |
if(conversationBound){ |
|
309 |
logger.trace(String.format("<<<<< %s cleanupConversation() unbind()", _toString())); |
|
310 |
conversationHolder.unbind(); // TODO remove, unbind is done on close below |
|
311 |
conversationBound = false; |
|
312 |
} |
|
313 |
logger.trace(String.format("<<<<< %s cleanupConversation() close()", _toString())); |
|
314 |
conversationHolder.close(); |
|
315 |
} |
|
293 | 316 |
|
294 | 317 |
/** |
295 | 318 |
* Extending classes should overwrite this method to react to the event when |
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractView.java | ||
---|---|---|
4 | 4 |
|
5 | 5 |
import org.apache.log4j.Logger; |
6 | 6 |
import org.springframework.beans.BeansException; |
7 |
import org.springframework.beans.factory.DisposableBean; |
|
7 | 8 |
import org.springframework.beans.factory.annotation.Autowired; |
8 | 9 |
import org.springframework.context.ApplicationContext; |
9 | 10 |
import org.springframework.context.ApplicationContextAware; |
... | ... | |
26 | 27 |
*/ |
27 | 28 |
@SuppressWarnings("serial") |
28 | 29 |
public abstract class AbstractView<P extends AbstractPresenter> extends CustomComponent |
29 |
implements ApplicationContextAware, ReleasableResourcesView { |
|
30 |
implements ApplicationContextAware, ReleasableResourcesView, DisposableBean {
|
|
30 | 31 |
|
31 | 32 |
|
32 | 33 |
public static final Logger logger = Logger.getLogger(AbstractView.class); |
... | ... | |
41 | 42 |
@SuppressWarnings("unchecked") |
42 | 43 |
@PostConstruct |
43 | 44 |
protected final void init() { |
45 |
|
|
46 |
// addDetachListener(e -> { |
|
47 |
// getPresenter().onViewExit(); |
|
48 |
// } |
|
49 |
// ); |
|
50 |
|
|
44 | 51 |
Logger.getLogger(getClass().getSimpleName()).info("View init"); |
45 | 52 |
if(!ApplicationView.class.isAssignableFrom(this.getClass())){ |
46 | 53 |
throw new RuntimeException("Any view bean must implement the ApplicationView interface: ViewBean ---> ViewInterface ---> ApplicationView"); |
... | ... | |
99 | 106 |
public void releaseResourcesOnAccessDenied() { |
100 | 107 |
getPresenter().onViewExit(); |
101 | 108 |
} |
109 |
|
|
110 |
@Override |
|
111 |
public void destroy() { |
|
112 |
presenter = null; |
|
113 |
} |
|
102 | 114 |
} |
Also available in: Unified diff
ref #7036 disposing resources in mvp beans