本文整理汇总了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));
}
}
示例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;
}
示例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;
}
示例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);
};
}
示例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));
}
}
示例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$
}
}
示例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));
}
}
示例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);
}
}
示例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));
}
}
示例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));
}
}
示例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));
}
}
示例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));
}
}
示例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;
}
示例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;
}
示例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);
}
});
}