Author: dan.j.allen
Date: 2009-06-12 17:21:46 -0400 (Fri, 12 Jun 2009)
New Revision: 11144
Removed:
branches/community/Seam_2_2/src/main/org/jboss/seam/jms/ContextualMessageHandlerRequest.java
branches/community/Seam_2_2/src/main/org/jboss/seam/jms/ContextualMessageHandlerRequestInterceptor.java
Log:
rollback. turns out we don't need this stuff. need to update docs so people don't
get confused again.
Deleted:
branches/community/Seam_2_2/src/main/org/jboss/seam/jms/ContextualMessageHandlerRequest.java
===================================================================
---
branches/community/Seam_2_2/src/main/org/jboss/seam/jms/ContextualMessageHandlerRequest.java 2009-06-12
21:21:33 UTC (rev 11143)
+++
branches/community/Seam_2_2/src/main/org/jboss/seam/jms/ContextualMessageHandlerRequest.java 2009-06-12
21:21:46 UTC (rev 11144)
@@ -1,161 +0,0 @@
-package org.jboss.seam.jms;
-
-import java.lang.reflect.ParameterizedType;
-
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.TextMessage;
-
-import org.jboss.seam.Component;
-import org.jboss.seam.async.AbstractDispatcher;
-import org.jboss.seam.bpm.BusinessProcess;
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.contexts.Lifecycle;
-import org.jboss.seam.core.Init;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
-
-/**
- * <p>
- * A class which provides a contextual-thread context for message-driven beans
- * in the scope of which Seam components can be instantiated and invoked.
- * </p>
- *
- * <p>
- * NOTE: Users are still likely to get the error reported in <a
- *
href="https://jira.jboss.org/jira/browse/EJBTHREE-898">EJBTH...
if a
- * transaction operation is performed in the message handler.
- * </p>
- *
- * @author Dan Allen
- */
-public abstract class ContextualMessageHandlerRequest<T>
-{
- private static transient final LogProvider log =
Logging.getLogProvider(ContextualMessageHandlerRequest.class);
-
- private Message message;
- private boolean setupRequired = false;
- private Object result = null;
- private T delegate;
-
- public ContextualMessageHandlerRequest(Message message)
- {
- this.message = message;
- this.setupRequired = !Contexts.isApplicationContextActive() &&
!Contexts.isEventContextActive();
- }
-
- public void run() throws Exception
- {
- setup();
- try
- {
- process();
- }
- finally
- {
- cleanup();
- }
- }
-
- public abstract void process() throws Exception;
-
- protected void setResult(Object result)
- {
- this.result = result;
- }
-
- public T getDelegate()
- {
- return delegate;
- }
-
- public Object getResult()
- {
- return result;
- }
-
- public Message getMessage()
- {
- return message;
- }
-
- /**
- * A convenience method to return the message as a TextMessage. If the
- * message is not a TextMessage, a null value is returned.
- */
- public TextMessage getTextMessage()
- {
- return message instanceof TextMessage ? (TextMessage) message : null;
- }
-
- @SuppressWarnings("unchecked")
- private void setup()
- {
- if (setupRequired)
- {
- Lifecycle.beginCall();
- }
-
- Contexts.getEventContext().set(AbstractDispatcher.EXECUTING_ASYNCHRONOUS_CALL,
true);
- if (Init.instance().isJbpmInstalled())
- {
- setupProcessOrTask();
- }
-
- Class<T> delegateClass = getDelegateClass();
- if (delegateClass != null)
- {
- delegate = (T) Component.getInstance(delegateClass);
- }
- }
-
- private void setupProcessOrTask()
- {
- try
- {
- Long taskId = message.getLongProperty("taskId");
- if (taskId != null)
- {
- BusinessProcess.instance().resumeTask(taskId);
- return;
- }
- }
- catch (JMSException e)
- {
- log.debug("Could not retrieve taskId from message object: " +
e.getMessage());
- }
-
- try
- {
- Long processId = message.getLongProperty("processId");
- if (processId != null)
- {
- BusinessProcess.instance().resumeProcess(processId);
- return;
- }
- }
- catch (JMSException e)
- {
- log.debug("Could not retrieve processId from message object: " +
e.getMessage());
- }
- }
-
- private void cleanup()
- {
- Contexts.getEventContext().remove(AbstractDispatcher.EXECUTING_ASYNCHRONOUS_CALL);
- if (setupRequired)
- {
- Lifecycle.endCall();
- }
- }
-
- /**
- * Get the type specified in the type parameter of the class. TODO This could
- * be made safer
- */
- @SuppressWarnings("unchecked")
- public Class<T> getDelegateClass()
- {
- return (Class<T>) ((ParameterizedType)
getClass().getGenericSuperclass()).getActualTypeArguments()[0];
- }
-}
Deleted:
branches/community/Seam_2_2/src/main/org/jboss/seam/jms/ContextualMessageHandlerRequestInterceptor.java
===================================================================
---
branches/community/Seam_2_2/src/main/org/jboss/seam/jms/ContextualMessageHandlerRequestInterceptor.java 2009-06-12
21:21:33 UTC (rev 11143)
+++
branches/community/Seam_2_2/src/main/org/jboss/seam/jms/ContextualMessageHandlerRequestInterceptor.java 2009-06-12
21:21:46 UTC (rev 11144)
@@ -1,44 +0,0 @@
-package org.jboss.seam.jms;
-
-import javax.interceptor.AroundInvoke;
-import javax.interceptor.InvocationContext;
-import javax.jms.Message;
-
-/**
- * <p>
- * An interceptor which is intented to be applied to message-driven beans to
- * setup a Seam request life cycle within the boundaries of the bean's method
- * calls so Seam components can be instantiated and invoked.
- * </p>
- *
- * <p>
- * TODO It would be nice to bake in an exception callback like the async
- * integration supports
- * </P>
- *
- * @author Dan Allen
- */
-public class ContextualMessageHandlerRequestInterceptor
-{
- @AroundInvoke
- public Object aroundInvoke(final InvocationContext invocation) throws Exception
- {
- String methodName = invocation.getMethod().getName();
- Object[] args = invocation.getParameters();
- if (!"onMessage".equals(methodName) || args.length != 1 || !(args[0]
instanceof Message))
- {
- return invocation.proceed();
- }
-
- ContextualMessageHandlerRequest contextualRequest = new
ContextualMessageHandlerRequest((Message) invocation.getParameters()[0])
- {
- @Override
- public void process() throws Exception
- {
- setResult(invocation.proceed());
- }
- };
- contextualRequest.run();
- return contextualRequest.getResult();
- }
-}