Merge branch 'master' of github.com:redisson/redisson

pull/1613/head
Nikita 7 years ago
commit 1faaaca92c

@ -57,29 +57,34 @@ Features
Used by
================================
[![Jeppesen](https://redisson.org/assets/logos/client25.png "Jeppesen")](https://www.jeppesen.com/)    
[![Siemens](https://redisson.org/assets/logos/client29.png "Siemens")](https://www.siemens.com)    
[![BMW GROUP](https://redisson.org/assets/logos/client27.png "BMW GROUP")](https://www.bmwgroup.com)    
[![AIG](https://redisson.org/assets/logos/client24.png "AIG")](https://www.aig.com/)    
[![Adobe](https://redisson.org/assets/logos/client23.png "Adobe")](https://www.adobe.com/)    
[![S&P Global](https://redisson.org/assets/logos/client20.png "S&P Global")](https://www.spglobal.com/)    
[![SAP](https://redisson.org/assets/logos/client12.png "SAP")](http://www.sap.com/)    
[![EA](https://redisson.org/assets/logos/client1.png "EA")](http://ea.com/)    
[![BROOKHAVEN](https://redisson.org/assets/logos/client6.png "Brookhaven National Laboratory")](http://bnl.gov/)
[![Adobe](https://redisson.org/assets/logos/client23.png "Adobe")](https://www.adobe.com/)
[![New Relic Synthetics](https://redisson.org/assets/logos/client3.png "New Relic Synthetics")](http://newrelic.com/synthetics)    
[![Singtel](https://redisson.org/assets/logos/client5.png "New Relic Synthetics")](http://singtel.com/)    
[![Jeppesen](https://redisson.org/assets/logos/client25.png "Jeppesen")](https://www.jeppesen.com/)    
[![BROOKHAVEN](https://redisson.org/assets/logos/client6.png "Brookhaven National Laboratory")](http://bnl.gov/)    
[![New Relic Synthetics](https://redisson.org/assets/logos/client3.png "New Relic Synthetics")](http://newrelic.com/synthetics)    
[![Netflix](https://redisson.org/assets/logos/client10.png "Netflix")](https://netflix.com/)    
[![Personal Capital](https://redisson.org/assets/logos/client26.png "Personal Capital")](https://www.personalcapital.com)
[![Singtel](https://redisson.org/assets/logos/client5.png "New Relic Synthetics")](http://singtel.com/)    
[![Baidu](https://redisson.org/assets/logos/client2.png "Baidu")](http://baidu.com/)    
[![Infor](https://redisson.org/assets/logos/client4.png "Infor")](http://www.infor.com/)    
[![Crimson Hexagon](https://redisson.org/assets/logos/client7.png "Crimson Hexagon")](https://www.crimsonhexagon.com/)
[![Crimson Hexagon](https://redisson.org/assets/logos/client7.png "Crimson Hexagon")](https://www.crimsonhexagon.com/)    
[![ContaAzul](https://redisson.org/assets/logos/client18.png "ContaAzul")](https://contaazul.com/)
[![Datorama](https://redisson.org/assets/logos/client8.png "Datorama")](https://datorama.com/)   
[![Invaluable](https://redisson.org/assets/logos/client13.png "Invaluable")](http://www.invaluable.com/)   
[![Ticketmaster](https://redisson.org/assets/logos/client14.png "Ticketmaster")](http://www.ticketmaster.com/)   
[![ContaAzul](https://redisson.org/assets/logos/client18.png "ContaAzul")](https://contaazul.com/)   
[![NAB](https://redisson.org/assets/logos/client11.png "NAB")](https://www.nab.com.au/)
[![NAB](https://redisson.org/assets/logos/client11.png "NAB")](https://www.nab.com.au/)   
[![RCI](https://redisson.org/assets/logos/client30.png "RCI")](https://www.rci.com/)
[![Alibaba](https://redisson.org/assets/logos/client19.png "Alibaba")](http://www.alibaba-inc.com)   
[![Flipkart](https://redisson.org/assets/logos/client21.png "Flipkart")](https://www.flipkart.com/)   
[![Invaluable](https://redisson.org/assets/logos/client13.png "Invaluable")](http://www.invaluable.com/)   
[![BBK](https://redisson.org/assets/logos/client22.png "BBK")](http://www.gdbbk.com/)
[![SULAKE](https://redisson.org/assets/logos/client17.png "SULAKE")](http://www.sulake.com/)   

@ -29,9 +29,11 @@ Usage
* `AFTER_REQUEST` - all session attributes are stored into Redis after each request.
<br/>
`sharedSession` - share single session across multiple deployed applications. Works only in `readMode=REDIS`.
`sharedSession` - share session across multiple deployed applications. Appropriate for migration EAR based application with multiple WARs. Works only in `readMode=REDIS`.
<i>This option available only in [Redisson PRO](http://redisson.pro) edition.</i>
* `false` - don't share single session. Default mode.
* `true` - share single session. <i>This option available only in [Redisson PRO](http://redisson.pro) edition.</i>
* `true` - share single session.
Requires to set `crossContext` setting in `tomcat/conf/context.xml`
```xml

@ -19,14 +19,11 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class CompositeIterable<T> implements Iterable<T>, Iterator<T> {
public class CompositeIterable<T> implements Iterable<T> {
private List<Iterable<T>> iterablesList;
private Iterable<T>[] iterables;
private Iterator<Iterator<T>> listIterator;
private Iterator<T> currentIterator;
public CompositeIterable(List<Iterable<T>> iterables) {
this.iterablesList = iterables;
}
@ -52,35 +49,7 @@ public class CompositeIterable<T> implements Iterable<T>, Iterator<T> {
iterators.add(iterable.iterator());
}
}
listIterator = iterators.iterator();
currentIterator = null;
return this;
Iterator<Iterator<T>> listIterator = iterators.iterator();
return new CompositeIterator<T>(listIterator);
}
@Override
public boolean hasNext() {
if (currentIterator == null || !currentIterator.hasNext()) {
while (listIterator.hasNext()) {
Iterator<T> iterator = listIterator.next();
if (iterator.hasNext()) {
currentIterator = iterator;
return true;
}
}
return false;
}
return currentIterator.hasNext();
}
@Override
public T next() {
hasNext();
return currentIterator.next();
}
@Override
public void remove() {
currentIterator.remove();
}
}

@ -0,0 +1,66 @@
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson.misc;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* @author Pepe Lu
*/
public class CompositeIterator<T> implements Iterator<T> {
private Iterator<Iterator<T>> listIterator;
private Iterator<T> currentIterator;
public CompositeIterator(Iterator<Iterator<T>> iterators) {
listIterator = iterators;
}
@Override
public boolean hasNext() {
if (currentIterator == null || !currentIterator.hasNext()) {
while (listIterator.hasNext()) {
Iterator<T> iterator = listIterator.next();
currentIterator = iterator;
if (iterator.hasNext()) {
return true;
}
}
return false;
}
return currentIterator.hasNext();
}
@Override
public T next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
return currentIterator.next();
}
@Override
public void remove() {
if (currentIterator == null) {
throw new IllegalStateException("next() has not yet been called");
}
currentIterator.remove();
}
}

@ -0,0 +1,132 @@
package org.redisson.misc;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import java.util.*;
import org.junit.Test;
/**
* @author Pepe Lu
*/
public class CompositeIteratorTest {
@Test
public void testHasNextWithEmpty() {
List<Integer> emptyList = new ArrayList<Integer>();
CompositeIterable<Integer> compositeIterable = new CompositeIterable<Integer>(
emptyList);
assertFalse(compositeIterable.iterator().hasNext());
}
@Test(expected = NoSuchElementException.class)
public void testNextWithEmpty() {
List<Integer> emptyList = new ArrayList<Integer>();
CompositeIterable<Integer> compositeIterable = new CompositeIterable<Integer>(
emptyList);
compositeIterable.iterator().next();
}
@Test
public void testNextWithOne() {
List<Integer> list = Arrays.asList(1, 2);
CompositeIterable<Integer> compositeIterable = new CompositeIterable<Integer>(
list);
Iterator<Integer> iterator = compositeIterable.iterator();
assertThat(iterator.next()).isEqualTo(1);
assertThat(iterator.next()).isEqualTo(2);
assertFalse(iterator.hasNext());
}
@Test
public void testNextWithTwo() {
List<Integer> list1 = Arrays.asList(1, 2);
List<Integer> list2 = Arrays.asList(3, 4);
CompositeIterable<Integer> compositeIterable = new CompositeIterable<Integer>(
list1, list2);
Iterator<Integer> iterator = compositeIterable.iterator();
assertThat(iterator.next()).isEqualTo(1);
assertThat(iterator.next()).isEqualTo(2);
assertThat(iterator.next()).isEqualTo(3);
assertThat(iterator.next()).isEqualTo(4);
assertFalse(iterator.hasNext());
}
@Test(expected = IllegalStateException.class)
public void testRemoveWithEmpty() {
List<Integer> emptyList = new ArrayList<Integer>();
CompositeIterable<Integer> compositeIterable = new CompositeIterable<Integer>(
emptyList);
compositeIterable.iterator().remove();
}
@Test
public void testRemoveWithOne() {
/**
* use ArrayList instead of Arrays.asList() because Arrays.asList() is using
* {@link Arrays.ArrayList} which is using {@link AbstractList.Itr} as its
* iterator. And this iterator does not implement remove()
*/
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
CompositeIterable<Integer> compositeIterable = new CompositeIterable<Integer>(
list);
Iterator<Integer> iterator = compositeIterable.iterator();
int count = list.size();
while (iterator.hasNext()) {
iterator.next();
iterator.remove();
count--;
}
assertThat(count).isEqualTo(0);
assertThat(list.size()).isEqualTo(0);
}
@Test
public void testRemoveWithTwo() {
List<Integer> list1 = new ArrayList<Integer>();
list1.add(1);
list1.add(2);
List<Integer> list2 = new ArrayList<Integer>();
list2.add(3);
list2.add(4);
CompositeIterable<Integer> compositeIterable = new CompositeIterable<Integer>(
list1, list2);
Iterator<Integer> iterator = compositeIterable.iterator();
int count = list1.size() + list2.size();
while (iterator.hasNext()) {
iterator.next();
iterator.remove();
count--;
}
assertThat(count).isEqualTo(0);
assertThat(list1.size()).isEqualTo(0);
assertThat(list2.size()).isEqualTo(0);
}
@Test
public void testPartialIterationWithTwo(){
List<Integer> list1 = new ArrayList<Integer>();
list1.add(1);
list1.add(2);
List<Integer> list2 = new ArrayList<Integer>();
list2.add(3);
list2.add(4);
CompositeIterable<Integer> compositeIterable = new CompositeIterable<Integer>(
list1, list2);
Iterator<Integer> iterator = compositeIterable.iterator();
iterator.next();
iterator.remove();
iterator.next();
iterator.next();
iterator.remove();
assertThat(list1.size()).isEqualTo(1);
assertThat(list2.size()).isEqualTo(1);
assertThat(list1.get(0)).isEqualTo(2);
assertThat(list2.get(0)).isEqualTo(4);
}
}
Loading…
Cancel
Save