This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new 8e1225c CAMEL-17022:add disconnect on timeout (#6195) 8e1225c is described below commit 8e1225caf08a4c38beaf519c6ce4f20e3067659a Author: christian ohr <christian....@gmail.com> AuthorDate: Fri Oct 1 17:21:05 2021 +0200 CAMEL-17022:add disconnect on timeout (#6195) * CAMEL-17022:add disconnect on timeout * CAMEL-17022:formatting Co-authored-by: Christian Ohr <christian....@icw.de> --- .../org/apache/camel/catalog/components/mina.json | 4 +- .../org/apache/camel/component/mina/mina.json | 8 +- .../camel/component/mina/MinaConfiguration.java | 5 +- .../apache/camel/component/mina/MinaProducer.java | 12 ++ .../mina/MinaDisconnectOnTimeOutTest.java | 98 ++++++++++++ .../src/test/resources/log4j2.properties | 2 +- .../component/dsl/MinaComponentBuilderFactory.java | 40 ++--- .../endpoint/dsl/MinaEndpointBuilderFactory.java | 164 +++++++++++++++------ 8 files changed, 256 insertions(+), 77 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/mina.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/mina.json index 742dc4a..e4f7a29 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/mina.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/mina.json @@ -29,7 +29,7 @@ "writeTimeout": { "kind": "property", "displayName": "Write Timeout", "group": "common", "label": "", "required": false, "type": "integer", "javaType": "long", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 10000, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Maximum amount of time it should take to send data to the MINA session. Default is 10000 milliseconds." }, "bridgeErrorHandler": { "kind": "property", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a me [...] "clientMode": { "kind": "property", "displayName": "Client Mode", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "If the clientMode is true, mina consumer will connect the address as a TCP client." }, - "disconnectOnNoReply": { "kind": "property", "displayName": "Disconnect On No Reply", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "If sync is enabled then this option dictates MinaConsumer if it shoul [...] + "disconnectOnNoReply": { "kind": "property", "displayName": "Disconnect On No Reply", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "If sync is enabled then this option dictates MinaConsumer if it should disconnect where t [...] "noReplyLogLevel": { "kind": "property", "displayName": "No Reply Log Level", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.LoggingLevel", "enum": [ "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "WARN", "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "descrip [...] "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during star [...] "cachedAddress": { "kind": "property", "displayName": "Cached Address", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Whether to create the InetAddress once and reuse. Setting this to false allows to p [...] @@ -62,7 +62,7 @@ "writeTimeout": { "kind": "parameter", "displayName": "Write Timeout", "group": "common", "label": "", "required": false, "type": "integer", "javaType": "long", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 10000, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Maximum amount of time it should take to send data to the MINA session. Default is 10000 milliseconds." }, "bridgeErrorHandler": { "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a m [...] "clientMode": { "kind": "parameter", "displayName": "Client Mode", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "If the clientMode is true, mina consumer will connect the address as a TCP client." }, - "disconnectOnNoReply": { "kind": "parameter", "displayName": "Disconnect On No Reply", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "If sync is enabled then this option dictates MinaConsumer if it shou [...] + "disconnectOnNoReply": { "kind": "parameter", "displayName": "Disconnect On No Reply", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "If sync is enabled then this option dictates MinaConsumer if it should disconnect where [...] "exceptionHandler": { "kind": "parameter", "displayName": "Exception Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", "deprecated": false, "autowired": false, "secret": false, "description": "To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the con [...] "exchangePattern": { "kind": "parameter", "displayName": "Exchange Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut", "InOptionalOut" ], "deprecated": false, "autowired": false, "secret": false, "description": "Sets the exchange pattern when the consumer creates an exchange." }, "noReplyLogLevel": { "kind": "parameter", "displayName": "No Reply Log Level", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.LoggingLevel", "enum": [ "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "WARN", "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "descri [...] diff --git a/components/camel-mina/src/generated/resources/org/apache/camel/component/mina/mina.json b/components/camel-mina/src/generated/resources/org/apache/camel/component/mina/mina.json index 742dc4a..dc265bd 100644 --- a/components/camel-mina/src/generated/resources/org/apache/camel/component/mina/mina.json +++ b/components/camel-mina/src/generated/resources/org/apache/camel/component/mina/mina.json @@ -22,20 +22,20 @@ "lenientProperties": false }, "componentProperties": { - "disconnect": { "kind": "property", "displayName": "Disconnect", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Whether or not to disconnect(close) from Mina session right after use. Can be used for both consumer and producer." }, + "disconnect": { "kind": "property", "displayName": "Disconnect", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Whether to disconnect(close) from Mina session right after use. Can be used for both consumer and producer." }, "minaLogger": { "kind": "property", "displayName": "Mina Logger", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "You can enable the Apache MINA logging filter. Apache MINA uses slf4j logging at INFO level to log all input and output." }, "sync": { "kind": "property", "displayName": "Sync", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Setting to set endpoint as one-way or request-response." }, "timeout": { "kind": "property", "displayName": "Timeout", "group": "common", "label": "", "required": false, "type": "integer", "javaType": "long", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 30000, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "You can configure the timeout that specifies how long to wait for a response from a remote server. The timeout unit is in millis [...] "writeTimeout": { "kind": "property", "displayName": "Write Timeout", "group": "common", "label": "", "required": false, "type": "integer", "javaType": "long", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 10000, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Maximum amount of time it should take to send data to the MINA session. Default is 10000 milliseconds." }, "bridgeErrorHandler": { "kind": "property", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a me [...] "clientMode": { "kind": "property", "displayName": "Client Mode", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "If the clientMode is true, mina consumer will connect the address as a TCP client." }, - "disconnectOnNoReply": { "kind": "property", "displayName": "Disconnect On No Reply", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "If sync is enabled then this option dictates MinaConsumer if it shoul [...] "noReplyLogLevel": { "kind": "property", "displayName": "No Reply Log Level", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.LoggingLevel", "enum": [ "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "WARN", "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "descrip [...] "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during star [...] "cachedAddress": { "kind": "property", "displayName": "Cached Address", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Whether to create the InetAddress once and reuse. Setting this to false allows to p [...] "lazySessionCreation": { "kind": "property", "displayName": "Lazy Session Creation", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Sessions can be lazily created to avoid exceptions, if the remote serv [...] "autowiredEnabled": { "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which t [...] "configuration": { "kind": "property", "displayName": "Configuration", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.mina.MinaConfiguration", "deprecated": false, "autowired": false, "secret": false, "description": "To use the shared mina configuration." }, + "disconnectOnNoReply": { "kind": "property", "displayName": "Disconnect On No Reply", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "If sync is enabled then this option dictates MinaConsumer if it should disconnect where t [...] "maximumPoolSize": { "kind": "property", "displayName": "Maximum Pool Size", "group": "advanced", "label": "advanced", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 16, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Number of worker threads in the worker pool for TCP and UDP" }, "orderedThreadPoolExecutor": { "kind": "property", "displayName": "Ordered Thread Pool Executor", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Whether to use ordered thread pool, to ensure events are processed orderly on [...] "transferExchange": { "kind": "property", "displayName": "Transfer Exchange", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Only used for TCP. You can transfer the exchange over the wire instead of just the body. The fol [...] @@ -55,20 +55,20 @@ "protocol": { "kind": "path", "displayName": "Protocol", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Protocol to use" }, "host": { "kind": "path", "displayName": "Host", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Hostname to use. Use localhost or 0.0.0.0 for local server as consumer. For producer use the hostname or ip address of the remot [...] "port": { "kind": "path", "displayName": "Port", "group": "common", "label": "", "required": true, "type": "integer", "javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Port number" }, - "disconnect": { "kind": "parameter", "displayName": "Disconnect", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Whether or not to disconnect(close) from Mina session right after use. Can be used for both consumer and producer." }, + "disconnect": { "kind": "parameter", "displayName": "Disconnect", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Whether to disconnect(close) from Mina session right after use. Can be used for both consumer and producer." }, "minaLogger": { "kind": "parameter", "displayName": "Mina Logger", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "You can enable the Apache MINA logging filter. Apache MINA uses slf4j logging at INFO level to log all input and output." }, "sync": { "kind": "parameter", "displayName": "Sync", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Setting to set endpoint as one-way or request-response." }, "timeout": { "kind": "parameter", "displayName": "Timeout", "group": "common", "label": "", "required": false, "type": "integer", "javaType": "long", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 30000, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "You can configure the timeout that specifies how long to wait for a response from a remote server. The timeout unit is in milli [...] "writeTimeout": { "kind": "parameter", "displayName": "Write Timeout", "group": "common", "label": "", "required": false, "type": "integer", "javaType": "long", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 10000, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Maximum amount of time it should take to send data to the MINA session. Default is 10000 milliseconds." }, "bridgeErrorHandler": { "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a m [...] "clientMode": { "kind": "parameter", "displayName": "Client Mode", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "If the clientMode is true, mina consumer will connect the address as a TCP client." }, - "disconnectOnNoReply": { "kind": "parameter", "displayName": "Disconnect On No Reply", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "If sync is enabled then this option dictates MinaConsumer if it shou [...] "exceptionHandler": { "kind": "parameter", "displayName": "Exception Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", "deprecated": false, "autowired": false, "secret": false, "description": "To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the con [...] "exchangePattern": { "kind": "parameter", "displayName": "Exchange Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut", "InOptionalOut" ], "deprecated": false, "autowired": false, "secret": false, "description": "Sets the exchange pattern when the consumer creates an exchange." }, "noReplyLogLevel": { "kind": "parameter", "displayName": "No Reply Log Level", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.LoggingLevel", "enum": [ "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "WARN", "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "descri [...] "lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during sta [...] "cachedAddress": { "kind": "parameter", "displayName": "Cached Address", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Whether to create the InetAddress once and reuse. Setting this to false allows to [...] "lazySessionCreation": { "kind": "parameter", "displayName": "Lazy Session Creation", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Sessions can be lazily created to avoid exceptions, if the remote ser [...] + "disconnectOnNoReply": { "kind": "parameter", "displayName": "Disconnect On No Reply", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "If sync is enabled then this option dictates MinaConsumer if it should disconnect where [...] "maximumPoolSize": { "kind": "parameter", "displayName": "Maximum Pool Size", "group": "advanced", "label": "advanced", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 16, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Number of worker threads in the worker pool for TCP and UDP" }, "orderedThreadPoolExecutor": { "kind": "parameter", "displayName": "Ordered Thread Pool Executor", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Whether to use ordered thread pool, to ensure events are processed orderly o [...] "transferExchange": { "kind": "parameter", "displayName": "Transfer Exchange", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.mina.MinaConfiguration", "configurationField": "configuration", "description": "Only used for TCP. You can transfer the exchange over the wire instead of just the body. The fo [...] diff --git a/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java b/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java index 43d9190..b7e88e3 100644 --- a/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java +++ b/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java @@ -74,7 +74,7 @@ public class MinaConfiguration implements Cloneable { private boolean allowDefaultCodec = true; @UriParam private boolean disconnect; - @UriParam(label = "consumer,advanced", defaultValue = "true") + @UriParam(label = "advanced", defaultValue = "true") private boolean disconnectOnNoReply = true; @UriParam(label = "consumer,advanced", defaultValue = "WARN") private LoggingLevel noReplyLogLevel = LoggingLevel.WARN; @@ -324,8 +324,7 @@ public class MinaConfiguration implements Cloneable { } /** - * Whether or not to disconnect(close) from Mina session right after use. Can be used for both consumer and - * producer. + * Whether to disconnect(close) from Mina session right after use. Can be used for both consumer and producer. */ public void setDisconnect(boolean disconnect) { this.disconnect = disconnect; diff --git a/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java b/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java index f03e2df..98376c5 100644 --- a/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java +++ b/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java @@ -172,6 +172,7 @@ public class MinaProducer extends DefaultProducer { LOG.debug("Waiting for response using timeout {} millis.", timeout); boolean done = responseLatch.await(timeout, TimeUnit.MILLISECONDS); if (!done) { + maybeDisconnectOnTimeout(); throw new ExchangeTimedOutException(exchange, timeout); } @@ -180,6 +181,7 @@ public class MinaProducer extends DefaultProducer { throw new CamelExchangeException("Error occurred in ResponseHandler", exchange, handler.getCause()); } else if (!handler.isMessageReceived()) { // no message received + maybeDisconnectOnTimeout(); throw new ExchangeTimedOutException(exchange, timeout); } else { // set the result on either IN or OUT on the original exchange depending on its pattern @@ -192,6 +194,16 @@ public class MinaProducer extends DefaultProducer { } } + protected void maybeDisconnectOnTimeout() throws InterruptedException { + if (session == null) { + return; + } + if (configuration.isDisconnectOnNoReply()) { + LOG.debug("Closing session when timed out at address: {}", address); + closeSessionIfNeededAndAwaitCloseInHandler(session); + } + } + protected void maybeDisconnectOnDone(Exchange exchange) throws InterruptedException { if (session == null) { return; diff --git a/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaDisconnectOnTimeOutTest.java b/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaDisconnectOnTimeOutTest.java new file mode 100644 index 0000000..5f01797 --- /dev/null +++ b/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaDisconnectOnTimeOutTest.java @@ -0,0 +1,98 @@ +/* + * 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.camel.component.mina; + +import org.apache.camel.ExchangeTimedOutException; +import org.apache.camel.builder.RouteBuilder; +import org.junit.jupiter.api.Test; +import org.junit.platform.commons.util.UnrecoverableExceptions; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * To test timeout and disconnect + */ +public class MinaDisconnectOnTimeOutTest extends BaseMinaTest { + + private static final String ENDPOINT = "mina:tcp://localhost:%s?textline=true&sync=true&timeout=250&disconnectOnNoReply=%s"; + private static final String RESPONSE = "Slept %s ms"; + + @Test + public void testBothRequestsTimeout() { + int tooLong = 400; + assertThrowable(ExchangeTimedOutException.class, () -> requestWithDelay(tooLong, true)); + assertThrowable(ExchangeTimedOutException.class, () -> requestWithDelay(tooLong, true)); + } + + @Test + public void testSecondRequestReturnsCorrectResult() { + int tooLong = 350; + int fastEnough = 150; + assertThrowable(ExchangeTimedOutException.class, () -> requestWithDelay(tooLong, true)); + assertEquals(response(fastEnough), requestWithDelay(fastEnough, true)); + } + + @Test + public void testSecondRequestReturnsWrongResult() { + int tooLong = 350; + int fastEnough = 150; + assertThrowable(ExchangeTimedOutException.class, () -> requestWithDelay(tooLong, false)); + // YIKES! The response from the first query is returned for the second query. Better leave disconnectOnNoReply on true! + assertEquals(response(tooLong), requestWithDelay(fastEnough, false)); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + + public void configure() { + from(String.format("mina:tcp://localhost:%1$s?textline=true&sync=true&timeout=30000", getPort())) + .process(e -> { + int sleep = e.getMessage().getBody(Integer.class); + Thread.sleep(sleep); + e.getMessage().setBody(response(sleep)); + }); + } + }; + } + + private String requestWithDelay(int sleep, boolean disconnect) { + return template.requestBody(String.format(ENDPOINT, getPort(), disconnect), sleep, String.class); + } + + private static String response(int sleep) { + return String.format(RESPONSE, sleep); + } + + private static void assertThrowable(Class<? extends Throwable> expectedCause, Runnable runnable) { + try { + runnable.run(); + } catch (Throwable t) { + Throwable t2 = t; + while (t2.getCause() != null) { + t2 = t2.getCause(); + if (expectedCause.isInstance(t2)) { + return; + } + } + UnrecoverableExceptions.rethrowIfUnrecoverable(t); + throw new AssertionError( + String.format("Expected exception %s, but exception stack did not contain it", expectedCause), t); + } + throw new AssertionError(String.format("Expected %s to be thrown, but nothing was thrown", expectedCause)); + } +} diff --git a/components/camel-mina/src/test/resources/log4j2.properties b/components/camel-mina/src/test/resources/log4j2.properties index f81ac82..137d070 100644 --- a/components/camel-mina/src/test/resources/log4j2.properties +++ b/components/camel-mina/src/test/resources/log4j2.properties @@ -24,5 +24,5 @@ appender.out.type = Console appender.out.name = out appender.out.layout.type = PatternLayout appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n -rootLogger.level = INFO +rootLogger.level = DEBUG rootLogger.appenderRef.file.ref = file diff --git a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/MinaComponentBuilderFactory.java b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/MinaComponentBuilderFactory.java index d805202..3dc2396 100644 --- a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/MinaComponentBuilderFactory.java +++ b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/MinaComponentBuilderFactory.java @@ -49,8 +49,8 @@ public interface MinaComponentBuilderFactory { */ interface MinaComponentBuilder extends ComponentBuilder<MinaComponent> { /** - * Whether or not to disconnect(close) from Mina session right after - * use. Can be used for both consumer and producer. + * Whether to disconnect(close) from Mina session right after use. Can + * be used for both consumer and producer. * * The option is a: <code>boolean</code> type. * @@ -167,23 +167,6 @@ public interface MinaComponentBuilderFactory { return this; } /** - * If sync is enabled then this option dictates MinaConsumer if it - * should disconnect where there is no reply to send back. - * - * The option is a: <code>boolean</code> type. - * - * Default: true - * Group: consumer (advanced) - * - * @param disconnectOnNoReply the value to set - * @return the dsl builder - */ - default MinaComponentBuilder disconnectOnNoReply( - boolean disconnectOnNoReply) { - doSetProperty("disconnectOnNoReply", disconnectOnNoReply); - return this; - } - /** * If sync is enabled this option dictates MinaConsumer which logging * level to use when logging a there is no reply to send back. * @@ -294,6 +277,23 @@ public interface MinaComponentBuilderFactory { return this; } /** + * If sync is enabled then this option dictates MinaConsumer if it + * should disconnect where there is no reply to send back. + * + * The option is a: <code>boolean</code> type. + * + * Default: true + * Group: advanced + * + * @param disconnectOnNoReply the value to set + * @return the dsl builder + */ + default MinaComponentBuilder disconnectOnNoReply( + boolean disconnectOnNoReply) { + doSetProperty("disconnectOnNoReply", disconnectOnNoReply); + return this; + } + /** * Number of worker threads in the worker pool for TCP and UDP. * * The option is a: <code>int</code> type. @@ -560,13 +560,13 @@ public interface MinaComponentBuilderFactory { case "writeTimeout": getOrCreateConfiguration((MinaComponent) component).setWriteTimeout((long) value); return true; case "bridgeErrorHandler": ((MinaComponent) component).setBridgeErrorHandler((boolean) value); return true; case "clientMode": getOrCreateConfiguration((MinaComponent) component).setClientMode((boolean) value); return true; - case "disconnectOnNoReply": getOrCreateConfiguration((MinaComponent) component).setDisconnectOnNoReply((boolean) value); return true; case "noReplyLogLevel": getOrCreateConfiguration((MinaComponent) component).setNoReplyLogLevel((org.apache.camel.LoggingLevel) value); return true; case "lazyStartProducer": ((MinaComponent) component).setLazyStartProducer((boolean) value); return true; case "cachedAddress": getOrCreateConfiguration((MinaComponent) component).setCachedAddress((boolean) value); return true; case "lazySessionCreation": getOrCreateConfiguration((MinaComponent) component).setLazySessionCreation((boolean) value); return true; case "autowiredEnabled": ((MinaComponent) component).setAutowiredEnabled((boolean) value); return true; case "configuration": ((MinaComponent) component).setConfiguration((org.apache.camel.component.mina.MinaConfiguration) value); return true; + case "disconnectOnNoReply": getOrCreateConfiguration((MinaComponent) component).setDisconnectOnNoReply((boolean) value); return true; case "maximumPoolSize": getOrCreateConfiguration((MinaComponent) component).setMaximumPoolSize((int) value); return true; case "orderedThreadPoolExecutor": getOrCreateConfiguration((MinaComponent) component).setOrderedThreadPoolExecutor((boolean) value); return true; case "transferExchange": getOrCreateConfiguration((MinaComponent) component).setTransferExchange((boolean) value); return true; diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MinaEndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MinaEndpointBuilderFactory.java index 6d17c04..e3ee87d 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MinaEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MinaEndpointBuilderFactory.java @@ -44,8 +44,8 @@ public interface MinaEndpointBuilderFactory { return (AdvancedMinaEndpointConsumerBuilder) this; } /** - * Whether or not to disconnect(close) from Mina session right after - * use. Can be used for both consumer and producer. + * Whether to disconnect(close) from Mina session right after use. Can + * be used for both consumer and producer. * * The option is a: <code>boolean</code> type. * @@ -60,8 +60,8 @@ public interface MinaEndpointBuilderFactory { return this; } /** - * Whether or not to disconnect(close) from Mina session right after - * use. Can be used for both consumer and producer. + * Whether to disconnect(close) from Mina session right after use. Can + * be used for both consumer and producer. * * The option will be converted to a <code>boolean</code> * type. @@ -617,41 +617,6 @@ public interface MinaEndpointBuilderFactory { return (MinaEndpointConsumerBuilder) this; } /** - * If sync is enabled then this option dictates MinaConsumer if it - * should disconnect where there is no reply to send back. - * - * The option is a: <code>boolean</code> type. - * - * Default: true - * Group: consumer (advanced) - * - * @param disconnectOnNoReply the value to set - * @return the dsl builder - */ - default AdvancedMinaEndpointConsumerBuilder disconnectOnNoReply( - boolean disconnectOnNoReply) { - doSetProperty("disconnectOnNoReply", disconnectOnNoReply); - return this; - } - /** - * If sync is enabled then this option dictates MinaConsumer if it - * should disconnect where there is no reply to send back. - * - * The option will be converted to a <code>boolean</code> - * type. - * - * Default: true - * Group: consumer (advanced) - * - * @param disconnectOnNoReply the value to set - * @return the dsl builder - */ - default AdvancedMinaEndpointConsumerBuilder disconnectOnNoReply( - String disconnectOnNoReply) { - doSetProperty("disconnectOnNoReply", disconnectOnNoReply); - return this; - } - /** * To let the consumer use a custom ExceptionHandler. Notice if the * option bridgeErrorHandler is enabled then this option is not in use. * By default the consumer will deal with exceptions, that will be @@ -758,6 +723,41 @@ public interface MinaEndpointBuilderFactory { return this; } /** + * If sync is enabled then this option dictates MinaConsumer if it + * should disconnect where there is no reply to send back. + * + * The option is a: <code>boolean</code> type. + * + * Default: true + * Group: advanced + * + * @param disconnectOnNoReply the value to set + * @return the dsl builder + */ + default AdvancedMinaEndpointConsumerBuilder disconnectOnNoReply( + boolean disconnectOnNoReply) { + doSetProperty("disconnectOnNoReply", disconnectOnNoReply); + return this; + } + /** + * If sync is enabled then this option dictates MinaConsumer if it + * should disconnect where there is no reply to send back. + * + * The option will be converted to a <code>boolean</code> + * type. + * + * Default: true + * Group: advanced + * + * @param disconnectOnNoReply the value to set + * @return the dsl builder + */ + default AdvancedMinaEndpointConsumerBuilder disconnectOnNoReply( + String disconnectOnNoReply) { + doSetProperty("disconnectOnNoReply", disconnectOnNoReply); + return this; + } + /** * Number of worker threads in the worker pool for TCP and UDP. * * The option is a: <code>int</code> type. @@ -879,8 +879,8 @@ public interface MinaEndpointBuilderFactory { return (AdvancedMinaEndpointProducerBuilder) this; } /** - * Whether or not to disconnect(close) from Mina session right after - * use. Can be used for both consumer and producer. + * Whether to disconnect(close) from Mina session right after use. Can + * be used for both consumer and producer. * * The option is a: <code>boolean</code> type. * @@ -895,8 +895,8 @@ public interface MinaEndpointBuilderFactory { return this; } /** - * Whether or not to disconnect(close) from Mina session right after - * use. Can be used for both consumer and producer. + * Whether to disconnect(close) from Mina session right after use. Can + * be used for both consumer and producer. * * The option will be converted to a <code>boolean</code> * type. @@ -1493,6 +1493,41 @@ public interface MinaEndpointBuilderFactory { return this; } /** + * If sync is enabled then this option dictates MinaConsumer if it + * should disconnect where there is no reply to send back. + * + * The option is a: <code>boolean</code> type. + * + * Default: true + * Group: advanced + * + * @param disconnectOnNoReply the value to set + * @return the dsl builder + */ + default AdvancedMinaEndpointProducerBuilder disconnectOnNoReply( + boolean disconnectOnNoReply) { + doSetProperty("disconnectOnNoReply", disconnectOnNoReply); + return this; + } + /** + * If sync is enabled then this option dictates MinaConsumer if it + * should disconnect where there is no reply to send back. + * + * The option will be converted to a <code>boolean</code> + * type. + * + * Default: true + * Group: advanced + * + * @param disconnectOnNoReply the value to set + * @return the dsl builder + */ + default AdvancedMinaEndpointProducerBuilder disconnectOnNoReply( + String disconnectOnNoReply) { + doSetProperty("disconnectOnNoReply", disconnectOnNoReply); + return this; + } + /** * Number of worker threads in the worker pool for TCP and UDP. * * The option is a: <code>int</code> type. @@ -1615,8 +1650,8 @@ public interface MinaEndpointBuilderFactory { return (AdvancedMinaEndpointBuilder) this; } /** - * Whether or not to disconnect(close) from Mina session right after - * use. Can be used for both consumer and producer. + * Whether to disconnect(close) from Mina session right after use. Can + * be used for both consumer and producer. * * The option is a: <code>boolean</code> type. * @@ -1631,8 +1666,8 @@ public interface MinaEndpointBuilderFactory { return this; } /** - * Whether or not to disconnect(close) from Mina session right after - * use. Can be used for both consumer and producer. + * Whether to disconnect(close) from Mina session right after use. Can + * be used for both consumer and producer. * * The option will be converted to a <code>boolean</code> * type. @@ -2108,6 +2143,41 @@ public interface MinaEndpointBuilderFactory { return (MinaEndpointBuilder) this; } /** + * If sync is enabled then this option dictates MinaConsumer if it + * should disconnect where there is no reply to send back. + * + * The option is a: <code>boolean</code> type. + * + * Default: true + * Group: advanced + * + * @param disconnectOnNoReply the value to set + * @return the dsl builder + */ + default AdvancedMinaEndpointBuilder disconnectOnNoReply( + boolean disconnectOnNoReply) { + doSetProperty("disconnectOnNoReply", disconnectOnNoReply); + return this; + } + /** + * If sync is enabled then this option dictates MinaConsumer if it + * should disconnect where there is no reply to send back. + * + * The option will be converted to a <code>boolean</code> + * type. + * + * Default: true + * Group: advanced + * + * @param disconnectOnNoReply the value to set + * @return the dsl builder + */ + default AdvancedMinaEndpointBuilder disconnectOnNoReply( + String disconnectOnNoReply) { + doSetProperty("disconnectOnNoReply", disconnectOnNoReply); + return this; + } + /** * Number of worker threads in the worker pool for TCP and UDP. * * The option is a: <code>int</code> type.