diff options
author | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
---|---|---|
committer | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
commit | bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a (patch) | |
tree | 38a92061c0793434c4be189f1d70c3458b6bc41d /sandbox/old/contrib/persistence/store.journal/src/main/java/org/apache/tuscany/persistence/store/journal/Journal.java |
Move Tuscany from Incubator to top level.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/old/contrib/persistence/store.journal/src/main/java/org/apache/tuscany/persistence/store/journal/Journal.java')
-rw-r--r-- | sandbox/old/contrib/persistence/store.journal/src/main/java/org/apache/tuscany/persistence/store/journal/Journal.java | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/sandbox/old/contrib/persistence/store.journal/src/main/java/org/apache/tuscany/persistence/store/journal/Journal.java b/sandbox/old/contrib/persistence/store.journal/src/main/java/org/apache/tuscany/persistence/store/journal/Journal.java new file mode 100644 index 0000000000..b8dfd072c5 --- /dev/null +++ b/sandbox/old/contrib/persistence/store.journal/src/main/java/org/apache/tuscany/persistence/store/journal/Journal.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.persistence.store.journal; + +import java.io.IOException; + +import org.apache.tuscany.spi.services.store.StoreWriteException; + +import org.objectweb.howl.log.Configuration; +import org.objectweb.howl.log.LogClosedException; +import org.objectweb.howl.log.LogFileOverflowException; +import org.objectweb.howl.log.LogRecordSizeException; +import org.objectweb.howl.log.Logger; + +/** + * Extends the HOWL logger implementation adding convenience methods for processing records + * + * @version $Rev$ $Date$ + */ +public class Journal extends Logger { + public static final short HEADER = 0; + public static final short RECORD = 1; + + public Journal() throws IOException { + } + + public Journal(Configuration config) throws IOException { + super(config); + } + + /** + * Writes a header record to the log. The format of the header is defined by {@link + * SerializationHelper#createHeader(short, int, String, String, long)} + * + * @param bytes the record as a byte array + * @param force true if the disk write should be forced + * @return the log entry key + * @throws StoreWriteException + */ + public long writeHeader(byte[] bytes, boolean force) throws StoreWriteException { + try { + return put(HEADER, new byte[][]{bytes}, force); + } catch (LogRecordSizeException e) { + throw new StoreWriteException(e); + } catch (LogFileOverflowException e) { + throw new StoreWriteException(e); + } catch (IOException e) { + throw new StoreWriteException(e); + } catch (LogClosedException e) { + throw new StoreWriteException(e); + } catch (InterruptedException e) { + throw new StoreWriteException(e); + } + } + + /** + * Writes a record block to the log. The block may be the complete number of bytes or a chunked part of thereof if + * it does not fit within HOWL's block size limit. + * + * @param data the data to write + * @param id the unique record id consisting of the owner id and the UUID + * @param force true if the disk write should be force. For records that are written in multiple blocks, only the + * last write should be forced. + * @return the log entry key + * @throws StoreWriteException + */ + public long writeBlock(byte[] data, byte[] id, boolean force) throws StoreWriteException { + try { + return put(RECORD, new byte[][]{id, data}, force); + } catch (LogRecordSizeException e) { + throw new StoreWriteException(e); + } catch (LogFileOverflowException e) { + throw new StoreWriteException(e); + } catch (IOException e) { + throw new StoreWriteException(e); + } catch (LogClosedException e) { + throw new StoreWriteException(e); + } catch (InterruptedException e) { + throw new StoreWriteException(e); + } + } + +} |