MCPcopy Index your code
hub / github.com/apache/tomcat / save

Method save

java/org/apache/catalina/session/FileStore.java:263–299  ·  view source on GitHub ↗
(Session session)

Source from the content-addressed store, hash-verified

261
262
263 @Override
264 public void save(Session session) throws IOException {
265 // Open an output stream to the specified pathname, if any
266 File file = file(session.getIdInternal());
267 if (file == null) {
268 return;
269 }
270 if (manager.getContext().getLogger().isTraceEnabled()) {
271 manager.getContext().getLogger()
272 .trace(sm.getString(getStoreName() + ".saving", session.getIdInternal(), file.getAbsolutePath()));
273 }
274
275 File tempFile = new File(file.getAbsolutePath() + ".tmp");
276
277 Lock writeLock = sessionLocksById.getLock(session.getIdInternal()).writeLock();
278 writeLock.lock();
279 try {
280 try (FileOutputStream fos = new FileOutputStream(tempFile);
281 ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(fos))) {
282 ((StandardSession) session).writeObjectData(oos);
283 }
284 try {
285 Files.move(tempFile.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING,
286 StandardCopyOption.ATOMIC_MOVE);
287 } catch (AtomicMoveNotSupportedException e) {
288 Files.move(tempFile.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
289 }
290 } finally {
291 try {
292 if (tempFile.exists() && !tempFile.delete()) {
293 log.warn(sm.getString("fileStore.deleteTempFailed", tempFile));
294 }
295 } finally {
296 writeLock.unlock();
297 }
298 }
299 }
300
301
302 // -------------------------------------------------------- Private Methods

Callers

nothing calls this directly

Calls 15

fileMethod · 0.95
getStoreNameMethod · 0.95
writeLockMethod · 0.80
moveMethod · 0.80
getIdInternalMethod · 0.65
isTraceEnabledMethod · 0.65
getLoggerMethod · 0.65
getContextMethod · 0.65
traceMethod · 0.65
getStringMethod · 0.65
getLockMethod · 0.65
lockMethod · 0.65

Tested by

no test coverage detected