Skip to content

Commit

Permalink
Merge branch 'issue-135-clean' into 'master'
Browse files Browse the repository at this point in the history
Fix most Javadoc errors

See merge request ghsc/hazdev/pdl!143
  • Loading branch information
jmfee-usgs committed May 3, 2021
2 parents 2f7c292 + c5f46a1 commit 8d33404
Show file tree
Hide file tree
Showing 181 changed files with 3,483 additions and 913 deletions.
25 changes: 20 additions & 5 deletions src/main/java/gov/usgs/earthquake/aws/AwsBatchIndexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,22 @@
* and call indexer.onProduct.
*/
public class AwsBatchIndexer implements Bootstrappable {

/** Force reindex argument */
public static final String FORCE_REINDEX_ARGUMENT = "--force";
/** Get product URL argument */
public static final String GET_PRODUCT_URL_ARGUMENT = "--getProductUrl=";
/** Argument for indexer configuration name */
public static final String INDEXER_CONFIG_NAME_ARGUMENT="--indexerConfigName=";
/** Default indexer configuration name */
public static final String INDEXER_CONFIG_NAME_DEFAULT = "indexer";

/** Argument for database driver */
public static final String DATABASE_DRIVER_ARGUMENT = "--databaseDriver=";
/** Argument for database URL */
public static final String DATABASE_URL_ARGUMENT = "--databaseUrl=";
/** Argument for indexer database */
public static final String INDEXER_DATABASE_ARGUMENT = "--indexerDatabase=";
/** Default database for indexer */
public static final String INDEXER_DATABASE_DEFAULT = "indexer";

/** Logging object. */
Expand Down Expand Up @@ -110,7 +117,7 @@ public void run(String[] args) throws Exception {
* @param id
* which product.
* @return URL with placeholders replaced.
* @throws Exception
* @throws Exception Exception
*/
public URL getProductUrl(final ProductId id) throws Exception {
String url = getProductUrlTemplate;
Expand All @@ -127,7 +134,7 @@ public URL getProductUrl(final ProductId id) throws Exception {
* @param id
* which product.
* @return Product object.
* @throws Exception
* @throws Exception Exception
*/
public Product getProduct(final ProductId id) throws Exception {
final URL url = getProductUrl(id);
Expand Down Expand Up @@ -171,6 +178,14 @@ public void processProductId(final ProductId id) {
}
}

/**
* Read product ids (as urns) from database and submit to executor for processing.
*
* @param driver database driver
* @param url database url
*
* @throws Exception exception
*/
public void readProductIdsFromDatabase(
final String driver,
final String url) throws Exception {
Expand Down Expand Up @@ -232,7 +247,7 @@ public void readProductIdsFromDatabase(
/**
* Read product ids (as urns) from stdin and submit to executor for processing.
*
* @throws Exception
* @throws Exception Exception
*/
public void readProductIdsFromStdin() throws Exception {
// read product ids from stdin
Expand Down Expand Up @@ -261,7 +276,7 @@ public void readProductIdsFromStdin() throws Exception {
*
* @param id
* which product
* @throws InterruptedException
* @throws InterruptedException InterruptedException
*/
public void submitProductId(final ProductId id) throws InterruptedException {
// queue for processing
Expand Down
100 changes: 77 additions & 23 deletions src/main/java/gov/usgs/earthquake/aws/AwsProductReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,31 @@
*/
public class AwsProductReceiver extends DefaultNotificationReceiver implements Runnable, WebSocketListener {

/** Initialzation of logger. For us later in file. */
public static final Logger LOGGER = Logger
.getLogger(AwsProductReceiver.class.getName());

/** Variable for URI string */
public static final String URI_PROPERTY = "url";
/** Variable for createdAfter string */
public static final String CREATED_AFTER_PROPERTY = "createdAfter";
/** Variable for trackingIndex string */
public static final String TRACKING_INDEX_PROPERTY = "trackingIndex";
/** Variable for trackingFileName string */
public static final String TRACKING_FILE_NAME_PROPERTY = "trackingFileName";
/** Variable for connectAttempts string */
public static final String CONNECT_ATTEMPTS_PROPERTY = "connectAttempts";
/** Variable for connectTimeout string */
public static final String CONNECT_TIMEOUT_PROPERTY = "connectTimeout";
/** Variable for initialCatchUpAge string */
public static final String INITIAL_CATCHUP_AGE_PROPERTY = "initialCatchUpAge";

/** Variable for tracking file. Links to data/AwsReceiver.json */
public static final String DEFAULT_TRACKING_FILE_NAME = "data/AwsReceiver.json";
/** Variable for connect attempts. Set to 5 */
public static final String DEFAULT_CONNECT_ATTEMPTS = "5";
/** Variable for timout. Set to 1000 */
public static final String DEFAULT_CONNECT_TIMEOUT = "1000";
/** Variable for catchup age. Set to 7.0 */
public static final String DEFAULT_INITIAL_CATCHUP_AGE = "7.0";

private URI uri;
Expand All @@ -55,30 +66,31 @@ public class AwsProductReceiver extends DefaultNotificationReceiver implements R
private TrackingIndex trackingIndex;
private WebSocketClient client;

/* Websocket session */
/** Websocket session */
private Session session;

/* µs timestamp of last message that has been processed */
/** µs timestamp of last message that has been processed */
protected Instant createdAfter = null;

/** How far back to check when first connecting. */
protected double initialCatchUpAge = Double.valueOf(DEFAULT_INITIAL_CATCHUP_AGE);

/* last broadcast message that has been processed (used for catch up) */
/** last broadcast message that has been processed (used for catch up) */
protected JsonNotification lastBroadcast = null;
/** ID of the previously mentioned last broadcast */
protected Long lastBroadcastId = null;
/* whether to process broadcast messages (after catching up). */
/** whether to process broadcast messages (after catching up). */
protected boolean processBroadcast = false;

/* whether currenting catching up. */
/** whether currenting catching up. */
protected boolean catchUpRunning = false;
/* sync object for catchUp state. */
/** sync object for catchUp state. */
protected final Object catchUpSync = new Object();
/* thread where catch up process runs. */
/** thread where catch up process runs. */
protected Thread catchUpThread = null;
/* whether thread should continue running (shutdown flag) */
/** whether thread should continue running (shutdown flag) */
protected boolean catchUpThreadRunning = false;
/* last catch up message sent (for response timeouts) */
/** last catch up message sent (for response timeouts) */
protected Instant lastCatchUpSent = null;

@Override
Expand Down Expand Up @@ -160,7 +172,7 @@ public void onClose(Session session, CloseReason closeReason) {
* compares state of latest product to determine whether caught up and if
* broadcasts should be processed.
*
* @param message
* @param message Message notification - string
*/
@Override
synchronized public void onMessage(String message) throws IOException {
Expand Down Expand Up @@ -191,8 +203,8 @@ synchronized public void onMessage(String message) throws IOException {
* If caught up process notification as usual, otherwise save notification
* to help detect when caught up.
*
* @param json
* @throws Exception
* @param json JSON Message
* @throws Exception Exception
*/
protected void onBroadcast(final JsonObject json) throws Exception {
final JsonNotification notification = new JsonNotification(
Expand Down Expand Up @@ -230,8 +242,8 @@ protected void onBroadcast(final JsonObject json) throws Exception {
/**
* Process a received notification and update current "created" timestamp.
*
* @param notification
* @throws Exception
* @param notification JSON Notification
* @throws Exception Exception
*/
protected void onJsonNotification(final JsonNotification notification) throws Exception {
// receive and notify listeners
Expand All @@ -246,8 +258,8 @@ protected void onJsonNotification(final JsonNotification notification) throws Ex
/**
* Handle a message with "action"="product", which is received during catch up.
*
* @param json
* @throws Exception
* @param json JSON Message
* @throws Exception Exception
*/
protected void onProduct(final JsonObject json) throws Exception {
final JsonNotification notification = new JsonNotification(
Expand All @@ -264,8 +276,8 @@ protected void onProduct(final JsonObject json) throws Exception {
* Check whether caught up, and either switch to broadcast mode or continue
* catch up process.
*
* @param json
* @throws Exception
* @param json JSON Message
* @throws Exception Exception
*/
protected void onProductsCreatedAfter(final JsonObject json) throws Exception {
final String after = json.getString("created_after");
Expand Down Expand Up @@ -362,6 +374,8 @@ public void run() {
* The server will reply with zero or more "action"="product" messages, and
* then one "action"="products_created_after" message to indicate the request
* is complete.
*
* @throws IOException IOException
*/
protected void sendProductsCreatedAfter() throws IOException {
// set default for created after
Expand Down Expand Up @@ -460,7 +474,7 @@ public void onReconnectFail() {
* Reads createdAfter from a tracking file if it exists,
* then connects to web socket.
*
* @throws Exception
* @throws Exception Exception
*/
@Override
public void startup() throws Exception{
Expand All @@ -485,7 +499,7 @@ public void startup() throws Exception{

/**
* Closes web socket
* @throws Exception
* @throws Exception Exception
*/
@Override
public void shutdown() throws Exception {
Expand All @@ -502,7 +516,7 @@ public void shutdown() throws Exception {
* Reads tracking file.
*
* @return JsonObject tracking file
* @throws Exception
* @throws Exception Exception
*/
public JsonObject readTrackingData() throws Exception {
// use name as key
Expand All @@ -512,7 +526,7 @@ public JsonObject readTrackingData() throws Exception {
/**
* Writes tracking file.
*
* @throws Exception
* @throws Exception Exception
*/
public void writeTrackingData() throws Exception {
JsonObject json = Json.createObjectBuilder()
Expand All @@ -523,42 +537,82 @@ public void writeTrackingData() throws Exception {
trackingIndex.setTrackingData(getName(), json);
}

/**
* Getter for URI
* @return URI
*/
public URI getURI() {
return uri;
}

/**
* Setter for URI
* @param uri URI
*/
public void setURI(final URI uri) {
this.uri = uri;
}

/**
* Getter for trackingFileName
* @return name of tracking file
*/
public String getTrackingFileName() {
return trackingFileName;
}

/**
* Setter for trackingFileName
* @param trackingFileName trackingFileName
*/
public void setTrackingFileName(final String trackingFileName) {
this.trackingFileName = trackingFileName;
}

/**
* Getter for createdAfter
* @return createdAfter
*/
public Instant getCreatedAfter() {
return createdAfter;
}

/**
* Setter for createdAfter
* @param createdAfter createdAfter
*/
public void setCreatedAfter(final Instant createdAfter) {
this.createdAfter = createdAfter;
}

/**
* Getter for attempts
* @return attempts
*/
public int getAttempts() {
return attempts;
}

/**
* Setter for attempts
* @param attempts attempts
*/
public void setAttempts(final int attempts) {
this.attempts = attempts;
}

/**
* Getter for timeout
* @return timeout
*/
public long getTimeout() {
return timeout;
}

/**
* Setter for timeout
* @param timeout long timeout
*/
public void setTimeout(final long timeout) {
this.timeout = timeout;
}
Expand Down
Loading

0 comments on commit 8d33404

Please sign in to comment.