| | |
| | | byte[] rcvLengthBuf = new byte[8]; |
| | | |
| | | /** |
| | | * The time the last message published to this session. |
| | | */ |
| | | private long lastPublishTime = 0; |
| | | |
| | | |
| | | /** |
| | | * The time the last message was received on this session. |
| | | */ |
| | | private long lastReceiveTime = 0; |
| | | |
| | | |
| | | /** |
| | | * Creates a new SocketSession based on the provided socket. |
| | | * |
| | | * @param socket The Socket on which the SocketSession will be based. |
| | |
| | | output.write(sendLengthBuf); |
| | | output.write(buffer); |
| | | output.flush(); |
| | | |
| | | lastPublishTime = System.currentTimeMillis(); |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | int read = input.read(rcvLengthBuf, length, 8-length); |
| | | if (read == -1) |
| | | { |
| | | throw new IOException("no more data"); |
| | | } |
| | | else |
| | | { |
| | | length += read; |
| | | } |
| | | } |
| | | |
| | | int totalLength = Integer.parseInt(new String(rcvLengthBuf), 16); |
| | |
| | | length = 0; |
| | | byte[] buffer = new byte[totalLength]; |
| | | while (length < totalLength) |
| | | { |
| | | length += input.read(buffer, length, totalLength - length); |
| | | } |
| | | |
| | | lastReceiveTime = System.currentTimeMillis(); |
| | | return SynchronizationMessage.generateMsg(buffer); |
| | | } |
| | | catch (OutOfMemoryError e) |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public long getLastPublishTime() |
| | | { |
| | | return lastPublishTime; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public long getLastReceiveTime() |
| | | { |
| | | return lastReceiveTime; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public String getRemoteAddress() |
| | | { |
| | | return socket.getInetAddress().getHostAddress(); |