Class Watch<T>

java.lang.Object
io.kubernetes.client.util.Watch<T>
All Implemented Interfaces:
Watchable<T>, Closeable, AutoCloseable, Iterable<Watch.Response<T>>, Iterator<Watch.Response<T>>

public class Watch<T> extends Object implements Watchable<T>, Closeable
Watch class implements watch mechansim of kubernetes. For every list API call with a watch parameter you should be able to pass its call to this class and watch changes to that list. For example CoreV1Api.listNamespace has watch parameter, so you can create a call using CoreV1Api.listNamespaceCall and set watch to True and watch the changes to namespaces.
  • Constructor Details

    • Watch

      protected Watch(io.kubernetes.client.openapi.JSON json, okhttp3.ResponseBody body, Type watchType, okhttp3.Call call)
  • Method Details

    • createWatch

      public static <T> Watch<T> createWatch(io.kubernetes.client.openapi.ApiClient client, okhttp3.Call call, Type watchType) throws io.kubernetes.client.openapi.ApiException
      Creates a watch on a TYPENAME (T) using an API Client and a Call object.
      Type Parameters:
      T - TYPENAME.
      Parameters:
      client - the API client
      call - the call object returned by api.{ListOperation}Call(...) method. Make sure watch flag is set in the call.
      watchType - The type of the WatchResponse<T>. Use something like new TypeToken<Watch.Response<TYPENAME>>(){}.getType()
      Returns:
      Watch object on TYPENAME
      Throws:
      io.kubernetes.client.openapi.ApiException - on IO exceptions.
    • next

      public Watch.Response<T> next()
      Specified by:
      next in interface Iterator<T>
    • isStatus

      protected boolean isStatus(String line) throws IOException
      Throws:
      IOException
    • parseLine

      protected Watch.Response<T> parseLine(String line) throws IOException
      Throws:
      IOException
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<T>
    • iterator

      public Iterator<Watch.Response<T>> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<T>
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException