Search in sources :

Example 96 with Duration

use of java.time.Duration in project config by typesafehub.

the class ConfigImpl method fromAnyRef.

static AbstractConfigValue fromAnyRef(Object object, ConfigOrigin origin, FromMapMode mapMode) {
    if (origin == null)
        throw new ConfigException.BugOrBroken("origin not supposed to be null");
    if (object == null) {
        if (origin != defaultValueOrigin)
            return new ConfigNull(origin);
        else
            return defaultNullValue;
    } else if (object instanceof AbstractConfigValue) {
        return (AbstractConfigValue) object;
    } else if (object instanceof Boolean) {
        if (origin != defaultValueOrigin) {
            return new ConfigBoolean(origin, (Boolean) object);
        } else if ((Boolean) object) {
            return defaultTrueValue;
        } else {
            return defaultFalseValue;
        }
    } else if (object instanceof String) {
        return new ConfigString.Quoted(origin, (String) object);
    } else if (object instanceof Number) {
        // Double, Integer, or Long.
        if (object instanceof Double) {
            return new ConfigDouble(origin, (Double) object, null);
        } else if (object instanceof Integer) {
            return new ConfigInt(origin, (Integer) object, null);
        } else if (object instanceof Long) {
            return new ConfigLong(origin, (Long) object, null);
        } else {
            return ConfigNumber.newNumber(origin, ((Number) object).doubleValue(), null);
        }
    } else if (object instanceof Duration) {
        return new ConfigLong(origin, ((Duration) object).toMillis(), null);
    } else if (object instanceof Map) {
        if (((Map<?, ?>) object).isEmpty())
            return emptyObject(origin);
        if (mapMode == FromMapMode.KEYS_ARE_KEYS) {
            Map<String, AbstractConfigValue> values = new HashMap<String, AbstractConfigValue>();
            for (Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) {
                Object key = entry.getKey();
                if (!(key instanceof String))
                    throw new ConfigException.BugOrBroken("bug in method caller: not valid to create ConfigObject from map with non-String key: " + key);
                AbstractConfigValue value = fromAnyRef(entry.getValue(), origin, mapMode);
                values.put((String) key, value);
            }
            return new SimpleConfigObject(origin, values);
        } else {
            return PropertiesParser.fromPathMap(origin, (Map<?, ?>) object);
        }
    } else if (object instanceof Iterable) {
        Iterator<?> i = ((Iterable<?>) object).iterator();
        if (!i.hasNext())
            return emptyList(origin);
        List<AbstractConfigValue> values = new ArrayList<AbstractConfigValue>();
        while (i.hasNext()) {
            AbstractConfigValue v = fromAnyRef(i.next(), origin, mapMode);
            values.add(v);
        }
        return new SimpleConfigList(origin, values);
    } else if (object instanceof ConfigMemorySize) {
        return new ConfigLong(origin, ((ConfigMemorySize) object).toBytes(), null);
    } else {
        throw new ConfigException.BugOrBroken("bug in method caller: not valid to create ConfigValue from: " + object);
    }
}
Also used : HashMap(java.util.HashMap) ConfigException(com.typesafe.config.ConfigException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Duration(java.time.Duration) ConfigMemorySize(com.typesafe.config.ConfigMemorySize) ConfigObject(com.typesafe.config.ConfigObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 97 with Duration

use of java.time.Duration in project wildfly by wildfly.

the class RecordableInactiveSessionStatistics method getMeanSessionLifetime.

@Override
public Duration getMeanSessionLifetime() {
    Map.Entry<Duration, Long> totals = this.totals.get();
    Duration lifetime = totals.getKey();
    long count = totals.getValue();
    return (count > 0) ? lifetime.dividedBy(count) : Duration.ZERO;
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Duration(java.time.Duration) AbstractMap(java.util.AbstractMap) Map(java.util.Map)

Example 98 with Duration

use of java.time.Duration in project wildfly by wildfly.

the class ImmutableHttpSessionAdapterTestCase method getMaxInactiveInterval.

@Test
public void getMaxInactiveInterval() {
    SessionMetaData metaData = mock(SessionMetaData.class);
    Duration interval = Duration.of(100L, ChronoUnit.SECONDS);
    when(this.session.getMetaData()).thenReturn(metaData);
    when(metaData.getMaxInactiveInterval()).thenReturn(interval);
    int result = this.httpSession.getMaxInactiveInterval();
    assertEquals(interval.getSeconds(), result);
}
Also used : Duration(java.time.Duration) Test(org.junit.Test)

Example 99 with Duration

use of java.time.Duration in project wildfly by wildfly.

the class DistributableSessionManagerTestCase method getSessionByIdentifier.

@Test
public void getSessionByIdentifier() {
    Batcher<Batch> batcher = mock(Batcher.class);
    Batch batch = mock(Batch.class);
    ImmutableSession session = mock(ImmutableSession.class);
    ImmutableSessionAttributes attributes = mock(ImmutableSessionAttributes.class);
    ImmutableSessionMetaData metaData = mock(ImmutableSessionMetaData.class);
    String id = "session";
    String name = "name";
    Object value = new Object();
    Set<String> names = Collections.singleton(name);
    Instant creationTime = Instant.now();
    Instant lastAccessedTime = Instant.now();
    Duration maxInactiveInterval = Duration.ofMinutes(30L);
    when(this.manager.getBatcher()).thenReturn(batcher);
    when(this.manager.viewSession(id)).thenReturn(session);
    when(session.getId()).thenReturn(id);
    when(session.getAttributes()).thenReturn(attributes);
    when(attributes.getAttributeNames()).thenReturn(names);
    when(attributes.getAttribute(name)).thenReturn(value);
    when(session.getMetaData()).thenReturn(metaData);
    when(metaData.getCreationTime()).thenReturn(creationTime);
    when(metaData.getLastAccessedTime()).thenReturn(lastAccessedTime);
    when(metaData.getMaxInactiveInterval()).thenReturn(maxInactiveInterval);
    when(batcher.createBatch()).thenReturn(batch);
    io.undertow.server.session.Session result = this.adapter.getSession(id);
    assertSame(this.adapter, result.getSessionManager());
    assertSame(id, result.getId());
    assertEquals(creationTime.toEpochMilli(), result.getCreationTime());
    assertEquals(lastAccessedTime.toEpochMilli(), result.getLastAccessedTime());
    assertEquals(maxInactiveInterval.getSeconds(), result.getMaxInactiveInterval());
    assertEquals(names, result.getAttributeNames());
    assertSame(value, result.getAttribute(name));
    verify(batch).close();
}
Also used : ImmutableSessionAttributes(org.wildfly.clustering.web.session.ImmutableSessionAttributes) ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) Instant(java.time.Instant) Duration(java.time.Duration) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) Batch(org.wildfly.clustering.ee.Batch) Test(org.junit.Test)

Example 100 with Duration

use of java.time.Duration in project wildfly by wildfly.

the class ScheduleSchedulerCommand method readObject.

private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
    Instant creationTime = (Instant) in.readObject();
    Duration maxInactiveInterval = (Duration) in.readObject();
    Duration lastAccessedDuration = (Duration) in.readObject();
    SessionCreationMetaData creationMetaData = new SimpleSessionCreationMetaData(creationTime);
    creationMetaData.setMaxInactiveInterval(maxInactiveInterval);
    SessionAccessMetaData accessMetaData = new SimpleSessionAccessMetaData();
    accessMetaData.setLastAccessedDuration(lastAccessedDuration);
    this.metaData = new SimpleSessionMetaData(creationMetaData, accessMetaData);
}
Also used : Instant(java.time.Instant) Duration(java.time.Duration)

Aggregations

Duration (java.time.Duration)195 Test (org.testng.annotations.Test)135 Instant (java.time.Instant)17 Test (org.junit.Test)16 List (java.util.List)6 Map (java.util.Map)4 ZonedDateTime (java.time.ZonedDateTime)3 ArrayList (java.util.ArrayList)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ReplSetHeartbeatReply (com.torodb.mongodb.commands.signatures.internal.ReplSetHeartbeatReply)2 LocalDateTime (java.time.LocalDateTime)2 OffsetDateTime (java.time.OffsetDateTime)2 ZoneId (java.time.ZoneId)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 Iterator (java.util.Iterator)2 Optional (java.util.Optional)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Collectors (java.util.stream.Collectors)2 Edge (org.apache.tinkerpop.gremlin.structure.Edge)2 JSONLexer (com.alibaba.fastjson.parser.JSONLexer)1