=== modified file 'src/com/goldencode/p2j/main/WebClientBuilder.java'
--- src/com/goldencode/p2j/main/WebClientBuilder.java 2016-02-05 10:17:52 +0000
+++ src/com/goldencode/p2j/main/WebClientBuilder.java 2016-02-20 18:09:00 +0000
@@ -15,6 +15,7 @@
** 004 GES 20150312 Added support for the GUI web client.
** 005 GES 20150710 Modified/added configuration processing for GUI, clipboard flag is ChUI-only.
** 006 CA 20160205 Changed to use ServerKeyStore.getStore().
+** SBI 20160220 Added maxBinaryMessage, maxTextMessage, maxIdleTime websocket's parameters.
*/
package com.goldencode.p2j.main;
@@ -96,10 +97,14 @@
command.add("client:chui:fontsize=" + options.get("fontsize"));
command.add("client:web:clipboard=" + options.get("clipboard"));
}
-
+ // Common Websocket parameters:
command.add("client:web:socketTimeout=" + options.get("webSocketTimeout"));
command.add("client:web:watchdogTimeout=" + options.get("watchdogTimeout"));
+ command.add("client:web:maxBinaryMessage=" + options.get("maxBinaryMessage"));
+ command.add("client:web:maxTextMessage=" + options.get("maxTextMessage"));
+ command.add("client:web:maxIdleTime=" + options.get("maxIdleTime"));
+
if (options.get("port") != null)
{
command.add("client:web:port=" + options.get("port"));
=== modified file 'src/com/goldencode/p2j/main/WebClientBuilderOptions.java'
--- src/com/goldencode/p2j/main/WebClientBuilderOptions.java 2015-08-07 20:47:38 +0000
+++ src/com/goldencode/p2j/main/WebClientBuilderOptions.java 2016-02-20 18:09:36 +0000
@@ -13,6 +13,7 @@
** 002 MAG 20140711 Enable/Disable clipboard.
** 003 GES 20150310 Made this class generic for web clients, not just for ChUI web clients.
** 004 GES 20150717 Added some GUI configuration values.
+** 005 SBI 20160220 Added maxBinaryMessage, maxTextMessage, maxIdleTime websocket's parameters
*/
package com.goldencode.p2j.main;
@@ -20,7 +21,6 @@
import java.util.*;
import com.goldencode.p2j.net.*;
-import com.goldencode.p2j.ui.client.*;
import com.goldencode.p2j.ui.client.chui.driver.*;
/**
@@ -35,6 +35,15 @@
{
/** Directory node name in which our configuration can be found. */
public static final String DIRECTORY_NODE_ID = "webClient";
+
+ /** The default maximal binary message size excepted by the configured websocket */
+ private static final int MAX_BINARY_MESSAGE_SIZE = 32768;
+
+ /** The default maximal text message size excepted by the configured websocket */
+ private static final int MAX_TEXT_MESSAGE_SIZE = 4096;
+
+ /** The default maximal idle time of the configured websocket */
+ private static final int MAX_IDLE_TIMEOUT = 90000;
/**
* Singleton instance. Not set as final to allow it to be invalidated (in case these
@@ -150,6 +159,12 @@
fontsize = getNode(DIRECTORY_NODE_ID, "fontsize", fontsize);
stimeout = getNode(DIRECTORY_NODE_ID, "webSocketTimeout", (int) stimeout);
wtimeout = getNode(DIRECTORY_NODE_ID, "watchdogTimeout", (int) wtimeout);
+
+ // Common websocket parameters:
+ int maxBinaryMessage = getNode(DIRECTORY_NODE_ID, "maxBinaryMessage", MAX_BINARY_MESSAGE_SIZE);
+ int maxTextMessage = getNode(DIRECTORY_NODE_ID, "maxTextMessage", MAX_TEXT_MESSAGE_SIZE);
+ int maxIdleTime = getNode(DIRECTORY_NODE_ID, "maxIdleTime", MAX_IDLE_TIMEOUT);
+
port = getNode(DIRECTORY_NODE_ID, "port", port);
host = getNode(DIRECTORY_NODE_ID, "host", host);
clipboard = getNode(DIRECTORY_NODE_ID, "clipboard", true);
@@ -171,5 +186,8 @@
options.put("host", host);
options.put("clipboard", clipboard ? "true" : "false");
options.put("taskbar", taskbar ? "true" : "false");
+ options.put("maxBinaryMessage", String.valueOf(maxBinaryMessage));
+ options.put("maxTextMessage", String.valueOf(maxTextMessage));
+ options.put("maxIdleTime", String.valueOf(maxIdleTime));
}
}
=== modified file 'src/com/goldencode/p2j/ui/client/driver/web/WebClientMessageTypes.java'
--- src/com/goldencode/p2j/ui/client/driver/web/WebClientMessageTypes.java 2016-02-03 11:21:56 +0000
+++ src/com/goldencode/p2j/ui/client/driver/web/WebClientMessageTypes.java 2016-02-20 16:11:14 +0000
@@ -19,6 +19,7 @@
** and z-order operations.
** 005 CA 20151024 Added support for WINDOW:SENSITIVE attribute.
** 006 CA 20160203 Added hash management operations.
+** SBI 20160220 Added MSG_PARTIAL, MSG_FILE_UPLOAD
*/
package com.goldencode.p2j.ui.client.driver.web;
@@ -183,4 +184,10 @@
/** Inform the javascript side to remove the list of expired hashes. */
public static final byte MSG_REMOVE_EXPIRED_HASH = (byte) 0xA0;
+
+ /** Wraps the large message from the client to the sequence of this partial type messages. */
+ public static final byte MSG_PARTIAL = (byte) 0xFE;
+
+ /** File upload message. */
+ public static final byte MSG_FILE_UPLOAD = (byte) 0xFD;
}
=== modified file 'src/com/goldencode/p2j/ui/client/driver/web/WebClientProtocol.java'
--- src/com/goldencode/p2j/ui/client/driver/web/WebClientProtocol.java 2016-02-03 11:21:56 +0000
+++ src/com/goldencode/p2j/ui/client/driver/web/WebClientProtocol.java 2016-02-20 16:50:14 +0000
@@ -19,17 +19,23 @@
** message result.
** 005 CA 20160203 Fixed deadlock for receivedMessages - it must lock on the "lock" field, as
** this object is used for all sock operations (including key reading).
+** SBI 20160220 Added MSG_PARTIAL and MSG_FILE_UPLOAD.
*/
package com.goldencode.p2j.ui.client.driver.web;
+import java.io.*;
import java.nio.*;
+import java.nio.channels.*;
+import java.nio.file.*;
+import java.nio.file.attribute.*;
import java.util.*;
import java.util.concurrent.*;
import org.eclipse.jetty.websocket.api.*;
import org.eclipse.jetty.websocket.api.annotations.*;
+
/**
* Implements the WebSockets protocol to drive communications with a JavaScript web client.
*
@@ -144,7 +150,7 @@
*
*/
@SuppressWarnings("serial")
-@WebSocket(maxIdleTime = 900000, maxTextMessageSize = 4096, maxBinaryMessageSize = 32768)
+@WebSocket
public class WebClientProtocol
implements WebClientMessageTypes
{
@@ -174,7 +180,48 @@
* "synchronous" approach must call {@link #waitForResult} for the expected operation.
*/
private Map receivedMessages = new HashMap<>();
-
+
+ /** Partial messages are mapped to open file channels. */
+ private Map partialMessages = new HashMap<>();
+
+ /** The directory to save partial messages to the corresponding temporary file */
+ private Path tmpDir;
+
+ /** The options used to open file channels for created temporary files */
+ private static final StandardOpenOption[] TMP_FILE_OPTIONS
+ = new StandardOpenOption[]
+ {
+ StandardOpenOption.READ,
+ StandardOpenOption.WRITE,
+ StandardOpenOption.DELETE_ON_CLOSE
+ };
+
+ /** The file permissions to create a new temporary file */
+ private static final Set NEW_TMP_FILE_PERMISSIONS;
+
+ static
+ {
+ PosixFilePermission[] permissions
+ = new PosixFilePermission[]
+ {
+ PosixFilePermission.OWNER_READ,
+ PosixFilePermission.OWNER_WRITE
+ };
+ NEW_TMP_FILE_PERMISSIONS = new HashSet(Arrays.asList(permissions));
+ }
+
+ /** The new created temporary file name should start from this string */
+ private static final String TMP_FILE_PREFIX = "msg";
+
+ /** The new created temporary file extension */
+ private static final String TMP_FILE_EXT = ".tmp";
+
+ /**
+ * Executes tasks to collect partial messages having the same id number to a one large
+ * binary message.
+ */
+ private final ExecutorService asynchIOExecutor = Executors.newSingleThreadExecutor();
+
/** Callbacks for delegated processing. */
protected ClientProtocolHooks callbacks = null;
@@ -207,7 +254,14 @@
this.callbacks = callbacks;
this.timeout = timeout;
this.wdtimeout = wdtimeout;
-
+ try
+ {
+ this.tmpDir = Files.createTempDirectory(null);
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
startWatchdog(wdtimeout);
}
@@ -331,6 +385,98 @@
paste(message, offset, length);
handled = true;
}
+ else if (length > 11 && message[offset] == MSG_PARTIAL)
+ {
+ // [MSG_PARTIAL_TYPE][MSG_ID][PARTIAL_STATUS][PAYLOAD_LENGTH][PAYLOAD_DATA]
+ // 1 + 4 + 1 + 4 + length(payload data) > 10
+ final int msgId = readMessageInt32(message, offset + 1);
+ // PARTIAL_STATUS is 1 byte that equals 0 if it is the last message with MSG_ID or
+ // 1 if a next message with the same MSG_ID should follow this one.
+ final boolean isLast = message[offset + 5] == 0x0;
+ final int payloadLength = readMessageInt32(message, offset + 6);
+ final ByteBuffer payloadData = ByteBuffer.wrap(message, offset + 10, payloadLength);
+ FileChannel channel = partialMessages.get(msgId);
+ if (channel == null)
+ {
+ try
+ {
+
+ Path channelPath = Files.createTempFile(tmpDir, TMP_FILE_PREFIX, TMP_FILE_EXT,
+ PosixFilePermissions.asFileAttribute(NEW_TMP_FILE_PERMISSIONS));
+ channel = FileChannel.open(channelPath, TMP_FILE_OPTIONS);
+ partialMessages.put(msgId, channel);
+ }
+ catch (IOException e)
+ {
+ // TODO how to log exceptions
+ // e.printStackTrace();
+ }
+ }
+
+ if (channel != null && channel.isOpen())
+ {
+ asynchIOExecutor.submit(
+ /**
+ * The task that appends a new partial message to the already received
+ * messages having the same id number (or belonging to the same packet
+ * of messages).
+ */
+ new Runnable()
+ {
+ @Override
+ public void run()
+ {
+
+ try
+ {
+ // Find a channel by id
+ FileChannel channel = partialMessages.get(msgId);
+ // Write a payload data
+ channel.write(payloadData);
+ if (isLast)
+ {
+ // if message is the last message in this messages packet
+ // then read all gathered payload data and deliver it
+ // to the messages processor
+
+ int size = (int) channel.size();
+ ByteBuffer dst = ByteBuffer.allocate(size);
+ final int readedBytes = channel.read(dst, 0);
+ dst.flip();
+
+ // close channel to dispose used resources
+ channel.close();
+ partialMessages.remove(msgId);
+
+ if (readedBytes == size)
+ {
+ // deliver the large message to its processor
+ webWorker.post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ processBinaryMessage(dst.array(), 0, readedBytes);
+ }
+ });
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ // TODO how to log exceptions
+ // e.printStackTrace();
+ }
+ }
+ });
+ }
+ handled = true;
+ }
+ else if (length > 5 && message[offset] == MSG_FILE_UPLOAD)
+ {
+ // TODO : MSG_FILE_UPLOAD is wrapped by MSG_PARTIAL messages as payload data
+ handled = true;
+ }
return handled;
}
=== modified file 'src/com/goldencode/p2j/ui/client/driver/web/WebPageHandler.java'
--- src/com/goldencode/p2j/ui/client/driver/web/WebPageHandler.java 2015-08-07 20:47:38 +0000
+++ src/com/goldencode/p2j/ui/client/driver/web/WebPageHandler.java 2016-02-20 17:05:56 +0000
@@ -12,6 +12,8 @@
** 001 GES 20150312 Created initial version by moving code from the ChuiWebPageHandler and making
** it more generic (to handle GUI too).
** 002 GES 20150717 Moved clipboard processing to ChUI-specific location.
+** 003 SBI 20160220 Added maxBinaryMessage parameter to the template file in order to deliver
+** its value to the JS client.
*/
package com.goldencode.p2j.ui.client.driver.web;
@@ -145,10 +147,17 @@
if (text.contains("${referrer}"))
{
- String referrer = config.getString("web", "referrer", "url", null);
+ String referrer = config.getString("web", "referrer", "url", null);
text = text.replace("${referrer}", referrer);
}
+ if (text.contains("${maxBinaryMessage}"))
+ {
+ // configuration must provide the valid value of client:web:maxBinaryMessage
+ int maxBinaryMessage = config.getInt("client", "web", "maxBinaryMessage", 1024);
+ text = text.replace("${maxBinaryMessage}", String.valueOf(maxBinaryMessage));
+ }
+
return text;
}
=== modified file 'src/com/goldencode/p2j/ui/client/driver/web/index.html'
--- src/com/goldencode/p2j/ui/client/driver/web/index.html 2015-12-17 20:00:50 +0000
+++ src/com/goldencode/p2j/ui/client/driver/web/index.html 2016-02-19 22:07:40 +0000
@@ -38,7 +38,7 @@
'font' : {'name' : '${font.name}', 'size' : ${font.size}, 'color' : {'f' : '${font.color}', 'b' : '${font.background}'}},
'cursor' : {'type' : 'solid', 'visible' : true, 'blinking' : false},
'sound' : {'id' : 'beep', 'enabled' : true},
- 'socket' : {'url' : 'wss://' + window.location.host + '${context}/ajax'},
+ 'socket' : {'url' : 'wss://' + window.location.host + '${context}/ajax', 'maxBinaryMessage' : ${maxBinaryMessage}},
'page' : 'index.html',
'clipboard' : {'enabled' : ${clipboard.enabled}, 'id' : 'clipboard', 'stroke' : true, 'input' : 'copy'},
'taskbar' : {'enabled' : ${taskbar.enabled}},
=== modified file 'src/com/goldencode/p2j/ui/client/driver/web/res/p2j.socket.js'
--- src/com/goldencode/p2j/ui/client/driver/web/res/p2j.socket.js 2016-02-16 20:45:37 +0000
+++ src/com/goldencode/p2j/ui/client/driver/web/res/p2j.socket.js 2016-02-20 17:36:01 +0000
@@ -41,7 +41,8 @@
** SBI 20160107 Supported new message with 0x9F id to test if the target font family is
** available for the browser.
** CA 20160629 Added a drawing cache (and cache management, when the hash was expired by the
-* client-side).
+** client-side).
+** SBI 20160202 Implemented MSG_PARTIAL.
*/
"use strict";
@@ -66,6 +67,116 @@
/** The count of the drawing operations. */
var drawNo = 0;
+ /** The maximal size for binary messages that can be accepted by the websocket server. */
+ var maxBinaryMessage;
+
+ /**
+ * The next unique message id.
+ */
+ var nextMsgId = 0;
+
+ /** The fast timer object */
+ var fastTimer = new FastTimer("https://" + window.location.host);
+
+ /**
+ * The fast timer to execute tasks in the UI thread.
+ *
+ * @param {String} origin
+ * The message origin is an URL that defines what messages are handled by this timer.
+ */
+ function FastTimer(origin)
+ {
+ var notification = "fast-timer-notification";
+ var targetOrigin = origin;
+
+ /**
+ * The tasks queue to be performed by the fast timer. A task must have "execute" function
+ * as its public member.
+ */
+ var tasksQueue = [];
+
+ /**
+ * Schedule a task to be executed by the fast timer.
+ *
+ * @param {Task} task
+ */
+ function scheduleTask(task)
+ {
+ tasksQueue.push(task);
+ window.postMessage(notification, targetOrigin);
+ }
+
+ this.scheduleTask = scheduleTask;
+
+ /**
+ * Executes the next task from the tasks queue as soon as a notification message is caught.
+ *
+ * @param {Event} event
+ * A notification event that is handled by this fast timer
+ */
+ function executeTask(event)
+ {
+ if (event.source == window && event.data == notification)
+ {
+ event.stopPropagation();
+ if (tasksQueue.length > 0)
+ {
+ var task = tasksQueue.shift();
+ task.execute();
+ }
+ }
+ }
+
+ window.addEventListener("message", executeTask, true);
+ };
+
+ /**
+ * Sends a large message via partial messages as payload data nested by MSG_PARTIAL messages.
+ *
+ * @param {Uint8Array} msg
+ * The large source message that should be send by packets.
+ */
+ function sendMessageByPackets(msg)
+ {
+ var task = {position : 0, capacity : msg.byteLength, msg : msg};
+ task.msgId = nextMsgId;
+ nextMsgId++;
+ task.execute = function ()
+ {
+ var position = task.position;
+ var capacity = task.capacity;
+ var remaining = capacity - position;
+
+ var payloadLength;
+ var isLast;
+ if (remaining >= maxBinaryMessage - 10)
+ {
+ payloadLength = maxBinaryMessage - 10;
+ isLast = false;
+ }
+ else
+ {
+ payloadLength = remaining;
+ isLast = true;
+ }
+ var limit = position + payloadLength;
+ // send partial message
+ me.sendPartialMessage(task.msg, position, limit, payloadLength, task.msgId, isLast)
+
+ position = limit;
+ remaining = capacity - position;
+ task.position = position;
+ task.remaining = remaining;
+ // if there are bytes to send, then schedule new task
+ if (remaining > 0)
+ {
+ fastTimer.scheduleTask(task);
+ }
+ };
+
+ fastTimer.scheduleTask(task);
+ }
+
/**
* Send data.
*
@@ -75,7 +186,14 @@
{
if (connected)
{
- ws.send(data);
+ if (data.byteLength <= maxBinaryMessage)
+ {
+ ws.send(data);
+ }
+ else
+ {
+ sendMessageByPackets(data);
+ }
}
else
{
@@ -98,6 +216,38 @@
};
/**
+ * Send a partial message that wraps the payload data.
+ *
+ * @param {Uint8Array} data
+ * The large source message that should be send by packets.
+ * @param {Number} position
+ * It points to the first byte of the payload data.
+ * @param {Number} limit
+ * The upper barrier index of the payload data. T
+ * @param {Number} payloadLength
+ * The number of bytes to send starting from the given position.
+ * @param {Number} msgId
+ * The message id that identifies the large source message.
+ * @param {Boolean} isLast
+ * Indicates the last message in the packets to send.
+ */
+ me.sendPartialMessage = function(data, position, limit, payloadLength, msgId, isLast)
+ {
+ var msg = new Uint8Array(payloadLength + 10);
+ msg[0] = 0xFE;
+ me.writeInt32BinaryMessage(msg, 1, msgId);
+ msg[5] = isLast ? 0 : 1;
+ me.writeInt32BinaryMessage(msg, 6, payloadLength);
+ var i, j;
+ for(i = position, j = 10; i < limit; i++, j++)
+ {
+ msg[j] = data[i];
+ }
+
+ me.send(msg);
+ };
+
+ /**
* Sends the window active event to the server.
*
* @param {Number} wid
@@ -455,6 +605,8 @@
{
referrer = cfg.referrer;
+ maxBinaryMessage = cfg.socket.maxBinaryMessage
+
if ('WebSocket' in window)
{
ws = new WebSocket(cfg.socket.url);
=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java'
--- src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2016-02-16 20:45:37 +0000
+++ src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2016-02-19 20:25:02 +0000
@@ -63,7 +63,7 @@
* is running during session establishment with the P2J server using logging no messages are
* written into the log and the application is blocked.
*/
-@WebSocket(maxIdleTime = 900000, maxTextMessageSize = 4096, maxBinaryMessageSize = 32768)
+@WebSocket
public class GuiWebSocket
extends WebClientProtocol
{
=== modified file 'src/com/goldencode/p2j/web/GenericWebServer.java'
--- src/com/goldencode/p2j/web/GenericWebServer.java 2015-05-18 20:48:28 +0000
+++ src/com/goldencode/p2j/web/GenericWebServer.java 2016-02-20 18:09:39 +0000
@@ -12,6 +12,7 @@
** 001 MAG 20131105 First version based on jetty 9.1
** 002 MAG 20131129 Import server KeyStore.
** 003 AB 20150515 Removed configWsContext() and now directly use the handler collection.
+** 004 SBI 20160220 Changed to set the websocket parameters from the server provided configuration.
*/
package com.goldencode.p2j.web;
@@ -232,7 +233,7 @@
*/
public void addWebSocketHandler(String target, Class> webSocket)
{
- Handler wsHandler = new PojoWebSocketHandler(target, webSocket);
+ Handler wsHandler = new PojoWebSocketHandler(target, webSocket, new WebSocketConfig(config));
handlerCollection.addHandler(wsHandler);
}
@@ -246,7 +247,7 @@
*/
public void addWebSocketHandler(String target, WebSocketCreator creator)
{
- Handler wsHandler = new PojoWebSocketHandler(target, creator);
+ Handler wsHandler = new PojoWebSocketHandler(target, creator, new WebSocketConfig(config));
handlerCollection.addHandler(wsHandler);
}
@@ -439,4 +440,5 @@
{
this.serverKeyStore = keyStore;
}
+
}
=== modified file 'src/com/goldencode/p2j/web/PojoWebSocketHandler.java'
--- src/com/goldencode/p2j/web/PojoWebSocketHandler.java 2013-11-16 08:00:52 +0000
+++ src/com/goldencode/p2j/web/PojoWebSocketHandler.java 2016-02-20 17:55:05 +0000
@@ -10,6 +10,7 @@
**
** -#- -I- --Date-- ----------------------Description--------------------------
** 001 MAG 20131105 First version based on jetty 9.1
+** 002 SBI 20160220 Added websocket configuration parameters.
*/
package com.goldencode.p2j.web;
@@ -23,6 +24,7 @@
import org.eclipse.jetty.websocket.server.*;
import org.eclipse.jetty.websocket.servlet.*;
+
/**
* This class is used to register and handle WebSockets POJO objects.
*
@@ -44,7 +46,10 @@
/** WebSocketCreator used to create WebSockets by hand */
private WebSocketCreator creator;
-
+
+ /** Websocket configuration */
+ private WebSocketConfig config;
+
/**
* Constructor.
*
@@ -55,11 +60,14 @@
* @param creator
* The WebSocketCreator instance used tom create
* WebSockets by hand.
+ * @param config
+ * The websocket configuration parameters.
*/
- public PojoWebSocketHandler(String webSocketTarget, WebSocketCreator creator)
+ public PojoWebSocketHandler(String webSocketTarget, WebSocketCreator creator, WebSocketConfig config)
{
this.webSocketTarget = webSocketTarget;
this.creator = creator;
+ this.config = config;
}
/**
@@ -71,11 +79,14 @@
* of handlers for the same server context.
* @param webSocketPojo
* The WebSocket POJO class.
+ * @param config
+ * The websocket configuration parameters.
*/
- public PojoWebSocketHandler(String webSocketTarget, Class> webSocketPojo)
+ public PojoWebSocketHandler(String webSocketTarget, Class> webSocketPojo, WebSocketConfig config)
{
this.webSocketTarget = webSocketTarget;
this.webSocketPojo = webSocketPojo;
+ this.config = config;
}
/**
@@ -90,6 +101,14 @@
@Override
public void configure(WebSocketServletFactory wsServletFactory)
{
+ if (config != null)
+ {
+ wsServletFactory.getPolicy().setIdleTimeout(config.getMaxIdleTime());
+ wsServletFactory.getPolicy().setMaxBinaryMessageSize(config.getMaxBinaryMessage());
+ wsServletFactory.getPolicy().setMaxTextMessageBufferSize(config.getMaxTextMessage());
+ // used only by streams
+ wsServletFactory.getPolicy().setMaxBinaryMessageBufferSize(config.getMaxBinaryMessage());
+ }
if (creator == null)
{
wsServletFactory.register(webSocketPojo);
=== added file 'src/com/goldencode/p2j/web/WebSocketConfig.java'
--- src/com/goldencode/p2j/web/WebSocketConfig.java 1970-01-01 00:00:00 +0000
+++ src/com/goldencode/p2j/web/WebSocketConfig.java 2016-02-20 18:05:51 +0000
@@ -0,0 +1,81 @@
+/*
+** Module : WebSocketConfig.java
+** Abstract : Wraps Websocket configuration parameters.
+**
+** Copyright (c) 2016, Golden Code Development Corporation.
+** ALL RIGHTS RESERVED. Use is subject to license terms.
+**
+** Golden Code Development Corporation
+** CONFIDENTIAL
+**
+** -#- -I- --Date-- ------------------------------Description----------------------------------
+** 001 SBI 20160220 Added to set the websocket parameters from the server provided configuration.
+*/
+package com.goldencode.p2j.web;
+
+import com.goldencode.p2j.cfg.BootstrapConfig;
+
+/**
+ * Wraps Websocket configuration parameters.
+ */
+public class WebSocketConfig
+{
+ /**
+ * Maximal size of accepted text messages
+ */
+ private final int maxTextMessage;
+
+ /**
+ * Maximal idle time
+ */
+ private final int maxIdleTime;
+
+ /**
+ * Maximal size of accepted binary messages
+ */
+ private final int maxBinaryMessage;
+
+ /**
+ * Create an immutable instance of the websocket configuration parameters.
+ *
+ * @param config
+ * The server provided bootstrap configuration.
+ */
+ public WebSocketConfig(BootstrapConfig config)
+ {
+ this.maxTextMessage = config.getInt("client", "web", "maxTextMessage", -1);
+ this.maxIdleTime = config.getInt("client", "web", "maxIdleTime", -1);
+ this.maxBinaryMessage = config.getInt("client", "web", "maxBinaryMessage", -1);
+ }
+
+ /**
+ * Return the maximal size of accepted text messages.
+ *
+ * @return Maximal size of accepted text messages.
+ */
+ public int getMaxTextMessage()
+ {
+ return this.maxTextMessage;
+ }
+
+ /**
+ * Returns the maximal idle time.
+ *
+ * @return Maximal idle time
+ */
+ public int getMaxIdleTime()
+ {
+ return this.maxIdleTime;
+ }
+
+ /**
+ * Returns the maximal size of accepted binary messages.
+ *
+ * @return Maximal size of accepted binary messages.
+ */
+ public int getMaxBinaryMessage()
+ {
+ return this.maxBinaryMessage;
+ }
+
+}