diff --git a/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java b/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
index ab64c28..b221108 100644
--- a/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
+++ b/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
@@ -24,11 +24,13 @@ import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.annotation.Nullable;
import javax.inject.Inject;
+import org.skife.config.TimeSpan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -90,6 +92,7 @@ public class PaymentProcessor extends ProcessorBase {
private static final Logger log = LoggerFactory.getLogger(PaymentProcessor.class);
+
@Inject
public PaymentProcessor(final OSGIServiceRegistration<PaymentPluginApi> pluginRegistry,
final PaymentMethodProcessor paymentMethodProcessor,
@@ -113,8 +116,9 @@ public class PaymentProcessor extends ProcessorBase {
this.autoPayoffRetryService = autoPayoffRetryService;
this.clock = clock;
this.paymentConfig = paymentConfig;
- this.paymentPluginDispatcher = new PluginDispatcher<Payment>(paymentConfig.getPaymentTimeoutSeconds(), executor);
- this.voidPluginDispatcher = new PluginDispatcher<Void>(paymentConfig.getPaymentTimeoutSeconds(), executor);
+ final long paymentPluginTimeoutSec = TimeUnit.SECONDS.convert(paymentConfig.getPaymentPluginTimeout().getPeriod(), paymentConfig.getPaymentPluginTimeout().getUnit());
+ this.paymentPluginDispatcher = new PluginDispatcher<Payment>(paymentPluginTimeoutSec, executor);
+ this.voidPluginDispatcher = new PluginDispatcher<Void>(paymentPluginTimeoutSec, executor);
}
public Payment getPayment(final UUID paymentId, final boolean withPluginInfo, final InternalTenantContext context) throws PaymentApiException {
@@ -278,6 +282,13 @@ public class PaymentProcessor extends ProcessorBase {
// swallowing exception
return null;
}
+ } catch (RuntimeException e) {
+ log.error("Failure when dispatching payment for invoice " + invoiceId , e);
+ if (isInstantPayment) {
+ throw new PaymentApiException(ErrorCode.PAYMENT_INTERNAL_ERROR, invoiceId);
+ } else {
+ return null;
+ }
}
}
diff --git a/payment/src/main/java/com/ning/billing/payment/glue/PaymentModule.java b/payment/src/main/java/com/ning/billing/payment/glue/PaymentModule.java
index 56da5d4..b13af26 100644
--- a/payment/src/main/java/com/ning/billing/payment/glue/PaymentModule.java
+++ b/payment/src/main/java/com/ning/billing/payment/glue/PaymentModule.java
@@ -51,7 +51,6 @@ import com.google.inject.name.Names;
public class PaymentModule extends AbstractModule {
- private static final int PLUGIN_NB_THREADS = 10;
private static final String PLUGIN_THREAD_PREFIX = "Plugin-th-";
public static final String PLUGIN_EXECUTOR_NAMED = "PluginExecutor";
@@ -78,8 +77,8 @@ public class PaymentModule extends AbstractModule {
bind(AutoPayRetryServiceScheduler.class).asEagerSingleton();
}
- protected void installProcessors() {
- final ExecutorService pluginExecutorService = Executors.newFixedThreadPool(PLUGIN_NB_THREADS, new ThreadFactory() {
+ protected void installProcessors(final PaymentConfig paymentConfig) {
+ final ExecutorService pluginExecutorService = Executors.newFixedThreadPool(paymentConfig.getPaymentPluginThreadNb(), new ThreadFactory() {
@Override
public Thread newThread(final Runnable r) {
@@ -109,7 +108,7 @@ public class PaymentModule extends AbstractModule {
bind(PaymentService.class).to(DefaultPaymentService.class).asEagerSingleton();
installPaymentProviderPlugins(paymentConfig);
installPaymentDao();
- installProcessors();
+ installProcessors(paymentConfig);
installRetryEngines();
}
}
diff --git a/util/src/main/java/com/ning/billing/util/config/PaymentConfig.java b/util/src/main/java/com/ning/billing/util/config/PaymentConfig.java
index 47549a1..8344cbb 100644
--- a/util/src/main/java/com/ning/billing/util/config/PaymentConfig.java
+++ b/util/src/main/java/com/ning/billing/util/config/PaymentConfig.java
@@ -21,6 +21,7 @@ import java.util.List;
import org.skife.config.Config;
import org.skife.config.Default;
import org.skife.config.Description;
+import org.skife.config.TimeSpan;
public interface PaymentConfig extends KillbillConfig {
@@ -48,10 +49,15 @@ public interface PaymentConfig extends KillbillConfig {
@Description("Maximum number of retries for failed payments")
public int getPluginFailureRetryMaxAttempts();
- @Config("killbill.payment.timeout.seconds")
- @Default("90")
+ @Config("killbill.payment.plugin.timeout")
+ @Default("90s")
@Description("Timeout for each payment attempt")
- public int getPaymentTimeoutSeconds();
+ public TimeSpan getPaymentPluginTimeout();
+
+ @Config("killbill.payment.plugin.threads.nb")
+ @Default("10")
+ @Description("Number of threads for plugin executor dispatcher")
+ public int getPaymentPluginThreadNb();
@Config("killbill.payment.off")
@Default("false")