public String getMappedIdeChangeListId(P4ChangelistId p4id) throws InterruptedException { return lockTimeout.withReadLock(lock, () -> linkedChangelistIds.get(p4id)); }
public void writeActions(Consumer<List<ActionStore.PendingAction>> fun) throws InterruptedException { lockTimeout.withWriteLock(lock, () -> fun.accept(pendingActions)); }
public void deleteChangelist(@NotNull P4ChangelistId changelistId) throws InterruptedException { lockTimeout.withWriteLock(lock, () -> { linkedChangelistIds.remove(changelistId); for (Map.Entry<String, P4LocalChangelist> entry : pendingChangelists.entrySet()) { if (entry.getValue().getChangelistId().equals(changelistId)) { pendingChangelists.remove(entry.getKey()); break; } } }); }
@NotNull public Map<P4ChangelistId, String> getLinkedChangelistIds() throws InterruptedException { return lockTimeout.withReadLock(lock, () -> new HashMap<>(linkedChangelistIds)); }
public void write(P4ServerName config, Consumer<ServerQueryCacheStore> fun) throws InterruptedException { lockTimeout.withWriteLock(lock, () -> { ServerQueryCacheStore store = serverQueryCache.get(config); if (store == null) { store = new ServerQueryCacheStore(config); serverQueryCache.put(config, store); } fun.accept(store); }); }
@NotNull public List<ActionStore.PendingAction> copyActions() throws InterruptedException { return lockTimeout.withReadLock(lock, () -> new ArrayList<>(pendingActions)); }
public void setLink(@NotNull P4ChangelistId p4ChangelistId, @NotNull String localId) throws InterruptedException { if (LOG.isDebugEnabled()) { LOG.debug("Mapping @" + p4ChangelistId + " to [" + localId + "]"); } lockTimeout.withWriteLock(lock, () -> { linkedChangelistIds.put(p4ChangelistId, localId); }); }
@NotNull public List<P4LocalChangelist> getPendingChangelists() throws InterruptedException { return lockTimeout.withReadLock(lock, () -> new ArrayList<>(pendingChangelists.values())); }
public void removeAction(@NotNull CreateChangelistAction action) throws InterruptedException { lockTimeout.withWriteLock(lock, () -> { P4LocalChangelist pendingChange = pendingChangelists.remove(action.getActionId()); if (pendingChange != null) { linkedChangelistIds.remove(pendingChange.getChangelistId()); } }); }
/** * 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; }); }
void setState(@Nullable State state) throws InterruptedException { if (state != null) { lockTimeout.withWriteLock(lock, () -> { linkedChangelistIds.clear(); for (LinkedChangelistState linkedChangelistState : state.linkedChangelistMap) { P4ChangelistId p4id = P4ChangelistIdStore.read(linkedChangelistState.changelistId); linkedChangelistIds.put(p4id, linkedChangelistState.linkedLocalChangeId); } pendingChangelists.clear(); for (PendingChangelistState pendingChangelistState : state.pendingChangelistMap) { P4LocalChangelist p4cl = P4LocalChangelistStore.read(pendingChangelistState.p4Changelist); pendingChangelists.put(pendingChangelistState.linkedLocalChangeId, p4cl); } pendingChangelistIdCounter.set(state.lastPendingChangelistId); }); } }
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); } }); }
public void updateCreatedChangelist(@NotNull P4ChangelistId serverChangelistId, @NotNull CreateChangelistAction action) throws InterruptedException { lockTimeout.withWriteLock(lock, () -> { P4LocalChangelist pendingChange = pendingChangelists.get(action.getActionId()); if (pendingChange != null) { // Update its link String ideId = linkedChangelistIds.remove(pendingChange.getChangelistId()); if (ideId != null) { linkedChangelistIds.put(serverChangelistId, ideId); } } else { LOG.warn("Attempted to remap pending Create Changelist action (" + action + "), but it wasn't known"); } }); }
@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; }); }
public void write(ClientConfig config, Consumer<ClientQueryCacheStore> fun) throws InterruptedException { lockTimeout.withWriteLock(lock, () -> { ClientQueryCacheStore store = clientQueryCache.get(config.getClientServerRef()); if (store == null) { store = new ClientQueryCacheStore(config.getClientServerRef()); clientQueryCache.put(config.getClientServerRef(), store); } fun.accept(store); }); }
@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; }); }
public void setState(@Nullable State state) throws InterruptedException { lockTimeout.withWriteLock(lock, () -> { serverQueryCache.clear(); clientQueryCache.clear();
@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; }
lockTimeout.withWriteLock(lock, () -> {
@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; }