You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tubemq.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2020/04/13 15:13:00 UTC
[jira] [Updated] (TUBEMQ-66) TubeSingleSessionFactory shutdown bug
[ https://issues.apache.org/jira/browse/TUBEMQ-66?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
ASF GitHub Bot updated TUBEMQ-66:
---------------------------------
Labels: pull-request-available (was: )
> TubeSingleSessionFactory shutdown bug
> -------------------------------------
>
> Key: TUBEMQ-66
> URL: https://issues.apache.org/jira/browse/TUBEMQ-66
> Project: Apache TubeMQ
> Issue Type: Bug
> Reporter: Guo Jiwei
> Assignee: Guo Jiwei
> Priority: Normal
> Labels: pull-request-available
>
> 1. TubeSingleSessionFactory could not shutdown
> due to we increase referenceCounter after first constructor method:
> {code:java}
> public TubeSingleSessionFactory(final TubeClientConfig tubeClientConfig) throws TubeClientException {
> if (referenceCounter.incrementAndGet() == 1) {
> RpcConfig config = TubeClientConfigUtils.getRpcConfigByClientConfig(tubeClientConfig, true);
> clientFactory.configure(config);
> //#1
> referenceCounter.incrementAndGet();
> baseSessionFactory = new TubeBaseSessionFactory(clientFactory, tubeClientConfig);
> }
> }
> {code}
> {code:java}
> public void shutdown() throws TubeClientException {
> if (referenceCounter.decrementAndGet() > 0) {
> return;
> }
> baseSessionFactory.shutdown();
> clientFactory.shutdown();
> }
> {code}
> We can fix it only remove #1, but I think this is not the best implementation for TubeSingleSessionFactory. How about do it like below :
> {code:java}
> private static final AtomicBoolean isStarted = new AtomicBoolean(false);
> private static TubeBaseSessionFactory baseSessionFactory;
> public TubeSingleSessionFactory(final TubeClientConfig tubeClientConfig) throws TubeClientException {
> if (isStarted.compareAndSet(false, true)) {
> RpcConfig config = TubeClientConfigUtils.getRpcConfigByClientConfig(tubeClientConfig, true);
> clientFactory.configure(config);
> baseSessionFactory = new TubeBaseSessionFactory(clientFactory, tubeClientConfig);
> }
> }
> @Override
> public void shutdown() throws TubeClientException {
> if (isStarted.compareAndSet(true, false)) {
> baseSessionFactory.shutdown();
> clientFactory.shutdown();
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)