/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.aspects.concurrent;

import org.jboss.aop.joinpoint.Invocation;

import java.util.concurrent.CountDownLatch;

/**
 * comment
 *
 * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
 */
public class LatchAspect
{
   public Object checkLatch(Invocation invocation) throws Throwable
   {
      LatchedObject latched = (LatchedObject) invocation.getTargetObject();
      CountDownLatch latch = latched.getLatch();
      try
      {
         latch.await();
      }
      catch (InterruptedException e)
      {
         throw new RuntimeException(e);
      }
      return invocation.invokeNext();
   }
}
