public String getMappedIdeChangeListId(P4ChangelistId p4id) throws InterruptedException { return lockTimeout.withReadLock(lock, () -> linkedChangelistIds.get(p4id)); }
@NotNull public Map<P4ChangelistId, String> getLinkedChangelistIds() throws InterruptedException { return lockTimeout.withReadLock(lock, () -> new HashMap<>(linkedChangelistIds)); }
@NotNull public List<ActionStore.PendingAction> copyActions() throws InterruptedException { return lockTimeout.withReadLock(lock, () -> new ArrayList<>(pendingActions)); }
@NotNull public List<P4LocalChangelist> getPendingChangelists() throws InterruptedException { return lockTimeout.withReadLock(lock, () -> new ArrayList<>(pendingChangelists.values())); }
public void read(ClientConfig config, Consumer<ClientQueryCacheStore> fun) throws InterruptedException { lockTimeout.withReadLock(lock, () -> { ClientQueryCacheStore store = clientQueryCache.get(config.getClientServerRef()); if (store != null) { fun.accept(store); } }); }
@Nullable public <T> T read(ClientConfig config, T defaultValue, Function<ClientQueryCacheStore, T> fun) throws InterruptedException { return lockTimeout.withReadLock(lock, () -> { ClientQueryCacheStore store = clientQueryCache.get(config.getClientServerRef()); if (store != null) { return fun.apply(store); } return defaultValue; }); }
/** * query cache can change during a read, so the function runs inside the lock. * * @param config source * @param defaultValue value if the source is not registered to have a cache * @param fun mapping function * @param <T> return type * @return return value from the mapping function, or the default value * @throws InterruptedException thrown if the lock is not acquired in time. */ @Nullable public <T> T read(P4ServerName config, T defaultValue, Function<ServerQueryCacheStore, T> fun) throws InterruptedException { return lockTimeout.withReadLock(lock, () -> { ServerQueryCacheStore store = serverQueryCache.get(config); if (store != null) { return fun.apply(store); } return defaultValue; }); }
@NotNull public List<P4ChangelistId> getLinkedChangelists(@NotNull String ideId) throws InterruptedException { return lockTimeout.withReadLock(lock, () -> { List<P4ChangelistId> ret = new ArrayList<>(); for (Map.Entry<P4ChangelistId, String> entry : linkedChangelistIds.entrySet()) { if (entry.getValue().equals(ideId)) { if (LOG.isDebugEnabled()) { LOG.debug("Matched IDE change list ID " + ideId + " to p4 changelist " + entry.getKey()); } ret.add(entry.getKey()); } } return ret; }); }
@Nullable public State getState() throws InterruptedException { final State ret = new State(); lockTimeout.withReadLock(lock, () -> { ret.serverState = new ArrayList<>(serverQueryCache.size()); for (ServerQueryCacheStore entry : serverQueryCache.values()) { ret.serverState.add(entry.getState()); } ret.clientState = new ArrayList<>(clientQueryCache.size()); for (ClientQueryCacheStore value : clientQueryCache.values()) { ret.clientState.add(value.getState()); } ret.pendingActions = new ArrayList<>(pendingActions.size()); for (ActionStore.PendingAction pendingAction : pendingActions) { ret.pendingActions.add(pendingAction.getState()); } ret.changelistState = changelistCacheStore.getState(); }); return ret; }
@NotNull State getState() throws InterruptedException { final State ret = new State(); lockTimeout.withReadLock(lock, () -> { ret.linkedChangelistMap = new ArrayList<>(linkedChangelistIds.size()); for (Map.Entry<P4ChangelistId, String> entry : linkedChangelistIds.entrySet()) { LinkedChangelistState state = new LinkedChangelistState(); state.changelistId = P4ChangelistIdStore.getState(entry.getKey()); state.linkedLocalChangeId = entry.getValue(); ret.linkedChangelistMap.add(state); } ret.pendingChangelistMap = new ArrayList<>(pendingChangelists.size()); for (Map.Entry<String, P4LocalChangelist> entry : pendingChangelists.entrySet()) { PendingChangelistState state = new PendingChangelistState(); state.linkedLocalChangeId = entry.getKey(); state.p4Changelist = P4LocalChangelistStore.getState(entry.getValue()); ret.pendingChangelistMap.add(state); } ret.lastPendingChangelistId = pendingChangelistIdCounter.get(); }); return ret; }