Example usage for org.joda.time LocalDateTime LocalDateTime

List of usage examples for org.joda.time LocalDateTime LocalDateTime

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime LocalDateTime.

Prototype

public LocalDateTime() 

Source Link

Document

Constructs an instance set to the current local time evaluated using ISO chronology in the default zone.

Usage

From source file:propel.core.collections.volatiles.KeyValueSessionStore.java

License:Open Source License

/**
 * Expires the time of a session item, i.e. removes the item from the collection. This is an O(log2(n)) operation.
 * /* w ww .ja v  a2  s. c  o m*/
 * @throws NullPointerException Key is null
 */
@Override
public boolean expire(TKey key) {
    if (key == null)
        throw new NullPointerException("key");

    lock();
    try {
        return expiries.replace(key, new LocalDateTime());
    } finally {
        unlock();
    }
}

From source file:propel.core.collections.volatiles.KeyValueSessionStore.java

License:Open Source License

/**
 * Renews the session expiration time for an item. Returns true if the item was found and refreshed. This is an O(log2(n)) operation.
 * /*from   w w  w  .  jav  a  2 s . c om*/
 * @throws NullPointerException Key is null
 */
@Override
public boolean refresh(TKey key) {
    if (key == null)
        throw new NullPointerException("key");

    lock();
    try {
        return expiries.replace(key, new LocalDateTime().plusMillis(expirationMillis));
    } finally {
        unlock();
    }
}

From source file:propel.core.collections.volatiles.ValueSessionStore.java

License:Open Source License

/**
 * Overloaded constructor, initializes session with a session expiration time and polling interval in milliseconds. Set to
 * CONSTANT.TIMEOUT_INFINITE to disable expiration.
 * /*  www. j  av  a 2  s . c om*/
 * @throws IllegalArgumentException When the values provided are out of range.
 * @throws SuperTypeTokenException When called without using anonymous class semantics.
 */
public ValueSessionStore(int expirationMillis, int pollingIntervalMillis) {
    setExpirationMillis(expirationMillis);
    setPollingIntervalMillis(pollingIntervalMillis);

    reEntrantLock = new ReentrantLock();
    expiries = new AvlHashtable<T, LocalDateTime>(SuperTypeToken.getClazz(this.getClass(), 0),
            LocalDateTime.class);

    // daemon timer
    expirationTimer = new Timer(true);

    // check if expiration is enabled
    if (expirationMillis >= 0)
        expirationTimer.scheduleAtFixedRate(new ExpirationCheckingTimerTask(),
                new LocalDateTime().plusMillis(expirationMillis).toDateTime().toDate(), pollingIntervalMillis);
}

From source file:propel.core.collections.volatiles.ValueSessionStore.java

License:Open Source License

/**
 * Overloaded constructor, initializes session with a session expiration time and polling interval in milliseconds. Set to
 * CONSTANT.TIMEOUT_INFINITE to disable expiration.
 * //from   w  w  w .j  av a 2s . c o m
 * @throws IllegalArgumentException When the values provided are out of range.
 * @throws NullPointerException When the generic type parameter is null.
 */
public ValueSessionStore(int expirationMillis, int pollingIntervalMillis, Class<?> genericTypeParameter) {
    setExpirationMillis(expirationMillis);
    setPollingIntervalMillis(pollingIntervalMillis);

    reEntrantLock = new ReentrantLock();
    expiries = new AvlHashtable<T, LocalDateTime>(genericTypeParameter, LocalDateTime.class);

    // daemon timer
    expirationTimer = new Timer(true);

    // check if expiration is enabled
    if (expirationMillis >= 0)
        expirationTimer.scheduleAtFixedRate(new ExpirationCheckingTimerTask(),
                new LocalDateTime().plusMillis(expirationMillis).toDateTime().toDate(), pollingIntervalMillis);
}

From source file:propel.core.collections.volatiles.ValueSessionStore.java

License:Open Source License

/**
 * Adds an item to the collection Returns true if successful. This is an O(log2(n)) operation.
 * /*from w w  w  .  j ava  2 s  . c  om*/
 * @throws NullPointerException When the item is null.
 */
@Override
public boolean add(T item) {
    if (item == null)
        throw new NullPointerException("item");

    lock();
    try {
        return expiries.add(item, new LocalDateTime().plusMillis(expirationMillis));
    } finally {
        unlock();
    }
}

From source file:propel.core.collections.volatiles.ValueSessionStore.java

License:Open Source License

/**
 * Expires the time of a session item, i.e. removes the item from the collection. This is an O(log2(n)) operation.
 * //  ww w  .j  a  v  a  2s .co m
 * @throws NullPointerException When the item is null.
 */
@Override
public boolean expire(T item) {
    if (item == null)
        throw new NullPointerException("item");

    lock();
    try {
        return expiries.replace(item, new LocalDateTime());
    } finally {
        unlock();
    }
}

From source file:propel.core.collections.volatiles.ValueSessionStore.java

License:Open Source License

/**
 * Renews the session expiration time for an item. Returns true if the item was found and refreshed. This is an O(log2(n)) operation.
 * /*from ww w  .j  ava2s.  c o m*/
 * @throws NullPointerException When the item is null.
 */
@Override
public boolean refresh(T item) {
    if (item == null)
        throw new NullPointerException("item");

    lock();
    try {
        return expiries.replace(item, new LocalDateTime().plusMillis(expirationMillis));
    } finally {
        unlock();
    }
}

From source file:se.inera.intyg.intygstjanst.persistence.model.dao.CertificateStateHistoryEntry.java

License:Open Source License

public CertificateStateHistoryEntry(String target, CertificateState state, LocalDateTime timestamp) {
    this.target = target;
    this.state = state;
    if (timestamp != null) {
        this.timestamp = timestamp;
    } else {/*from  www .j ava 2  s  . c o  m*/
        this.timestamp = new LocalDateTime();
    }
}

From source file:se.inera.intyg.intygstjanst.web.integration.test.CertificateResource.java

License:Open Source License

@POST
@Consumes(MediaType.APPLICATION_JSON)//  w ww .j  ava  2s.c  o  m
@Path("/")
public Response insertCertificate(final CertificateHolder certificateHolder) {
    return transactionTemplate.execute(new TransactionCallback<Response>() {
        public Response doInTransaction(TransactionStatus status) {
            Certificate certificate = ConverterUtil.toCertificate(certificateHolder);
            try {
                OriginalCertificate originalCertificate = new OriginalCertificate();
                originalCertificate.setReceived(new LocalDateTime());

                // Call marshall from the modules ModuleApi to create XML for originalCertificate
                ModuleApi moduleApi = null;
                try {
                    moduleApi = moduleRegistry.getModuleApi(certificateHolder.getType());
                } catch (ModuleNotFoundException e) {
                    LOGGER.error("Module {} not found ", certificateHolder.getType());
                }
                if (moduleApi != null && moduleApi.marshall(certificate.getDocument()) != null) {
                    originalCertificate.setDocument(moduleApi.marshall(certificate.getDocument()));
                } else {
                    LOGGER.debug("Got null while populating with original_certificate");
                    originalCertificate.setDocument(certificate.getDocument());
                }

                originalCertificate.setCertificate(certificate);
                entityManager.persist(certificate);
                entityManager.persist(originalCertificate);
                return Response.ok().build();
            } catch (Throwable t) {
                status.setRollbackOnly();
                LOGGER.warn("insert certificate with id " + certificate.getId() + " failed: " + t.getMessage());
                return Response.serverError().build();
            }
        }
    });
}

From source file:se.inera.intyg.intygstjanst.web.service.bean.IntygBootstrapBean.java

License:Open Source License

private void addIntyg(final Resource metadata, final Resource content) {
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override//from  www.  jav  a  2  s.  com
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            try {
                Certificate certificate = new CustomObjectMapper().readValue(metadata.getInputStream(),
                        Certificate.class);
                certificate.setDocument(IOUtils.toString(content.getInputStream(), "UTF-8"));
                ModuleApi moduleApi = null;
                OriginalCertificate originalCertificate = new OriginalCertificate();
                try {
                    moduleApi = moduleRegistry.getModuleApi(certificate.getType());
                } catch (ModuleNotFoundException e) {
                    LOG.error("Module {} not found ", certificate.getType());
                }
                if (moduleApi != null && moduleApi.marshall(certificate.getDocument()) != null) {
                    originalCertificate.setReceived(new LocalDateTime());
                    originalCertificate.setDocument(moduleApi.marshall(certificate.getDocument()));
                    certificate.setOriginalCertificate(originalCertificate);
                    originalCertificate.setCertificate(certificate);
                } else {
                    LOG.debug("Got null while populating with original_certificate");
                    originalCertificate.setDocument(certificate.getDocument());
                }
                entityManager.persist(originalCertificate);
                entityManager.persist(certificate);
            } catch (Throwable t) {
                status.setRollbackOnly();
                LOG.error("Loading failed of {}: {}", metadata.getFilename(), t.getMessage());
            }
        }
    });

}