User: fleury
Date: 00/08/14 08:04:11
Modified: src/main/org/jboss/ejb/plugins
NoPassivationStatefulSessionInstanceCache.java
Log:
Error propagation, indentation and I need to remove some old debug comments
Revision Changes Path
1.7 +166 -158
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- NoPassivationStatefulSessionInstanceCache.java 2000/08/12 00:40:46 1.6
+++ NoPassivationStatefulSessionInstanceCache.java 2000/08/14 15:04:10 1.7
@@ -24,172 +24,180 @@
import org.jboss.ejb.EnterpriseContext;
import org.jboss.ejb.StatefulSessionEnterpriseContext;
+
/**
* <description>
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.6 $
+* @version $Revision: 1.7 $
*/
public class NoPassivationStatefulSessionInstanceCache
implements InstanceCache
{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
- Container con;
-
- Map active = new HashMap();
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- /**
- * Set the callback to the container. This is for initialization.
- * The IM may extract the configuration from the container.
- *
- * @param c
- */
- public void setContainer(Container c)
- {
- this.con = c;
- }
-
- public void init()
- throws Exception
- {
- }
-
- public void start()
- throws Exception
- {
- }
-
- public void stop()
- {
- }
-
- public void destroy()
- {
- }
-
- public synchronized EnterpriseContext get(Object id)
- throws RemoteException
- {
- InstanceInfo info = null;
-
- // Do we have the context in cache?
- StatefulSessionEnterpriseContext ctx =
- (StatefulSessionEnterpriseContext)active.get(id);
-
- // We have it in cache
- if (ctx != null) {
-
- info = (InstanceInfo)ctx.getCacheContext();
-
- if (info.isLocked()) {
-
- //MF DESIGN: talk about this one... I know it is spec
compliant but it sucks
- throw new RemoteException("Concurrent call to stateful
session is not allowed");
- }
-
- else {
-
- info.lock();
- }
- }
-
- // We don't have it in cache
- if (ctx == null) {
-
- // Get new instance from pool (bogus in our case)
- ctx =
(StatefulSessionEnterpriseContext)((InstancePoolContainer)con).getInstancePool().get();
-
- // Activate
- ctx.setId(id);
-
-
((StatefulSessionContainer)con).getPersistenceManager().activateSession(ctx);
-
- insert(ctx);
- }
- // The context has the instance as well and the right id
- return ctx;
- }
-
- public synchronized void insert(EnterpriseContext ctx)
- {
- InstanceInfo info =
createInstanceInfo((StatefulSessionEnterpriseContext)ctx);
- ((StatefulSessionEnterpriseContext)ctx).setCacheContext(info);
- info.lock();
- active.put(ctx.getId(), ctx) ;
- }
-
- public void release(EnterpriseContext ctx)
- {
- // This context is now available for other threads
-
((InstanceInfo)((StatefulSessionEnterpriseContext)ctx).getCacheContext()).unlock();
-
- // The following code makes sense if we put threads to sleep (not the
case anymore)
- //if
(!((InstanceInfo)((StatefulSessionEnterpriseContext)ctx).getCacheContext()).isLocked())
- // ctx.notify();
-
- }
-
- public synchronized void remove(Object id)
- {
- Object ctx = active.remove(id);
- synchronized(ctx)
- {
- ctx.notifyAll();
- }
- }
-
- // Z implementation ----------------------------------------------
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
- protected InstanceInfo createInstanceInfo(StatefulSessionEnterpriseContext ctx)
- {
- return new InstanceInfo(ctx);
- }
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
- class InstanceInfo
- {
- int locked = 0; // 0 == unlocked, >0 == locked
-
- StatefulSessionEnterpriseContext ctx;
-
- InstanceInfo(StatefulSessionEnterpriseContext ctx)
- {
- this.ctx = ctx;
- }
-
- public void lock()
- {
- locked++;
- }
-
- public void unlock()
- {
- locked--;
- }
-
- public boolean isLocked()
- {
- return locked > 0;
- }
-
- public StatefulSessionEnterpriseContext getContext()
- {
- return ctx;
- }
- }
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+ Container con;
+
+ Map active = new HashMap();
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ /**
+ * Set the callback to the container. This is for initialization.
+ * The IM may extract the configuration from the container.
+ *
+ * @param c
+ */
+ public void setContainer(Container c)
+ {
+ this.con = c;
+ }
+
+ public void init()
+ throws Exception
+ {
+ }
+
+ public void start()
+ throws Exception
+ {
+ }
+
+ public void stop()
+ {
+ }
+
+ public void destroy()
+ {
+ }
+
+ public synchronized EnterpriseContext get(Object id)
+ throws RemoteException
+ {
+ InstanceInfo info = null;
+
+ System.out.println("I AM LOOKING FOR THE ID "+id);
+ // Do we have the context in cache?
+ StatefulSessionEnterpriseContext ctx =
+ (StatefulSessionEnterpriseContext)active.get(id);
+
+ // We have it in cache
+ if (ctx != null) {
+
+ info = (InstanceInfo)ctx.getCacheContext();
+
+ if (info.isLocked()) {
+
+ //MF DESIGN: talk about this one... I know it is spec compliant but it
sucks
+ throw new RemoteException("Concurrent call to stateful session is not
allowed");
+ }
+
+ else {
+
+ info.lock();
+ }
+ }
+
+ // We don't have it in cache
+ if (ctx == null) {
+
+ // Get new instance from pool (bogus in our case)
+ ctx =
(StatefulSessionEnterpriseContext)((InstancePoolContainer)con).getInstancePool().get();
+
+ // Activate
+ ctx.setId(id);
+
+ try {
+
+
((StatefulSessionContainer)con).getPersistenceManager().activateSession(ctx);
+ }
+ catch (Exception e) {
+
+ throw new RemoteException("Object was not found");
+ }
+ insert(ctx);
+ }
+ // The context has the instance as well and the right id
+ return ctx;
+ }
+
+ public synchronized void insert(EnterpriseContext ctx)
+ {
+ InstanceInfo info =
createInstanceInfo((StatefulSessionEnterpriseContext)ctx);
+ ((StatefulSessionEnterpriseContext)ctx).setCacheContext(info);
+ info.lock();
+ active.put(ctx.getId(), ctx) ;
+ }
+
+ public void release(EnterpriseContext ctx)
+ {
+ // This context is now available for other threads
+
((InstanceInfo)((StatefulSessionEnterpriseContext)ctx).getCacheContext()).unlock();
+
+ // The following code makes sense if we put threads to sleep (not the case
anymore)
+ //if
(!((InstanceInfo)((StatefulSessionEnterpriseContext)ctx).getCacheContext()).isLocked())
+ // ctx.notify();
+
+ }
+
+ public synchronized void remove(Object id)
+ {
+ Object ctx = active.remove(id);
+ synchronized(ctx)
+ {
+ ctx.notifyAll();
+ }
+ }
+
+ // Z implementation ----------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+ protected InstanceInfo createInstanceInfo(StatefulSessionEnterpriseContext ctx)
+ {
+ return new InstanceInfo(ctx);
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+ class InstanceInfo
+ {
+ int locked = 0; // 0 == unlocked, >0 == locked
+
+ StatefulSessionEnterpriseContext ctx;
+
+ InstanceInfo(StatefulSessionEnterpriseContext ctx)
+ {
+ this.ctx = ctx;
+ }
+
+ public void lock()
+ {
+ locked++;
+ }
+
+ public void unlock()
+ {
+ locked--;
+ }
+
+ public boolean isLocked()
+ {
+ return locked > 0;
+ }
+
+ public StatefulSessionEnterpriseContext getContext()
+ {
+ return ctx;
+ }
+ }
}