107 // format version numbers read from/written to this.log
108 private int majorFormatVersion = 0;
109 private int minorFormatVersion = 0;
110
111
112 /**
113 * Constructor for the log file. If the system property
114 * sun.rmi.log.class is non-null and the class specified by this
115 * property a) can be loaded, b) is a subclass of LogFile, and c) has a
116 * public two-arg constructor (String, String), ReliableLog uses the
117 * constructor to construct the LogFile.
118 **/
119 private static final Constructor<? extends LogFile>
120 logClassConstructor = getLogClassConstructor();
121
122 /**
123 * Creates a ReliableLog to handle checkpoints and logging in a
124 * stable storage directory.
125 *
126 * @param dirPath path to the stable storage directory
127 * @param logCl the closure object containing callbacks for logging and
128 * recovery
129 * @param pad ignored
130 * @exception IOException If a directory creation error has
131 * occurred or if initialSnapshot callback raises an exception or
132 * if an exception occurs during invocation of the handler's
133 * snapshot method or if other IOException occurs.
134 */
135 public ReliableLog(String dirPath,
136 LogHandler handler,
137 boolean pad)
138 throws IOException
139 {
140 super();
141 this.Debug = AccessController.doPrivileged(
142 (PrivilegedAction<Boolean>) () -> Boolean.getBoolean("sun.rmi.log.debug"));
143 dir = new File(dirPath);
144 if (!(dir.exists() && dir.isDirectory())) {
145 // create directory
146 if (!dir.mkdir()) {
147 throw new IOException("could not create directory for log: " +
153 lastSnapshot = 0;
154 lastLog = 0;
155 getVersion();
156 if (version == 0) {
157 try {
158 snapshot(handler.initialSnapshot());
159 } catch (IOException e) {
160 throw e;
161 } catch (Exception e) {
162 throw new IOException("initial snapshot failed with " +
163 "exception: " + e);
164 }
165 }
166 }
167
168 /**
169 * Creates a ReliableLog to handle checkpoints and logging in a
170 * stable storage directory.
171 *
172 * @param dirPath path to the stable storage directory
173 * @param logCl the closure object containing callbacks for logging and
174 * recovery
175 * @exception IOException If a directory creation error has
176 * occurred or if initialSnapshot callback raises an exception
177 */
178 public ReliableLog(String dirPath,
179 LogHandler handler)
180 throws IOException
181 {
182 this(dirPath, handler, false);
183 }
184
185 /* public methods */
186
187 /**
188 * Returns an object which is the value recorded in the current
189 * snapshot. This snapshot is recovered by calling the client
190 * supplied callback "recover" and then subsequently invoking
191 * the "readUpdate" callback to apply any logged updates to the state.
192 *
193 * @exception IOException If recovery fails due to serious log
|
107 // format version numbers read from/written to this.log
108 private int majorFormatVersion = 0;
109 private int minorFormatVersion = 0;
110
111
112 /**
113 * Constructor for the log file. If the system property
114 * sun.rmi.log.class is non-null and the class specified by this
115 * property a) can be loaded, b) is a subclass of LogFile, and c) has a
116 * public two-arg constructor (String, String), ReliableLog uses the
117 * constructor to construct the LogFile.
118 **/
119 private static final Constructor<? extends LogFile>
120 logClassConstructor = getLogClassConstructor();
121
122 /**
123 * Creates a ReliableLog to handle checkpoints and logging in a
124 * stable storage directory.
125 *
126 * @param dirPath path to the stable storage directory
127 * @param handler the closure object containing callbacks for logging and
128 * recovery
129 * @param pad ignored
130 * @exception IOException If a directory creation error has
131 * occurred or if initialSnapshot callback raises an exception or
132 * if an exception occurs during invocation of the handler's
133 * snapshot method or if other IOException occurs.
134 */
135 public ReliableLog(String dirPath,
136 LogHandler handler,
137 boolean pad)
138 throws IOException
139 {
140 super();
141 this.Debug = AccessController.doPrivileged(
142 (PrivilegedAction<Boolean>) () -> Boolean.getBoolean("sun.rmi.log.debug"));
143 dir = new File(dirPath);
144 if (!(dir.exists() && dir.isDirectory())) {
145 // create directory
146 if (!dir.mkdir()) {
147 throw new IOException("could not create directory for log: " +
153 lastSnapshot = 0;
154 lastLog = 0;
155 getVersion();
156 if (version == 0) {
157 try {
158 snapshot(handler.initialSnapshot());
159 } catch (IOException e) {
160 throw e;
161 } catch (Exception e) {
162 throw new IOException("initial snapshot failed with " +
163 "exception: " + e);
164 }
165 }
166 }
167
168 /**
169 * Creates a ReliableLog to handle checkpoints and logging in a
170 * stable storage directory.
171 *
172 * @param dirPath path to the stable storage directory
173 * @param handler the closure object containing callbacks for logging and
174 * recovery
175 * @exception IOException If a directory creation error has
176 * occurred or if initialSnapshot callback raises an exception
177 */
178 public ReliableLog(String dirPath,
179 LogHandler handler)
180 throws IOException
181 {
182 this(dirPath, handler, false);
183 }
184
185 /* public methods */
186
187 /**
188 * Returns an object which is the value recorded in the current
189 * snapshot. This snapshot is recovered by calling the client
190 * supplied callback "recover" and then subsequently invoking
191 * the "readUpdate" callback to apply any logged updates to the state.
192 *
193 * @exception IOException If recovery fails due to serious log
|