Commit e5e294d0cc60e1093f538e1e95fbc4fcabc10da9
1 parent
e3193825
Exists in
master
Implementado método para determinar se o "store" de custom contexts foi
inicializado. Usa isso para evitar acesso desnecessário a getStore() e evitar um bug onde se criava um store (via getStore()) apenas para testar se ele está vazio.
Showing
6 changed files
with
28 additions
and
5 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CoreBootstrap.java
@@ -91,13 +91,16 @@ public class CoreBootstrap implements Extension { | @@ -91,13 +91,16 @@ public class CoreBootstrap implements Extension { | ||
91 | 91 | ||
92 | ContextManager.activate(StaticContext.class, StaticScoped.class); | 92 | ContextManager.activate(StaticContext.class, StaticScoped.class); |
93 | } | 93 | } |
94 | + | ||
95 | + public void terminateCustomContexts(@Observes final BeforeShutdown event) { | ||
96 | + ContextManager.shutdown(); | ||
97 | + } | ||
94 | 98 | ||
95 | public void takeOff(@Observes final AfterDeploymentValidation event) { | 99 | public void takeOff(@Observes final AfterDeploymentValidation event) { |
96 | getLogger().info(getBundle().getString("taking-off")); | 100 | getLogger().info(getBundle().getString("taking-off")); |
97 | } | 101 | } |
98 | 102 | ||
99 | public void engineOff(@Observes final BeforeShutdown event) { | 103 | public void engineOff(@Observes final BeforeShutdown event) { |
100 | - ContextManager.shutdown(); | ||
101 | getLogger().info(getBundle().getString("engine-off")); | 104 | getLogger().info(getBundle().getString("engine-off")); |
102 | } | 105 | } |
103 | } | 106 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractCustomContext.java
@@ -58,12 +58,15 @@ public abstract class AbstractCustomContext implements CustomContext { | @@ -58,12 +58,15 @@ public abstract class AbstractCustomContext implements CustomContext { | ||
58 | } | 58 | } |
59 | 59 | ||
60 | protected abstract Store getStore(); | 60 | protected abstract Store getStore(); |
61 | + | ||
62 | + protected abstract boolean isStoreInitialized(); | ||
61 | 63 | ||
62 | @Override | 64 | @Override |
63 | public <T> T get(final Contextual<T> contextual) { | 65 | public <T> T get(final Contextual<T> contextual) { |
64 | return get(contextual, null); | 66 | return get(contextual, null); |
65 | } | 67 | } |
66 | 68 | ||
69 | + @SuppressWarnings("unchecked") | ||
67 | @Override | 70 | @Override |
68 | public <T> T get(final Contextual<T> contextual, final CreationalContext<T> creationalContext) { | 71 | public <T> T get(final Contextual<T> contextual, final CreationalContext<T> creationalContext) { |
69 | T instance = null; | 72 | T instance = null; |
@@ -97,7 +100,9 @@ public abstract class AbstractCustomContext implements CustomContext { | @@ -97,7 +100,9 @@ public abstract class AbstractCustomContext implements CustomContext { | ||
97 | public void setActive(boolean active) { | 100 | public void setActive(boolean active) { |
98 | if (!active && this.active) { | 101 | if (!active && this.active) { |
99 | // Limpando contexto | 102 | // Limpando contexto |
100 | - getStore().clear(); | 103 | + if (isStoreInitialized()){ |
104 | + getStore().clear(); | ||
105 | + } | ||
101 | } | 106 | } |
102 | this.active = active; | 107 | this.active = active; |
103 | } | 108 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ContextManager.java
@@ -10,7 +10,6 @@ import javax.enterprise.context.ContextNotActiveException; | @@ -10,7 +10,6 @@ import javax.enterprise.context.ContextNotActiveException; | ||
10 | import javax.enterprise.context.spi.Context; | 10 | import javax.enterprise.context.spi.Context; |
11 | import javax.enterprise.inject.spi.AfterBeanDiscovery; | 11 | import javax.enterprise.inject.spi.AfterBeanDiscovery; |
12 | import javax.enterprise.inject.spi.BeanManager; | 12 | import javax.enterprise.inject.spi.BeanManager; |
13 | -import javax.enterprise.inject.spi.BeforeShutdown; | ||
14 | 13 | ||
15 | import org.slf4j.Logger; | 14 | import org.slf4j.Logger; |
16 | 15 | ||
@@ -196,8 +195,7 @@ public class ContextManager { | @@ -196,8 +195,7 @@ public class ContextManager { | ||
196 | 195 | ||
197 | /** | 196 | /** |
198 | * <p> | 197 | * <p> |
199 | - * This method should be called when the application is shutting down, usually by observing the | ||
200 | - * {@link BeforeShutdown} event. | 198 | + * This method should be called when the application is shutting down. |
201 | * </p> | 199 | * </p> |
202 | */ | 200 | */ |
203 | public static synchronized void shutdown() { | 201 | public static synchronized void shutdown() { |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/StaticContext.java
@@ -50,4 +50,9 @@ public class StaticContext extends AbstractCustomContext { | @@ -50,4 +50,9 @@ public class StaticContext extends AbstractCustomContext { | ||
50 | protected Store getStore() { | 50 | protected Store getStore() { |
51 | return store; | 51 | return store; |
52 | } | 52 | } |
53 | + | ||
54 | + @Override | ||
55 | + protected boolean isStoreInitialized() { | ||
56 | + return store!=null; | ||
57 | + } | ||
53 | } | 58 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ThreadLocalContext.java
@@ -62,6 +62,11 @@ public class ThreadLocalContext extends AbstractCustomContext { | @@ -62,6 +62,11 @@ public class ThreadLocalContext extends AbstractCustomContext { | ||
62 | public ThreadLocalContext(final Class<? extends Annotation> scope) { | 62 | public ThreadLocalContext(final Class<? extends Annotation> scope) { |
63 | super(scope); | 63 | super(scope); |
64 | } | 64 | } |
65 | + | ||
66 | + @Override | ||
67 | + protected boolean isStoreInitialized() { | ||
68 | + return threadLocal.get()!=null; | ||
69 | + } | ||
65 | 70 | ||
66 | @Override | 71 | @Override |
67 | protected Store getStore() { | 72 | protected Store getStore() { |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/context/ViewContext.java
@@ -38,6 +38,8 @@ package br.gov.frameworkdemoiselle.internal.context; | @@ -38,6 +38,8 @@ package br.gov.frameworkdemoiselle.internal.context; | ||
38 | 38 | ||
39 | import java.util.Map; | 39 | import java.util.Map; |
40 | 40 | ||
41 | +import javax.faces.context.FacesContext; | ||
42 | + | ||
41 | import br.gov.frameworkdemoiselle.annotation.ViewScoped; | 43 | import br.gov.frameworkdemoiselle.annotation.ViewScoped; |
42 | import br.gov.frameworkdemoiselle.util.Faces; | 44 | import br.gov.frameworkdemoiselle.util.Faces; |
43 | 45 | ||
@@ -46,6 +48,11 @@ public class ViewContext extends AbstractCustomContext { | @@ -46,6 +48,11 @@ public class ViewContext extends AbstractCustomContext { | ||
46 | public ViewContext() { | 48 | public ViewContext() { |
47 | super(ViewScoped.class); | 49 | super(ViewScoped.class); |
48 | } | 50 | } |
51 | + | ||
52 | + @Override | ||
53 | + protected boolean isStoreInitialized() { | ||
54 | + return FacesContext.getCurrentInstance()!=null; | ||
55 | + } | ||
49 | 56 | ||
50 | @Override | 57 | @Override |
51 | protected Store getStore() { | 58 | protected Store getStore() { |