diff --git a/common/source/java/ch/systemsx/cisd/common/process/CleanUpCallable.java b/common/source/java/ch/systemsx/cisd/common/process/CleanUpCallable.java deleted file mode 100644 index e7165e06894d68c14030bef56fbda2f50926ae2a..0000000000000000000000000000000000000000 --- a/common/source/java/ch/systemsx/cisd/common/process/CleanUpCallable.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2007 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.process; - -/** - * A class that implements the logic of cleaning up a resource even in case of an exception but - * re-throws an exception of the clean up procedure only when the main procedure didn't throw one. - * <code>CleanUpRunner</code>s can be stacked. - * - * @author Bernd Rinn - */ -public final class CleanUpCallable -{ - - private final CleanUpRegistry registry = new CleanUpRegistry(); - - /** - * Runs a {@link ICallableWithCleanUp} and ensures that all registered clean-ups are performed - * afterwards. - */ - public <T> T call(ICallableWithCleanUp<T> runnable) - { - boolean exceptionThrown = true; - try - { - T result = runnable.call(registry); - exceptionThrown = false; - return result; - } finally - { - registry.cleanUp(exceptionThrown); - } - } - -} diff --git a/common/source/java/ch/systemsx/cisd/common/process/CleanUpRegistry.java b/common/source/java/ch/systemsx/cisd/common/process/CleanUpRegistry.java deleted file mode 100644 index c83be2c54c919069457d0cb045d1cf9d8e635c1f..0000000000000000000000000000000000000000 --- a/common/source/java/ch/systemsx/cisd/common/process/CleanUpRegistry.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.process; - -import java.util.ArrayList; -import java.util.List; - -/** - * A class that allows registering items for clean up and that allows to perform the clean up later. - * - * @author Bernd Rinn - */ -public final class CleanUpRegistry implements ICleanUpRegistry -{ - - private final List<Runnable> cleanUpList = new ArrayList<Runnable>(); - - public void registerCleanUp(Runnable cleanUp) - { - cleanUpList.add(cleanUp); - } - - /** - * Performs all clean-ups registered with {@link #registerCleanUp(Runnable)}. - * - * @param suppressExceptions If <code>true</code>, all exceptions that happen during clean-up - * will be suppressed. - */ - public void cleanUp(boolean suppressExceptions) - { - RuntimeException exceptionDuringCleanUp = null; - for (int i = cleanUpList.size() - 1; i >= 0; --i) - { - final Runnable runnable = cleanUpList.get(i); - try - { - runnable.run(); - } catch (RuntimeException ex) - { - if (suppressExceptions == false && exceptionDuringCleanUp == null) - { - exceptionDuringCleanUp = ex; - } - } - } - cleanUpList.clear(); - if (exceptionDuringCleanUp != null) - { - throw exceptionDuringCleanUp; - } - } - -} diff --git a/common/source/java/ch/systemsx/cisd/common/process/ICallableWithCleanUp.java b/common/source/java/ch/systemsx/cisd/common/process/ICallableWithCleanUp.java deleted file mode 100644 index 66ecca2929a490bbce3f0834491b31580165f285..0000000000000000000000000000000000000000 --- a/common/source/java/ch/systemsx/cisd/common/process/ICallableWithCleanUp.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2007 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.process; - -/** - * A role that calls a method which requires one or more clean-up steps that need to be run reliably - * at the end of the method regardless of whether the method is finished normally or whether it - * exits with an exception. - * - * @author Bernd Rinn - */ -public interface ICallableWithCleanUp<T> -{ - - /** Calls the method requiring clean-up. */ - public T call(ICleanUpRegistry registry); - -} diff --git a/common/source/java/ch/systemsx/cisd/common/process/ICleanUpRegistry.java b/common/source/java/ch/systemsx/cisd/common/process/ICleanUpRegistry.java deleted file mode 100644 index a8e55c708005e37a8d4aba7f85d55cafa35d6466..0000000000000000000000000000000000000000 --- a/common/source/java/ch/systemsx/cisd/common/process/ICleanUpRegistry.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2007 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.process; - -/** - * A role that allows to register a clean-up method that is called regardless of whether an - * exception occurs or not. - * - * @author Bernd Rinn - */ -public interface ICleanUpRegistry -{ - - /** - * Register a clean-up to run when the main {@link Runnable} has been executed. - */ - public void registerCleanUp(Runnable cleanUp); - -}