use of org.apache.openejb.SystemException in project tomee by apache.
the class RAFPassivater method passivate.
public synchronized void passivate(final Map stateTable) throws SystemException {
try (final RandomAccessFile ras = new RandomAccessFile(JavaSecurityManagers.getSystemProperty("java.io.tmpdir", File.separator + "tmp") + File.separator + "passivation" + fileID + ".ser", "rw")) {
fileID++;
final Iterator iterator = stateTable.keySet().iterator();
Pointer lastPointer = null;
while (iterator.hasNext()) {
final Object id = iterator.next();
final Object obj = stateTable.get(id);
final byte[] bytes = Serializer.serialize(obj);
final long filepointer = ras.getFilePointer();
if (lastPointer == null) {
lastPointer = new Pointer(fileID, filepointer, (int) filepointer);
} else {
lastPointer = new Pointer(fileID, filepointer, (int) (filepointer - lastPointer.filepointer));
}
masterTable.put(id, lastPointer);
ras.write(bytes);
}
} catch (final Exception e) {
throw new SystemException(e);
}
}
use of org.apache.openejb.SystemException in project tomee by apache.
the class MdbContainer method beforeDelivery.
public void beforeDelivery(final BeanContext deployInfo, final Object instance, final Method method, final XAResource xaResource) throws SystemException {
// intialize call context
final ThreadContext callContext = new ThreadContext(deployInfo, null);
final ThreadContext oldContext = ThreadContext.enter(callContext);
// create mdb context
final MdbCallContext mdbCallContext = new MdbCallContext();
callContext.set(MdbCallContext.class, mdbCallContext);
mdbCallContext.deliveryMethod = method;
mdbCallContext.oldCallContext = oldContext;
// call the tx before method
try {
mdbCallContext.txPolicy = createTransactionPolicy(deployInfo.getTransactionType(method), callContext);
// if we have an xaResource and a transaction was not imported from the adapter, enlist the xaResource
if (xaResource != null && mdbCallContext.txPolicy.isNewTransaction()) {
mdbCallContext.txPolicy.enlistResource(xaResource);
}
} catch (final ApplicationException e) {
ThreadContext.exit(oldContext);
throw new SystemException("Should never get an Application exception", e);
} catch (final SystemException e) {
ThreadContext.exit(oldContext);
throw e;
} catch (final Exception e) {
ThreadContext.exit(oldContext);
throw new SystemException("Unable to enlist xa resource in the transaction", e);
}
}
use of org.apache.openejb.SystemException 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 org.apache.openejb.SystemException in project tomee by apache.
the class EntityInstanceManager method getPooledInstance.
protected EntityBean getPooledInstance(final ThreadContext callContext) throws OpenEJBException {
final BeanContext beanContext = callContext.getBeanContext();
final Stack methodReadyPool = poolMap.get(beanContext.getDeploymentID());
if (methodReadyPool == null) {
throw new SystemException("Invalid deployment id " + beanContext.getDeploymentID() + " for this container");
}
EntityBean bean = (EntityBean) methodReadyPool.pop();
if (bean == null) {
try {
bean = (EntityBean) beanContext.getBeanClass().newInstance();
} catch (final Exception e) {
logger.error("Bean instantiation failed for class " + beanContext.getBeanClass(), e);
throw new SystemException(e);
}
final Operation currentOp = callContext.getCurrentOperation();
callContext.setCurrentOperation(Operation.SET_CONTEXT);
try {
/*
* setEntityContext executes in an unspecified transactional context. In this case we choose to
* allow it to have what every transaction context is current. Better then suspending it
* unnecessarily.
*
* We also chose not to invoke EntityContainer.invoke( ) method, which duplicate the exception handling
* logic but also attempt to manage the begining and end of a transaction. It its a container managed transaciton
* we don't want the TransactionScopeHandler commiting the transaction in afterInvoke() which is what it would attempt
* to do.
*/
bean.setEntityContext(createEntityContext());
} catch (final Exception e) {
/*
* The EJB 1.1 specification does not specify how exceptions thrown by setEntityContext impact the
* transaction, if there is one. In this case we choose the least disruptive operation, throwing an
* application exception and NOT automatically marking the transaciton for rollback.
*/
logger.error("Bean callback method failed ", e);
throw new ApplicationException(e);
} finally {
callContext.setCurrentOperation(currentOp);
}
} else {
reusingBean(bean, callContext);
}
if (callContext.getCurrentOperation() == Operation.BUSINESS || callContext.getCurrentOperation() == Operation.REMOVE) {
/*
* When a bean is retrieved from the bean pool to service a client's business method request it must be
* notified that its about to enter service by invoking its ejbActivate( ) method. A bean instance
* does not have its ejbActivate() invoked when:
* 1. Its being retreived to service an ejbCreate()/ejbPostCreate().
* 2. Its being retrieved to service an ejbFind method.
* 3. Its being retrieved to service an ejbRemove() method.
* See section 9.1.4 of the EJB 1.1 specification.
*/
final Operation currentOp = callContext.getCurrentOperation();
callContext.setCurrentOperation(Operation.ACTIVATE);
try {
/*
In the event of an exception, OpenEJB is required to log the exception, evict the instance,
and mark the transaction for rollback. If there is a transaction to rollback, then the a
javax.transaction.TransactionRolledbackException must be throw to the client.
See EJB 1.1 specification, section 12.3.2
*/
bean.ejbActivate();
} catch (final Throwable e) {
logger.error("Encountered exception during call to ejbActivate()", e);
final TransactionPolicy txPolicy = callContext.getTransactionPolicy();
if (txPolicy != null && txPolicy.isTransactionActive()) {
txPolicy.setRollbackOnly(e);
throw new ApplicationException(new TransactionRolledbackException("Reflection exception thrown while attempting to call ejbActivate() on the instance", e));
}
throw new ApplicationException(new RemoteException("Exception thrown while attempting to call ejbActivate() on the instance. Exception message = " + e.getMessage(), e));
} finally {
callContext.setCurrentOperation(currentOp);
}
}
return bean;
}
use of org.apache.openejb.SystemException in project tomee by apache.
the class LocalClientRunner method createDeployment.
private BeanContext createDeployment(final Class<?> testClass) {
try {
final AppContext appContext = new AppContext("", SystemInstance.get(), testClass.getClassLoader(), new IvmContext(), new IvmContext(), false);
final ModuleContext moduleContext = new ModuleContext("", null, "", appContext, new IvmContext(), null);
return new BeanContext(null, new IvmContext(), moduleContext, testClass, null, null, null, null, null, null, null, null, null, BeanType.MANAGED, false, false);
} catch (final SystemException e) {
throw new IllegalStateException(e);
}
}
Aggregations