View Javadoc

1   package org.csc.phynixx.loggersystem.logger;
2   
3   /*
4    * #%L
5    * phynixx-common
6    * %%
7    * Copyright (C) 2014 csc
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  
24  import org.csc.phynixx.loggersystem.logger.channellogger.AccessMode;
25  import org.csc.phynixx.loggersystem.logrecord.ILogRecordReplayListener;
26  
27  import java.io.IOException;
28  
29  /**
30   * A logger is enabled to write data in an atomic manner. The data is entirely written or the data is rejected.
31   *
32   * This class is not thread safe . Use facades to protect instances
33   */
34  public interface IDataLogger {
35  
36      /**
37       * Sub-classes call this method to write log records with
38       * a specific record type.
39       *
40       * @param type a record type defined in LogRecordType.
41       * @param data record data to be logged.
42       * @return a log key that can be used to de-reference the record.
43       * <p/>
44       */
45      long write(short type, byte[][] data)
46              throws InterruptedException, IOException;
47  
48  
49      /**
50       * callback method to replay the data of the logger.
51       * @param replayListener
52       * @throws IOException
53       */
54      void replay(ILogRecordReplayListener replayListener) throws IOException;
55  
56      /**
57       * close the Log files and perform necessary cleanup tasks.
58       * The logger could be reopen
59       */
60      void close() throws IOException, InterruptedException;
61  
62  
63      /**
64       *
65       * @return true if and if the logger is closed
66       */
67      boolean isClosed();
68  
69      /**
70       * opens the logger with the specified ACCESS_MODE. If the logger isn't closed it is closed.
71       *
72       * @param accessMode
73       * @throws IOException
74       *
75       * @see #reopen(org.csc.phynixx.loggersystem.logger.channellogger.AccessMode)
76       */
77      void open(AccessMode accessMode) throws IOException;
78  
79      /**
80       * reopens the datalogger. It is assumed that the logger is open.
81       * <pre>
82       *    READ   - position to 0, content cannot be changed or added
83       *    WRITE  - position to 0 and resets the committed size to 0. Content is deleted (kind of reset)
84       *    APPEND - position to the committed size. Content is not effected.
85       * </pre>
86       *
87       * @param accessMode
88       * @throws IOException
89       * @throws InterruptedException
90       */
91      void reopen(AccessMode accessMode) throws IOException, InterruptedException;
92  
93  
94      /**
95       * destroys the logger and removes its resources. The logger cannot be reopened
96       *
97       * @throws IOException
98       */
99      void destroy() throws IOException;
100 }