LocalFileSpanReceiver extends SpanReceiver { public static String getUniqueLocalTraceFileName() { String tmp = System.getProperty("java.io.tmpdir", "/tmp"); String nonce = null; BufferedReader reader = null; try { reader = new BufferedReader( new InputStreamReader(new FileInputStream("/proc/self/stat"), "UTF-8")); String line = reader.readLine(); if (line == null) { throw new EOFException(); } nonce = line.split(" ")[0]; } catch (IOException e) { } finally { if (reader != null) { try { reader.close(); } catch(IOException e) { LOG.warn("Exception in closing " + reader, e); } } } if (nonce == null) { nonce = UUID.randomUUID().toString(); } return new File(tmp, nonce).getAbsolutePath(); } LocalFileSpanReceiver(HTraceConfiguration conf); @Override void receiveSpan(Span span); @Override void close(); static String getUniqueLocalTraceFileName(); static final String PATH_KEY; static final String CAPACITY_KEY; static final int CAPACITY_DEFAULT; }
@Test public void testUniqueLocalTraceFileName() { String filename1 = LocalFileSpanReceiver.getUniqueLocalTraceFileName(); String filename2 = LocalFileSpanReceiver.getUniqueLocalTraceFileName(); boolean eq = filename1.equals(filename2); if (System.getProperty("os.name").startsWith("Linux")) { assertTrue(eq); } else { assertFalse(eq); } }