Skip to content
Snippets Groups Projects
Commit 97424703 authored by brinn's avatar brinn
Browse files

add: WrappedIOException

change: improve CheckedExceptionTunnel: wrap IOException and ThreadDeath exception in their unchecked counter parts
[LMS-472] Solve performance problem of BDS dataset creation and process triggering on trunk
merged from branch 8.04.x, improvements for 8.04.3

SVN: 7797
parent 8c4d38fc
No related branches found
No related tags found
No related merge requests found
......@@ -16,12 +16,14 @@
package ch.systemsx.cisd.common.exceptions;
import java.io.IOException;
/**
* An exception for tunneling checked exception through code that doesn't expect it.
*
* @author Bernd Rinn
*/
public final class CheckedExceptionTunnel extends RuntimeException
public class CheckedExceptionTunnel extends RuntimeException
{
private static final long serialVersionUID = 1L;
......@@ -41,16 +43,23 @@ public final class CheckedExceptionTunnel extends RuntimeException
/**
* Convenience wrapper for {@link #wrapIfNecessary(Exception)}. If <var>throwable</var> is an
* {@link Error}, this method will not return but the error will be thrown.
*
*
* @param throwable The exception to represent by the return value.
* @return A {@link RuntimeException} representing the <var>throwable</var>.
* @throws Error If <var>throwable</var> is an {@link Error}.
* @throws Error If <var>throwable</var> is an {@link Error} (except when it is a
* {@link ThreadDeath}, which returns a {@link StopException}).
*/
public final static RuntimeException wrapIfNecessary(final Throwable throwable) throws Error
{
if (throwable instanceof Error)
{
throw (Error) throwable;
if (throwable instanceof ThreadDeath)
{
return new StopException();
} else
{
throw (Error) throwable;
}
}
return wrapIfNecessary((Exception) throwable);
}
......@@ -70,6 +79,10 @@ public final class CheckedExceptionTunnel extends RuntimeException
{
return (RuntimeException) exception;
}
if (exception instanceof IOException)
{
return new WrappedIOException((IOException) exception);
}
if (exception instanceof InterruptedException)
{
return new StopException((InterruptedException) exception);
......@@ -81,6 +94,17 @@ public final class CheckedExceptionTunnel extends RuntimeException
return new CheckedExceptionTunnel(exception);
}
/**
* Returns the original exception before being wrapped for an {@link WrappedIOException}.
*/
public final static IOException unwrapIfNecessary(final WrappedIOException exception)
{
assert exception != null : "Exception not specified.";
// We are sure that the wrapped exception is an 'IOException'.
return (IOException) exception.getCause();
}
/**
* Returns the original exception before being wrapped, if the exception has been wrapped, or
* <var>exception</var> otherwise.
......
/*
* Copyright 2008 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.common.exceptions;
import java.io.IOException;
/**
* A {@link CheckedExceptionTunnel} for an {@link IOException}.
*
* @author Bernd Rinn
*/
public class WrappedIOException extends CheckedExceptionTunnel
{
private static final long serialVersionUID = 1L;
/**
* Returns an unchecked exception from a <var>checkedException</var>.
*
* @param checkedException The checked exception to tunnel.
*/
public WrappedIOException(final IOException checkedException)
{
super(checkedException);
assert checkedException != null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment