LCOV - code coverage report
Current view: top level - server/project - ProjectCache.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 2 2 100.0 %
Date: 2022-11-19 15:00:39 Functions: 3 4 75.0 %

          Line data    Source code
       1             : // Copyright (C) 2008 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.server.project;
      16             : 
      17             : import com.google.common.collect.ImmutableSortedSet;
      18             : import com.google.gerrit.common.Nullable;
      19             : import com.google.gerrit.entities.AccountGroup;
      20             : import com.google.gerrit.entities.Project;
      21             : import com.google.gerrit.exceptions.StorageException;
      22             : import java.io.IOException;
      23             : import java.util.Optional;
      24             : import java.util.Set;
      25             : import java.util.function.Supplier;
      26             : 
      27             : /** Cache of project information, including access rights. */
      28             : public interface ProjectCache {
      29             :   /**
      30             :    * Returns a supplier to be used as a short-hand when unwrapping an {@link Optional} returned from
      31             :    * this cache.
      32             :    */
      33             :   static Supplier<IllegalStateException> illegalState(Project.NameKey nameKey) {
      34         152 :     return () -> new IllegalStateException("unable to find project " + nameKey);
      35             :   }
      36             : 
      37             :   /**
      38             :    * Returns a supplier to be used as a short-hand when unwrapping an {@link Optional} returned from
      39             :    * this cache.
      40             :    */
      41             :   static Supplier<NoSuchProjectException> noSuchProject(Project.NameKey nameKey) {
      42          67 :     return () -> new NoSuchProjectException(nameKey);
      43             :   }
      44             : 
      45             :   /** Returns the parent state for all projects on this server. */
      46             :   ProjectState getAllProjects();
      47             : 
      48             :   /** Returns the project state of the project storing meta data for all users. */
      49             :   ProjectState getAllUsers();
      50             : 
      51             :   /**
      52             :    * Get the cached data for a project by its unique name.
      53             :    *
      54             :    * @param projectName name of the project.
      55             :    * @return an {@link Optional} wrapping the cached data; {@code absent} if no such project exists
      56             :    *     or the projectName is null
      57             :    * @throws StorageException when there was an error.
      58             :    */
      59             :   Optional<ProjectState> get(@Nullable Project.NameKey projectName) throws StorageException;
      60             : 
      61             :   /**
      62             :    * Invalidate the cached information about the given project.
      63             :    *
      64             :    * @param p the NameKey of the project that is being evicted
      65             :    */
      66             :   void evict(Project.NameKey p);
      67             : 
      68             :   /**
      69             :    * Invalidate the cached information about the given project, and triggers reindexing for it
      70             :    *
      71             :    * @param p project that is being evicted
      72             :    */
      73             :   void evictAndReindex(Project p);
      74             : 
      75             :   /**
      76             :    * Invalidate the cached information about the given project, and triggers reindexing for it
      77             :    *
      78             :    * @param p the NameKey of the project that is being evicted
      79             :    */
      80             :   void evictAndReindex(Project.NameKey p);
      81             : 
      82             :   /**
      83             :    * Remove information about the given project from the cache. It will no longer be returned from
      84             :    * {@link #all()}.
      85             :    */
      86             :   void remove(Project p);
      87             : 
      88             :   /**
      89             :    * Remove information about the given project from the cache. It will no longer be returned from
      90             :    * {@link #all()}.
      91             :    */
      92             :   void remove(Project.NameKey name);
      93             : 
      94             :   /** Returns sorted iteration of projects. */
      95             :   ImmutableSortedSet<Project.NameKey> all();
      96             : 
      97             :   /** Refreshes project list cache */
      98             :   void refreshProjectList();
      99             : 
     100             :   /**
     101             :    * Returns estimated set of relevant groups extracted from hot project access rules. If the cache
     102             :    * is cold or too small for the entire project set of the server, this set may be incomplete.
     103             :    */
     104             :   Set<AccountGroup.UUID> guessRelevantGroupUUIDs();
     105             : 
     106             :   /**
     107             :    * Filter the set of registered project names by common prefix.
     108             :    *
     109             :    * @param prefix common prefix.
     110             :    * @return sorted iteration of projects sharing the same prefix.
     111             :    */
     112             :   ImmutableSortedSet<Project.NameKey> byName(String prefix);
     113             : 
     114             :   /** Notify the cache that a new project was constructed. */
     115             :   void onCreateProject(Project.NameKey newProjectName) throws IOException;
     116             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750