+ /**\r
+ * Template used to generate the URL to issue the GET against\r
+ */\r
+ private static final String POKE_URL_TEMPLATE = "http://%s/internal/fetchProv";\r
+\r
+ private static final Object lock = new Object();\r
+ private static final String CARRIAGE_RETURN = "\n],\n";\r
+\r
+ /**\r
+ * This is a singleton -- there is only one Poker object in the server\r
+ */\r
+ private static Poker poker;\r
+ private long timer1;\r
+ private long timer2;\r
+ private String thisPod; // DNS name of this machine\r
+ private EELFLogger logger;\r
+ private String provString;\r
+\r
+\r
+ private Poker() {\r
+ timer1 = timer2 = 0;\r
+ Timer rolex = new Timer();\r
+ logger = EELFManager.getInstance().getLogger("InternalLog");\r
+ try {\r
+ thisPod = InetAddress.getLocalHost().getHostName();\r
+ } catch (UnknownHostException e) {\r
+ thisPod = "*UNKNOWN_POD*"; // not a major problem\r
+ logger.info("UnknownHostException: Setting thisPod to \"*UNKNOWN_POD*\"", e);\r
+ }\r
+ provString = buildProvisioningString();\r
+\r
+ rolex.scheduleAtFixedRate(this, 0L, 1000L); // Run once a second to check the timers\r
+ }\r
+\r
+ /**\r
+ * Get the singleton Poker object.\r
+ *\r
+ * @return the Poker\r
+ */\r
+ public static synchronized Poker getPoker() {\r
+ if (poker == null) {\r
+ poker = new Poker();\r
+ }\r
+ return poker;\r
+ }\r
+\r
+ /**\r
+ * This method sets the two timers described in the design notes.\r
+ *\r
+ * @param t1 the first timer controls how long to wait after a provisioning request before poking each node This\r
+ * timer can be reset if it has not "gone off".\r
+ * @param t2 the second timer set the outer bound on how long to wait. It cannot be reset.\r
+ */\r
+ public void setTimers(long t1, long t2) {\r
+ synchronized (lock) {\r
+ if (timer1 == 0 || t1 > timer1) {\r
+ timer1 = t1;\r
+ }\r
+ if (timer2 == 0) {\r
+ timer2 = t2;\r
+ }\r
+ }\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug("Poker timers set to " + timer1 + " and " + timer2);\r
+ }\r
+\r