User: fleury
Date: 00/08/14 08:02:21
Modified: src/main/org/jboss/ejb/plugins TxInterceptor.java
StatefulSessionFilePersistenceManager.java
Log:
indentation
Revision Changes Path
1.11 +341 -341 jboss/src/main/org/jboss/ejb/plugins/TxInterceptor.java
Index: TxInterceptor.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/TxInterceptor.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- TxInterceptor.java 2000/08/12 00:40:47 1.10
+++ TxInterceptor.java 2000/08/14 15:02:20 1.11
@@ -38,351 +38,351 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.10 $
+* @version $Revision: 1.11 $
*/
public class TxInterceptor
extends AbstractInterceptor
{
-
- // Attributes ----------------------------------------------------
- private TxManager tm;
- private HashMap methodTx = new HashMap();
-
- protected Container container;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
- public void setContainer(Container container)
- {
- this.container = container;
- }
-
- public Container getContainer()
- {
- return container;
- }
-
- // Interceptor implementation --------------------------------------
- public void init()
- throws Exception
- {
- // Store TM reference locally
- tm = (TxManager) getContainer().getTransactionManager();
-
- // Find out method->tx-type mappings from meta-info
- // EnterpriseBean eb = getContainer.getMetaData();
- // eb.getBeanContext()
- }
-
- public Object invokeHome(MethodInvocation mi)
- throws Exception
- {
- return runWithTransactions(false, mi);
- }
-
- /**
- * This method does invocation interpositioning of tx management
- *
- * @param id
- * @param m
- * @param args
- * @return
- * @exception Exception
- */
- public Object invoke(MethodInvocation mi) throws Exception {
- return runWithTransactions(true, mi);
- }
-
- private void printMethod(Method m, byte type) {
- String name;
- switch(type) {
- case MetaData.TX_MANDATORY:
- name = "TX_MANDATORY";
- break;
- case MetaData.TX_NEVER:
- name = "TX_NEVER";
- break;
- case MetaData.TX_NOT_SUPPORTED:
- name = "TX_NOT_SUPPORTED";
- break;
- case MetaData.TX_REQUIRED:
- name = "TX_REQUIRED";
- break;
- case MetaData.TX_REQUIRES_NEW:
- name = "TX_REQUIRES_NEW";
- break;
- case MetaData.TX_SUPPORTS:
- name = "TX_SUPPORTS";
- break;
- default:
- name = "TX_UNKNOWN";
- }
- Logger.debug(name+" for "+m.getName());
- }
-
- private Object invokeNext(boolean remoteInvocation, MethodInvocation mi)
throws Exception {
- if (remoteInvocation) {
- return getNext().invoke(mi);
- } else {
- return getNext().invokeHome(mi);
- }
- }
-
-
- private Object runWithTransactions(boolean remoteInvocation, MethodInvocation
mi) throws Exception {
-
- // Old transaction is the transaction that comes with the MI
- Transaction oldTransaction = mi.getTransaction();
- // New transaction is the new transaction this might start
- Transaction newTransaction = null;
-
-//DEBUG System.out.println("Current transaction in MI is
"+mi.getTransaction());
-
- byte transType = getTransactionMethod(mi.getMethod(),
remoteInvocation);
+
+ // Attributes ----------------------------------------------------
+ private TxManager tm;
+ private HashMap methodTx = new HashMap();
+
+ protected Container container;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+ public void setContainer(Container container)
+ {
+ this.container = container;
+ }
+
+ public Container getContainer()
+ {
+ return container;
+ }
+
+ // Interceptor implementation --------------------------------------
+ public void init()
+ throws Exception
+ {
+ // Store TM reference locally
+ tm = (TxManager) getContainer().getTransactionManager();
+
+ // Find out method->tx-type mappings from meta-info
+ // EnterpriseBean eb = getContainer.getMetaData();
+ // eb.getBeanContext()
+ }
+
+ public Object invokeHome(MethodInvocation mi)
+ throws Exception
+ {
+ return runWithTransactions(false, mi);
+ }
+
+ /**
+ * This method does invocation interpositioning of tx management
+ *
+ * @param id
+ * @param m
+ * @param args
+ * @return
+ * @exception Exception
+ */
+ public Object invoke(MethodInvocation mi) throws Exception {
+ return runWithTransactions(true, mi);
+ }
+
+ private void printMethod(Method m, byte type) {
+ String name;
+ switch(type) {
+ case MetaData.TX_MANDATORY:
+ name = "TX_MANDATORY";
+ break;
+ case MetaData.TX_NEVER:
+ name = "TX_NEVER";
+ break;
+ case MetaData.TX_NOT_SUPPORTED:
+ name = "TX_NOT_SUPPORTED";
+ break;
+ case MetaData.TX_REQUIRED:
+ name = "TX_REQUIRED";
+ break;
+ case MetaData.TX_REQUIRES_NEW:
+ name = "TX_REQUIRES_NEW";
+ break;
+ case MetaData.TX_SUPPORTS:
+ name = "TX_SUPPORTS";
+ break;
+ default:
+ name = "TX_UNKNOWN";
+ }
+ Logger.debug(name+" for "+m.getName());
+ }
+
+ private Object invokeNext(boolean remoteInvocation, MethodInvocation mi) throws
Exception {
+ if (remoteInvocation) {
+ return getNext().invoke(mi);
+ } else {
+ return getNext().invokeHome(mi);
+ }
+ }
+
+
+ private Object runWithTransactions(boolean remoteInvocation, MethodInvocation
mi) throws Exception {
+
+ // Old transaction is the transaction that comes with the MI
+ Transaction oldTransaction = mi.getTransaction();
+ // New transaction is the new transaction this might start
+ Transaction newTransaction = null;
+
+ System.out.println("Current transaction in MI is "+mi.getTransaction());
+ System.out.println("Current method "+mi.getMethod());
+ byte transType = getTransactionMethod(mi.getMethod(), remoteInvocation);
// DEBUG printMethod(mi.getMethod(), transType);
-
- switch (transType) {
-
- case MetaData.TX_NOT_SUPPORTED: {
-
-
- // Thread arriving must be clean (jboss doesn't set
the thread previously)
- // But for robustness purposes we disassociate the
thread
- tm.disassociateThread();
-
- // Do not set a transaction on the thread even if in
MI, just run
- return invokeNext(remoteInvocation,mi );
-
- // We don't have to do anything since we don't deal
with transactions
- }
-
-
- case MetaData.TX_REQUIRED: {
-
- if (oldTransaction == null) { // No tx running
-
- //DEBUG Logger.debug("Begin tx");
-
- // Create tx
- tm.begin();
-
- // get the tx
- newTransaction = tm.getTransaction();
-
- // Let the method invocation know
- mi.setTransaction(newTransaction);
- }
-
- else { // We have a tx propagated
-
- // Associate it with the thread
- tm.associateThread(oldTransaction);
- }
-
- // Continue invocation
- try {
-
- return invokeNext(remoteInvocation,mi );
- }
- catch (RemoteException e) {
-
- if (newTransaction != null) {
-
- //We started it,
- newTransaction.rollback();
- }
-
- throw e;
- }
- catch (RuntimeException e) {
-
- if (newTransaction != null) {
-
- // We started it
- newTransaction.rollback();
- }
-
- throw new ServerException("Exception
occurred", e);
- }
- catch (Error e) {
-
- if (newTransaction != null) {
-
- // we started it
- newTransaction.rollback();
- }
- throw new ServerException("Exception
occurred:"+e.getMessage());
- }
-
- finally {
-
- // Only do something if we started the
transaction
- if (newTransaction != null) {
-
- // Marked rollback
- if (newTransaction.getStatus() ==
Status.STATUS_MARKED_ROLLBACK) {
-
- // actually roll it back
- newTransaction.rollback();
- }
-
- //Still running
- else if(newTransaction.getStatus() ==
Status.STATUS_ACTIVE) {
-
- // Commit tx
- // This will happen if
- // a) everything goes well
- // b) app. exception was thrown
- newTransaction.commit();
- }
-
- // reassociate the oldTransaction with
the methodInvocation (even null)
- mi.setTransaction(oldTransaction);
- }
- }
- }
-
- case MetaData.TX_SUPPORTS: {
-
- if (oldTransaction != null) { // We have a tx
propagated
-
- // Associate it with the thread
- tm.associateThread(oldTransaction);
- }
-
- // If we don't have a tx propagated we don't do
anything
-
- // Continue invocation
- try {
-
- return invokeNext(remoteInvocation,mi );
- }
- catch (RuntimeException e) {
-
- throw new ServerException("Exception
occurred", e);
- }
- catch (Error e) {
-
- throw new ServerException("Exception
occurred:"+e.getMessage());
- }
-
- // Even on error we don't do anything with the tx, we
didn't start it
-
- }
-
- case MetaData.TX_REQUIRES_NEW: {
-
- // Always begin a transaction
- tm.begin();
-
- // get it
- newTransaction = tm.getTransaction();
-
- // Set it on the method invocation
- mi.setTransaction(newTransaction);
-
- // Continue invocation
- try {
-
- return invokeNext(remoteInvocation,mi );
- }
- catch (RemoteException e) {
-
- // We started it for sure
- newTransaction.rollback();
-
- throw e;
- }
- catch (RuntimeException e) {
-
- // We started it for sure
- newTransaction.rollback();
-
- throw new ServerException("Exception
occurred", e);
- }
- catch (Error e) {
-
- // We started it for sure
- newTransaction.rollback();
-
- throw new ServerException("Exception
occurred:"+e.getMessage());
- }
- finally {
-
- // We started the transaction for sure so we
commit or roll back
-
- if (newTransaction.getStatus() ==
Status.STATUS_MARKED_ROLLBACK) {
-
- newTransaction.rollback();
- }
- else {
-
- // Commit tx
- // This will happen if
- // a) everything goes well
- // b) app. exception was thrown
- newTransaction.commit();
- }
-
- // set the old transaction back on the method
invocation
- mi.setTransaction(oldTransaction);
- }
- }
-
- case MetaData.TX_MANDATORY: {
-
- if (oldTransaction == null) { // no transaction = bad!
-
- throw new TransactionRequiredException("read
the spec!");
- }
- else {
-
- // Associate it with the thread
- tm.associateThread(oldTransaction);
-
- // That's it
- return invokeNext(remoteInvocation,mi );
- }
- }
-
- case MetaData.TX_NEVER: {
-
- if (oldTransaction != null) { // Transaction = bad!
-
- throw new RemoteException("Transaction not
allowed");
- }
- else {
-
- return invokeNext(remoteInvocation,mi );
- }
- }
- }
-
- return null;
- }
-
- // Protected ----------------------------------------------------
-
- // This should be cached, since this method is called very often
- protected byte getTransactionMethod(Method m, boolean remoteInvocation) {
- Byte b = (Byte)methodTx.get(m);
- if(b != null) return b.byteValue();
-
- BeanMetaData bmd = container.getBeanMetaData();
- System.out.println("Found metadata for bean '"+bmd.getEjbName()+"'"+"
method is "+m);
- byte result = bmd.getMethodTransactionType(m.getName(),
m.getParameterTypes(), remoteInvocation);
-
- // provide default if method is not found in descriptor
- if (result == MetaData.TX_UNKNOWN) result = MetaData.TX_SUPPORTS;
-
- methodTx.put(m, new Byte(result));
- return result;
- }
-
- // Inner classes -------------------------------------------------
-
+
+ switch (transType) {
+
+ case MetaData.TX_NOT_SUPPORTED: {
+
+
+ // Thread arriving must be clean (jboss doesn't set the thread previously)
+ // But for robustness purposes we disassociate the thread
+ tm.disassociateThread();
+
+ // Do not set a transaction on the thread even if in MI, just run
+ return invokeNext(remoteInvocation,mi );
+
+ // We don't have to do anything since we don't deal with transactions
+ }
+
+
+ case MetaData.TX_REQUIRED: {
+
+ if (oldTransaction == null) { // No tx running
+
+ //DEBUG Logger.debug("Begin tx");
+
+ // Create tx
+ tm.begin();
+
+ // get the tx
+ newTransaction = tm.getTransaction();
+
+ // Let the method invocation know
+ mi.setTransaction(newTransaction);
+ }
+
+ else { // We have a tx propagated
+
+ // Associate it with the thread
+ tm.associateThread(oldTransaction);
+ }
+
+ // Continue invocation
+ try {
+
+ return invokeNext(remoteInvocation,mi );
+ }
+ catch (RemoteException e) {
+
+ if (newTransaction != null) {
+
+ //We started it,
+ newTransaction.rollback();
+ }
+
+ throw e;
+ }
+ catch (RuntimeException e) {
+
+ if (newTransaction != null) {
+
+ // We started it
+ newTransaction.rollback();
+ }
+
+ throw new ServerException("Exception occurred", e);
+ }
+ catch (Error e) {
+
+ if (newTransaction != null) {
+
+ // we started it
+ newTransaction.rollback();
+ }
+ throw new ServerException("Exception occurred:"+e.getMessage());
+ }
+
+ finally {
+
+ // Only do something if we started the transaction
+ if (newTransaction != null) {
+
+ // Marked rollback
+ if (newTransaction.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
+
+ // actually roll it back
+ newTransaction.rollback();
+ }
+
+ //Still running
+ else if(newTransaction.getStatus() == Status.STATUS_ACTIVE) {
+
+ // Commit tx
+ // This will happen if
+ // a) everything goes well
+ // b) app. exception was thrown
+ newTransaction.commit();
+ }
+
+ // reassociate the oldTransaction with the methodInvocation (even
null)
+ mi.setTransaction(oldTransaction);
+ }
+ }
+ }
+
+ case MetaData.TX_SUPPORTS: {
+
+ if (oldTransaction != null) { // We have a tx propagated
+
+ // Associate it with the thread
+ tm.associateThread(oldTransaction);
+ }
+
+ // If we don't have a tx propagated we don't do anything
+
+ // Continue invocation
+ try {
+
+ return invokeNext(remoteInvocation,mi );
+ }
+ catch (RuntimeException e) {
+
+ throw new ServerException("Exception occurred", e);
+ }
+ catch (Error e) {
+
+ throw new ServerException("Exception occurred:"+e.getMessage());
+ }
+
+ // Even on error we don't do anything with the tx, we didn't start it
+
+ }
+
+ case MetaData.TX_REQUIRES_NEW: {
+
+ // Always begin a transaction
+ tm.begin();
+
+ // get it
+ newTransaction = tm.getTransaction();
+
+ // Set it on the method invocation
+ mi.setTransaction(newTransaction);
+
+ // Continue invocation
+ try {
+
+ return invokeNext(remoteInvocation,mi );
+ }
+ catch (RemoteException e) {
+
+ // We started it for sure
+ newTransaction.rollback();
+
+ throw e;
+ }
+ catch (RuntimeException e) {
+
+ // We started it for sure
+ newTransaction.rollback();
+
+ throw new ServerException("Exception occurred", e);
+ }
+ catch (Error e) {
+
+ // We started it for sure
+ newTransaction.rollback();
+
+ throw new ServerException("Exception occurred:"+e.getMessage());
+ }
+ finally {
+
+ // We started the transaction for sure so we commit or roll back
+
+ if (newTransaction.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
+
+ newTransaction.rollback();
+ }
+ else {
+
+ // Commit tx
+ // This will happen if
+ // a) everything goes well
+ // b) app. exception was thrown
+ newTransaction.commit();
+ }
+
+ // set the old transaction back on the method invocation
+ mi.setTransaction(oldTransaction);
+ }
+ }
+
+ case MetaData.TX_MANDATORY: {
+
+ if (oldTransaction == null) { // no transaction = bad!
+
+ throw new TransactionRequiredException("read the spec!");
+ }
+ else {
+
+ // Associate it with the thread
+ tm.associateThread(oldTransaction);
+
+ // That's it
+ return invokeNext(remoteInvocation,mi );
+ }
+ }
+
+ case MetaData.TX_NEVER: {
+
+ if (oldTransaction != null) { // Transaction = bad!
+
+ throw new RemoteException("Transaction not allowed");
+ }
+ else {
+
+ return invokeNext(remoteInvocation,mi );
+ }
+ }
+ }
+
+ return null;
+ }
+
+ // Protected ----------------------------------------------------
+
+ // This should be cached, since this method is called very often
+ protected byte getTransactionMethod(Method m, boolean remoteInvocation) {
+ Byte b = (Byte)methodTx.get(m);
+ if(b != null) return b.byteValue();
+
+ BeanMetaData bmd = container.getBeanMetaData();
+ System.out.println("Found metadata for bean '"+bmd.getEjbName()+"'"+" method
is "+m.getName());
+ byte result = bmd.getMethodTransactionType(m.getName(),
m.getParameterTypes(), remoteInvocation);
+
+ // provide default if method is not found in descriptor
+ if (result == MetaData.TX_UNKNOWN) result = MetaData.TX_SUPPORTS;
+
+ methodTx.put(m, new Byte(result));
+ return result;
+ }
+
+ // Inner classes -------------------------------------------------
+
}
1.5 +57 -54
jboss/src/main/org/jboss/ejb/plugins/StatefulSessionFilePersistenceManager.java
Index: StatefulSessionFilePersistenceManager.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/StatefulSessionFilePersistenceManager.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- StatefulSessionFilePersistenceManager.java 2000/08/12 00:40:46 1.4
+++ StatefulSessionFilePersistenceManager.java 2000/08/14 15:02:20 1.5
@@ -58,7 +58,7 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public class StatefulSessionFilePersistenceManager
implements StatefulSessionPersistenceManager
@@ -85,34 +85,34 @@
con = (StatefulSessionContainer)c;
}
- public void init()
- throws Exception {
-
- // Find methods
- ejbActivate = SessionBean.class.getMethod("ejbActivate", new Class[0]);
-
- ejbPassivate = SessionBean.class.getMethod("ejbPassivate", new
Class[0]);
-
- ejbRemove = SessionBean.class.getMethod("ejbRemove", new Class[0]);
+ public void init()
+ throws Exception {
+
+ // Find methods
+ ejbActivate = SessionBean.class.getMethod("ejbActivate", new Class[0]);
+
+ ejbPassivate = SessionBean.class.getMethod("ejbPassivate", new Class[0]);
+
+ ejbRemove = SessionBean.class.getMethod("ejbRemove", new Class[0]);
// Initialize the dataStore
- String ejbName = con.getBeanMetaData().getEjbName();
-
- File database = new File("database");
-
- dir = new File(database, ejbName);
-
- dir.mkdirs();
-
- System.out.println("Storing sessions for "+ejbName+" in:"+dir);
+ String ejbName = con.getBeanMetaData().getEjbName();
+
+ File database = new File("database");
- // Clear dir of old files
- File[] sessions = dir.listFiles();
- for (int i = 0; i < sessions.length; i++)
- {
- sessions[i].delete();
- }
- System.out.println(sessions.length + " old sessions removed");
+ dir = new File(database, ejbName);
+
+ dir.mkdirs();
+
+ System.out.println("Storing sessions for "+ejbName+" in:"+dir);
+
+ // Clear dir of old files
+ File[] sessions = dir.listFiles();
+ for (int i = 0; i < sessions.length; i++)
+ {
+ sessions[i].delete();
+ }
+ System.out.println(sessions.length + " old sessions removed");
}
public void start()
@@ -163,18 +163,21 @@
public void activateSession(StatefulSessionEnterpriseContext ctx)
throws RemoteException
{
- try
- {
- // Load state
- ObjectInputStream in = new SessionObjectInputStream(ctx, new
FileInputStream(new File(dir, ctx.getId()+".ser")));
-
- Field[] fields = ctx.getInstance().getClass().getFields();
-
- for (int i = 0; i < fields.length; i++)
- if (!Modifier.isTransient(fields[i].getModifiers()))
- fields[i].set(ctx.getInstance(),
in.readObject());
-
- // Call bean
+ try
+ {
+
+ ObjectInputStream in;
+
+
+ // Load state
+ in = new SessionObjectInputStream(ctx, new FileInputStream(new
File(dir, ctx.getId()+".ser")));
+ Field[] fields = ctx.getInstance().getClass().getFields();
+
+ for (int i = 0; i < fields.length; i++)
+ if (!Modifier.isTransient(fields[i].getModifiers()))
+ fields[i].set(ctx.getInstance(), in.readObject());
+
+ // Call bean
ejbActivate.invoke(ctx.getInstance(), new Object[0]);
} catch (Exception e)
{
@@ -187,23 +190,23 @@
{
try
{
- // Call bean
+ // Call bean
ejbPassivate.invoke(ctx.getInstance(), new Object[0]);
-
- // Store state
- ObjectOutputStream out = new SessionObjectOutputStream(new
FileOutputStream(new File(dir, ctx.getId()+".ser")));
-
- Field[] fields = ctx.getInstance().getClass().getFields();
-
- for (int i = 0; i < fields.length; i++)
- if (!Modifier.isTransient(fields[i].getModifiers()))
-
out.writeObject(fields[i].get(ctx.getInstance()));
-
- out.close();
- } catch (Exception e)
- {
- throw new ServerException("Passivation failed", e);
- }
+
+ // Store state
+ ObjectOutputStream out = new SessionObjectOutputStream(new
FileOutputStream(new File(dir, ctx.getId()+".ser")));
+
+ Field[] fields = ctx.getInstance().getClass().getFields();
+
+ for (int i = 0; i < fields.length; i++)
+ if (!Modifier.isTransient(fields[i].getModifiers()))
+ out.writeObject(fields[i].get(ctx.getInstance()));
+
+ out.close();
+ } catch (Exception e)
+ {
+ throw new ServerException("Passivation failed", e);
+ }
}
public void removeSession(StatefulSessionEnterpriseContext ctx)