WebSocket - fixing message (buffer) size settings and checks
This commit is contained in:
parent
833aa6723d
commit
89b33f5b88
|
@ -308,14 +308,15 @@ public class ClientContainer extends ContainerLifeCycle implements WebSocketCont
|
|||
@Override
|
||||
public void setAsyncSendTimeout(long ms)
|
||||
{
|
||||
client.setMaxIdleTimeout(ms);
|
||||
client.setAsyncWriteTimeout(ms);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultMaxBinaryMessageBufferSize(int max)
|
||||
{
|
||||
// overall message limit (used in non-streaming)
|
||||
client.getPolicy().setMaxBinaryMessageSize(max);
|
||||
// incoming streaming buffer size
|
||||
client.setMaxBinaryMessageBufferSize(max);
|
||||
}
|
||||
|
||||
|
@ -328,7 +329,9 @@ public class ClientContainer extends ContainerLifeCycle implements WebSocketCont
|
|||
@Override
|
||||
public void setDefaultMaxTextMessageBufferSize(int max)
|
||||
{
|
||||
// overall message limit (used in non-streaming)
|
||||
client.getPolicy().setMaxTextMessageSize(max);
|
||||
// incoming streaming buffer size
|
||||
client.setMaxTextMessageBufferSize(max);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,7 +148,7 @@ public class ServerContainer extends ClientContainer implements javax.websocket.
|
|||
@Override
|
||||
public int getDefaultMaxBinaryMessageBufferSize()
|
||||
{
|
||||
return webSocketServerFactory.getPolicy().getMaxBinaryMessageBufferSize();
|
||||
return webSocketServerFactory.getPolicy().getMaxBinaryMessageSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -160,7 +160,7 @@ public class ServerContainer extends ClientContainer implements javax.websocket.
|
|||
@Override
|
||||
public int getDefaultMaxTextMessageBufferSize()
|
||||
{
|
||||
return webSocketServerFactory.getPolicy().getMaxTextMessageBufferSize();
|
||||
return webSocketServerFactory.getPolicy().getMaxTextMessageSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -172,7 +172,9 @@ public class ServerContainer extends ClientContainer implements javax.websocket.
|
|||
@Override
|
||||
public void setDefaultMaxBinaryMessageBufferSize(int max)
|
||||
{
|
||||
// overall message limit (used in non-streaming)
|
||||
webSocketServerFactory.getPolicy().setMaxBinaryMessageSize(max);
|
||||
// incoming streaming buffer size
|
||||
webSocketServerFactory.getPolicy().setMaxBinaryMessageBufferSize(max);
|
||||
}
|
||||
|
||||
|
@ -185,7 +187,9 @@ public class ServerContainer extends ClientContainer implements javax.websocket.
|
|||
@Override
|
||||
public void setDefaultMaxTextMessageBufferSize(int max)
|
||||
{
|
||||
// overall message limit (used in non-streaming)
|
||||
webSocketServerFactory.getPolicy().setMaxTextMessageSize(max);
|
||||
// incoming streaming buffer size
|
||||
webSocketServerFactory.getPolicy().setMaxTextMessageBufferSize(max);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,9 +47,7 @@ public class WebSocketPolicy
|
|||
/**
|
||||
* The maximum size of a text message buffer.
|
||||
* <p>
|
||||
* Used primarily for stream based messaging.
|
||||
* <p>
|
||||
* Note: Cannot be greater than {@link #maxTextMessageSize}, or less than {@link #inputBufferSize}
|
||||
* Used ONLY for stream based message writing.
|
||||
* <p>
|
||||
* Default: 32768 (32 K)
|
||||
*/
|
||||
|
@ -67,9 +65,7 @@ public class WebSocketPolicy
|
|||
/**
|
||||
* The maximum size of a binary message buffer
|
||||
* <p>
|
||||
* Used primarily for stream based messaging.
|
||||
* <p>
|
||||
* Note: Cannot be greater than {@link #maxBinaryMessageSize}, or less than {@link #inputBufferSize}
|
||||
* Used ONLY for for stream based message writing
|
||||
* <p>
|
||||
* Default: 32768 (32 K)
|
||||
*/
|
||||
|
@ -106,14 +102,6 @@ public class WebSocketPolicy
|
|||
this.behavior = behavior;
|
||||
}
|
||||
|
||||
private void assertGreaterThan(String name, long size, String otherName, long otherSize)
|
||||
{
|
||||
if (size < otherSize)
|
||||
{
|
||||
throw new IllegalArgumentException(String.format("%s [%d] must be greater than %s [%d]",name,size,otherName,otherSize));
|
||||
}
|
||||
}
|
||||
|
||||
private void assertLessThan(String name, long size, String otherName, long otherSize)
|
||||
{
|
||||
if (size > otherSize)
|
||||
|
@ -207,7 +195,7 @@ public class WebSocketPolicy
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the maximum size of a binary message buffer
|
||||
* Get the maximum size of a binary message buffer (for streaming writing)
|
||||
* <p>
|
||||
* Note: Cannot be greater than {@link #getMaxBinaryMessageSize()}
|
||||
*
|
||||
|
@ -231,7 +219,7 @@ public class WebSocketPolicy
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the maximum size of a text message buffer.
|
||||
* Get the maximum size of a text message buffer (for streaming writing)
|
||||
* <p>
|
||||
* Note: Cannot be greater than {@link #maxTextMessageSize}
|
||||
*
|
||||
|
@ -298,9 +286,7 @@ public class WebSocketPolicy
|
|||
/**
|
||||
* The maximum size of a binary message buffer.
|
||||
* <p>
|
||||
* Used primarily for stream based messaging.
|
||||
* <p>
|
||||
* Note: Cannot be greater than {@link #getMaxBinaryMessageSize()} or less than {@link #getInputBufferSize()}
|
||||
* Used ONLY for stream based message writing.
|
||||
*
|
||||
* @param size
|
||||
* the maximum size of the binary message buffer
|
||||
|
@ -308,8 +294,6 @@ public class WebSocketPolicy
|
|||
public void setMaxBinaryMessageBufferSize(int size)
|
||||
{
|
||||
assertPositive("MaxBinaryMessageBufferSize",size);
|
||||
assertLessThan("MaxBinaryMessageBufferSize",size,"MaxBinaryMessageSize",maxBinaryMessageSize);
|
||||
assertGreaterThan("MaxBinaryMessageBufferSize",size,"InputBufferSize",inputBufferSize);
|
||||
|
||||
this.maxBinaryMessageBufferSize = size;
|
||||
}
|
||||
|
@ -325,7 +309,6 @@ public class WebSocketPolicy
|
|||
public void setMaxBinaryMessageSize(int size)
|
||||
{
|
||||
assertPositive("MaxBinaryMessageSize",size);
|
||||
assertGreaterThan("MaxBinaryMessageSize",size,"MaxBinaryMessageBufferSize",maxBinaryMessageBufferSize);
|
||||
|
||||
this.maxBinaryMessageSize = size;
|
||||
}
|
||||
|
@ -333,9 +316,7 @@ public class WebSocketPolicy
|
|||
/**
|
||||
* The maximum size of a text message buffer.
|
||||
* <p>
|
||||
* Used primarily for stream based messaging.
|
||||
* <p>
|
||||
* Note: Cannot be greater than {@link #getMaxTextMessageSize()} or less than {@link #getInputBufferSize()}
|
||||
* Used ONLY for stream based message writing.
|
||||
*
|
||||
* @param size
|
||||
* the maximum size of the text message buffer
|
||||
|
@ -343,8 +324,6 @@ public class WebSocketPolicy
|
|||
public void setMaxTextMessageBufferSize(int size)
|
||||
{
|
||||
assertPositive("MaxTextMessageBufferSize",size);
|
||||
assertLessThan("MaxTextMessageBufferSize",size,"MaxTextMessageSize",maxTextMessageSize);
|
||||
assertGreaterThan("MaxTextMessageBufferSize",size,"InputBufferSize",inputBufferSize);
|
||||
|
||||
this.maxTextMessageBufferSize = size;
|
||||
}
|
||||
|
@ -360,7 +339,6 @@ public class WebSocketPolicy
|
|||
public void setMaxTextMessageSize(int size)
|
||||
{
|
||||
assertPositive("MaxTextMessageSize",size);
|
||||
assertGreaterThan("MaxTextMessageSize",size,"MaxTextMessageBufferSize",maxTextMessageBufferSize);
|
||||
|
||||
this.maxTextMessageSize = size;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue