From 1bd914bc65f57ccf3d30e66d8769c129ae9520f6 Mon Sep 17 00:00:00 2001 From: brinn <brinn> Date: Tue, 24 Mar 2009 14:00:30 +0000 Subject: [PATCH] move: CleanUpCallable & friends to from common.process to hdf5.cleanup SVN: 10344 --- .../cisd/common/process/CleanUpCallable.java | 49 -------------- .../cisd/common/process/CleanUpRegistry.java | 67 ------------------- .../common/process/ICallableWithCleanUp.java | 32 --------- .../cisd/common/process/ICleanUpRegistry.java | 33 --------- 4 files changed, 181 deletions(-) delete mode 100644 common/source/java/ch/systemsx/cisd/common/process/CleanUpCallable.java delete mode 100644 common/source/java/ch/systemsx/cisd/common/process/CleanUpRegistry.java delete mode 100644 common/source/java/ch/systemsx/cisd/common/process/ICallableWithCleanUp.java delete mode 100644 common/source/java/ch/systemsx/cisd/common/process/ICleanUpRegistry.java 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 e7165e06894..00000000000 --- 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 c83be2c54c9..00000000000 --- 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 66ecca2929a..00000000000 --- 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 a8e55c70800..00000000000 --- 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); - -} -- GitLab