1   /*
2    * Copyright 2017 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  
17  package com.linecorp.centraldogma.server.command;
18  
19  import java.util.concurrent.CompletableFuture;
20  
21  import javax.annotation.Nullable;
22  
23  import com.linecorp.centraldogma.server.QuotaConfig;
24  
25  /**
26   * An executor interface which executes {@link Command}s.
27   */
28  public interface CommandExecutor {
29      /**
30       * Returns the ID of a replica.
31       */
32      int replicaId();
33  
34      /**
35       * Returns {@code true} if the executor is started.
36       */
37      boolean isStarted();
38  
39      /**
40       * Starts the executor.
41       */
42      CompletableFuture<Void> start();
43  
44      /**
45       * Stops the executor.
46       */
47      CompletableFuture<Void> stop();
48  
49      /**
50       * Returns {@code true} if the executor can accept the {@link Command}s making a change to the replica.
51       * {@code false} would be returned if the replica is running as a read-only mode.
52       */
53      boolean isWritable();
54  
55      /**
56       * Makes the executor read/write mode or read-only mode.
57       *
58       * @param writable {@code true} to make the executor read/write mode, or {@code false} to make it
59       *                 read-only mode
60       */
61      void setWritable(boolean writable);
62  
63      /**
64       * Sets the specified {@linkplain QuotaConfig write quota} to the specified {@code repoName} in the
65       * specified {@code projectName}.
66       */
67      void setWriteQuota(String projectName, String repoName, @Nullable QuotaConfig writeQuota);
68  
69      /**
70       * Executes the specified {@link Command}.
71       *
72       * @param command the command which is supposed to be executed
73       * @param <T> the type of the result to be returned
74       */
75      <T> CompletableFuture<T> execute(Command<T> command);
76  
77      /**
78       * Returns the status manager of this executor.
79       */
80      CommandExecutorStatusManager statusManager();
81  }