com.alipay.remoting
Interface ConnectionManager

All Superinterfaces:
Scannable
All Known Implementing Classes:
DefaultConnectionManager

public interface ConnectionManager
extends Scannable

Connection manager of connection pool


Method Summary
 void add(Connection connection)
          Add a connection to ConnectionPool.
 void add(Connection connection, String poolKey)
          Add a connection to ConnectionPool with the specified poolKey.
 void check(Connection connection)
          check a connection whether available, if not, throw RemotingException
 int count(String poolKey)
          Get the number of Connection in ConnectionPool with the specified pool key
 Connection create(String address, int connectTimeout)
          Create a connection using specified String address.
 Connection create(String ip, int port, int connectTimeout)
          Create a connection using specified ip and port.
 Connection create(Url url)
          Create a connection using specified Url.
 void createConnectionAndHealIfNeed(Url url)
          This method can create connection pool with connections initialized and check the number of connections.
 Connection get(String poolKey)
          Get a connection from ConnectionPool with the specified poolKey.
 Map<String,List<Connection>> getAll()
          Get all connections of all poolKey.
 List<Connection> getAll(String poolKey)
          Get all connections from ConnectionPool with the specified poolKey.
 Connection getAndCreateIfAbsent(Url url)
          Get a connection using Url, if null then create and add into ConnectionPool.
 void init()
          init
 void remove(Connection connection)
          Remove a Connection from all ConnectionPool with the poolKeys in Connection, and close it.
 void remove(Connection connection, String poolKey)
          Remove and close a Connection from ConnectionPool with the specified poolKey.
 void remove(String poolKey)
          Remove and close all connections from ConnectionPool with the specified poolKey.
 void removeAll()
          Remove and close all connections from all ConnectionPool.
 
Methods inherited from interface com.alipay.remoting.Scannable
scan
 

Method Detail

init

void init()
init


add

void add(Connection connection)
Add a connection to ConnectionPool. If it contains multiple pool keys, this connection will be added to multiple ConnectionPool too.

Parameters:
connection - an available connection, you should check(Connection) this connection before add

add

void add(Connection connection,
         String poolKey)
Add a connection to ConnectionPool with the specified poolKey.

Parameters:
connection - an available connection, you should check(Connection) this connection before add
poolKey - unique key of a ConnectionPool

get

Connection get(String poolKey)
Get a connection from ConnectionPool with the specified poolKey.

Parameters:
poolKey - unique key of a ConnectionPool
Returns:
a Connection selected by ConnectionSelectStrategy
or return null if there is no ConnectionPool mapping with poolKey
or return null if there is no Connection in ConnectionPool.

getAll

List<Connection> getAll(String poolKey)
Get all connections from ConnectionPool with the specified poolKey.

Parameters:
poolKey - unique key of a ConnectionPool
Returns:
a list of Connection
or return an empty list if there is no ConnectionPool mapping with poolKey.

getAll

Map<String,List<Connection>> getAll()
Get all connections of all poolKey.

Returns:
a map with poolKey as key and a list of connections in ConnectionPool as value

remove

void remove(Connection connection)
Remove a Connection from all ConnectionPool with the poolKeys in Connection, and close it.

Parameters:
connection -

remove

void remove(Connection connection,
            String poolKey)
Remove and close a Connection from ConnectionPool with the specified poolKey.

Parameters:
connection -
poolKey - unique key of a ConnectionPool

remove

void remove(String poolKey)
Remove and close all connections from ConnectionPool with the specified poolKey.

Parameters:
poolKey - unique key of a ConnectionPool

removeAll

void removeAll()
Remove and close all connections from all ConnectionPool.


check

void check(Connection connection)
           throws RemotingException
check a connection whether available, if not, throw RemotingException

Parameters:
connection -
Throws:
RemotingException

count

int count(String poolKey)
Get the number of Connection in ConnectionPool with the specified pool key

Parameters:
poolKey - unique key of a ConnectionPool
Returns:

getAndCreateIfAbsent

Connection getAndCreateIfAbsent(Url url)
                                throws InterruptedException,
                                       RemotingException
Get a connection using Url, if null then create and add into ConnectionPool. The connection number of ConnectionPool is decided by Url.getConnNum()

Parameters:
url - Url contains connect infos.
Returns:
the created Connection.
Throws:
InterruptedException - if interrupted
RemotingException - if create failed.

createConnectionAndHealIfNeed

void createConnectionAndHealIfNeed(Url url)
                                   throws InterruptedException,
                                          RemotingException
This method can create connection pool with connections initialized and check the number of connections. The connection number of ConnectionPool is decided by Url.getConnNum(). Each time call this method, will check the number of connection, if not enough, this will do the healing logic additionally.

Parameters:
url -
Throws:
InterruptedException
RemotingException

create

Connection create(Url url)
                  throws RemotingException
Create a connection using specified Url.

Parameters:
url - Url contains connect infos.
Returns:
Throws:
RemotingException

create

Connection create(String address,
                  int connectTimeout)
                  throws RemotingException
Create a connection using specified String address.

Parameters:
address - a String address, e.g. 127.0.0.1:1111
connectTimeout - an int connect timeout value
Returns:
the created Connection
Throws:
RemotingException - if create failed

create

Connection create(String ip,
                  int port,
                  int connectTimeout)
                  throws RemotingException
Create a connection using specified ip and port.

Parameters:
ip - connect ip, e.g. 127.0.0.1
port - connect port, e.g. 1111
connectTimeout - an int connect timeout value
Returns:
the created Connection
Throws:
RemotingException


Copyright © 2018. All rights reserved.