public TransactorID(Environment env) { this(env.getSharedResources().getCurator()); }
GcTimestampTracker() throws Exception { this.curator = env.getSharedResources().getCurator(); }
public TransactorCache(Environment env) { timeoutCache = CacheBuilder.newBuilder().maximumSize(1 << 15) .expireAfterAccess(TxInfoCache.CACHE_TIMEOUT_MIN, TimeUnit.MINUTES) .concurrencyLevel(10).build(); this.env = env; cache = new PathChildrenCache(env.getSharedResources().getCurator(), ZookeeperPath.TRANSACTOR_NODES, true); try { cache.start(StartMode.BUILD_INITIAL_CACHE); status = TcStatus.OPEN; } catch (Exception e) { throw new RuntimeException(e); } }
/** * Start watching the fluo app uuid. If it changes or goes away then halt the process. */ public static NodeCache startAppIdWatcher(Environment env) { try { CuratorFramework curator = env.getSharedResources().getCurator(); byte[] uuidBytes = curator.getData().forPath(ZookeeperPath.CONFIG_FLUO_APPLICATION_ID); if (uuidBytes == null) { Halt.halt("Fluo Application UUID not found"); throw new RuntimeException(); // make findbugs happy } final String uuid = new String(uuidBytes, Charsets.UTF_8); final NodeCache nodeCache = new NodeCache(curator, ZookeeperPath.CONFIG_FLUO_APPLICATION_ID); nodeCache.getListenable().addListener(new NodeCacheListener() { @Override public void nodeChanged() throws Exception { ChildData node = nodeCache.getCurrentData(); if (node == null || !uuid.equals(new String(node.getData(), Charsets.UTF_8))) { Halt.halt("Fluo Application UUID has changed or disappeared"); } } }); nodeCache.start(); return nodeCache; } catch (Exception e) { throw new RuntimeException(e); } }
private void createZkNode(long ts) { Preconditions.checkState(node == null, "expected node to be null"); node = new PersistentEphemeralNode(env.getSharedResources().getCurator(), Mode.EPHEMERAL, getNodePath(), LongUtil.toByteArray(ts)); CuratorUtil.startAndWait(node, 10); zkTimestamp = ts; }
/** * Creates a transactor node using given transactor id * * @param env Environment * @param tid Transactor ID used to create node */ public TransactorNode(Environment env, TransactorID tid) { this.env = env; this.tid = tid; node = new PersistentEphemeralNode(env.getSharedResources().getCurator(), Mode.EPHEMERAL, getNodePath(), tid.toString().getBytes()); CuratorUtil.startAndWait(node, 10); status = TrStatus.OPEN; }
@Override public void init(Environment env, NotificationProcessor notificationProcessor) { Preconditions.checkState(this.notificationProcessor == null); this.notificationProcessor = notificationProcessor; this.env = env; this.curator = env.getSharedResources().getCurator(); try { myESNode = new PersistentEphemeralNode(curator, Mode.EPHEMERAL_SEQUENTIAL, ZookeeperPath.FINDERS + "/f-", new byte[0]); myESNode.start(); myESNode.waitForInitialCreate(1, TimeUnit.MINUTES); childrenCache = new PathChildrenCache(env.getSharedResources().getCurator(), ZookeeperPath.FINDERS, false); childrenCache.getListenable().addListener(new FindersListener()); childrenCache.start(StartMode.BUILD_INITIAL_CACHE); updateFinders(); } catch (Exception e) { throw new RuntimeException(e); } }