0

I am using the built in implementation of SCTP found in java 1.7. I am using it to write a client server application. I am using the following code:

public void sendMessage(byte[] buffer, int length, boolean flush) throws Exception {
    logger.debug("Sending message length: {}, data: \n{}", length, debugData(buffer, 0, length, 256, true));
    ByteBuffer bb = ByteBuffer.wrap(buffer, 0, length);

    final MessageInfo messageInfo = MessageInfo.createOutgoing(null, 0);
    synchronized (sc){
        sc.send(bb, messageInfo);               
    }
    logger.debug("Finished sending message length: {}", length);
}

public int readMessage(byte[] readBuf) throws Exception {
    ByteBuffer buf = ByteBuffer.wrap(readBuf, 0, BinaryMessageBase.BUFFER_SIZE);
    MessageInfo messageInfo = null;
    do {
        try {
            messageInfo = sc.receive(buf, null, null);
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
            throw e;
        }
    } while (messageInfo == null || !messageInfo.isComplete());

    return messageInfo.bytes();
}

sc referenced in the code is a SctpChannel object. The readMessage method just grabs a message off the wire, and puts it in a buffer. Then sc.recieve populates MessageInfo until the complete message has been captured. Profiling this with jvisualvm shows that the readMessage method is the slowest by far. I can't really see anything to optimise as there is not much code as it is. Ideas would be greatly appreciated.

4

0 回答 0