Package net.spy.memcached.config

Examples of net.spy.memcached.config.NodeEndPoint


   * @param addrs
   * @throws IOException
   */
  private void initializeClientUsingConfigEndPoint(ConnectionFactory cf, InetSocketAddress configurationEndPoint)
      throws IOException{
    configurationNode = new NodeEndPoint(configurationEndPoint.getHostName(), configurationEndPoint.getPort());
    setupConnection(cf, Collections.singletonList(configurationEndPoint));
   
    String configResult;
    try{
      try{
View Full Code Here


      String hostName = hostDetails.substring(0, firstDelimiter).trim();
      String ipAddress = hostDetails.substring(firstDelimiter+1, secondDelimiter).trim();
      String portNum = hostDetails.substring(secondDelimiter + 1).trim();
      int port = Integer.parseInt(portNum);
     
      NodeEndPoint endPoint = new NodeEndPoint(hostName, ipAddress, port);
      endPoints.add(endPoint);
    }
    assert !endPoints.isEmpty() : "No endpoints found";
   
    ClusterConfiguration config = new ClusterConfiguration(versionNumber, endPoints);
View Full Code Here

  @Override
  public void run(){
    try{
      getLogger().info("Starting configuration poller.");
      String newConfigResponse = null;
      NodeEndPoint endpointToGetConfig = null;
   
      Collection<NodeEndPoint> endpoints = client.getAvailableNodeEndPoints();
      if(endpoints.isEmpty()){
        //If no nodes are available status, then get all the endpoints. This provides an
        //oppurtunity to re-resolve the hostname by recreating InetSocketAddress instance in "NodeEndPoint".getInetSocketAddress().
        endpoints = client.getAllNodeEndPoints();
      }
      currentIndex = (currentIndex+1)%endpoints.size();
      Iterator<NodeEndPoint> iterator = endpoints.iterator();
      for(int i =0;i<currentIndex;i++){
        iterator.next();
      }
     
      endpointToGetConfig = iterator.next();
      InetSocketAddress socketAddressToGetConfig = endpointToGetConfig.getInetSocketAddress();
     
      getLogger().info("Endpoint to use for configuration access in this poll " + endpointToGetConfig.toString());
     
      int retryCount = 0;
     
      //If client is not initialized for the first time with the list of cache nodes, keep retrying till the call succeeds.
      //To avoid execessive calls, there is a small retry interval between the retry attempts.
      while(retryCount < MAX_RETRY_ATTEMPT || !client.isConfigurationInitialized()){
        try{
          if(client.isConfigurationProtocolSupported()){
            try{
              newConfigResponse = (String)client.getConfig(socketAddressToGetConfig,
                                                                                         ConfigurationType.CLUSTER,
                                                                                         configTranscoder);
            }catch(OperationNotSupportedException e){
              //Fallback to key based config access.
              client.setIsConfigurationProtocolSupported(false);
              continue;
            }
          } else {
            newConfigResponse = (String)client.get(socketAddressToGetConfig,
                                                                             ConfigurationType.CLUSTER.getValueWithNameSpace(),
                                                                             configTranscoder);
          }
         
          //Operation succeeded and break out of the loop.
          break;
        }catch(OperationTimeoutException e){
          retryCount++;
          try{
            Thread.sleep(RETRY_INTERVAL);
          }catch (InterruptedException ex) {
            getLogger().warn("Poller thread interrupted during the retry interval for config call. Continue with retry.", ex);
          }
          if(retryCount >= MAX_RETRY_ATTEMPT && client.isConfigurationInitialized()) {
            getLogger().warn("Max retry attempt reached for config call. Stopping the current poll cycle.", e);
            return;
          }else if(retryCount == MAX_RETRY_ATTEMPT - 1){
            //Fall back to config endpoint
            socketAddressToGetConfig = client.getConfigurationNode().getInetSocketAddress();
          }else {
            //Reresolve on retry attempt
            socketAddressToGetConfig = endpointToGetConfig.getInetSocketAddress(true);
          }
        }
      }
     
      if(newConfigResponse == null){
        getLogger().warn("The configuration is null in the server " + endpointToGetConfig.getHostName());
        trackPollingError();
        return;
      }
     
      getLogger().debug("Retrieved configuration value:" + newConfigResponse);
View Full Code Here

    //The conversion from SocketAddress to NodeEndPoint is done for backwards compatibility.
    List<NodeEndPoint> endPoints = new ArrayList<NodeEndPoint>(socketAddressList.size());
    for(InetSocketAddress sa : socketAddressList){
      InetAddress addr = sa.getAddress();
      String ipAddress = (addr != null) ? addr.getHostAddress() : null;
      NodeEndPoint endPoint = new NodeEndPoint(sa.getHostName(), ipAddress, sa.getPort());
      endPoints.add(endPoint);
    }
   
    List<MemcachedNode> connections = createConnections(endPoints);
    locator = f.createLocator(connections);
View Full Code Here

      for(NodeEndPoint newEndPoint : endPoints){
        Iterator<MemcachedNode> curentNodesIterator = currentNodes.iterator();
        boolean foundMatch = false;
        while(curentNodesIterator.hasNext()){
          MemcachedNode currentNode = curentNodesIterator.next();
          NodeEndPoint endPointFromCurrentNode = currentNode.getNodeEndPoint();
         
          if(endPointFromCurrentNode.getHostName().equals(newEndPoint.getHostName()) &&
               endPointFromCurrentNode.getPort() == newEndPoint.getPort()){
         
            //Reconnect if the Ip address changes for the hostname.
            //1) ip address do not match
            //2) current ip address is null and the new config has a ip address.
            if( (endPointFromCurrentNode.getIpAddress() != null  &&  !endPointFromCurrentNode.getIpAddress().equals(newEndPoint.getIpAddress()))
               ||
               (endPointFromCurrentNode.getIpAddress() == null  && newEndPoint.getIpAddress() != null)
              ){
              currentNode.setNodeEndPoint(newEndPoint);
              queueReconnect(currentNode);
            }
           
View Full Code Here

  protected void addOperation(final InetSocketAddress addr, final Operation o) {

    Collection<MemcachedNode> nodes = locator.getAll();
    boolean foundNode = false;
    for(MemcachedNode node : nodes){
      NodeEndPoint endpoint = node.getNodeEndPoint();
      String hostName = addr.getHostName();
      String ipAddress = null;
      if(addr.getAddress() != null){
        ipAddress = addr.getAddress().getHostAddress();
      }
     
      if((hostName != null && hostName.equals(endpoint.getHostName()))
          || (ipAddress != null && ipAddress.equals(endpoint.getIpAddress())) ){
        addOperation(node, o);
        foundNode = true;
        break;
      }
    }
View Full Code Here

TOP

Related Classes of net.spy.memcached.config.NodeEndPoint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.