NutzCN Logo
问答 websocket 修改成redis存储房间报空指针
发布于 1644天前 作者 comzt 1509 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk
//ServerEndpoint是websocket的必备注解, value是映射路径, configurator是配置类.
@ServerEndpoint(value = "/websocket", configurator=NutWsConfigurator.class)
@IocBean // 使用NutWsConfigurator的必备条件
public class GameWebsocket extends AbstractWsEndpoint {
	private static final Log log = Logs.get();
	@Inject JedisAgent jedisAgent;
	    public WsHandler createHandler(Session session, EndpointConfig config) {
	        GameWsHandler gamehandler = new GameWsHandler("GameRoom:");
	        WsRoomProvider  roomProvider = new JedisRoomProvider(jedisAgent);
	        gamehandler.setRoomProvider(roomProvider);
	        return gamehandler;
	    }

不知道是什么问题

6 回复

具体哪一行的哪个变量为null

[INFO ] 09:09:06.322 [qtp824774188-43] com.game.web.commons.websocket.AbstractGameWsHandler - bad message ? msg={"room":"ALL","action":"join"}
java.lang.NullPointerException: null
	at org.nutz.plugins.mvc.websocket.room.JedisRoomProvider.join(JedisRoomProvider.java:31)
	at com.game.web.commons.websocket.AbstractGameWsHandler.join(AbstractGameWsHandler.java:57)
	at com.game.web.commons.websocket.GameWsHandler.join(GameWsHandler.java:26)
	at com.game.web.commons.websocket.GameWsHandler$FM$join$4366a781fe3826b955eb773c582eb6f3.invoke(GameWsHandler.java)
	at com.game.web.commons.websocket.AbstractGameWsHandler$1.invoke(AbstractGameWsHandler.java:90)
	at com.game.web.commons.websocket.AbstractGameWsHandler$1.invoke(AbstractGameWsHandler.java:1)
	at com.game.web.commons.websocket.AbstractGameWsHandler.onMessage(AbstractGameWsHandler.java:127)
	at org.nutz.plugins.mvc.websocket.AbstractWsEndpoint.onMesssageString(AbstractWsEndpoint.java:124)
	at org.nutz.plugins.mvc.websocket.AbstractWsEndpoint._onMesssageString(AbstractWsEndpoint.java:129)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
    public void join(String room, String wsid) {
        try (Jedis jedis = jedisAgent.getResource()) {
            jedis.sadd(room, wsid);
        }
    }

try (Jedis jedis = jedisAgent.getResource()) {这句

看看jedisAgent是不是null

jedisAgent不是null的,有这样一个错误

Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR This instance has cluster support disabled

jedisAgent里面还有这样一个错误
jedisPool --->creationStackTrace

java.lang.Exception
	at org.apache.commons.pool2.impl.BaseGenericObjectPool.<init>(BaseGenericObjectPool.java:139)
	at org.apache.commons.pool2.impl.GenericObjectPool.<init>(GenericObjectPool.java:107)
	at redis.clients.util.Pool.initPool(Pool.java:44)
	at redis.clients.util.Pool.<init>(Pool.java:23)
	at redis.clients.jedis.JedisPool.<init>(JedisPool.java:185)
	at redis.clients.jedis.JedisPool.<init>(JedisPool.java:162)
	at redis.clients.jedis.JedisPool.<init>(JedisPool.java:144)
	at redis.clients.jedis.JedisPool$FC$6150a72612b35941df4e131fae967884.invoke(JedisPool.java)
	at org.nutz.lang.born.AbstractConstructorBorning.call(AbstractConstructorBorning.java:25)
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:19)
	at org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:78)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:117)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	at org.nutz.integration.jedis.JedisAgent.getJedisPool(JedisAgent.java:60)
	at org.nutz.integration.jedis.JedisAgent.jedis(JedisAgent.java:49)
	at org.nutz.integration.jedis.JedisAgent.getResource(JedisAgent.java:54)
	at org.nutz.integration.jedis.RedisService.getJedis(RedisService.java:34)
	at org.nutz.integration.jedis.RedisService.setex(RedisService.java:759)
	at org.nutz.boot.starter.logback.exts.loglevel.LoglevelService.saveToRedis(LoglevelService.java:58)
	at org.nutz.boot.starter.logback.exts.loglevel.LoglevelService.init(LoglevelService.java:37)
	at org.nutz.boot.starter.logback.exts.loglevel.LoglevelService$FM$init$63be95218921869a8abcc66fe54a34dc.invoke(LoglevelService.java)
	at org.nutz.ioc.impl.ObjectMakerImpl$2.trigger(ObjectMakerImpl.java:181)
	at org.nutz.ioc.weaver.DefaultWeaver.onCreate(DefaultWeaver.java:89)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:141)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:161)
	at org.nutz.boot.starter.logback.exts.LogbackStarter.start(LogbackStarter.java:92)
	at org.nutz.boot.AppContext.startServers(AppContext.java:310)
	at org.nutz.boot.NbApp.execute(NbApp.java:210)
	at org.nutz.boot.NbApp.run(NbApp.java:182)
	at com.game.web.commons.core.WebApiMainLauncher.main(WebApiMainLauncher.java:32)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:282)
	at java.lang.Thread.run(Thread.java:748)

添加回复
请先登陆
回到顶部