svnno****@sourc*****
svnno****@sourc*****
2009年 4月 7日 (火) 15:04:04 JST
Revision: 3154 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=3154 Author: j5ik2o Date: 2009-04-07 15:04:04 +0900 (Tue, 07 Apr 2009) Log Message: ----------- クラスを追加しました。 Added Paths: ----------- leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/DisposableUtil.java -------------- next part -------------- Added: leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/DisposableUtil.java =================================================================== --- leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/DisposableUtil.java (rev 0) +++ leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/DisposableUtil.java 2009-04-07 06:04:04 UTC (rev 3154) @@ -0,0 +1,71 @@ +/* + * Copyright 2004-2009 the Seasar Foundation and the Others. + * + * 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 org.jiemamy.utils; + +import java.beans.Introspector; +import java.util.LinkedList; + +import org.jiemamy.exception.JiemamyError; + +/** + * リソースを破棄するためのユーティリティクラス。 + * + * @author j5ik2o + */ +public class DisposableUtil { + + /** 登録済みの{@link Disposable} */ + private static final LinkedList<Disposable> DISPOSABLES = new LinkedList<Disposable>(); + + + /** + * 破棄可能なリソースを登録する。 + * + * @param disposable 破棄可能なリソース + */ + public static synchronized void add(final Disposable disposable) { + DISPOSABLES.add(disposable); + } + + /** + * 登録済みのリソースを全て破棄する。 + */ + public static synchronized void dispose() { + while (DISPOSABLES.isEmpty() == false) { + final Disposable disposable = DISPOSABLES.removeLast(); + try { + disposable.dispose(); + } catch (final Throwable t) { + t.printStackTrace(); // must not use Logger. + } + } + DISPOSABLES.clear(); + Introspector.flushCaches(); + } + + /** + * 破棄可能なリソースの登録を解除する。 + * + * @param disposable 破棄可能なリソース + */ + public static synchronized void remove(final Disposable disposable) { + DISPOSABLES.remove(disposable); + } + + private DisposableUtil() { + throw new JiemamyError("不到達ポイント"); + } +} Property changes on: leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/DisposableUtil.java ___________________________________________________________________ Added: svn:mime-type + text/plain