Removing throws IOException on WSConnection.close()

This commit is contained in:
Joakim Erdfelt 2012-08-08 12:42:57 -07:00
parent 0abb7511ff
commit 889d20ba55
8 changed files with 35 additions and 69 deletions

View File

@ -15,7 +15,6 @@
//========================================================================
package org.eclipse.jetty.websocket.client;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Queue;
@ -59,11 +58,6 @@ public class WebSocketClientFactory extends AggregateLifeCycle
this(threadPool,Executors.newSingleThreadScheduledExecutor());
}
public WebSocketClientFactory(SslContextFactory sslContextFactory)
{
this(new QueuedThreadPool(), Executors.newSingleThreadScheduledExecutor(), sslContextFactory);
}
public WebSocketClientFactory(Executor threadPool, ScheduledExecutorService scheduler)
{
this(threadPool,scheduler,null);
@ -72,16 +66,22 @@ public class WebSocketClientFactory extends AggregateLifeCycle
public WebSocketClientFactory(Executor executor, ScheduledExecutorService scheduler, SslContextFactory sslContextFactory)
{
if (executor == null)
{
throw new IllegalArgumentException("Executor is required");
}
this.executor = executor;
addBean(executor);
if (scheduler == null)
{
throw new IllegalArgumentException("Scheduler is required");
}
this.scheduler = scheduler;
if (sslContextFactory != null)
{
addBean(sslContextFactory);
}
this.policy = WebSocketPolicy.newClientPolicy();
@ -92,19 +92,17 @@ public class WebSocketClientFactory extends AggregateLifeCycle
this.methodsCache = new EventMethodsCache();
}
public WebSocketClientFactory(SslContextFactory sslContextFactory)
{
this(new QueuedThreadPool(),Executors.newSingleThreadScheduledExecutor(),sslContextFactory);
}
private void closeConnections()
{
for (WebSocketConnection connection : connections)
{
try
{
connection.close();
}
catch (IOException e)
{
LOG.warn(e);
}
}
connections.clear();
}

View File

@ -1,8 +1,10 @@
package org.eclipse.jetty.websocket.api;
import java.io.IOException;
import java.net.InetSocketAddress;
/**
* Base Connection concepts
*/
public interface BaseConnection
{
/**
@ -21,12 +23,10 @@ public interface BaseConnection
* <p>
* Basic usage: results in an non-blocking async write, then connection close.
*
* @throws IOException
* if unable to send the close frame, or close the connection successfully.
* @see StatusCode
* @see #close(int, String)
*/
void close() throws IOException;
void close();
/**
* Terminate connection, with status code.
@ -37,11 +37,9 @@ public interface BaseConnection
* the status code
* @param reason
* the (optional) reason. (can be null for no reason)
* @throws IOException
* if unable to send the close frame, or close the connection successfully.
* @see StatusCode
*/
void close(int statusCode, String reason) throws IOException;
void close(int statusCode, String reason);
/**
* Get the remote Address in use for this connection.

View File

@ -15,7 +15,6 @@
//========================================================================
package org.eclipse.jetty.websocket.driver;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.eclipse.jetty.io.ByteBufferPool;
@ -286,8 +285,6 @@ public class WebSocketEventDriver implements IncomingFrames
}
private void terminateConnection(int statusCode, String rawreason)
{
try
{
String reason = rawreason;
if (StringUtil.isNotBlank(reason))
@ -301,11 +298,6 @@ public class WebSocketEventDriver implements IncomingFrames
LOG.debug("terminateConnection({},{})",statusCode,rawreason);
session.close(statusCode,reason);
}
catch (IOException e)
{
LOG.debug(e);
}
}
@Override
public String toString()

View File

@ -80,13 +80,13 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
}
@Override
public void close() throws IOException
public void close()
{
terminateConnection(StatusCode.NORMAL,null);
}
@Override
public void close(int statusCode, String reason) throws IOException
public void close(int statusCode, String reason)
{
terminateConnection(statusCode,reason);
}

View File

@ -15,7 +15,6 @@
//========================================================================
package org.eclipse.jetty.websocket.io;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.InterruptedByTimeoutException;
import java.util.concurrent.ScheduledFuture;
@ -87,14 +86,7 @@ public abstract class FrameBytes<C> implements Callback<C>, Runnable
public void run()
{
// If this occurs we had a timeout!
try
{
connection.close();
}
catch (IOException e)
{
LOG.ignore(e);
}
failed(context, new InterruptedByTimeoutException());
}

View File

@ -40,13 +40,13 @@ public class WebSocketSession implements WebSocketConnection, IncomingFrames, Ou
}
@Override
public void close() throws IOException
public void close()
{
baseConnection.close();
}
@Override
public void close(int statusCode, String reason) throws IOException
public void close(int statusCode, String reason)
{
baseConnection.close(statusCode,reason);
}

View File

@ -144,16 +144,9 @@ public class WebSocketServerFactory extends AbstractLifeCycle implements WebSock
protected void closeConnections()
{
for (WebSocketSession session : sessions)
{
try
{
session.close();
}
catch (IOException e)
{
LOG.warn("Unable to close session",e);
}
}
sessions.clear();
}

View File

@ -83,15 +83,8 @@ public class WebSocketChatServlet extends WebSocketServlet implements WebSocketC
public void onMessage(String data)
{
if (data.contains("disconnect"))
{
try
{
connection.close();
}
catch (IOException e)
{
LOG.warn(e);
}
return;
}