test_class.file: proxy/src/test/java/com/wavefront/agent/ProxyUtilTest.java
test_class.identifier: ProxyUtilTest
test_case.body: @Test
    public void testLoadProxyIdFromFile() throws Exception {
      UUID proxyId = UUID.randomUUID();
      String path = File.createTempFile("proxyTestIdFile", null).getPath();
      Files.asCharSink(new File(path), Charsets.UTF_8).write(proxyId.toString());
      UUID uuid = ProxyUtil.getOrCreateProxyIdFromFile(path);
      assertEquals(proxyId, uuid);
  
      path = File.createTempFile("proxyTestIdFile", null).getPath() + ".id";
      uuid = ProxyUtil.getOrCreateProxyIdFromFile(path);
      assertEquals(uuid, ProxyUtil.getOrCreateProxyIdFromFile(path));
    }
test_case.class_method_signature: ProxyUtilTest.testLoadProxyIdFromFile()
test_case.full_signature: @Test public void testLoadProxyIdFromFile()
test_case.identifier: testLoadProxyIdFromFile
test_case.invocations: randomUUID getPath createTempFile write asCharSink toString getOrCreateProxyIdFromFile assertEquals getPath createTempFile getOrCreateProxyIdFromFile assertEquals getOrCreateProxyIdFromFile
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testLoadProxyIdFromFile()
focal_class.declarator: logger = Logger.getLogger("proxy")
focal_class.modifier: protected static final
focal_class.original_string: protected static final Logger logger = Logger.getLogger("proxy");
focal_class.type: Logger
focal_class.var_name: logger
focal_class.file: proxy/src/main/java/com/wavefront/agent/ProxyUtil.java
focal_class.identifier: ProxyUtil
focal_class.class_method_signature: ProxyUtil.ProxyUtil()
focal_class.full_signature: private  ProxyUtil()
focal_class.identifier: ProxyUtil
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.signature:  ProxyUtil()
focal_class.class_method_signature: ProxyUtil.getOrCreateProxyId(ProxyConfig proxyConfig)
focal_class.full_signature: static UUID getOrCreateProxyId(ProxyConfig proxyConfig)
focal_class.identifier: getOrCreateProxyId
focal_class.modifiers: static
focal_class.parameters: (ProxyConfig proxyConfig)
focal_class.return: UUID
focal_class.signature: UUID getOrCreateProxyId(ProxyConfig proxyConfig)
focal_class.class_method_signature: ProxyUtil.getOrCreateProxyIdFromFile(@Nullable String idFileName)
focal_class.full_signature: static UUID getOrCreateProxyIdFromFile(@Nullable String idFileName)
focal_class.identifier: getOrCreateProxyIdFromFile
focal_class.modifiers: static
focal_class.parameters: (@Nullable String idFileName)
focal_class.return: UUID
focal_class.signature: UUID getOrCreateProxyIdFromFile(@Nullable String idFileName)
focal_class.class_method_signature: ProxyUtil.createInitializer(ChannelHandler channelHandler,
                                                               int port, int messageMaxLength,
                                                               int httpRequestBufferSize,
                                                               int idleTimeout,
                                                               @Nullable SslContext sslContext,
                                                               @Nullable CorsConfig corsConfig)
focal_class.full_signature: static ChannelInitializer<SocketChannel> createInitializer(ChannelHandler channelHandler,
                                                               int port, int messageMaxLength,
                                                               int httpRequestBufferSize,
                                                               int idleTimeout,
                                                               @Nullable SslContext sslContext,
                                                               @Nullable CorsConfig corsConfig)
focal_class.identifier: createInitializer
focal_class.modifiers: static
focal_class.parameters: (ChannelHandler channelHandler,
                                                               int port, int messageMaxLength,
                                                               int httpRequestBufferSize,
                                                               int idleTimeout,
                                                               @Nullable SslContext sslContext,
                                                               @Nullable CorsConfig corsConfig)
focal_class.return: ChannelInitializer<SocketChannel>
focal_class.signature: ChannelInitializer<SocketChannel> createInitializer(ChannelHandler channelHandler,
                                                               int port, int messageMaxLength,
                                                               int httpRequestBufferSize,
                                                               int idleTimeout,
                                                               @Nullable SslContext sslContext,
                                                               @Nullable CorsConfig corsConfig)
focal_class.class_method_signature: ProxyUtil.createInitializer(
        Iterable<Supplier<ChannelHandler>> channelHandlerSuppliers, int port, int idleTimeout,
        @Nullable SslContext sslContext)
focal_class.full_signature: static ChannelInitializer<SocketChannel> createInitializer(
        Iterable<Supplier<ChannelHandler>> channelHandlerSuppliers, int port, int idleTimeout,
        @Nullable SslContext sslContext)
focal_class.identifier: createInitializer
focal_class.modifiers: static
focal_class.parameters: (
        Iterable<Supplier<ChannelHandler>> channelHandlerSuppliers, int port, int idleTimeout,
        @Nullable SslContext sslContext)
focal_class.return: ChannelInitializer<SocketChannel>
focal_class.signature: ChannelInitializer<SocketChannel> createInitializer(
        Iterable<Supplier<ChannelHandler>> channelHandlerSuppliers, int port, int idleTimeout,
        @Nullable SslContext sslContext)
focal_method.body: static UUID getOrCreateProxyIdFromFile(@Nullable String idFileName) {
      File proxyIdFile;
      UUID proxyId = UUID.randomUUID();
      if (idFileName != null) {
        proxyIdFile = new File(idFileName);
      } else {
        File userHome = new File(System.getProperty("user.home"));
        if (!userHome.exists() || !userHome.isDirectory()) {
          throw new RuntimeException("Cannot read from user.home, quitting");
        }
        File configDirectory = new File(userHome, ".dshell");
        if (configDirectory.exists()) {
          if (!configDirectory.isDirectory()) {
            throw new RuntimeException(configDirectory + " must be a directory!");
          }
        } else {
          if (!configDirectory.mkdir()) {
            throw new RuntimeException("Cannot create .dshell directory under " + userHome);
          }
        }
        proxyIdFile = new File(configDirectory, "id");
      }
      if (proxyIdFile.exists()) {
        if (proxyIdFile.isFile()) {
          try {
            proxyId = UUID.fromString(Objects.requireNonNull(Files.asCharSource(proxyIdFile,
                Charsets.UTF_8).readFirstLine()));
            logger.info("Proxy Id read from file: " + proxyId);
          } catch (IllegalArgumentException ex) {
            throw new RuntimeException("Cannot read proxy id from " + proxyIdFile +
                ", content is malformed");
          } catch (IOException e) {
            throw new RuntimeException("Cannot read from " + proxyIdFile, e);
          }
        } else {
          throw new RuntimeException(proxyIdFile + " is not a file!");
        }
      } else {
        logger.info("Proxy Id created: " + proxyId);
        try {
          Files.asCharSink(proxyIdFile, Charsets.UTF_8).write(proxyId.toString());
        } catch (IOException e) {
          throw new RuntimeException("Cannot write to " + proxyIdFile);
        }
      }
      return proxyId;
    }
focal_method.class_method_signature: ProxyUtil.getOrCreateProxyIdFromFile(@Nullable String idFileName)
focal_method.full_signature: static UUID getOrCreateProxyIdFromFile(@Nullable String idFileName)
focal_method.identifier: getOrCreateProxyIdFromFile
focal_method.invocations: randomUUID getProperty exists isDirectory exists isDirectory mkdir exists isFile fromString requireNonNull readFirstLine asCharSource info info write asCharSink toString
focal_method.modifiers: static
focal_method.parameters: (@Nullable String idFileName)
focal_method.return: UUID
focal_method.signature: UUID getOrCreateProxyIdFromFile(@Nullable String idFileName)