From 868ce7469262d6fd2fe3f2e7f04cfe7af654d59f Mon Sep 17 00:00:00 2001 From: Kim van der Riet Date: Mon, 27 Aug 2012 15:40:33 +0000 Subject: QPID-3858: Updated code to include recent refactoring by Gordon (gsim) - see QPID-4178. git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/asyncstore@1377715 13f79535-47bb-0310-9956-ffa450edef68 --- .../qpid/configuration/ClientProperties.java | 13 ++++--- .../qpid/configuration/CommonProperties.java | 41 ++++++++++++++++++++++ .../java/org/apache/qpid/transport/Connection.java | 26 +++++++++++--- .../apache/qpid/transport/ConnectionSettings.java | 22 ++++++------ .../qpid/transport/ProtocolViolationException.java | 35 ------------------ .../transport/network/io/IoNetworkTransport.java | 7 ++-- 6 files changed, 86 insertions(+), 58 deletions(-) create mode 100644 java/common/src/main/java/org/apache/qpid/configuration/CommonProperties.java delete mode 100644 java/common/src/main/java/org/apache/qpid/transport/ProtocolViolationException.java (limited to 'java/common/src/main') diff --git a/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java b/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java index 97fbd43ea0..5268ce9bc2 100644 --- a/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java +++ b/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java @@ -20,10 +20,11 @@ package org.apache.qpid.configuration; /** * This class centralized the Qpid client properties. + * + * @see CommonProperties */ public class ClientProperties { - /** * Currently with Qpid it is not possible to change the client ID. * If one is not specified upon connection construction, an id is generated automatically. @@ -118,10 +119,6 @@ public class ClientProperties */ public static final String REJECT_BEHAVIOUR_PROP_NAME = "qpid.reject.behaviour"; - private ClientProperties() - { - } - /** * System property used to set the key manager factory algorithm. * @@ -192,4 +189,10 @@ public class ClientProperties * waiting because the client was flow controlled by the broker. */ public static final long DEFAULT_FLOW_CONTROL_WAIT_NOTIFY_PERIOD = 5000L; + + + private ClientProperties() + { + //No instances + } } diff --git a/java/common/src/main/java/org/apache/qpid/configuration/CommonProperties.java b/java/common/src/main/java/org/apache/qpid/configuration/CommonProperties.java new file mode 100644 index 0000000000..2449f457e5 --- /dev/null +++ b/java/common/src/main/java/org/apache/qpid/configuration/CommonProperties.java @@ -0,0 +1,41 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.configuration; + +/** + * Centralised record of Qpid common properties. + * + * @see ClientProperties + */ +public class CommonProperties +{ + /** + * The timeout used by the IO layer for timeouts such as send timeout in IoSender, and the close timeout for IoSender and IoReceiver + */ + public static final String IO_NETWORK_TRANSPORT_TIMEOUT_PROP_NAME = "qpid.io_network_transport_timeout"; + public static final int IO_NETWORK_TRANSPORT_TIMEOUT_DEFAULT = 60000; + + + private CommonProperties() + { + //no instances + } +} diff --git a/java/common/src/main/java/org/apache/qpid/transport/Connection.java b/java/common/src/main/java/org/apache/qpid/transport/Connection.java index 388e3442bf..e87851cf7d 100644 --- a/java/common/src/main/java/org/apache/qpid/transport/Connection.java +++ b/java/common/src/main/java/org/apache/qpid/transport/Connection.java @@ -382,7 +382,7 @@ public class Connection extends ConnectionInvoker { log.debug("SEND: [%s] %s", this, event); } - Sender s = sender; + Sender s = sender; if (s == null) { throw new ConnectionException("connection closed"); @@ -415,15 +415,23 @@ public class Connection extends ConnectionInvoker public void dispatch(Method method) { - Session ssn = getSession(method.getChannel()); + int channel = method.getChannel(); + Session ssn = getSession(channel); if(ssn != null) { ssn.received(method); } else { - throw new ProtocolViolationException( - "Received frames for an already detached session", null); + /* + * A peer receiving any other control on a detached transport MUST discard it and + * send a session.detached with the "not-attached" reason code. + */ + if(log.isDebugEnabled()) + { + log.debug("Control received on unattached channel : %d", channel); + } + invokeSessionDetached(channel, SessionDetachCode.NOT_ATTACHED); } } @@ -663,7 +671,7 @@ public class Connection extends ConnectionInvoker public void setServerProperties(final Map serverProperties) { - _serverProperties = serverProperties == null ? Collections.EMPTY_MAP : serverProperties; + _serverProperties = serverProperties == null ? Collections.emptyMap() : serverProperties; } public Map getServerProperties() @@ -719,4 +727,12 @@ public class Connection extends ConnectionInvoker { return _localAddress; } + + private void invokeSessionDetached(int channel, SessionDetachCode sessionDetachCode) + { + SessionDetached sessionDetached = new SessionDetached(); + sessionDetached.setChannel(channel); + sessionDetached.setCode(sessionDetachCode); + invoke(sessionDetached); + } } diff --git a/java/common/src/main/java/org/apache/qpid/transport/ConnectionSettings.java b/java/common/src/main/java/org/apache/qpid/transport/ConnectionSettings.java index c90a11594c..14dfeb18ec 100644 --- a/java/common/src/main/java/org/apache/qpid/transport/ConnectionSettings.java +++ b/java/common/src/main/java/org/apache/qpid/transport/ConnectionSettings.java @@ -60,9 +60,9 @@ public class ConnectionSettings private int maxChannelCount = 32767; private int maxFrameSize = 65535; private int heartbeatInterval; + private int connectTimeout = 30000; private int readBufferSize = QpidProperty.intProperty(65535, RECEIVE_BUFFER_SIZE_PROP_NAME, LEGACY_RECEIVE_BUFFER_SIZE_PROP_NAME).get(); private int writeBufferSize = QpidProperty.intProperty(65535, SEND_BUFFER_SIZE_PROP_NAME, LEGACY_SEND_BUFFER_SIZE_PROP_NAME).get();; - private long transportTimeout = 60000; // SSL props private boolean useSSL; @@ -345,6 +345,16 @@ public class ConnectionSettings this.trustStoreType = trustStoreType; } + public int getConnectTimeout() + { + return connectTimeout; + } + + public void setConnectTimeout(int connectTimeout) + { + this.connectTimeout = connectTimeout; + } + public int getReadBufferSize() { return readBufferSize; @@ -364,14 +374,4 @@ public class ConnectionSettings { this.writeBufferSize = writeBufferSize; } - - public long getTransportTimeout() - { - return transportTimeout; - } - - public void setTransportTimeout(long transportTimeout) - { - this.transportTimeout = transportTimeout; - } } diff --git a/java/common/src/main/java/org/apache/qpid/transport/ProtocolViolationException.java b/java/common/src/main/java/org/apache/qpid/transport/ProtocolViolationException.java deleted file mode 100644 index 6787157e8e..0000000000 --- a/java/common/src/main/java/org/apache/qpid/transport/ProtocolViolationException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.transport; - - -/** - * ProtocolViolationException - * - */ - -public final class ProtocolViolationException extends ConnectionException -{ - public ProtocolViolationException(String msg,Throwable cause) - { - super(msg, cause); - } -} diff --git a/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java b/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java index dfb318b80c..9b6f0a0b1b 100644 --- a/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java +++ b/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java @@ -33,6 +33,8 @@ import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLServerSocket; import javax.net.ssl.SSLServerSocketFactory; import javax.net.ssl.SSLSocket; + +import org.apache.qpid.configuration.CommonProperties; import org.apache.qpid.protocol.ProtocolEngine; import org.apache.qpid.protocol.ProtocolEngineFactory; import org.apache.qpid.transport.ConnectionSettings; @@ -47,7 +49,8 @@ import org.slf4j.LoggerFactory; public class IoNetworkTransport implements OutgoingNetworkTransport, IncomingNetworkTransport { private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(IoNetworkTransport.class); - private static final int TIMEOUT = 60000; + private static final int TIMEOUT = Integer.getInteger(CommonProperties.IO_NETWORK_TRANSPORT_TIMEOUT_PROP_NAME, + CommonProperties.IO_NETWORK_TRANSPORT_TIMEOUT_DEFAULT); private Socket _socket; private IoNetworkConnection _connection; @@ -75,7 +78,7 @@ public class IoNetworkTransport implements OutgoingNetworkTransport, IncomingNet InetAddress address = InetAddress.getByName(settings.getHost()); - _socket.connect(new InetSocketAddress(address, settings.getPort()), TIMEOUT); + _socket.connect(new InetSocketAddress(address, settings.getPort()), settings.getConnectTimeout()); } catch (SocketException e) { -- cgit v1.2.1