Removing throws IOException on WSConnection.close()
This commit is contained in:
parent
0abb7511ff
commit
889d20ba55
|
@ -15,7 +15,6 @@
|
||||||
//========================================================================
|
//========================================================================
|
||||||
package org.eclipse.jetty.websocket.client;
|
package org.eclipse.jetty.websocket.client;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
@ -56,54 +55,53 @@ public class WebSocketClientFactory extends AggregateLifeCycle
|
||||||
|
|
||||||
public WebSocketClientFactory(Executor threadPool)
|
public WebSocketClientFactory(Executor threadPool)
|
||||||
{
|
{
|
||||||
this(threadPool, Executors.newSingleThreadScheduledExecutor());
|
this(threadPool,Executors.newSingleThreadScheduledExecutor());
|
||||||
}
|
|
||||||
|
|
||||||
public WebSocketClientFactory(SslContextFactory sslContextFactory)
|
|
||||||
{
|
|
||||||
this(new QueuedThreadPool(), Executors.newSingleThreadScheduledExecutor(), sslContextFactory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public WebSocketClientFactory(Executor threadPool, ScheduledExecutorService scheduler)
|
public WebSocketClientFactory(Executor threadPool, ScheduledExecutorService scheduler)
|
||||||
{
|
{
|
||||||
this(threadPool, scheduler, null);
|
this(threadPool,scheduler,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WebSocketClientFactory(Executor executor, ScheduledExecutorService scheduler, SslContextFactory sslContextFactory)
|
public WebSocketClientFactory(Executor executor, ScheduledExecutorService scheduler, SslContextFactory sslContextFactory)
|
||||||
{
|
{
|
||||||
if (executor == null)
|
if (executor == null)
|
||||||
|
{
|
||||||
throw new IllegalArgumentException("Executor is required");
|
throw new IllegalArgumentException("Executor is required");
|
||||||
|
}
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
addBean(executor);
|
addBean(executor);
|
||||||
|
|
||||||
if (scheduler == null)
|
if (scheduler == null)
|
||||||
|
{
|
||||||
throw new IllegalArgumentException("Scheduler is required");
|
throw new IllegalArgumentException("Scheduler is required");
|
||||||
|
}
|
||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
|
|
||||||
if (sslContextFactory != null)
|
if (sslContextFactory != null)
|
||||||
|
{
|
||||||
addBean(sslContextFactory);
|
addBean(sslContextFactory);
|
||||||
|
}
|
||||||
|
|
||||||
this.policy = WebSocketPolicy.newClientPolicy();
|
this.policy = WebSocketPolicy.newClientPolicy();
|
||||||
|
|
||||||
selector = new WebSocketClientSelectorManager(bufferPool, executor, scheduler, policy);
|
selector = new WebSocketClientSelectorManager(bufferPool,executor,scheduler,policy);
|
||||||
selector.setSslContextFactory(sslContextFactory);
|
selector.setSslContextFactory(sslContextFactory);
|
||||||
addBean(selector);
|
addBean(selector);
|
||||||
|
|
||||||
this.methodsCache = new EventMethodsCache();
|
this.methodsCache = new EventMethodsCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WebSocketClientFactory(SslContextFactory sslContextFactory)
|
||||||
|
{
|
||||||
|
this(new QueuedThreadPool(),Executors.newSingleThreadScheduledExecutor(),sslContextFactory);
|
||||||
|
}
|
||||||
|
|
||||||
private void closeConnections()
|
private void closeConnections()
|
||||||
{
|
{
|
||||||
for (WebSocketConnection connection : connections)
|
for (WebSocketConnection connection : connections)
|
||||||
{
|
{
|
||||||
try
|
connection.close();
|
||||||
{
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
LOG.warn(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
connections.clear();
|
connections.clear();
|
||||||
}
|
}
|
||||||
|
@ -152,6 +150,6 @@ public class WebSocketClientFactory extends AggregateLifeCycle
|
||||||
|
|
||||||
public WebSocketEventDriver newWebSocketDriver(Object websocketPojo)
|
public WebSocketEventDriver newWebSocketDriver(Object websocketPojo)
|
||||||
{
|
{
|
||||||
return new WebSocketEventDriver(websocketPojo, methodsCache, policy, getBufferPool());
|
return new WebSocketEventDriver(websocketPojo,methodsCache,policy,getBufferPool());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package org.eclipse.jetty.websocket.api;
|
package org.eclipse.jetty.websocket.api;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base Connection concepts
|
||||||
|
*/
|
||||||
public interface BaseConnection
|
public interface BaseConnection
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -21,12 +23,10 @@ public interface BaseConnection
|
||||||
* <p>
|
* <p>
|
||||||
* Basic usage: results in an non-blocking async write, then connection close.
|
* 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 StatusCode
|
||||||
* @see #close(int, String)
|
* @see #close(int, String)
|
||||||
*/
|
*/
|
||||||
void close() throws IOException;
|
void close();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Terminate connection, with status code.
|
* Terminate connection, with status code.
|
||||||
|
@ -37,11 +37,9 @@ public interface BaseConnection
|
||||||
* the status code
|
* the status code
|
||||||
* @param reason
|
* @param reason
|
||||||
* the (optional) reason. (can be null for no 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
|
* @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.
|
* Get the remote Address in use for this connection.
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
//========================================================================
|
//========================================================================
|
||||||
package org.eclipse.jetty.websocket.driver;
|
package org.eclipse.jetty.websocket.driver;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import org.eclipse.jetty.io.ByteBufferPool;
|
import org.eclipse.jetty.io.ByteBufferPool;
|
||||||
|
@ -287,24 +286,17 @@ public class WebSocketEventDriver implements IncomingFrames
|
||||||
|
|
||||||
private void terminateConnection(int statusCode, String rawreason)
|
private void terminateConnection(int statusCode, String rawreason)
|
||||||
{
|
{
|
||||||
try
|
String reason = rawreason;
|
||||||
|
if (StringUtil.isNotBlank(reason))
|
||||||
{
|
{
|
||||||
String reason = rawreason;
|
// Trim big exception messages here.
|
||||||
if (StringUtil.isNotBlank(reason))
|
if (reason.length() > (WebSocketFrame.MAX_CONTROL_PAYLOAD - 2))
|
||||||
{
|
{
|
||||||
// Trim big exception messages here.
|
reason = reason.substring(0,WebSocketFrame.MAX_CONTROL_PAYLOAD - 2);
|
||||||
if (reason.length() > (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
|
@Override
|
||||||
|
|
|
@ -80,13 +80,13 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException
|
public void close()
|
||||||
{
|
{
|
||||||
terminateConnection(StatusCode.NORMAL,null);
|
terminateConnection(StatusCode.NORMAL,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close(int statusCode, String reason) throws IOException
|
public void close(int statusCode, String reason)
|
||||||
{
|
{
|
||||||
terminateConnection(statusCode,reason);
|
terminateConnection(statusCode,reason);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
//========================================================================
|
//========================================================================
|
||||||
package org.eclipse.jetty.websocket.io;
|
package org.eclipse.jetty.websocket.io;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.InterruptedByTimeoutException;
|
import java.nio.channels.InterruptedByTimeoutException;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
@ -87,14 +86,7 @@ public abstract class FrameBytes<C> implements Callback<C>, Runnable
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
// If this occurs we had a timeout!
|
// If this occurs we had a timeout!
|
||||||
try
|
connection.close();
|
||||||
{
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
LOG.ignore(e);
|
|
||||||
}
|
|
||||||
failed(context, new InterruptedByTimeoutException());
|
failed(context, new InterruptedByTimeoutException());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,13 +40,13 @@ public class WebSocketSession implements WebSocketConnection, IncomingFrames, Ou
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException
|
public void close()
|
||||||
{
|
{
|
||||||
baseConnection.close();
|
baseConnection.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close(int statusCode, String reason) throws IOException
|
public void close(int statusCode, String reason)
|
||||||
{
|
{
|
||||||
baseConnection.close(statusCode,reason);
|
baseConnection.close(statusCode,reason);
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,14 +145,7 @@ public class WebSocketServerFactory extends AbstractLifeCycle implements WebSock
|
||||||
{
|
{
|
||||||
for (WebSocketSession session : sessions)
|
for (WebSocketSession session : sessions)
|
||||||
{
|
{
|
||||||
try
|
session.close();
|
||||||
{
|
|
||||||
session.close();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
LOG.warn("Unable to close session",e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
sessions.clear();
|
sessions.clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,14 +84,7 @@ public class WebSocketChatServlet extends WebSocketServlet implements WebSocketC
|
||||||
{
|
{
|
||||||
if (data.contains("disconnect"))
|
if (data.contains("disconnect"))
|
||||||
{
|
{
|
||||||
try
|
connection.close();
|
||||||
{
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
LOG.warn(e);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue