diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/WebSocketServer.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/WebSocketServer.java index 135fca15323..ef5271a88f9 100644 --- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/WebSocketServer.java +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/WebSocketServer.java @@ -22,6 +22,7 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.websocket.api.Session; +import org.eclipse.jetty.websocket.api.WriteCallback; import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; import org.eclipse.jetty.websocket.api.annotations.WebSocket; import org.eclipse.jetty.websocket.server.JettyWebSocketServlet; @@ -43,7 +44,7 @@ public class WebSocketServer @OnWebSocketMessage public void onMessage( Session session, String message ) { - session.getRemote().sendStringByFuture(message); + session.getRemote().sendString(message, WriteCallback.NOOP); } } diff --git a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/SimpleEchoSocket.java b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/SimpleEchoSocket.java index 0629ca8600d..1327cf66667 100644 --- a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/SimpleEchoSocket.java +++ b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/SimpleEchoSocket.java @@ -19,7 +19,6 @@ package org.eclipse.jetty.osgi.test; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import org.eclipse.jetty.websocket.api.Session; @@ -52,7 +51,6 @@ public class SimpleEchoSocket @OnWebSocketClose public void onClose(int statusCode, String reason) { - //System.out.printf("Connection closed: %d - %s%n",statusCode,reason); this.session = null; this.closeLatch.countDown(); // trigger latch } @@ -60,17 +58,10 @@ public class SimpleEchoSocket @OnWebSocketConnect public void onConnect(Session session) { - //System.out.printf("Got connect: %s%n",session); this.session = session; try { - Future fut; - //System.err.println("Sending Foo!"); - fut = session.getRemote().sendStringByFuture("Foo"); - - fut.get(2,TimeUnit.SECONDS); // wait for send to complete. - //System.err.println("Foo complete"); - + session.getRemote().sendString("Foo"); session.close(StatusCode.NORMAL,"I'm done"); } catch (Throwable t) @@ -82,6 +73,5 @@ public class SimpleEchoSocket @OnWebSocketMessage public void onMessage(String msg) { - //System.out.printf("Got msg: %s%n",msg); } } diff --git a/jetty-websocket/jetty-websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java b/jetty-websocket/jetty-websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java index 6d406dc8d7c..d5bebbd4c33 100644 --- a/jetty-websocket/jetty-websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java +++ b/jetty-websocket/jetty-websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java @@ -19,10 +19,8 @@ package org.eclipse.jetty.websocket.api; import java.io.IOException; -import java.net.InetSocketAddress; import java.net.SocketAddress; import java.nio.ByteBuffer; -import java.util.concurrent.Future; public interface RemoteEndpoint { @@ -45,16 +43,6 @@ public interface RemoteEndpoint */ void sendBytes(ByteBuffer data, WriteCallback callback); - /** - * Initiates the asynchronous transmission of a binary message. This method returns before the message is transmitted. - * Developers may use the returned Future object to track progress of the transmission. - * - * @param data the data being sent - * @return the Future object representing the send operation. - */ - @Deprecated - Future sendBytesByFuture(ByteBuffer data); - /** * Send a binary message in pieces, blocking until all of the message has been transmitted. * The runtime reads the message in order. Non-final pieces are @@ -79,20 +67,6 @@ public interface RemoteEndpoint */ void sendPartialBytes(ByteBuffer fragment, boolean isLast, WriteCallback callback); - /** - * Initiates the asynchronous transmission of a partial binary message. This method returns before the message is - * transmitted. - * The runtime reads the message in order. Non-final pieces are sent with isLast - * set to false. The final piece must be sent with isLast set to true. - * Developers may use the returned Future object to track progress of the transmission. - * - * @param fragment the data being sent - * @param isLast true if this is the last piece of the partial bytes - * @return the Future object representing the send operation. - */ - @Deprecated - Future sendPartialBytesByFuture(ByteBuffer fragment, boolean isLast); - /** * Send a text message, blocking until all bytes of the message has been transmitted. *

@@ -113,17 +87,6 @@ public interface RemoteEndpoint */ void sendString(String text, WriteCallback callback); - /** - * Initiates the asynchronous transmission of a text message. This method may return before the message is - * transmitted. Developers may use the returned - * Future object to track progress of the transmission. - * - * @param text the text being sent - * @return the Future object representing the send operation. - */ - @Deprecated - Future sendStringByFuture(String text); - /** * Send a text message in pieces, blocking until all of the message has been transmitted. The runtime reads the * message in order. Non-final pieces are sent @@ -148,20 +111,6 @@ public interface RemoteEndpoint */ void sendPartialString(String fragment, boolean isLast, WriteCallback callback) throws IOException; - /** - * Initiates the asynchronous transmission of a partial text message. - * This method may return before the message is transmitted. - * The runtime reads the message in order. Non-final pieces are sent with isLast - * set to false. The final piece must be sent with isLast set to true. - * Developers may use the returned Future object to track progress of the transmission. - * - * @param fragment the text being sent - * @param isLast true if this is the last piece of the partial bytes - * @return the Future object representing the send operation. - */ - @Deprecated - Future sendPartialStringByFuture(String fragment, boolean isLast) throws IOException; - /** * Send a Ping message containing the given application data to the remote endpoint, blocking until all of the * message has been transmitted. @@ -181,16 +130,6 @@ public interface RemoteEndpoint */ void sendPing(ByteBuffer applicationData, WriteCallback callback); - /** - * Asynchronously send a Ping message containing the given application data to the remote endpoint. - * The corresponding Pong message may be picked up using the MessageHandler.Pong handler. - * - * @param applicationData the data to be carried in the ping request - * @return the Future object representing the send operation. - */ - @Deprecated - Future sendPingByFuture(ByteBuffer applicationData); - /** * Allows the developer to send an unsolicited Pong message containing the given application data * in order to serve as a unidirectional heartbeat for the session, this will block until @@ -210,16 +149,6 @@ public interface RemoteEndpoint */ void sendPong(ByteBuffer applicationData, WriteCallback callback); - /** - * Allows the developer to asynchronously send an unsolicited Pong message containing the given application data - * in order to serve as a unidirectional heartbeat for the session. - * - * @param applicationData the application data to be carried in the pong response. - * @return the Future object representing the send operation. - */ - @Deprecated - Future sendPongByFuture(ByteBuffer applicationData); - /** * @return the batch mode with which messages are sent. * @see #flush() @@ -234,15 +163,6 @@ public interface RemoteEndpoint */ void setBatchMode(BatchMode mode); - /** - * Get the InetSocketAddress for the established connection. - * - * @return the InetSocketAddress for the established connection. (or null, if there is none) - * @deprecated use {@link #getRemoteAddress()} instead - */ - @Deprecated - InetSocketAddress getInetSocketAddress(); - /** * Get the SocketAddress for the established connection. * diff --git a/jetty-websocket/jetty-websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/WebSocket.java b/jetty-websocket/jetty-websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/WebSocket.java index efe590a3d84..14f6b1c5a81 100644 --- a/jetty-websocket/jetty-websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/WebSocket.java +++ b/jetty-websocket/jetty-websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/WebSocket.java @@ -48,13 +48,6 @@ public @interface WebSocket */ int maxBinaryMessageSize() default -1; - /** - * The time in ms (milliseconds) that a websocket may be idle before closing. - * @deprecated use {@link #idleTimeout()} instead - */ - @Deprecated - int maxIdleTime() default -1; - /** * The time in ms (milliseconds) that a websocket may be idle before closing. */ diff --git a/jetty-websocket/jetty-websocket-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerFactory.java b/jetty-websocket/jetty-websocket-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerFactory.java index 2522c0ccf10..4f46f4f98cd 100644 --- a/jetty-websocket/jetty-websocket-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerFactory.java +++ b/jetty-websocket/jetty-websocket-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerFactory.java @@ -296,8 +296,6 @@ public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle if (max>=0) metadata.setMaxTextMessageSize(max); max = anno.idleTimeout(); - if (max<0) - max = anno.maxIdleTime(); if (max>=0) metadata.setIdleTimeout(Duration.ofMillis(max)); metadata.setBatchMode(anno.batchMode()); diff --git a/jetty-websocket/jetty-websocket-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java b/jetty-websocket/jetty-websocket-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java index ab96f43bcc7..ac74da8255e 100644 --- a/jetty-websocket/jetty-websocket-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java +++ b/jetty-websocket/jetty-websocket-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java @@ -19,15 +19,12 @@ package org.eclipse.jetty.websocket.common; import java.io.IOException; -import java.net.InetSocketAddress; import java.net.SocketAddress; import java.nio.ByteBuffer; import java.util.Objects; -import java.util.concurrent.Future; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; -import org.eclipse.jetty.util.FutureCallback; import org.eclipse.jetty.util.SharedBlockingCallback; import org.eclipse.jetty.websocket.api.BatchMode; import org.eclipse.jetty.websocket.api.WriteCallback; @@ -101,16 +98,6 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket isBatch()); } - @Override - public Future sendBytesByFuture(ByteBuffer data) - { - FutureCallback callback = new FutureCallback(); - coreSession.sendFrame(new Frame(OpCode.BINARY).setPayload(data), - callback, - isBatch()); - return callback; - } - @Override public void sendPartialBytes(ByteBuffer fragment, boolean isLast) throws IOException { @@ -127,14 +114,6 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket sendPartialBytes(fragment, isLast, Callback.from(callback::writeSuccess, callback::writeFailed)); } - @Override - public Future sendPartialBytesByFuture(ByteBuffer fragment, boolean isLast) - { - FutureCallback callback = new FutureCallback(); - sendPartialBytes(fragment, isLast, callback); - return callback; - } - @Override public void sendString(String text) throws IOException { @@ -148,16 +127,6 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket coreSession.sendFrame(new Frame(OpCode.TEXT).setPayload(text), cb, isBatch()); } - @Override - public Future sendStringByFuture(String text) - { - FutureCallback callback = new FutureCallback(); - coreSession.sendFrame(new Frame(OpCode.TEXT).setPayload(text), - callback, - isBatch()); - return callback; - } - @Override public void sendPartialString(String fragment, boolean isLast) throws IOException { @@ -169,19 +138,11 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket } @Override - public void sendPartialString(String fragment, boolean isLast, WriteCallback callback) throws IOException + public void sendPartialString(String fragment, boolean isLast, WriteCallback callback) { sendPartialText(fragment, isLast, Callback.from(callback::writeSuccess, callback::writeFailed)); } - @Override - public Future sendPartialStringByFuture(String fragment, boolean isLast) throws IOException - { - FutureCallback callback = new FutureCallback(); - sendPartialText(fragment, isLast, callback); - return callback; - } - @Override public void sendPing(ByteBuffer applicationData) throws IOException { @@ -195,14 +156,6 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket Callback.from(callback::writeSuccess, callback::writeFailed), false); } - @Override - public Future sendPingByFuture(ByteBuffer applicationData) - { - FutureCallback callback = new FutureCallback(); - coreSession.sendFrame(new Frame(OpCode.PING).setPayload(applicationData), callback, false); - return callback; - } - @Override public void sendPong(ByteBuffer applicationData) throws IOException { @@ -216,14 +169,6 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket Callback.from(callback::writeSuccess, callback::writeFailed), false); } - @Override - public Future sendPongByFuture(ByteBuffer applicationData) - { - FutureCallback callback = new FutureCallback(); - coreSession.sendFrame(new Frame(OpCode.PONG).setPayload(applicationData), callback, false); - return callback; - } - private void sendPartialBytes(ByteBuffer fragment, boolean isLast, Callback callback) { Frame frame; @@ -311,16 +256,6 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket return BatchMode.ON == batchMode; } - @Override - public InetSocketAddress getInetSocketAddress() - { - SocketAddress remoteAddress = coreSession.getRemoteAddress(); - if (remoteAddress instanceof InetSocketAddress) - return (InetSocketAddress)remoteAddress; - - return null; - } - @Override public SocketAddress getRemoteAddress() { diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java index d52ec3e75cc..cb0aad80fc8 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java @@ -54,6 +54,7 @@ import org.eclipse.jetty.websocket.server.JettyWebSocketServlet; import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory; import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer; import org.eclipse.jetty.websocket.tests.CloseTrackingEndpoint; +import org.eclipse.jetty.websocket.tests.util.FutureWriteCallback; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -84,7 +85,8 @@ public class ClientCloseTest { // Send message from client to server final String echoMsg = "echo-test"; - Future testFut = clientSocket.getRemote().sendStringByFuture(echoMsg); + FutureWriteCallback testFut = new FutureWriteCallback(); + clientSocket.getRemote().sendString(echoMsg, testFut); // Wait for send future testFut.get(5, SECONDS); diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientWriteThread.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientWriteThread.java index 105df992917..8860e1ac904 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientWriteThread.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientWriteThread.java @@ -18,7 +18,6 @@ package org.eclipse.jetty.websocket.tests.client; -import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -27,6 +26,7 @@ import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.api.BatchMode; import org.eclipse.jetty.websocket.api.RemoteEndpoint; import org.eclipse.jetty.websocket.api.Session; +import org.eclipse.jetty.websocket.tests.util.FutureWriteCallback; public class ClientWriteThread extends Thread { @@ -65,11 +65,12 @@ public class ClientWriteThread extends Thread { LOG.debug("Writing {} messages to connection {}",messageCount); LOG.debug("Artificial Slowness {} ms",slowness); - Future lastMessage = null; + FutureWriteCallback lastMessage = null; RemoteEndpoint remote = session.getRemote(); while (m.get() < messageCount) { - lastMessage = remote.sendStringByFuture(message + "/" + m.get() + "/"); + lastMessage = new FutureWriteCallback(); + remote.sendString(message + "/" + m.get() + "/", lastMessage); m.incrementAndGet(); diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ContainerEndpoint.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ContainerEndpoint.java index c4350612198..d27dc7afba6 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ContainerEndpoint.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ContainerEndpoint.java @@ -22,6 +22,7 @@ import java.util.Collection; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.StatusCode; +import org.eclipse.jetty.websocket.api.WriteCallback; import org.eclipse.jetty.websocket.common.WebSocketContainer; /** @@ -53,7 +54,7 @@ public class ContainerEndpoint extends AbstractCloseEndpoint { ret.append('[').append(idx++).append("] ").append(sess.toString()).append('\n'); } - session.getRemote().sendStringByFuture(ret.toString()); + session.getRemote().sendString(ret.toString(), WriteCallback.NOOP); } session.close(StatusCode.NORMAL,"ContainerEndpoint"); }