1 24 25 package com.mckoi.store; 26 27 import java.io.IOException ; 28 29 42 43 public final class JournalledFileStore extends AbstractStore { 44 45 48 private final String resource_name; 49 50 53 private final LoggingBufferManager buffer_manager; 54 55 59 private JournalledResource store_resource; 60 61 62 65 public JournalledFileStore(String resource_name, 66 LoggingBufferManager buffer_manager, 67 boolean read_only) { 68 super(read_only); 69 this.resource_name = resource_name; 70 this.buffer_manager = buffer_manager; 71 72 this.store_resource = buffer_manager.createResource(resource_name); 74 } 75 76 77 79 83 public boolean delete() throws IOException { 84 store_resource.delete(); 85 return true; 86 } 87 88 91 public boolean exists() throws IOException { 92 return store_resource.exists(); 93 } 94 95 public void lockForWrite() { 96 try { 97 buffer_manager.lockForWrite(); 98 } 99 catch (InterruptedException e) { 100 throw new Error ("Interrupted: " + e.getMessage()); 101 } 102 } 103 104 public void unlockForWrite() { 105 buffer_manager.unlockForWrite(); 106 } 107 108 110 114 protected void internalOpen(boolean read_only) throws IOException { 115 store_resource.open(read_only); 116 } 117 118 121 protected void internalClose() throws IOException { 122 buffer_manager.close(store_resource); 123 } 124 125 126 protected int readByteFrom(long position) throws IOException { 127 return buffer_manager.readByteFrom(store_resource, position); 128 } 129 130 protected int readByteArrayFrom(long position, 131 byte[] buf, int off, int len) throws IOException { 132 return buffer_manager.readByteArrayFrom(store_resource, 133 position, buf, off, len); 134 } 135 136 protected void writeByteTo(long position, int b) throws IOException { 137 buffer_manager.writeByteTo(store_resource, position, b); 138 } 139 140 protected void writeByteArrayTo(long position, 141 byte[] buf, int off, int len) throws IOException { 142 buffer_manager.writeByteArrayTo(store_resource, 143 position, buf, off, len); 144 } 145 146 protected long endOfDataAreaPointer() throws IOException { 147 return buffer_manager.getDataAreaSize(store_resource); 148 } 149 150 protected void setDataAreaSize(long new_size) throws IOException { 151 buffer_manager.setDataAreaSize(store_resource, new_size); 152 } 153 154 156 public String toString() { 157 return "[ JournalledFileStore: " + resource_name + " ]"; 158 } 159 160 } 161 162 | Popular Tags |