User: fleury
Date: 00/08/24 19:03:37
Modified: src/main/org/jboss/ejb/plugins
RandomEntityInstanceCache.java
Log:
Random Entity now works with the right cache
Revision Changes Path
1.6 +114 -108
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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- RandomEntityInstanceCache.java 2000/08/24 18:02:24 1.5
+++ RandomEntityInstanceCache.java 2000/08/25 02:03:37 1.6
@@ -29,120 +29,125 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.5 $
+* @version $Revision: 1.6 $
*/
public class RandomEntityInstanceCache
extends NoPassivationEntityInstanceCache
{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
- boolean running = false; // Passivator thread running?
-
- int minActive = 100; // Always try to passivate if more than this nr are active
-
- long timeout = 60*1000L; // Passivation sweep sleep time
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
- public void start()
- throws Exception
- {
- running = true;
- new Thread(new Passivator()).start();
- }
-
- public void stop()
- {
- running = false;
- }
-
- // Z implementation ----------------------------------------------
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
- class Passivator
- implements Runnable
- {
- RandomEntityInstanceCache cache;
-
- public void run()
- {
- Logger.debug("Passivator started");
- // Passivation loop
- while(running)
- {
+<<<<<<< RandomEntityInstanceCache.java
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+ boolean running = false; // Passivator thread running?
+
+ int minActive = 100; // Always try to passivate if more than this nr are active
+
+ long timeout = 60*1000L; // Passivation sweep sleep time
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+ public void start()
+ throws Exception
+ {
+ running = true;
+ new Thread(new Passivator()).start();
+ }
+
+ public void stop()
+ {
+ running = false;
+ }
+
+ // Z implementation ----------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+ class Passivator
+ implements Runnable
+ {
+ //RandomEntityInstanceCache cache;
+
+ public void run()
+ {
+ Logger.debug("Passivator started");
+ // Passivation loop
+ while(running)
+ {
// Logger.log("Clearing cache");
- // Passivate old. Lock cache first
- synchronized(RandomEntityInstanceCache.this)
- {
- // Do not use cache (many to one entries)
- int currentActive = fastKeys.size();
- if (currentActive > minActive)
- {
- InstancePool pool =
((EntityContainer)con).getInstancePool();
-
- Logger.debug("Too many active instances:"+currentActive);
-
- // Passivate some instance; they need to be unlocked though
-
- Iterator ids = fastKeys.keySet().iterator();
-
- while(ids.hasNext())
- {
-
- Object id = ids.next();
-
- //Get the context
- EntityEnterpriseContext ctx =
- (EntityEnterpriseContext)fastCache.get(((LinkedList)
fastKeys.get(id)).getFirst());
-
-
- // Make sure we can work on it
- Logger.debug("Checking:"+ctx.getId());
- InstanceInfo info = (InstanceInfo)ctx.getCacheContext();
-
- //We we locked?
- if (!info.isLocked())
- {
- // Nope then Passivate
- try
- {
- Logger.debug("Passivating:"+ctx.getId());
-
((EntityContainer)con).getPersistenceManager().passivateEntity(ctx);
-
-
- // Get the List by removing from fastKeys
- LinkedList keysList = (LinkedList)
fastKeys.remove(ids.next());
-
- // Remove all the fastKeys from the cache
- Iterator iterator = keysList.listIterator();
-
- while (iterator.hasNext()) {
-
- fastCache.remove(iterator.next());
- }
-
- currentActive--;
- }
-
- catch (Exception e) { Logger.log("Could not
passivate instance");}
- }
-
- if (currentActive == minActive) break;
-
- }
- }
- }
+ // Passivate old. Lock cache first
+ //synchronized(RandomEntityInstanceCache.this)
+ synchronized(cache)
+ {
+ // Do not use cache (many to one entries)
+ int currentActive = cacheKeys.size();
+ if (currentActive > minActive)
+ {
+ InstancePool pool =
((EntityContainer)con).getInstancePool();
+
+ Logger.debug("Too many active
instances:"+currentActive);
+
+ // Passivate some instance; they need
to be unlocked though
+
+ //KeySet has keys (currentActive>0)
+ Iterator ids =
cacheKeys.keySet().iterator();
+
+ while(ids.hasNext())
+ {
+
+ Object id = ids.next();
+
+ //Get the context
+ EntityEnterpriseContext ctx =
+
(EntityEnterpriseContext) cache.get(((LinkedList) cacheKeys.get(id)).getFirst());
+
+
+ // Make sure we can work on it
+
Logger.debug("Checking:"+ctx.getId());
+ InstanceInfo info =
(InstanceInfo)ctx.getCacheContext();
+
+ //We we locked?
+ if (!info.isLocked())
+ {
+ // Nope then Passivate
+ try
+ {
+
Logger.debug("Passivating:"+ctx.getId());
+
((EntityContainer)con).getPersistenceManager().passivateEntity(ctx);
+
+
+ // Get the
List by removing from cacheKeys
+ LinkedList
keysList = (LinkedList) cacheKeys.remove(ids.next());
+
+ // Remove all
the cacheKeys from the cache
+ Iterator
iterator = keysList.listIterator();
+
+ while
(iterator.hasNext()) {
+
+
cache.remove(iterator.next());
+ }
+
+
currentActive--;
+ }
+
+ catch (Exception e) {
Logger.log("Could not passivate instance");}
+ }
+
+ if (currentActive ==
minActive) break;
+
+ }
+
+ }
+ }
// Logger.log("Passivation done");
+
// Sleep
try
{
@@ -151,6 +156,7 @@
{
// Ignore
}
+
}
}
}
- [jBoss-Dev] CVS update: jboss/src/main/org/jboss/ejb... jBoss CVS Development
- [jBoss-Dev] CVS update: jboss/src/main/org/jbos... jBoss CVS Development
- [jBoss-Dev] CVS update: jboss/src/main/org/jbos... jBoss CVS Development
- [jBoss-Dev] CVS update: jboss/src/main/org/jbos... jBoss CVS Development
