richie
7 years ago
3 changed files with 217 additions and 217 deletions
@ -1,90 +1,90 @@ |
|||||||
///**
|
/** |
||||||
// * Copyright 2012 Nikita Koksharov
|
* Copyright 2012 Nikita Koksharov |
||||||
// *
|
* |
||||||
// * Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
// * you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License. |
||||||
// * You may obtain a copy of the License at
|
* You may obtain a copy of the License at |
||||||
// *
|
* |
||||||
// * http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
// *
|
* |
||||||
// * Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software |
||||||
// * distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
// * See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and |
||||||
// * limitations under the License.
|
* limitations under the License. |
||||||
// */
|
*/ |
||||||
//package com.fr.third.socketio.store;
|
package com.fr.third.socketio.store; |
||||||
//
|
|
||||||
//import java.util.Queue;
|
import java.util.Queue; |
||||||
//import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue; |
||||||
//import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap; |
||||||
//
|
|
||||||
//import com.fr.third.socketio.store.pubsub.PubSubListener;
|
import com.fr.third.socketio.store.pubsub.PubSubListener; |
||||||
//import com.fr.third.socketio.store.pubsub.PubSubMessage;
|
import com.fr.third.socketio.store.pubsub.PubSubMessage; |
||||||
//import com.fr.third.socketio.store.pubsub.PubSubStore;
|
import com.fr.third.socketio.store.pubsub.PubSubStore; |
||||||
//import com.fr.third.socketio.store.pubsub.PubSubType;
|
import com.fr.third.socketio.store.pubsub.PubSubType; |
||||||
//import org.redisson.api.RTopic;
|
import com.fr.third.redisson.api.RTopic; |
||||||
//import org.redisson.api.RedissonClient;
|
import com.fr.third.redisson.api.RedissonClient; |
||||||
//import org.redisson.api.listener.MessageListener;
|
import com.fr.third.redisson.api.listener.MessageListener; |
||||||
//
|
|
||||||
//import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent; |
||||||
//
|
|
||||||
//public class RedissonPubSubStore implements PubSubStore {
|
public class RedissonPubSubStore implements PubSubStore { |
||||||
//
|
|
||||||
// private final RedissonClient redissonPub;
|
private final RedissonClient redissonPub; |
||||||
// private final RedissonClient redissonSub;
|
private final RedissonClient redissonSub; |
||||||
// private final Long nodeId;
|
private final Long nodeId; |
||||||
//
|
|
||||||
// private final ConcurrentMap<String, Queue<Integer>> map = PlatformDependent.newConcurrentHashMap();
|
private final ConcurrentMap<String, Queue<Integer>> map = PlatformDependent.newConcurrentHashMap(); |
||||||
//
|
|
||||||
// public RedissonPubSubStore(RedissonClient redissonPub, RedissonClient redissonSub, Long nodeId) {
|
public RedissonPubSubStore(RedissonClient redissonPub, RedissonClient redissonSub, Long nodeId) { |
||||||
// this.redissonPub = redissonPub;
|
this.redissonPub = redissonPub; |
||||||
// this.redissonSub = redissonSub;
|
this.redissonSub = redissonSub; |
||||||
// this.nodeId = nodeId;
|
this.nodeId = nodeId; |
||||||
// }
|
} |
||||||
//
|
|
||||||
// @Override
|
@Override |
||||||
// public void publish(PubSubType type, PubSubMessage msg) {
|
public void publish(PubSubType type, PubSubMessage msg) { |
||||||
// msg.setNodeId(nodeId);
|
msg.setNodeId(nodeId); |
||||||
// redissonPub.getTopic(type.toString()).publish(msg);
|
redissonPub.getTopic(type.toString()).publish(msg); |
||||||
// }
|
} |
||||||
//
|
|
||||||
// @Override
|
@Override |
||||||
// public <T extends PubSubMessage> void subscribe(PubSubType type, final PubSubListener<T> listener, Class<T> clazz) {
|
public <T extends PubSubMessage> void subscribe(PubSubType type, final PubSubListener<T> listener, Class<T> clazz) { |
||||||
// String name = type.toString();
|
String name = type.toString(); |
||||||
// RTopic<T> topic = redissonSub.getTopic(name);
|
RTopic<T> topic = redissonSub.getTopic(name); |
||||||
// int regId = topic.addListener(new MessageListener<T>() {
|
int regId = topic.addListener(new MessageListener<T>() { |
||||||
// @Override
|
@Override |
||||||
// public void onMessage(String channel, T msg) {
|
public void onMessage(String channel, T msg) { |
||||||
// if (!nodeId.equals(msg.getNodeId())) {
|
if (!nodeId.equals(msg.getNodeId())) { |
||||||
// listener.onMessage(msg);
|
listener.onMessage(msg); |
||||||
// }
|
} |
||||||
// }
|
} |
||||||
// });
|
}); |
||||||
//
|
|
||||||
// Queue<Integer> list = map.get(name);
|
Queue<Integer> list = map.get(name); |
||||||
// if (list == null) {
|
if (list == null) { |
||||||
// list = new ConcurrentLinkedQueue<Integer>();
|
list = new ConcurrentLinkedQueue<Integer>(); |
||||||
// Queue<Integer> oldList = map.putIfAbsent(name, list);
|
Queue<Integer> oldList = map.putIfAbsent(name, list); |
||||||
// if (oldList != null) {
|
if (oldList != null) { |
||||||
// list = oldList;
|
list = oldList; |
||||||
// }
|
} |
||||||
// }
|
} |
||||||
// list.add(regId);
|
list.add(regId); |
||||||
// }
|
} |
||||||
//
|
|
||||||
// @Override
|
@Override |
||||||
// public void unsubscribe(PubSubType type) {
|
public void unsubscribe(PubSubType type) { |
||||||
// String name = type.toString();
|
String name = type.toString(); |
||||||
// Queue<Integer> regIds = map.remove(name);
|
Queue<Integer> regIds = map.remove(name); |
||||||
// RTopic<Object> topic = redissonSub.getTopic(name);
|
RTopic<Object> topic = redissonSub.getTopic(name); |
||||||
// for (Integer id : regIds) {
|
for (Integer id : regIds) { |
||||||
// topic.removeListener(id);
|
topic.removeListener(id); |
||||||
// }
|
} |
||||||
// }
|
} |
||||||
//
|
|
||||||
// @Override
|
@Override |
||||||
// public void shutdown() {
|
public void shutdown() { |
||||||
// }
|
} |
||||||
//
|
|
||||||
//}
|
} |
||||||
|
@ -1,51 +1,51 @@ |
|||||||
///**
|
/** |
||||||
// * Copyright 2012 Nikita Koksharov
|
* Copyright 2012 Nikita Koksharov |
||||||
// *
|
* |
||||||
// * Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
// * you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License. |
||||||
// * You may obtain a copy of the License at
|
* You may obtain a copy of the License at |
||||||
// *
|
* |
||||||
// * http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
// *
|
* |
||||||
// * Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software |
||||||
// * distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
// * See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and |
||||||
// * limitations under the License.
|
* limitations under the License. |
||||||
// */
|
*/ |
||||||
//package com.fr.third.socketio.store;
|
package com.fr.third.socketio.store; |
||||||
//
|
|
||||||
//import java.util.Map;
|
import java.util.Map; |
||||||
//import java.util.UUID;
|
import java.util.UUID; |
||||||
//
|
|
||||||
//import org.redisson.api.RedissonClient;
|
import com.fr.third.redisson.api.RedissonClient; |
||||||
//
|
|
||||||
//public class RedissonStore implements Store {
|
public class RedissonStore implements Store { |
||||||
//
|
|
||||||
// private final Map<String, Object> map;
|
private final Map<String, Object> map; |
||||||
//
|
|
||||||
// public RedissonStore(UUID sessionId, RedissonClient redisson) {
|
public RedissonStore(UUID sessionId, RedissonClient redisson) { |
||||||
// this.map = redisson.getMap(sessionId.toString());
|
this.map = redisson.getMap(sessionId.toString()); |
||||||
// }
|
} |
||||||
//
|
|
||||||
// @Override
|
@Override |
||||||
// public void set(String key, Object value) {
|
public void set(String key, Object value) { |
||||||
// map.put(key, value);
|
map.put(key, value); |
||||||
// }
|
} |
||||||
//
|
|
||||||
// @Override
|
@Override |
||||||
// public <T> T get(String key) {
|
public <T> T get(String key) { |
||||||
// return (T) map.get(key);
|
return (T) map.get(key); |
||||||
// }
|
} |
||||||
//
|
|
||||||
// @Override
|
@Override |
||||||
// public boolean has(String key) {
|
public boolean has(String key) { |
||||||
// return map.containsKey(key);
|
return map.containsKey(key); |
||||||
// }
|
} |
||||||
//
|
|
||||||
// @Override
|
@Override |
||||||
// public void del(String key) {
|
public void del(String key) { |
||||||
// map.remove(key);
|
map.remove(key); |
||||||
// }
|
} |
||||||
//
|
|
||||||
//}
|
} |
||||||
|
@ -1,76 +1,76 @@ |
|||||||
///**
|
/** |
||||||
// * Copyright 2012 Nikita Koksharov
|
* Copyright 2012 Nikita Koksharov |
||||||
// *
|
* |
||||||
// * Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
// * you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License. |
||||||
// * You may obtain a copy of the License at
|
* You may obtain a copy of the License at |
||||||
// *
|
* |
||||||
// * http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
// *
|
* |
||||||
// * Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software |
||||||
// * distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
// * See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and |
||||||
// * limitations under the License.
|
* limitations under the License. |
||||||
// */
|
*/ |
||||||
//package com.fr.third.socketio.store;
|
package com.fr.third.socketio.store; |
||||||
//
|
|
||||||
//import java.util.Map;
|
import java.util.Map; |
||||||
//import java.util.UUID;
|
import java.util.UUID; |
||||||
//
|
|
||||||
//import com.fr.third.socketio.store.pubsub.BaseStoreFactory;
|
import com.fr.third.socketio.store.pubsub.BaseStoreFactory; |
||||||
//import com.fr.third.socketio.store.pubsub.PubSubStore;
|
import com.fr.third.socketio.store.pubsub.PubSubStore; |
||||||
//import org.redisson.Redisson;
|
import com.fr.third.redisson.Redisson; |
||||||
//import org.redisson.api.RedissonClient;
|
import com.fr.third.redisson.api.RedissonClient; |
||||||
//
|
|
||||||
//public class RedissonStoreFactory extends BaseStoreFactory {
|
public class RedissonStoreFactory extends BaseStoreFactory { |
||||||
//
|
|
||||||
// private final RedissonClient redisClient;
|
private final RedissonClient redisClient; |
||||||
// private final RedissonClient redisPub;
|
private final RedissonClient redisPub; |
||||||
// private final RedissonClient redisSub;
|
private final RedissonClient redisSub; |
||||||
//
|
|
||||||
// private final PubSubStore pubSubStore;
|
private final PubSubStore pubSubStore; |
||||||
//
|
|
||||||
// public RedissonStoreFactory() {
|
public RedissonStoreFactory() { |
||||||
// this(Redisson.create());
|
this(Redisson.create()); |
||||||
// }
|
} |
||||||
//
|
|
||||||
// public RedissonStoreFactory(RedissonClient redisson) {
|
public RedissonStoreFactory(RedissonClient redisson) { |
||||||
// this.redisClient = redisson;
|
this.redisClient = redisson; |
||||||
// this.redisPub = redisson;
|
this.redisPub = redisson; |
||||||
// this.redisSub = redisson;
|
this.redisSub = redisson; |
||||||
//
|
|
||||||
// this.pubSubStore = new RedissonPubSubStore(redisPub, redisSub, getNodeId());
|
this.pubSubStore = new RedissonPubSubStore(redisPub, redisSub, getNodeId()); |
||||||
// }
|
} |
||||||
//
|
|
||||||
// public RedissonStoreFactory(Redisson redisClient, Redisson redisPub, Redisson redisSub) {
|
public RedissonStoreFactory(Redisson redisClient, Redisson redisPub, Redisson redisSub) { |
||||||
// this.redisClient = redisClient;
|
this.redisClient = redisClient; |
||||||
// this.redisPub = redisPub;
|
this.redisPub = redisPub; |
||||||
// this.redisSub = redisSub;
|
this.redisSub = redisSub; |
||||||
//
|
|
||||||
// this.pubSubStore = new RedissonPubSubStore(redisPub, redisSub, getNodeId());
|
this.pubSubStore = new RedissonPubSubStore(redisPub, redisSub, getNodeId()); |
||||||
// }
|
} |
||||||
//
|
|
||||||
// @Override
|
@Override |
||||||
// public Store createStore(UUID sessionId) {
|
public Store createStore(UUID sessionId) { |
||||||
// return new RedissonStore(sessionId, redisClient);
|
return new RedissonStore(sessionId, redisClient); |
||||||
// }
|
} |
||||||
//
|
|
||||||
// @Override
|
@Override |
||||||
// public PubSubStore pubSubStore() {
|
public PubSubStore pubSubStore() { |
||||||
// return pubSubStore;
|
return pubSubStore; |
||||||
// }
|
} |
||||||
//
|
|
||||||
// @Override
|
@Override |
||||||
// public void shutdown() {
|
public void shutdown() { |
||||||
// redisClient.shutdown();
|
redisClient.shutdown(); |
||||||
// redisPub.shutdown();
|
redisPub.shutdown(); |
||||||
// redisSub.shutdown();
|
redisSub.shutdown(); |
||||||
// }
|
} |
||||||
//
|
|
||||||
// @Override
|
@Override |
||||||
// public <K, V> Map<K, V> createMap(String name) {
|
public <K, V> Map<K, V> createMap(String name) { |
||||||
// return redisClient.getMap(name);
|
return redisClient.getMap(name); |
||||||
// }
|
} |
||||||
//
|
|
||||||
//}
|
} |
||||||
|
Loading…
Reference in new issue