当前位置: 首页>>代码示例>>Java>>正文


Java IAsyncHandler类代码示例

本文整理汇总了Java中io.apiman.gateway.engine.async.IAsyncHandler的典型用法代码示例。如果您正苦于以下问题:Java IAsyncHandler类的具体用法?Java IAsyncHandler怎么用?Java IAsyncHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IAsyncHandler类属于io.apiman.gateway.engine.async包,在下文中一共展示了IAsyncHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: changeResponseWhenCallbackParamNameIsSavedInContext

import io.apiman.gateway.engine.async.IAsyncHandler; //导入依赖的package包/类
@Test
public void changeResponseWhenCallbackParamNameIsSavedInContext() throws Exception {
    JsonpConfigBean config = new JsonpConfigBean();

    // given
    String functionName = "testFunction";
    sContext.setAttribute(JsonpPolicy.CALLBACK_FUNCTION_NAME, functionName);
    ApiResponse response = new ApiResponse();
    String json = "{\"name\": \"test\"}";
    IApimanBuffer chunk = new ByteBuffer(json.getBytes().length);
    chunk.append(json);
    IAsyncHandler<IApimanBuffer> bodyHandler = mock(IAsyncHandler.class);
    // when
    IReadWriteStream<ApiResponse> responseDataHandler = jsonpPolicy.getResponseDataHandler(response, sContext, config);
    ApiResponse head = responseDataHandler.getHead();
    responseDataHandler.bodyHandler(bodyHandler);
    responseDataHandler.write(chunk);
    responseDataHandler.end();
    // then
    assertSame(response, head);

    verify(bodyHandler).handle(refEq(new ByteBuffer("testFunction(")));
    verify(bodyHandler).handle(refEq(new ByteBuffer(json)));
    verify(bodyHandler).handle(refEq(new ByteBuffer(")")));
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:26,代码来源:JsonpPolicyTest.java

示例2: setPeriodicTimer

import io.apiman.gateway.engine.async.IAsyncHandler; //导入依赖的package包/类
/**
 * @see io.apiman.gateway.engine.components.IPeriodicComponent#setPeriodicTimer(long, long,
 *      io.apiman.gateway.engine.async.IAsyncHandler)
 */
@Override
public long setPeriodicTimer(long periodMillis, long initialDelayMillis,
        final IAsyncHandler<Long> periodicHandler) {
    final long timerId = id.incrementAndGet();

    TimerTask task = new TimerTask() {

        @Override
        public void run() {
            periodicHandler.handle(timerId);
        }
    };
    // Keep reference to TimerTask and Timer ID we hand back (to cancel later).
    timerTaskMap.put(timerId, task);
    // Task, delay, frequency
    timer.schedule(task, initialDelayMillis, periodMillis);
    return timerId;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:23,代码来源:PeriodicComponentImpl.java

示例3: setOneshotTimer

import io.apiman.gateway.engine.async.IAsyncHandler; //导入依赖的package包/类
/**
 * @see io.apiman.gateway.engine.components.IPeriodicComponent#setOneshotTimer(long,
 *      io.apiman.gateway.engine.async.IAsyncHandler)
 */
@Override
public long setOneshotTimer(long deltaMillis, final IAsyncHandler<Long> timerHandler) {
    final long timerId = id.incrementAndGet();

    TimerTask task = new TimerTask() {

        @Override
        public void run() {
            timerHandler.handle(timerId);
        }
    };
    // Keep reference to TimerTask and Timer ID we hand back (to cancel later).
    timerTaskMap.put(timerId, task);
    // Task, delay, frequency
    timer.schedule(task, deltaMillis);
    return timerId;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:22,代码来源:PeriodicComponentImpl.java

示例4: setPeriodicTimer

import io.apiman.gateway.engine.async.IAsyncHandler; //导入依赖的package包/类
/**
 * @see io.apiman.gateway.engine.components.IPeriodicComponent#setPeriodicTimer(long, long,
 *      io.apiman.gateway.engine.async.IAsyncHandler)
 */
@Override
public long setPeriodicTimer(final long periodMillis, final long initialDelayMillis,
        final IAsyncHandler<Long> periodicHandler) {
    // Make our own ID to cope with initial delay feature not being present in vert.x's timers.
    final long timerId = id++;

    // Do the initial delay, then map the next timer back to our ID.
    long vertxId = vertx.setTimer(initialDelayMillis, (Handler<Long>) tid -> {

        long newVertxId = vertx.setPeriodic(periodMillis,  (Handler<Long>) tid2 -> {
            periodicHandler.handle(timerId);
        });

        // Periodic delay - re-map to the new Vert.x timer ID, as original timer ID is now invalid.
        // Vert.x. is single-threaded per-verticle so this should be safe.
        timerMap.put(timerId, newVertxId);
    });

    timerMap.put(timerId, vertxId);
    return timerId;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:26,代码来源:PeriodicComponentImpl.java

示例5: write

import io.apiman.gateway.engine.async.IAsyncHandler; //导入依赖的package包/类
/**
 * Simple write to "/write". Must be valid Influx line format.
 *
 * @param lineDocument document to write, as string
 * @param failureHandler handler in case of failure
 */
public void write(String lineDocument,
        final IAsyncHandler<InfluxException> failureHandler) {
    // Make request to influx
    IHttpClientRequest request = httpClient.request(writeUrl.toString(), HttpMethod.POST,
            result -> {
                if (result.isError() || result.getResult().getResponseCode() < 200
                        || result.getResult().getResponseCode() > 299) {
                    failureHandler.handle(new InfluxException(result.getResult()));
                }
            });
    // For some reason Java's URLEncoding doesn't seem to be parseable by influx?
    //request.addHeader("Content-Type", "application/x-www-form-urlencoded");
    request.addHeader("Content-Type", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$
    request.write(lineDocument, StandardCharsets.UTF_8.name());
    request.end();
}
 
开发者ID:apiman,项目名称:apiman,代码行数:23,代码来源:InfluxDb09Driver.java

示例6: setup

import io.apiman.gateway.engine.async.IAsyncHandler; //导入依赖的package包/类
@Before
public void setup() {
    Policy policyBean = mock(Policy.class);
    given(policyBean.getPolicyImpl()).willReturn(PassthroughPolicy.QUALIFIED_NAME);
    given(policyBean.getPolicyJsonConfig()).willReturn("{}");

    mockBufferInbound = mock(IApimanBuffer.class);
    given(mockBufferInbound.toString()).willReturn("stottie");

    mockBufferOutbound = mock(IApimanBuffer.class);
    given(mockBufferOutbound.toString()).willReturn("bacon");

    policyList = new ArrayList<>();
    policyList.add(policyBean);

    mockBodyHandler = mock(IAsyncHandler.class);
    mockEndHandler = mock(IAsyncHandler.class);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:19,代码来源:DefaultEngineFactoryTest.java

示例7: shouldCallFailureHandlerOnDoFail

import io.apiman.gateway.engine.async.IAsyncHandler; //导入依赖的package包/类
@Test
public void shouldCallFailureHandlerOnDoFail() {
    policies.add(pwcOne);
    policies.add(pwcTwo);

    requestChain = new RequestChain(policies, mockContext);

    IAsyncHandler<PolicyFailure> mPolicyFailureHandler = mock(IAsyncHandler.class);

    PolicyFailure mPolicyFailure = mock(PolicyFailure.class);

    requestChain.policyFailureHandler(mPolicyFailureHandler);
    requestChain.bodyHandler(mockBodyHandler);
    requestChain.endHandler(mockEndHandler);

    requestChain.doApply(mockRequest);
    requestChain.doFailure(mPolicyFailure);

    verify(mPolicyFailureHandler).handle(mPolicyFailure);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:21,代码来源:PolicyChainTest.java

示例8: shouldCallErrorHandlerOnThrowError

import io.apiman.gateway.engine.async.IAsyncHandler; //导入依赖的package包/类
@Test
public void shouldCallErrorHandlerOnThrowError() {
    policies.add(pwcOne);
    policies.add(pwcTwo);

    requestChain = new RequestChain(policies, mockContext);

    IAsyncHandler<Throwable> mThrowableFailureHandler = mock(IAsyncHandler.class);

    Throwable mThrowable = mock(Throwable.class);

    requestChain.policyErrorHandler(mThrowableFailureHandler);
    requestChain.bodyHandler(mockBodyHandler);
    requestChain.endHandler(mockEndHandler);

    requestChain.doApply(mockRequest);
    requestChain.throwError(mThrowable);

    verify(mThrowableFailureHandler).handle(mThrowable);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:21,代码来源:PolicyChainTest.java

示例9: reloadData

import io.apiman.gateway.engine.async.IAsyncHandler; //导入依赖的package包/类
public static void reloadData(IAsyncHandler<Void> doneHandler) {
    synchronized(URILoadingRegistry.class) {
        if (instance == null) {
            doneHandler.handle((Void) null);
            return;
        }
        Map<URILoadingRegistry, IAsyncResultHandler<Void>> regs = instance.handlers;
        Vertx vertx = instance.vertx;
        URI uri = instance.uri;
        Map<String, String> config = instance.config;
        AtomicInteger ctr = new AtomicInteger(regs.size());
        OneShotURILoader newLoader = new OneShotURILoader(vertx, uri, config);

        regs.entrySet().stream().forEach(pair -> {
            // Clear the registrys' internal maps to prepare for reload.
            // NB: If we add production hot reloading, we'll need to work around this (e.g. clone?).
            pair.getKey().getMap().clear();
            // Re-subscribe the registry.
            newLoader.subscribe(pair.getKey(), result -> {
                checkAndFlip(ctr.decrementAndGet(), newLoader, doneHandler);
            });
        });
        checkAndFlip(ctr.get(), newLoader, doneHandler);
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:26,代码来源:URILoadingRegistry.java

示例10: setOneshotTimer

import io.apiman.gateway.engine.async.IAsyncHandler; //导入依赖的package包/类
/**
 * @see io.apiman.gateway.engine.components.IPeriodicComponent#setOneshotTimer(long,
 *      io.apiman.gateway.engine.async.IAsyncHandler)
 */
@Override
public long setOneshotTimer(long deltaMillis, final IAsyncHandler<Long> timerHandler) {
    final long timerId = id++;

    long vertxTimerId = vertx.setTimer(deltaMillis, (Handler<Long>) tid -> {
        timerHandler.handle(timerId);
    });

    timerMap.put(timerId, vertxTimerId);
    return timerId;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:16,代码来源:PeriodicComponentImpl.java

示例11: executeBlocking

import io.apiman.gateway.engine.async.IAsyncHandler; //导入依赖的package包/类
@Override
public <T> void executeBlocking(IAsyncHandler<IAsyncFuture<T>> blockingCode, IAsyncResultHandler<T> resultHandler) {
    vertx.<T>executeBlocking(future -> {
        blockingCode.handle(wrapFuture(future));
    }, result -> {
        resultHandler.handle(wrapResult(result));
    });
}
 
开发者ID:apiman,项目名称:apiman,代码行数:9,代码来源:ExecuteBlockingComponentImpl.java

示例12: reload

import io.apiman.gateway.engine.async.IAsyncHandler; //导入依赖的package包/类
public synchronized void reload(IAsyncHandler<Void> reloadHandler) {
    this.reloadHandler = reloadHandler;
    awaiting.addAll(allRegistries);
    apis.clear();
    clients.clear();
    failureHandlers.clear();
    allRegistries.stream()
        .map(ThreeScaleImmutableRegistry::getMap)
        .forEach(Map::clear);
    dataProcessed = false;
    // Load again from scratch.
    fetchResource();
}
 
开发者ID:apiman,项目名称:apiman,代码行数:14,代码来源:ThreeScaleImmutableRegistry.java

示例13: bind

import io.apiman.gateway.engine.async.IAsyncHandler; //导入依赖的package包/类
private void bind(final LDAPIdentitySource config, final LdapConfigBean ldapConfigBean, final ILdapComponent ldapComponent,
        final IPolicyContext context, final IAsyncResultHandler<ILdapResult> handler) {
    // If no role extraction is needed, just do a fast and simple BIND & exit
    if (!config.isExtractRoles()) {
        ldapComponent.bind(ldapConfigBean, handler);
    } else { // Otherwise open up longer-lived connection and query role info.
        ldapComponent.connect(ldapConfigBean, successHandler(handler, new IAsyncHandler<ILdapClientConnection>() {
            @Override // Extract the roles.
            public void handle(final ILdapClientConnection connection) {
                extractRoles(connection, ldapConfigBean.getBindDn(), config, context, handler);
            }
        }));
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:15,代码来源:LDAPIdentityValidator.java

示例14: createRequestChain

import io.apiman.gateway.engine.async.IAsyncHandler; //导入依赖的package包/类
/**
 * Creates the chain used to apply policies in order to the api request.
 */
private Chain<ApiRequest> createRequestChain(IAsyncHandler<ApiRequest> requestHandler) {
    RequestChain chain = new RequestChain(policyImpls, context);
    chain.headHandler(requestHandler);
    chain.policyFailureHandler(policyFailureHandler);
    chain.policyErrorHandler(policyErrorHandler);
    return chain;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:11,代码来源:ApiRequestExecutorImpl.java

示例15: createResponseChain

import io.apiman.gateway.engine.async.IAsyncHandler; //导入依赖的package包/类
/**
 * Creates the chain used to apply policies in reverse order to the api response.
 */
private Chain<ApiResponse> createResponseChain(IAsyncHandler<ApiResponse> responseHandler) {
    ResponseChain chain = new ResponseChain(policyImpls, context);
    chain.headHandler(responseHandler);
    chain.policyFailureHandler(result -> {
        apiConnectionResponse.abort();
        policyFailureHandler.handle(result);
    });
    chain.policyErrorHandler(result -> {
        apiConnectionResponse.abort();
        policyErrorHandler.handle(result);
    });
    return chain;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:17,代码来源:ApiRequestExecutorImpl.java


注:本文中的io.apiman.gateway.engine.async.IAsyncHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。