Skip to content

Commit

Permalink
#302 clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jul 12, 2022
1 parent 7bde2d2 commit fe56bd6
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 54 deletions.
35 changes: 16 additions & 19 deletions src/main/java/com/jcabi/aspects/aj/MethodAsyncRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,24 @@ public Object wrap(final ProceedingJoinPoint point) {
}
final Future<?> result = this.executor.submit(
// @checkstyle AnonInnerLength (23 lines)
new Callable<Object>() {
@Override
public Object call() {
Object returned = null;
try {
final Object result = point.proceed();
if (result instanceof Future) {
returned = ((Future<?>) result).get();
}
// @checkstyle IllegalCatch (1 line)
} catch (final Throwable ex) {
throw new IllegalStateException(
String.format(
"%s: Exception thrown",
Mnemos.toText(point, true, true)
),
ex
);
() -> {
Object returned1 = null;
try {
final Object result1 = point.proceed();
if (result1 instanceof Future) {
returned1 = ((Future<?>) result1).get();
}
return returned;
// @checkstyle IllegalCatch (1 line)
} catch (final Throwable ex) {
throw new IllegalStateException(
String.format(
"%s: Exception thrown",
Mnemos.toText(point, true, true)
),
ex
);
}
return returned1;
}
);
Object res = null;
Expand Down
14 changes: 2 additions & 12 deletions src/main/java/com/jcabi/aspects/aj/MethodCacher.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,13 @@ public final class MethodCacher {
public MethodCacher() {
this.cleaner.scheduleWithFixedDelay(
new VerboseRunnable(
new Runnable() {
@Override
public void run() {
MethodCacher.this.clean();
}
}
this::clean
),
1L, 1L, TimeUnit.SECONDS
);
this.updater.schedule(
new VerboseRunnable(
new Runnable() {
@Override
public void run() {
MethodCacher.this.update();
}
}
this::update
),
0L, TimeUnit.SECONDS
);
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/com/jcabi/aspects/aj/MethodInterrupter.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,7 @@ public MethodInterrupter() {
);
this.interrupter.scheduleWithFixedDelay(
new VerboseRunnable(
new Runnable() {
@Override
public void run() {
MethodInterrupter.this.interrupt();
}
}
this::interrupt
),
1, 1, TimeUnit.SECONDS
);
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/com/jcabi/aspects/aj/MethodLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,10 @@ public MethodLogger() {
monitor.scheduleWithFixedDelay(
new FutureTask<Void>(
new VerboseRunnable(
new Runnable() {
@Override
public void run() {
for (final MethodLogger.Marker marker
: MethodLogger.this.running) {
marker.monitor();
}
() -> {
for (final Marker marker
: this.running) {
marker.monitor();
}
}
), null
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/jcabi/aspects/aj/MethodScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,9 @@ protected Service(final Runnable runnable, final Object obj,
this.verbose = annt.verbose();
this.await = annt.awaitUnit().toMillis(annt.await());
this.attempts = annt.shutdownAttempts();
final Runnable job = new Runnable() {
@Override
public void run() {
runnable.run();
MethodScheduler.Service.this.counter.incrementAndGet();
}
final Runnable job = () -> {
runnable.run();
this.counter.incrementAndGet();
};
for (int thread = 0; thread < annt.threads(); ++thread) {
this.executor.scheduleWithFixedDelay(
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/jcabi/aspects/ImmutableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public final class ImmutableTest {
public void catchedMutableTypes() {
Assertions.assertThrows(
IllegalStateException.class,
() -> new Mutable()
Mutable::new
);
}

Expand All @@ -70,7 +70,7 @@ public void catchedMutableTypes() {
public void catchedMutableTypesWithArrays() {
Assertions.assertThrows(
IllegalStateException.class,
() -> new MutableWithArray()
MutableWithArray::new
);
}

Expand Down Expand Up @@ -99,7 +99,7 @@ public void passesImmutableObjectsWithNonPrivateFields() {
public void catchesTypesMutableByClassInheritance() {
Assertions.assertThrows(
IllegalStateException.class,
() -> new MutableByInheritance()
MutableByInheritance::new
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/jcabi/aspects/TimeableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public final class TimeableTest {
public void interruptsLongRunningMethod() {
Assertions.assertThrows(
InterruptedException.class,
() -> this.slow()
this::slow
);
}

Expand Down

0 comments on commit fe56bd6

Please sign in to comment.