Merge branch 'mrniko/master'
commit
a4c9b412df
@ -0,0 +1,40 @@
|
||||
# Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
#
|
||||
# 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.
|
||||
|
||||
sudo: false
|
||||
dist: trusty
|
||||
|
||||
language: java
|
||||
jdk:
|
||||
- oraclejdk8
|
||||
env:
|
||||
matrix:
|
||||
- REDIS_VERSION=3.0.7
|
||||
- REDIS_VERSION=2.8.24
|
||||
- REDIS_VERSION=3.2.0-rc3
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.m2
|
||||
install:
|
||||
- export REDIS_BIN=$HOME/redis/${REDIS_VERSION}/bin
|
||||
- wget -c https://github.com/antirez/redis/archive/${REDIS_VERSION}.tar.gz -O redis-${REDIS_VERSION}.tar.gz
|
||||
- tar -xvf redis-${REDIS_VERSION}.tar.gz
|
||||
- make -C redis-${REDIS_VERSION} PREFIX=$HOME/redis/${REDIS_VERSION} install
|
||||
before_script:
|
||||
- $REDIS_BIN/redis-server --daemonize yes
|
||||
- sleep 3
|
||||
- $REDIS_BIN/redis-cli PING
|
||||
- export REDIS_VERSION="$(redis-cli INFO SERVER | sed -n 2p)"
|
||||
- echo $REDIS_VERSION
|
||||
script: mvn -DargLine="-DredisBinary=$REDIS_BIN/redis-server -DtravisEnv=true" -Punit-test -Ptravis clean verify
|
@ -0,0 +1,143 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.redisson.client.protocol.decoder.ListScanResult;
|
||||
|
||||
abstract class RedissonBaseIterator<V> implements Iterator<V> {
|
||||
|
||||
private List<V> firstValues;
|
||||
private List<V> lastValues;
|
||||
private Iterator<V> lastIter;
|
||||
protected long nextIterPos;
|
||||
protected InetSocketAddress client;
|
||||
|
||||
private boolean finished;
|
||||
private boolean currentElementRemoved;
|
||||
private boolean removeExecuted;
|
||||
private V value;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if (lastIter == null || !lastIter.hasNext()) {
|
||||
if (finished) {
|
||||
|
||||
currentElementRemoved = false;
|
||||
removeExecuted = false;
|
||||
client = null;
|
||||
firstValues = null;
|
||||
lastValues = null;
|
||||
nextIterPos = 0;
|
||||
|
||||
if (!tryAgain()) {
|
||||
return false;
|
||||
}
|
||||
finished = false;
|
||||
}
|
||||
long prevIterPos;
|
||||
do {
|
||||
prevIterPos = nextIterPos;
|
||||
ListScanResult<V> res = iterator(client, nextIterPos);
|
||||
lastValues = new ArrayList<V>(res.getValues());
|
||||
client = res.getRedisClient();
|
||||
|
||||
if (nextIterPos == 0 && firstValues == null) {
|
||||
firstValues = lastValues;
|
||||
lastValues = null;
|
||||
if (firstValues.isEmpty() && tryAgain()) {
|
||||
client = null;
|
||||
firstValues = null;
|
||||
nextIterPos = 0;
|
||||
prevIterPos = -1;
|
||||
}
|
||||
} else {
|
||||
if (firstValues.isEmpty()) {
|
||||
firstValues = lastValues;
|
||||
lastValues = null;
|
||||
if (firstValues.isEmpty() && tryAgain()) {
|
||||
client = null;
|
||||
firstValues = null;
|
||||
nextIterPos = 0;
|
||||
prevIterPos = -1;
|
||||
continue;
|
||||
}
|
||||
} else if (lastValues.removeAll(firstValues)) {
|
||||
currentElementRemoved = false;
|
||||
removeExecuted = false;
|
||||
client = null;
|
||||
firstValues = null;
|
||||
lastValues = null;
|
||||
nextIterPos = 0;
|
||||
prevIterPos = -1;
|
||||
if (tryAgain()) {
|
||||
continue;
|
||||
}
|
||||
finished = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
lastIter = res.getValues().iterator();
|
||||
nextIterPos = res.getPos();
|
||||
} while (!lastIter.hasNext() && nextIterPos != prevIterPos);
|
||||
if (prevIterPos == nextIterPos && !removeExecuted) {
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
return lastIter.hasNext();
|
||||
}
|
||||
|
||||
protected boolean tryAgain() {
|
||||
return false;
|
||||
}
|
||||
|
||||
abstract ListScanResult<V> iterator(InetSocketAddress client, long nextIterPos);
|
||||
|
||||
@Override
|
||||
public V next() {
|
||||
if (!hasNext()) {
|
||||
throw new NoSuchElementException("No such element");
|
||||
}
|
||||
|
||||
value = lastIter.next();
|
||||
currentElementRemoved = false;
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
if (currentElementRemoved) {
|
||||
throw new IllegalStateException("Element been already deleted");
|
||||
}
|
||||
if (lastIter == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
firstValues.remove(value);
|
||||
lastIter.remove();
|
||||
remove(value);
|
||||
currentElementRemoved = true;
|
||||
removeExecuted = true;
|
||||
}
|
||||
|
||||
abstract void remove(V value);
|
||||
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.redisson.client.codec.Codec;
|
||||
import org.redisson.client.codec.DelegateDecoderCodec;
|
||||
import org.redisson.client.protocol.RedisCommand;
|
||||
import org.redisson.client.protocol.RedisCommand.ValueType;
|
||||
import org.redisson.client.protocol.RedisCommands;
|
||||
import org.redisson.command.CommandExecutor;
|
||||
import org.redisson.connection.decoder.MapGetAllDecoder;
|
||||
import org.redisson.core.RBucket;
|
||||
import org.redisson.core.RBuckets;
|
||||
|
||||
import io.netty.util.concurrent.Future;
|
||||
|
||||
public class RedissonBuckets implements RBuckets {
|
||||
|
||||
private final Codec codec;
|
||||
private final CommandExecutor commandExecutor;
|
||||
private final Redisson redisson;
|
||||
|
||||
public RedissonBuckets(Redisson redisson, CommandExecutor commandExecutor) {
|
||||
this(redisson, commandExecutor.getConnectionManager().getCodec(), commandExecutor);
|
||||
}
|
||||
|
||||
public RedissonBuckets(Redisson redisson, Codec codec, CommandExecutor commandExecutor) {
|
||||
super();
|
||||
this.codec = codec;
|
||||
this.commandExecutor = commandExecutor;
|
||||
this.redisson = redisson;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> List<RBucket<V>> find(String pattern) {
|
||||
Collection<String> keys = commandExecutor.get(commandExecutor.<List<String>, String>readAllAsync(RedisCommands.KEYS, pattern));
|
||||
List<RBucket<V>> buckets = new ArrayList<RBucket<V>>(keys.size());
|
||||
for (String key : keys) {
|
||||
if(key == null) {
|
||||
continue;
|
||||
}
|
||||
buckets.add(redisson.<V>getBucket(key, codec));
|
||||
}
|
||||
return buckets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> Map<String, V> get(String... keys) {
|
||||
if (keys.length == 0) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("MGET", new MapGetAllDecoder(Arrays.<Object>asList(keys), 0), ValueType.OBJECTS);
|
||||
Future<Map<String, V>> future = commandExecutor.readAsync(keys[0], new DelegateDecoderCodec(codec), command, keys);
|
||||
return commandExecutor.get(future);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trySet(Map<String, ?> buckets) {
|
||||
if (buckets.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Object> params = new ArrayList<Object>(buckets.size());
|
||||
for (Entry<String, ?> entry : buckets.entrySet()) {
|
||||
params.add(entry.getKey());
|
||||
try {
|
||||
params.add(codec.getValueEncoder().encode(entry.getValue()));
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return commandExecutor.write(params.get(0).toString(), RedisCommands.MSETNX, params.toArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(Map<String, ?> buckets) {
|
||||
if (buckets.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Object> params = new ArrayList<Object>(buckets.size());
|
||||
for (Entry<String, ?> entry : buckets.entrySet()) {
|
||||
params.add(entry.getKey());
|
||||
try {
|
||||
params.add(codec.getValueEncoder().encode(entry.getValue()));
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
commandExecutor.write(params.get(0).toString(), RedisCommands.MSET, params.toArray());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,197 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.redisson.client.codec.Codec;
|
||||
import org.redisson.client.codec.GeoEntryCodec;
|
||||
import org.redisson.client.codec.ScoredCodec;
|
||||
import org.redisson.client.protocol.RedisCommand;
|
||||
import org.redisson.client.protocol.RedisCommand.ValueType;
|
||||
import org.redisson.client.protocol.RedisCommands;
|
||||
import org.redisson.client.protocol.decoder.GeoDistanceDecoder;
|
||||
import org.redisson.client.protocol.decoder.GeoMapReplayDecoder;
|
||||
import org.redisson.client.protocol.decoder.GeoPositionDecoder;
|
||||
import org.redisson.client.protocol.decoder.GeoPositionMapDecoder;
|
||||
import org.redisson.client.protocol.decoder.MultiDecoder;
|
||||
import org.redisson.client.protocol.decoder.NestedMultiDecoder;
|
||||
import org.redisson.client.protocol.decoder.FlatNestedMultiDecoder;
|
||||
import org.redisson.command.CommandAsyncExecutor;
|
||||
import org.redisson.connection.decoder.MapGetAllDecoder;
|
||||
import org.redisson.core.GeoEntry;
|
||||
import org.redisson.core.GeoPosition;
|
||||
import org.redisson.core.GeoUnit;
|
||||
import org.redisson.core.RGeo;
|
||||
|
||||
import io.netty.util.concurrent.Future;
|
||||
|
||||
public class RedissonGeo<V> extends RedissonExpirable implements RGeo<V> {
|
||||
|
||||
MultiDecoder<Map<Object, Object>> postitionDecoder;
|
||||
MultiDecoder<Map<Object, Object>> distanceDecoder;
|
||||
|
||||
public RedissonGeo(CommandAsyncExecutor connectionManager, String name) {
|
||||
super(connectionManager, name);
|
||||
postitionDecoder = new NestedMultiDecoder(new GeoPositionDecoder(), new GeoDistanceDecoder(codec), new GeoMapReplayDecoder(), true);
|
||||
distanceDecoder = new FlatNestedMultiDecoder(new GeoDistanceDecoder(codec), new GeoMapReplayDecoder(), true);
|
||||
}
|
||||
|
||||
public RedissonGeo(Codec codec, CommandAsyncExecutor connectionManager, String name) {
|
||||
super(codec, connectionManager, name);
|
||||
postitionDecoder = new NestedMultiDecoder(new GeoPositionDecoder(), new GeoDistanceDecoder(codec), new GeoMapReplayDecoder(), true);
|
||||
distanceDecoder = new FlatNestedMultiDecoder(new GeoDistanceDecoder(codec), new GeoMapReplayDecoder(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<Long> addAsync(double longitude, double latitude, V member) {
|
||||
return commandExecutor.writeAsync(getName(), codec, RedisCommands.GEOADD, getName(), convert(longitude), convert(latitude), member);
|
||||
}
|
||||
|
||||
private String convert(double longitude) {
|
||||
return BigDecimal.valueOf(longitude).toPlainString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long add(double longitude, double latitude, V member) {
|
||||
return get(addAsync(longitude, latitude, member));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long add(GeoEntry... entries) {
|
||||
return get(addAsync(entries));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<Long> addAsync(GeoEntry... entries) {
|
||||
List<Object> params = new ArrayList<Object>(entries.length + 1);
|
||||
params.add(getName());
|
||||
for (GeoEntry entry : entries) {
|
||||
params.add(entry.getLongitude());
|
||||
params.add(entry.getLatitude());
|
||||
params.add(entry.getMember());
|
||||
}
|
||||
return commandExecutor.writeAsync(getName(), new GeoEntryCodec(codec), RedisCommands.GEOADD_ENTRIES, params.toArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double dist(V firstMember, V secondMember, GeoUnit geoUnit) {
|
||||
return get(distAsync(firstMember, secondMember, geoUnit));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<Double> distAsync(V firstMember, V secondMember, GeoUnit geoUnit) {
|
||||
return commandExecutor.readAsync(getName(), new ScoredCodec(codec), RedisCommands.GEODIST, getName(), firstMember, secondMember, geoUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<V, String> hash(V... members) {
|
||||
return get(hashAsync(members));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<Map<V, String>> hashAsync(V... members) {
|
||||
List<Object> params = new ArrayList<Object>(members.length + 1);
|
||||
params.add(getName());
|
||||
params.addAll(Arrays.asList(members));
|
||||
RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("GEOHASH", new MapGetAllDecoder(params, 1), 2, ValueType.OBJECTS);
|
||||
return commandExecutor.readAsync(getName(), new ScoredCodec(codec), command, params.toArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<V, GeoPosition> pos(V... members) {
|
||||
return get(posAsync(members));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<Map<V, GeoPosition>> posAsync(V... members) {
|
||||
List<Object> params = new ArrayList<Object>(members.length + 1);
|
||||
params.add(getName());
|
||||
params.addAll(Arrays.asList(members));
|
||||
|
||||
MultiDecoder<Map<Object, Object>> decoder = new NestedMultiDecoder(new GeoPositionDecoder(), new GeoPositionMapDecoder(params), true);
|
||||
RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("GEOPOS", decoder, 2, ValueType.OBJECTS);
|
||||
return commandExecutor.readAsync(getName(), new ScoredCodec(codec), command, params.toArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<V> radius(double longitude, double latitude, double radius, GeoUnit geoUnit) {
|
||||
return get(radiusAsync(longitude, latitude, radius, geoUnit));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<List<V>> radiusAsync(double longitude, double latitude, double radius, GeoUnit geoUnit) {
|
||||
return commandExecutor.readAsync(getName(), codec, RedisCommands.GEORADIUS, getName(), convert(longitude), convert(latitude), radius, geoUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<V, Double> radiusWithDistance(double longitude, double latitude, double radius, GeoUnit geoUnit) {
|
||||
return get(radiusWithDistanceAsync(longitude, latitude, radius, geoUnit));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<Map<V, Double>> radiusWithDistanceAsync(double longitude, double latitude, double radius, GeoUnit geoUnit) {
|
||||
RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("GEORADIUS", distanceDecoder);
|
||||
return commandExecutor.readAsync(getName(), codec, command, getName(), convert(longitude), convert(latitude), radius, geoUnit, "WITHDIST");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<V, GeoPosition> radiusWithPosition(double longitude, double latitude, double radius, GeoUnit geoUnit) {
|
||||
return get(radiusWithPositionAsync(longitude, latitude, radius, geoUnit));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<Map<V, GeoPosition>> radiusWithPositionAsync(double longitude, double latitude, double radius, GeoUnit geoUnit) {
|
||||
RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("GEORADIUS", postitionDecoder);
|
||||
return commandExecutor.readAsync(getName(), codec, command, getName(), convert(longitude), convert(latitude), radius, geoUnit, "WITHCOORD");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<V> radius(V member, double radius, GeoUnit geoUnit) {
|
||||
return get(radiusAsync(member, radius, geoUnit));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<List<V>> radiusAsync(V member, double radius, GeoUnit geoUnit) {
|
||||
return commandExecutor.readAsync(getName(), codec, RedisCommands.GEORADIUSBYMEMBER, getName(), member, radius, geoUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<V, Double> radiusWithDistance(V member, double radius, GeoUnit geoUnit) {
|
||||
return get(radiusWithDistanceAsync(member, radius, geoUnit));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<Map<V, Double>> radiusWithDistanceAsync(V member, double radius, GeoUnit geoUnit) {
|
||||
RedisCommand command = new RedisCommand("GEORADIUSBYMEMBER", distanceDecoder, 2);
|
||||
return commandExecutor.readAsync(getName(), codec, command, getName(), member, radius, geoUnit, "WITHDIST");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<V, GeoPosition> radiusWithPosition(V member, double radius, GeoUnit geoUnit) {
|
||||
return get(radiusWithPositionAsync(member, radius, geoUnit));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<Map<V, GeoPosition>> radiusWithPositionAsync(V member, double radius, GeoUnit geoUnit) {
|
||||
RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("GEORADIUSBYMEMBER", postitionDecoder, 2);
|
||||
return commandExecutor.readAsync(getName(), codec, command, getName(), member, radius, geoUnit, "WITHCOORD");
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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;
|
||||
|
||||
public class RedissonShutdownException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -2694051226420789395L;
|
||||
|
||||
public RedissonShutdownException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.codec;
|
||||
|
||||
import org.redisson.client.protocol.Decoder;
|
||||
|
||||
public class DelegateDecoderCodec extends StringCodec {
|
||||
|
||||
private final Codec delegate;
|
||||
|
||||
public DelegateDecoderCodec(Codec delegate) {
|
||||
super();
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Decoder<Object> getValueDecoder() {
|
||||
return delegate.getValueDecoder();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.codec;
|
||||
|
||||
import org.redisson.client.protocol.Encoder;
|
||||
|
||||
public class GeoEntryCodec extends StringCodec {
|
||||
|
||||
private final ThreadLocal<Integer> pos = new ThreadLocal<Integer>() {
|
||||
protected Integer initialValue() {
|
||||
return 0;
|
||||
};
|
||||
};
|
||||
|
||||
private final Codec delegate;
|
||||
|
||||
public GeoEntryCodec(Codec delegate) {
|
||||
super();
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Encoder getValueEncoder() {
|
||||
Integer p = pos.get() + 1;
|
||||
pos.set(p);
|
||||
if (p % 3 == 0) {
|
||||
return delegate.getValueEncoder();
|
||||
}
|
||||
return super.getValueEncoder();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.handler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class StateLevel {
|
||||
|
||||
private long size;
|
||||
private List<Object> parts;
|
||||
|
||||
public StateLevel(long size, List<Object> parts) {
|
||||
super();
|
||||
this.size = size;
|
||||
this.parts = parts;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public List<Object> getParts() {
|
||||
return parts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StateLevel [size=" + size + ", parts=" + parts + "]";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.protocol;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.redisson.client.RedisRedirectException;
|
||||
import org.redisson.client.codec.Codec;
|
||||
|
||||
import io.netty.util.concurrent.Promise;
|
||||
|
||||
public class BatchCommandData<T, R> extends CommandData<T, R> {
|
||||
|
||||
private final AtomicReference<RedisRedirectException> redirectError = new AtomicReference<RedisRedirectException>();
|
||||
|
||||
public BatchCommandData(Promise<R> promise, Codec codec, RedisCommand<T> command, Object[] params) {
|
||||
super(promise, codec, command, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryFailure(Throwable cause) {
|
||||
if (redirectError.get() != null) {
|
||||
return false;
|
||||
}
|
||||
if (cause instanceof RedisRedirectException) {
|
||||
return redirectError.compareAndSet(null, (RedisRedirectException) cause);
|
||||
}
|
||||
|
||||
return super.tryFailure(cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuccess() {
|
||||
return redirectError.get() == null && super.isSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Throwable cause() {
|
||||
if (redirectError.get() != null) {
|
||||
return redirectError.get();
|
||||
}
|
||||
return super.cause();
|
||||
}
|
||||
|
||||
public void clearError() {
|
||||
redirectError.set(null);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.protocol.decoder;
|
||||
|
||||
public interface DecoderState {
|
||||
|
||||
DecoderState copy();
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.protocol.decoder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.redisson.client.handler.State;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class FlatNestedMultiDecoder<T> extends NestedMultiDecoder {
|
||||
|
||||
public FlatNestedMultiDecoder(MultiDecoder<Object> firstDecoder, MultiDecoder<Object> secondDecoder) {
|
||||
super(firstDecoder, secondDecoder);
|
||||
}
|
||||
|
||||
public FlatNestedMultiDecoder(MultiDecoder firstDecoder, MultiDecoder secondDecoder, boolean handleEmpty) {
|
||||
super(firstDecoder, secondDecoder, handleEmpty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuf buf, State state) throws IOException {
|
||||
return firstDecoder.decode(buf, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(int paramNum, State state) {
|
||||
NestedDecoderState ds = getDecoder(state);
|
||||
if (paramNum == 0) {
|
||||
ds.resetDecoderIndex();
|
||||
}
|
||||
return firstDecoder.isApplicable(paramNum, state);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.protocol.decoder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.redisson.client.codec.Codec;
|
||||
import org.redisson.client.codec.DoubleCodec;
|
||||
import org.redisson.client.handler.State;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
public class GeoDistanceDecoder implements MultiDecoder<List<Object>> {
|
||||
|
||||
private final ThreadLocal<Integer> pos = new ThreadLocal<Integer>();
|
||||
|
||||
private final Codec codec;
|
||||
|
||||
public GeoDistanceDecoder(Codec codec) {
|
||||
super();
|
||||
this.codec = codec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuf buf, State state) throws IOException {
|
||||
if (pos.get() % 2 == 0) {
|
||||
return codec.getValueDecoder().decode(buf, state);
|
||||
}
|
||||
return DoubleCodec.INSTANCE.getValueDecoder().decode(buf, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(int paramNum, State state) {
|
||||
pos.set(paramNum);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> decode(List<Object> parts, State state) {
|
||||
return parts;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.protocol.decoder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.redisson.client.codec.Codec;
|
||||
import org.redisson.client.codec.DoubleCodec;
|
||||
import org.redisson.client.handler.State;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class GeoDistanceMapDecoder implements MultiDecoder<Map<Object, Object>> {
|
||||
|
||||
private final ThreadLocal<Integer> pos = new ThreadLocal<Integer>();
|
||||
|
||||
private final Codec codec;
|
||||
|
||||
public GeoDistanceMapDecoder(Codec codec) {
|
||||
super();
|
||||
this.codec = codec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuf buf, State state) throws IOException {
|
||||
if (pos.get() % 2 == 0) {
|
||||
return codec.getValueDecoder().decode(buf, state);
|
||||
}
|
||||
return DoubleCodec.INSTANCE.getValueDecoder().decode(buf, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(int paramNum, State state) {
|
||||
pos.set(paramNum);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Object, Object> decode(List<Object> parts, State state) {
|
||||
Map<Object, Object> result = new HashMap<Object, Object>(parts.size()/2);
|
||||
for (int i = 0; i < parts.size(); i++) {
|
||||
if (i % 2 != 0) {
|
||||
result.put(parts.get(i-1), parts.get(i));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.protocol.decoder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.redisson.client.handler.State;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class GeoMapReplayDecoder implements MultiDecoder<Map<Object, Object>> {
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuf buf, State state) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Object, Object> decode(List<Object> parts, State state) {
|
||||
Map<Object, Object> result = new HashMap<Object, Object>(parts.size());
|
||||
for (Object object : parts) {
|
||||
List<Object> vals = ((List<Object>) object);
|
||||
result.put(vals.get(0), vals.get(1));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(int paramNum, State state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.protocol.decoder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.redisson.client.codec.DoubleCodec;
|
||||
import org.redisson.client.handler.State;
|
||||
import org.redisson.core.GeoPosition;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class GeoPositionDecoder implements MultiDecoder<GeoPosition> {
|
||||
|
||||
@Override
|
||||
public Double decode(ByteBuf buf, State state) throws IOException {
|
||||
return (Double) DoubleCodec.INSTANCE.getValueDecoder().decode(buf, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(int paramNum, State state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeoPosition decode(List<Object> parts, State state) {
|
||||
if (parts.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Double longitude = Double.valueOf(parts.get(0).toString());
|
||||
Double latitude = Double.valueOf(parts.get(1).toString());
|
||||
return new GeoPosition(longitude, latitude);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.protocol.decoder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.redisson.client.handler.State;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class GeoPositionMapDecoder implements MultiDecoder<Map<Object, Object>> {
|
||||
|
||||
private final List<Object> args;
|
||||
|
||||
public GeoPositionMapDecoder(List<Object> args) {
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double decode(ByteBuf buf, State state) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(int paramNum, State state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Object, Object> decode(List<Object> parts, State state) {
|
||||
if (parts.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<Object, Object> result = new HashMap<Object, Object>(parts.size());
|
||||
for (int index = 0; index < args.size()-1; index++) {
|
||||
Object value = parts.get(index);
|
||||
if (value == null || value == Collections.emptyMap()) {
|
||||
continue;
|
||||
}
|
||||
result.put(args.get(index+1), value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.protocol.decoder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.redisson.client.handler.State;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ListMultiDecoder<T> implements MultiDecoder<Object> {
|
||||
|
||||
private final MultiDecoder<?>[] decoders;
|
||||
|
||||
public static class NestedDecoderState implements DecoderState {
|
||||
|
||||
int index = -1;
|
||||
int partsIndex = -1;
|
||||
|
||||
public NestedDecoderState() {
|
||||
}
|
||||
|
||||
public NestedDecoderState(int index) {
|
||||
super();
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public void resetPartsIndex() {
|
||||
partsIndex = -1;
|
||||
}
|
||||
|
||||
public int incPartsIndex() {
|
||||
return ++partsIndex;
|
||||
}
|
||||
|
||||
public int getPartsIndex() {
|
||||
return partsIndex;
|
||||
}
|
||||
|
||||
public int incIndex() {
|
||||
return ++index;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DecoderState copy() {
|
||||
return new NestedDecoderState(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NestedDecoderState [index=" + index + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected final NestedDecoderState getDecoder(State state) {
|
||||
NestedDecoderState ds = state.getDecoderState();
|
||||
if (ds == null) {
|
||||
ds = new NestedDecoderState();
|
||||
state.setDecoderState(ds);
|
||||
}
|
||||
return ds;
|
||||
}
|
||||
|
||||
public ListMultiDecoder(MultiDecoder<?> ... decoders) {
|
||||
this.decoders = decoders;
|
||||
}
|
||||
|
||||
public Object decode(ByteBuf buf, State state) throws IOException {
|
||||
int index = getDecoder(state).getIndex();
|
||||
return decoders[index].decode(buf, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(int paramNum, State state) {
|
||||
if (paramNum == 0) {
|
||||
NestedDecoderState s = getDecoder(state);
|
||||
s.incIndex();
|
||||
s.resetPartsIndex();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object decode(List<Object> parts, State state) {
|
||||
NestedDecoderState s = getDecoder(state);
|
||||
int index = s.getIndex();
|
||||
index += s.incPartsIndex();
|
||||
Object res = decoders[index].decode(parts, state);
|
||||
if (res == null) {
|
||||
index = s.incIndex() + s.getPartsIndex();
|
||||
return decoders[index].decode(parts, state);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.protocol.decoder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.redisson.client.codec.LongCodec;
|
||||
import org.redisson.client.handler.State;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class LongMultiDecoder implements MultiDecoder<Object> {
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuf buf, State state) throws IOException {
|
||||
return LongCodec.INSTANCE.getValueDecoder().decode(buf, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(int paramNum, State state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object decode(List<Object> parts, State state) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.protocol.decoder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MapCacheScanResult<K, V> extends MapScanResult<K, V> {
|
||||
|
||||
private final List<K> idleKeys;
|
||||
|
||||
public MapCacheScanResult(Long pos, Map<K, V> values, List<K> idleKeys) {
|
||||
super(pos, values);
|
||||
this.idleKeys = idleKeys;
|
||||
};
|
||||
|
||||
public List<K> getIdleKeys() {
|
||||
return idleKeys;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.protocol.decoder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.redisson.client.handler.State;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class MapCacheScanResultReplayDecoder implements MultiDecoder<MapCacheScanResult<Object, Object>> {
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuf buf, State state) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapCacheScanResult<Object, Object> decode(List<Object> parts, State state) {
|
||||
Long pos = (Long)parts.get(0);
|
||||
Map<Object, Object> values = (Map<Object, Object>)parts.get(1);
|
||||
List<Object> idleKeys = (List<Object>) parts.get(2);
|
||||
return new MapCacheScanResult<Object, Object>(pos, values, idleKeys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(int paramNum, State state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.protocol.decoder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.redisson.client.handler.State;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class NestedMultiDecoder2<T> implements MultiDecoder<Object> {
|
||||
|
||||
private final MultiDecoder<Object> firstDecoder;
|
||||
private final MultiDecoder<Object> secondDecoder;
|
||||
|
||||
public NestedMultiDecoder2(MultiDecoder<Object> firstDecoder, MultiDecoder<Object> secondDecoder) {
|
||||
this.firstDecoder = firstDecoder;
|
||||
this.secondDecoder = secondDecoder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuf buf, State state) throws IOException {
|
||||
return firstDecoder.decode(buf, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(int paramNum, State state) {
|
||||
if (paramNum == 0) {
|
||||
setCounter(state, 0);
|
||||
}
|
||||
return firstDecoder.isApplicable(paramNum, state);
|
||||
}
|
||||
|
||||
private Integer getCounter(State state) {
|
||||
Integer value = state.getDecoderState();
|
||||
if (value == null) {
|
||||
return 0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private void setCounter(State state, Integer value) {
|
||||
state.setDecoderState(value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object decode(List<Object> parts, State state) {
|
||||
// handle empty result
|
||||
if (parts.isEmpty() && state.getDecoderState() == null) {
|
||||
return secondDecoder.decode(parts, state);
|
||||
}
|
||||
|
||||
int counter = getCounter(state);
|
||||
if (counter == 2) {
|
||||
counter = 0;
|
||||
}
|
||||
counter++;
|
||||
setCounter(state, counter);
|
||||
MultiDecoder<?> decoder = null;
|
||||
if (counter == 1) {
|
||||
decoder = firstDecoder;
|
||||
}
|
||||
if (counter == 2) {
|
||||
decoder = secondDecoder;
|
||||
}
|
||||
return decoder.decode(parts, state);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.protocol.decoder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.redisson.client.codec.Codec;
|
||||
import org.redisson.client.handler.State;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ObjectListDecoder<T> implements MultiDecoder<List<T>> {
|
||||
|
||||
private Codec codec;
|
||||
|
||||
public ObjectListDecoder(Codec codec) {
|
||||
super();
|
||||
this.codec = codec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuf buf, State state) throws IOException {
|
||||
return codec.getMapKeyDecoder().decode(buf, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> decode(List<Object> parts, State state) {
|
||||
return (List<T>) parts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(int paramNum, State state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.client.protocol.decoder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.redisson.client.codec.Codec;
|
||||
import org.redisson.client.handler.State;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ObjectMapDecoder implements MultiDecoder<Map<Object, Object>> {
|
||||
|
||||
private Codec codec;
|
||||
|
||||
public ObjectMapDecoder(Codec codec) {
|
||||
super();
|
||||
this.codec = codec;
|
||||
}
|
||||
|
||||
private int pos;
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuf buf, State state) throws IOException {
|
||||
if (pos++ % 2 == 0) {
|
||||
return codec.getMapKeyDecoder().decode(buf, state);
|
||||
}
|
||||
return codec.getMapValueDecoder().decode(buf, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Object, Object> decode(List<Object> parts, State state) {
|
||||
Map<Object, Object> result = new HashMap<Object, Object>(parts.size()/2);
|
||||
for (int i = 0; i < parts.size(); i++) {
|
||||
if (i % 2 != 0) {
|
||||
result.put(parts.get(i-1), parts.get(i));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(int paramNum, State state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.connection;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.netty.util.concurrent.CompleteFuture;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
|
||||
/**
|
||||
* Invokes Future listeners in the same thread unlike {@code SucceededFuture} does.
|
||||
*
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
* @param <V>
|
||||
*/
|
||||
public abstract class FastCompleteFuture<V> extends CompleteFuture<V> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(FastCompleteFuture.class);
|
||||
|
||||
protected FastCompleteFuture() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<V> addListener(GenericFutureListener<? extends Future<? super V>> listener) {
|
||||
if (listener == null) {
|
||||
throw new NullPointerException("listener");
|
||||
}
|
||||
|
||||
notify(listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void notify(GenericFutureListener<? extends Future<? super V>> listener) {
|
||||
try {
|
||||
((GenericFutureListener)listener).operationComplete(this);
|
||||
} catch (Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("An exception was thrown by " + listener.getClass().getName() + ".operationComplete()", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<V> addListeners(GenericFutureListener<? extends Future<? super V>>... listeners) {
|
||||
if (listeners == null) {
|
||||
throw new NullPointerException("listeners");
|
||||
}
|
||||
for (GenericFutureListener<? extends Future<? super V>> l: listeners) {
|
||||
if (l == null) {
|
||||
break;
|
||||
}
|
||||
notify(l);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.connection;
|
||||
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
* @param <V>
|
||||
*/
|
||||
public class FastFailedFuture<V> extends FastCompleteFuture<V> {
|
||||
|
||||
private final Throwable cause;
|
||||
|
||||
protected FastFailedFuture(Throwable cause) {
|
||||
if (cause == null) {
|
||||
throw new NullPointerException("cause");
|
||||
}
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Throwable cause() {
|
||||
return cause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuccess() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<V> sync() {
|
||||
PlatformDependent.throwException(cause);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<V> syncUninterruptibly() {
|
||||
PlatformDependent.throwException(cause);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getNow() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.core;
|
||||
|
||||
public class GeoEntry {
|
||||
|
||||
private final double longitude;
|
||||
private final double latitude;
|
||||
private final Object member;
|
||||
|
||||
public GeoEntry(double longitude, double latitude, Object member) {
|
||||
super();
|
||||
this.longitude = longitude;
|
||||
this.latitude = latitude;
|
||||
this.member = member;
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public Object getMember() {
|
||||
return member;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.core;
|
||||
|
||||
public class GeoPosition {
|
||||
|
||||
private final double longitude;
|
||||
private final double latitude;
|
||||
|
||||
public GeoPosition(double longitude, double latitude) {
|
||||
super();
|
||||
this.longitude = longitude;
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(latitude);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(longitude);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
GeoPosition other = (GeoPosition) obj;
|
||||
if (Double.doubleToLongBits(latitude) != Double.doubleToLongBits(other.latitude))
|
||||
return false;
|
||||
if (Double.doubleToLongBits(longitude) != Double.doubleToLongBits(other.longitude))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GeoPosition [longitude=" + longitude + ", latitude=" + latitude + "]";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.core;
|
||||
|
||||
public enum GeoUnit {
|
||||
|
||||
METERS {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "m";
|
||||
}
|
||||
},
|
||||
|
||||
KILOMETERS {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "km";
|
||||
}
|
||||
},
|
||||
|
||||
MILES {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "mi";
|
||||
}
|
||||
},
|
||||
|
||||
FEET {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ft";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.core;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface RBuckets {
|
||||
|
||||
/**
|
||||
* <p>Returns a list of object holder instances by a key pattern.
|
||||
*
|
||||
* <pre>Supported glob-style patterns:
|
||||
* h?llo subscribes to hello, hallo and hxllo
|
||||
* h*llo subscribes to hllo and heeeello
|
||||
* h[ae]llo subscribes to hello and hallo, but not hillo
|
||||
* h[^e]llo matches hallo, hbllo, ... but not hello
|
||||
* h[a-b]llo matches hallo and hbllo</pre>
|
||||
* <p>Use \ to escape special characters if you want to match them verbatim.
|
||||
*
|
||||
* @param pattern
|
||||
* @return
|
||||
*/
|
||||
<V> List<RBucket<V>> find(String pattern);
|
||||
|
||||
/**
|
||||
* Returns Redis object mapped by key. Result Map is not contains
|
||||
* key-value entry for null values.
|
||||
*
|
||||
* @param keys
|
||||
* @return
|
||||
*/
|
||||
<V> Map<String, V> get(String ... keys);
|
||||
|
||||
/**
|
||||
* Try to save objects mapped by Redis key.
|
||||
* If at least one of them is already exist then
|
||||
* don't set none of them.
|
||||
*
|
||||
* @param buckets
|
||||
*/
|
||||
boolean trySet(Map<String, ?> buckets);
|
||||
|
||||
/**
|
||||
* Saves objects mapped by Redis key.
|
||||
*
|
||||
* @param buckets
|
||||
*/
|
||||
void set(Map<String, ?> buckets);
|
||||
|
||||
}
|
@ -0,0 +1,166 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.core;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Geospatial items holder
|
||||
*
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
* @param <V>
|
||||
*/
|
||||
public interface RGeo<V> extends RExpirable, RGeoAsync<V> {
|
||||
|
||||
/**
|
||||
* Adds geospatial member.
|
||||
*
|
||||
* @param entries
|
||||
* @return number of elements added to the sorted set,
|
||||
* not including elements already existing for which
|
||||
* the score was updated
|
||||
*/
|
||||
long add(double longitude, double latitude, V member);
|
||||
|
||||
/**
|
||||
* Adds geospatial members.
|
||||
*
|
||||
* @param entries
|
||||
* @return number of elements added to the sorted set,
|
||||
* not including elements already existing for which
|
||||
* the score was updated
|
||||
*/
|
||||
long add(GeoEntry... entries);
|
||||
|
||||
/**
|
||||
* Returns distance between members in <code>GeoUnit</code> units.
|
||||
*
|
||||
* @see {@link GeoUnit}
|
||||
*
|
||||
* @param firstMember
|
||||
* @param secondMember
|
||||
* @param geoUnit
|
||||
* @return
|
||||
*/
|
||||
Double dist(V firstMember, V secondMember, GeoUnit geoUnit);
|
||||
|
||||
/**
|
||||
* Returns 11 characters Geohash string mapped by defined member.
|
||||
*
|
||||
* @param members
|
||||
* @return
|
||||
*/
|
||||
Map<V, String> hash(V... members);
|
||||
|
||||
/**
|
||||
* Returns geo-position mapped by defined member.
|
||||
*
|
||||
* @param members
|
||||
* @return
|
||||
*/
|
||||
Map<V, GeoPosition> pos(V... members);
|
||||
|
||||
/**
|
||||
* Returns the members of a sorted set, which are within the
|
||||
* borders of the area specified with the center location
|
||||
* and the maximum distance from the center (the radius)
|
||||
* in <code>GeoUnit</code> units.
|
||||
*
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param radius
|
||||
* @param geoUnit
|
||||
* @return
|
||||
*/
|
||||
List<V> radius(double longitude, double latitude, double radius, GeoUnit geoUnit);
|
||||
|
||||
/**
|
||||
* Returns the distance mapped by member, distance between member and the location.
|
||||
* Members of a sorted set, which are within the
|
||||
* borders of the area specified with the center location
|
||||
* and the maximum distance from the center (the radius)
|
||||
* in <code>GeoUnit</code> units.
|
||||
*
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param radius
|
||||
* @param geoUnit
|
||||
* @return
|
||||
*/
|
||||
Map<V, Double> radiusWithDistance(double longitude, double latitude, double radius, GeoUnit geoUnit);
|
||||
|
||||
/**
|
||||
* Returns the geo-position mapped by member.
|
||||
* Members of a sorted set, which are within the
|
||||
* borders of the area specified with the center location
|
||||
* and the maximum distance from the center (the radius)
|
||||
* in <code>GeoUnit</code> units.
|
||||
*
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param radius
|
||||
* @param geoUnit
|
||||
* @return
|
||||
*/
|
||||
Map<V, GeoPosition> radiusWithPosition(double longitude, double latitude, double radius, GeoUnit geoUnit);
|
||||
|
||||
/**
|
||||
* Returns the members of a sorted set, which are within the
|
||||
* borders of the area specified with the defined member location
|
||||
* and the maximum distance from the defined member location (the radius)
|
||||
* in <code>GeoUnit</code> units.
|
||||
*
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param radius
|
||||
* @param geoUnit
|
||||
* @return
|
||||
*/
|
||||
List<V> radius(V member, double radius, GeoUnit geoUnit);
|
||||
|
||||
/**
|
||||
* Returns the distance mapped by member, distance between member and the defined member location.
|
||||
* Members of a sorted set, which are within the
|
||||
* borders of the area specified with the defined member location
|
||||
* and the maximum distance from the defined member location (the radius)
|
||||
* in <code>GeoUnit</code> units.
|
||||
*
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param radius
|
||||
* @param geoUnit
|
||||
* @return
|
||||
*/
|
||||
Map<V, Double> radiusWithDistance(V member, double radius, GeoUnit geoUnit);
|
||||
|
||||
/**
|
||||
* Returns the geo-position mapped by member.
|
||||
* Members of a sorted set, which are within the
|
||||
* borders of the area specified with the defined member location
|
||||
* and the maximum distance from the defined member location (the radius)
|
||||
* in <code>GeoUnit</code> units.
|
||||
*
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param radius
|
||||
* @param geoUnit
|
||||
* @return
|
||||
*/
|
||||
Map<V, GeoPosition> radiusWithPosition(V member, double radius, GeoUnit geoUnit);
|
||||
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* 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.core;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.netty.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
* @param <V>
|
||||
*/
|
||||
public interface RGeoAsync<V> extends RExpirableAsync {
|
||||
|
||||
/**
|
||||
* Adds geospatial member.
|
||||
*
|
||||
* @param entries
|
||||
* @return number of elements added to the sorted set,
|
||||
* not including elements already existing for which
|
||||
* the score was updated
|
||||
*/
|
||||
Future<Long> addAsync(double longitude, double latitude, V member);
|
||||
|
||||
/**
|
||||
* Adds geospatial members.
|
||||
*
|
||||
* @param entries
|
||||
* @return number of elements added to the sorted set,
|
||||
* not including elements already existing for which
|
||||
* the score was updated
|
||||
*/
|
||||
Future<Long> addAsync(GeoEntry... entries);
|
||||
|
||||
/**
|
||||
* Returns distance between members in <code>GeoUnit</code> units.
|
||||
*
|
||||
* @see {@link GeoUnit}
|
||||
*
|
||||
* @param firstMember
|
||||
* @param secondMember
|
||||
* @param geoUnit
|
||||
* @return
|
||||
*/
|
||||
Future<Double> distAsync(V firstMember, V secondMember, GeoUnit geoUnit);
|
||||
|
||||
/**
|
||||
* Returns 11 characters Geohash string mapped by defined member.
|
||||
*
|
||||
* @param members
|
||||
* @return
|
||||
*/
|
||||
Future<Map<V, String>> hashAsync(V... members);
|
||||
|
||||
/**
|
||||
* Returns geo-position mapped by defined member.
|
||||
*
|
||||
* @param members
|
||||
* @return
|
||||
*/
|
||||
Future<Map<V, GeoPosition>> posAsync(V... members);
|
||||
|
||||
/**
|
||||
* Returns the members of a sorted set, which are within the
|
||||
* borders of the area specified with the center location
|
||||
* and the maximum distance from the center (the radius)
|
||||
* in <code>GeoUnit</code> units.
|
||||
*
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param radius
|
||||
* @param geoUnit
|
||||
* @return
|
||||
*/
|
||||
Future<List<V>> radiusAsync(double longitude, double latitude, double radius, GeoUnit geoUnit);
|
||||
|
||||
/**
|
||||
* Returns the distance mapped by member, distance between member and the location.
|
||||
* Members of a sorted set, which are within the
|
||||
* borders of the area specified with the center location
|
||||
* and the maximum distance from the center (the radius)
|
||||
* in <code>GeoUnit</code> units.
|
||||
*
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param radius
|
||||
* @param geoUnit
|
||||
* @return
|
||||
*/
|
||||
Future<Map<V, Double>> radiusWithDistanceAsync(double longitude, double latitude, double radius, GeoUnit geoUnit);
|
||||
|
||||
/**
|
||||
* Returns the geo-position mapped by member.
|
||||
* Members of a sorted set, which are within the
|
||||
* borders of the area specified with the center location
|
||||
* and the maximum distance from the center (the radius)
|
||||
* in <code>GeoUnit</code> units.
|
||||
*
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param radius
|
||||
* @param geoUnit
|
||||
* @return
|
||||
*/
|
||||
Future<Map<V, GeoPosition>> radiusWithPositionAsync(double longitude, double latitude, double radius, GeoUnit geoUnit);
|
||||
|
||||
/**
|
||||
* Returns the members of a sorted set, which are within the
|
||||
* borders of the area specified with the defined member location
|
||||
* and the maximum distance from the defined member location (the radius)
|
||||
* in <code>GeoUnit</code> units.
|
||||
*
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param radius
|
||||
* @param geoUnit
|
||||
* @return
|
||||
*/
|
||||
Future<List<V>> radiusAsync(V member, double radius, GeoUnit geoUnit);
|
||||
|
||||
/**
|
||||
* Returns the distance mapped by member, distance between member and the defined member location.
|
||||
* Members of a sorted set, which are within the
|
||||
* borders of the area specified with the defined member location
|
||||
* and the maximum distance from the defined member location (the radius)
|
||||
* in <code>GeoUnit</code> units.
|
||||
*
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param radius
|
||||
* @param geoUnit
|
||||
* @return
|
||||
*/
|
||||
Future<Map<V, Double>> radiusWithDistanceAsync(V member, double radius, GeoUnit geoUnit);
|
||||
|
||||
/**
|
||||
* Returns the geo-position mapped by member.
|
||||
* Members of a sorted set, which are within the
|
||||
* borders of the area specified with the defined member location
|
||||
* and the maximum distance from the defined member location (the radius)
|
||||
* in <code>GeoUnit</code> units.
|
||||
*
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param radius
|
||||
* @param geoUnit
|
||||
* @return
|
||||
*/
|
||||
Future<Map<V, GeoPosition>> radiusWithPositionAsync(V member, double radius, GeoUnit geoUnit);
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue