001/*
002 * Util.java
003 *
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *     http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020
021
022package org.apache.hadoop.metrics.spi;
023
024import java.net.InetSocketAddress;
025import java.util.ArrayList;
026import java.util.List;
027
028import org.apache.hadoop.classification.InterfaceAudience;
029import org.apache.hadoop.classification.InterfaceStability;
030import org.apache.hadoop.net.NetUtils;
031
032/**
033 * Static utility methods
034 *
035 * @deprecated Use org.apache.hadoop.metrics2 package instead.
036 */
037@Deprecated
038@InterfaceAudience.Public
039@InterfaceStability.Evolving
040public class Util {
041    
042  /**
043   * This class is not intended to be instantiated
044   */
045  private Util() {}
046    
047  /**
048   * Parses a space and/or comma separated sequence of server specifications
049   * of the form <i>hostname</i> or <i>hostname:port</i>.  If 
050   * the specs string is null, defaults to localhost:defaultPort.
051   * 
052   * @return a list of InetSocketAddress objects.
053   */
054  public static List<InetSocketAddress> parse(String specs, int defaultPort) {
055    List<InetSocketAddress> result = new ArrayList<InetSocketAddress>(1);
056    if (specs == null) {
057      result.add(new InetSocketAddress("localhost", defaultPort));
058    }
059    else {
060      String[] specStrings = specs.split("[ ,]+");
061      for (String specString : specStrings) {
062        result.add(NetUtils.createSocketAddr(specString, defaultPort));
063      }
064    }
065    return result;
066  }
067    
068}