INT-3283: Prevent AbstractSelectableChannel NPE
JIRA: https://jira.springsource.org/browse/INT-3283 INT-3236: Remove deprecated `AbstractConnectionFactory.close` JIRA: https://jira.springsource.org/browse/INT-3236 INT-3283: Remove `selectorLock` As far as the issue in JVM's `AbstractSelectableChannel` was fixed in Java 7 and 8, just catch entire `Exception` on `stop()`.
This commit is contained in:
committed by
Gary Russell
parent
dd4fdee0cb
commit
4ac1a9113a
@@ -409,13 +409,6 @@ public abstract class AbstractConnectionFactory extends IntegrationObjectSupport
|
||||
this.nioHarvestInterval = nioHarvestInterval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the factory.
|
||||
* @deprecated As of 3.0; use {@link #stop()}.
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract void close();
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
if (logger.isInfoEnabled()) {
|
||||
@@ -446,7 +439,6 @@ public abstract class AbstractConnectionFactory extends IntegrationObjectSupport
|
||||
@Override
|
||||
public void stop() {
|
||||
this.active = false;
|
||||
this.close();
|
||||
synchronized (this.connections) {
|
||||
Iterator<TcpConnectionSupport> iterator = this.connections.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -170,12 +170,6 @@ public class CachingClientConnectionFactory extends AbstractClientConnectionFact
|
||||
return targetConnectionFactory.isRunning();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void close() {
|
||||
targetConnectionFactory.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return targetConnectionFactory.hashCode();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -113,13 +113,6 @@ public class FailoverClientConnectionFactory extends AbstractClientConnectionFac
|
||||
return failoverTcpConnection;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void close() {
|
||||
for (AbstractClientConnectionFactory factory : this.factories) {
|
||||
factory.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
|
||||
@@ -76,10 +76,6 @@ public class TcpNetClientConnectionFactory extends
|
||||
return this.tcpSocketFactorySupport.getSocketFactory().createSocket(host, port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
|
||||
protected TcpSocketFactorySupport getTcpSocketFactorySupport() {
|
||||
return tcpSocketFactorySupport;
|
||||
}
|
||||
|
||||
@@ -148,14 +148,16 @@ public class TcpNetServerConnectionFactory extends AbstractServerConnectionFacto
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
public void stop() {
|
||||
if (this.serverSocket == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.serverSocket.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
catch (IOException e) {}
|
||||
this.serverSocket = null;
|
||||
super.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* A client connection factory that creates {@link TcpNioConnection}s.
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
@@ -112,17 +113,17 @@ public class TcpNioClientConnectionFactory extends
|
||||
this.tcpNioConnectionSupport = tcpNioSupport;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void close() {
|
||||
public void stop() {
|
||||
if (this.selector != null) {
|
||||
try {
|
||||
this.selector.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (Exception e) {
|
||||
logger.error("Error closing selector", e);
|
||||
}
|
||||
}
|
||||
super.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -37,7 +37,9 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* Implements a server connection factory that produces {@link TcpNioConnection}s using
|
||||
* a {@link ServerSocketChannel}. Must have a {@link TcpListener} registered.
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
@@ -99,14 +101,10 @@ public class TcpNioServerConnectionFactory extends AbstractServerConnectionFacto
|
||||
|
||||
}
|
||||
catch (IOException e) {
|
||||
this.close();
|
||||
if (this.isActive()) {
|
||||
logger.error("Error on ServerSocketChannel", e);
|
||||
}
|
||||
this.stop();
|
||||
}
|
||||
finally {
|
||||
this.setListening(false);
|
||||
this.setActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +123,7 @@ public class TcpNioServerConnectionFactory extends AbstractServerConnectionFacto
|
||||
* @throws SocketException
|
||||
*/
|
||||
private void doSelect(ServerSocketChannel server, final Selector selector)
|
||||
throws IOException, ClosedChannelException, SocketException {
|
||||
throws IOException, SocketException {
|
||||
while (this.isActive()) {
|
||||
int soTimeout = this.getSoTimeout();
|
||||
int selectionCount = 0;
|
||||
@@ -202,12 +200,12 @@ public class TcpNioServerConnectionFactory extends AbstractServerConnectionFacto
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
public void stop() {
|
||||
if (this.selector != null) {
|
||||
try {
|
||||
this.selector.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (Exception e) {
|
||||
logger.error("Error closing selector", e);
|
||||
}
|
||||
}
|
||||
@@ -219,6 +217,7 @@ public class TcpNioServerConnectionFactory extends AbstractServerConnectionFacto
|
||||
}
|
||||
catch (IOException e) {}
|
||||
this.serverChannel = null;
|
||||
super.stop();
|
||||
}
|
||||
|
||||
public void setUsingDirectBuffers(boolean usingDirectBuffers) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -42,11 +42,6 @@ public class ConnectionFactoryShutDownTests {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void close() {
|
||||
}
|
||||
|
||||
};
|
||||
factory.setActive(true);
|
||||
Executor executor = factory.getTaskExecutor();
|
||||
|
||||
Reference in New Issue
Block a user