[ 
https://issues.apache.org/jira/browse/TUBEMQ-66?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Guo Jiwei closed TUBEMQ-66.
---------------------------
    Resolution: Won't Fix

> 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
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> 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)

Reply via email to