View Javadoc

1   /**
2    * Copyright (c) 2011, University of Konstanz, Distributed Systems Group
3    * All rights reserved.
4    * 
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    * * Redistributions of source code must retain the above copyright
8    * notice, this list of conditions and the following disclaimer.
9    * * Redistributions in binary form must reproduce the above copyright
10   * notice, this list of conditions and the following disclaimer in the
11   * documentation and/or other materials provided with the distribution.
12   * * Neither the name of the University of Konstanz nor the
13   * names of its contributors may be used to endorse or promote products
14   * derived from this software without specific prior written permission.
15   * 
16   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19   * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20   * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26   */
27  package org.treetank.io;
28  
29  import java.util.Properties;
30  
31  import org.treetank.exception.TTException;
32  import org.treetank.exception.TTIOException;
33  import org.treetank.io.bytepipe.IByteHandler.IByteHandlerPipeline;
34  
35  /**
36   * Interface to generate access to the underlaying storage. The underlaying
37   * storage is flexible as long as {@link IBackendReader} and {@link IBackendWriter} -implementations are
38   * provided. Utility
39   * methods for common interaction with
40   * the storage are provided via the <code>IOUtils</code>-class.
41   * 
42   * @author Sebastian Graf, University of Konstanz
43   * 
44   */
45  public interface IBackend {
46  
47      /**
48       * Getting a writer.
49       * 
50       * @return an {@link IBackendWriter} instance
51       * @throws TTIOException
52       *             if the initalisation fails
53       */
54      IBackendWriter getWriter() throws TTException;
55  
56      /**
57       * Getting a reader.
58       * 
59       * @return an {@link IBackendReader} instance
60       * @throws TTIOException
61       *             if the initalisation fails
62       */
63      IBackendReader getReader() throws TTException;
64  
65      /**
66       * Closing this storage.
67       * 
68       * @throws TTIOException
69       *             exception to be throwns
70       */
71      void close() throws TTException;
72  
73      /**
74       * Getting the ByteHandlers associated with this Storage.
75       * 
76       * @return the {@link IByteHandlerPipeline} transforming bytes before storage
77       */
78      IByteHandlerPipeline getByteHandler();
79  
80      /**
81       * Truncating a storage.
82       * 
83       * @return true if successful, false otherwise
84       * @throws TTException
85       *             if anything weird happens
86       */
87      boolean truncate() throws TTException;
88  
89      /**
90       * Initializing the storage.
91       */
92      void initialize() throws TTIOException;
93  
94      /**
95       * 
96       * Factory for generating an {@link IBackend}-instance. Needed mainly
97       * because of Guice-Assisted utilization.
98       * 
99       * @author Sebastian Graf, University of Konstanz
100      * 
101      */
102     public static interface IBackendFactory {
103 
104         /**
105          * Generating a storage for a fixed file.
106          * 
107          * @param pProperties
108          *            referencing not only to the storage.
109          * @return an {@link IBackend}-instance
110          */
111         IBackend create(Properties pProperties);
112     }
113 
114 }