public static <T> PersistentAtomicReference<T> create(final String filename, final JavaType javaType, final Supplier<? extends T> initialValue) throws IOException, InterruptedException { return create(FileSystems.getDefault().getPath(filename), javaType, initialValue); }
public static <T> PersistentAtomicReference<T> create(final Path filename, final JavaType javaType, final Supplier<? extends T> initialValue) throws IOException, InterruptedException { return new PersistentAtomicReference<>(filename, javaType, initialValue); }
public TaskHistoryWriter(final String hostname, final ZooKeeperClient client, final Path backingFile) throws IOException, InterruptedException { this.hostname = hostname; this.client = client; this.backingStore = PersistentAtomicReference.create(backingFile, new TypeReference<ConcurrentMap<JobId, Deque<TaskStatusEvent>>>() { }, new Supplier<ConcurrentMap<JobId, Deque<TaskStatusEvent>>>() { @Override public ConcurrentMap<JobId, Deque<TaskStatusEvent>> get() { return Maps.newConcurrentMap(); } }); this.items = backingStore.get(); // Clean out any errant null values. Normally shouldn't have any, but we did have a few // where it happened, and this will make sure we can get out of a bad state if we get into it. final ImmutableSet<JobId> curKeys = ImmutableSet.copyOf(this.items.keySet()); for (final JobId key : curKeys) { if (this.items.get(key) == null) { this.items.remove(key); } } int itemCount = 0; for (final Deque<TaskStatusEvent> deque : items.values()) { itemCount += deque.size(); } this.count = new AtomicInteger(itemCount); }
private ZooKeeperUpdatingPersistentDirectory(final String name, final ZooKeeperClientProvider provider, final Path stateFile, final String path) throws IOException, InterruptedException { this.provider = provider; this.path = path; this.entries = PersistentAtomicReference.create(stateFile, ENTRIES_TYPE, Suppliers.ofInstance(EMPTY_ENTRIES)); this.reactor = new DefaultReactor(name, new Update(), RETRY_INTERVAL_MILLIS); }
public PersistentPathChildrenCache(final CuratorFramework curator, final String path, final String clusterId, final Path snapshotFile, final JavaType valueType) throws IOException, InterruptedException { this.curator = curator; this.path = path; this.clusterId = clusterId; this.valueType = valueType; final MapType mapType = Json.typeFactory().constructMapType(HashMap.class, Json.type(String.class), valueType); final Supplier<Map<String, T>> empty = Suppliers.ofInstance(Collections.<String, T>emptyMap()); this.snapshot = PersistentAtomicReference.create(snapshotFile, mapType, empty); this.reactor = new DefaultReactor("zk-ppcc:" + path, new Update(), REFRESH_INTERVAL_MILLIS); curator.getConnectionStateListenable().addListener(new ConnectionListener()); }
executions = PersistentAtomicReference.create(stateDirectory.resolve("executions.json"), JOBID_EXECUTIONS_MAP, Suppliers.ofInstance(EMPTY_EXECUTIONS));
public static <T> PersistentAtomicReference<T> create(final String filename, final JavaType javaType, final Supplier<? extends T> initialValue) throws IOException, InterruptedException { return create(FileSystems.getDefault().getPath(filename), javaType, initialValue); }
public static <T> PersistentAtomicReference<T> create(final Path filename, final JavaType javaType, final Supplier<? extends T> initialValue) throws IOException, InterruptedException { return new PersistentAtomicReference<>(filename, javaType, initialValue); }
public QueueingHistoryWriter(final ZooKeeperClient client, final Path backingFile) throws IOException, InterruptedException { this.client = checkNotNull(client, "client"); this.backingStore = PersistentAtomicReference.create( checkNotNull(backingFile, "backingFile"), new TypeReference<ConcurrentMap<String, Deque<TEvent>>>(){}, new Supplier<ConcurrentMap<String, Deque<TEvent>>>() { @Override public ConcurrentMap<String, Deque<TEvent>> get() { return Maps.newConcurrentMap(); } }); this.events = backingStore.get(); // Clean out any errant null values. Normally shouldn't have any, but we did have a few // where it happened, and this will make sure we can get out of a bad state if we get into it. final ImmutableSet<String> curKeys = ImmutableSet.copyOf(this.events.keySet()); for (final String key : curKeys) { if (this.events.get(key) == null) { this.events.remove(key); } } int eventCount = 0; for (Deque<TEvent> deque : events.values()) { eventCount += deque.size(); } this.count = new AtomicInteger(eventCount); }
private ZooKeeperUpdatingPersistentDirectory(final String name, final ZooKeeperClientProvider provider, final Path stateFile, final String path) throws IOException, InterruptedException { this.provider = provider; this.path = path; this.entries = PersistentAtomicReference.create(stateFile, ENTRIES_TYPE, Suppliers.ofInstance(EMPTY_ENTRIES)); this.reactor = new DefaultReactor(name, new Update(), RETRY_INTERVAL_MILLIS); }
public PersistentPathChildrenCache(final CuratorFramework curator, final String path, final String clusterId, final Path snapshotFile, final JavaType valueType) throws IOException, InterruptedException { this.curator = curator; this.path = path; this.clusterId = clusterId; this.valueType = valueType; final MapType mapType = Json.typeFactory().constructMapType(HashMap.class, Json.type(String.class), valueType); final Supplier<Map<String, T>> empty = Suppliers.ofInstance(Collections.<String, T>emptyMap()); this.snapshot = PersistentAtomicReference.create(snapshotFile, mapType, empty); this.reactor = new DefaultReactor("zk-ppcc:" + path, new Update(), REFRESH_INTERVAL_MILLIS); curator.getConnectionStateListenable().addListener(new ConnectionListener()); }
executions = PersistentAtomicReference.create(stateDirectory.resolve("executions.json"), JOBID_EXECUTIONS_MAP, Suppliers.ofInstance(EMPTY_EXECUTIONS));