Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2012-12-14 20:36:13 +0000
committerJoakim Erdfelt2012-12-14 23:12:48 +0000
commitecb472f30b985cd119f65437ffd1fe4a12f75075 (patch)
treea72cec5259344cd67406e2414e4590e9d49c1773 /jetty-websocket/websocket-api/src
parentecf7563a79eee36546e00ccb23dd1a84d47177b2 (diff)
downloadorg.eclipse.jetty.project-ecb472f30b985cd119f65437ffd1fe4a12f75075.tar.gz
org.eclipse.jetty.project-ecb472f30b985cd119f65437ffd1fe4a12f75075.tar.xz
org.eclipse.jetty.project-ecb472f30b985cd119f65437ffd1fe4a12f75075.zip
Introducing WriteBytesProvider
Diffstat (limited to 'jetty-websocket/websocket-api/src')
-rw-r--r--jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java16
-rw-r--r--jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketConnection.java6
-rw-r--r--jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WriteCallback.java48
-rw-r--r--jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/extensions/OutgoingFrames.java19
-rw-r--r--jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/io/WebSocketBlockingConnection.java25
5 files changed, 83 insertions, 31 deletions
diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java
index ecd8945f9b..810ea681af 100644
--- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java
+++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java
@@ -25,7 +25,9 @@ import java.util.concurrent.Future;
public interface RemoteEndpoint
{
/**
- * Send a binary message, returning when all of the message has been transmitted.
+ * Send a binary message, returning when all bytes of the message has been transmitted.
+ * <p>
+ * Note: this is a blocking call
*
* @param data
* the message to be sent
@@ -43,7 +45,7 @@ public interface RemoteEndpoint
* handler that will be notified of progress
* @return the Future object representing the send operation.
*/
- Future<WriteResult> sendBytesByFuture(ByteBuffer data);
+ Future<Void> 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
@@ -70,7 +72,7 @@ public interface RemoteEndpoint
* @param applicationData
* the data to be carried in the ping request
*/
- void sendPing(ByteBuffer applicationData);
+ void sendPing(ByteBuffer applicationData) throws IOException;
/**
* Allows the developer to send an unsolicited Pong message containing the given application data in order to serve as a unidirectional heartbeat for the
@@ -79,10 +81,12 @@ public interface RemoteEndpoint
* @param applicationData
* the application data to be carried in the pong response.
*/
- void sendPong(ByteBuffer applicationData);
+ void sendPong(ByteBuffer applicationData) throws IOException;
/**
- * Send a text message, blocking until all of the message has been transmitted.
+ * Send a text message, blocking until all bytes of the message has been transmitted.
+ * <p>
+ * Note: this is a blocking call
*
* @param text
* the message to be sent
@@ -100,5 +104,5 @@ public interface RemoteEndpoint
* the handler which will be notified of progress
* @return the Future object representing the send operation.
*/
- Future<WriteResult> sendStringByFuture(String text);
+ Future<Void> sendStringByFuture(String text);
}
diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketConnection.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketConnection.java
index 0240522e6f..b2c8b68ab4 100644
--- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketConnection.java
+++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketConnection.java
@@ -116,15 +116,15 @@ public interface WebSocketConnection
/**
* Send an async binary message.
*/
- Future<WriteResult> write(byte buf[], int offset, int len) throws IOException;
+ Future<Void> write(byte buf[], int offset, int len);
/**
* Send an async binary message.
*/
- Future<WriteResult> write(ByteBuffer buffer) throws IOException;
+ Future<Void> write(ByteBuffer buffer);
/**
* Send an async text messages.
*/
- Future<WriteResult> write(String message) throws IOException;
+ Future<Void> write(String message);
} \ No newline at end of file
diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WriteCallback.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WriteCallback.java
new file mode 100644
index 0000000000..d1655308d3
--- /dev/null
+++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WriteCallback.java
@@ -0,0 +1,48 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.websocket.api;
+
+/**
+ * Callback for Write events.
+ */
+public interface WriteCallback
+{
+ /*
+ * NOTE: We don't expose org.eclipse.jetty.util.Callback here as that would complicate matters with the WebAppContext's classloader isolation.
+ */
+
+ /**
+ * <p>
+ * Callback invoked when the write fails.
+ * </p>
+ *
+ * @param x
+ * the reason for the write failure
+ */
+ public void writeFailed(Throwable x);
+
+ /**
+ * <p>
+ * Callback invoked when the write completes.
+ * </p>
+ *
+ * @see #writeFailed(Throwable)
+ */
+ public abstract void writeSuccess();
+}
diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/extensions/OutgoingFrames.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/extensions/OutgoingFrames.java
index 737b071fd7..fe1b30b20a 100644
--- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/extensions/OutgoingFrames.java
+++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/extensions/OutgoingFrames.java
@@ -18,15 +18,24 @@
package org.eclipse.jetty.websocket.api.extensions;
-import java.io.IOException;
-import java.util.concurrent.Future;
-
-import org.eclipse.jetty.websocket.api.WriteResult;
+import org.eclipse.jetty.websocket.api.WriteCallback;
/**
* Interface for dealing with frames outgoing to the network (eventually)
*/
public interface OutgoingFrames
{
- Future<WriteResult> outgoingFrame(Frame frame) throws IOException;
+ /**
+ * A frame, and optional callback, intended for the network.
+ * <p>
+ * Note: the frame can undergo many transformations in the various layers and extensions present in the implementation.
+ * <p>
+ * If you are implementing a mutation, you are obliged to handle the incoming WriteCallback appropriately.
+ *
+ * @param frame
+ * the frame to eventually write to the network.
+ * @param callback
+ * the optional callback to use for success/failure of the network write operation. Can be null.
+ */
+ void outgoingFrame(Frame frame, WriteCallback callback);
}
diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/io/WebSocketBlockingConnection.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/io/WebSocketBlockingConnection.java
index e49e85a827..80f029d88f 100644
--- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/io/WebSocketBlockingConnection.java
+++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/io/WebSocketBlockingConnection.java
@@ -24,7 +24,6 @@ import java.util.concurrent.Future;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
import org.eclipse.jetty.websocket.api.WebSocketException;
-import org.eclipse.jetty.websocket.api.WriteResult;
/**
* For working with the {@link WebSocketConnection} in a blocking technique.
@@ -49,20 +48,16 @@ public class WebSocketBlockingConnection
{
try
{
- Future<WriteResult> blocker = conn.write(data,offset,length);
- WriteResult result = blocker.get(); // block till finished
- if (result.getException() != null)
- {
- throw new WebSocketException(result.getException());
- }
+ Future<Void> blocker = conn.write(data,offset,length);
+ blocker.get(); // block till finished
}
catch (InterruptedException e)
{
- throw new IOException("Blocking write failed",e);
+ throw new WebSocketException("Blocking write failed",e);
}
catch (ExecutionException e)
{
- throw new WebSocketException(e.getCause());
+ throw new IOException(e.getCause());
}
}
@@ -75,20 +70,16 @@ public class WebSocketBlockingConnection
{
try
{
- Future<WriteResult> blocker = conn.write(message);
- WriteResult result = blocker.get(); // block till finished
- if (result.getException() != null)
- {
- throw new WebSocketException(result.getException());
- }
+ Future<Void> blocker = conn.write(message);
+ blocker.get(); // block till finished
}
catch (InterruptedException e)
{
- throw new IOException("Blocking write failed",e);
+ throw new WebSocketException("Blocking write failed",e);
}
catch (ExecutionException e)
{
- throw new WebSocketException(e.getCause());
+ throw new IOException(e.getCause());
}
}
}

Back to the top