KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > blobstore > BlobStore


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.blobstore;
17
18 import EDU.oswego.cs.dl.util.concurrent.Sync;
19
20 import java.io.InputStream JavaDoc;
21
22
23 /**
24  * Stores arbitrairy blob ("binary large object") data.
25  *
26  * <p>The store is a write-once, read-many type of store. An existing
27  * blob cannot be updated, rather a new one needs to be written.
28  *
29  * <p>The user of the BlobStore is himself responsible not to retrieve or delete
30  * a blob before it is completely written.
31  */

32 public interface BlobStore {
33     /**
34      * Returns an auto-generated key by which the blob can later be retrieved.
35      */

36     String JavaDoc store(byte[] data) throws BlobIOException;
37
38     /**
39      * Returns an auto-generated key by which the blob can later be retrieved.
40      * The InputStream will be closed for you.
41      */

42     String JavaDoc store(InputStream JavaDoc is) throws BlobIOException;
43
44     /**
45      * The caller is responsible himself that a file is not being read before it is completely written.
46      * The caller is also responsible for making sure the stream gets closed, otherwise resource
47      * might leak (thus: always in a try-catch block!).
48      */

49     InputStream JavaDoc retrieve(String JavaDoc name) throws BlobIOException, NonExistingBlobException;
50
51     void delete(String JavaDoc name) throws NonExistingBlobException;
52
53     /**
54      * Suspends all write operations to the blob store, after calling this method
55      * only read operation will be allowed. This method only returns after all
56      * active write operations have been finished.
57      *
58      * @param msecs max time to wait for active write operations to finish
59      */

60     boolean suspendWrites(long msecs) throws InterruptedException JavaDoc;
61
62     /**
63      * Resumes write operations (after being suspended with {@link #suspendWrites(long)}.
64      */

65     void resumeWrites();
66
67     /**
68      * Returns a lock which can be acquired to avoid that the BlobStore can
69      * go into suspension while you have this lock.
70      */

71     Sync getAvoidSuspendLock();
72 }
73
Popular Tags