Skip to content

Commit

Permalink
remove conversation.isLongRunning, support @New(Foo)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Oct 19, 2009
1 parent f07d531 commit 07f5248
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 33 deletions.
4 changes: 0 additions & 4 deletions impl/pom.xml
Expand Up @@ -99,16 +99,12 @@
<dependency>
<groupId>org.jboss.interceptor</groupId>
<artifactId>jboss-interceptor-api</artifactId>
<!-- WELD-198 -->
<!-- <optional>true</optional>-->
</dependency>


<dependency>
<groupId>org.jboss.interceptor</groupId>
<artifactId>jboss-interceptor</artifactId>
<!-- WELD-198 -->
<!-- <optional>true</optional>-->
</dependency>

</dependencies>
Expand Down
Expand Up @@ -26,6 +26,8 @@
import java.util.Map;
import java.util.Set;

import javax.enterprise.inject.New;

import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.bean.AbstractBean;
import org.jboss.weld.bean.AbstractClassBean;
Expand Down Expand Up @@ -214,14 +216,28 @@ private void addNewBeansFromInjectionPoints(Set<WeldInjectionPoint<?, ?>> newInj
{
for (WeldInjectionPoint<?, ?> injectionPoint : newInjectionPoints)
{
if (getEjbDescriptors().contains(injectionPoint.getJavaClass()))
New _new = injectionPoint.getAnnotation(New.class);
if (_new.value().equals(New.class))
{
newSessionBeanDescriptors.add(getEjbDescriptors().getUnique(injectionPoint.getJavaClass()));
addNewBeanFromInjecitonPoint(injectionPoint.getJavaClass(), injectionPoint.getBaseType());
}
else
{
newManagedBeanClasses.add(classTransformer.loadClass(injectionPoint.getJavaClass(), injectionPoint.getBaseType()));
addNewBeanFromInjecitonPoint(_new.value(), _new.value());
}

}
}

private void addNewBeanFromInjecitonPoint(Class<?> rawType, Type baseType)
{
if (getEjbDescriptors().contains(rawType))
{
newSessionBeanDescriptors.add(getEjbDescriptors().getUnique(rawType));
}
else
{
newManagedBeanClasses.add(classTransformer.loadClass(rawType, baseType));
}
}

Expand Down
Expand Up @@ -130,7 +130,7 @@ public void cleanupConversation()
{
log.trace("Cleaning up conversation for " + currentConversation);
String cid = currentConversation.getUnderlyingId();
if (currentConversation.isLongRunning())
if (!currentConversation.isTransient())
{
Future<?> terminationHandle = scheduleForTermination(cid, currentConversation.getTimeout());
// When the conversation ends, a long-running conversation needs to
Expand Down
Expand Up @@ -51,7 +51,7 @@ public class ConversationImpl implements Conversation, Serializable
// The original conversation ID (if any)
private String originalId;
// Is the conversation long-running?
private boolean longRunning;
private boolean _transient = true;
// The timeout in milliseconds
private long timeout;

Expand All @@ -70,7 +70,7 @@ public ConversationImpl()
public ConversationImpl(ConversationImpl conversation)
{
this.id = conversation.getUnderlyingId();
this.longRunning = conversation.isLongRunning();
this._transient = conversation.isTransient();
this.timeout = conversation.getTimeout();
}

Expand All @@ -85,18 +85,18 @@ public void init(ConversationIdGenerator conversationIdGenerator, @ConversationI
{
this.id = conversationIdGenerator.nextId();
this.timeout = timeout;
this.longRunning = false;
this._transient = true;
log.debug("Created a new conversation " + this);
}

public void begin()
{
if (isLongRunning())
if (!isTransient())
{
throw new IllegalStateException("Attempt to call begin() on a long-running conversation");
}
log.debug("Promoted conversation " + id + " to long-running");
longRunning = true;
this._transient = false;
}

public void begin(String id)
Expand All @@ -115,17 +115,17 @@ public void begin(String id)

public void end()
{
if (!isLongRunning())
if (isTransient())
{
throw new IllegalStateException("Attempt to call end() on a transient conversation");
}
log.debug("Demoted conversation " + id + " to transient");
this.longRunning = false;
this._transient = true;
}

public String getId()
{
if (isLongRunning())
if (!isTransient())
{
return id;
}
Expand All @@ -151,11 +151,6 @@ public long getTimeout()
return timeout;
}

public boolean isLongRunning()
{
return longRunning;
}

public void setTimeout(long timeout)
{
this.timeout = timeout;
Expand All @@ -171,21 +166,15 @@ public void switchTo(ConversationImpl conversation)
{
log.debug("Switched conversation from " + this);
id = conversation.getUnderlyingId();
longRunning = conversation.isLongRunning();
this._transient = conversation.isTransient();
timeout = conversation.getTimeout();
log.debug(" to " + this);
}

@Override
public String toString()
{
return "ID: " + id + ", long-running: " + longRunning + ", timeout: " + timeout + "ms";
}

public void setLongRunning(boolean longRunning)
{
log.debug("Set conversation " + id + " to long-running: " + longRunning);
this.longRunning = longRunning;
return "ID: " + id + ", transient: " + isTransient() + ", timeout: " + timeout + "ms";
}

/**
Expand Down Expand Up @@ -220,6 +209,6 @@ public int hashCode()

public boolean isTransient()
{
return !isLongRunning();
return _transient;
}
}
Expand Up @@ -68,7 +68,7 @@ public String getActionURL(FacesContext context, String viewId)
{
String actionUrl = super.getActionURL(context, viewId);
ConversationImpl conversation = getModuleBeanManager(context).getInstanceByType(ConversationImpl.class);
if (conversation.isLongRunning())
if (!conversation.isTransient())
{
return new FacesUrlTransformer(actionUrl, context).appendConversationIdIfNecessary(conversation.getUnderlyingId()).getUrl();
}
Expand Down
Expand Up @@ -17,12 +17,14 @@
package org.jboss.weld.resolution;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.HashSet;
import java.util.Set;

import javax.enterprise.inject.New;

import org.jboss.weld.literal.NewLiteral;
import org.jboss.weld.util.Reflections;

/**
* @author pmuir
Expand Down Expand Up @@ -81,6 +83,33 @@ public <A extends Annotation> A getAnnotation(Class<A> annotationType)

};
}
else
{
final Class<?> javaClass = originalNewAnnotation.value();
final Set<Type> typeClosure = new Reflections.HierarchyDiscovery(javaClass).getTypeClosureAsSet();
return new ForwardingResolvable()
{

@Override
protected Resolvable delegate()
{
return element;
}

@Override
public Class<?> getJavaClass()
{
return javaClass;
}

@Override
public Set<Type> getTypeClosure()
{
return typeClosure;
}

};
}
}
return element;
}
Expand Down
Expand Up @@ -80,7 +80,7 @@ private ServletResponse wrapResponse(HttpServletResponse response, final String
public void sendRedirect(String path) throws IOException
{
ConversationImpl conversation = getModuleBeanManager(ctx) .getInstanceByType(ConversationImpl.class);
if (conversation.isLongRunning())
if (!conversation.isTransient())
{
String cidParamName = getModuleBeanManager(ctx).getInstanceByType(String.class, new AnnotationLiteral<ConversationIdName>(){});
path = new FacesUrlTransformer(path, FacesContext.getCurrentInstance()).toRedirectViewId().toActionUrl().appendConversationIdIfNecessary(conversation.getUnderlyingId()).encode();
Expand Down
2 changes: 1 addition & 1 deletion jboss-tck-runner/src/test/resources/log4j.xml
Expand Up @@ -14,7 +14,7 @@
</filter>
<filter class="org.apache.log4j.varia.StringMatchFilter">
<param name="AcceptOnMatch" value="false" />
<param name="StringToMatch" value="Error destroying org.jboss.weld.bean-test-ManagedBean-org.jboss.jsr299.tck.tests.implementation.simple.lifecycle.Cod" />
<param name="StringToMatch" value="Error destroying org.jboss.weld.bean-test-ManagedBean-class org.jboss.jsr299.tck.tests.implementation.simple.lifecycle.Cod" />
</filter>
</appender>

Expand Down

0 comments on commit 07f5248

Please sign in to comment.