class LocalBarrierGroups extends AbstractBarrierGroups {

  @Override
  protected BarrierGroupImplementation createBarrierGroup(String name) {

    return new BarrierGroupImplementation(name) {

      @Override public void removeBarriers(long n)
        throws CommunicationException {

        final Set<BarrierIdentity> waiters;

        synchronized (this) {
          super.removeBarriers(n);
          waiters = checkCondition();
        }

        if (waiters.size() > 0) {
          fireAwaken(waiters);
        }
      }

      @Override public void addWaiter(BarrierIdentity barrierIdentity)
        throws CommunicationException {

        final Set<BarrierIdentity> waiters;

        synchronized (this) {
          super.addWaiter(barrierIdentity);
          waiters = checkCondition();
        }

        if (waiters.size() > 0) {
          fireAwaken(waiters);
        }
      }
    };
  }

}