use of org.apache.openejb.SystemException in project tomee by apache.
the class ManagedContainer method afterInvoke.
private void afterInvoke(final ThreadContext callContext, final TransactionPolicy txPolicy, final Instance instance) throws OpenEJBException {
try {
unregisterEntityManagers(instance, callContext);
if (instance != null && txPolicy instanceof BeanTransactionPolicy) {
// suspend the currently running transaction if any
SuspendedTransaction suspendedTransaction = null;
try {
final BeanTransactionPolicy beanTxEnv = (BeanTransactionPolicy) txPolicy;
suspendedTransaction = beanTxEnv.suspendUserTransaction();
} catch (final SystemException e) {
EjbTransactionUtil.handleSystemException(txPolicy, e, callContext);
} finally {
instance.setBeanTransaction(suspendedTransaction);
}
}
} finally {
if (instance != null) {
instance.setInUse(false);
}
EjbTransactionUtil.afterInvoke(txPolicy, callContext);
}
}
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 RAFPassivater method activate.
public synchronized Object activate(final Object primaryKey) throws SystemException {
final Pointer pointer = (Pointer) masterTable.get(primaryKey);
if (pointer == null) {
return null;
}
try (final RandomAccessFile ras = new RandomAccessFile(JavaSecurityManagers.getSystemProperty("java.io.tmpdir", File.separator + "tmp") + File.separator + "passivation" + pointer.fileid + ".ser", "r")) {
final byte[] bytes = new byte[pointer.bytesize];
ras.seek(pointer.filepointer);
ras.readFully(bytes);
ras.close();
return Serializer.deserialize(bytes);
} catch (final Exception e) {
throw new SystemException(e);
}
}
use of org.apache.openejb.SystemException in project tomee by apache.
the class SimplePassivater method passivate.
public void passivate(final Object primaryKey, final Object state) throws SystemException {
try {
final String filename = primaryKey.toString().replace(':', '=');
final File sessionFile = new File(sessionDirectory, filename);
if (!sessionFile.exists() && !sessionFile.createNewFile()) {
throw new Exception("Failed to create passivation file: " + sessionFile.getAbsolutePath());
}
logger.info("Passivating to file " + sessionFile);
try (final OutputStream os = IO.write(sessionFile);
final ObjectOutputStream oos = new ObjectOutputStream(os)) {
// passivate just the bean instance
oos.writeObject(state);
} finally {
sessionFile.deleteOnExit();
}
} catch (final NotSerializableException nse) {
logger.error("Passivation failed ", nse);
throw (SystemException) new SystemException("The type " + nse.getMessage() + " is not serializable as mandated by the EJB specification.").initCause(nse);
} catch (final Exception t) {
logger.error("Passivation failed ", t);
throw new SystemException(t);
}
}
use of org.apache.openejb.SystemException in project tomee by apache.
the class AbstractEndpointHandler 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) {
if (isValidException(method, throwable)) {
throw throwable;
} else {
throw new EJBException().initCause(throwable);
}
}
return value;
}
Aggregations