View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shardingsphere.mode.repository.cluster;
19  
20  import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
21  import org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener;
22  import org.apache.shardingsphere.mode.repository.cluster.lock.DistributedLock;
23  import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
24  
25  import java.util.Optional;
26  
27  /**
28   * Cluster persist repository.
29   */
30  public interface ClusterPersistRepository extends PersistRepository {
31      
32      /**
33       * Initialize registry center.
34       *
35       * @param config cluster persist repository configuration
36       * @param computeNodeInstanceContext compute node instance context
37       */
38      void init(ClusterPersistRepositoryConfiguration config, ComputeNodeInstanceContext computeNodeInstanceContext);
39      
40      /**
41       * Persist ephemeral data.
42       *
43       * @param key key of data
44       * @param value value of data
45       */
46      void persistEphemeral(String key, String value);
47      
48      /**
49       * Persist exclusive ephemeral data.
50       *
51       * @param key key of data
52       * @param value value of data
53       * @return persist success or not
54       */
55      boolean persistExclusiveEphemeral(String key, String value);
56      
57      /**
58       * Get distributed lock.
59       *
60       * @param lockKey kock key
61       * @return distributed lock
62       */
63      Optional<DistributedLock> getDistributedLock(String lockKey);
64      
65      /**
66       * Watch key or path of governance server.
67       *
68       * @param key key of data
69       * @param listener data changed event listener
70       */
71      void watch(String key, DataChangedEventListener listener);
72      
73      /**
74       * Remove listener by key.
75       *
76       * @param key key to be removed
77       */
78      void removeDataListener(String key);
79  }