2000-12-15 09:14:03 -06:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 07:40:28 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-12-15 09:14:03 -06:00
|
|
|
*
|
2008-04-11 07:40:28 -05:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2000-12-15 09:14:03 -06:00
|
|
|
*
|
2008-04-11 07:40:28 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-12-15 09:14:03 -06:00
|
|
|
*
|
2008-04-11 07:40:28 -05:00
|
|
|
* $RCSfile: disposetimer.cxx,v $
|
|
|
|
* $Revision: 1.24 $
|
2000-12-15 09:14:03 -06:00
|
|
|
*
|
2008-04-11 07:40:28 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-12-15 09:14:03 -06:00
|
|
|
*
|
2008-04-11 07:40:28 -05:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-12-15 09:14:03 -06:00
|
|
|
*
|
2008-04-11 07:40:28 -05:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-12-15 09:14:03 -06:00
|
|
|
*
|
2008-04-11 07:40:28 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-12-15 09:14:03 -06:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 09:26:19 -05:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_configmgr.hxx"
|
|
|
|
|
2000-12-15 09:14:03 -06:00
|
|
|
#include <stdio.h>
|
2001-06-25 07:28:36 -05:00
|
|
|
|
2000-12-15 09:14:03 -06:00
|
|
|
#include "disposetimer.hxx"
|
2002-03-28 02:08:05 -06:00
|
|
|
#include "cachecontroller.hxx"
|
2001-06-25 07:28:36 -05:00
|
|
|
#include "configexcept.hxx"
|
2000-12-15 09:14:03 -06:00
|
|
|
#include "tracer.hxx"
|
|
|
|
#include <osl/diagnose.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace configmgr
|
|
|
|
{
|
|
|
|
//==========================================================================
|
|
|
|
//=
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
|
2002-03-28 02:08:05 -06:00
|
|
|
void OTreeDisposeScheduler::scheduleCleanup(RequestOptions const& _aOptions)
|
2000-12-15 09:14:03 -06:00
|
|
|
{
|
2002-03-28 02:08:05 -06:00
|
|
|
OSL_ENSURE(_aOptions.hasLocale(), "ERROR: OTreeDisposeScheduler: cannot handle complete user scheduling");
|
2000-12-15 09:14:03 -06:00
|
|
|
|
2000-12-18 06:01:20 -06:00
|
|
|
CFG_TRACE_INFO("Scheduling data cleanup for user '%s' with locale '%s'",
|
2002-03-28 02:08:05 -06:00
|
|
|
OUSTRING2ASCII(_aOptions.getEntity()),
|
|
|
|
OUSTRING2ASCII(_aOptions.getLocale()));
|
2000-12-18 06:01:20 -06:00
|
|
|
|
|
|
|
CFG_TRACE_INFO_NI("- Cleanup will be started in about %d seconds", int(m_aCleanupDelay.getTimeValue().Seconds));
|
|
|
|
|
2000-12-15 09:14:03 -06:00
|
|
|
TimeStamp aNewTime = implGetCleanupTime(TimeStamp::getCurrentTime(), m_aCleanupDelay);
|
|
|
|
OSL_ASSERT(!aNewTime.isNever());
|
|
|
|
|
2002-03-28 02:08:05 -06:00
|
|
|
TimeStamp aScheduleTime = implAddTask(_aOptions, aNewTime);
|
2000-12-15 09:14:03 -06:00
|
|
|
|
|
|
|
OSL_ASSERT(aScheduleTime <= aNewTime);
|
|
|
|
OSL_ASSERT(!aScheduleTime.isNever());
|
|
|
|
|
|
|
|
implStartBefore(aNewTime);
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static
|
|
|
|
inline
|
2002-03-28 02:08:05 -06:00
|
|
|
bool equivalentOptions(RequestOptions const& lhs, RequestOptions const& rhs)
|
2000-12-15 09:14:03 -06:00
|
|
|
{
|
2002-03-28 02:08:05 -06:00
|
|
|
lessRequestOptions lessThan;
|
2000-12-15 09:14:03 -06:00
|
|
|
return ! (lessThan(lhs,rhs) || lessThan(rhs,lhs));
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
2002-03-28 02:08:05 -06:00
|
|
|
void OTreeDisposeScheduler::clearTasks(RequestOptions const& _aOptions)
|
2000-12-15 09:14:03 -06:00
|
|
|
{
|
2000-12-18 06:01:20 -06:00
|
|
|
CFG_TRACE_INFO("Cancelling all data cleanup tasks for user '%s' with locale '%s'",
|
2002-03-28 02:08:05 -06:00
|
|
|
OUSTRING2ASCII(_aOptions.getEntity()),
|
|
|
|
OUSTRING2ASCII(_aOptions.getLocale()));
|
2000-12-18 06:01:20 -06:00
|
|
|
|
2000-12-15 09:14:03 -06:00
|
|
|
Agenda::iterator it = m_aAgenda.begin();
|
|
|
|
while(it != m_aAgenda.end())
|
|
|
|
{
|
|
|
|
Agenda::iterator cur = it++;
|
2002-03-28 02:08:05 -06:00
|
|
|
if (equivalentOptions(_aOptions,cur->second))
|
2000-12-15 09:14:03 -06:00
|
|
|
{
|
|
|
|
m_aAgenda.erase(cur);
|
2000-12-18 06:01:20 -06:00
|
|
|
CFG_TRACE_INFO_NI("- One pending task canceled");
|
2000-12-15 09:14:03 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void OTreeDisposeScheduler::stopAndClearTasks()
|
|
|
|
{
|
2000-12-18 06:01:20 -06:00
|
|
|
CFG_TRACE_INFO("Cancelling all data cleanup tasks, Stopping Cleanup timer");
|
|
|
|
CFG_TRACE_INFO_NI("- %d cleanup tasks were pending", int(m_aAgenda.size()) );
|
|
|
|
|
2000-12-15 09:14:03 -06:00
|
|
|
if (m_xTimer.isValid())
|
2001-02-15 10:15:21 -06:00
|
|
|
m_xTimer->dispose(); // just to be sure
|
|
|
|
|
2000-12-15 09:14:03 -06:00
|
|
|
m_aAgenda.clear();
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
2002-03-28 02:08:05 -06:00
|
|
|
OTreeDisposeScheduler::Task OTreeDisposeScheduler::getTask(TimeStamp const& _aActualTime, TimeStamp& _rNextTime)
|
2000-12-15 09:14:03 -06:00
|
|
|
{
|
|
|
|
OSL_ASSERT( _rNextTime.isNever() ); // internal contract, we set this only in the positive case
|
|
|
|
|
2002-03-28 02:08:05 -06:00
|
|
|
Task aTask( false, RequestOptions() );
|
2000-12-15 09:14:03 -06:00
|
|
|
|
|
|
|
if (!m_aAgenda.empty())
|
|
|
|
{
|
|
|
|
Agenda::iterator const it = m_aAgenda.begin();
|
|
|
|
|
|
|
|
if (it->first <= _aActualTime)
|
|
|
|
{
|
2002-03-28 02:08:05 -06:00
|
|
|
aTask = std::make_pair(true,it->second);
|
2000-12-15 09:14:03 -06:00
|
|
|
m_aAgenda.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_aAgenda.empty())
|
|
|
|
{
|
|
|
|
Agenda::iterator const it = m_aAgenda.begin();
|
|
|
|
|
|
|
|
_rNextTime = it->first;
|
|
|
|
}
|
|
|
|
|
2002-03-28 02:08:05 -06:00
|
|
|
return aTask;
|
2000-12-15 09:14:03 -06:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void OTreeDisposeScheduler::Timer::onShot()
|
|
|
|
{
|
2007-11-23 07:38:01 -06:00
|
|
|
UnoApiLock aLock;
|
2001-02-15 10:15:21 -06:00
|
|
|
if (pParent)
|
|
|
|
pParent->onTimerShot();
|
2000-12-15 09:14:03 -06:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void OTreeDisposeScheduler::onTimerShot()
|
|
|
|
{
|
2000-12-18 06:01:20 -06:00
|
|
|
CFG_TRACE_INFO("Cleanup Timer invoked - executing dispose task");
|
|
|
|
|
2000-12-15 09:14:03 -06:00
|
|
|
TimeStamp aActualTime = TimeStamp::getCurrentTime();
|
|
|
|
TimeStamp aNextTime = implGetCleanupTime(aActualTime, getCleanupInterval());
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
TimeStamp aNextDisposeTime = runDisposer(aActualTime);
|
|
|
|
|
|
|
|
if (aNextTime < aNextDisposeTime)
|
|
|
|
aNextTime = aNextDisposeTime;
|
|
|
|
}
|
|
|
|
|
2004-03-23 03:31:07 -06:00
|
|
|
catch (uno::Exception& )
|
2000-12-15 09:14:03 -06:00
|
|
|
{
|
|
|
|
OSL_ENSURE(false, "ERROR: UNO Exception left a disposer");
|
|
|
|
}
|
2004-03-23 03:31:07 -06:00
|
|
|
catch (configuration::Exception& )
|
2000-12-15 09:14:03 -06:00
|
|
|
{
|
|
|
|
OSL_ENSURE(false, "ERROR: configuration::Exception left a disposer");
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
OSL_ENSURE(false, "ERROR: Unknown Exception left a disposer");
|
|
|
|
}
|
|
|
|
|
2007-11-23 07:38:01 -06:00
|
|
|
OSL_ASSERT(UnoApiLock::isHeld());
|
2000-12-15 09:14:03 -06:00
|
|
|
implStartBefore(aNextTime);
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// this really should be a member of the TreeManager (see TreeManager::disposeOne etc.)
|
|
|
|
TimeStamp OTreeDisposeScheduler::runDisposer(TimeStamp const& _aActualTime)
|
|
|
|
{
|
|
|
|
TimeStamp aNextTime = TimeStamp::never();
|
|
|
|
OSL_ASSERT(aNextTime.isNever());
|
|
|
|
|
2007-11-23 07:38:01 -06:00
|
|
|
OSL_ASSERT(UnoApiLock::isHeld());
|
2000-12-15 09:14:03 -06:00
|
|
|
|
2002-03-28 02:08:05 -06:00
|
|
|
Task aTask = this->getTask( _aActualTime, aNextTime );
|
|
|
|
if (aTask.first)
|
2000-12-15 09:14:03 -06:00
|
|
|
{
|
2002-03-28 02:08:05 -06:00
|
|
|
RequestOptions & rTaskOptions = aTask.second;
|
|
|
|
|
2000-12-18 06:01:20 -06:00
|
|
|
CFG_TRACE_INFO("Found cleanup task for user %s and locale %s",
|
2002-03-28 02:08:05 -06:00
|
|
|
OUSTRING2ASCII(rTaskOptions.getEntity()),
|
|
|
|
OUSTRING2ASCII(rTaskOptions.getLocale()));
|
2000-12-18 06:01:20 -06:00
|
|
|
|
2007-11-23 07:38:01 -06:00
|
|
|
CacheManager::CacheRef aCache = m_rTreeManager.m_aCacheMap.get(rTaskOptions);
|
2002-03-28 02:08:05 -06:00
|
|
|
if (aCache.is())
|
2000-12-15 09:14:03 -06:00
|
|
|
{
|
2000-12-18 06:01:20 -06:00
|
|
|
CFG_TRACE_INFO_NI("- Found matching data container (TreeInfo) - collecting data");
|
|
|
|
|
2002-03-28 02:08:05 -06:00
|
|
|
CacheLoadingAccess::DisposeList aDisposeList;
|
2000-12-15 09:14:03 -06:00
|
|
|
|
2002-03-28 02:08:05 -06:00
|
|
|
TimeStamp aNextTaskTime = aCache->collectDisposeList(aDisposeList, _aActualTime, m_aCleanupDelay);
|
2000-12-15 09:14:03 -06:00
|
|
|
|
2000-12-18 06:01:20 -06:00
|
|
|
CFG_TRACE_INFO_NI("- Found %d module trees to dispose", int(aDisposeList.size()) );
|
|
|
|
|
2000-12-15 09:14:03 -06:00
|
|
|
if (!aNextTaskTime.isNever())
|
|
|
|
{
|
2002-03-28 02:08:05 -06:00
|
|
|
OSL_ENSURE( !aCache->isEmpty(), "ERROR: Empty TreeInfo returning finite dispose time");
|
2000-12-15 09:14:03 -06:00
|
|
|
|
|
|
|
// repost with new time
|
2007-11-23 07:38:01 -06:00
|
|
|
OSL_ASSERT(UnoApiLock::isHeld());
|
2000-12-15 09:14:03 -06:00
|
|
|
|
2000-12-18 06:01:20 -06:00
|
|
|
CFG_TRACE_INFO_NI("- Rescheduling current option set" );
|
|
|
|
|
2002-03-28 02:08:05 -06:00
|
|
|
aNextTime = this->implAddTask(rTaskOptions,aNextTaskTime);
|
2000-12-15 09:14:03 -06:00
|
|
|
}
|
|
|
|
|
2002-03-28 02:08:05 -06:00
|
|
|
else if (aCache->isEmpty())// may have been the last one - check that
|
2000-12-15 09:14:03 -06:00
|
|
|
{
|
2001-02-15 10:15:21 -06:00
|
|
|
// currently it is not possible to release options which are
|
|
|
|
// because it is not save to delete the info if another thread is running in
|
|
|
|
// a read request
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
2000-12-18 06:01:20 -06:00
|
|
|
CFG_TRACE_INFO_NI("- Disposing last data for this options set => Removing TreeInfo" );
|
|
|
|
|
2000-12-15 09:14:03 -06:00
|
|
|
// get rid of it - see TreeManager::disposeOne
|
|
|
|
std::auto_ptr<TreeInfo> pDisposeInfo(pInfo);
|
|
|
|
|
2001-01-17 08:02:34 -06:00
|
|
|
m_rTreeManager.m_aTreeList.erase(xTaskOption);
|
2000-12-15 09:14:03 -06:00
|
|
|
// got it out of reachability - now dispose/notify without lock
|
|
|
|
|
|
|
|
aGuard.clear();
|
|
|
|
m_rTreeManager.ConfigChangeBroadcaster::disposeBroadcastHelper(pInfo->pBroadcastHelper);
|
|
|
|
|
|
|
|
OSL_ENSURE(pInfo->m_aNotificationList.empty(),
|
|
|
|
"WARNING: Empty TreeInfo still has notifications registered - will be leaked");
|
2000-12-20 03:54:23 -06:00
|
|
|
|
|
|
|
pInfo = NULL;
|
2001-02-15 10:15:21 -06:00
|
|
|
|
|
|
|
*/
|
2000-12-15 09:14:03 -06:00
|
|
|
}
|
2000-12-18 06:01:20 -06:00
|
|
|
else
|
|
|
|
CFG_TRACE_INFO_NI("- Currently no more cleanup tasks for this options set" );
|
2000-12-15 09:14:03 -06:00
|
|
|
|
|
|
|
if (!aDisposeList.empty())
|
|
|
|
{
|
2002-03-28 02:08:05 -06:00
|
|
|
CFG_TRACE_INFO_NI("- Closing %d modules", int(aDisposeList.size()) );
|
|
|
|
m_rTreeManager.closeModules(aDisposeList,rTaskOptions);
|
2000-12-15 09:14:03 -06:00
|
|
|
}
|
2000-12-18 06:01:20 -06:00
|
|
|
else
|
|
|
|
CFG_TRACE_INFO_NI("- No modules trees to dispose");
|
2000-12-15 09:14:03 -06:00
|
|
|
}
|
2000-12-18 06:01:20 -06:00
|
|
|
else
|
|
|
|
CFG_TRACE_INFO_NI("- No matching data container (TreeInfo) found - task is obsolete");
|
2000-12-15 09:14:03 -06:00
|
|
|
}
|
2000-12-18 06:01:20 -06:00
|
|
|
else
|
|
|
|
CFG_TRACE_INFO("No eligible task found - may reschedule");
|
2000-12-15 09:14:03 -06:00
|
|
|
|
|
|
|
return aNextTime;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static inline
|
|
|
|
TimeStamp getExpirationTime( vos::OTimer const& aTimer )
|
|
|
|
{
|
2001-05-30 04:59:15 -05:00
|
|
|
OSL_ENSURE(aTimer.isTicking(), "Timer is already expired !");
|
|
|
|
|
|
|
|
// note: order ensures that result time may be earlier, but not later
|
|
|
|
TimeStamp const now ( TimeStamp::getCurrentTime() );
|
|
|
|
TimeInterval const left( aTimer.getRemainingTime() );
|
|
|
|
TimeStamp const expires = now + left;
|
|
|
|
|
|
|
|
return expires;
|
2000-12-15 09:14:03 -06:00
|
|
|
}
|
2001-05-30 04:59:15 -05:00
|
|
|
|
2000-12-15 09:14:03 -06:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
2003-04-15 11:18:49 -05:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2001-05-30 04:59:15 -05:00
|
|
|
static
|
|
|
|
void checkTimerStarted( vos::OTimer const& aTimer, TimeStamp const& _aLimit)
|
|
|
|
{
|
|
|
|
const TimeInterval tolerance( vos::TTimeValue(1) ); // milliseconds
|
|
|
|
if (aTimer.isTicking())
|
|
|
|
{
|
|
|
|
TimeStamp const expires = getExpirationTime(aTimer);
|
|
|
|
TimeStamp const limit = _aLimit + tolerance;
|
|
|
|
|
|
|
|
OSL_ENSURE(expires <= limit, "Timer does not expire within expected time (tolerance 1 ms) !");
|
|
|
|
// OSL_ENSURE(expires <= _aLimit, "Timer does not expire within expected time !");
|
|
|
|
OSL_ENSURE(aTimer.isTicking(), "Timer just started already expired ?!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSL_ENSURE(false, "Timer just started is not ticking ?!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
2000-12-15 09:14:03 -06:00
|
|
|
// should be called guarded only
|
|
|
|
void OTreeDisposeScheduler::implStartBefore(TimeStamp const& _aTime)
|
|
|
|
{
|
|
|
|
// check if we were cleared
|
|
|
|
if (!m_aAgenda.empty() && !_aTime.isNever())
|
|
|
|
{
|
|
|
|
if (!m_xTimer->isTicking() || _aTime < getExpirationTime(*m_xTimer))
|
|
|
|
{
|
|
|
|
m_xTimer->setAbsoluteTime(_aTime.getTimeValue());
|
|
|
|
|
|
|
|
if (!m_xTimer->isTicking()) m_xTimer->start();
|
|
|
|
|
2001-05-30 04:59:15 -05:00
|
|
|
OSL_DEBUG_ONLY( checkTimerStarted(*m_xTimer,_aTime) );
|
2000-12-15 09:14:03 -06:00
|
|
|
}
|
2000-12-18 06:01:20 -06:00
|
|
|
CFG_TRACE_INFO_NI("- Cleanup timer running - next execution in %d seconds", int (m_xTimer->getRemainingTime().Seconds) );
|
|
|
|
CFG_TRACE_INFO_NI("- %d cleanup tasks are pending", int(m_aAgenda.size()) );
|
2000-12-15 09:14:03 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-02-15 10:15:21 -06:00
|
|
|
m_xTimer->stop();
|
|
|
|
CFG_TRACE_INFO_NI("- Stopped timer - no more open cleanup tasks");
|
2000-12-15 09:14:03 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
2002-03-28 02:08:05 -06:00
|
|
|
TimeStamp OTreeDisposeScheduler::implAddTask(RequestOptions const& _aOptions, TimeStamp const& _aTime)
|
2000-12-15 09:14:03 -06:00
|
|
|
{
|
2007-11-23 07:38:01 -06:00
|
|
|
OSL_ASSERT(UnoApiLock::isHeld());
|
2000-12-15 09:14:03 -06:00
|
|
|
|
|
|
|
// try to insert after euivalent entries (but STL may ignore the hint)
|
|
|
|
Agenda::iterator where = m_aAgenda.upper_bound(_aTime);
|
|
|
|
|
2007-11-23 07:38:01 -06:00
|
|
|
m_aAgenda.insert(where, Agenda::value_type(_aTime,_aOptions));
|
2000-12-15 09:14:03 -06:00
|
|
|
|
|
|
|
OSL_ASSERT(!m_aAgenda.empty());
|
|
|
|
|
|
|
|
return m_aAgenda.begin()->first;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
} // namespace
|