use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.
the class DefaultRedisSessionManager method postConstruct.
@PostConstruct
public void postConstruct() {
int corePoolSize = 30 * OsUtils.getCpuCount();
int maxPoolSize = 512;
DefaultExecutorFactory executorFactory = new DefaultExecutorFactory("RedisSession", corePoolSize, maxPoolSize, new ThreadPoolExecutor.AbortPolicy());
executors = executorFactory.createExecutorService();
int fixedPoolSize = OsUtils.getCpuCount();
pingAndDelayExecutor = new DefaultExecutorFactory("Ping-Delay-Executor", fixedPoolSize, fixedPoolSize, new ThreadPoolExecutor.CallerRunsPolicy()).createExecutorService();
scheduled.scheduleAtFixedRate(new AbstractExceptionLogTask() {
@Override
protected void doRun() throws Exception {
try {
removeUnusedRedises();
} catch (Exception e) {
logger.error("[removeUnusedRedises]", e);
}
for (RedisSession redisSession : sessions.values()) {
try {
redisSession.check();
} catch (Exception e) {
logger.error("[check]" + redisSession, e);
}
}
}
}, 5, 5, TimeUnit.SECONDS);
}
use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.
the class AbstractNewMasterChooser method getMasters.
protected Pair<List<RedisMeta>, List<RedisMeta>> getMasters(List<RedisMeta> allRedises) {
List<RedisMeta> masters = new LinkedList<>();
List<RedisMeta> tmpAliveServers = new LinkedList<>();
CountDownLatch latch = new CountDownLatch(allRedises.size());
for (RedisMeta redisMeta : allRedises) {
executors.execute(new AbstractExceptionLogTask() {
@Override
protected void doRun() throws Exception {
try {
SERVER_ROLE role = serverRole(redisMeta);
if (role == SERVER_ROLE.MASTER) {
synchronized (masters) {
masters.add(redisMeta);
}
}
if (role != SERVER_ROLE.UNKNOWN) {
synchronized (tmpAliveServers) {
tmpAliveServers.add(redisMeta);
}
}
} finally {
latch.countDown();
}
}
});
}
try {
latch.await(CHECK_NEW_MASTER_TIMEOUT_SECONDS * 2, TimeUnit.SECONDS);
} catch (InterruptedException e) {
logger.error("[getMasters]" + allRedises, e);
}
List<RedisMeta> aliveServers = sortAccording(allRedises, tmpAliveServers);
return new Pair<>(masters, aliveServers);
}
use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.
the class AbstractMigrationMigratingState method doMigrateOtherDc.
protected void doMigrateOtherDc() {
logger.debug("[doMigrateOtherDc]{}", this);
MigrationCluster migrationCluster = getHolder();
String clusterName = migrationCluster.clusterName();
for (MigrationShard migrationShard : migrationCluster.getMigrationShards()) {
executors.execute(new AbstractExceptionLogTask() {
@Override
public void doRun() {
String shardName = migrationShard.shardName();
logger.info("[doOtherDcMigrate][start]{},{}", clusterName, shardName);
migrationShard.doMigrateOtherDc();
logger.info("[doOtherDcMigrate][done]{},{}", clusterName, shardName);
}
});
}
}
use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.
the class ReferenceFileChannelTest method testConcurrentRead.
@Test
public void testConcurrentRead() throws InterruptedException, IOException {
int concurrentCount = 10;
final LinkedBlockingQueue<ReferenceFileRegion> fileRegions = new LinkedBlockingQueue<>();
final CountDownLatch latch = new CountDownLatch(concurrentCount);
for (int i = 0; i < concurrentCount; i++) {
executors.execute(new AbstractExceptionLogTask() {
private int count = 0;
@Override
protected void doRun() throws Exception {
try {
while (true) {
count++;
ReferenceFileRegion referenceFileRegion = referenceFileChannel.readTilEnd(1);
fileRegions.offer(referenceFileRegion);
if (count > totalFileLen) {
logger.info("{}", referenceFileRegion);
}
if (referenceFileRegion.count() == 0) {
break;
}
if (referenceFileRegion.count() < 0) {
logger.error("{}", referenceFileRegion);
}
}
} finally {
latch.countDown();
}
}
});
}
latch.await();
referenceFileChannel.close();
Assert.assertFalse(referenceFileChannel.isFileChannelClosed());
long realTotalLen = 0;
Set<Long> starts = new HashSet<>();
while (true) {
ReferenceFileRegion referenceFileRegion = fileRegions.poll(100, TimeUnit.MILLISECONDS);
if (referenceFileRegion == null) {
break;
}
if (referenceFileRegion.position() != totalFileLen) {
Assert.assertTrue(starts.add(referenceFileRegion.position()));
}
realTotalLen += referenceFileRegion.count();
referenceFileRegion.release();
}
Assert.assertEquals(totalFileLen, realTotalLen);
Assert.assertTrue(referenceFileChannel.isFileChannelClosed());
}
use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.
the class DefaultRedisConfManager method postConstruct.
@PostConstruct
public void postConstruct() {
int initialDelay = 5;
int period = 1;
scheduled.scheduleAtFixedRate(new AbstractExceptionLogTask() {
@Override
protected void doRun() {
String eventType = "Redis.Server.Version";
try {
for (ConcurrentMap.Entry entry : configs.entrySet()) {
CatEventMonitor.DEFAULT.logEvent(eventType, entry.getValue().toString());
}
logger.debug("Current Redis Conf Manager Cache:\n {}", this.toString());
} catch (Exception e) {
logger.error("[postConstruct]{}", e);
}
}
}, initialDelay, period, TimeUnit.MINUTES);
}
Aggregations