Example usage for java.time OffsetDateTime now

List of usage examples for java.time OffsetDateTime now

Introduction

In this page you can find the example usage for java.time OffsetDateTime now.

Prototype

public static OffsetDateTime now() 

Source Link

Document

Obtains the current date-time from the system clock in the default time-zone.

Usage

From source file:com.epam.dlab.backendapi.service.impl.SchedulerJobServiceImpl.java

@Override
public void executeTerminateResourceJob(boolean isAppliedForClusters) {
    OffsetDateTime currentDateTime = OffsetDateTime.now();
    List<SchedulerJobData> jobsToTerminate = getSchedulerJobsForAction(UserInstanceStatus.TERMINATED,
            currentDateTime, isAppliedForClusters);
    if (!jobsToTerminate.isEmpty()) {
        log.debug(isAppliedForClusters ? "Scheduler computational resource terminate job is executing..."
                : "Scheduler exploratory terminate job is executing...");
        log.info(CURRENT_DATETIME_INFO,//ww w .  ja v a  2s .  co  m
                LocalTime.of(currentDateTime.toLocalTime().getHour(),
                        currentDateTime.toLocalTime().getMinute()),
                currentDateTime.toLocalDate(), currentDateTime.getDayOfWeek());
        log.info(isAppliedForClusters ? "Quantity of clusters for terminating: {}"
                : "Quantity of exploratories for terminating: {}", jobsToTerminate.size());
        jobsToTerminate.forEach(
                job -> changeResourceStatusTo(UserInstanceStatus.TERMINATED, job, isAppliedForClusters));
    }
}

From source file:net.dv8tion.jda.requests.WebSocketClient.java

@Override
public void onDisconnected(WebSocket websocket, WebSocketFrame serverCloseFrame,
        WebSocketFrame clientCloseFrame, boolean closedByServer) {
    connected = false;/* ww w.  j  a  v  a 2 s.  c o  m*/
    api.setStatus(JDA.Status.DISCONNECTED);
    if (keepAliveThread != null) {
        keepAliveThread.interrupt();
        keepAliveThread = null;
    }
    if (!shouldReconnect) //we should not reconnect
    {
        LOG.info("The connection was closed!");
        LOG.info("By remote? " + closedByServer);
        if (serverCloseFrame != null) {
            LOG.info("Reason: " + serverCloseFrame.getCloseReason());
            LOG.info("Close code: " + serverCloseFrame.getCloseCode());
        }
        api.setStatus(JDA.Status.SHUTDOWN);
        api.getEventManager().handle(new ShutdownEvent(api, OffsetDateTime.now(), dcAudioConnections));
    } else {
        for (AudioManager mng : api.getAudioManagersMap().values()) {
            AudioManagerImpl mngImpl = (AudioManagerImpl) mng;
            VoiceChannel channel = null;
            if (mngImpl.isConnected()) {
                //This causes the AudioDisconnectEvent to be fired.. maybe we should reevaluate that.
                channel = mng.getConnectedChannel();
                mngImpl.closeAudioConnection();
            } else if (mngImpl.isAttemptingToConnect())
                channel = mng.getQueuedAudioConnection();
            else if (mngImpl.wasUnexpectedlyDisconnected())
                channel = mngImpl.getUnexpectedDisconnectedChannel();

            if (channel != null) {
                dcAudioConnections.add(channel);
            }
        }
        api.getEventManager().handle(new DisconnectEvent(api, serverCloseFrame, clientCloseFrame,
                closedByServer, OffsetDateTime.now(), dcAudioConnections));
        reconnect();
    }
}

From source file:net.dv8tion.jda.entities.impl.GuildImpl.java

@Override
public boolean checkVerification() {
    if (api.getSelfInfo().isBot())
        return true;
    if (canSendVerification)
        return true;
    switch (verificationLevel) {
    case HIGH://from   w w w. ja  va  2 s .  c om
        if (ChronoUnit.MINUTES.between(getJoinDateForUser(api.getSelfInfo()), OffsetDateTime.now()) < 10)
            break;
    case MEDIUM:
        if (ChronoUnit.MINUTES.between(MiscUtil.getCreationTime(api.getSelfInfo()), OffsetDateTime.now()) < 5)
            break;
    case LOW:
        if (!api.getSelfInfo().isVerified())
            break;
    case NONE:
        canSendVerification = true;
        return true;
    }
    return false;
}

From source file:org.silverpeas.components.gallery.notification.user.AlbumMediaNotificationManagerTest.java

@Test
void putCreationWithDelayOnSeveralAlbums() throws Exception {
    gallerySettings.put("subscription.notification.delay", "10");
    final OffsetDateTime now = OffsetDateTime.now();
    testedManager.putCreationOf(albumMediaA, senderX);
    testedManager.putCreationOf(albumMediaB, senderX);
    testedManager.putCreationOf(albumMediaC, senderX);
    assertThat(getContextCache().size(), is(2));
    final String expectedKey1 = "1@gallery38@26";
    assertThat(getContextCache(), hasKey(expectedKey1));
    NotificationAlbumJob notificationAlbumJob = getContextCache().get(expectedKey1);
    assertNotificationAlbumJob(notificationAlbumJob, 2, albumDetail1, senderX);
    final String expectedKey2 = "1@gallery38@27";
    assertThat(getContextCache(), hasKey(expectedKey2));
    notificationAlbumJob = getContextCache().get(expectedKey2);
    assertNotificationAlbumJob(notificationAlbumJob, 1, albumDetail2, senderX);
    verify(scheduler, times(3)).unscheduleJob(anyString());
    final ArgumentCaptor<JobTrigger> captor = forClass(JobTrigger.class);
    verify(scheduler, times(3)).scheduleJob(any(NotificationAlbumJob.class), captor.capture());
    final List<JobTrigger> jobTriggers = captor.getAllValues();
    assertThat(jobTriggers, hasSize(3));
    assertJobScheduled(jobTriggers.get(0), now, 0);
    assertJobScheduled(jobTriggers.get(1), now, 0);
    assertJobScheduled(jobTriggers.get(2), now, 0);
}

From source file:org.jimsey.project.turbine.condenser.service.ElasticsearchNativeServiceImplTest.java

@Test
public void testFindIndicatorsByMarketAndSymbolAndNameAndDateGreaterThan() throws Exception {
    int number = 7;
    int expected = 7;
    final String nameOne = "indicator-one";
    final String nameTwo = "indicator-two";
    logger.info("given {} {} {} indicators and {} {} {} indicators", number, stockOne, nameOne, number,
            stockOne, nameTwo);//w ww  .  j  ava  2  s  .c o m
    populateElasticsearch(rdogOne, number, indexForIndicators, typeForIndicators, nameOne, IndicatorJson.class);
    long midpoint = OffsetDateTime.now().toInstant().toEpochMilli();
    populateElasticsearch(rdogOne, number, indexForIndicators, typeForIndicators, nameTwo, IndicatorJson.class);
    logger.info("it should return only {} {} {} indicators after the midpoint", expected, nameOne, stockOne);
    List<IndicatorJson> result = service.findIndicatorsByMarketAndSymbolAndNameAndDateGreaterThan(market,
            stockOne, nameOne, midpoint);
    logger.info(" *** findIndicatorsByMarketAndSymbolAndNameAndDateGreaterThan({}, {}, {}): {}, expected: {}",
            stockOne, nameOne, midpoint, result.size(), expected);
    assertThat(result, hasSize(expected));
}

From source file:org.silverpeas.core.calendar.CalendarSynchronizationIT.java

private CalendarEvent addExternalEventIn(final Calendar calendar) throws SQLException {
    CalendarEvent event = CalendarEvent.on(LocalDate.now().minusMonths(2))
            .withExternalId(UUID.randomUUID().toString()).withTitle("next deleted event")
            .withDescription("This event will be deleted at the next synchronization");
    event.setLastSynchronizationDate(OffsetDateTime.now().minusDays(2));
    return event.planOn(calendar);
}

From source file:org.silverpeas.components.gallery.notification.user.AlbumMediaNotificationManagerTest.java

@Test
void putCreationWithDelayOnSeveralAlbumsWithSeveralUsers() throws Exception {
    gallerySettings.put("subscription.notification.delay", "10");
    final OffsetDateTime now = OffsetDateTime.now();
    testedManager.putCreationOf(albumMediaA, senderX);
    testedManager.putCreationOf(albumMediaB, senderX);
    testedManager.putCreationOf(albumMediaC, senderY);
    testedManager.putCreationOf(albumMediaD, senderX);
    assertThat(getContextCache().size(), is(4));
    final String expectedKey1 = "1@gallery38@26";
    assertThat(getContextCache(), hasKey(expectedKey1));
    NotificationAlbumJob notificationAlbumJob = getContextCache().get(expectedKey1);
    assertNotificationAlbumJob(notificationAlbumJob, 1, albumDetail1, senderX);
    final String expectedKey2 = "1@gallery38@27";
    assertThat(getContextCache(), hasKey(expectedKey2));
    notificationAlbumJob = getContextCache().get(expectedKey2);
    assertNotificationAlbumJob(notificationAlbumJob, 1, albumDetail2, senderX);
    final String expectedKey3 = "2@gallery38@26";
    assertThat(getContextCache(), hasKey(expectedKey3));
    notificationAlbumJob = getContextCache().get(expectedKey3);
    assertNotificationAlbumJob(notificationAlbumJob, 1, albumDetail1, senderY);
    final String expectedKey4 = "1@gallery39@28";
    assertThat(getContextCache(), hasKey(expectedKey4));
    notificationAlbumJob = getContextCache().get(expectedKey4);
    assertNotificationAlbumJob(notificationAlbumJob, 1, albumDetail3, senderX);
    verify(scheduler, times(4)).unscheduleJob(anyString());
    final ArgumentCaptor<JobTrigger> captor = forClass(JobTrigger.class);
    verify(scheduler, times(4)).scheduleJob(any(NotificationAlbumJob.class), captor.capture());
    final List<JobTrigger> jobTriggers = captor.getAllValues();
    assertThat(jobTriggers, hasSize(4));
    assertJobScheduled(jobTriggers.get(0), now, 0);
    assertJobScheduled(jobTriggers.get(1), now, 0);
    assertJobScheduled(jobTriggers.get(2), now, 0);
    assertJobScheduled(jobTriggers.get(3), now, 0);
}

From source file:edu.purdue.cybercenter.dm.service.CqlService.java

private Object getSystemValue(String name, Map<String, Object> context) {
    Object value;// w w  w.  ja  v a  2 s .c o  m
    TermName termName = new TermName(name);
    String alias = termName.getAlias();
    String queryString = termName.getQueryString();
    Integer id = null;
    if (queryString != null) {
        Map<String, Object> queryMap = (Map<String, Object>) Helper.deserialize(queryString, Map.class);
        id = (Integer) queryMap.get(MetaField.Id);
    }
    if (CONST_SYS_VAR_PROJECTS.equals(alias)) {
        if (id == null) {
            List<Project> items = Project.findAllProjects();
            value = items;
        } else {
            Project item = projectRepository.findOne(id);
            value = item;
        }
    } else if (CONST_SYS_VAR_EXPERIMENTS.equals(alias)) {
        if (id == null) {
            List<Experiment> items = experimentRepository.findAll();
            value = items;
        } else {
            Experiment item = experimentRepository.findOne(id);
            value = item;
        }
    } else if (alias.startsWith(MetaField.Current)) {
        String path = alias.substring(MetaField.Current.length());
        int dotIndex = path.indexOf(".");
        int dashIndex = path.indexOf("_", 1);
        String objectName;
        String fieldName;

        if (dashIndex != -1) {
            // e.g. _job_id for compatibility
            if (context != null && context.get(path) != null) {
                value = context.get(path);
            } else {
                value = null;
            }
        } else {
            if (dotIndex == -1 && dashIndex == -1) {
                // e.g. _job
                objectName = path;
                fieldName = null;
            } else {
                // e.g. _job.id
                objectName = path.substring(0, dotIndex);
                fieldName = path.substring(dotIndex + 1);
            }
            if (objectName != null) {
                Object object = context.get(objectName);
                if (MetaField.Date.equals(objectName)) {
                    DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
                    value = formatter.format(OffsetDateTime.now());
                } else if (fieldName != null) {
                    try {
                        value = getPropertyValue(object, fieldName);
                    } catch (SecurityException | IllegalArgumentException ex) {
                        throw new RuntimeException(
                                "Object: " + objectName + " does not have field: " + fieldName, ex);
                    } catch (IllegalAccessException ex) {
                        throw new RuntimeException(
                                "Object: " + objectName + " unable to access field: " + fieldName, ex);
                    }
                } else {
                    value = object;
                }
            } else {
                value = null;
            }
        }
    } else {
        value = null;
    }
    return value;
}

From source file:net.dv8tion.jda.core.entities.impl.GuildImpl.java

@Override
public boolean checkVerification() {
    if (api.getAccountType() == AccountType.BOT)
        return true;
    if (canSendVerification)
        return true;
    switch (verificationLevel) {
    case HIGH://from  ww w. j  a v a  2 s. co m
        if (ChronoUnit.MINUTES.between(getSelfMember().getJoinDate(), OffsetDateTime.now()) < 10)
            break;
    case MEDIUM:
        if (ChronoUnit.MINUTES.between(MiscUtil.getCreationTime(api.getSelfUser()), OffsetDateTime.now()) < 5)
            break;
    case LOW:
        if (!api.getSelfUser().isVerified())
            break;
    case NONE:
        canSendVerification = true;
        return true;
    }
    return false;
}