All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.spotify.helios.serviceregistration.ServiceRegistration Maven / Gradle / Ivy

There is a newer version: 0.9.283
Show newest version
/*
 * Copyright (c) 2014 Spotify AB.
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package com.spotify.helios.serviceregistration;

import com.google.common.base.Objects;

import java.util.ArrayList;
import java.util.List;

import static java.util.Collections.unmodifiableList;

/**
 * A list of endpoints to for service registration.
 */
public class ServiceRegistration {

  private final List endpoints;

  public ServiceRegistration(List endpoints) {
    this.endpoints = unmodifiableList(new ArrayList<>(endpoints));
  }

  public List getEndpoints() {
    return endpoints;
  }

  public static Builder newBuilder() {
    return new Builder();
  }

  public static class Builder {

    private List endpoints = new ArrayList<>();

    @Deprecated
    public Builder endpoint(final String name,
                            final String protocol,
                            final int port) {
      endpoints.add(new Endpoint(name, protocol, port, "", ""));
      return this;
    }

    public Builder endpoint(final String name,
                            final String protocol,
                            final int port,
                            final String domain,
                            final String host) {
      endpoints.add(new Endpoint(name, protocol, port, domain, host));
      return this;
    }

    public ServiceRegistration build() {
      return new ServiceRegistration(endpoints);
    }
  }

  /**
   * A single service endpoint.
   */
  public static class Endpoint {

    private final String name;
    private final String protocol;
    private final int port;
    private final String domain;
    /** The hostname on which we will advertise this service in service discovery */
    private final String host;

    public Endpoint(final String name, final String protocol, final int port,
                    final String domain, final String host) {
      this.name = name;
      this.protocol = protocol;
      this.port = port;
      this.domain = domain;
      this.host = host;
    }

    public String getHost() {
      return host;
    }

    public String getDomain() {
      return domain;
    }

    public String getName() {
      return name;
    }

    public String getProtocol() {
      return protocol;
    }

    public int getPort() {
      return port;
    }


    @Override
    public String toString() {
      return Objects.toStringHelper(this)
          .add("name", name)
          .add("protocol", protocol)
          .add("port", port)
          .add("domain", domain)
          .add("host", host)
          .toString();
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy