/** {@inheritDoc} */
  public void writeWire(final DataOutputStream out) throws IOException {

    // Write map size
    out.writeInt(lockQueues.size());

    // Write map entries
    final IOException[] exception = new IOException[1];
    lockQueues.forEachEntry(
        new ObjectObjectProcedure<LockQueueKey, LockQueue>() {

          public boolean execute(final LockQueueKey key, final LockQueue value) {

            try {

              key.writeWire(out);
              value.writeWire(out);
            } catch (final IOException e) {

              exception[0] = e;
              return false;
            }

            return true;
          }
        });

    // Throw exception if any
    if (exception[0] != null) {

      throw exception[0];
    }
  }
  /**
   * Returns a lock queue for a lock identified by the combination of <code>lockRegionName</code>
   * and <code>lockKey</code>. If the lock queue does not exist, creates and registers it.
   *
   * @param lockRegionName a name of the region where this lock is going to be placed. The region
   *     name is used to separate cluster-wide and cache-specific locks.
   * @param lockKey@return a lock queue.
   * @return the lock queue.
   */
  public LockQueue getLockQueue(final String lockRegionName, final Binary lockKey) {

    final LockQueueKey lockQueueKey = new LockQueueKey(lockRegionName, lockKey);
    LockQueue lockQueue = lockQueues.get(lockQueueKey);
    if (lockQueue == null) {

      lockQueue = new LockQueue();
      lockQueues.put(lockQueueKey, lockQueue);
    }
    return lockQueue;
  }
  /** {@inheritDoc} */
  public void readWire(final DataInputStream in) throws IOException, ClassNotFoundException {

    final int size = in.readInt();
    for (int i = 0; i < size; i++) {

      final LockQueueKey lockQueueKey = new LockQueueKey();
      lockQueueKey.readWire(in);
      final LockQueue lockQueue = new LockQueue();
      lockQueue.readWire(in);
      lockQueues.put(lockQueueKey, lockQueue);
    }
  }
  public boolean equals(final Object o) {

    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    final LockRegistry that = (LockRegistry) o;

    if (lockQueues != null ? !lockQueues.equals(that.lockQueues) : that.lockQueues != null) {
      return false;
    }

    return true;
  }
  public int hashCode() {

    return lockQueues != null ? lockQueues.hashCode() : 0;
  }