use of com.haulmont.cuba.core.global.TimeSource in project cuba by cuba-platform.
the class SchedulingTest method testRunning.
@Test
public void testRunning() {
Scheduling scheduling = new Scheduling() {
{
timeSource = new TimeSource() {
@Override
public Date currentTimestamp() {
return new Date();
}
@Override
public long currentTimeMillis() {
return System.currentTimeMillis();
}
};
}
@Override
protected TimeZone getCurrentTimeZone() {
return TimeZone.getTimeZone("GMT-0");
}
};
ScheduledTask scheduledTask = new ScheduledTask();
assertFalse(scheduling.setRunning(scheduledTask, true));
assertTrue(scheduling.setRunning(scheduledTask, true));
}
use of com.haulmont.cuba.core.global.TimeSource in project cuba by cuba-platform.
the class WebDatePicker method setDateRangeByProperty.
protected void setDateRangeByProperty(MetaProperty metaProperty) {
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
if (metaProperty.getAnnotations().get(Past.class.getName()) != null) {
TimeSource timeSource = AppBeans.get(TimeSource.NAME);
Date currentTimestamp = timeSource.currentTimestamp();
Calendar calendar = Calendar.getInstance(sessionSource.getLocale());
calendar.setTime(currentTimestamp);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
calendar.set(Calendar.MILLISECOND, 999);
setRangeEnd(calendar.getTime());
} else if (metaProperty.getAnnotations().get(Future.class.getName()) != null) {
TimeSource timeSource = AppBeans.get(TimeSource.NAME);
Date currentTimestamp = timeSource.currentTimestamp();
Calendar calendar = Calendar.getInstance(sessionSource.getLocale());
calendar.setTime(currentTimestamp);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.add(Calendar.DATE, 1);
setRangeStart(calendar.getTime());
}
}
use of com.haulmont.cuba.core.global.TimeSource in project cuba by cuba-platform.
the class EntityLogBrowser method setDateFieldTime.
public void setDateFieldTime() {
TimeSource timeSource = AppBeans.get(TimeSource.NAME);
Date date = timeSource.currentTimestamp();
fromDateField.setValue(DateUtils.addDays(date, -1));
tillDateField.setValue(DateUtils.addMinutes(date, 1));
}
use of com.haulmont.cuba.core.global.TimeSource in project cuba by cuba-platform.
the class UserSessionsDatasource method loadData.
@Override
protected void loadData(Map<String, Object> params) {
TimeSource timeSource = AppBeans.get(TimeSource.NAME);
updateTs = timeSource.currentTimestamp();
data.clear();
if (!AppBeans.get(Security.class).isEntityOpPermitted(UserSessionEntity.class, EntityOp.READ))
return;
UserSessionService uss = AppBeans.get(UserSessionService.NAME);
Collection<UserSessionEntity> userSessionList = uss.loadUserSessionEntities(createFilter(params));
for (UserSessionEntity entity : userSessionList) {
if (!sessionFilter.test(entity)) {
continue;
}
data.put(entity.getId(), entity);
}
}
use of com.haulmont.cuba.core.global.TimeSource in project cuba by cuba-platform.
the class ObjectsCache method refresh.
public void refresh() {
TimeSource timeSource = AppBeans.get(TimeSource.class);
if (isValidState()) {
Date updateStart = timeSource.currentTimestamp();
// Load data
CacheSet data;
try {
data = loader.loadData(this);
} catch (CacheException e) {
log.error(String.format("Load data for cache %s failed", name), e);
this.cacheSet = new CacheSet(Collections.emptyList());
return;
}
Date updateEnd = timeSource.currentTimestamp();
this.lastUpdateDuration = updateEnd.getTime() - updateStart.getTime();
if (updateDurations.size() > updateDurationsIndex)
updateDurations.set(updateDurationsIndex, lastUpdateDuration);
else
updateDurations.add(lastUpdateDuration);
updateDurationsIndex = (updateDurationsIndex + 1) % UPDATE_COUNT_FOR_AVERAGE_DURATION;
cacheLock.writeLock().lock();
// Modify cache set
this.cacheSet = data;
cacheLock.writeLock().unlock();
this.lastUpdateTime = timeSource.currentTimestamp();
if (logUpdateEvent)
log.debug("Updated cache set in " + name + " " + String.valueOf(lastUpdateDuration) + " millis");
}
}
Aggregations