diff options
author | Simon Rettberg | 2015-07-08 17:22:06 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-07-08 17:22:06 +0200 |
commit | fd7a500e25cdad1f56cd3514e6e6c99011150635 (patch) | |
tree | 720ca2819d6d23d6074e18a05fe61b115fa45e9c /src/main/java/org/openslx/thrifthelper/ThriftHandler.java | |
parent | Thrift api (diff) | |
download | master-sync-shared-fd7a500e25cdad1f56cd3514e6e6c99011150635.tar.gz master-sync-shared-fd7a500e25cdad1f56cd3514e6e6c99011150635.tar.xz master-sync-shared-fd7a500e25cdad1f56cd3514e6e6c99011150635.zip |
Fix behavior of thrift proxy when getting a new client fails by throwing an exception instead of returning null
Diffstat (limited to 'src/main/java/org/openslx/thrifthelper/ThriftHandler.java')
-rw-r--r-- | src/main/java/org/openslx/thrifthelper/ThriftHandler.java | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/main/java/org/openslx/thrifthelper/ThriftHandler.java b/src/main/java/org/openslx/thrifthelper/ThriftHandler.java index c9a88cc..121d34b 100644 --- a/src/main/java/org/openslx/thrifthelper/ThriftHandler.java +++ b/src/main/java/org/openslx/thrifthelper/ThriftHandler.java @@ -68,35 +68,36 @@ class ThriftHandler<T extends Object> implements InvocationHandler throw cause; } } - LOGGER.debug( "Proxying '" + method.getName() + "'" ); T client = getClient( false ); Throwable cause = null; - for ( int i = 1; ; i++ ) { + for ( int i = 1;; i++ ) { if ( client == null ) { LOGGER.debug( "Transport error - re-initialising ..." ); client = getClient( true ); - if ( client == null ) - continue; } - try { - return method.invoke( client, args ); - } catch ( InvocationTargetException e ) { - cause = e.getCause(); - if ( cause != null && ! ( cause instanceof TTransportException ) ) - throw cause; - client = null; - if ( cause == null ) - cause = e; + if ( client != null ) { + try { + return method.invoke( client, args ); + } catch ( InvocationTargetException e ) { + cause = e.getCause(); + if ( cause != null && ! ( cause instanceof TTransportException ) ) + throw cause; + client = null; + if ( cause == null ) + cause = e; + } } - if ( !callback.error( i, method.getName(), cause ) ) + // Call the error callback. As long as true is returned, keep retrying + if ( !callback.error( i, method.getName(), cause ) ) { break; + } } // Uh oh if ( cause != null ) throw cause; - return null; + throw new TTransportException( "Could not connect" ); } private T getClient( boolean forceNew ) |