Skip to content

Commit

Permalink
Removed throwing of TransportClientPoolExhaustedException
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Aug 2, 2023
1 parent ec8bf3f commit c514147
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ protected KuraResponseMessage sendInternal(@NotNull KuraRequestMessage requestMe
* @throws TransportClientGetException If getting the {@link TransportFacade} causes an {@link Exception}.
* @since 1.0.0
*/
protected TransportFacade<?, ?, ?, ?> borrowClient(KuraRequestMessage kuraRequestMessage) throws TransportClientGetException, TransportClientPoolExhaustedException {
protected TransportFacade<?, ?, ?, ?> borrowClient(KuraRequestMessage kuraRequestMessage) throws TransportException {
String serverIp = null;
try {
serverIp = KapuaSecurityUtils.doPrivileged(() -> {
Expand All @@ -224,7 +224,7 @@ protected KuraResponseMessage sendInternal(@NotNull KuraRequestMessage requestMe
configParameters.put("serverAddress", serverIp);

return TRANSPORT_CLIENT_FACTORY.getFacade(configParameters);
} catch (TransportClientGetException | TransportClientPoolExhaustedException tce) {
} catch (TransportException tce) {
throw tce;
} catch (Exception e) {
throw new TransportClientGetException(e, serverIp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.kapua.model.KapuaObjectFactory;
import org.eclipse.kapua.transport.exception.TransportClientGetException;
import org.eclipse.kapua.transport.exception.TransportClientPoolExhaustedException;
import org.eclipse.kapua.transport.exception.TransportException;
import org.eclipse.kapua.transport.message.TransportChannel;
import org.eclipse.kapua.transport.message.TransportMessage;
import org.eclipse.kapua.transport.message.TransportPayload;
Expand Down Expand Up @@ -48,7 +49,7 @@ public interface TransportClientFactory<C extends TransportChannel, P extends Tr
* @throws TransportClientGetException If error occurs when getting the {@link TransportFacade}.
* @since 1.0.0
*/
T getFacade(Map<String, Object> configParameters) throws TransportClientGetException, TransportClientPoolExhaustedException;
T getFacade(Map<String, Object> configParameters) throws TransportException;

/**
* Gets an instance of the {@link TransportClientConnectOptions} implementing class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,14 @@ public String getRequestMessage() {
public String getServerIp() {
return serverIp;
}

/**
* Gets the {@link Throwable#getMessage()} if provided.
*
* @return The {@link Throwable#getMessage()} if provided.
* @since 2.0.0
*/
public String getCauseMessage() {
return causeMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.eclipse.kapua.locator.KapuaProvider;
import org.eclipse.kapua.transport.TransportClientFactory;
import org.eclipse.kapua.transport.exception.TransportClientGetException;
import org.eclipse.kapua.transport.exception.TransportClientPoolExhaustedException;
import org.eclipse.kapua.transport.exception.TransportException;
import org.eclipse.kapua.transport.message.mqtt.MqttMessage;
import org.eclipse.kapua.transport.message.mqtt.MqttPayload;
import org.eclipse.kapua.transport.message.mqtt.MqttTopic;
Expand All @@ -34,7 +34,7 @@
public class MqttClientFactoryImpl implements TransportClientFactory<MqttTopic, MqttPayload, MqttMessage, MqttMessage, MqttFacade, MqttClientConnectionOptions> {

@Override
public MqttFacade getFacade(Map<String, Object> configParameters) throws TransportClientGetException, TransportClientPoolExhaustedException {
public MqttFacade getFacade(Map<String, Object> configParameters) throws TransportException {
String host = (String) configParameters.get("serverAddress");

if (Strings.isNullOrEmpty(host)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.kapua.transport.TransportFacade;
import org.eclipse.kapua.transport.exception.TransportClientGetException;
import org.eclipse.kapua.transport.exception.TransportClientPoolExhaustedException;
import org.eclipse.kapua.transport.exception.TransportException;
import org.eclipse.kapua.transport.exception.TransportSendException;
import org.eclipse.kapua.transport.exception.TransportTimeoutException;
import org.eclipse.kapua.transport.message.mqtt.MqttMessage;
Expand All @@ -30,7 +31,6 @@
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

/**
* Implementation of {@link TransportFacade} API for MQTT transport facade.
Expand Down Expand Up @@ -60,15 +60,14 @@ public class MqttFacade implements TransportFacade<MqttTopic, MqttPayload, MqttM
* @throws TransportClientGetException When {@link MqttClient} is not available for the given node URI.
* @since 1.0.0
*/
public MqttFacade(@NotNull String nodeUri) throws TransportClientGetException, TransportClientPoolExhaustedException {
public MqttFacade(@NotNull String nodeUri) throws TransportException {
this.nodeUri = nodeUri;

//
// Get the client form the pool
Long maxBorrowTimeout = null;
try {
MqttClientPool perBrokerMqttClientPool = MqttClientPool.getInstance(nodeUri);
maxBorrowTimeout = perBrokerMqttClientPool.getMaxWaitMillis();
Long maxBorrowTimeout = maxBorrowTimeout = perBrokerMqttClientPool.getMaxWaitMillis();

long borrowTimerStart = System.nanoTime();
borrowedClient = perBrokerMqttClientPool.borrowObject();
Expand All @@ -79,8 +78,6 @@ public MqttFacade(@NotNull String nodeUri) throws TransportClientGetException, T
LOG.debug("MqttClient borrowed for BrokerNode {} in {}ns. Max time waited currently is {}ms with a {}ms timeout",
nodeUri, (borrowTimerStop - borrowTimerStart), perBrokerMqttClientPool.getMaxBorrowWaitTimeMillis(), maxBorrowTimeout);
}
} catch (NoSuchElementException nsee) {
throw new TransportClientPoolExhaustedException(nsee, nodeUri, maxBorrowTimeout);
} catch (Exception e) {
throw new TransportClientGetException(e, nodeUri);
}
Expand Down

0 comments on commit c514147

Please sign in to comment.