EMMA Coverage Report (generated Tue Apr 17 08:51:20 BST 2007)
[all classes][org.jtoolkit.essence.utils]

COVERAGE SUMMARY FOR SOURCE FILE [Factory.java]

nameclass, %method, %block, %line, %
Factory.java100% (1/1)80%  (4/5)74%  (29/39)71%  (10/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class Factory$AbstractFactory100% (1/1)80%  (4/5)74%  (29/39)71%  (10/14)
release (Object): void 0%   (0/1)0%   (0/10)0%   (0/4)
Factory$AbstractFactory (String): void 100% (1/1)100% (12/12)100% (4/4)
close (): void 100% (1/1)100% (5/5)100% (2/2)
finalize (): void 100% (1/1)100% (9/9)100% (3/3)
getName (): String 100% (1/1)100% (3/3)100% (1/1)

1package org.jtoolkit.essence.utils;
2 
3import org.jetbrains.annotations.NotNull;
4import org.jetbrains.annotations.Nullable;
5import org.jtoolkit.essence.concurrency.ThreadSafe;
6 
7import java.io.Closeable;
8import java.util.concurrent.atomic.AtomicBoolean;
9 
10/*
11   Copyright 2006 Peter Lawrey
12 
13   Licensed under the Apache License, Version 2.0 (the "License");
14   you may not use this file except in compliance with the License.
15   You may obtain a copy of the License at
16 
17       http://www.apache.org/licenses/LICENSE-2.0
18 
19   Unless required by applicable law or agreed to in writing, software
20   distributed under the License is distributed on an "AS IS" BASIS,
21   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22   See the License for the specific language governing permissions and
23   limitations under the License.
24*/
25 
26/**
27 * A factory interface which creates object based on a description.  These object can be returned to the factory for recycling and disposal.
28 *
29 * @author Peter Lawrey
30 */
31@ThreadSafe
32public interface Factory<D, E> extends Closeable, Named {
33    /**
34     * Create or recycle an object suitable for the description.
35     */
36    @NotNull public E acquire(D description) throws InterruptedException;
37 
38    /**
39     * Release, recycle or dispose of an object this factory created.
40     */
41    public void release(@Nullable E element);
42 
43    /**
44     * Base class for factory implementations.
45     */
46    public abstract class AbstractFactory<D, E> implements Factory<D, E> {
47        protected final String name;
48        protected final AtomicBoolean closed = new AtomicBoolean(false);
49 
50        protected AbstractFactory(String name) {
51            this.name = name;
52        }
53 
54        @NotNull public String getName() {
55            return name;
56        }
57 
58        public void close() {
59            closed.set(true);
60        }
61 
62        public void release(E element) {
63            if (element == null) return;
64            if (element instanceof Closeable)
65                IOUtils.close((Closeable) element);
66        }
67 
68        @Override protected void finalize() throws Throwable {
69            super.finalize();
70            if (!closed.get()) close();
71        }
72    }
73}

[all classes][org.jtoolkit.essence.utils]
EMMA 2.0.5312 (C) Vladimir Roubtsov