Exemplo n.º 1
0
  private ObjectValuePair<String, URL> _getBootupClusterNodeObjectValuePair(Address bootupAddress) {

    ClusterRequest clusterRequest =
        ClusterRequest.createUnicastRequest(
            new MethodHandler(_createTokenMethodKey, _CLUSTER_LINK_NODE_BOOTUP_RESPONSE_TIMEOUT),
            bootupAddress);

    FutureClusterResponses futureClusterResponses = ClusterExecutorUtil.execute(clusterRequest);

    BlockingQueue<ClusterNodeResponse> clusterNodeResponses =
        futureClusterResponses.getPartialResults();

    try {
      ClusterNodeResponse clusterNodeResponse =
          clusterNodeResponses.poll(
              _CLUSTER_LINK_NODE_BOOTUP_RESPONSE_TIMEOUT, TimeUnit.MILLISECONDS);

      ClusterNode clusterNode = clusterNodeResponse.getClusterNode();

      InetSocketAddress inetSocketAddress = clusterNode.getPortalInetSocketAddress();

      if (inetSocketAddress == null) {
        StringBundler sb = new StringBundler(6);

        sb.append("Invalid cluster node InetSocketAddress ");
        sb.append(". The InetSocketAddress is set by the first ");
        sb.append("request or configured in portal.properties by the");
        sb.append("properties ");
        sb.append("\"portal.instance.http.inet.socket.address\" and ");
        sb.append("\"portal.instance.https.inet.socket.address\".");

        throw new Exception(sb.toString());
      }

      InetAddress inetAddress = inetSocketAddress.getAddress();

      String fileName = PortalUtil.getPathContext();

      if (!fileName.endsWith(StringPool.SLASH)) {
        fileName = fileName.concat(StringPool.SLASH);
      }

      fileName = fileName.concat("lucene/dump");

      URL url =
          new URL(_protocol, inetAddress.getHostAddress(), inetSocketAddress.getPort(), fileName);

      String transientToken = (String) clusterNodeResponse.getResult();

      return new ObjectValuePair<String, URL>(transientToken, url);
    } catch (Exception e) {
      throw new SystemException(e);
    }
  }
Exemplo n.º 2
0
    @Override
    public void callback(BlockingQueue<ClusterNodeResponse> blockingQueue) {
      Address bootupAddress = null;

      do {
        _clusterNodeAddressesCount--;

        ClusterNodeResponse clusterNodeResponse = null;

        try {
          clusterNodeResponse =
              blockingQueue.poll(_CLUSTER_LINK_NODE_BOOTUP_RESPONSE_TIMEOUT, TimeUnit.MILLISECONDS);
        } catch (Exception e) {
          _log.error("Unable to get cluster node response", e);
        }

        if (clusterNodeResponse == null) {
          if (_log.isDebugEnabled()) {
            _log.debug(
                "Unable to get cluster node response in "
                    + _CLUSTER_LINK_NODE_BOOTUP_RESPONSE_TIMEOUT
                    + TimeUnit.MILLISECONDS);
          }

          continue;
        }

        ClusterNode clusterNode = clusterNodeResponse.getClusterNode();

        if (clusterNode.getPortalInetSocketAddress() != null) {
          try {
            long remoteLastGeneration = (Long) clusterNodeResponse.getResult();

            if (remoteLastGeneration > _localLastGeneration) {
              bootupAddress = clusterNodeResponse.getAddress();

              break;
            }
          } catch (Exception e) {
            if (_log.isDebugEnabled()) {
              _log.debug("Suppress exception caused by remote method " + "invocation", e);
            }

            continue;
          }
        } else if (_log.isDebugEnabled()) {
          _log.debug("Cluster node " + clusterNode + " has invalid InetSocketAddress");
        }
      } while ((bootupAddress == null) && (_clusterNodeAddressesCount > 1));

      if (bootupAddress == null) {
        return;
      }

      if (_log.isInfoEnabled()) {
        _log.info("Start loading lucene index files from cluster node " + bootupAddress);
      }

      InputStream inputStream = null;

      try {
        inputStream = getLoadIndexesInputStreamFromCluster(_companyId, bootupAddress);

        _indexAccessor.loadIndex(inputStream);

        if (_log.isInfoEnabled()) {
          _log.info("Lucene index files loaded successfully");
        }
      } catch (Exception e) {
        _log.error("Unable to load index for company " + _companyId, e);
      } finally {
        if (inputStream != null) {
          try {
            inputStream.close();
          } catch (IOException ioe) {
            _log.error("Unable to close input stream for company " + _companyId, ioe);
          }
        }
      }
    }