@Override
  public synchronized void setBlockingState(
      final BlockingState state, final Clock clock, final InternalCallContext context) {
    if (blockingStates.get(state.getBlockedId()) == null) {
      blockingStates.put(state.getBlockedId(), new ArrayList<BlockingState>());
    }
    blockingStates.get(state.getBlockedId()).add(state);

    if (blockingStatesPerAccountRecordId.get(context.getAccountRecordId()) == null) {
      blockingStatesPerAccountRecordId.put(
          context.getAccountRecordId(), new ArrayList<BlockingState>());
    }
    blockingStatesPerAccountRecordId.get(context.getAccountRecordId()).add(state);
  }
 // Notes:
 //  + we need to keep the same implementation here as
 // DefaultBlockingStateDao.BLOCKING_STATE_MODEL_DAO_ORDERING
 //  + to sort blocking states in entitlement, check ProxyBlockingStateDao#sortedCopy
 @Override
 public int compareTo(final BlockingState arg0) {
   // effective_date column NOT NULL
   final int comparison = effectiveDate.compareTo(arg0.getEffectiveDate());
   if (comparison == 0) {
     // Keep a stable ordering for ties
     final int comparison2 = createdDate.compareTo(arg0.getCreatedDate());
     if (comparison2 == 0 && getClass() != arg0.getClass()) {
       final DefaultBlockingState other = (DefaultBlockingState) arg0;
       // New element is last
       if (totalOrdering == null) {
         return 1;
       } else if (other.getTotalOrdering() == null) {
         return -1;
       } else {
         return totalOrdering.compareTo(other.getTotalOrdering());
       }
     } else {
       return comparison2;
     }
   } else {
     return comparison;
   }
 }
  @Override
  public List<BlockingState> getBlockingState(
      final UUID blockableId,
      final BlockingStateType blockingStateType,
      final InternalTenantContext context) {
    final List<BlockingState> blockingStatesForId = blockingStates.get(blockableId);
    if (blockingStatesForId == null) {
      return new ArrayList<BlockingState>();
    }

    final Map<String, BlockingState> tmp = new HashMap<String, BlockingState>();
    for (BlockingState cur : blockingStatesForId) {
      final BlockingState curStateForService = tmp.get(cur.getService());
      if (curStateForService == null
          || curStateForService.getEffectiveDate().compareTo(cur.getEffectiveDate()) < 0) {
        tmp.put(cur.getService(), cur);
      }
    }
    return new ArrayList<BlockingState>(tmp.values());
  }