Skip to content

Commit

Permalink
[sre] Rename ChuckNorrisException to EarlyExitException.
Browse files Browse the repository at this point in the history
close #606

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Mar 22, 2017
1 parent 6ae4dd5 commit 356bec9
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 31 deletions.
Expand Up @@ -52,7 +52,7 @@
import org.arakhne.afc.vmutil.FileSystem;

import io.janusproject.kernel.Kernel;
import io.janusproject.services.executor.ChuckNorrisException;
import io.janusproject.services.executor.EarlyExitException;
import io.janusproject.services.network.NetworkConfig;
import io.janusproject.util.LoggerCreator;

Expand Down Expand Up @@ -322,7 +322,7 @@ public static String[] parseCommandLine(String[] args) {
// Do nothing at exit
if (embedded) {
setExiter(() -> {
throw new ChuckNorrisException();
throw new EarlyExitException();
});
}
// Show the Janus logo?
Expand Down Expand Up @@ -429,7 +429,7 @@ public static void main(String[] args) {
assert agent != null;

startJanus(agent, freeArgs);
} catch (ChuckNorrisException exception) {
} catch (EarlyExitException exception) {
// Be silent
return;
} catch (Throwable e) {
Expand Down
Expand Up @@ -27,7 +27,7 @@

import com.google.inject.Inject;

import io.janusproject.services.executor.ChuckNorrisException;
import io.janusproject.services.executor.EarlyExitException;
import io.janusproject.services.spawn.SpawnService;

import io.sarl.core.DefaultContextInteractions;
Expand Down Expand Up @@ -143,7 +143,7 @@ public void killMe() {
busCapacity.selfEvent(new AsynchronousAgentKillingEvent());
// Never return from the killMe
Thread.yield();
throw new ChuckNorrisException();
throw new EarlyExitException();
}

/**
Expand Down
Expand Up @@ -43,7 +43,6 @@ public class Messages extends NLS {
public static String LoggingSkill_0;
public static String SchedulesSkill_0;
public static String SchedulesSkill_1;
public static String SchedulesSkill_2;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Expand Down
Expand Up @@ -38,7 +38,7 @@

import io.janusproject.JanusConfig;
import io.janusproject.services.AbstractDependentService;
import io.janusproject.services.executor.ChuckNorrisException;
import io.janusproject.services.executor.EarlyExitException;

/**
* Platform service that supports the execution resources.
Expand Down Expand Up @@ -185,7 +185,7 @@ public int executeMultipleTimesInParallelAndWaitForTermination(Runnable task, in
for (int j = 0; j < runGroupSize; ++j) {
try {
task.run();
} catch (ChuckNorrisException e) {
} catch (EarlyExitException e) {
//
} catch (Throwable e) {
errors.incrementAndGet();
Expand All @@ -200,7 +200,7 @@ public int executeMultipleTimesInParallelAndWaitForTermination(Runnable task, in
for (int j = 0; j < rest; ++j) {
try {
task.run();
} catch (ChuckNorrisException e) {
} catch (EarlyExitException e) {
//
} catch (Throwable e) {
errors.incrementAndGet();
Expand All @@ -215,7 +215,7 @@ public int executeMultipleTimesInParallelAndWaitForTermination(Runnable task, in
this.exec.execute(() -> {
try {
task.run();
} catch (ChuckNorrisException e) {
} catch (EarlyExitException e) {
//
} catch (Throwable e) {
errors.incrementAndGet();
Expand Down Expand Up @@ -343,7 +343,7 @@ public String toString() {
}

/**
* A specific Janus runnable that is catching the {@link ChuckNorrisException}.
* A specific Janus runnable that is catching the {@link EarlyExitException}.
*
* @author $Author: sgalland$
* @version $FullVersion$
Expand Down Expand Up @@ -373,7 +373,7 @@ public Runnable getWrappedRunnable() {
public void run() {
try {
this.runnable.run();
} catch (ChuckNorrisException ex) {
} catch (EarlyExitException ex) {
//
}
}
Expand All @@ -396,7 +396,7 @@ public int hashCode() {
}

/**
* A specific Janus callable that is catching the {@link ChuckNorrisException}.
* A specific Janus callable that is catching the {@link EarlyExitException}.
*
* @param <T> the type of the result.
* @author $Author: sgalland$
Expand Down Expand Up @@ -427,7 +427,7 @@ public Callable<T> getWrappedCallable() {
public T call() throws Exception {
try {
return this.callable.call();
} catch (ChuckNorrisException e) {
} catch (EarlyExitException e) {
return null;
}
}
Expand Down
Expand Up @@ -30,7 +30,7 @@
import com.google.inject.Inject;
import com.google.inject.Singleton;

import io.janusproject.services.executor.ChuckNorrisException;
import io.janusproject.services.executor.EarlyExitException;
import io.janusproject.services.logging.LogService;

/**
Expand Down Expand Up @@ -62,7 +62,7 @@ private void log(Throwable exception, String taskId, String taskName) {
cause = cause.getCause();
}
final LogRecord record;
if (cause instanceof ChuckNorrisException || exception instanceof ChuckNorrisException) {
if (cause instanceof EarlyExitException || exception instanceof EarlyExitException) {
// Chuck Norris cannot be catched!
return;
}
Expand Down
Expand Up @@ -32,14 +32,14 @@
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
public final class ChuckNorrisException extends RuntimeException {
public final class EarlyExitException extends RuntimeException {

private static final long serialVersionUID = -3212775069868589362L;

/**
* Construct.
*/
public ChuckNorrisException() {
public EarlyExitException() {
//
}

Expand Down
Expand Up @@ -42,7 +42,7 @@
import io.janusproject.kernel.bic.InternalEventBusCapacity;
import io.janusproject.kernel.bic.InternalEventBusSkill;
import io.janusproject.kernel.bic.LifecycleSkill;
import io.janusproject.services.executor.ChuckNorrisException;
import io.janusproject.services.executor.EarlyExitException;
import io.janusproject.services.spawn.SpawnService;
import io.janusproject.tests.testutils.AbstractJanusTest;

Expand Down Expand Up @@ -174,7 +174,7 @@ public void killMe() throws Exception {
try {
this.skill.killMe();
fail("killMe() must never return!"); //$NON-NLS-1$
} catch (ChuckNorrisException exception) {
} catch (EarlyExitException exception) {
// Expected exception
} catch (Exception e) {
throw e;
Expand Down
Expand Up @@ -26,7 +26,7 @@
import java.util.logging.LogRecord;

import io.janusproject.kernel.services.jdk.executors.JdkUncaughtExceptionHandler;
import io.janusproject.services.executor.ChuckNorrisException;
import io.janusproject.services.executor.EarlyExitException;
import io.janusproject.services.logging.LogService;
import io.janusproject.tests.testutils.AbstractJanusTest;
import org.junit.Before;
Expand Down Expand Up @@ -75,7 +75,7 @@ public void uncaughtException_Exception() {

@Test
public void uncaughtException_ChuckNorris() {
Exception e = new ChuckNorrisException();
Exception e = new EarlyExitException();
this.handler.uncaughtException(Thread.currentThread(), e);
Mockito.verifyZeroInteractions(this.logger);
}
Expand Down
Expand Up @@ -48,7 +48,7 @@
import io.janusproject.Boot;
import io.janusproject.kernel.Kernel;
import io.janusproject.modules.StandardJanusPlatformModule;
import io.janusproject.services.executor.ChuckNorrisException;
import io.janusproject.services.executor.EarlyExitException;

import io.sarl.core.Initialize;
import io.sarl.core.Lifecycle;
Expand Down Expand Up @@ -475,7 +475,7 @@ protected Object[] getAgentInitializationParameters() {
getSkill(Schedules.class).in(1000, (it) -> forceKillMe());
}
} catch (Throwable exception) {
if (!(exception instanceof ChuckNorrisException)) {
if (!(exception instanceof EarlyExitException)) {
addResult(exception);
}
throw exception;
Expand Down
Expand Up @@ -19,6 +19,7 @@
*/
package io.janusproject.tests.testutils;

import java.text.MessageFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -110,17 +111,16 @@ public void warning(Throwable exception) {

@Override
public void error(String message, Object... params) {
final Exception ex = new LoggedException(message);
synchronized(getResultMutex()) {
this.results.add(ex);
}
final Exception ex = new LoggedException(MessageFormat.format(message, params));
error(ex);
}

@Override
public void error(Throwable exception) {
synchronized(getResultMutex()) {
this.results.add(exception);
}
this.logger.log(Level.SEVERE, exception.getMessage(), exception);
}

@Override
Expand All @@ -130,6 +130,7 @@ public void log(LogRecord record) {
synchronized(getResultMutex()) {
this.results.add(ex);
}
this.logger.log(Level.SEVERE, ex.getMessage(), ex);
}
}

Expand All @@ -140,6 +141,7 @@ public void log(Level level, String message, Object... params) {
synchronized(getResultMutex()) {
this.results.add(ex);
}
this.logger.log(Level.SEVERE, ex.getMessage(), ex);
}
}

Expand All @@ -165,7 +167,7 @@ public Filter getFilter() {

@Override
public boolean isLoggeable(Level level) {
return level == Level.SEVERE;
return level.intValue() <= Level.SEVERE.intValue();
}

@Override
Expand All @@ -180,13 +182,13 @@ public void setLevel(Level level) {

@Override
protected void doStart() {
this.logger.setLevel(Level.OFF);
this.logger.setLevel(Level.SEVERE);
notifyStarted();
}

@Override
protected void doStop() {
this.logger.setLevel(Level.OFF);
//this.logger.setLevel(Level.OFF);
notifyStopped();
}

Expand Down

0 comments on commit 356bec9

Please sign in to comment.