com.baidu.driver4j.bns
类 BNSQueryAgentProxy

java.lang.Object
  继承者 com.baidu.driver4j.bns.BNSQueryAgentProxy
所有已实现的接口:
InstanceQuery

public class BNSQueryAgentProxy
extends Object
implements InstanceQuery

BNS query proxy which query from BNS agent supports.

从以下版本开始:
1.0.0
作者:
xiemalin

方法摘要
protected  byte[] doRequest(String host, int port, byte[] requestBodyBytes, short requestMsgType, short expectResponseType, int timeoutMs)
          Communicate with target host
 List<Instance> getAuthInstanceByService(String serviceName)
          Get the Instances that are configured in Auth Config on noah.baidu.com This functionality is used to ease the managing of the so called white ip list.
 List<Instance> getAuthInstanceByService(String serviceName, int timeoutMs)
          Get the Instances that are configured in Auth Config on noah.baidu.com This functionality is used to ease the managing of the so called white ip list.
protected  byte[] getBNSMsgBytes(byte[] requestBodyBytes, short requestMsgType)
           
 BNSQueryProxy getBnsQueryProxy()
          Gets the bns query proxy.
static String getDefaultGateway()
           
 List<Instance> getInstanceByService(String serviceName)
          Get the instances list of given serviceName.
 List<Instance> getInstanceByService(String serviceName, int timeoutMs)
          Get the instances list of given serviceName.
 Instance getInstanceByService(String serviceName, SelectionStrategy strategy)
          Get only one instance by SelectionStrategy.
 Instance getInstanceByService(String serviceName, SelectionStrategy strategy, int timeout)
          Get only one instance by SelectionStrategy.
static String getLocalNamedAddress()
           
 Service getService(String serviceName)
          Get the Service object by noah service name.
 Service getService(String serviceName, int timeoutMs)
          Get the Service object first it will query from local agent then try to query from remote agent, at last query from HTTP API
static BNSQueryAgentProxy proxy()
           
static BNSQueryAgentProxy proxy(BNSQueryProxy proxy)
           
static BNSQueryAgentProxy proxy(String bnsServiceUrl)
           
 List<Instance> queryInstances(String serviceName)
           
protected  byte[] readBNSMsg(InputStream is, short expectResponseType)
           
protected  Instance selectOneByStrategy(List<Instance> instances, SelectionStrategy strategy)
          To select only one instance by SelectionStrategy. or return null if a empty instances list.
 void setConnectTimeout(int connectTimeout)
          setter method for property connectTimeout
 void setReadTimeout(int readTimeout)
          setter method for property readTimeout
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

方法详细信息

proxy

public static BNSQueryAgentProxy proxy()

proxy

public static BNSQueryAgentProxy proxy(String bnsServiceUrl)

proxy

public static BNSQueryAgentProxy proxy(BNSQueryProxy proxy)

setConnectTimeout

public void setConnectTimeout(int connectTimeout)
setter method for property connectTimeout

参数:
connectTimeout - the connectTimeout to set

setReadTimeout

public void setReadTimeout(int readTimeout)
setter method for property readTimeout

参数:
readTimeout - the readTimeout to set

getInstanceByService

public Instance getInstanceByService(String serviceName,
                                     SelectionStrategy strategy)
                              throws BNSException
Get only one instance by SelectionStrategy.

参数:
serviceName - service name
strategy - SelectionStrategy.
返回:
Instance object
抛出:
BNSException - in case of access BNS server failed

getInstanceByService

public Instance getInstanceByService(String serviceName,
                                     SelectionStrategy strategy,
                                     int timeout)
                              throws BNSException
Get only one instance by SelectionStrategy.

参数:
serviceName - service name
strategy - SelectionStrategy.
timeout - time out on reading
返回:
Instance object
抛出:
BNSException - in case of access BNS server failed

selectOneByStrategy

protected Instance selectOneByStrategy(List<Instance> instances,
                                       SelectionStrategy strategy)
To select only one instance by SelectionStrategy. or return null if a empty instances list.

参数:
instances - target instance list
strategy - SelectionStrategy instance
返回:
Instance object

getInstanceByService

public List<Instance> getInstanceByService(String serviceName)
                                    throws BNSException
Get the instances list of given serviceName. This function will throws BNSException with several kind of error code. Check BNSException.errorToString for more information.
You shold take BNS_SERVICE_BEYOND_THRESHOLD exceptin seriously, In many times, just use the previous result.

参数:
serviceName -
返回:
List instances list of the given serviceName
抛出:
BNSException - in case of access BNS server failed
另请参见:
getInstanceByService(String, int)

getInstanceByService

public List<Instance> getInstanceByService(String serviceName,
                                           int timeoutMs)
                                    throws BNSException
Get the instances list of given serviceName.
first it will query from local agent then try to query from remote agent, at last query from HTTP API This function will throws BNSException with several kind of error code. Check BNSException.errorToString for more information.
You should take BNS_SERVICE_BEYOND_THRESHOLD exception seriously, In many times, just use the previous result.

参数:
serviceName -
timeoutMs - minimum is 500ms
返回:
List instances list of the given serviceName
抛出:
BNSException - in case of access BNS server failed

getAuthInstanceByService

public List<Instance> getAuthInstanceByService(String serviceName)
                                        throws BNSException
Get the Instances that are configured in Auth Config on noah.baidu.com This functionality is used to ease the managing of the so called white ip list. For example, if your service name is "test.noah.all", you want "web.noah.all" and "monitor.noah.all" can access your service. Then you can set in ServiceUnit page of test.noah.all on noah.baidu.com. After that you call this function with serviceName = test.noah.all you will get all the machines that belong to those two services you have configured.
This function will throws BNSException with several kind of error code. Check BNSException.errorToString for more information.
You shold take BNS_SERVICE_BEYOND_THRESHOLD exceptin seriously, In many times, just use the previous result. first it will query from local agent then try to query from remote agent

参数:
serviceName - , usually your service name
返回:
All Instances belongs to the services that are configured on web
抛出:
BNSException - when error occurs.
另请参见:
getAuthInstanceByService(String, int)

getAuthInstanceByService

public List<Instance> getAuthInstanceByService(String serviceName,
                                               int timeoutMs)
                                        throws BNSException
Get the Instances that are configured in Auth Config on noah.baidu.com This functionality is used to ease the managing of the so called white ip list. For example, if your service name is "test.noah.all", you want "web.noah.all" and "monitor.noah.all" can access your service. Then you can set in ServiceUnit page of test.noah.all on noah.baidu.com. After that you call this function with serviceName = test.noah.all you will get all the machines that belong to those two services you have configured.
This function will throws BNSException with several kind of error code. Check BNSException.errorToString for more information.
You should take BNS_SERVICE_BEYOND_THRESHOLD exception seriously, In many times, just use the previous result.

参数:
serviceName - , usually your service name
timeoutMs - in ms minimum is 500ms
返回:
All Instances belongs to the services that are configured on web
抛出:
BNSException - when error occurs.

getService

public Service getService(String serviceName)
Get the Service object by noah service name.

参数:
serviceName - serivce name
timeoutMs - minimum is 500ms
返回:
Service instance
另请参见:
getService(String, int)

getService

public Service getService(String serviceName,
                          int timeoutMs)
Get the Service object first it will query from local agent then try to query from remote agent, at last query from HTTP API

参数:
serviceName - serivce name
timeoutMs - minimum is 500ms
返回:
Service instance

doRequest

protected byte[] doRequest(String host,
                           int port,
                           byte[] requestBodyBytes,
                           short requestMsgType,
                           short expectResponseType,
                           int timeoutMs)
                    throws BNSException
Communicate with target host

参数:
host - host name
port - port number
requestBodyBytes - request bytes
requestMsgType - request type
expectResponseType - response type
timeoutMs - read time out
返回:
byte[] response content
抛出:
BNSException - in case of access BNS service failed

getBNSMsgBytes

protected byte[] getBNSMsgBytes(byte[] requestBodyBytes,
                                short requestMsgType)
                         throws IOException
抛出:
IOException

readBNSMsg

protected byte[] readBNSMsg(InputStream is,
                            short expectResponseType)
                     throws IOException
抛出:
IOException

getLocalNamedAddress

public static String getLocalNamedAddress()

getDefaultGateway

public static String getDefaultGateway()

queryInstances

public List<Instance> queryInstances(String serviceName)
                              throws BNSException
指定者:
接口 InstanceQuery 中的 queryInstances
抛出:
BNSException

getBnsQueryProxy

public BNSQueryProxy getBnsQueryProxy()
Gets the bns query proxy.

返回:
the bns query proxy


Copyright © 2016. All rights reserved.