Skip to content

Commit

Permalink
Fix scope prints. Fix registry lock usage by handling interruptions. …
Browse files Browse the repository at this point in the history
…Fix rpc exception printing.
  • Loading branch information
DivineThreepwood committed Jan 5, 2024
1 parent 7296390 commit cf1d00d
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,6 @@ public String toString() {
if (publisher == null) {
return getClass().getSimpleName();
}
return getClass().getSimpleName() + "[" + publisher.getScope() + "]";
return getClass().getSimpleName() + "[" + ScopeProcessor.generateStringRep(publisher.getScope(), "?") + "]";
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ public RPCResolvedException(final RPCException rpcException) {
* Method parses the RPCException message and resolves the causes and messagen and use those to reconstruct the exception chain.
*
* @param rpcException the origin RPCException
*
* @return the reconstruced excetion cause chain.
*/
public static Exception resolveRPCException(final RPCException rpcException) {
Exception exception = null;
public static Throwable resolveRPCException(final RPCException rpcException) {
Throwable exception = null;

// build stacktrace array where each line is stored as entry. entry is extract each line stacktrace into arr
final String[] stacktrace = ("Caused by: " + rpcException.getMessage()).split("\n");
Expand All @@ -97,15 +98,16 @@ public static Exception resolveRPCException(final RPCException rpcException) {
final String message = causes.length <= 2 ? "" : stacktrace[i].substring(stacktrace[i].lastIndexOf(exceptionClassName) + exceptionClassName.length() + 2).trim();

// detect exception class
final Class<Exception> exceptionClass;
final Class<Throwable> exceptionClass;
try {
exceptionClass = (Class<Exception>) Class.forName(exceptionClassName);
exceptionClass = (Class<Throwable>) Class.forName(exceptionClassName);

// build exception
try {
// try default constructor
exception = exceptionClass.getConstructor(String.class, Throwable.class).newInstance(message, exception);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassCastException | UnsupportedOperationException ex) {
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
NoSuchMethodException | ClassCastException | UnsupportedOperationException ex) {
try {
// try to handle missing fields
if (exception == null && message.isEmpty()) {
Expand All @@ -117,7 +119,8 @@ public static Exception resolveRPCException(final RPCException rpcException) {
} else {
throw ex;
}
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException exx) {
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
NoSuchMethodException exx) {
throw new CouldNotPerformException("No compatible constructor found!", exx);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory
import java.lang.reflect.InvocationTargetException
import java.time.Duration
import java.util.*
import java.util.concurrent.ExecutionException
import java.util.concurrent.Future
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
Expand Down Expand Up @@ -158,19 +159,20 @@ class RPCServerImpl(
val result = method.invoke(request.paramsList)
responseBuilder.result = result
} catch (ex: Exception) {
when (ex) {
is InvocationTargetException -> {
val targetException = when (ex) {
is InvocationTargetException, is ExecutionException -> {
if (JPService.verboseMode()) {
ExceptionPrinter.printHistory(ex, logger, LogLevel.WARN)
}
responseBuilder.error = ex.cause?.stackTraceToString() ?: ex.stackTraceToString()
ex.cause ?: ex
}

else -> {
ExceptionPrinter.printHistory(ex, logger, LogLevel.WARN)
responseBuilder.error = CouldNotPerformException("Server error ${ex.message}").stackTraceToString()
CouldNotPerformException("Server error ${ex.message}", ex)
}
}
responseBuilder.error = targetException.stackTraceToString()
}

mqttClient.publish(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
Expand All @@ -34,6 +34,14 @@ public class ScopeProcessor {

public static final String COMPONENT_SEPARATOR = "/";

public static String generateStringRep(final ScopeType.Scope scope, final String alternative) {
try {
return generateStringRep(scope);
} catch (CouldNotPerformException ex) {
return alternative;
}
}

public static String generateStringRep(final ScopeType.Scope scope) throws CouldNotPerformException {
try {
if (scope == null) {
Expand All @@ -51,7 +59,7 @@ public static String generateStringRep(final Collection<String> components) thro
for (String component : components) {

// merge to components in case they are connected by an empty one
if(component.isEmpty()) {
if (component.isEmpty()) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
Expand Down Expand Up @@ -107,7 +107,7 @@ protected boolean check(T message) throws CouldNotPerformException {
final boolean result = dataProvider.getTransactionId() >= transactionId;

if (!result) {
logger.debug("Transition check failed, received {} but waiting for {} of {}", dataProvider.getTransactionId(), transactionId, dataProvider);
logger.trace("Outdated transition {} received, waiting for {} of {}", dataProvider.getTransactionId(), transactionId, dataProvider);
}

return result;
Expand Down
Loading

0 comments on commit cf1d00d

Please sign in to comment.