Skip to content

Commit

Permalink
sonar :: update interrupt handling (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-mlb committed Apr 21, 2023
1 parent 9cb7a95 commit 26f9b13
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/main/java/emissary/admin/Startup.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ protected boolean localDirectorySetup(final Map<String, String> localDirectories
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// empty catch block
Thread.currentThread().interrupt();
}
}

Expand Down Expand Up @@ -421,7 +421,7 @@ protected void stopAndWaitForPlaceCreation() {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// empty catch block
Thread.currentThread().interrupt();
}

if (numPlacesFound != numPlacesFoundPreviously) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/command/MonitorCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void run(JCommander jc) {
}
} while (getMonitor());
} catch (InterruptedException e) {
// nothing to log here, command was terminated
Thread.currentThread().interrupt();
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/emissary/core/MobileAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void run() {
// as a last resort
wait(60000);
} catch (InterruptedException e) {
// empty catch block
Thread.currentThread().interrupt();
}
}

Expand Down Expand Up @@ -373,6 +373,9 @@ protected final void checkInterrupt(final IServiceProviderPlace place) {
// Log only when interrupted by the ResourceWatcher, not during shutdown.
if (!this.timeToQuit) {
logger.warn("Place {} was interrupted during execution. Adjust place time out or modify code accordingly.", place);
} else {
// It must be time to quit so re-interrupt the current thread
Thread.currentThread().interrupt();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/core/Pausable.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public boolean checkPaused() {
logger.info("{} currently paused, sleeping for {}", getClass().getName(), getPauseInterval());
sleep(getPauseInterval());
} catch (InterruptedException ignore) {
// ignore and continue
Thread.currentThread().interrupt();
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/core/ResourceWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void run() {
try {
Thread.sleep(100);
} catch (InterruptedException ignore) {
// Ignore.
Thread.currentThread().interrupt();
}
Iterator<TimedResource> it = tracking.iterator();
while (it.hasNext()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/output/DropOffUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public boolean setupPath(final String fileName) {
try {
Thread.sleep(50L * tryCount);
} catch (InterruptedException e) {
// Ignored.
Thread.currentThread().interrupt();
}
}
tryCount++;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/emissary/output/roller/JournaledCoalescer.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public final KeyedOutput getOutput() throws IOException {
// Return the final, full path
return journaledPool.getFree();
} catch (InterruptedException ex) {
// should not happen in our implementation
Thread.currentThread().interrupt();
throw new IOException("Interrupted trying to obtain KeyedOutput", ex);
} finally {
lock.unlock();
Expand All @@ -200,6 +200,7 @@ public void roll() {
LOG.error("Error occurred during roll.", ex);
} catch (InterruptedException ex) {
LOG.warn("Roll interrupted during execution. Should continue on next roll.", ex);
Thread.currentThread().interrupt();
} finally {
this.rolling = false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/emissary/pickup/QueServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void run() {
try {
Thread.sleep(pollingInterval);
} catch (InterruptedException ignore) {
// empty catch block
Thread.currentThread().interrupt();
}
continue;
}
Expand All @@ -106,6 +106,7 @@ public void run() {
}
} catch (InterruptedException e) {
logger.debug("Woke me up so lets check the queue!");
Thread.currentThread().interrupt();
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/emissary/pickup/WorkSpace.java
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ protected boolean notifyPickUp(final String pup) {
try {
Thread.sleep((tryCount + 1) * 100L);
} catch (InterruptedException ignore) {
// empty catch block
Thread.currentThread().interrupt();
}
} else {
notified = true;
Expand Down Expand Up @@ -987,7 +987,7 @@ protected void monitorProgress() {
}
}
} catch (InterruptedException ex) {
// empty catch block
Thread.currentThread().interrupt();
}

if (!this.timeToQuit) {
Expand Down Expand Up @@ -1106,7 +1106,7 @@ public void run() {
Thread.sleep(WorkSpace.this.NOTIFIER_PAUSE_TIME);
rotatePickUps();
} catch (InterruptedException ignore) {
// empty catch block
Thread.currentThread().interrupt();
}

final int outboundSize = getOutboundQueueSize();
Expand Down Expand Up @@ -1188,7 +1188,7 @@ public void run() {
try {
Thread.sleep(WorkSpace.this.LOOP_PAUSE_TIME);
} catch (InterruptedException ioex) {
// empty catch block
Thread.currentThread().interrupt();
}
continue;
}
Expand Down Expand Up @@ -1367,7 +1367,7 @@ protected void pauseCollector() {
try {
Thread.sleep(intv);
} catch (InterruptedException ex) {
// empty catch block
Thread.currentThread().interrupt();
}
count++;
heap = mbean.getHeapMemoryUsage();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/emissary/pickup/file/FileDataServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ public boolean accept(File dir, String name) {
if (processedCount == 0) {
try {
Thread.sleep(pollingInterval);
} catch (InterruptedException e) { /* Dont care */
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/emissary/place/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ public void run() {
try {
Thread.sleep(100);
} catch (InterruptedException ignore) {
// empty catch block
Thread.currentThread().interrupt();
}
}
} while (loopOnInput);
Expand All @@ -523,7 +523,7 @@ public void run() {
try {
Thread.sleep(10);
} catch (InterruptedException ignore) {
// empty catch block
Thread.currentThread().interrupt();
}
}
}
Expand Down Expand Up @@ -1159,7 +1159,7 @@ else if (!timeToStop) {
try {
workQueue.wait(1000);
} catch (InterruptedException ignore) {
// empty catch block
Thread.currentThread().interrupt();
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/emissary/pool/AgentPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ protected void emptyPool() {
logger.info("Pool is now empty");
} catch (InterruptedException e) {
logger.error("emptyPool interrupted", e);
Thread.currentThread().interrupt();
} finally {
setMaxIdle(0); // just in case
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/pool/MoveSpool.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void run() {
}
}
} catch (InterruptedException ignore) {
// empty catch block
Thread.currentThread().interrupt();
}
continue;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/emissary/roll/RollScheduledExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ protected void afterExecute(Runnable r, Throwable t) {
} catch (InterruptedException ex) {
// shouldn't happen;
log.warn("Thread Interrupted", ex);
Thread.currentThread().interrupt();
} catch (ExecutionException ee) {
Throwable ex = ee.getCause();
Rollable rollable = f.r.getRollable();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/emissary/server/EmissaryServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ public static void stopServer(final String name, final boolean quiet) {
} catch (NamespaceException e) {
LOG.error("Unable to lookup {} ", name, e);
} catch (InterruptedException e) {
LOG.warn("Stop interrupted. Expected?");
LOG.warn("Interrupted! Expected?");
Thread.currentThread().interrupt();
} catch (Exception e) {
LOG.warn("Unable to stop server {} ", name, e);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/emissary/util/WatcherThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void run() {
}
}
} catch (InterruptedException ix) {
Thread.currentThread().interrupt();
}
}
}
Expand Down Expand Up @@ -98,6 +99,7 @@ public static void main(String[] args) throws IOException {
t1.join();
t2.join();
} catch (InterruptedException ix) {
Thread.currentThread().interrupt();
}

System.out.println(name + " ends at " + new Date());
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/emissary/util/shell/Executrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -845,8 +845,11 @@ public int execute(final String[] cmd, final byte[] data, @Nullable final String
stdOutThread.finish();
stdErrThread.finish();
exitValue = p.exitValue();
} catch (InterruptedException | IOException e) {
} catch (IOException e) {
logger.warn("Exec exception, args={}", Arrays.asList(cmd), e);
} catch (InterruptedException e) {
logger.warn("Interrupted exception, args={}", Arrays.asList(cmd), e);
Thread.currentThread().interrupt();
} finally {
if (dog != null) {
dog.stop();
Expand Down Expand Up @@ -1242,7 +1245,7 @@ public static boolean cleanupDirectory(final File dir) {
try {
Thread.sleep(10);
} catch (InterruptedException ignore) {
// empty catch block
Thread.currentThread().interrupt();
}
if (dir.exists()) {
deleted = dir.delete();
Expand All @@ -1254,7 +1257,7 @@ public static boolean cleanupDirectory(final File dir) {
try {
Thread.sleep(10);
} catch (InterruptedException ignore) {
// empty catch block
Thread.currentThread().interrupt();
}
if (dir.exists()) {
logger.debug("Temporary directory is still there. doing rm-rf {}", dir.getAbsolutePath());
Expand Down

0 comments on commit 26f9b13

Please sign in to comment.