use of com.ctrip.xpipe.api.observer.Observable in project x-pipe by ctripcorp.
the class AbstractRedisKeeperTest method createReplicationStoreManager.
protected ReplicationStoreManager createReplicationStoreManager(String clusterId, String shardId, String keeperRunid, KeeperConfig keeperConfig, File storeDir) {
DefaultReplicationStoreManager replicationStoreManager = new DefaultReplicationStoreManager(keeperConfig, clusterId, shardId, keeperRunid, storeDir, createkeeperMonitor());
replicationStoreManager.addObserver(new Observer() {
@Override
public void update(Object args, Observable observable) {
if (args instanceof NodeAdded) {
@SuppressWarnings("unchecked") ReplicationStore replicationStore = ((NodeAdded<ReplicationStore>) args).getNode();
try {
replicationStore.getMetaStore().becomeActive();
} catch (IOException e) {
logger.error("[update]" + replicationStore, e);
}
}
}
});
return replicationStoreManager;
}
use of com.ctrip.xpipe.api.observer.Observable in project x-pipe by ctripcorp.
the class HealthStatusTest method testDown.
@Test
public void testDown() {
AtomicBoolean isDown = new AtomicBoolean();
HealthStatus healthStatus = new HealthStatus(hostPort, () -> downAfterMilli, () -> healthDelayMilli, scheduled);
healthStatus.addObserver(new Observer() {
@Override
public void update(Object args, Observable observable) {
logger.debug("{}, {}", args, observable);
if (args instanceof InstanceUp) {
isDown.set(false);
} else if (args instanceof InstanceDown) {
isDown.set(true);
} else {
throw new IllegalStateException("unknown " + args);
}
}
});
healthStatus.delay(healthDelayMilli);
Assert.assertFalse(isDown.get());
sleep(downAfterMilli * 3);
Assert.assertTrue(isDown.get());
healthStatus.delay(healthDelayMilli);
Assert.assertFalse(isDown.get());
}
use of com.ctrip.xpipe.api.observer.Observable in project x-pipe by ctripcorp.
the class DefaultRedisKeeperServer method clientConnected.
@Override
public RedisClient clientConnected(Channel channel) {
RedisClient redisClient = new DefaultRedisClient(channel, this);
redisClients.put(channel, redisClient);
redisClient.addObserver(new Observer() {
@Override
public void update(Object args, Observable observable) {
if (args instanceof RedisSlave) {
becomeSlave(((RedisClient) observable).channel(), (RedisSlave) args);
}
}
});
return redisClient;
}
use of com.ctrip.xpipe.api.observer.Observable in project x-pipe by ctripcorp.
the class LifecycleObservableAbstractTest method testConcurrent.
@Test
public void testConcurrent() {
int count = 100;
AtomicBoolean nullObserver = new AtomicBoolean(false);
TestLifecycle testLifecycle = new TestLifecycle(nullObserver);
List<Observer> observers = new LinkedList<>();
for (int i = 0; i < count; i++) {
Observer observer = new Observer() {
@Override
public void update(Object args, Observable observable) {
}
};
observers.add(observer);
testLifecycle.addObserver(observer);
}
executors.execute(new Runnable() {
@Override
public void run() {
observers.forEach(observer -> testLifecycle.removeObserver(observer));
}
});
for (int i = 0; i < count * 10; i++) {
testLifecycle.notifyObservers(new Object());
}
Assert.assertFalse(nullObserver.get());
}
Aggregations