@Override
    public void getContract(String apiOrganizationId, String apiId, String apiVersion, String apiKey,
            IAsyncResultHandler<ApiContract> handler) {
        Client client = null;
        Api api = null;

        String apiIdx = getApiIndex(apiOrganizationId, apiId, apiVersion);
        synchronized (mutex) {
            client = (Client) getMap().get(apiKey);
            api = (Api) getMap().get(apiIdx);
        }
        if (client == null) {
            Exception error = new ClientNotFoundException(Messages.i18n.format("InMemoryRegistry.NoClientForAPIKey", apiKey)); //$NON-NLS-1$
            handler.handle(AsyncResultImpl.create(error, ApiContract.class));
            return;
        }
        if (api == null) {
            Exception error = new ApiRetiredException(Messages.i18n.format("InMemoryRegistry.ApiWasRetired", //$NON-NLS-1$
                    apiId, apiOrganizationId));
            handler.handle(AsyncResultImpl.create(error, ApiContract.class));
            return;
        }

        Contract matchedContract = null;
        for (Contract contract : client.getContracts()) {
            if (contract.matches(apiOrganizationId, apiId, apiVersion)) {
                matchedContract = contract;
                break;
            }
        }

        if (matchedContract == null) {
            Exception error = new NoContractFoundException(Messages.i18n.format("InMemoryRegistry.NoContractFound", //$NON-NLS-1$
                    client.getClientId(), api.getApiId()));
            handler.handle(AsyncResultImpl.create(error, ApiContract.class));
            return;
        }

        ApiContract contract = new ApiContract(api, client, matchedContract.getPlan(), matchedContract.getPolicies());
        handler.handle(AsyncResultImpl.create(contract));
    }
@see io.apiman.gateway.engine.IRegistry#getContract(java.lang.String, java.lang.String, java.lang.String, java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/InMemoryRegistry.java