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.storage.project.Project;
26  import com.linecorp.centraldogma.server.storage.project.ProjectManager;
27  
28  import io.micrometer.core.instrument.MeterRegistry;
29  
30  /**
31   * A class which is used to pass internally-created instances into the {@link Plugin}.
32   */
33  public class PluginContext {
34  
35      private final CentralDogmaConfig config;
36      private final ProjectManager projectManager;
37      private final CommandExecutor commandExecutor;
38      private final MeterRegistry meterRegistry;
39      private final ScheduledExecutorService purgeWorker;
40  
41      /**
42       * Creates a new instance.
43       *
44       * @param config the Central Dogma configuration
45       * @param projectManager the instance which has the operations for the {@link Project}s
46       * @param commandExecutor the executor which executes the {@link Command}s
47       * @param meterRegistry the {@link MeterRegistry} of the Central Dogma server
48       * @param purgeWorker the {@link ScheduledExecutorService} for the purging service
49       */
50      public PluginContext(CentralDogmaConfig config,
51                           ProjectManager projectManager,
52                           CommandExecutor commandExecutor,
53                           MeterRegistry meterRegistry,
54                           ScheduledExecutorService purgeWorker) {
55          this.config = requireNonNull(config, "config");
56          this.projectManager = requireNonNull(projectManager, "projectManager");
57          this.commandExecutor = requireNonNull(commandExecutor, "commandExecutor");
58          this.meterRegistry = requireNonNull(meterRegistry, "meterRegistry");
59          this.purgeWorker = requireNonNull(purgeWorker, "purgeWorker");
60      }
61  
62      /**
63       * Returns the {@link CentralDogmaConfig}.
64       */
65      public CentralDogmaConfig config() {
66          return config;
67      }
68  
69      /**
70       * Returns the {@link ProjectManager}.
71       */
72      public ProjectManager projectManager() {
73          return projectManager;
74      }
75  
76      /**
77       * Returns the {@link CommandExecutor}.
78       */
79      public CommandExecutor commandExecutor() {
80          return commandExecutor;
81      }
82  
83      /**
84       * Returns the {@link MeterRegistry}.
85       */
86      public MeterRegistry meterRegistry() {
87          return meterRegistry;
88      }
89  
90      /**
91       * Returns the {@link ScheduledExecutorService} of {@code purgeWorker}.
92       */
93      public ScheduledExecutorService purgeWorker() {
94          return purgeWorker;
95      }
96  }