Skip to content

Commit

Permalink
errorprone :: ConstantField - core classes (#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpdahlke authored Aug 1, 2024
1 parent fc5278e commit ad36e1d
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/main/java/emissary/command/Banner.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class Banner {

static String DEFAULT_TEXT = " ________ ________ _____ _____ ___ ________ __\n"
static final String DEFAULT_TEXT = " ________ ________ _____ _____ ___ ________ __\n"
+ "| ___| \\/ |_ _/ ___/ ___|/ _ \\ | ___ \\ \\ / /\n" + "| |__ | . . | | | \\ `--.\\ `--./ /_\\ \\| |_/ /\\ V / \n"
+ "| __|| |\\/| | | | `--. \\`--. \\ _ || / \\ / \n" + "| |___| | | |_| |_/\\__/ /\\__/ / | | || |\\ \\ | | \n"
+ "\\____/\\_| |_/\\___/\\____/\\____/\\_| |_/\\_| \\_| \\_/ \n";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/command/EnvCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class EnvCommand extends HttpCommand {

static final Logger LOG = LoggerFactory.getLogger(EnvCommand.class);

public static int DEFAULT_PORT = 8001;
public static final int DEFAULT_PORT = 8001;

@Option(names = {"--bashable"}, description = "format output for sourcing by bash\nDefault: ${DEFAULT-VALUE}")
private boolean bashable = false;
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/emissary/core/BaseDataObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ public class BaseDataObject implements Serializable, Cloneable, Remote, IBaseDat
protected StringBuilder brokenDocument = null;

// Filetypes that we think are equivalent to no file type at all
protected String[] FILETYPE_EMPTY = {Form.UNKNOWN};

// Filetypes with this suffix are equivalent to no file type at all
protected String FILETYPE_ENDSWITH = "-UNWRAPPED";
protected String[] emptyFileTypes = {Form.UNKNOWN};

/**
* The integer priority of the data object. A lower number is higher priority.
Expand Down Expand Up @@ -1162,12 +1159,12 @@ public boolean setFileTypeIfEmpty(final String v, final String[] empties) {

@Override
public boolean setFileTypeIfEmpty(final String v) {
return setFileTypeIfEmpty(v, this.FILETYPE_EMPTY);
return setFileTypeIfEmpty(v, this.emptyFileTypes);
}

@Override
public boolean isFileTypeEmpty() {
return isFileTypeEmpty(this.FILETYPE_EMPTY);
return isFileTypeEmpty(this.emptyFileTypes);
}

/**
Expand All @@ -1182,7 +1179,7 @@ protected boolean isFileTypeEmpty(@Nullable final String[] empties) {
return true;
}

if (s.endsWith(FILETYPE_ENDSWITH)) {
if (s.endsWith(Form.SUFFIXES_UNWRAPPED)) {
return true;
}

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/emissary/core/DataObjectFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DataObjectFactory {

public static final String DEFAULT_CLASS = BaseDataObject.class.getName();

private static String CLAZZ;
private static String clazz;

private static final Logger logger = LoggerFactory.getLogger(DataObjectFactory.class);

Expand All @@ -26,10 +26,10 @@ public class DataObjectFactory {
static {
try {
final Configurator c = ConfigUtil.getConfigInfo(AgentPool.class);
CLAZZ = c.findStringEntry("payload.class", DEFAULT_CLASS);
clazz = c.findStringEntry("payload.class", DEFAULT_CLASS);
} catch (IOException ioe) {
logger.warn("Unable to configure DataObjectFactory", ioe);
CLAZZ = DEFAULT_CLASS;
clazz = DEFAULT_CLASS;
}
}

Expand All @@ -44,21 +44,21 @@ private DataObjectFactory() {
* Override implementation details
*/
public static void setImplementingClass(final String clazz) {
CLAZZ = clazz;
DataObjectFactory.clazz = clazz;
}

/**
* Get the name of the impl we are using
*/
public static String getImplementingClass() {
return CLAZZ;
return clazz;
}

/**
* Get an instance of the configured DataObject impl
*/
public static IBaseDataObject getInstance() {
final Object o = Factory.create(CLAZZ);
final Object o = Factory.create(clazz);
return (IBaseDataObject) o;
}

Expand All @@ -68,7 +68,7 @@ public static IBaseDataObject getInstance() {
* @param args the arguments to the BaseDataObject constructor
*/
public static IBaseDataObject getInstance(final Object... args) {
final Object o = Factory.create(CLAZZ, args);
final Object o = Factory.create(clazz, args);
return (IBaseDataObject) o;
}

Expand All @@ -94,7 +94,7 @@ public static IBaseDataObject getInstance(final byte[] payload, final String fil
* @return an IBDO with the payload, filename, file type, and form set
*/
public static IBaseDataObject getInstance(final byte[] payload, final String filename, final String form, final String fileType) {
final Object o = Factory.create(CLAZZ, payload, filename, form, fileType);
final Object o = Factory.create(clazz, payload, filename, form, fileType);
return (IBaseDataObject) o;
}
}
22 changes: 12 additions & 10 deletions src/main/java/emissary/core/MobileAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ public abstract class MobileAgent implements IMobileAgent, MobileAgentMBean {

// Name for our threads
public static final String AGENT_THREAD = "MobileAgent-";
private static int AGENT_COUNTER = 0;
private static int agentCounter = 0;

// For tracking errors
protected int MAX_MOVE_ERRORS = 3;
public static final int DEFAULT_MAX_MOVE_ERRORS = 3;
protected int maxMoveErrors = DEFAULT_MAX_MOVE_ERRORS;

// For stopping infinite loops
protected int MAX_ITINERARY_STEPS = 100;
public static final int DEFAULT_MAX_ITINERARY_STEPS = 100;
protected int maxItinerarySteps = DEFAULT_MAX_ITINERARY_STEPS;

// Stages of processing
protected static final String ERROR_FORM = Form.ERROR;
Expand Down Expand Up @@ -91,7 +93,7 @@ public abstract class MobileAgent implements IMobileAgent, MobileAgentMBean {
* Still have an uncaught exception handler but not really in a true ThreadGroup with other agents
*/
public MobileAgent() {
this(new AgentThreadGroup(TG_ID), AGENT_THREAD + AGENT_COUNTER++);
this(new AgentThreadGroup(TG_ID), AGENT_THREAD + agentCounter++);
}

/**
Expand Down Expand Up @@ -304,7 +306,7 @@ protected void agentControl(final IServiceProviderPlace currentPlaceArg) {
}

controlError = true;
if (++this.moveErrorsOccurred > this.MAX_MOVE_ERRORS || this.payload.transformHistory().size() > this.MAX_ITINERARY_STEPS) {
if (++this.moveErrorsOccurred > this.maxMoveErrors || this.payload.transformHistory().size() > this.maxItinerarySteps) {
logger.error("Too many move errors, giving up");
newEntry = null;
break;
Expand Down Expand Up @@ -439,7 +441,7 @@ protected DirectoryEntry getNextKey(@Nullable final IServiceProviderPlace place,
}

// Stop looping from occurring
if (payloadArg.transformHistory().size() > this.MAX_ITINERARY_STEPS &&
if (payloadArg.transformHistory().size() > this.maxItinerarySteps &&
!ERROR_FORM.equals(payloadArg.currentForm())) {
payloadArg.replaceCurrentForm(ERROR_FORM);
payloadArg.addProcessingError("Agent stopped due to larger than max transform history size (looping?)");
Expand Down Expand Up @@ -875,7 +877,7 @@ public void dumpPlaceStats() {
*/
@Override
public int getMaxMoveErrors() {
return this.MAX_MOVE_ERRORS;
return this.maxMoveErrors;
}

/**
Expand All @@ -886,15 +888,15 @@ public int getMaxMoveErrors() {
*/
@Override
public void setMaxMoveErrors(final int value) {
this.MAX_MOVE_ERRORS = value;
this.maxMoveErrors = value;
}

/**
* Get the maximum number of itinerary steps
*/
@Override
public int getMaxItinerarySteps() {
return this.MAX_ITINERARY_STEPS;
return this.maxItinerarySteps;
}

/**
Expand All @@ -904,6 +906,6 @@ public int getMaxItinerarySteps() {
*/
@Override
public void setMaxItinerarySteps(final int value) {
this.MAX_ITINERARY_STEPS = value;
this.maxItinerarySteps = value;
}
}
19 changes: 10 additions & 9 deletions src/main/java/emissary/parser/ParserFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ public class ParserFactory {

// Map of dataType to FileChannel parser implementation class name
// Read from config file
protected Map<String, String> NIO_TYPE_MAP = new HashMap<>();
protected Map<String, String> nioTypeMap = new HashMap<>();

// For channel sizes larger than this no fallback to a byte[]
// parser is attempted.
protected long nioFallbackMax = 1024L * 1024L * 100L; // 100 Mb

protected String DEFAULT_NIO_PARSER = "emissary.parser.SimpleNioParser";
protected static final String DEFAULT_NIO_PARSER = "emissary.parser.SimpleNioParser";
protected String nioParser = DEFAULT_NIO_PARSER;


// Data type identification engine
Expand Down Expand Up @@ -89,13 +90,13 @@ public void reconfigure(@Nullable Configurator config) {

nioFallbackMax = config.findSizeEntry("MAX_NIO_FALLBACK_SIZE", nioFallbackMax);

NIO_TYPE_MAP.clear();
NIO_TYPE_MAP.putAll(m);
nioTypeMap.clear();
nioTypeMap.putAll(m);

logger.debug("Loaded {} nio parsers with fallback size {}", NIO_TYPE_MAP.size(), nioFallbackMax);
logger.debug("Loaded {} nio parsers with fallback size {}", nioTypeMap.size(), nioFallbackMax);

// change this to "DEFAULT_PARSER"
DEFAULT_NIO_PARSER = config.findStringEntry("DEFAULT_NIO_PARSER", DEFAULT_NIO_PARSER);
nioParser = config.findStringEntry("DEFAULT_NIO_PARSER", DEFAULT_NIO_PARSER);

String idEngineClass = config.findStringEntry("ID_ENGINE_CLASS", null);

Expand Down Expand Up @@ -132,10 +133,10 @@ public SessionParser makeSessionParser(SeekableByteChannel channel) {
public SessionParser makeSessionParser(String type, SeekableByteChannel channel) {
SessionParser sp;

if (NIO_TYPE_MAP.containsKey(type)) {
sp = makeSessionParserClass(NIO_TYPE_MAP.get(type), channel);
if (nioTypeMap.containsKey(type)) {
sp = makeSessionParserClass(nioTypeMap.get(type), channel);
} else {
sp = makeSessionParserClass(DEFAULT_NIO_PARSER, channel);
sp = makeSessionParserClass(nioParser, channel);
}
return sp;
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/emissary/pool/MobileAgentFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import emissary.config.Configurator;
import emissary.core.Factory;
import emissary.core.IMobileAgent;
import emissary.core.MobileAgent;
import emissary.core.Namespace;

import org.apache.commons.pool2.PooledObject;
Expand All @@ -17,20 +18,19 @@
public class MobileAgentFactory implements PooledObjectFactory<IMobileAgent> {

// This is the default class when nothing else is
// configured or passed on on a constructor. This value
// configured or passed on a constructor. This value
// can be overridden from the AgentPool.cfg file
static String DEFAULT_CLASS_STRING = "emissary.core.MobileAgent";
static final String DEFAULT_CLASS_STRING = "emissary.core.MobileAgent";

public static String AGENT_NAME = "MobileAgent";
public static final String AGENT_NAME = "MobileAgent";

// This is the class we are going to be pooling
// The value can be set by constructor, by public setter
// or from the value in DEFAULT_CLASS_STRING
String classString = DEFAULT_CLASS_STRING;

int maxAgentMoveErrors = 3;

int maxAgentItinerary = 100;
int maxAgentMoveErrors;
int maxAgentItinerary;

private static final Logger logger = LoggerFactory.getLogger(MobileAgentFactory.class);

Expand All @@ -49,8 +49,8 @@ protected void configure() {
Configurator conf = ConfigUtil.getConfigInfo(AgentPool.class);
classString = conf.findStringEntry("agent.class", DEFAULT_CLASS_STRING);

maxAgentMoveErrors = conf.findIntEntry("agent.move.errors", maxAgentMoveErrors);
maxAgentItinerary = conf.findIntEntry("agent.max.itinerary", maxAgentItinerary);
maxAgentMoveErrors = conf.findIntEntry("agent.move.errors", MobileAgent.DEFAULT_MAX_MOVE_ERRORS);
maxAgentItinerary = conf.findIntEntry("agent.max.itinerary", MobileAgent.DEFAULT_MAX_ITINERARY_STEPS);
} catch (IOException e) {
logger.debug("Cannot read AgentPool.cfg, taking default values");
}
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/emissary/roll/RollManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class RollManager implements PropertyChangeListener {
final HashSet<Roller> rollers = new HashSet<>();
// SINGLETON
@Nullable
private static RollManager RM;
private static RollManager rollManager;

protected RollManager() {
init();
Expand Down Expand Up @@ -111,10 +111,10 @@ public void propertyChange(PropertyChangeEvent evt) {
* Synchronized on RM to prevent multiple returns on RollManager
*/
public static synchronized RollManager getManager() {
if (RM == null) {
RM = new RollManager();
if (rollManager == null) {
rollManager = new RollManager();
}
return RM;
return rollManager;
}

/**
Expand All @@ -123,16 +123,16 @@ public static synchronized RollManager getManager() {
* Used to create custom RollManager based on configs.
*/
public static synchronized RollManager getManager(Configurator configG) {
if (RM == null) {
RM = new RollManager(configG);
if (rollManager == null) {
rollManager = new RollManager(configG);
}
return RM;
return rollManager;
}

public static void shutdown() {
RM.exec.shutdown();
log.info("Closing all rollers ({})", RM.rollers.size());
for (Roller roller : RM.rollers) {
rollManager.exec.shutdown();
log.info("Closing all rollers ({})", rollManager.rollers.size());
for (Roller roller : rollManager.rollers) {
Rollable r = roller.getRollable();
try {
r.roll();
Expand All @@ -141,7 +141,7 @@ public static void shutdown() {
log.warn("Error while closing Rollable: {}", r.getClass(), ex);
}
}
RM = null;
rollManager = null;
}

private static final class RMThreadFactory implements ThreadFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class TransferDirectoryAction {
private static final Logger LOG = LoggerFactory.getLogger(TransferDirectoryAction.class);

public final String TARGET_DIR_PARAM = "targetDir";
public static final String TARGET_DIR_PARAM = "targetDir";

@GET
@Path("/TransferDirectory.action")
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/emissary/core/ExtendedDataObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ExtendedDataObject extends BaseDataObject implements Serializable,
public ExtendedDataObject() {
super();
this.theData = null;
FILETYPE_EMPTY = NEW_FILETYPE_EMPTY;
emptyFileTypes = NEW_FILETYPE_EMPTY;
this.intVar = 37;
}

Expand Down

0 comments on commit ad36e1d

Please sign in to comment.