org.elasticsearch.transport.TransportService.openConnection()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(83)

本文整理了Java中org.elasticsearch.transport.TransportService.openConnection()方法的一些代码示例,展示了TransportService.openConnection()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TransportService.openConnection()方法的具体详情如下:
包路径:org.elasticsearch.transport.TransportService
类名称:TransportService
方法名:openConnection

TransportService.openConnection介绍

[英]Establishes and returns a new connection to the given node. The connection is NOT maintained by this service, it's the callers responsibility to close the connection once it goes out of scope.
[中]建立并返回到给定节点的新连接。此服务不维护连接,一旦连接超出范围,呼叫者有责任关闭连接。

代码示例

代码示例来源:origin: org.elasticsearch/elasticsearch

public Connection getOrConnect(DiscoveryNode node) throws IOException {
  Connection result;
  try (Releasable ignore = connectionLock.acquire(node.getAddress())) {
    result = tempConnections.get(node.getAddress());
    if (result == null) {
      ensureOpen();
      boolean success = false;
      logger.trace("[{}] opening connection to [{}]", id(), node);
      result = transportService.openConnection(node, connectionProfile);
      try {
        transportService.handshake(result, connectionProfile.getHandshakeTimeout().millis());
        synchronized (this) {
          // acquire lock and check if closed, to prevent leaving an open connection after closing
          ensureOpen();
          Connection existing = tempConnections.put(node.getAddress(), result);
          assert existing == null;
          success = true;
        }
      } finally {
        if (success == false) {
          logger.trace("[{}] closing connection to [{}] due to failure", id(), node);
          IOUtils.closeWhileHandlingException(result);
        }
      }
    }
  }
  return result;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

connectionToClose = transportService.openConnection(nodeToPing, LISTED_NODES_PROFILE);
pingConnection = connectionToClose;

代码示例来源:origin: org.elasticsearch/elasticsearch

ArrayList<DiscoveryNode> newFilteredNodes = new ArrayList<>();
for (DiscoveryNode listedNode : listedNodes) {
  try (Transport.Connection connection = transportService.openConnection(listedNode, LISTED_NODES_PROFILE)){
    final PlainTransportFuture<LivenessResponse> handler = new PlainTransportFuture<>(
      new FutureTransportResponseHandler<LivenessResponse>() {

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

@Override
public Transport.Connection openConnection(DiscoveryNode node, ConnectionProfile profile) throws IOException {
  FilteredConnection filteredConnection = new FilteredConnection(super.openConnection(node, profile)) {
    final AtomicBoolean closed = new AtomicBoolean(false);
    @Override
    public void close() throws IOException {
      try {
        super.close();
      } finally {
        if (closed.compareAndSet(false, true)) {
          synchronized (openConnections) {
            List<Transport.Connection> connections = openConnections.get(node);
            boolean remove = connections.remove(this);
            assert remove;
            if (connections.isEmpty()) {
              openConnections.remove(node);
            }
          }
        }
      }
    }
  };
  synchronized (openConnections) {
    List<Transport.Connection> connections = openConnections.computeIfAbsent(node,
      (n) -> new CopyOnWriteArrayList<>());
    connections.add(filteredConnection);
  }
  return filteredConnection;
}

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

IOUtils.close(service.openConnection(first, builder.build()));
builder.setConnectTimeout(TimeValue.timeValueMillis(1));
final ConnectionProfile profile = builder.build();
ConnectTransportException ex = expectThrows(ConnectTransportException.class, () -> service.openConnection(second, profile));
final long now = System.nanoTime();
final long timeTaken = TimeValue.nsecToMSec(now - startTime);

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

public Connection getOrConnect(DiscoveryNode node) throws IOException {
  Connection result;
  try (Releasable ignore = connectionLock.acquire(node.getAddress())) {
    result = tempConnections.get(node.getAddress());
    if (result == null) {
      ensureOpen();
      boolean success = false;
      logger.trace("[{}] opening connection to [{}]", id(), node);
      result = transportService.openConnection(node, connectionProfile);
      try {
        transportService.handshake(result, connectionProfile.getHandshakeTimeout().millis());
        synchronized (this) {
          // acquire lock and check if closed, to prevent leaving an open connection after closing
          ensureOpen();
          Connection existing = tempConnections.put(node.getAddress(), result);
          assert existing == null;
          success = true;
        }
      } finally {
        if (success == false) {
          logger.trace("[{}] closing connection to [{}] due to failure", id(), node);
          IOUtils.closeWhileHandlingException(result);
        }
      }
    }
  }
  return result;
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

public Connection getOrConnect(DiscoveryNode node) throws IOException {
  Connection result;
  try (Releasable ignore = connectionLock.acquire(node.getAddress())) {
    result = tempConnections.get(node.getAddress());
    if (result == null) {
      ensureOpen();
      boolean success = false;
      logger.trace("[{}] opening connection to [{}]", id(), node);
      result = transportService.openConnection(node, connectionProfile);
      try {
        transportService.handshake(result, connectionProfile.getHandshakeTimeout().millis());
        synchronized (this) {
          // acquire lock and check if closed, to prevent leaving an open connection after closing
          ensureOpen();
          Connection existing = tempConnections.put(node.getAddress(), result);
          assert existing == null;
          success = true;
        }
      } finally {
        if (success == false) {
          logger.trace("[{}] closing connection to [{}] due to failure", id(), node);
          IOUtils.closeWhileHandlingException(result);
        }
      }
    }
  }
  return result;
}

代码示例来源:origin: apache/servicemix-bundles

public Connection getOrConnect(DiscoveryNode node) throws IOException {
  Connection result;
  try (Releasable ignore = connectionLock.acquire(node.getAddress())) {
    result = tempConnections.get(node.getAddress());
    if (result == null) {
      ensureOpen();
      boolean success = false;
      logger.trace("[{}] opening connection to [{}]", id(), node);
      result = transportService.openConnection(node, connectionProfile);
      try {
        transportService.handshake(result, connectionProfile.getHandshakeTimeout().millis());
        synchronized (this) {
          // acquire lock and check if closed, to prevent leaving an open connection after closing
          ensureOpen();
          Connection existing = tempConnections.put(node.getAddress(), result);
          assert existing == null;
          success = true;
        }
      } finally {
        if (success == false) {
          logger.trace("[{}] closing connection to [{}] due to failure", id(), node);
          IOUtils.closeWhileHandlingException(result);
        }
      }
    }
  }
  return result;
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

HashSet<DiscoveryNode> newFilteredNodes = new HashSet<>();
for (DiscoveryNode listedNode : listedNodes) {
  try (Transport.Connection connection = transportService.openConnection(listedNode, LISTED_NODES_PROFILE)){
    final PlainTransportFuture<LivenessResponse> handler = new PlainTransportFuture<>(
      new FutureTransportResponseHandler<LivenessResponse>() {

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

connectionToClose = transportService.openConnection(nodeToPing, LISTED_NODES_PROFILE);
pingConnection = connectionToClose;

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

connectionToClose = transportService.openConnection(nodeToPing, LISTED_NODES_PROFILE);
pingConnection = connectionToClose;

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

ArrayList<DiscoveryNode> newFilteredNodes = new ArrayList<>();
for (DiscoveryNode listedNode : listedNodes) {
  try (Transport.Connection connection = transportService.openConnection(listedNode, LISTED_NODES_PROFILE)){
    final PlainTransportFuture<LivenessResponse> handler = new PlainTransportFuture<>(
      new FutureTransportResponseHandler<LivenessResponse>() {

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

final DiscoveryNode seedNode = seedNodes.next();
final DiscoveryNode handshakeNode;
Transport.Connection connection = transportService.openConnection(seedNode,
  ConnectionProfile.buildSingleChannelProfile(TransportRequestOptions.Type.REG, null, null));
boolean success = false;

相关文章

微信公众号

最新文章

更多

TransportService类方法