Search in sources :

Example 1 with TimeSource

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));
}
Also used : ScheduledTask(com.haulmont.cuba.core.entity.ScheduledTask) TimeSource(com.haulmont.cuba.core.global.TimeSource) Date(java.util.Date) Test(org.junit.Test)

Example 2 with TimeSource

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());
    }
}
Also used : UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) Calendar(java.util.Calendar) Future(javax.validation.constraints.Future) TimeSource(com.haulmont.cuba.core.global.TimeSource) Date(java.util.Date)

Example 3 with TimeSource

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));
}
Also used : TimeSource(com.haulmont.cuba.core.global.TimeSource)

Example 4 with TimeSource

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);
    }
}
Also used : UserSessionService(com.haulmont.cuba.security.app.UserSessionService) TimeSource(com.haulmont.cuba.core.global.TimeSource) UserSessionEntity(com.haulmont.cuba.security.entity.UserSessionEntity)

Example 5 with TimeSource

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");
    }
}
Also used : TimeSource(com.haulmont.cuba.core.global.TimeSource)

Aggregations

TimeSource (com.haulmont.cuba.core.global.TimeSource)6 Date (java.util.Date)2 ScheduledTask (com.haulmont.cuba.core.entity.ScheduledTask)1 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 UserSessionService (com.haulmont.cuba.security.app.UserSessionService)1 UserSessionEntity (com.haulmont.cuba.security.entity.UserSessionEntity)1 Calendar (java.util.Calendar)1 Future (javax.validation.constraints.Future)1 Test (org.junit.Test)1