Package jnr.netdb

Class Service


  • public final class Service
    extends java.lang.Object
    Holds information about TCP and UDP services on a host.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  Service.ServicesDBSingletonHolder
      Holds the global lazily-loaded instance of the ServicesDB
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Collection<java.lang.String> aliases
      All the aliases for this service
      private int port
      TCP or UDP port number
      (package private) java.lang.String proto
      Protocol to use
      private java.lang.String serviceName
      Official service name
    • Constructor Summary

      Constructors 
      Constructor Description
      Service​(java.lang.String name, int port, java.lang.String proto, java.util.Collection<java.lang.String> aliases)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Collection<java.lang.String> getAliases()
      Gets a list of aliases this Service is also known as.
      static java.util.Collection<Service> getAllServices()
      Returns a list of all services.
      java.lang.String getName()
      Returns the official IANA name of this Service
      int getPort()
      Returns the official IANA port for this Service
      static Service getServiceByName​(java.lang.String name, java.lang.String proto)
      Locates a service by name and protocol.
      static Service getServiceByPort​(int port, java.lang.String proto)
      Locates a service by port and protocol.
      private static ServicesDB getServicesDB()
      Returns the currently loaded ServicesDB
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • serviceName

        private final java.lang.String serviceName
        Official service name
      • port

        private final int port
        TCP or UDP port number
      • proto

        final java.lang.String proto
        Protocol to use
      • aliases

        private final java.util.Collection<java.lang.String> aliases
        All the aliases for this service
    • Constructor Detail

      • Service

        Service​(java.lang.String name,
                int port,
                java.lang.String proto,
                java.util.Collection<java.lang.String> aliases)
    • Method Detail

      • getServiceByName

        public static final Service getServiceByName​(java.lang.String name,
                                                     java.lang.String proto)
        Locates a service by name and protocol.
        Parameters:
        name - the official IANA name for the service, or an alias.
        proto - the protocol for the service. Usually "tcp" or "udp".
        Returns:
        a Service instance, or null if the service could not be found.
      • getServiceByPort

        public static final Service getServiceByPort​(int port,
                                                     java.lang.String proto)
        Locates a service by port and protocol.
        Parameters:
        port - the TCP or UDP port of the service.
        proto - the protocol for the service. Usually "tcp" or "udp".
        Returns:
        a Service instance, or null if the service could not be found.
      • getAllServices

        public static final java.util.Collection<Service> getAllServices()
        Returns a list of all services.
        Returns:
        a Collection of Service instances.
      • getName

        public final java.lang.String getName()
        Returns the official IANA name of this Service
        Returns:
        The name of this Service as a String
      • getPort

        public final int getPort()
        Returns the official IANA port for this Service
        Returns:
        The port for this Service as an int
      • getAliases

        public final java.util.Collection<java.lang.String> getAliases()
        Gets a list of aliases this Service is also known as.
        Returns:
        A Collection of Strings for aliases this Service
      • getServicesDB

        private static final ServicesDB getServicesDB()
        Returns the currently loaded ServicesDB
        Returns:
        an instance of ServicesDB
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object