[ 
https://issues.apache.org/jira/browse/ZOOKEEPER-2842?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16116208#comment-16116208
 ] 

ASF GitHub Bot commented on ZOOKEEPER-2842:
-------------------------------------------

Github user maoling commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/308#discussion_r131591446
  
    --- Diff: 
src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java ---
    @@ -233,25 +233,25 @@ public QuorumCnxManager(QuorumPeer self) {
             listener = new Listener();
             listener.setName("QuorumPeerListener");
         }
    -
    +    
         /**
    -     * Invokes initiateConnection for testing purposes
    -     * 
    +     * establish Connection with sid using its electionAddr.
          * @param sid
    +     * @param sock
    +     * @throws IOException
          */
    -    public void testInitiateConnection(long sid) throws Exception {
    -        LOG.debug("Opening channel to server " + sid);
    -        Socket sock = new Socket();
    +   public void establishConnection(Long sid, Socket sock) throws 
IOException {
    +           LOG.debug("Opening channel to server " + sid);
             setSockOpts(sock);
             sock.connect(self.getVotingView().get(sid).electionAddr, cnxTO);
    -        initiateConnection(sock, sid);
    -    }
    +        LOG.debug("Connected to server " + sid);
    +   }
         
         /**
          * If this server has initiated the connection, then it gives up on the
          * connection if it loses challenge. Otherwise, it keeps the 
connection.
          */
    -    public boolean initiateConnection(Socket sock, Long sid) {
    +    public boolean initiateConnection(Long sid, Socket sock) {
    --- End diff --
    
    I think put the mutable variables after fixed variables may be better in 
the parameter list;
    such as :
    `private void myMethod(int a, Integer b, String s1, StringBuilder s2){}`


> optimize the finish() of Send/RecvWorker in QuorumCnxManager and remove 
> testInitiateConnection() and formates some codes
> ------------------------------------------------------------------------------------------------------------------------
>
>                 Key: ZOOKEEPER-2842
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2842
>             Project: ZooKeeper
>          Issue Type: Improvement
>          Components: quorum
>            Reporter: maoling
>            Priority: Trivial
>
> 1.the finish() of Send/RecvWorker in QuorumCnxManager changes to 
> double-checked lock style 
> [https://en.wikipedia.org/wiki/Double-checked_locking]
> ,a trivial code changes implement a smaller granularity lock to have a better 
> perfermance in too fierce multithread situation.
> 2.testInitiateConnection() is redundant test function which is only used in 
> TestCase,so I refactor it.
> 3.some codes don't abide to Java Programme Specification ,so I lift a finger 
> to format them



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to