Committed by
Gerrit Code Review
SQueue: lazily deserialize iterator
Change-Id: I09ba574a0479181774e287d8a39286c976740675
Showing
1 changed file
with
23 additions
and
5 deletions
... | @@ -15,15 +15,16 @@ | ... | @@ -15,15 +15,16 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.store.hz; | 16 | package org.onlab.onos.store.hz; |
17 | 17 | ||
18 | -import com.google.common.collect.Lists; | 18 | +import com.google.common.base.Function; |
19 | +import com.google.common.collect.FluentIterable; | ||
19 | import com.hazelcast.core.IQueue; | 20 | import com.hazelcast.core.IQueue; |
20 | import com.hazelcast.core.ItemListener; | 21 | import com.hazelcast.core.ItemListener; |
21 | import com.hazelcast.monitor.LocalQueueStats; | 22 | import com.hazelcast.monitor.LocalQueueStats; |
23 | + | ||
22 | import org.onlab.onos.store.serializers.StoreSerializer; | 24 | import org.onlab.onos.store.serializers.StoreSerializer; |
23 | 25 | ||
24 | import java.util.Collection; | 26 | import java.util.Collection; |
25 | import java.util.Iterator; | 27 | import java.util.Iterator; |
26 | -import java.util.List; | ||
27 | import java.util.concurrent.TimeUnit; | 28 | import java.util.concurrent.TimeUnit; |
28 | 29 | ||
29 | import static com.google.common.base.Preconditions.checkNotNull; | 30 | import static com.google.common.base.Preconditions.checkNotNull; |
... | @@ -105,11 +106,13 @@ public class SQueue<T> implements IQueue<T> { | ... | @@ -105,11 +106,13 @@ public class SQueue<T> implements IQueue<T> { |
105 | return q.contains(serialize(o)); | 106 | return q.contains(serialize(o)); |
106 | } | 107 | } |
107 | 108 | ||
109 | + @Deprecated // not implemented yet | ||
108 | @Override | 110 | @Override |
109 | public int drainTo(Collection<? super T> collection) { | 111 | public int drainTo(Collection<? super T> collection) { |
110 | throw new UnsupportedOperationException(); | 112 | throw new UnsupportedOperationException(); |
111 | } | 113 | } |
112 | 114 | ||
115 | + @Deprecated // not implemented yet | ||
113 | @Override | 116 | @Override |
114 | public int drainTo(Collection<? super T> collection, int i) { | 117 | public int drainTo(Collection<? super T> collection, int i) { |
115 | throw new UnsupportedOperationException(); | 118 | throw new UnsupportedOperationException(); |
... | @@ -147,36 +150,42 @@ public class SQueue<T> implements IQueue<T> { | ... | @@ -147,36 +150,42 @@ public class SQueue<T> implements IQueue<T> { |
147 | 150 | ||
148 | @Override | 151 | @Override |
149 | public Iterator<T> iterator() { | 152 | public Iterator<T> iterator() { |
150 | - List<T> list = Lists.newArrayList(); | 153 | + return FluentIterable.from(q) |
151 | - q.forEach(elem -> list.add(deserialize(elem))); | 154 | + .transform(new DeserializeVal()) |
152 | - return list.iterator(); | 155 | + .iterator(); |
153 | } | 156 | } |
154 | 157 | ||
158 | + @Deprecated // not implemented yet | ||
155 | @Override | 159 | @Override |
156 | public Object[] toArray() { | 160 | public Object[] toArray() { |
157 | throw new UnsupportedOperationException(); | 161 | throw new UnsupportedOperationException(); |
158 | } | 162 | } |
159 | 163 | ||
164 | + @Deprecated // not implemented yet | ||
160 | @Override | 165 | @Override |
161 | public <T1> T1[] toArray(T1[] t1s) { | 166 | public <T1> T1[] toArray(T1[] t1s) { |
162 | throw new UnsupportedOperationException(); | 167 | throw new UnsupportedOperationException(); |
163 | } | 168 | } |
164 | 169 | ||
170 | + @Deprecated // not implemented yet | ||
165 | @Override | 171 | @Override |
166 | public boolean containsAll(Collection<?> collection) { | 172 | public boolean containsAll(Collection<?> collection) { |
167 | throw new UnsupportedOperationException(); | 173 | throw new UnsupportedOperationException(); |
168 | } | 174 | } |
169 | 175 | ||
176 | + @Deprecated // not implemented yet | ||
170 | @Override | 177 | @Override |
171 | public boolean addAll(Collection<? extends T> collection) { | 178 | public boolean addAll(Collection<? extends T> collection) { |
172 | throw new UnsupportedOperationException(); | 179 | throw new UnsupportedOperationException(); |
173 | } | 180 | } |
174 | 181 | ||
182 | + @Deprecated // not implemented yet | ||
175 | @Override | 183 | @Override |
176 | public boolean removeAll(Collection<?> collection) { | 184 | public boolean removeAll(Collection<?> collection) { |
177 | throw new UnsupportedOperationException(); | 185 | throw new UnsupportedOperationException(); |
178 | } | 186 | } |
179 | 187 | ||
188 | + @Deprecated // not implemented yet | ||
180 | @Override | 189 | @Override |
181 | public boolean retainAll(Collection<?> collection) { | 190 | public boolean retainAll(Collection<?> collection) { |
182 | throw new UnsupportedOperationException(); | 191 | throw new UnsupportedOperationException(); |
... | @@ -192,11 +201,13 @@ public class SQueue<T> implements IQueue<T> { | ... | @@ -192,11 +201,13 @@ public class SQueue<T> implements IQueue<T> { |
192 | return q.getLocalQueueStats(); | 201 | return q.getLocalQueueStats(); |
193 | } | 202 | } |
194 | 203 | ||
204 | + @Deprecated // not implemented yet | ||
195 | @Override | 205 | @Override |
196 | public String addItemListener(ItemListener<T> itemListener, boolean b) { | 206 | public String addItemListener(ItemListener<T> itemListener, boolean b) { |
197 | throw new UnsupportedOperationException(); | 207 | throw new UnsupportedOperationException(); |
198 | } | 208 | } |
199 | 209 | ||
210 | + @Deprecated // not implemented yet | ||
200 | @Override | 211 | @Override |
201 | public boolean removeItemListener(String s) { | 212 | public boolean removeItemListener(String s) { |
202 | throw new UnsupportedOperationException(); | 213 | throw new UnsupportedOperationException(); |
... | @@ -227,4 +238,11 @@ public class SQueue<T> implements IQueue<T> { | ... | @@ -227,4 +238,11 @@ public class SQueue<T> implements IQueue<T> { |
227 | public void destroy() { | 238 | public void destroy() { |
228 | q.destroy(); | 239 | q.destroy(); |
229 | } | 240 | } |
241 | + | ||
242 | + private final class DeserializeVal implements Function<byte[], T> { | ||
243 | + @Override | ||
244 | + public T apply(byte[] input) { | ||
245 | + return deserialize(input); | ||
246 | + } | ||
247 | + } | ||
230 | } | 248 | } | ... | ... |
-
Please register or login to post a comment