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);
}
}
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;
}
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);
}
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();
}
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);
}
Aggregations