use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.
the class OneDcKeepers method sendMessageForever.
@Test
public void sendMessageForever() throws IOException {
executors.execute(new AbstractExceptionLogTask() {
@Override
protected void doRun() throws Exception {
while (!Thread.interrupted()) {
sendMessageToMaster();
}
}
});
waitForAnyKeyToExit();
}
use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.
the class PubSubMode method startProducerJob.
@Override
protected void startProducerJob() {
super.startProducerJob();
scheduled.scheduleAtFixedRate(new AbstractExceptionLogTask() {
@Override
protected void doRun() throws Exception {
try (Jedis resource = masterPool.getResource()) {
long currentNanos = System.nanoTime();
String currentNanosStr = String.valueOf(currentNanos);
logger.debug("[publish]{}", currentNanosStr);
resource.publish(pubChannel, currentNanosStr);
}
}
}, pubIntervalMilli, pubIntervalMilli, TimeUnit.MILLISECONDS);
}
use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.
the class DefaultCommandStoreTest method testLengthEqual.
@Test
public void testLengthEqual() throws InterruptedException {
final int runTimes = 1000;
final AtomicLong realLength = new AtomicLong();
final AtomicReference<Boolean> result = new AtomicReference<Boolean>(true);
final Semaphore read = new Semaphore(0);
final Semaphore write = new Semaphore(1);
final AtomicBoolean finished = new AtomicBoolean(false);
final CountDownLatch latch = new CountDownLatch(2);
executors.execute(new AbstractExceptionLogTask() {
@Override
protected void doRun() throws Exception {
try {
for (int i = 0; i < runTimes; i++) {
write.acquire();
int randomLength = randomInt(0, 1 << 8);
commandStore.appendCommands(Unpooled.wrappedBuffer(randomString(randomLength).getBytes()));
realLength.addAndGet(randomLength);
read.release();
}
} finally {
finished.set(true);
read.release();
latch.countDown();
}
}
});
executors.execute(new AbstractExceptionLogTask() {
@Override
protected void doRun() throws Exception {
try {
while (!finished.get()) {
read.acquire();
long len = commandStore.totalLength();
if (len != realLength.get()) {
result.set(false);
}
write.release();
}
} finally {
latch.countDown();
}
}
});
latch.await();
Assert.assertTrue(result.get());
}
use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.
the class DefaultReplicationStoreTest method testReadWhileDestroy.
@Test
public void testReadWhileDestroy() throws Exception {
store = new DefaultReplicationStore(baseDir, new DefaultKeeperConfig(), randomKeeperRunid(), createkeeperMonitor());
store.getMetaStore().becomeActive();
int dataLen = 1000;
RdbStore rdbStore = store.beginRdb(randomKeeperRunid(), -1, new LenEofType(dataLen));
rdbStore.writeRdb(Unpooled.wrappedBuffer(randomString(dataLen).getBytes()));
rdbStore.endRdb();
CountDownLatch latch = new CountDownLatch(2);
AtomicBoolean result = new AtomicBoolean(true);
executors.execute(new AbstractExceptionLogTask() {
@Override
protected void doRun() throws Exception {
try {
sleep(2);
store.close();
store.destroy();
} finally {
latch.countDown();
}
}
});
executors.execute(new AbstractExceptionLogTask() {
@Override
protected void doRun() throws Exception {
try {
store.fullSyncIfPossible(new FullSyncListener() {
@Override
public ChannelFuture onCommand(ReferenceFileRegion referenceFileRegion) {
return null;
}
@Override
public void beforeCommand() {
}
@Override
public void setRdbFileInfo(EofType eofType, long rdbFileKeeperOffset) {
}
@Override
public void onFileData(ReferenceFileRegion referenceFileRegion) throws IOException {
sleep(10);
}
@Override
public boolean isOpen() {
return true;
}
@Override
public void exception(Exception e) {
logger.info("[exception][fail]" + e.getMessage());
result.set(false);
}
@Override
public void beforeFileData() {
}
});
} catch (Exception e) {
logger.info("[exception][fail]" + e.getMessage());
result.set(false);
} finally {
latch.countDown();
}
}
});
latch.await(100, TimeUnit.MILLISECONDS);
Assert.assertFalse(result.get());
}
use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.
the class AbstractClusterServers method doStart.
@Override
protected void doStart() throws Exception {
CuratorFramework client = zkClient.get();
serversCache = new PathChildrenCache(client, MetaZkConfig.getMetaServerRegisterPath(), true, XpipeThreadFactory.create(String.format("PathChildrenCache(%d)", currentServer.getServerId())));
serversCache.getListenable().addListener(new ChildrenChanged());
serversCache.start();
future = scheduled.scheduleWithFixedDelay(new AbstractExceptionLogTask() {
@Override
public void doRun() {
try {
childrenChanged();
} catch (Throwable th) {
logger.error("[doStart]", th);
}
}
}, 1000, metaServerConfig.getClusterServersRefreshMilli(), TimeUnit.MILLISECONDS);
}
Aggregations