Search in sources :

Example 31 with AbstractExceptionLogTask

use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.

the class AbstractRedisMasterReplication method checkTimeout.

private void checkTimeout(final Channel channel) {
    logger.info("[checkTimeout]{} ms, {}", replTimeoutMilli, ChannelUtil.getDesc(channel));
    final ScheduledFuture<?> repliTimeoutCheckFuture = scheduled.scheduleAtFixedRate(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            long current = System.currentTimeMillis();
            if ((current - repl_transfer_lastio) >= replTimeoutMilli) {
                logger.info("[doRun][no action with master for a long time, close connection]{}, {}", channel, AbstractRedisMasterReplication.this);
                channel.close();
            }
        }
    }, replTimeoutMilli, replTimeoutMilli, TimeUnit.MILLISECONDS);
    channel.closeFuture().addListener(new ChannelFutureListener() {

        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            logger.info("[cancelTimeout]{}ms, {}", replTimeoutMilli, channel);
            repliTimeoutCheckFuture.cancel(true);
        }
    });
}
Also used : AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) IOException(java.io.IOException) XpipeException(com.ctrip.xpipe.exception.XpipeException)

Example 32 with AbstractExceptionLogTask

use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.

the class DefaultRedisSlave method close.

public void close() throws IOException {
    logger.info("[close]{}", this);
    if (closeState.isClosed()) {
        logger.info("[close][already closed]{}", this);
        return;
    }
    closeState.setClosing();
    psyncProcessed.addListener(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            doRealClose();
        }
    }, MoreExecutors.directExecutor());
    if (closeState.isClosing()) {
        scheduled.schedule(new AbstractExceptionLogTask() {

            @Override
            protected void doRun() throws Exception {
                logger.info("[wait for psync processed timeout close slave]{}", DefaultRedisSlave.this);
                doRealClose();
            }
        }, waitForPsyncProcessedTimeoutMilli, TimeUnit.MILLISECONDS);
    }
}
Also used : AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) IOException(java.io.IOException) RedisKeeperRuntimeException(com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException)

Example 33 with AbstractExceptionLogTask

use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.

the class ScheduleCommandWrapper method doExecute.

@Override
protected void doExecute() throws Exception {
    final ScheduledFuture<?> scheduleFuture = scheduled.schedule(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            try {
                command.execute().addListener(new CommandFutureListener<V>() {

                    @Override
                    public void operationComplete(CommandFuture<V> commandFuture) throws Exception {
                        if (commandFuture.isSuccess()) {
                            future().setSuccess(commandFuture.get());
                        } else {
                            future().setFailure(ExceptionUtils.getRootCause(commandFuture.cause()));
                        }
                    }
                });
            } catch (Exception e) {
                future().setFailure(ExceptionUtils.getRootCause(e));
            }
        }
    }, time, timeUnit);
    future().addListener(new CommandFutureListener<V>() {

        @Override
        public void operationComplete(CommandFuture<V> commandFuture) throws Exception {
            if (commandFuture.isCancelled()) {
                logger.info("[command canceled][cancel execution]{}", time);
                command.future().cancel(true);
                scheduleFuture.cancel(false);
            }
        }
    });
}
Also used : CommandFuture(com.ctrip.xpipe.api.command.CommandFuture) CommandFutureListener(com.ctrip.xpipe.api.command.CommandFutureListener) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)

Example 34 with AbstractExceptionLogTask

use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.

the class AlertManager method postConstruct.

@PostConstruct
public void postConstruct() {
    scheduled.scheduleWithFixedDelay(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            alertClusterWhiteList = consoleConfig.getAlertWhileList();
        }
    }, 0, 30, TimeUnit.SECONDS);
    scheduled.scheduleWithFixedDelay(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            logger.info("[clusterCreateTimeMapper][execute]");
            List<ClusterTbl> clusterTbls = clusterService.findAllClustersWithOrgInfo();
            for (ClusterTbl clusterTbl : clusterTbls) {
                clusterCreateTime.put(clusterTbl.getClusterName(), clusterTbl.getCreateTime());
            }
        }
    }, 1, 60, TimeUnit.MINUTES);
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) PostConstruct(javax.annotation.PostConstruct)

Example 35 with AbstractExceptionLogTask

use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.

the class AbstractIntervalCheck method postConstruct.

@PostConstruct
public void postConstruct() {
    logger.info("[postConstruct]{}", this);
    scheduled.scheduleAtFixedRate(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            checkStart();
        }
    }, 1, 1, TimeUnit.SECONDS);
}
Also used : AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) PostConstruct(javax.annotation.PostConstruct)

Aggregations

AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)46 IOException (java.io.IOException)19 Test (org.junit.Test)18 CountDownLatch (java.util.concurrent.CountDownLatch)9 PostConstruct (javax.annotation.PostConstruct)9 ExecutionException (java.util.concurrent.ExecutionException)8 AbstractRedisKeeperTest (com.ctrip.xpipe.redis.keeper.AbstractRedisKeeperTest)6 AbstractTest (com.ctrip.xpipe.AbstractTest)5 MigrationShard (com.ctrip.xpipe.redis.console.migration.model.MigrationShard)5 LinkedList (java.util.LinkedList)5 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)3 FileChannel (java.nio.channels.FileChannel)3 Semaphore (java.util.concurrent.Semaphore)3 TimeoutException (java.util.concurrent.TimeoutException)3 ReferenceFileRegion (com.ctrip.xpipe.netty.filechannel.ReferenceFileRegion)2 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)2 RedisKeeperRuntimeException (com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException)2 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)2 Server (com.ctrip.xpipe.simpleserver.Server)2 List (java.util.List)2