读书人

Active MQ5.7版在NIO模式下SSL通信的有

发布时间: 2013-11-16 23:15:33 作者: rapoo

Active MQ5.7版在NIO模式下SSL通信的问题以及后续版本的解决
1 //得到数据包长度nextFrameSize = plain.getInt();2//为命令分配buffer,总长度为数据包长度 + 4,4是nextFrameSize自身的长度currentBuffer = ByteBuffer.allocate(nextFrameSize + 4); 3 //从socket buffer中读取数据到命令buffer currentBuffer.putInt(nextFrameSize); // 放入数据包长度// 如果从socket读取的数据小于当前命令buffer的可用长度,则将socket数据全部读取命令buffer中 if (currentBuffer.remaining() >= plain.remaining()) { currentBuffer.put(plain); }//如果从socket读取的数据大于当前命令buffer的可用长度,则只从socket读取当前命令buffer的可用长度,这样保证读取的数据只属于本命令的数据 else { byte[] fill = new byte[currentBuffer.remaining()]; plain.get(fill); currentBuffer.put(fill); }4 //处理从socket读取的命令 //如果命令buffer还没有写满,则返回,等待下个数据包 if (currentBuffer.hasRemaining()) { return; } else { //消费数据 nextFrameSize = -1;//当前命令已经读取完毕

?

protected void processCommand(ByteBuffer plain) throws Exception { if (nextFrameSize == -1) { if (plain.remaining() < Integer.SIZE) { if (currentBuffer == null) { currentBuffer = ByteBuffer.allocate(4); } while (currentBuffer.hasRemaining() && plain.hasRemaining()) { currentBuffer.put(plain.get()); } if (currentBuffer.hasRemaining()) { return; } else { currentBuffer.flip(); nextFrameSize = currentBuffer.getInt(); } } else { if (currentBuffer != null) { while (currentBuffer.hasRemaining()) { currentBuffer.put(plain.get()); } currentBuffer.flip(); nextFrameSize = currentBuffer.getInt(); } else { nextFrameSize = plain.getInt(); } } if (wireFormat instanceof OpenWireFormat) {long maxFrameSize = ((OpenWireFormat) wireFormat).getMaxFrameSize(); if (nextFrameSize > maxFrameSize) {throw new IOException("***); } } currentBuffer = ByteBuffer.allocate(nextFrameSize + 4); currentBuffer.putInt(nextFrameSize); } else { if (currentBuffer.remaining() >= plain.remaining()) { currentBuffer.put(plain); } else { byte[] fill = new byte[currentBuffer.remaining()] plain.get(fill); currentBuffer.put(fill); } if (currentBuffer.hasRemaining()) { return; } else { currentBuffer.flip(); Object command = wireFormat.unmarshal(new DataInputStream(new NIOInputStream(currentBuffer))); doConsume((Command) command); nextFrameSize = -1; currentBuffer = null; } } }

?

?

?

读书人网 >开源软件

热点推荐