當前位置: 首頁>>代碼示例>>Java>>正文


Java IAsyncResultHandler.handle方法代碼示例

本文整理匯總了Java中io.apiman.gateway.engine.async.IAsyncResultHandler.handle方法的典型用法代碼示例。如果您正苦於以下問題:Java IAsyncResultHandler.handle方法的具體用法?Java IAsyncResultHandler.handle怎麽用?Java IAsyncResultHandler.handle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.apiman.gateway.engine.async.IAsyncResultHandler的用法示例。


在下文中一共展示了IAsyncResultHandler.handle方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getProperty

import io.apiman.gateway.engine.async.IAsyncResultHandler; //導入方法依賴的package包/類
/**
 * @see io.apiman.gateway.engine.components.ISharedStateComponent#getProperty(java.lang.String, java.lang.String, java.lang.Object, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@SuppressWarnings("unchecked")
@Override
public <T> void getProperty(String namespace, String propertyName, T defaultValue, IAsyncResultHandler<T> handler) {
    final String namespacedKey = buildNamespacedKey(namespace, propertyName);
    if (getSharedState().containsKey(namespacedKey)) {
        try {
            T rval = (T) getSharedState().get(namespacedKey);
            handler.handle(AsyncResultImpl.create(rval));
        } catch (Exception e) {
            handler.handle(AsyncResultImpl.create(e));
        }

    } else {
        handler.handle(AsyncResultImpl.create(defaultValue));
    }
}
 
開發者ID:outofcoffee,項目名稱:apiman-plugins-session,代碼行數:20,代碼來源:HazelcastSharedStateComponent.java

示例2: auth

import io.apiman.gateway.engine.async.IAsyncResultHandler; //導入方法依賴的package包/類
@Override
public StandardAuth auth(IAsyncResultHandler<Void> resultHandler) {
    // If we have no cache entry, then block. Otherwise, the request can immediately go
    // through and we will resolve the rate limiting status post hoc (various strategies
    // depending on settings).
    if (authCache.isAuthCached(config, request, keyElems)) {
        logger.debug("[ServiceId: {0}] Cached auth on request: {1}", serviceId, request);
        resultHandler.handle(OK_CACHED);
    } else {
        logger.debug("[ServiceId: {0}] Uncached auth on request: {1}", serviceId, request);
        context.setAttribute(BLOCKING_FLAG, true);
        doBlockingAuthRep(result -> {
            logger.debug("Blocking auth success?: {0}", result.isSuccess());
            // Only cache if successful
            if (result.isSuccess()) {
                authCache.cache(config, request, keyElems);
            }
            // Pass result up.
            resultHandler.handle(result);
        });
    }
    return this;
}
 
開發者ID:apiman,項目名稱:apiman-plugins,代碼行數:24,代碼來源:StandardAuth.java

示例3: auth

import io.apiman.gateway.engine.async.IAsyncResultHandler; //導入方法依賴的package包/類
@Override
public BatchedAuth auth(IAsyncResultHandler<Void> resultHandler) {
    // If we have no cache entry, then block. Otherwise, the request can immediately go
    // through and we will resolve the rate limiting status post hoc (various strategies
    // depending on settings).
    if (authCache.isAuthCached(config, request, keyElems)) {
        logger.debug("[ServiceId: {0}] Cached auth on request: {1}", serviceId, request);
        resultHandler.handle(OK_CACHED);
    } else {
        logger.debug("[ServiceId: {0}] Uncached auth on request: {1}", serviceId, request);
        context.setAttribute(BLOCKING_FLAG, true);
        doBlockingAuthRep(result -> {
            logger.debug("Blocking auth success?: {0}", result.isSuccess());
            // Only cache if successful
            if (result.isSuccess()) {
                authCache.cache(config, request, keyElems);
            }
            // Pass result up.
            resultHandler.handle(result);
        });
    }
    return this;
}
 
開發者ID:apiman,項目名稱:apiman-plugins,代碼行數:24,代碼來源:BatchedAuth.java

示例4: wrapResultHandler

import io.apiman.gateway.engine.async.IAsyncResultHandler; //導入方法依賴的package包/類
/**
 * Wraps the result handler so that metrics can be properly recorded.
 */
private IAsyncResultHandler<IEngineResult> wrapResultHandler(final IAsyncResultHandler<IEngineResult> handler) {
    return (IAsyncResult<IEngineResult> result) -> {
        boolean doRecord = true;
        if (result.isError()) {
            recordErrorMetrics(result.getError());
        } else {
            IEngineResult engineResult = result.getResult();
            if (engineResult.isFailure()) {
                recordFailureMetrics(engineResult.getPolicyFailure());
            } else {
                recordSuccessMetrics(engineResult.getApiResponse());
                doRecord = false; // don't record the metric now because we need to record # of bytes downloaded, which hasn't happened yet
            }
        }
        requestMetric.setRequestEnd(new Date());
        if (doRecord) {
            metrics.record(requestMetric);
        }
        handler.handle(result);
    };
}
 
開發者ID:apiman,項目名稱:apiman,代碼行數:25,代碼來源:ApiRequestExecutorImpl.java

示例5: getProperty

import io.apiman.gateway.engine.async.IAsyncResultHandler; //導入方法依賴的package包/類
/**
 * @see io.apiman.gateway.engine.components.ISharedStateComponent#getProperty(java.lang.String, java.lang.String, java.lang.Object, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@SuppressWarnings("unchecked")
@Override
public <T> void getProperty(String namespace, String propertyName, T defaultValue,
        IAsyncResultHandler<T> handler) {
    QName qname = new QName(namespace, propertyName);
    if (getCache().containsKey(qname)) {
        try {
            T rval = (T) getCache().get(qname);
            handler.handle(AsyncResultImpl.create(rval));
        } catch (Exception e) {
            handler.handle(AsyncResultImpl.<T>create(e));
        }

    } else {
        handler.handle(AsyncResultImpl.create(defaultValue));
    }
}
 
開發者ID:apiman,項目名稱:apiman,代碼行數:21,代碼來源:InfinispanSharedStateComponent.java

示例6: retireApi

import io.apiman.gateway.engine.async.IAsyncResultHandler; //導入方法依賴的package包/類
/**
 * @see io.apiman.gateway.engine.IRegistry#retireApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@Override
public void retireApi(Api api, final IAsyncResultHandler<Void> handler) {
    final String id = getApiId(api);

    try {
        Delete delete = new Delete.Builder(id).index(getIndexName()).type("api").build(); //$NON-NLS-1$
        JestResult result = getClient().execute(delete);
        if (result.isSucceeded()) {
            handler.handle(AsyncResultImpl.create((Void) null));
        } else {
            handler.handle(AsyncResultImpl.create(new ApiNotFoundException(Messages.i18n.format("ESRegistry.ApiNotFound")))); //$NON-NLS-1$
        }
    } catch (IOException e) {
        handler.handle(AsyncResultImpl.create(new PublishingException(Messages.i18n.format("ESRegistry.ErrorRetiringApi"), e))); //$NON-NLS-1$
    }
}
 
開發者ID:apiman,項目名稱:apiman,代碼行數:20,代碼來源:ESRegistry.java

示例7: accept

import io.apiman.gateway.engine.async.IAsyncResultHandler; //導入方法依賴的package包/類
/**
 * @see io.apiman.gateway.engine.components.IRateLimiterComponent#accept(java.lang.String, io.apiman.gateway.engine.rates.RateBucketPeriod, long, long, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@Override
public void accept(String bucketId, RateBucketPeriod period, long limit, long increment, IAsyncResultHandler<RateLimitResponse> handler) {
    RateLimiterBucket bucket;
    synchronized (buckets) {
        bucket = buckets.get(bucketId);
        if (bucket == null) {
            bucket = new RateLimiterBucket();
            buckets.put(bucketId, bucket);
        }
        bucket.resetIfNecessary(period);

        RateLimitResponse response = new RateLimitResponse();
        if (bucket.getCount() > limit) {
            response.setAccepted(false);
        } else {
            response.setAccepted(bucket.getCount() < limit);
            bucket.setCount(bucket.getCount() + increment);
            bucket.setLast(System.currentTimeMillis());
        }
        int reset = (int) (bucket.getResetMillis(period) / 1000L);
        response.setReset(reset);
        response.setRemaining(limit - bucket.getCount());
        handler.handle(AsyncResultImpl.<RateLimitResponse>create(response));
    }
}
 
開發者ID:apiman,項目名稱:apiman,代碼行數:29,代碼來源:InMemoryRateLimiterComponent.java

示例8: accept

import io.apiman.gateway.engine.async.IAsyncResultHandler; //導入方法依賴的package包/類
/**
 * @see io.apiman.gateway.engine.components.IRateLimiterComponent#accept(java.lang.String, io.apiman.gateway.engine.rates.RateBucketPeriod, long, long, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@Override
public void accept(final String bucketId, final RateBucketPeriod period, final long limit,
                   final long increment, final IAsyncResultHandler<RateLimitResponse> handler) {
    RateLimiterBucket bucket;
    synchronized (mutex) {
        bucket = (RateLimiterBucket) getSharedState().get(bucketId);
        if (bucket == null) {
            bucket = new RateLimiterBucket();
            getSharedState().put(bucketId, bucket);
        }
        bucket.resetIfNecessary(period);

        RateLimitResponse response = new RateLimitResponse();
        if (bucket.getCount() > limit) {
            response.setAccepted(false);
        } else {
            response.setAccepted(bucket.getCount() < limit);
            bucket.setCount(bucket.getCount() + increment);
            bucket.setLast(System.currentTimeMillis());
        }
        int reset = (int) (bucket.getResetMillis(period) / 1000L);
        response.setReset(reset);
        response.setRemaining(limit - bucket.getCount());
        handler.handle(AsyncResultImpl.create(response));
        getSharedState().put(bucketId, bucket);
    }
}
 
開發者ID:outofcoffee,項目名稱:apiman-plugins-session,代碼行數:31,代碼來源:HazelcastRateLimiterComponent.java

示例9: setProperty

import io.apiman.gateway.engine.async.IAsyncResultHandler; //導入方法依賴的package包/類
/**
 * @see io.apiman.gateway.engine.components.ISharedStateComponent#setProperty(java.lang.String, java.lang.String, java.lang.Object, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@Override
public <T> void setProperty(String namespace, String propertyName, T value, IAsyncResultHandler<Void> handler) {
    final String namespacedKey = buildNamespacedKey(namespace, propertyName);
    try {
        getSharedState().put(namespacedKey, value);
        handler.handle(AsyncResultImpl.create((Void) null));
    } catch (Exception e) {
        handler.handle(AsyncResultImpl.create(e));
    }
}
 
開發者ID:outofcoffee,項目名稱:apiman-plugins-session,代碼行數:14,代碼來源:HazelcastSharedStateComponent.java

示例10: clearProperty

import io.apiman.gateway.engine.async.IAsyncResultHandler; //導入方法依賴的package包/類
/**
 * @see io.apiman.gateway.engine.components.ISharedStateComponent#clearProperty(java.lang.String, java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@Override
public <T> void clearProperty(String namespace, String propertyName, IAsyncResultHandler<Void> handler) {
    final String namespacedKey = buildNamespacedKey(namespace, propertyName);
    try {
        getSharedState().remove(namespacedKey);
        handler.handle(AsyncResultImpl.create((Void) null));
    } catch (Exception e) {
        handler.handle(AsyncResultImpl.create(e));
    }
}
 
開發者ID:outofcoffee,項目名稱:apiman-plugins-session,代碼行數:14,代碼來源:HazelcastSharedStateComponent.java

示例11: storeSession

import io.apiman.gateway.engine.async.IAsyncResultHandler; //導入方法依賴的package包/類
@Override
public void storeSession(String sessionId, Session session, IAsyncResultHandler<Void> handler) {
    try {
        cacheStore.put(buildCacheKey(sessionId), session, Constants.MAX_SESSION_TTL);
        handler.handle(AsyncResultImpl.<Void>create(null));

    } catch (IOException e) {
        handler.handle(AsyncResultImpl.<Void>create(e));
    }
}
 
開發者ID:outofcoffee,項目名稱:apiman-plugins-session,代碼行數:11,代碼來源:CacheSessionStoreImpl.java

示例12: deleteSession

import io.apiman.gateway.engine.async.IAsyncResultHandler; //導入方法依賴的package包/類
@Override
public void deleteSession(String sessionId, IAsyncResultHandler<Void> handler) {
    try {
        // overwrite the data and set it to expire immediately
        cacheStore.put(buildCacheKey(sessionId), new Session(), 0);
        handler.handle(AsyncResultImpl.<Void>create(null));

    } catch (IOException e) {
        handler.handle(AsyncResultImpl.<Void>create(e));
    }
}
 
開發者ID:outofcoffee,項目名稱:apiman-plugins-session,代碼行數:12,代碼來源:CacheSessionStoreImpl.java

示例13: auth

import io.apiman.gateway.engine.async.IAsyncResultHandler; //導入方法依賴的package包/類
@Override
public AuthPrincipal auth(IAsyncResultHandler<Void> resultHandler) {
    String appId = AppIdUtils.getAppId(config, request);
    String appKey = AppIdUtils.getAppKey(config, request);

    if (appId == null) {
        resultHandler.handle(FAIL_PROVIDE_APP_ID);
        return this;
    }

    if (appKey == null) {
        resultHandler.handle(FAIL_PROVIDE_APP_KEY);
        return this;
    }

    if (!Auth3ScaleUtils.hasRoutes(config, request)) {
        resultHandler.handle(FAIL_NO_ROUTE);
        return this;
    }

    AppIdReportData report = new AppIdReportData()
            .setAppId(appId)
            .setAppKey(appKey)
            .setServiceToken(config.getBackendAuthenticationValue())
            .setServiceId(Long.toString(config.getProxy().getServiceId()))
            .setUsage(Auth3ScaleUtils.buildRepMetrics(config, request))
            .setReferrer(request.getHeaders().get(REFERRER))
            .setUserId(request.getHeaders().get(USER_ID));

    auth.setKeyElems(appId, appKey);
    auth.setReport(report);
    auth.policyFailureHandler(policyFailureHandler::handle);
    auth.auth(resultHandler);
    return this;
}
 
開發者ID:apiman,項目名稱:apiman-plugins,代碼行數:36,代碼來源:AppIdAuth.java

示例14: auth

import io.apiman.gateway.engine.async.IAsyncResultHandler; //導入方法依賴的package包/類
@Override
public AuthPrincipal auth(IAsyncResultHandler<Void> resultHandler) {
  String userKey = getUserKey();
  if (userKey == null) {
      resultHandler.handle(FAIL_PROVIDE_USER_KEY);
      return this;
  }

  if (!hasRoutes(config, request)) {
      resultHandler.handle(FAIL_NO_ROUTE);
      return this;
  }

  String serviceId = Long.toString(config.getProxy().getServiceId());
  ApiKeyReportData data = new ApiKeyReportData()
          .setUserKey(userKey)
          .setServiceToken(config.getBackendAuthenticationValue())
          .setServiceId(serviceId)
          .setUsage(buildRepMetrics(config, request))
          .setReferrer(request.getHeaders().get(REFERRER))
          .setUserId(request.getHeaders().get(USER_ID));

  auth.setKeyElems(userKey);
  auth.setReport(data);
  auth.policyFailureHandler(policyFailureHandler::handle);
  auth.auth(resultHandler);
  return this;
}
 
開發者ID:apiman,項目名稱:apiman-plugins,代碼行數:29,代碼來源:ApiKeyAuth.java

示例15: retireApi

import io.apiman.gateway.engine.async.IAsyncResultHandler; //導入方法依賴的package包/類
/**
 * @see io.apiman.gateway.engine.CachingJdbcRegistry.CachingESRegistry#retireApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@Override
public void retireApi(Api api, final IAsyncResultHandler<Void> handler) {
    super.retireApi(api, new IAsyncResultHandler<Void>() {
        @Override
        public void handle(IAsyncResult<Void> result) {
            if (result.isSuccess()) {
                updateDataVersion();
            }
            handler.handle(result);
        }
    });
}
 
開發者ID:apiman,項目名稱:apiman,代碼行數:16,代碼來源:PollCachingJdbcRegistry.java


注:本文中的io.apiman.gateway.engine.async.IAsyncResultHandler.handle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。