1   /*
2    * Copyright 2019 LINE Corporation
3    *
4    * LINE Corporation licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package com.linecorp.centraldogma.server.plugin;
17  
18  import static java.util.Objects.requireNonNull;
19  
20  import java.util.concurrent.ScheduledExecutorService;
21  
22  import com.linecorp.centraldogma.server.CentralDogmaConfig;
23  import com.linecorp.centraldogma.server.command.Command;
24  import com.linecorp.centraldogma.server.command.CommandExecutor;
25  import com.linecorp.centraldogma.server.mirror.MirrorAccessController;
26  import com.linecorp.centraldogma.server.storage.project.InternalProjectInitializer;
27  import com.linecorp.centraldogma.server.storage.project.Project;
28  import com.linecorp.centraldogma.server.storage.project.ProjectManager;
29  
30  import io.micrometer.core.instrument.MeterRegistry;
31  
32  /**
33   * A class which is used to pass internally-created instances into the {@link Plugin}.
34   */
35  public class PluginContext {
36  
37      private final CentralDogmaConfig config;
38      private final ProjectManager projectManager;
39      private final CommandExecutor commandExecutor;
40      private final MeterRegistry meterRegistry;
41      private final ScheduledExecutorService purgeWorker;
42      private final InternalProjectInitializer internalProjectInitializer;
43      private final MirrorAccessController mirrorAccessController;
44  
45      /**
46       * Creates a new instance.
47       *
48       * @param config the Central Dogma configuration
49       * @param projectManager the instance which has the operations for the {@link Project}s
50       * @param commandExecutor the executor which executes the {@link Command}s
51       * @param meterRegistry the {@link MeterRegistry} of the Central Dogma server
52       * @param purgeWorker the {@link ScheduledExecutorService} for the purging service
53       * @param internalProjectInitializer the initializer for the internal projects
54       * @param mirrorAccessController the controller which controls the access to the remote repos of mirrors
55       */
56      public PluginContext(CentralDogmaConfig config,
57                           ProjectManager projectManager,
58                           CommandExecutor commandExecutor,
59                           MeterRegistry meterRegistry,
60                           ScheduledExecutorService purgeWorker,
61                           InternalProjectInitializer internalProjectInitializer,
62                           MirrorAccessController mirrorAccessController) {
63          this.config = requireNonNull(config, "config");
64          this.projectManager = requireNonNull(projectManager, "projectManager");
65          this.commandExecutor = requireNonNull(commandExecutor, "commandExecutor");
66          this.meterRegistry = requireNonNull(meterRegistry, "meterRegistry");
67          this.purgeWorker = requireNonNull(purgeWorker, "purgeWorker");
68          this.internalProjectInitializer = requireNonNull(internalProjectInitializer,
69                                                           "internalProjectInitializer");
70          this.mirrorAccessController = requireNonNull(mirrorAccessController, "mirrorAccessController");
71      }
72  
73      /**
74       * Returns the {@link CentralDogmaConfig}.
75       */
76      public CentralDogmaConfig config() {
77          return config;
78      }
79  
80      /**
81       * Returns the {@link ProjectManager}.
82       */
83      public ProjectManager projectManager() {
84          return projectManager;
85      }
86  
87      /**
88       * Returns the {@link CommandExecutor}.
89       */
90      public CommandExecutor commandExecutor() {
91          return commandExecutor;
92      }
93  
94      /**
95       * Returns the {@link MeterRegistry}.
96       */
97      public MeterRegistry meterRegistry() {
98          return meterRegistry;
99      }
100 
101     /**
102      * Returns the {@link ScheduledExecutorService} of {@code purgeWorker}.
103      */
104     public ScheduledExecutorService purgeWorker() {
105         return purgeWorker;
106     }
107 
108     /**
109      * Returns the {@link InternalProjectInitializer}.
110      */
111     public InternalProjectInitializer internalProjectInitializer() {
112         return internalProjectInitializer;
113     }
114 
115     /**
116      * Returns the {@link MirrorAccessController}.
117      */
118     public MirrorAccessController mirrorAccessController() {
119         return mirrorAccessController;
120     }
121 }