Search in sources :

Example 1 with NodeAdded

use of com.ctrip.xpipe.observer.NodeAdded in project x-pipe by ctripcorp.

the class AbstractCurrentMetaObserver method update.

@SuppressWarnings("rawtypes")
@Override
public void update(Object args, Observable observable) {
    if (args instanceof NodeAdded) {
        ClusterMeta clusterMeta = (ClusterMeta) ((NodeAdded) args).getNode();
        logger.info("[update][add][{}]{}", getClass().getSimpleName(), clusterMeta.getId());
        handleClusterAdd(clusterMeta);
        return;
    }
    if (args instanceof NodeDeleted) {
        ClusterMeta clusterMeta = (ClusterMeta) ((NodeDeleted) args).getNode();
        logger.info("[update][delete][{}]{}", getClass().getSimpleName(), clusterMeta.getId());
        handleClusterDeleted(clusterMeta);
        return;
    }
    if (args instanceof ClusterMetaComparator) {
        ClusterMetaComparator clusterMetaComparator = (ClusterMetaComparator) args;
        logger.info("[update][modify][{}]{}", getClass().getSimpleName(), clusterMetaComparator);
        handleClusterModified(clusterMetaComparator);
        return;
    }
    throw new IllegalArgumentException("unknown argument:" + args);
}
Also used : ClusterMetaComparator(com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) NodeAdded(com.ctrip.xpipe.observer.NodeAdded) NodeDeleted(com.ctrip.xpipe.observer.NodeDeleted)

Example 2 with NodeAdded

use of com.ctrip.xpipe.observer.NodeAdded 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;
}
Also used : Observer(com.ctrip.xpipe.api.observer.Observer) DefaultReplicationStoreManager(com.ctrip.xpipe.redis.keeper.store.DefaultReplicationStoreManager) NodeAdded(com.ctrip.xpipe.observer.NodeAdded) IOException(java.io.IOException) DefaultReplicationStore(com.ctrip.xpipe.redis.keeper.store.DefaultReplicationStore) Observable(com.ctrip.xpipe.api.observer.Observable)

Aggregations

NodeAdded (com.ctrip.xpipe.observer.NodeAdded)2 Observable (com.ctrip.xpipe.api.observer.Observable)1 Observer (com.ctrip.xpipe.api.observer.Observer)1 NodeDeleted (com.ctrip.xpipe.observer.NodeDeleted)1 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)1 ClusterMetaComparator (com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator)1 DefaultReplicationStore (com.ctrip.xpipe.redis.keeper.store.DefaultReplicationStore)1 DefaultReplicationStoreManager (com.ctrip.xpipe.redis.keeper.store.DefaultReplicationStoreManager)1 IOException (java.io.IOException)1