示例#1
0
 public SocketChannel getClientChannel(final boolean noTearDown) throws IOException {
   final List<String> listeners = m_config.getListenerAddresses();
   final Random r = new Random();
   final String listener = listeners.get(r.nextInt(listeners.size()));
   byte[] hashedPassword = ConnectionUtil.getHashedPassword(m_password);
   HostAndPort hNp = HostAndPort.fromString(listener);
   int port = Constants.DEFAULT_PORT;
   if (hNp.hasPort()) {
     port = hNp.getPort();
   }
   final SocketChannel channel =
       (SocketChannel)
           ConnectionUtil.getAuthenticatedConnection(
               hNp.getHostText(),
               m_username,
               hashedPassword,
               port,
               null,
               ClientAuthHashScheme.getByUnencodedLength(hashedPassword.length))[0];
   channel.configureBlocking(true);
   if (!noTearDown) {
     synchronized (m_clientChannels) {
       m_clientChannels.add(channel);
     }
   }
   return channel;
 }