Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stability and debugging improvements. #107

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading