User: oberg
Date: 00/06/16 06:10:25
Modified: src/main/org/jboss/ejb/plugins AbstractInterceptor.java
EntityInstanceInterceptor.java
EntitySynchronizationInterceptor.java
LogInterceptor.java
NoPassivationEntityInstanceCache.java
NoPassivationStatefulSessionInstanceCache.java
RandomEntityInstanceCache.java
SecurityInterceptor.java
StatefulSessionInstanceInterceptor.java
StatelessSessionInstanceInterceptor.java
TxInterceptor.java
Log:
Added configuration service
Changed interceptors to be messagebased
Added mini webserver
Changed server bootstrap process
Revision Changes Path
1.2 +8 -8 jboss/src/main/org/jboss/ejb/plugins/AbstractInterceptor.java
Index: AbstractInterceptor.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/AbstractInterceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractInterceptor.java 2000/04/23 14:29:28 1.1
+++ AbstractInterceptor.java 2000/06/16 13:10:23 1.2
@@ -22,13 +22,14 @@
import org.jboss.ejb.Container;
import org.jboss.ejb.Interceptor;
import org.jboss.ejb.EnterpriseContext;
+import org.jboss.ejb.MethodInvocation;
/**
* <description>
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public abstract class AbstractInterceptor
implements Interceptor
@@ -36,7 +37,6 @@
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
- private Container container;
protected Interceptor nextInterceptor;
// Static --------------------------------------------------------
@@ -46,8 +46,8 @@
// Public --------------------------------------------------------
// Interceptor implementation ------------------------------------
- public void setContainer(Container container) { this.container = container; }
- public Container getContainer() { return container; }
+ public abstract void setContainer(Container container);
+ public abstract Container getContainer();
public void setNext(Interceptor interceptor) { nextInterceptor = interceptor; }
public Interceptor getNext() { return nextInterceptor; }
@@ -69,16 +69,16 @@
{
}
- public Object invokeHome(Method method, Object[] args, EnterpriseContext ctx)
+ public Object invokeHome(MethodInvocation mi)
throws Exception
{
- return getNext().invokeHome(method, args, ctx);
+ return getNext().invokeHome(mi);
}
- public Object invoke(Object id, Method method, Object[] args, EnterpriseContext
ctx)
+ public Object invoke(MethodInvocation mi)
throws Exception
{
- return getNext().invoke(id, method, args, ctx);
+ return getNext().invoke(mi);
}
// Protected -----------------------------------------------------
}
1.3 +28 -18
jboss/src/main/org/jboss/ejb/plugins/EntityInstanceInterceptor.java
Index: EntityInstanceInterceptor.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/EntityInstanceInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- EntityInstanceInterceptor.java 2000/05/12 10:17:18 1.2
+++ EntityInstanceInterceptor.java 2000/06/16 13:10:23 1.3
@@ -25,19 +25,21 @@
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
+import org.jboss.ejb.Container;
import org.jboss.ejb.EntityContainer;
import org.jboss.ejb.EntityPersistenceManager;
import org.jboss.ejb.EntityEnterpriseContext;
import org.jboss.ejb.EnterpriseContext;
import org.jboss.ejb.InstanceCache;
import org.jboss.ejb.InstancePool;
+import org.jboss.ejb.MethodInvocation;
/**
* This container acquires the given instance.
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class EntityInstanceInterceptor
extends AbstractInterceptor
@@ -45,83 +47,91 @@
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
+ protected EntityContainer container;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
+ public void setContainer(Container container)
+ {
+ this.container = (EntityContainer)container;
+ }
+
+ public Container getContainer()
+ {
+ return container;
+ }
// Interceptor implementation --------------------------------------
- public Object invokeHome(Method method, Object[] args, EnterpriseContext ctx)
+ public Object invokeHome(MethodInvocation mi)
throws Exception
{
// Get context
- ctx = ((EntityContainer)getContainer()).getInstancePool().get();
+
mi.setEnterpriseContext(((EntityContainer)getContainer()).getInstancePool().get());
try
{
// Invoke through interceptors
- return getNext().invokeHome(method, args, ctx);
+ return getNext().invokeHome(mi);
} finally
{
// Still free? Not free if create() was called successfully
- if (ctx.getId() == null)
+ if (mi.getEnterpriseContext().getId() == null)
{
- getContainer().getInstancePool().free(ctx);
+ container.getInstancePool().free(mi.getEnterpriseContext());
} else
{
// System.out.println("Entity was created; not returned to pool");
- ((EntityContainer)getContainer()).getInstanceCache().release(ctx);
+
((EntityContainer)getContainer()).getInstanceCache().release(mi.getEnterpriseContext());
}
}
}
- public Object invoke(Object id, Method method, Object[] args, EnterpriseContext
ctx)
+ public Object invoke(MethodInvocation mi)
throws Exception
{
// Get context
- ctx = ((EntityContainer)getContainer()).getInstanceCache().get(id);
+
mi.setEnterpriseContext(((EntityContainer)getContainer()).getInstanceCache().get(mi.getId()));
try
{
// Invoke through interceptors
- return getNext().invoke(id, method, args, ctx);
+ return getNext().invoke(mi);
} catch (RemoteException e)
{
// Discard instance
// EJB 1.1 spec 12.3.1
-
((EntityContainer)getContainer()).getInstanceCache().remove(id);
- ctx = null;
+
((EntityContainer)getContainer()).getInstanceCache().remove(mi.getId());
throw e;
} catch (RuntimeException e)
{
// Discard instance
// EJB 1.1 spec 12.3.1
-
((EntityContainer)getContainer()).getInstanceCache().remove(id);
- ctx = null;
+
((EntityContainer)getContainer()).getInstanceCache().remove(mi.getId());
throw e;
} catch (Error e)
{
// Discard instance
// EJB 1.1 spec 12.3.1
-
((EntityContainer)getContainer()).getInstanceCache().remove(id);
- ctx = null;
+
((EntityContainer)getContainer()).getInstanceCache().remove(mi.getId());
throw e;
} finally
{
// System.out.println("Release instance for "+id);
+ EnterpriseContext ctx = mi.getEnterpriseContext();
if (ctx != null)
{
if (ctx.getId() == null)
{
// Remove from cache
-
((EntityContainer)getContainer()).getInstanceCache().remove(id);
+
((EntityContainer)getContainer()).getInstanceCache().remove(mi.getId());
// It has been removed -> send to free pool
- getContainer().getInstancePool().free(ctx);
+ container.getInstancePool().free(ctx);
}
{
// Return context
1.5 +47 -73
jboss/src/main/org/jboss/ejb/plugins/EntitySynchronizationInterceptor.java
Index: EntitySynchronizationInterceptor.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/EntitySynchronizationInterceptor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- EntitySynchronizationInterceptor.java 2000/05/30 18:32:22 1.4
+++ EntitySynchronizationInterceptor.java 2000/06/16 13:10:23 1.5
@@ -26,12 +26,14 @@
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
+import org.jboss.ejb.Container;
import org.jboss.ejb.EntityContainer;
import org.jboss.ejb.EntityPersistenceManager;
import org.jboss.ejb.EntityEnterpriseContext;
import org.jboss.ejb.EnterpriseContext;
import org.jboss.ejb.InstanceCache;
import org.jboss.ejb.InstancePool;
+import org.jboss.ejb.MethodInvocation;
import org.jboss.logging.Logger;
@@ -45,7 +47,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public class EntitySynchronizationInterceptor
extends AbstractInterceptor
@@ -62,12 +64,24 @@
HashMap synchs = new HashMap(); // tx -> synch
int commitOption = A;
+
+ protected EntityContainer container;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
+ public void setContainer(Container container)
+ {
+ this.container = (EntityContainer)container;
+ }
+
+ public Container getContainer()
+ {
+ return container;
+ }
+
public void setCommitOption(int commitOption)
{
this.commitOption = commitOption;
@@ -125,19 +139,20 @@
// Interceptor implementation --------------------------------------
- public Object invokeHome(Method method, Object[] args, EnterpriseContext ctx)
+ public Object invokeHome(MethodInvocation mi)
throws Exception
{
try
{
- return getNext().invokeHome(method, args, ctx);
+ return getNext().invokeHome(mi);
} finally
{
// Anonymous was sent in, so if it has an id it was created
- if (ctx.getId() != null &&
getContainer().getTransactionManager().getTransaction().getStatus() ==
Status.STATUS_ACTIVE)
+ EnterpriseContext ctx = mi.getEnterpriseContext();
+ if (ctx.getId() != null && mi.getTransaction().getStatus() ==
Status.STATUS_ACTIVE)
{
// Set tx
- register(ctx, getContainer().getTransactionManager().getTransaction());
+ register(ctx, mi.getTransaction());
// Currently synched with underlying storage
((EntityEnterpriseContext)ctx).setSynchronized(true);
@@ -145,70 +160,30 @@
}
}
- public Object invoke(Object id, Method method, Object[] args, EnterpriseContext
ctx)
+ public Object invoke(MethodInvocation mi)
throws Exception
{
- EntityEnterpriseContext entityCtx = (EntityEnterpriseContext)ctx;
+ EntityEnterpriseContext ctx =
(EntityEnterpriseContext)mi.getEnterpriseContext();
- Transaction tx = entityCtx.getTransaction();
- Transaction current = getContainer().getTransactionManager().getTransaction();
+ Transaction tx = ctx.getTransaction();
+ Transaction current = mi.getTransaction();
//DEBUG Logger.debug("TX:"+(current.getStatus() == Status.STATUS_ACTIVE));
if (current.getStatus() == Status.STATUS_ACTIVE)
{
- // Registered with other tx?
- if (tx != null && !tx.equals(current))
- {
- // Wait for other tx associated with ctx to finish
- while ((tx = entityCtx.getTransaction()) != null)
- {
- // Release context temporarily
-
((EntityContainer)getContainer()).getInstanceCache().release(entityCtx);
-
- // Wait for tx to end
-//DEBUG Logger.debug("Wait for "+ctx.getId()+":Current="+current+",
Tx="+tx);
- Synchronization synch = new Synchronization()
- {
- public void beforeCompletion() {}
- public synchronized void afterCompletion(int status)
- {
- this.notifyAll();
- }
- };
- tx.registerSynchronization(synch);
- synchronized(synch)
- {
- try
- {
- synch.wait(TIMEOUT); // This should be changed to a s
- } catch (InterruptedException e)
- {
- throw new ServerException("Time out", e);
- }
- }
-
- // Get context again -- it may be gone by now though if other tx
removed it
- ctx =
((EntityContainer)getContainer()).getInstanceCache().get(ctx.getId());
- }
-
- }
-
- // At this point the ctx is either not associated with a tx,
- // or it has been previously associated with the current tx
-
// Synchronize with DB
//DEBUG Logger.debug("SYNCH");
- if (!entityCtx.isSynchronized())
+ if (!ctx.isSynchronized())
{
-
((EntityContainer)getContainer()).getPersistenceManager().loadEntity(entityCtx);
- entityCtx.setSynchronized(true);
+
((EntityContainer)getContainer()).getPersistenceManager().loadEntity(ctx);
+ ctx.setSynchronized(true);
}
try
{
- return getNext().invoke(id, method, args, ctx);
+ return getNext().invoke(mi);
} finally
{
if (ctx.getId() != null)
@@ -216,16 +191,16 @@
// Associate ctx with tx
if (tx == null)
{
- entityCtx.setInvoked(true); // This causes ejbStore to be invoked
on tx commit
+ ctx.setInvoked(true); // This causes ejbStore to be invoked on tx
commit
register(ctx, current);
}
} else
{
// Entity was removed
- if (entityCtx.getTransaction() != null)
+ if (ctx.getTransaction() != null)
{
// Disassociate ctx with tx
- deregister(entityCtx, current);
+ deregister(ctx, current);
}
}
}
@@ -235,25 +210,26 @@
// Synchronize with DB
//DEBUG Logger.debug("SYNCH");
- if (!entityCtx.isSynchronized())
+ if (!ctx.isSynchronized())
{
-
((EntityContainer)getContainer()).getPersistenceManager().loadEntity(entityCtx);
- entityCtx.setSynchronized(true);
+
((EntityContainer)getContainer()).getPersistenceManager().loadEntity(ctx);
+ ctx.setSynchronized(true);
}
try
{
- Object result = getNext().invoke(id, method, args, ctx);
+ Object result = getNext().invoke(mi);
- // Store after each invocation -- not on exception though, or removal
- if (ctx.getId() != null && !method.getName().startsWith("get"))
-
((EntityContainer)getContainer()).getPersistenceManager().storeEntity((EntityEnterpriseContext)ctx);
+ // Store after each invocation -- not on exception though, or removal
+ // And skip reads too ("get" methods)
+ if (ctx.getId() != null && !mi.getMethod().getName().startsWith("get"))
+
((EntityContainer)getContainer()).getPersistenceManager().storeEntity(ctx);
return result;
} catch (Exception e)
{
// Exception - force reload on next call
- entityCtx.setSynchronized(false);
+ ctx.setSynchronized(false);
throw e;
}
}
@@ -323,9 +299,6 @@
public void afterCompletion(int status)
{
- InstanceCache cache = ((EntityContainer)getContainer()).getInstanceCache();
- InstancePool pool = getContainer().getInstancePool();
-
// If rolled back -> invalidate instance
if (status == Status.STATUS_ROLLEDBACK)
{
@@ -338,8 +311,8 @@
ctx.setId(null);
ctx.setTransaction(null);
- cache.remove(ctx);
- pool.free(ctx); // TODO: should this be done? still valid
instance?
+ container.getInstanceCache().remove(ctx);
+ container.getInstancePool().free(ctx); // TODO: should this be
done? still valid instance?
} catch (Exception e)
{
// Ignore
@@ -358,7 +331,7 @@
EntityEnterpriseContext ctx
= (EntityEnterpriseContext)ctxList.get(i);
ctx.setTransaction(null);
ctx.setInvoked(false);
- cache.release(ctx);
+
container.getInstanceCache().release(ctx);
} catch (Exception e)
{
Logger.debug(e);
@@ -374,7 +347,7 @@
ctx.setInvoked(false);
ctx.setSynchronized(false); // Invalidate state
- cache.release(ctx);
+
container.getInstanceCache().release(ctx);
} catch (Exception e)
{
Logger.debug(e);
@@ -389,10 +362,11 @@
ctx.setTransaction(null);
ctx.setInvoked(false);
+
container.getInstanceCache().get(ctx.getId()); // Lock in cache
((EntityContainer)getContainer()).getPersistenceManager().passivateEntity(ctx); //
Passivate instance
- cache.remove(ctx.getId()); //
Remove from cache
+
container.getInstanceCache().remove(ctx.getId()); // Remove from cache
- pool.free(ctx); // Add to
instance pool
+
container.getInstancePool().free(ctx); // Add to instance pool
} catch (Exception e)
{
1.5 +24 -10 jboss/src/main/org/jboss/ejb/plugins/LogInterceptor.java
Index: LogInterceptor.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/LogInterceptor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LogInterceptor.java 2000/05/31 09:42:09 1.4
+++ LogInterceptor.java 2000/06/16 13:10:23 1.5
@@ -22,6 +22,7 @@
import org.jboss.ejb.Container;
import org.jboss.ejb.EnterpriseContext;
+import org.jboss.ejb.MethodInvocation;
import org.jboss.logging.Log;
@@ -30,7 +31,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public class LogInterceptor
extends AbstractInterceptor
@@ -38,15 +39,26 @@
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
- Log log;
+ protected Log log;
- boolean callLogging;
+ protected boolean callLogging;
+ protected Container container;
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
+ public void setContainer(Container container)
+ {
+ this.container = container;
+ }
+
+ public Container getContainer()
+ {
+ return container;
+ }
// Container implementation --------------------------------------
public void init()
@@ -62,7 +74,7 @@
log = new Log(name);
}
- public Object invokeHome(Method method, Object[] args, EnterpriseContext ctx)
+ public Object invokeHome(MethodInvocation mi)
throws Exception
{
Log.setLog(log);
@@ -71,8 +83,9 @@
if (callLogging)
{
StringBuffer str = new StringBuffer();
- str.append(method.getName());
+ str.append(mi.getMethod().getName());
str.append("(");
+ Object[] args = mi.getArguments();
if (args != null)
for (int i = 0; i < args.length; i++)
{
@@ -85,7 +98,7 @@
try
{
- return getNext().invokeHome(method, args, ctx);
+ return getNext().invokeHome(mi);
} catch (Exception e)
{
// Log system exceptions
@@ -113,7 +126,7 @@
* @return
* @exception Exception
*/
- public Object invoke(Object id, Method method, Object[] args, EnterpriseContext
ctx)
+ public Object invoke(MethodInvocation mi)
throws Exception
{
Log.setLog(log);
@@ -122,9 +135,10 @@
if (callLogging)
{
StringBuffer str = new StringBuffer();
- str.append(id == null ? "" : "["+id.toString()+"] ");
- str.append(method.getName());
+ str.append(mi.getId() == null ? "" : "["+mi.getId().toString()+"] ");
+ str.append(mi.getMethod().getName());
str.append("(");
+ Object[] args = mi.getArguments();
if (args != null)
for (int i = 0; i < args.length; i++)
{
@@ -137,7 +151,7 @@
try
{
- return getNext().invoke(id, method, args, ctx);
+ return getNext().invoke(mi);
} catch (Exception e)
{
log.exception(e);
1.4 +4 -3
jboss/src/main/org/jboss/ejb/plugins/NoPassivationEntityInstanceCache.java
Index: NoPassivationEntityInstanceCache.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/NoPassivationEntityInstanceCache.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- NoPassivationEntityInstanceCache.java 2000/05/19 07:34:33 1.3
+++ NoPassivationEntityInstanceCache.java 2000/06/16 13:10:23 1.4
@@ -19,6 +19,7 @@
import org.jboss.ejb.EntityContainer;
import org.jboss.ejb.InstanceCache;
import org.jboss.ejb.InstancePool;
+import org.jboss.ejb.InstancePoolContainer;
import org.jboss.ejb.EntityPersistenceManager;
import org.jboss.ejb.EnterpriseContext;
import org.jboss.ejb.EntityEnterpriseContext;
@@ -30,7 +31,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
public class NoPassivationEntityInstanceCache
implements InstanceCache
@@ -129,7 +130,7 @@
if (ctx == null) // Not in cache
{
// Get new instance from pool
- ctx = (EntityEnterpriseContext)con.getInstancePool().get();
+ ctx =
(EntityEnterpriseContext)((InstancePoolContainer)con).getInstancePool().get();
// Activate
ctx.setId(id);
@@ -162,7 +163,7 @@
((InstanceInfo)((EntityEnterpriseContext)ctx).getCacheContext()).unlock();
// System.out.println("Release entity:"+ctx.getId());
if
(!((InstanceInfo)((EntityEnterpriseContext)ctx).getCacheContext()).isLocked())
- ctx.notify();
+ ctx.notifyAll();
}
}
1.5 +3 -2
jboss/src/main/org/jboss/ejb/plugins/NoPassivationStatefulSessionInstanceCache.java
Index: NoPassivationStatefulSessionInstanceCache.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/NoPassivationStatefulSessionInstanceCache.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- NoPassivationStatefulSessionInstanceCache.java 2000/06/03 00:02:04 1.4
+++ NoPassivationStatefulSessionInstanceCache.java 2000/06/16 13:10:23 1.5
@@ -19,6 +19,7 @@
import org.jboss.ejb.StatefulSessionContainer;
import org.jboss.ejb.InstanceCache;
import org.jboss.ejb.InstancePool;
+import org.jboss.ejb.InstancePoolContainer;
import org.jboss.ejb.StatefulSessionPersistenceManager;
import org.jboss.ejb.EnterpriseContext;
import org.jboss.ejb.StatefulSessionEnterpriseContext;
@@ -31,7 +32,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 NoPassivationStatefulSessionInstanceCache
implements InstanceCache
@@ -108,7 +109,7 @@
if (ctx == null) {
// Get new instance from pool (bogus in our case)
- ctx =
(StatefulSessionEnterpriseContext)con.getInstancePool().get();
+ ctx =
(StatefulSessionEnterpriseContext)((InstancePoolContainer)con).getInstancePool().get();
// Activate
ctx.setId(id);
1.2 +2 -2
jboss/src/main/org/jboss/ejb/plugins/RandomEntityInstanceCache.java
Index: RandomEntityInstanceCache.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/RandomEntityInstanceCache.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RandomEntityInstanceCache.java 2000/04/22 14:30:12 1.1
+++ RandomEntityInstanceCache.java 2000/06/16 13:10:23 1.2
@@ -27,7 +27,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class RandomEntityInstanceCache
extends NoPassivationEntityInstanceCache
@@ -85,7 +85,7 @@
int currentActive = active.size();
if (currentActive > minActive)
{
- InstancePool pool = con.getInstancePool();
+ InstancePool pool = ((EntityContainer)con).getInstancePool();
Logger.debug("Too many active instances:"+currentActive);
// Passivate some instance; they need to be unlocked though
1.3 +19 -8 jboss/src/main/org/jboss/ejb/plugins/SecurityInterceptor.java
Index: SecurityInterceptor.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/SecurityInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SecurityInterceptor.java 2000/05/30 18:32:22 1.2
+++ SecurityInterceptor.java 2000/06/16 13:10:23 1.3
@@ -24,6 +24,7 @@
import org.jboss.ejb.EnterpriseContext;
import org.jboss.ejb.EntityEnterpriseContext;
import org.jboss.ejb.ContainerInvoker;
+import org.jboss.ejb.MethodInvocation;
import org.jboss.ejb.plugins.jrmp.interfaces.SecureSocketFactory;
@@ -34,7 +35,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class SecurityInterceptor
extends AbstractInterceptor
@@ -42,12 +43,22 @@
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
+ protected Container container;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
+ public void setContainer(Container container)
+ {
+ this.container = container;
+ }
+
+ public Container getContainer()
+ {
+ return container;
+ }
// Container implementation --------------------------------------
public void start()
@@ -56,12 +67,12 @@
super.start();
}
- public Object invokeHome(Method method, Object[] args, EnterpriseContext ctx)
+ public Object invokeHome(MethodInvocation mi)
throws Exception
{
-// if (ctx != null)
-// ctx.setPrincipal(SecureSocketFactory.getPrincipal());
- return getNext().invokeHome(method, args, ctx);
+ // TODO security checks
+
+ return getNext().invokeHome(mi);
}
/**
@@ -75,11 +86,11 @@
* @return
* @exception Exception
*/
- public Object invoke(Object id, Method method, Object[] args, EnterpriseContext
ctx)
+ public Object invoke(MethodInvocation mi)
throws Exception
{
-// ctx.setPrincipal(SecureSocketFactory.getPrincipal());
- return getNext().invoke(id, method, args, ctx);
+ // TODO security checks
+ return getNext().invoke(mi);
}
// Private -------------------------------------------------------
1.3 +35 -23
jboss/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceInterceptor.java
Index: StatefulSessionInstanceInterceptor.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StatefulSessionInstanceInterceptor.java 2000/06/02 09:36:43 1.2
+++ StatefulSessionInstanceInterceptor.java 2000/06/16 13:10:23 1.3
@@ -8,10 +8,13 @@
import java.lang.reflect.Method;
import java.rmi.RemoteException;
+
+import org.jboss.ejb.Container;
import org.jboss.ejb.InstanceCache;
import org.jboss.ejb.InstancePool;
import org.jboss.ejb.StatefulSessionContainer;
import org.jboss.ejb.EnterpriseContext;
+import org.jboss.ejb.MethodInvocation;
/**
@@ -20,38 +23,45 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.2 $
+* @version $Revision: 1.3 $
*/
public class StatefulSessionInstanceInterceptor
-extends AbstractInterceptor
+ extends AbstractInterceptor
{
// Constants ----------------------------------------------------
// Attributes ---------------------------------------------------
+ protected StatefulSessionContainer container;
// Static -------------------------------------------------------
// Constructors -------------------------------------------------
// Public -------------------------------------------------------
+ public void setContainer(Container container)
+ {
+ this.container = (StatefulSessionContainer)container;
+ }
+ public Container getContainer()
+ {
+ return container;
+ }
// Interceptor implementation -----------------------------------
- public Object invokeHome(Method method, Object[] args, EnterpriseContext ctx)
- throws Exception
+ public Object invokeHome(MethodInvocation mi)
+ throws Exception
{
// Get context
- ctx =
((StatefulSessionContainer)getContainer()).getInstancePool().get();
+ mi.setEnterpriseContext(container.getInstancePool().get());
try
{
// Invoke through interceptors
- return getNext().invokeHome(method, args, ctx);
-
+ return getNext().invokeHome(mi);
} finally
{
// Still free? Not free if create() was called successfully
- // MF Praise: hey for once the comment is good rickard ;-0
- if (ctx.getId() == null)
+ if (mi.getEnterpriseContext().getId() == null)
{
// Create did not associate an ID with the ctx
// There is nothing to do just let the garbage
collector do its work
@@ -59,58 +69,60 @@
} else
{
// Create was called succesfully we go to the cache
-
((StatefulSessionContainer)getContainer()).getInstanceCache().release(ctx);
+
container.getInstanceCache().release(mi.getEnterpriseContext());
}
}
}
- public Object invoke(Object id, Method method, Object[] args,
EnterpriseContext ctx)
- throws Exception
+ public Object invoke(MethodInvocation mi)
+ throws Exception
{
// Get context
- ctx =
((StatefulSessionContainer)getContainer()).getInstanceCache().get(id);
+ EnterpriseContext ctx = container.getInstanceCache().get(mi.getId());
+ mi.setEnterpriseContext(ctx);
try
{
// Invoke through interceptors
- return getNext().invoke(id, method, args, ctx);
+ return getNext().invoke(mi);
} catch (RemoteException e)
{
// Discard instance
-
((StatefulSessionContainer)getContainer()).getInstanceCache().remove(id);
+ container.getInstanceCache().remove(mi.getId());
ctx = null;
throw e;
} catch (RuntimeException e)
{
// Discard instance
-
((StatefulSessionContainer)getContainer()).getInstanceCache().remove(id);
+ container.getInstanceCache().remove(mi.getId());
ctx = null;
throw e;
} catch (Error e)
{
// Discard instance
-
((StatefulSessionContainer)getContainer()).getInstanceCache().remove(id);
+ container.getInstanceCache().remove(mi.getId());
ctx = null;
throw e;
- }
- finally {
-
+ } finally
+ {
if (ctx != null)
{
+ // Still a valid instance
+
if (ctx.getId() == null)
{
// Remove from cache
-
((StatefulSessionContainer)getContainer()).getInstanceCache().remove(id);
+
container.getInstanceCache().remove(mi.getId());
// It has been removed -> send to free pool
- getContainer().getInstancePool().free(ctx);
+ container.getInstancePool().free(ctx);
}
{
// Return context
-
((StatefulSessionContainer)getContainer()).getInstanceCache().release(ctx);
+ container.getInstanceCache().release(ctx);
}
}
}
1.2 +20 -10
jboss/src/main/org/jboss/ejb/plugins/StatelessSessionInstanceInterceptor.java
Index: StatelessSessionInstanceInterceptor.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/StatelessSessionInstanceInterceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StatelessSessionInstanceInterceptor.java 2000/04/22 14:30:12 1.1
+++ StatelessSessionInstanceInterceptor.java 2000/06/16 13:10:23 1.2
@@ -25,12 +25,12 @@
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
-import org.jboss.ejb.EntityContainer;
-import org.jboss.ejb.EntityPersistenceManager;
-import org.jboss.ejb.EntityEnterpriseContext;
+import org.jboss.ejb.Container;
+import org.jboss.ejb.StatelessSessionContainer;
import org.jboss.ejb.EnterpriseContext;
import org.jboss.ejb.InstanceCache;
import org.jboss.ejb.InstancePool;
+import org.jboss.ejb.MethodInvocation;
/**
* This container acquires the given instance. This must be used after
@@ -39,7 +39,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class StatelessSessionInstanceInterceptor
extends AbstractInterceptor
@@ -47,34 +47,44 @@
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
+ protected StatelessSessionContainer container;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
+ public void setContainer(Container container)
+ {
+ this.container = (StatelessSessionContainer)container;
+ }
+ public Container getContainer()
+ {
+ return container;
+ }
+
// Interceptor implementation --------------------------------------
- public Object invokeHome(Method method, Object[] args, EnterpriseContext ctx)
+ public Object invokeHome(MethodInvocation mi)
throws Exception
{
- return getNext().invokeHome(method, args, ctx);
+ return getNext().invokeHome(mi);
}
- public Object invoke(Object id, Method method, Object[] args, EnterpriseContext
ctx)
+ public Object invoke(MethodInvocation mi)
throws Exception
{
// Get context
- ctx = getContainer().getInstancePool().get();
+ mi.setEnterpriseContext(container.getInstancePool().get());
try
{
// Invoke through interceptors
- return getNext().invoke(id, method, args, ctx);
+ return getNext().invoke(mi);
} finally
{
// Return context
- getContainer().getInstancePool().free(ctx);
+ container.getInstancePool().free(mi.getEnterpriseContext());
}
}
}
1.6 +28 -15 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TxInterceptor.java 2000/05/30 18:32:22 1.5
+++ TxInterceptor.java 2000/06/16 13:10:23 1.6
@@ -21,7 +21,9 @@
import javax.ejb.EJBException;
+import org.jboss.ejb.Container;
import org.jboss.ejb.EnterpriseContext;
+import org.jboss.ejb.MethodInvocation;
import org.jboss.logging.Logger;
/**
@@ -29,7 +31,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public class TxInterceptor
extends AbstractInterceptor
@@ -45,12 +47,23 @@
// Attributes ----------------------------------------------------
private TransactionManager 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()
@@ -64,11 +77,11 @@
// eb.getBeanContext()
}
- public Object invokeHome(Method method, Object[] args, EnterpriseContext ctx)
+ public Object invokeHome(MethodInvocation mi)
throws Exception
{
// TODO
- return getNext().invokeHome(method, args, ctx);
+ return getNext().invokeHome(mi);
}
/**
@@ -80,12 +93,12 @@
* @return
* @exception Exception
*/
- public Object invoke(Object id, Method method, Object[] args, EnterpriseContext
ctx)
+ public Object invoke(MethodInvocation mi)
throws Exception
{
- Transaction current = getContainer().getTransactionManager().getTransaction();
+ Transaction current = mi.getTransaction();
- switch (getTransactionMethod(method))
+ switch (getTransactionMethod(mi.getMethod()))
{
case TX_NOT_SUPPORTED:
{
@@ -97,7 +110,7 @@
try
{
- return getNext().invoke(id, method, args, ctx);
+ return getNext().invoke(mi);
} finally
{
// Resume tx
@@ -105,7 +118,7 @@
}
} else
{
- return getNext().invoke(id, method, args, ctx);
+ return getNext().invoke(mi);
}
}
@@ -120,13 +133,13 @@
// Create tx
//DEBUG Logger.debug("Begin tx");
getContainer().getTransactionManager().begin();
- tx = getContainer().getTransactionManager().getTransaction();
+
mi.setTransaction(getContainer().getTransactionManager().getTransaction());
}
// Continue invocation
try
{
- return getNext().invoke(id, method, args, ctx);
+ return getNext().invoke(mi);
} catch (RemoteException e)
{
if (!tx.equals(current))
@@ -169,14 +182,13 @@
case TX_SUPPORTS:
{
//DEBUG Logger.debug("TX_SUPPORTS");
- Transaction tx = current;
// This mode doesn't really do anything
// If tx started -> do nothing
// If tx not started -> do nothing
// Continue invocation
- return getNext().invoke(id, method, args, ctx);
+ return getNext().invoke(mi);
}
case TX_REQUIRES_NEW:
@@ -186,11 +198,12 @@
// Always begin new tx
Logger.debug("Begin tx");
getContainer().getTransactionManager().begin();
+
mi.setTransaction(getContainer().getTransactionManager().getTransaction());
// Continue invocation
try
{
- return getNext().invoke(id, method, args, ctx);
+ return getNext().invoke(mi);
} catch (RemoteException e)
{
getContainer().getTransactionManager().rollback();
@@ -228,7 +241,7 @@
throw new TransactionRequiredException();
} else
{
- return getNext().invoke(id, method, args, ctx);
+ return getNext().invoke(mi);
}
}
@@ -240,7 +253,7 @@
throw new RemoteException("Transaction not allowed");
} else
{
- return getNext().invoke(id, method, args, ctx);
+ return getNext().invoke(mi);
}
}
}