Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #4450 - websocket-core exposes internal classes #4451

Merged
merged 15 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
exports org.eclipse.jetty.websocket.core;
exports org.eclipse.jetty.websocket.core.client;
exports org.eclipse.jetty.websocket.core.server;
exports org.eclipse.jetty.websocket.core.exception;
exports org.eclipse.jetty.websocket.core.internal to org.eclipse.jetty.util;

requires jetty.servlet.api;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.eclipse.jetty.util.compression.InflaterPool;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;

@ManagedObject("Abstract Extension")
public class AbstractExtension implements Extension
Expand All @@ -36,7 +35,7 @@ public class AbstractExtension implements Extension
private ExtensionConfig config;
private OutgoingFrames nextOutgoing;
private IncomingFrames nextIncoming;
private WebSocketCoreSession coreSession;
private Configuration configuration;
private DeflaterPool deflaterPool;
private InflaterPool inflaterPool;

Expand Down Expand Up @@ -169,14 +168,14 @@ public void setNextOutgoingFrames(OutgoingFrames nextOutgoing)
}

@Override
public void setWebSocketCoreSession(WebSocketCoreSession coreSession)
public void setCoreSession(CoreSession coreSession)
{
this.coreSession = coreSession;
this.configuration = coreSession;
}

protected WebSocketCoreSession getWebSocketCoreSession()
protected Configuration getConfiguration()
{
return coreSession;
return configuration;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Utf8Appendable;
import org.eclipse.jetty.util.Utf8StringBuilder;
import org.eclipse.jetty.websocket.core.exception.BadPayloadException;
import org.eclipse.jetty.websocket.core.exception.ProtocolException;
import org.eclipse.jetty.websocket.core.internal.NullAppendable;

/**
* Representation of a WebSocket Close (status code & reason)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//

package org.eclipse.jetty.websocket.core;

import java.time.Duration;

public interface Configuration
{
/**
* Get the Idle Timeout
*
* @return the idle timeout
*/
Duration getIdleTimeout();

/**
* Get the Write Timeout
*
* @return the write timeout
*/
Duration getWriteTimeout();

/**
* Set the Idle Timeout.
*
* @param timeout the timeout duration (timeout <= 0 implies an infinite timeout)
*/
void setIdleTimeout(Duration timeout);

/**
* Set the Write Timeout.
*
* @param timeout the timeout duration (timeout <= 0 implies an infinite timeout)
*/
void setWriteTimeout(Duration timeout);

boolean isAutoFragment();

void setAutoFragment(boolean autoFragment);

long getMaxFrameSize();

void setMaxFrameSize(long maxFrameSize);

int getOutputBufferSize();

void setOutputBufferSize(int outputBufferSize);

int getInputBufferSize();

void setInputBufferSize(int inputBufferSize);

long getMaxBinaryMessageSize();

void setMaxBinaryMessageSize(long maxSize);

long getMaxTextMessageSize();

void setMaxTextMessageSize(long maxSize);

interface Customizer
{
void customize(Configuration configurable);
}

class ConfigurationCustomizer implements Configuration, Customizer
{
private Duration idleTimeout;
private Duration writeTimeout;
private Boolean autoFragment;
private Long maxFrameSize;
private Integer outputBufferSize;
private Integer inputBufferSize;
private Long maxBinaryMessageSize;
private Long maxTextMessageSize;

@Override
public Duration getIdleTimeout()
{
return idleTimeout == null ? WebSocketConstants.DEFAULT_IDLE_TIMEOUT : idleTimeout;
}

@Override
public Duration getWriteTimeout()
{
return writeTimeout == null ? WebSocketConstants.DEFAULT_WRITE_TIMEOUT : writeTimeout;
}

@Override
public void setIdleTimeout(Duration timeout)
{
this.idleTimeout = timeout;
}

@Override
public void setWriteTimeout(Duration timeout)
{
this.writeTimeout = timeout;
}

@Override
public boolean isAutoFragment()
{
return autoFragment == null ? WebSocketConstants.DEFAULT_AUTO_FRAGMENT : autoFragment;
}

@Override
public void setAutoFragment(boolean autoFragment)
{
this.autoFragment = autoFragment;
}

@Override
public long getMaxFrameSize()
{
return maxFrameSize == null ? WebSocketConstants.DEFAULT_MAX_FRAME_SIZE : maxFrameSize;
}

@Override
public void setMaxFrameSize(long maxFrameSize)
{
this.maxFrameSize = maxFrameSize;
}

@Override
public int getOutputBufferSize()
{
return outputBufferSize == null ? WebSocketConstants.DEFAULT_OUTPUT_BUFFER_SIZE : outputBufferSize;
}

@Override
public void setOutputBufferSize(int outputBufferSize)
{
this.outputBufferSize = outputBufferSize;
}

@Override
public int getInputBufferSize()
{
return inputBufferSize == null ? WebSocketConstants.DEFAULT_INPUT_BUFFER_SIZE : inputBufferSize;
}

@Override
public void setInputBufferSize(int inputBufferSize)
{
this.inputBufferSize = inputBufferSize;
}

@Override
public long getMaxBinaryMessageSize()
{
return maxBinaryMessageSize == null ? WebSocketConstants.DEFAULT_MAX_BINARY_MESSAGE_SIZE : maxBinaryMessageSize;
}

@Override
public void setMaxBinaryMessageSize(long maxBinaryMessageSize)
{
this.maxBinaryMessageSize = maxBinaryMessageSize;
}

@Override
public long getMaxTextMessageSize()
{
return maxTextMessageSize == null ? WebSocketConstants.DEFAULT_MAX_TEXT_MESSAGE_SIZE : maxTextMessageSize;
}

@Override
public void setMaxTextMessageSize(long maxTextMessageSize)
{
this.maxTextMessageSize = maxTextMessageSize;
}

@Override
public void customize(Configuration configurable)
{
if (idleTimeout != null)
configurable.setIdleTimeout(idleTimeout);
if (writeTimeout != null)
configurable.setWriteTimeout(writeTimeout);
if (autoFragment != null)
configurable.setAutoFragment(autoFragment);
if (maxFrameSize != null)
configurable.setMaxFrameSize(maxFrameSize);
if (inputBufferSize != null)
configurable.setInputBufferSize(inputBufferSize);
if (outputBufferSize != null)
configurable.setOutputBufferSize(outputBufferSize);
if (maxBinaryMessageSize != null)
configurable.setMaxBinaryMessageSize(maxBinaryMessageSize);
if (maxTextMessageSize != null)
configurable.setMaxTextMessageSize(maxTextMessageSize);
}
sbordet marked this conversation as resolved.
Show resolved Hide resolved

public static ConfigurationCustomizer from(ConfigurationCustomizer parent, ConfigurationCustomizer child)
lachlan-roberts marked this conversation as resolved.
Show resolved Hide resolved
{
ConfigurationCustomizer customizer = new ConfigurationCustomizer();
parent.customize(customizer);
child.customize(customizer);
return customizer;
}
}
}
Loading