Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
185 additions
and
137 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
payment/src/main/java/org/killbill/billing/payment/core/PaymentExecutors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright 2014-2015 Groupon, Inc | ||
* Copyright 2014-2015 The Billing Project, LLC | ||
* | ||
* The Billing Project 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.killbill.billing.payment.core; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.ThreadFactory; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.killbill.billing.util.config.PaymentConfig; | ||
import org.killbill.commons.concurrent.Executors; | ||
import org.killbill.commons.concurrent.WithProfilingThreadPoolExecutor; | ||
|
||
public class PaymentExecutors { | ||
|
||
private static final long TIMEOUT_EXECUTOR_SEC = 3L; | ||
|
||
private static final String PLUGIN_THREAD_PREFIX = "Plugin-th-"; | ||
private static final String PAYMENT_PLUGIN_TH_GROUP_NAME = "pay-plugin-grp"; | ||
|
||
public static final String JANITOR_EXECUTOR_NAMED = "JanitorExecutor"; | ||
public static final String PLUGIN_EXECUTOR_NAMED = "PluginExecutor"; | ||
|
||
private final PaymentConfig paymentConfig; | ||
|
||
private volatile ExecutorService pluginExecutorService; | ||
private volatile ScheduledExecutorService janitorExecutorService; | ||
|
||
@Inject | ||
public PaymentExecutors(PaymentConfig paymentConfig) { | ||
this.paymentConfig = paymentConfig; | ||
|
||
} | ||
|
||
public void initialize() { | ||
this.pluginExecutorService = createPluginExecutorService(); | ||
this.janitorExecutorService = createJanitorExecutorService(); | ||
} | ||
|
||
|
||
public void stop() throws InterruptedException { | ||
pluginExecutorService.shutdownNow(); | ||
janitorExecutorService.shutdownNow(); | ||
|
||
pluginExecutorService.awaitTermination(TIMEOUT_EXECUTOR_SEC, TimeUnit.SECONDS); | ||
pluginExecutorService = null; | ||
|
||
janitorExecutorService.awaitTermination(TIMEOUT_EXECUTOR_SEC, TimeUnit.SECONDS); | ||
janitorExecutorService = null; | ||
} | ||
|
||
public ExecutorService getPluginExecutorService() { | ||
return pluginExecutorService; | ||
} | ||
|
||
public ScheduledExecutorService getJanitorExecutorService() { | ||
return janitorExecutorService; | ||
} | ||
|
||
private ExecutorService createPluginExecutorService() { | ||
return new WithProfilingThreadPoolExecutor(paymentConfig.getPaymentPluginThreadNb(), | ||
paymentConfig.getPaymentPluginThreadNb(), | ||
0L, | ||
TimeUnit.MILLISECONDS, | ||
new LinkedBlockingQueue<Runnable>(), | ||
new ThreadFactory() { | ||
|
||
@Override | ||
public Thread newThread(final Runnable r) { | ||
final Thread th = new Thread(new ThreadGroup(PAYMENT_PLUGIN_TH_GROUP_NAME), r); | ||
th.setName(PLUGIN_THREAD_PREFIX + th.getId()); | ||
return th; | ||
} | ||
}); | ||
|
||
} | ||
|
||
private ScheduledExecutorService createJanitorExecutorService() { | ||
return Executors.newSingleThreadScheduledExecutor("PaymentJanitor"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.