Example usage for java.time Instant now

List of usage examples for java.time Instant now

Introduction

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

Prototype

public static Instant now() 

Source Link

Document

Obtains the current instant from the system clock.

Usage

From source file:oauth2.authentication.UserAuthenticationProvider.java

@Override
@Transactional(noRollbackFor = AuthenticationException.class)
public Authentication authenticate(Authentication authentication) {
    checkNotNull(authentication);/*from  ww w.ja v  a 2s  . c o  m*/
    String userId = authentication.getName();
    User user = userRepository.findByUserId(userId);
    if (user == null) {
        LOGGER.debug("User {} not found", userId);
        throw new BadCredentialsException(messages
                .getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
    }
    try {
        authenticationStrategy.authenticate(user, authentication.getCredentials());
        user.getLoginStatus().loginSuccessful(Instant.now());
        Set<GrantedAuthority> authorities = mapAuthorities(user);
        return createSuccessAuthentication(authentication.getPrincipal(), authentication, authorities);
    } catch (BadCredentialsException ex) {
        user.getLoginStatus().loginFailed(Instant.now());
        throw ex;
    }
}

From source file:co.runrightfast.component.events.impl.ComponentEventImpl.java

public ComponentEventImpl(@NonNull final ComponentId componentId, @NonNull final Event<DATA> event) {
    this(componentId, UUID.randomUUID(), Instant.now(), AppUtils.JVM_ID, event, Optional.empty(),
            Optional.empty(), Optional.empty());
}

From source file:org.jhk.pulsing.web.service.prod.PulseService.java

/**
 * For creation of pulse there are couple of tasks that must be done
 * 1) Add the pulse to Redis /*from  w ww. j  a  va  2s. c om*/
 * 2) Send the message to storm of the creation (need couple of different writes to Hadoop for Data + Edges for processing)
 * 3) Send the websocket topic to clients (namely MapComponent) that a new pulse has been created (to either map or not)
 * 
 * @param pulse
 * @return
 */
@Override
public Result<Pulse> createPulse(Pulse pulse) {

    PulseId pId = PulseId.newBuilder().build();
    pId.setId(Util.uniqueId());
    pulse.setAction(ACTION.CREATE);
    pulse.setId(pId);
    pulse.setTimeStamp(Instant.now().getEpochSecond());

    Result<Pulse> cPulse = redisPulseDao.createPulse(pulse);

    if (cPulse.getCode() == SUCCESS) {
        getStormPublisher().produce(CommonConstants.TOPICS.PULSE_CREATE.toString(), cPulse.getData());

        try {
            template.convertAndSend("/topics/pulseCreated",
                    SerializationHelper.serializeAvroTypeToJSONString(cPulse.getData()));
        } catch (Exception except) {
            _LOGGER.error("Error while converting pulse ", except);
            except.printStackTrace();
        }
    }

    return cPulse;
}

From source file:com.orange.cepheus.broker.LocalRegistrations.java

/**
 * Add or update a new context registration.
 * When the duration of the context is set to zero, this is handled as a remove.
 * @param registerContext//  w  w  w .  j  av a 2 s.  c o  m
 * @return contextRegistrationId
 */
public String updateRegistrationContext(RegisterContext registerContext)
        throws RegistrationException, RegistrationPersistenceException {
    Duration duration = registrationDuration(registerContext);
    String registrationId = registerContext.getRegistrationId();

    // Handle a zero duration as a special remove operation
    if (duration.isZero() && registrationId != null) {
        registrationsRepository.removeRegistration(registrationId);
        registrations.remove(registrationId);
        remoteRegistrations.removeRegistration(registrationId);
        return registrationId;
    }

    // Compile all entity patterns now to check for conformance (result is cached for later use)
    try {
        registerContext.getContextRegistrationList()
                .forEach(c -> c.getEntityIdList().forEach(patterns::getPattern));
    } catch (PatternSyntaxException e) {
        throw new RegistrationException("bad pattern", e);
    }

    // Generate a registration id if none was provided or if it does not refer to an existing registration
    if (registrationId == null || registrations.get(registrationId) == null) {
        registrationId = UUID.randomUUID().toString();
        registerContext.setRegistrationId(registrationId);
    }

    // Exists in database
    Instant expirationDate = Instant.now().plus(duration);
    Registration registration;
    //TODO: instead of use insert or update, use replace instruction of sqlite
    try {
        registration = registrationsRepository.getRegistration(registerContext.getRegistrationId());
        // update registration
        registration.setExpirationDate(expirationDate);
        registration.setRegisterContext(registerContext);
        registrationsRepository.updateRegistration(registration);
    } catch (EmptyResultDataAccessException e) {
        // Create registration and set the expiration date
        registration = new Registration(expirationDate, registerContext);
        registrationsRepository.saveRegistration(registration);
    }

    registrations.put(registrationId, registration);

    // Forward to remote broker
    remoteRegistrations.registerContext(registerContext, registrationId);

    return registrationId;
}

From source file:boutiqueEnLigne.test.SpringTest.java

@Before
public void initialiserDB() {
    dbService.deleteAll();/*www .jav a2 s  . co  m*/
    Utilisateur u1 = new Utilisateur(1L, "xx@.fr", "mdp", "addresse", "nom", "prenom", "33000", "bordeaux",
            "060629594");
    utilisateurService.save(u1);
    Categorie c1 = new Categorie(1L, "vetement");
    categorieService.save(c1);
    Article a1 = new Article(1L, c1, 10L, 10.0, "pantalon bleu", Genre.HOMME);
    articleService.save(a1);
    Article a2 = new Article(2L, c1, 10L, 10.0, "pantalon rose", Genre.FEMME);
    articleService.save(a2);
    Article a3 = new Article(3L, c1, 10L, 10.0, "pantalon court", Genre.ENFANT);
    articleService.save(a3);
    Article a4 = new Article(4L, c1, 10L, 10.0, "pantalon rouge", Genre.MIXTE);
    articleService.save(a4);
    Article a5 = new Article(5L, c1, 10L, 10.0, "chapeau rouge", Genre.MIXTE);
    articleService.save(a5);
    ModeLivraison m1 = new ModeLivraison(1L, "chronopost", 2.5);
    modeLivraisonService.save(m1);
    Commande co1 = new Commande(1L, Date.from(Instant.now()), u1, m1, false, false);
    commandeService.save(co1);
    SousCommande s1 = new SousCommande(1L, a1, co1, 2L);
    sousCommandeService.save(s1);
    SousCommande s2 = new SousCommande(2L, a2, co1, 4L);
    sousCommandeService.save(s2);
}

From source file:eu.hansolo.tilesfx.tools.Location.java

public Location(final double LATITUDE, final double LONGITUDE, final String NAME, final String INFO) {
    this(LATITUDE, LONGITUDE, 0, Instant.now(), NAME, INFO, TileColor.BLUE);
}

From source file:com.orange.cepheus.broker.persistence.RegistrationsRepositoryTest.java

@Test
public void saveRegistrationWithDuplicateKeyExceptionTest()
        throws URISyntaxException, RegistrationPersistenceException {
    thrown.expect(RegistrationPersistenceException.class);
    RegisterContext registerContext = createRegisterContextTemperature();
    registerContext.setRegistrationId("12345");
    Registration registration = new Registration(Instant.now().plus(1, ChronoUnit.DAYS), registerContext);
    registrationsRepository.saveRegistration(registration);
    registrationsRepository.saveRegistration(registration);
}

From source file:org.createnet.raptor.models.objects.ServiceObject.java

/**
 * Set the current time in seconds
 */
public void setUpdateTime() {
    updatedAt = Instant.now().getEpochSecond();
}

From source file:com.vmware.photon.controller.api.client.resource.ClusterApiTest.java

@Test
public void testDelete() throws IOException {
    Task responseTask = new Task();
    responseTask.setId("12345");
    responseTask.setState("QUEUED");
    responseTask.setQueuedTime(Date.from(Instant.now()));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(responseTask);

    setupMocks(serializedTask, HttpStatus.SC_CREATED);

    ClusterApi clusterApi = new ClusterApi(restClient);

    Task task = clusterApi.delete("foo");
    assertEquals(task, responseTask);/* ww  w . j av a2 s.c  o  m*/
}

From source file:com.vmware.photon.controller.api.client.resource.ClusterRestApiTest.java

@Test
public void testDelete() throws IOException {
    Task responseTask = new Task();
    responseTask.setId("12345");
    responseTask.setState("QUEUED");
    responseTask.setQueuedTime(Date.from(Instant.now()));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(responseTask);

    setupMocks(serializedTask, HttpStatus.SC_CREATED);

    ClusterApi clusterApi = new ClusterRestApi(restClient);

    Task task = clusterApi.delete("foo");
    assertEquals(task, responseTask);//  w  w  w.jav  a  2  s .c om
}