From de36e49c01f7e0658afffbfdffa145a876557986 Mon Sep 17 00:00:00 2001 From: jpdahlke Date: Thu, 1 Aug 2024 09:54:36 -0400 Subject: [PATCH] errorprone :: ConstantField - more core classes (#864) --- src/main/java/emissary/command/AgentsCommand.java | 2 +- src/main/java/emissary/command/ConfigCommand.java | 4 ++-- src/main/java/emissary/command/TopologyCommand.java | 4 ++-- .../java/emissary/config/ServiceConfigGuide.java | 12 ++++++------ src/main/java/emissary/pickup/PickUpSpace.java | 2 +- .../java/emissary/pickup/file/FileDataServer.java | 7 +++---- .../java/emissary/pickup/file/FilePickUpPlace.java | 7 ++++--- .../emissary/place/ServiceProviderPlaceTest.java | 6 +++--- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/emissary/command/AgentsCommand.java b/src/main/java/emissary/command/AgentsCommand.java index 24301465a7..e9629af8d2 100644 --- a/src/main/java/emissary/command/AgentsCommand.java +++ b/src/main/java/emissary/command/AgentsCommand.java @@ -12,7 +12,7 @@ subcommands = {HelpCommand.class}) public class AgentsCommand extends MonitorCommand { - public static String COMMAND_NAME = "agents"; + public static final String COMMAND_NAME = "agents"; @Override public String getCommandName() { diff --git a/src/main/java/emissary/command/ConfigCommand.java b/src/main/java/emissary/command/ConfigCommand.java index 46c4cb4d8b..78b6f691d2 100644 --- a/src/main/java/emissary/command/ConfigCommand.java +++ b/src/main/java/emissary/command/ConfigCommand.java @@ -22,8 +22,8 @@ public class ConfigCommand extends HttpCommand { @Spec private CommandSpec spec; private static final Logger logger = LoggerFactory.getLogger(ConfigCommand.class); - public static int DEFAULT_PORT = 8001; - public static String COMMAND_NAME = "config"; + public static final int DEFAULT_PORT = 8001; + public static final String COMMAND_NAME = "config"; @Option(names = {"--place"}, description = "fully-qualified place", arity = "1", required = true) private String place; diff --git a/src/main/java/emissary/command/TopologyCommand.java b/src/main/java/emissary/command/TopologyCommand.java index f2ec6baf51..14e12889c4 100644 --- a/src/main/java/emissary/command/TopologyCommand.java +++ b/src/main/java/emissary/command/TopologyCommand.java @@ -15,8 +15,8 @@ public class TopologyCommand extends HttpCommand { static final Logger LOG = LoggerFactory.getLogger(TopologyCommand.class); - public static String COMMAND_NAME = "topology"; - public static int DEFAULT_PORT = 8001; + public static final String COMMAND_NAME = "topology"; + public static final int DEFAULT_PORT = 8001; @Override public String getCommandName() { diff --git a/src/main/java/emissary/config/ServiceConfigGuide.java b/src/main/java/emissary/config/ServiceConfigGuide.java index 66288d922b..bb0b2eeea9 100755 --- a/src/main/java/emissary/config/ServiceConfigGuide.java +++ b/src/main/java/emissary/config/ServiceConfigGuide.java @@ -50,7 +50,7 @@ public class ServiceConfigGuide implements Configurator, Serializable { // Used on the RHS to make a null assignment // Obsolete, use @{NULL} - protected String NULL_VALUE = ""; + protected static final String NULL_VALUE = ""; // Hold all service specific parameters in a list protected List p_service_parameters = new ArrayList<>(); @@ -76,12 +76,12 @@ public class ServiceConfigGuide implements Configurator, Serializable { protected Map values = new HashMap<>(); // Get this once per jvm - private static String THIS_HOST_NAME = "localhost"; + private static String hostname = "localhost"; // Grab the hostname for @{HOST} replacement static { try { - THIS_HOST_NAME = InetAddress.getLocalHost().getCanonicalHostName(); + hostname = InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException e) { logger.error("Error getting host name", e); } @@ -174,7 +174,7 @@ protected void initializeValues() { this.values.put("PROJECT_BASE", ConfigUtil.getProjectBase()); this.values.put("OUTPUT_ROOT", ConfigUtil.getOutputRoot()); this.values.put("BIN_DIR", ConfigUtil.getBinDir()); - this.values.put("HOST", THIS_HOST_NAME); + this.values.put("HOST", hostname); this.values.put("/", File.separator); this.values.put("TMPDIR", System.getProperty("java.io.tmpdir")); this.values.put("NULL", null); @@ -374,9 +374,9 @@ protected String handleReplacements(final String svalArg, final String filename, } // This is obsolete - if (sval != null && sval.equals(this.NULL_VALUE)) { + if (sval != null && sval.equals(NULL_VALUE)) { sval = null; - logger.debug("Using {} is deprecated, please just use {}NULL{}", this.NULL_VALUE, VSTART, VEND); + logger.debug("Using {} is deprecated, please just use {}NULL{}", NULL_VALUE, VSTART, VEND); } return sval; } diff --git a/src/main/java/emissary/pickup/PickUpSpace.java b/src/main/java/emissary/pickup/PickUpSpace.java index d89afdaae0..0aeff09655 100755 --- a/src/main/java/emissary/pickup/PickUpSpace.java +++ b/src/main/java/emissary/pickup/PickUpSpace.java @@ -30,7 +30,7 @@ public abstract class PickUpSpace extends PickUpPlace implements IPickUpSpace { protected Map pendingBundles = new HashMap<>(); // Number of consecutive take errors that cause space to close - protected int TAKE_ERROR_MAX = 10; + protected static final int TAKE_ERROR_MAX = 10; /** * Create using default configuration diff --git a/src/main/java/emissary/pickup/file/FileDataServer.java b/src/main/java/emissary/pickup/file/FileDataServer.java index f4434dd062..81c091f4b0 100755 --- a/src/main/java/emissary/pickup/file/FileDataServer.java +++ b/src/main/java/emissary/pickup/file/FileDataServer.java @@ -93,17 +93,16 @@ public void run() { // Process files currently in the pickup directory, list // the first bundleSize in a batch String[] fileList = theDirectory.list(new FilenameFilter() { - final int MAXFILESTOLIST = bundleSize; + final int maxFileToList = bundleSize; int filesInList = 0; @Override public boolean accept(File dir, String name) { - return !name.startsWith(".") && ++filesInList <= MAXFILESTOLIST; + return !name.startsWith(".") && ++filesInList <= maxFileToList; } }); - // Rename all of the selected files out of the - // polling area + // Rename all the selected files out of the polling area for (int i = 0; fileList != null && i < fileList.length; i++) { File f = new File(theDataDir, fileList[i]); diff --git a/src/main/java/emissary/pickup/file/FilePickUpPlace.java b/src/main/java/emissary/pickup/file/FilePickUpPlace.java index 920ed2b813..5741d3ec19 100755 --- a/src/main/java/emissary/pickup/file/FilePickUpPlace.java +++ b/src/main/java/emissary/pickup/file/FilePickUpPlace.java @@ -19,7 +19,8 @@ public class FilePickUpPlace extends PickUpPlace implements IPickUp { protected List theDataServer = new ArrayList<>(); // How many files the FileDataServer should group - protected int BUNDLE_SIZE = 20; + protected static final int DEFAULT_BUNDLE_SIZE = 20; + protected int bundleSize; // Input directories to poll protected String[] inputDataDirs; @@ -53,7 +54,7 @@ public FilePickUpPlace(String configInfo, String dir, String placeLoc) throws IO */ protected void configurePlace() { pollingInterval = configG.findIntEntry("POLLING_INTERVAL", pollingInterval); - BUNDLE_SIZE = configG.findIntEntry("BUNDLE_SIZE", BUNDLE_SIZE); + bundleSize = configG.findIntEntry("BUNDLE_SIZE", DEFAULT_BUNDLE_SIZE); List params = configG.findEntries("INPUT_DATA"); inputDataDirs = params.toArray(new String[0]); } @@ -116,7 +117,7 @@ public void startDataServer() { FileDataServer fds = new FileDataServer(inputDataDirs[i], this, pollingInterval); // Tell it how many files to pick up at a time - fds.setBundleSize(BUNDLE_SIZE); + fds.setBundleSize(bundleSize); // Set priority below agent processing fds.setPriority(Thread.NORM_PRIORITY - 1); diff --git a/src/test/java/emissary/place/ServiceProviderPlaceTest.java b/src/test/java/emissary/place/ServiceProviderPlaceTest.java index b1897f7ef2..526d4dbafd 100644 --- a/src/test/java/emissary/place/ServiceProviderPlaceTest.java +++ b/src/test/java/emissary/place/ServiceProviderPlaceTest.java @@ -84,7 +84,7 @@ class ServiceProviderPlaceTest extends UnitTest { + "SERVICE_QUALITY = 90\n" + "SERVICE_PROXY = \"TEST_SERVICE_PROXY\"\n" + "SERVICE_PROXY_DENY = \"TEST_SERVICE_PROXY\"\n" + "SERVICE_PROXY_DENY != \"*\"\n").getBytes(); - String CFGDIR = System.getProperty(ConfigUtil.CONFIG_DIR_PROPERTY); + String configDir = System.getProperty(ConfigUtil.CONFIG_DIR_PROPERTY); @Override @BeforeEach @@ -228,9 +228,9 @@ private void runFileConfiguredTest(boolean usePackage, int ctorType) throws IOEx Path cfg; // Write out the config data to the temp config dir if (usePackage) { - cfg = Paths.get(CFGDIR, thisPackage.getName() + ".MyFileConfigedTestPlace" + ConfigUtil.CONFIG_FILE_ENDING); + cfg = Paths.get(configDir, thisPackage.getName() + ".MyFileConfigedTestPlace" + ConfigUtil.CONFIG_FILE_ENDING); } else { - cfg = Paths.get(CFGDIR, "MyFileConfigedTestPlace" + ConfigUtil.CONFIG_FILE_ENDING); + cfg = Paths.get(configDir, "MyFileConfigedTestPlace" + ConfigUtil.CONFIG_FILE_ENDING); } try (OutputStream fos = Files.newOutputStream(cfg)) {