From ba691ef7a9ee4b0abd121dd487859f8fb38a0fa1 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 22 Jun 2015 17:30:12 +0200 Subject: Update api --- .../openslx/bwlp/thrift/iface/LectureWrite.java | 77 ++++++++-------- src/main/java/org/openslx/util/TimeoutHashMap.java | 102 +++++++++++++++++++++ .../java/org/openslx/util/TimeoutReference.java | 12 +++ 3 files changed, 155 insertions(+), 36 deletions(-) create mode 100644 src/main/java/org/openslx/util/TimeoutHashMap.java (limited to 'src/main/java/org') diff --git a/src/main/java/org/openslx/bwlp/thrift/iface/LectureWrite.java b/src/main/java/org/openslx/bwlp/thrift/iface/LectureWrite.java index ea4bd53..2259b45 100644 --- a/src/main/java/org/openslx/bwlp/thrift/iface/LectureWrite.java +++ b/src/main/java/org/openslx/bwlp/thrift/iface/LectureWrite.java @@ -67,8 +67,8 @@ public class LectureWrite implements org.apache.thrift.TBase nics; // required - public List allowedUsers; // required - public List networkExceptions; // required + public List allowedUsers; // optional + public List networkExceptions; // optional public boolean isExam; // required public boolean hasInternetAccess; // required public LecturePermissions defaultPermissions; // required @@ -181,6 +181,7 @@ public class LectureWrite implements org.apache.thrift.TBase metaDataMap; static { Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); @@ -205,10 +206,10 @@ public class LectureWrite implements org.apache.thrift.TBase nics, - List allowedUsers, - List networkExceptions, boolean isExam, boolean hasInternetAccess, LecturePermissions defaultPermissions) @@ -256,8 +255,6 @@ public class LectureWrite implements org.apache.thrift.TBase implements Map +{ + + private final Map> map; + private final long timeout; + + public TimeoutHashMap( long timeout ) + { + this.map = new HashMap<>(); + this.timeout = timeout; + } + + @Override + public int size() + { + return map.size(); + } + + @Override + public boolean isEmpty() + { + return map.isEmpty(); + } + + @Override + public boolean containsKey( Object key ) + { + return map.containsKey( key ); + } + + @Override + public boolean containsValue( Object value ) + { + return map.containsValue( value ); + } + + @Override + public V get( Object key ) + { + TimeoutReference timeoutReference = map.get( key ); + if ( timeoutReference == null ) + return null; + return timeoutReference.get(); + } + + @Override + public V put( K key, V value ) + { + map.put( key, new TimeoutReference( + false, timeout, value ) ); + return value; + } + + @Override + public V remove( Object key ) + { + TimeoutReference remove = map.remove( key ); + if ( remove == null ) + return null; + return remove.get(); + } + + @Override + public void putAll( Map m ) + { + for ( java.util.Map.Entry entry : m.entrySet() ) { + put( entry.getKey(), entry.getValue() ); + } + } + + @Override + public void clear() + { + map.clear(); + } + + @Override + public Set keySet() + { + return map.keySet(); + } + + @Override + public Collection values() + { + throw new UnsupportedOperationException(); + } + + @Override + public Set> entrySet() + { + throw new UnsupportedOperationException(); + } + +} diff --git a/src/main/java/org/openslx/util/TimeoutReference.java b/src/main/java/org/openslx/util/TimeoutReference.java index 4d7a992..e86c6c7 100644 --- a/src/main/java/org/openslx/util/TimeoutReference.java +++ b/src/main/java/org/openslx/util/TimeoutReference.java @@ -46,4 +46,16 @@ public class TimeoutReference this.deadline = System.currentTimeMillis() + timeoutMs; } + @Override + public int hashCode() + { + return item.hashCode(); + } + + @Override + public boolean equals( Object o ) + { + return this == o || item.equals( o ); + } + } -- cgit v1.2.3-55-g7522