• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / iotdb / #10009

06 Sep 2023 07:16AM UTC coverage: 47.654% (-0.04%) from 47.697%
#10009

push

travis_ci

web-flow
[To rel/1.2] add hot load compaction configs (#10759)

60 of 60 new or added lines in 1 file covered. (100.0%)

80169 of 168232 relevant lines covered (47.65%)

0.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.07
/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/ClientManager.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
package org.apache.iotdb.commons.client;
21

22
import org.apache.iotdb.commons.client.exception.BorrowNullClientManagerException;
23
import org.apache.iotdb.commons.client.exception.ClientManagerException;
24
import org.apache.iotdb.commons.utils.TestOnly;
25

26
import org.apache.commons.pool2.KeyedObjectPool;
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
29

30
import java.util.Optional;
31

32
public class ClientManager<K, V> implements IClientManager<K, V> {
33

34
  private static final Logger logger = LoggerFactory.getLogger(ClientManager.class);
1✔
35

36
  private final KeyedObjectPool<K, V> pool;
37

38
  ClientManager(IClientPoolFactory<K, V> factory) {
1✔
39
    pool = factory.createClientPool(this);
1✔
40
  }
1✔
41

42
  @TestOnly
43
  public KeyedObjectPool<K, V> getPool() {
44
    return pool;
1✔
45
  }
46

47
  @Override
48
  public V borrowClient(K node) throws ClientManagerException {
49
    if (node == null) {
1✔
50
      throw new BorrowNullClientManagerException();
1✔
51
    }
52
    try {
53
      return pool.borrowObject(node);
1✔
54
    } catch (Exception e) {
1✔
55
      throw new ClientManagerException(e);
1✔
56
    }
57
  }
58

59
  /**
60
   * return a client V for node K to the ClientManager.
61
   *
62
   * <p>Note: We do not define this interface in IClientManager to make you aware that the return of
63
   * a client is automatic whenever a particular client is used.
64
   */
65
  public void returnClient(K node, V client) {
66
    Optional.ofNullable(node)
1✔
67
        .ifPresent(
1✔
68
            x -> {
69
              try {
70
                pool.returnObject(node, client);
1✔
71
              } catch (Exception e) {
×
72
                logger.warn(
×
73
                    String.format("Return client %s for node %s to pool failed.", client, node), e);
×
74
              }
1✔
75
            });
1✔
76
  }
1✔
77

78
  @Override
79
  public void clear(K node) {
80
    Optional.ofNullable(node)
×
81
        .ifPresent(
×
82
            x -> {
83
              try {
84
                pool.clear(node);
×
85
              } catch (Exception e) {
×
86
                logger.warn(String.format("Clear all client in pool for node %s failed.", node), e);
×
87
              }
×
88
            });
×
89
  }
×
90

91
  @Override
92
  public void close() {
93
    pool.close();
1✔
94
  }
1✔
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc