Skip to content

Commit

Permalink
Replace AbstractImmutableSessionMetaData with default ImmutableSessio…
Browse files Browse the repository at this point in the history
…nMetaData methods.
  • Loading branch information
pferraro committed May 22, 2019
1 parent 9e4ca6e commit 28eea71
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 51 deletions.

This file was deleted.

Expand Up @@ -28,7 +28,7 @@
* Composite view of the meta data of a session, combining volatile and static aspects.
* @author Paul Ferraro
*/
public class CompositeSessionMetaData extends AbstractImmutableSessionMetaData implements InvalidatableSessionMetaData {
public class CompositeSessionMetaData implements InvalidatableSessionMetaData {

private final SessionCreationMetaData creationMetaData;
private final SessionAccessMetaData accessMetaData;
Expand All @@ -40,7 +40,7 @@ public CompositeSessionMetaData(SessionCreationMetaData creationMetaData, Sessio

@Override
public boolean isNew() {
// We can implement this more efficiently than the super implementation
// We can implement this more efficiently than the default implementation
return this.accessMetaData.getLastAccessedDuration().isZero();
}

Expand Down
Expand Up @@ -30,7 +30,7 @@
* An immutable "snapshot" of a session's meta-data which can be accessed outside the scope of a transaction.
* @author Paul Ferraro
*/
public class SimpleImmutableSessionMetaData extends AbstractImmutableSessionMetaData {
public class SimpleImmutableSessionMetaData implements ImmutableSessionMetaData {

private final Instant creationTime;
private final Instant lastAccessedTime;
Expand Down
Expand Up @@ -29,17 +29,23 @@
* @author Paul Ferraro
*/
public interface ImmutableSessionMetaData {

/**
* Indicates whether or not this session was created by the current thread.
* @return true, if this session is new, false otherwise
*/
boolean isNew();
default boolean isNew() {
return this.getCreationTime().equals(this.getLastAccessedTime());
}

/**
* Indicates whether or not this session was previously idle for longer than the maximum inactive interval.
* @return true, if this session is expired, false otherwise
*/
boolean isExpired();
default boolean isExpired() {
Duration maxInactiveInterval = this.getMaxInactiveInterval();
return !maxInactiveInterval.isZero() ? this.getLastAccessedTime().plus(maxInactiveInterval).isBefore(Instant.now()) : false;
}

/**
* Returns the time this session was created.
Expand Down

0 comments on commit 28eea71

Please sign in to comment.