//
// ========================================================================
-// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
+// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
package org.eclipse.jetty.server.session;
import java.io.DataInputStream;
-import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
-import org.eclipse.jetty.server.SessionIdManager;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.ClassLoadingObjectInputStream;
-import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
import org.eclipse.jetty.util.thread.Scheduler;
}
finally
{
- if (_timer != null && _timer.isRunning())
- _timer.schedule(this, _scavengePeriodMs, TimeUnit.MILLISECONDS);
+ if (_timer != null && _timer.isRunning()) {
+ _task = _timer.schedule(this, _scavengePeriodMs, TimeUnit.MILLISECONDS);
+ }
}
}
}
finally
{
if (_timer != null && _timer.isRunning())
- _timer.schedule(this, _savePeriodMs, TimeUnit.MILLISECONDS);
+ _saveTask = _timer.schedule(this, _savePeriodMs, TimeUnit.MILLISECONDS);
}
}
}
ServletContext context = ContextHandler.getCurrentContext();
if (context!=null)
_timer = (Scheduler)context.getAttribute("org.eclipse.jetty.server.session.timer");
- }
+ }
if (_timer == null)
{
}
else
addBean(_timer,false);
-
+
super.doStart();
setScavengePeriod(getScavengePeriod());
{
if (_saveTask!=null)
_saveTask.cancel();
+
_saveTask=null;
if (_task!=null)
_task.cancel();
+
_task=null;
_timer=null;
}
+
// This will callback invalidate sessions - where we decide if we will save
super.doStop();
_scavengePeriodMs=period;
- if (_timer!=null && (period!=old_period || _task==null))
+ synchronized (this)
{
- synchronized (this)
+ if (_timer!=null && (period!=old_period || _task==null))
{
if (_task!=null)
{
_task.cancel();
_task = null;
}
+
_task = _timer.schedule(new Scavenger(),_scavengePeriodMs, TimeUnit.MILLISECONDS);
}
}
{
File file = new File(_storeDir,idInCuster);
- FileInputStream in = null;
Exception error = null;
- try
+ if (!file.exists())
{
- if (file.exists())
+ if (LOG.isDebugEnabled())
{
- in = new FileInputStream(file);
- HashedSession session = restoreSession(in, null);
- addSession(session, false);
- session.didActivate();
- return session;
+ LOG.debug("Not loading: {}",file);
}
+ return null;
+ }
+
+ try (FileInputStream in = new FileInputStream(file))
+ {
+ HashedSession session = restoreSession(in,null);
+ addSession(session,false);
+ session.didActivate();
+ return session;
}
catch (Exception e)
{
}
finally
{
- if (in != null) IO.close(in);
-
if (error != null)
{
if (isDeleteUnrestorableSessions() && file.exists() && file.getParentFile().equals(_storeDir) )
}
}
else
- file.delete(); //delete successfully restored file
+ {
+ // delete successfully restored file
+ file.delete();
+ }
}
return null;
}
if (session == null)
session = (HashedSession)newSession(created, accessed, clusterId);
+
session.setRequests(requests);
+ // Attributes
int size = di.readInt();
restoreSessionAttributes(di, size, session);
int maxIdle = di.readInt();
session.setMaxInactiveInterval(maxIdle);
}
- catch (EOFException e)
+ catch (IOException e)
{
LOG.debug("No maxInactiveInterval persisted for session "+clusterId);
LOG.ignore(e);
return session;
}
-
+
+ @SuppressWarnings("resource")
private void restoreSessionAttributes (InputStream is, int size, HashedSession session)
throws Exception
{
if (size>0)
{
+ // input stream should not be closed here
ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream(is);
for (int i=0; i<size;i++)
{