Java Code Examples for javax.websocket.Session#setMaxBinaryMessageBufferSize()

The following examples show how to use javax.websocket.Session#setMaxBinaryMessageBufferSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WsConfigurator.java    From mercury with Apache License 2.0 6 votes vote down vote up
public void update(Session session) {
    session.setMaxIdleTimeout(getIdleTimeout() * 1000);
    if (!idleTimerLogged) {
        idleTimerLogged = true;
        log.info("{} = {} seconds", IDLE_TIMEOUT, session.getMaxIdleTimeout() / 1000);
    }
    // adjust web socket buffer size
    int originalTextSize = session.getMaxTextMessageBufferSize();
    int originalBinarySize = session.getMaxBinaryMessageBufferSize();
    if (originalTextSize != getTextSize()) {
        session.setMaxTextMessageBufferSize(getTextSize());
        if (!textSizeLogged) {
            textSizeLogged = true;
            log.warn("{} changed from {} to {}", TEXT_SIZE, originalTextSize, session.getMaxTextMessageBufferSize());
        }
    }
    if (originalBinarySize != getBinarySize()) {
        session.setMaxBinaryMessageBufferSize(getBinarySize());
        if (!binarySizeLogged) {
            binarySizeLogged = true;
            log.warn("{} changed from {} to {}", BINARY_SIZE, originalBinarySize, session.getMaxBinaryMessageBufferSize());
        }
    }
}
 
Example 2
Source File: AdminEndpoind.java    From opencps-v2 with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * @Override onOpen websocket connect
 * 
 * @param Session
 * @param EndpointConfig
 */
@Override
public void onOpen(Session session, EndpointConfig config) {

	session.setMaxBinaryMessageBufferSize(8388608);
	session.setMaxTextMessageBufferSize(8388608);
	
	MessageHandler handler = new MessageHandler.Whole<String>() {

		@Override
		public void onMessage(String text) {
			try {
				onMessageHandler(text, session);
			} catch (Exception e) {
				_log.error(e);
			}
		}

	};

	session.addMessageHandler(handler);

}
 
Example 3
Source File: LibertyClientEndpoint.java    From rogue-cloud with Apache License 2.0 6 votes vote down vote up
@Override
	public void onOpen(Session session, EndpointConfig ec) {
		
		// If the client instance is disposed, then immediately close all opened Sessions 
		if(LibertyClientInstance.getInstance().isDisposed()) {
			log.interesting("Ignoring onOpen on an endpoint with a closed LibertyClientInstance", clientState.getLogContext());
			try { session.close(); } catch (IOException e) {  /*ignore*/ }
			return;
		}
		
		log.interesting("Websocket session "+session.getId()+" opened with client instance "+LibertyClientInstance.getInstance().getUuid(),
				clientState.getLogContext());
		
		session.setMaxBinaryMessageBufferSize(128 * 1024);
		session.addMessageHandler(new BinaryMessageHandler(this, session, sessionWrapper));
		
//		session.addMessageHandler(new StringMessageHandler(this, session));
		
		sessionWrapper.newSession(session);
		
		ResourceLifecycleUtil.getInstance().addNewSession(ClientUtil.convertSessionToManagedResource(session));

		LibertyClientInstance.getInstance().add(session);
	}
 
Example 4
Source File: GameRoundWebsocket.java    From liberty-bikes with Eclipse Public License 1.0 5 votes vote down vote up
@OnOpen
public void onOpen(@PathParam("roundId") String roundId, Session session) {
    log(roundId, "Opened a session");
    session.setMaxTextMessageBufferSize(1000);
    session.setMaxBinaryMessageBufferSize(1000);
    session.setMaxIdleTimeout(90 * 1000);
    timerContext = GameMetrics.timerStart(GameMetrics.openWebsocketTimerMetadata);
}