use of javax.resource.spi.UnavailableException in project tomee by apache.
the class MdbContainer method invoke.
public Object invoke(final Object deploymentId, final InterfaceType type, final Class callInterface, final Method method, final Object[] args, final Object primKey) throws OpenEJBException {
final BeanContext beanContext = getBeanContext(deploymentId);
final EndpointFactory endpointFactory = (EndpointFactory) beanContext.getContainerData();
final MdbInstanceFactory instanceFactory = endpointFactory.getInstanceFactory();
final Instance instance;
try {
instance = (Instance) instanceFactory.createInstance(true);
} catch (final UnavailableException e) {
throw new SystemException("Unable to create instance for invocation", e);
}
try {
beforeDelivery(beanContext, instance, method, null);
final Object value = invoke(instance, method, type, args);
afterDelivery(instance);
return value;
} finally {
instanceFactory.freeInstance(instance, true);
}
}
use of javax.resource.spi.UnavailableException in project wildfly by wildfly.
the class TransactionInflowWork method run.
public void run() {
MessageEndpoint messageEndpoint;
try {
messageEndpoint = messageFactory.createEndpoint(null);
if (messageEndpoint instanceof MessageListener) {
log.tracef("Calling on message on endpoint '%s' with data message '%s'", messageEndpoint, msg);
TransactionInflowTextMessage textMessage = new TransactionInflowTextMessage(msg);
((MessageListener) messageEndpoint).onMessage(textMessage);
} else {
throw new IllegalStateException("Not supported message endpoint: " + messageEndpoint);
}
} catch (UnavailableException ue) {
String msg = String.format("Not capable to create message factory '%s' endpoint", messageFactory);
throw new IllegalStateException(msg, ue);
}
}
use of javax.resource.spi.UnavailableException in project tomee by apache.
the class EndpointFactory method createEndpoint.
@Override
public MessageEndpoint createEndpoint(final XAResource xaResource, final long timeout) throws UnavailableException {
if (timeout <= 0) {
return createEndpoint(xaResource);
}
final long end = System.currentTimeMillis() + timeout;
MessageEndpoint messageEndpoint = null;
while (System.currentTimeMillis() <= end) {
try {
messageEndpoint = createEndpoint(xaResource);
break;
} catch (final Exception ex) {
// ignore so we can keep trying
}
}
if (messageEndpoint != null) {
return messageEndpoint;
} else {
throw new UnavailableException("Unable to create end point within the specified timeout " + timeout);
}
}
use of javax.resource.spi.UnavailableException in project tomee by apache.
the class EndpointHandler method deliverMessage.
public Object deliverMessage(final Method method, final Object[] args) throws Throwable {
boolean callBeforeAfter = false;
// verify current state
switch(state) {
case NONE:
try {
beforeDelivery(method);
} catch (final ApplicationServerInternalException e) {
throw (EJBException) new EJBException().initCause(e.getCause());
}
callBeforeAfter = true;
state = State.METHOD_CALLED;
break;
case BEFORE_CALLED:
state = State.METHOD_CALLED;
break;
case RELEASED:
throw new IllegalStateException("Message endpoint factory has been released");
case METHOD_CALLED:
case SYSTEM_EXCEPTION:
throw new IllegalStateException("The last message delivery must be completed with an afterDeliver before another message can be delivered");
}
Throwable throwable = null;
Object value = null;
try {
// deliver the message
value = container.invoke(instance, method, null, wrapMessageForAmq5(args));
} catch (final SystemException se) {
throwable = se.getRootCause() != null ? se.getRootCause() : se;
state = State.SYSTEM_EXCEPTION;
} catch (final ApplicationException ae) {
throwable = ae.getRootCause() != null ? ae.getRootCause() : ae;
} finally {
// if the adapter is not using before/after, we must call afterDelivery to clean up
if (callBeforeAfter) {
try {
afterDelivery();
} catch (final ApplicationServerInternalException e) {
throwable = throwable == null ? e.getCause() : throwable;
} catch (final UnavailableException e) {
throwable = throwable == null ? e : throwable;
}
}
}
if (throwable != null) {
throwable.printStackTrace();
if (isValidException(method, throwable)) {
throw throwable;
} else {
throw new EJBException().initCause(throwable);
}
}
return value;
}
use of javax.resource.spi.UnavailableException in project tomee by apache.
the class MdbInstanceFactory method constructBean.
private Object constructBean() throws UnavailableException {
final BeanContext beanContext = this.beanContext;
final ThreadContext callContext = new ThreadContext(beanContext, null, Operation.INJECTION);
final ThreadContext oldContext = ThreadContext.enter(callContext);
try {
final InstanceContext context = beanContext.newInstance();
if (context.getBean() instanceof MessageDrivenBean) {
callContext.setCurrentOperation(Operation.CREATE);
final Method create = beanContext.getCreateMethod();
final InterceptorStack ejbCreate = new InterceptorStack(context.getBean(), create, Operation.CREATE, new ArrayList(), new HashMap());
ejbCreate.invoke();
}
return new Instance(context.getBean(), context.getInterceptors(), context.getCreationalContext());
} catch (Throwable e) {
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
final String message = "The bean instance threw a system exception:" + e;
MdbInstanceFactory.logger.error(message, e);
throw new UnavailableException(message, e);
} finally {
ThreadContext.exit(oldContext);
}
}
Aggregations