package io.kubernetes.client.examples;

import io.kubernetes.client.ApiClient;
import io.kubernetes.client.ApiException;
import io.kubernetes.client.Configuration;
import io.kubernetes.client.apis.CoreV1Api;
import io.kubernetes.client.informer.*;
import io.kubernetes.client.informer.cache.Lister;
import io.kubernetes.client.models.V1Node;
import io.kubernetes.client.models.V1NodeList;
import io.kubernetes.client.models.V1ObjectMeta;
import io.kubernetes.client.util.CallGeneratorParams;
import io.kubernetes.client.util.Config;

public class InformerExample {
  public static void main(String[] args) throws Exception {

    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);

    SharedInformerFactory factory = new SharedInformerFactory();

    CoreV1Api coreV1Api = new CoreV1Api();

    // Node informer
    SharedIndexInformer<V1Node> nodeInformer =
        factory.sharedIndexInformerFor(
            (CallGeneratorParams params) -> {
              try {
                return coreV1Api.listNodeCall(
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    params.resourceVersion,
                    params.timeoutSeconds,
                    params.watch,
                    null,
                    null);
              } catch (ApiException e) {
                throw new RuntimeException(e);
              }
            },
            V1Node.class,
            V1NodeList.class);

    nodeInformer.addEventHandler(
        new ResourceEventHandler<V1Node>() {
          @Override
          public void onAdd(V1Node node) {
            System.out.printf("%s node added!\n", node.getMetadata().getName());
          }

          @Override
          public void onUpdate(V1Node oldNode, V1Node newNode) {
            System.out.printf(
                "%s => %s node updated!\n",
                oldNode.getMetadata().getName(), newNode.getMetadata().getName());
          }

          @Override
          public void onDelete(V1Node node, boolean deletedFinalStateUnknown) {
            System.out.printf("%s node deleted!\n", node.getMetadata().getName());
          }
        });

    factory.startAllRegisteredInformers();

    V1Node nodeToCreate = new V1Node();
    V1ObjectMeta metadata = new V1ObjectMeta();
    metadata.setName("noxu");
    nodeToCreate.setMetadata(metadata);
    String s = coreV1Api.getApiClient().getJSON().serialize(nodeToCreate);
    V1Node createdNode = coreV1Api.createNode(nodeToCreate, null, null, null);
    Thread.sleep(3000);

    Lister<V1Node> nodeLister = new Lister<V1Node>(nodeInformer.getIndexer());
    V1Node node = nodeLister.get("noxu");
    System.out.printf("noxu created! %s\n", node.getMetadata().getCreationTimestamp());
    factory.stopAllRegisteredInformers();
    Thread.sleep(3000);
    System.out.println("informer stopped..");
  }
}

@@ -526,16 +526,265 @@
 Config;%0A
+import java.util.concurrent.TimeUnit;%0A%0A/**%0A * A simple example of how to use the Java API%0A *%0A * %3Cp%3EEasiest way to run this: mvn exec:java%0A * -Dexec.mainClass=%22io.kubernetes.client.examples.InformerExample%22%0A *%0A * %3Cp%3EFrom inside $REPO_DIR/examples%0A */
 %0Apublic 
@@ -867,17 +867,16 @@
 ption %7B%0A
-%0A
     ApiC
@@ -910,24 +910,89 @@
 ltClient();%0A
+    client.getHttpClient().setReadTimeout(60, TimeUnit.SECONDS);%0A
     Configur
@@ -2771,83 +2771,8 @@
 a);%0A
-    String s = coreV1Api.getApiClient().getJSON().serialize(nodeToCreate);%0A
     

Add timeout configuration to InformerExample