@Override
    public void registerClient(Client client, IAsyncResultHandler<Void> handler) {
        Exception error = null;
        synchronized (mutex) {
            // Validate the client first - we need to be able to resolve all the contracts.
            for (Contract contract : client.getContracts()) {
                String apiIdx = getApiIndex(contract.getApiOrgId(), contract.getApiId(), contract.getApiVersion());
                if (!getMap().containsKey(apiIdx)) {
                    error = new ApiNotFoundException(Messages.i18n.format("InMemoryRegistry.ApiNotFoundInOrg", //$NON-NLS-1$
                            contract.getApiId(), contract.getApiOrgId()));
                    break;
                }
            }

            if (error == null) {
                // Unregister the client (if it exists)
                unregisterClientInternal(client, true);

                // Now, register the client.
                String clientIdx = getClientIndex(client);
                getMap().put(clientIdx, client);
                getMap().put(client.getApiKey(), client);

                handler.handle(AsyncResultImpl.create((Void) null));
            } else {
                handler.handle(AsyncResultImpl.create(error, Void.class));
            }
        }
    }
@see io.apiman.gateway.engine.IRegistry#registerClient(io.apiman.gateway.engine.beans.Client, io.apiman.gateway.engine.async.IAsyncResultHandler)
gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/InMemoryRegistry.java