Class Graphite

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class Graphite
    extends java.lang.Object
    implements java.io.Closeable
    A client to a Carbon server.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.net.InetSocketAddress address  
      private java.nio.charset.Charset charset  
      private int failures  
      private java.net.Socket socket  
      private javax.net.SocketFactory socketFactory  
      private static java.nio.charset.Charset UTF_8  
      private static java.util.regex.Pattern WHITESPACE  
      private java.io.Writer writer  
    • Constructor Summary

      Constructors 
      Constructor Description
      Graphite​(java.net.InetSocketAddress address)
      Creates a new client which connects to the given address using the default SocketFactory.
      Graphite​(java.net.InetSocketAddress address, javax.net.SocketFactory socketFactory)
      Creates a new client which connects to the given address and socket factory.
      Graphite​(java.net.InetSocketAddress address, javax.net.SocketFactory socketFactory, java.nio.charset.Charset charset)
      Creates a new client which connects to the given address and socket factory using the given character set.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void connect()
      Connects to the server.
      int getFailures()
      Returns the number of failed writes to the server.
      protected java.lang.String sanitize​(java.lang.String s)  
      void send​(java.lang.String name, java.lang.String value, long timestamp)
      Sends the given measurement to the server.
      • Methods inherited from class java.lang.Object

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

      • WHITESPACE

        private static final java.util.regex.Pattern WHITESPACE
      • UTF_8

        private static final java.nio.charset.Charset UTF_8
      • address

        private final java.net.InetSocketAddress address
      • socketFactory

        private final javax.net.SocketFactory socketFactory
      • charset

        private final java.nio.charset.Charset charset
      • socket

        private java.net.Socket socket
      • writer

        private java.io.Writer writer
      • failures

        private int failures
    • Constructor Detail

      • Graphite

        public Graphite​(java.net.InetSocketAddress address)
        Creates a new client which connects to the given address using the default SocketFactory.
        Parameters:
        address - the address of the Carbon server
      • Graphite

        public Graphite​(java.net.InetSocketAddress address,
                        javax.net.SocketFactory socketFactory)
        Creates a new client which connects to the given address and socket factory.
        Parameters:
        address - the address of the Carbon server
        socketFactory - the socket factory
      • Graphite

        public Graphite​(java.net.InetSocketAddress address,
                        javax.net.SocketFactory socketFactory,
                        java.nio.charset.Charset charset)
        Creates a new client which connects to the given address and socket factory using the given character set.
        Parameters:
        address - the address of the Carbon server
        socketFactory - the socket factory
        charset - the character set used by the server
    • Method Detail

      • connect

        public void connect()
                     throws java.lang.IllegalStateException,
                            java.io.IOException
        Connects to the server.
        Throws:
        java.lang.IllegalStateException - if the client is already connected
        java.io.IOException - if there is an error connecting
      • send

        public void send​(java.lang.String name,
                         java.lang.String value,
                         long timestamp)
                  throws java.io.IOException
        Sends the given measurement to the server.
        Parameters:
        name - the name of the metric
        value - the value of the metric
        timestamp - the timestamp of the metric
        Throws:
        java.io.IOException - if there was an error sending the metric
      • getFailures

        public int getFailures()
        Returns the number of failed writes to the server.
        Returns:
        the number of failed writes to the server
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • sanitize

        protected java.lang.String sanitize​(java.lang.String s)