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;
@ -56,54 +55,53 @@ public class WebSocketClientFactory extends AggregateLifeCycle
public WebSocketClientFactory(Executor threadPool)
{
this(threadPool, Executors.newSingleThreadScheduledExecutor());
}
public WebSocketClientFactory(SslContextFactory sslContextFactory)
{
this(new QueuedThreadPool(), Executors.newSingleThreadScheduledExecutor(), sslContextFactory);
this(threadPool,Executors.newSingleThreadScheduledExecutor());
}
public WebSocketClientFactory(Executor threadPool, ScheduledExecutorService scheduler)
{
this(threadPool, scheduler, null);
this(threadPool,scheduler,null);
}
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();
selector = new WebSocketClientSelectorManager(bufferPool, executor, scheduler, policy);
selector = new WebSocketClientSelectorManager(bufferPool,executor,scheduler,policy);
selector.setSslContextFactory(sslContextFactory);
addBean(selector);
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);
}
connection.close();
}
connections.clear();
}
@ -152,6 +150,6 @@ public class WebSocketClientFactory extends AggregateLifeCycle
public WebSocketEventDriver newWebSocketDriver(Object websocketPojo)
{
return new WebSocketEventDriver(websocketPojo, methodsCache, policy, getBufferPool());
return new WebSocketEventDriver(websocketPojo,methodsCache,policy,getBufferPool());
}
}

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;
@ -287,24 +286,17 @@ public class WebSocketEventDriver implements IncomingFrames
private void terminateConnection(int statusCode, String rawreason)
{
try
String reason = rawreason;
if (StringUtil.isNotBlank(reason))
{
String reason = rawreason;
if (StringUtil.isNotBlank(reason))
// Trim big exception messages here.
if (reason.length() > (WebSocketFrame.MAX_CONTROL_PAYLOAD - 2))
{
// Trim big exception messages here.
if (reason.length() > (WebSocketFrame.MAX_CONTROL_PAYLOAD - 2))
{
reason = reason.substring(0,WebSocketFrame.MAX_CONTROL_PAYLOAD - 2);
}
reason = reason.substring(0,WebSocketFrame.MAX_CONTROL_PAYLOAD - 2);
}
LOG.debug("terminateConnection({},{})",statusCode,rawreason);
session.close(statusCode,reason);
}
catch (IOException e)
{
LOG.debug(e);
}
LOG.debug("terminateConnection({},{})",statusCode,rawreason);
session.close(statusCode,reason);
}
@Override

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);
}
connection.close();
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

@ -145,14 +145,7 @@ public class WebSocketServerFactory extends AbstractLifeCycle implements WebSock
{
for (WebSocketSession session : sessions)
{
try
{
session.close();
}
catch (IOException e)
{
LOG.warn("Unable to close session",e);
}
session.close();
}
sessions.clear();
}

View File

@ -84,14 +84,7 @@ public class WebSocketChatServlet extends WebSocketServlet implements WebSocketC
{
if (data.contains("disconnect"))
{
try
{
connection.close();
}
catch (IOException e)
{
LOG.warn(e);
}
connection.close();
return;
}