summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/thrifthelper
diff options
context:
space:
mode:
authorSimon Rettberg2015-09-09 14:25:31 +0200
committerSimon Rettberg2015-09-09 14:25:31 +0200
commit8e03d38f0c4d687162e8be1b9bbf660ed210d8f9 (patch)
treecfcd0ea0f2fc53a799e31c5ce8e68ef76c4ce6a9 /src/main/java/org/openslx/thrifthelper
parentmaster server rpc (diff)
downloadmaster-sync-shared-8e03d38f0c4d687162e8be1b9bbf660ed210d8f9.tar.gz
master-sync-shared-8e03d38f0c4d687162e8be1b9bbf660ed210d8f9.tar.xz
master-sync-shared-8e03d38f0c4d687162e8be1b9bbf660ed210d8f9.zip
VCache und thrift
Diffstat (limited to 'src/main/java/org/openslx/thrifthelper')
-rw-r--r--src/main/java/org/openslx/thrifthelper/ThriftHandler.java24
-rw-r--r--src/main/java/org/openslx/thrifthelper/ThriftManager.java28
2 files changed, 23 insertions, 29 deletions
diff --git a/src/main/java/org/openslx/thrifthelper/ThriftHandler.java b/src/main/java/org/openslx/thrifthelper/ThriftHandler.java
index 01ed0b0..760220a 100644
--- a/src/main/java/org/openslx/thrifthelper/ThriftHandler.java
+++ b/src/main/java/org/openslx/thrifthelper/ThriftHandler.java
@@ -60,25 +60,13 @@ class ThriftHandler<T extends TServiceClient> implements InvocationHandler
// first find the thrift methods
if ( !thriftMethods.contains( method.getName() ) ) {
- try {
- return method.invoke( getClient(), args );
- } catch ( InvocationTargetException e ) {
- Throwable cause = e.getCause();
- if ( cause == null ) {
- cause = e;
- }
- throw cause;
- }
+ throw new IllegalAccessException( "Cannot call this method on a proxied thrift client" );
}
T client = getClient();
try {
Throwable cause = null;
for ( int i = 1;; i++ ) {
- if ( client == null ) {
- LOGGER.debug( "Transport error - re-initialising ..." );
- client = getClient();
- }
if ( client != null ) {
try {
return method.invoke( client, args );
@@ -89,14 +77,19 @@ class ThriftHandler<T extends TServiceClient> implements InvocationHandler
}
freeClient( client );
client = null;
- if ( cause == null )
+ if ( cause == null ) {
cause = e;
+ }
}
}
// Call the error callback. As long as true is returned, keep retrying
if ( !errorCallback.thriftError( i, method.getName(), cause ) ) {
break;
}
+ if ( client == null ) {
+ client = getClient();
+ cause = null;
+ }
}
// Uh oh
@@ -126,8 +119,9 @@ class ThriftHandler<T extends TServiceClient> implements InvocationHandler
T client;
synchronized ( pool ) {
client = pool.poll();
- if ( client != null )
+ if ( client != null ) {
return client;
+ }
}
// Pool is closed, create new client
LOGGER.debug( "Creating new thrift client" );
diff --git a/src/main/java/org/openslx/thrifthelper/ThriftManager.java b/src/main/java/org/openslx/thrifthelper/ThriftManager.java
index c276034..7fc6aa7 100644
--- a/src/main/java/org/openslx/thrifthelper/ThriftManager.java
+++ b/src/main/java/org/openslx/thrifthelper/ThriftManager.java
@@ -5,6 +5,7 @@ import java.lang.reflect.Proxy;
import java.net.InetSocketAddress;
import java.net.Socket;
+import javax.net.SocketFactory;
import javax.net.ssl.SSLContext;
import org.apache.log4j.Logger;
@@ -193,23 +194,22 @@ public class ThriftManager<T>
{
try {
TSocket tsock;
- if ( ctx == null ) {
- tsock = new TSocket( host, port, timeout );
- tsock.open();
- } else {
- Socket socket = null;
- try {
+ Socket socket = null;
+ try {
+ if ( ctx == null ) {
+ socket = SocketFactory.getDefault().createSocket();
+ } else {
socket = ctx.getSocketFactory().createSocket();
- socket.setSoTimeout( timeout );
- socket.connect( new InetSocketAddress( host, port ), timeout );
- } catch ( IOException e ) {
- if ( socket != null ) {
- Util.safeClose( socket );
- }
- throw new TTransportException();
}
- tsock = new TSocket( socket );
+ socket.connect( new InetSocketAddress( host, port ), 4000 );
+ socket.setSoTimeout( timeout );
+ } catch ( IOException e ) {
+ if ( socket != null ) {
+ Util.safeClose( socket );
+ }
+ throw new TTransportException();
}
+ tsock = new TSocket( socket );
return new TBinaryProtocol( new TFramedTransport( tsock ) );
} catch ( TTransportException e ) {
LOGGER.error( "Could not open transport to thrift server at " + host + ":" + port );