[jboss-cvs] JBossAS SVN: r78916 - trunk/server/src/main/org/jboss/ejb/txtimer.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Sep 29 05:34:09 EDT 2008


Author: alex.loubyansky at jboss.com
Date: 2008-09-29 05:34:08 -0400 (Mon, 29 Sep 2008)
New Revision: 78916

Modified:
   trunk/server/src/main/org/jboss/ejb/txtimer/EJBTimerServiceImpl.java
Log:
JBAS-5999 synchronize on timerServiceMap before iteration; type-parameterized timerServiceMap

Modified: trunk/server/src/main/org/jboss/ejb/txtimer/EJBTimerServiceImpl.java
===================================================================
--- trunk/server/src/main/org/jboss/ejb/txtimer/EJBTimerServiceImpl.java	2008-09-29 07:33:34 UTC (rev 78915)
+++ trunk/server/src/main/org/jboss/ejb/txtimer/EJBTimerServiceImpl.java	2008-09-29 09:34:08 UTC (rev 78916)
@@ -124,7 +124,7 @@
    private TimerIdGenerator timerIdGenerator;   
    
    // Maps the timedObjectId to TimerServiceImpl objects
-   private Map timerServiceMap = Collections.synchronizedMap(new HashMap());
+   private Map<TimedObjectId, TimerServiceImpl> timerServiceMap = Collections.synchronizedMap(new HashMap<TimedObjectId, TimerServiceImpl>());
 
    // Attributes ----------------------------------------------------
    
@@ -252,7 +252,7 @@
       // Get the timerId generator
       try
       {
-         Class timerIdGeneratorClass = getClass().getClassLoader().loadClass(timerIdGeneratorClassName);
+         Class<?> timerIdGeneratorClass = getClass().getClassLoader().loadClass(timerIdGeneratorClassName);
          timerIdGenerator = (TimerIdGenerator)timerIdGeneratorClass.newInstance();
       }
       catch (Exception e)
@@ -288,8 +288,8 @@
       try
       {
          TimedObjectId timedObjectId = new TimedObjectId(containerId, instancePk);
-         Class invokerClass = getClass().getClassLoader().loadClass(timedObjectInvokerClassName);
-         Constructor constr = invokerClass.getConstructor(new Class[]{TimedObjectId.class, Container.class});
+         Class<?> invokerClass = getClass().getClassLoader().loadClass(timedObjectInvokerClassName);
+         Constructor<?> constr = invokerClass.getConstructor(new Class[]{TimedObjectId.class, Container.class});
          invoker = (TimedObjectInvoker)constr.newInstance(new Object[]{timedObjectId, container});
       }
       catch (Exception e)
@@ -312,7 +312,7 @@
    public TimerService createTimerService(ObjectName containerId, Object instancePk, TimedObjectInvoker invoker)
    {
       TimedObjectId timedObjectId = new TimedObjectId(containerId, instancePk);
-      TimerServiceImpl timerService = (TimerServiceImpl)timerServiceMap.get(timedObjectId);
+      TimerServiceImpl timerService = timerServiceMap.get(timedObjectId);
       if (timerService == null)
       {
          timerService = new TimerServiceImpl(timedObjectId, invoker,
@@ -333,7 +333,7 @@
    public TimerService getTimerService(ObjectName containerId, Object instancePk)
    {
       TimedObjectId timedObjectId = new TimedObjectId(containerId, instancePk);
-      return (TimerServiceImpl)timerServiceMap.get(timedObjectId);
+      return timerServiceMap.get(timedObjectId);
    }
 
    /**
@@ -383,17 +383,20 @@
    public void removeTimerService(ObjectName containerId, boolean keepState) throws IllegalStateException
    {
       // remove all timers with the given containerId
-      Iterator it = timerServiceMap.entrySet().iterator();
-      while (it.hasNext())
+      synchronized(timerServiceMap)
       {
-         Map.Entry entry = (Map.Entry)it.next();
-         TimedObjectId key = (TimedObjectId)entry.getKey();
-         TimerServiceImpl timerService = (TimerServiceImpl)entry.getValue();
-         if (containerId.equals(key.getContainerId()))
+         Iterator<Map.Entry<TimedObjectId, TimerServiceImpl>> it = timerServiceMap.entrySet().iterator();
+         while (it.hasNext())
          {
-            log.debug("removeTimerService: " + timerService);
-            timerService.shutdown(keepState);
-            it.remove();
+            Map.Entry<TimedObjectId, TimerServiceImpl> entry = it.next();
+            TimedObjectId key = entry.getKey();
+            TimerServiceImpl timerService = entry.getValue();
+            if (containerId.equals(key.getContainerId()))
+            {
+               log.debug("removeTimerService: " + timerService);
+               timerService.shutdown(keepState);
+               it.remove();
+            }
          }
       }
    }
@@ -422,17 +425,20 @@
       // remove all timers with the given containerId
       else
       {
-         Iterator it = timerServiceMap.entrySet().iterator();
-         while (it.hasNext())
+         synchronized(timerServiceMap)
          {
-            Map.Entry entry = (Map.Entry)it.next();
-            TimedObjectId key = (TimedObjectId)entry.getKey();
-            TimerServiceImpl timerService = (TimerServiceImpl)entry.getValue();
-            if (containerId.equals(key.getContainerId()))
+            Iterator<Map.Entry<TimedObjectId, TimerServiceImpl>> it = timerServiceMap.entrySet().iterator();
+            while (it.hasNext())
             {
-               log.debug("removeTimerService: " + timerService);
-               timerService.shutdown(keepState);
-               it.remove();
+               Map.Entry<TimedObjectId, TimerServiceImpl> entry = it.next();
+               TimedObjectId key = (TimedObjectId) entry.getKey();
+               TimerServiceImpl timerService = (TimerServiceImpl) entry.getValue();
+               if (containerId.equals(key.getContainerId()))
+               {
+                  log.debug("removeTimerService: " + timerService);
+                  timerService.shutdown(keepState);
+                  it.remove();
+               }
             }
          }
       }      
@@ -491,24 +497,26 @@
    public String listTimers()
    {
       StringBuffer retBuffer = new StringBuffer();
-      Iterator it = timerServiceMap.entrySet().iterator();
-      while (it.hasNext())
+      synchronized(timerServiceMap)
       {
-         Map.Entry entry = (Map.Entry)it.next();
-         TimedObjectId timedObjectId = (TimedObjectId)entry.getKey();
-         retBuffer.append(timedObjectId + "\n");
+         Iterator<Map.Entry<TimedObjectId, TimerServiceImpl>> it = timerServiceMap.entrySet().iterator();
+         while (it.hasNext())
+         {
+            Map.Entry<TimedObjectId, TimerServiceImpl> entry = it.next();
+            TimedObjectId timedObjectId = (TimedObjectId) entry.getKey();
+            retBuffer.append(timedObjectId + "\n");
 
-         TimerServiceImpl timerService = (TimerServiceImpl)entry.getValue();
-         Collection col = timerService.getAllTimers();
-         for (Iterator iterator = col.iterator(); iterator.hasNext();)
-         {
-            TimerImpl timer = (TimerImpl)iterator.next();
-            TimerHandleImpl handle = new TimerHandleImpl(timer);
-            retBuffer.append("   handle: " + handle + "\n");
-            retBuffer.append("      " + timer + "\n");
+            TimerServiceImpl timerService = (TimerServiceImpl) entry.getValue();
+            Collection col = timerService.getAllTimers();
+            for (Iterator iterator = col.iterator(); iterator.hasNext();)
+            {
+               TimerImpl timer = (TimerImpl) iterator.next();
+               TimerHandleImpl handle = new TimerHandleImpl(timer);
+               retBuffer.append("   handle: " + handle + "\n");
+               retBuffer.append("      " + timer + "\n");
+            }
          }
       }
       return retBuffer.toString();
-   }
- 
+   } 
 }




More information about the jboss-cvs-commits mailing list