(Session session)
| 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 |
nothing calls this directly
no test coverage detected