Ошибка при подготовке запросов для доступа в Кассандре - PullRequest
0 голосов
/ 27 ноября 2018

В проекте lagom я пытаюсь использовать Средства доступа Но я получаю сообщение об ошибке.

java.util.concurrent.CompletionException: java.lang.RuntimeException: Ошибка при подготовке запросов для средства доступа TestAccessor в java.util.concurrent.CompletableFuture.encodeThrowable (CompletableFuture.java:273) в java.util.concurrent.CompletableFuture.uniComposeStage (CompletableFuture.java:u1. at).concurrent.CompletableFuture.thenCompose (CompletableFuture.java:2124) в java.util.concurrent.CompletableFuture.thenCompose (CompletableFuture.java:110) в org.test.impl.persist.CassandraRepository.getAll (Cassandra:pository).test.impl.workers.Worker.lambda $ testMessage $ 2 (Worker.java:91) в java.util.concurrent.CompletableFuture.uniCompose (CompletableFuture.java:952) в java.util.concurrent.CompletableFuture $ UniCompose.Fire $CompletableFuture.java:926) в java.util.concurrent.CompletableFuture.postComplete (CompletableFuture.java:474) в java.util.concurrent.CompletableFuture.complete (CompletableFuture.java:1962) на com.spotify.futures.ListenableToCompletableFutureWrapper.onSuccess (ListenableToCompletableFutureWrapper.java:49) на com.google.common.util.concurrent.Futures $ CallbackListener.unна com.google.common.util.concurrent.MoreExecutors $ DirectExecutor.execute (MoreExecutors.java:399) на com.google.common.util.concurrent.AbstractFuture.executeListener (AbstractFuture.java:911) на com.google.common.util.concurrent.AbstractFuture.complete (AbstractFuture.java:822) на com.google.common.util.concurrent.AbstractFuture.set (AbstractFuture.java:664) на com.google.common.util.concurrent.AbstractTransformFuture $ TransformFuture $.setResult (AbstractTransformFuture.java:245) на com.google.common.util.concurrent.AbstractTransformFuture.run (AbstractTransformFuture.java:177) на com.google.common.util.concurrent.MoreExecutors $ DirectExecutor.execute (MoreExecutors.java: 399) на com.google.common.util.concurrent.AbstractFuture.executeListener (AbstractFuture.java:911) на com.google.common.util.concurrent.AbstractFuture.complete (AbstractFuture.java:822) на com.google.common.util.concurrent.AbstractFuture.set (AbstractFuture.java:664) на com.datastax.driver.core.DefaultResultSetFuture.onSet (DefaultResultSetFuture.java:174) в com.datastax.driver.core.RequestHandler.setFinalResult (RequestHandler.java:198) в com.datastax.driver.coreRequestHandler.java:50) в com.datastax.driver.core.RequestHandler $ SpeculativeExecution.setFinalResult (RequestHandler.java:852) в com.datastax.driver.core.RequestHandler $ SpeculativeExecution.onSet (RequestHand6) comava.datastax.driver.core.Connection $ Dispatcher.channelRead0 (Connection.java:1087) в com.datastax.driver.core.Connection $ Dispatcher.channelRead0 (Connection.java:1010) в io.netty.channel.SimpleChannelInboundHandler.chan(SimpleChannelInboundHandler.java:105) в io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead (AbstractChannelHandlerContext.java:362) по адресу io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead (AbstractChannelHandlerContext.java:348) по адресу io.netty.channel.AbstractChannelHandlerContext.fireChannelRead (AbstractChannelHand..channelRead (IdleStateHandler.java:286) по адресу io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead (AbstractChannelHandlerContext.java:362) по адресу io.netty.channel.AbstractChannelHandlerContext.invoj.net.chan.chanAbstractChannelHandlerContext.fireChannelRead (AbstractChannelHandlerContext.java:340) в io.netty.handler.codec.MessageToMessageDecoder.channelRead (MessageToMessageDecoder.java:102)по адресу io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead (AbstractChannelHandlerContext.java:362) по адресу io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead (AbstractChannelHandlerContext.jnelj.netThanHhanThanThanChantehanChannel) по адресу io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead (ByteToMessageDecoder.java:310) по адресу io.netty.handler.codec.ByteToMessageDecoder.channelRead (ByteToMessageDecoder.jnel.ehan.ChaneCityChineTech) 28AbstractChannelHandlerContext.java:362) по адресу io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead (AbstractChannelHandlerContext.java:348) по адресу io.netty.channel.AbstractChannelHandlerContext.fireChannelReandInhanhanChannelHanChannelHan)(ChannelInboundHandlerAdapter.java:86) в com.datastax.driver.core.InboundTrafficMeter.channelRead (InboundTrafficMeter.java:38) по адресу io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead (AbstractChannelHandlerContext.java:362) по адресу io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead (AbstractChannel.HannelHandConHannelHandConHannelHandlerHandlerAh(AbstractChannelHandlerContext.java:340) по адресу io.netty.channel.DefaultChannelPipeline $ HeadContext.channelRead (DefaultChannelPipeline.java:1434) по адресу io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead (AbstractChannel.and) ato.hannelHan) athAbstractChannelHandlerContext.invokeChannelRead (AbstractChannelHandlerContext.java:348) по адресу io.netty.channel.DefaultChannelPipeline.fireChannelRead (DefaultChannelPipeline.java:965) по адресу io.netty.channel.nio.AbstractNneljioNioBioByNioBio.netty.channel.nio.NioEventLoop.processSelectedKey (NioEventLoop.java:647) в io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized (NioEventLoop.java:582) на io.netty.channel.nio.NioEventLoop.processSelectedKeys (NioEventLoop.java:499) на io.netty.channel.nio.NioEventLoop.run (NioEventLoop.java:461) на io.netty.util.concurrent.SingleThreadEventExecutor $ 5.run (SingleThreadEventExecutor.java:884) в io.netty.util.concurrent.FastThreadLocalRunnable.run (FastThreadLocalRunnable.java:30) в java.lang.Thread.run (Thread.java: 7): java.lang.RuntimeException: Ошибка при подготовке запросов для аксессора TestAccessor в com.datastax.driver.mapping.AccessorMapper.prepare (AccessorMapper.java:61) в com.datastax.driver.mapping.MappingManager.getAccessor (MappingManager.java:) на com.datastax.driver.mapping.MappingManager.createAccessor (MappingManager.java:297) на org.test.impl.persist.CassandraRepository.lambda $ getAll $ 5 (CassandraRepository.java:99) на java.util.pletableFuture.uniComposeStage (CompletableFuture.java:981) ... пропущено 61 общее число кадров. Причина: java.util.concurrent.ExecutionException: com.datastax.driver.core.exceptions.OperationTimedOutException: [localhost / 127.0.0.1: 9042] Истекло время ожидания ответа сервера на com.google.common.util.concurrent.AbstractFuture.getDoneValue (AbstractFuture.java:503) на com.google.common.util.concurrent.AbstractFuture.get (AbstractFuture.java:482) на com.google.common.util.concurrent.AbstractFuture $ TrustedFuture.get (AbstractFuture.java:79) на com.datastax.driver.mapping.AccessorMapper.prepare (AccessorMapper.java: 57) ... пропущено 65 общих кадров. Причина: com.datastax.driver.core.exceptions.OperationTimedOutException: [localhost / 127.0.0.1: 9042] Истекло время ожидания ответа сервера в com.datastax.driver.core.RequestHandler $ SpeculativeExecution.onTimeout (RequestHandler.java:825)в com.datastax.driver.core.Connection $ ResponseHandler $ 1.run (Connection.java:1392) в io.netty.util.HashedWheelTimer $ HashedWheelTimeout.expire (HashedWheelTimer.java:668) в io.netty.util.HasWhe $HashedWheelBucket.expireTimeouts (HashedWheelTimer.java:743) в io.netty.util.HashedWheelTimer $ Worker.run (HashedWheelTimer.java:471) ... 2 общих кадра опущено

Аксессор

@Accessor
public interface TestAccessor {
    @Query("SELECT * FROM test_table")
    Result<TestTable> getAll();
}

Использование

TestAccessor acc = mappingManager.createAccessor(TestAccessor.class);
Result<TestTable> channels = acc.getAll();

Предоставление сеанса и сопоставления.

public class Module extends AbstractModule implements ServiceGuiceSupport, AkkaGuiceSupport {
    private static CompletableFuture<Void> codecRegistrationPromise = new CompletableFuture<>();

    @Override
    protected void configure() {
        bindService(TestService.class, TestServiceImpl.class);
    }

    @Provides
    @Singleton
    public CompletionStage<MappingManager> provideMappingManager(CompletionStage<Session> session) {
        return session.thenApply(MappingManager::new));
    }

    @Provides
    public CompletionStage<Cluster> provideCassandraCluster(CompletionStage<Session> session) {
        return session.thenApply(Session::getCluster);
    }

    @Provides
    @Singleton
    public CompletionStage<Session> provideCassandraSession(CassandraSession sessionWrapper) {
        CompletableFuture<Session> future = new CompletableFuture<>();
        completeWithSession(sessionWrapper, future);
        return future;
    }

    private void completeWithSession(CassandraSession sessionWrapper, CompletableFuture<Session> future) {
        sessionWrapper.underlying().whenComplete((session, throwable) -> {
            if (throwable != null) {
                if (throwable instanceof NoServiceLocatorException) {
                    log.error("Failed to obtain Cassandra session, try again", throwable);
                    completeWithSession(sessionWrapper, future);
                } else {
                    log.error("Failed to obtain Cassandra session", throwable);
                    future.completeExceptionally(throwable);
                }
            } else {
                log.info("Cassandra session obtained");
                future.complete(session);
            }
        });
    }
}

Использование в каком-либо классе

@Inject
    public CassandraRepository(CompletionStage<MappingManager> mappingManagerPromise, ActorSystem system) {
        this.mappingManagerPromise = mappingManagerPromise;
        this.system = system;
    }



    mappingManagerPromise.thenApply(mappingManager -> {
                    TestAccessor acc = mappingManager.createAccessor(TestAccessor.class);
Result<TestTable> channels = acc.getAll();
                })

Если я использую mapper.getAsyncвсе хорошо.

Mapper<TestTable> mapper = mappingManager.mapper(TestTable.class);
            return toCompletableFuture(mapper.getAsync(id));
...