本文整理汇总了Java中org.apache.http.util.Asserts类的典型用法代码示例。如果您正苦于以下问题:Java Asserts类的具体用法?Java Asserts怎么用?Java Asserts使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Asserts类属于org.apache.http.util包,在下文中一共展示了Asserts类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lease
import org.apache.http.util.Asserts; //导入依赖的package包/类
/**
* {@inheritDoc}
* <p/>
* Please note that this class does not maintain its own pool of execution
* {@link Thread}s. Therefore, one <b>must</b> call {@link Future#get()}
* or {@link Future#get(long, TimeUnit)} method on the {@link Future}
* returned by this method in order for the lease operation to complete.
*/
public Future<E> lease(final T route, final Object state, final FutureCallback<E> callback) {
Args.notNull(route, "Route");
Asserts.check(!this.isShutDown, "Connection pool shut down");
return new PoolEntryFuture<E>(this.lock, callback) {
@Override
public E getPoolEntry(
final long timeout,
final TimeUnit tunit)
throws InterruptedException, TimeoutException, IOException {
final E entry = getPoolEntryBlocking(route, state, timeout, tunit, this);
onLease(entry);
return entry;
}
};
}
示例2: GroupsIOApiClient
import org.apache.http.util.Asserts; //导入依赖的package包/类
/**
* More in-depth constructor to override the defaults.
*
* @param hostname
* - the base hostname (e.g. api.groups.io) to use
* @param version
* - the API version (e.g. v1) to use
* @param apiKey
* - TODO: Update with details once published.
* @param email
* - the email of the user to log in as
* @param domain
* - the domain name to connect with
* @param twoFactor
* - the appropriate two-factor code to use
*/
public GroupsIOApiClient(
final String hostname,
final String version,
final String apiKey,
final String email,
final String domain,
final Integer twoFactor)
{
Asserts.notBlank(apiKey, "apiKey");
Asserts.notBlank(email, "email");
this.hostname = hostname;
this.version = version;
this.apiKey = apiKey;
this.email = email;
this.domain = domain;
this.twoFactor = twoFactor;
}
示例3: getConnection
import org.apache.http.util.Asserts; //导入依赖的package包/类
synchronized HttpClientConnection getConnection(final HttpRoute route, final Object state) {
Asserts.check(!this.isShutdown.get(), "Connection manager has been shut down");
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Get connection for route " + route);
}
Asserts.check(!this.leased, "Connection is still allocated");
if (!LangUtils.equals(this.route, route) || !LangUtils.equals(this.state, state)) {
closeConnection();
}
this.route = route;
this.state = state;
checkExpiry();
if (this.conn == null) {
this.conn = this.connFactory.create(route, this.connConfig);
}
this.leased = true;
return this.conn;
}
示例4: connect
import org.apache.http.util.Asserts; //导入依赖的package包/类
public void connect(
final HttpClientConnection conn,
final HttpRoute route,
final int connectTimeout,
final HttpContext context) throws IOException {
Args.notNull(conn, "Connection");
Args.notNull(route, "HTTP route");
Asserts.check(conn == this.conn, "Connection not obtained from this manager");
final HttpHost host;
if (route.getProxyHost() != null) {
host = route.getProxyHost();
} else {
host = route.getTargetHost();
}
final InetSocketAddress localAddress = route.getLocalAddress() != null ? new InetSocketAddress(route.getLocalAddress(), 0) : null;;
this.connectionOperator.connect(this.conn, host, localAddress,
connectTimeout, this.socketConfig, context);
}
示例5: leaseConnection
import org.apache.http.util.Asserts; //导入依赖的package包/类
protected HttpClientConnection leaseConnection(
final Future<CPoolEntry> future,
final long timeout,
final TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException {
final CPoolEntry entry;
try {
entry = future.get(timeout, tunit);
if (entry == null || future.isCancelled()) {
throw new InterruptedException();
}
Asserts.check(entry.getConnection() != null, "Pool entry with no connection");
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Connection leased: " + format(entry) + formatStats(entry.getRoute()));
}
return CPoolProxy.newProxy(entry);
} catch (final TimeoutException ex) {
throw new ConnectionPoolTimeoutException("Timeout waiting for connection from pool");
}
}
示例6: main
import org.apache.http.util.Asserts; //导入依赖的package包/类
public static void main(String argvs[]) throws TTransportException, IOException {
Asserts.check(argvs != null && argvs.length == 2, "require params type and config path");
String type = argvs[0];
String config = argvs[1];
try {
if ("server".equals(type)) {
ServerForSync.main(new String[] { config });
} else if ("client".equals(type)) {
ClientForSync.main(new String[] { config });
} else if ("client_sync".equals(type)) {
ClientForSync.sync(config);
} else if ("client_validate".equals(type)) {
ClientForSync.validate(config);
} else {
throw new RuntimeException("unknow type " + type);
}
} finally {
ThriftClientPool.closeAll();
}
}
示例7: sync
import org.apache.http.util.Asserts; //导入依赖的package包/类
public void sync(StopAble stop) throws IOException {
String store_path = new File(new File(store_folder), store_name).getCanonicalPath();
if (null == fromManage) {
fromManage = RemoteFileFactory.queryManage(url);
}
logger.stdout(String.format("sync[%s] %s => %s", name, url, store_path));
File root = new File(store_path);
if (!root.exists()) {
root.mkdir();
}
Asserts.check(root.isDirectory(), "must be a directory :" + store_path);
long time = System.currentTimeMillis();
try {
if (stop.isStop()) {
return;
}
doSync(stop, null, root);
} finally {
long end = System.currentTimeMillis();
logger.stdout(String.format("sync finish[%s](cost: %s) %s => %s", name, (end - time) / 1000 + "s", url,
store_path));
}
}
示例8: updateSecureConnection
import org.apache.http.util.Asserts; //导入依赖的package包/类
@Override
public void updateSecureConnection(
final OperatedClientConnection conn,
final HttpHost target,
final HttpContext context,
final HttpParams params) throws IOException {
Args.notNull(conn, "Connection");
Args.notNull(target, "Target host");
Args.notNull(params, "Parameters");
Asserts.check(conn.isOpen(), "Connection must be open");
final SchemeRegistry registry = getSchemeRegistry(context);
final Scheme schm = registry.getScheme(target.getSchemeName());
Asserts.check(schm.getSchemeSocketFactory() instanceof SchemeLayeredSocketFactory,
"Socket factory must implement SchemeLayeredSocketFactory");
final SchemeLayeredSocketFactory lsf = (SchemeLayeredSocketFactory) schm.getSchemeSocketFactory();
final Socket sock = lsf.createLayeredSocket(
conn.getSocket(), target.getHostName(), schm.resolvePort(target.getPort()), params);
prepareSocket(sock, context, params);
conn.update(sock, target, lsf.isSecure(sock), params);
}
示例9: getConnection
import org.apache.http.util.Asserts; //导入依赖的package包/类
ManagedClientConnection getConnection(final HttpRoute route, final Object state) {
Args.notNull(route, "Route");
synchronized (this) {
assertNotShutdown();
if (this.log.isDebugEnabled()) {
this.log.debug("Get connection for route " + route);
}
Asserts.check(this.conn == null, MISUSE_MESSAGE);
if (this.poolEntry != null && !this.poolEntry.getPlannedRoute().equals(route)) {
this.poolEntry.close();
this.poolEntry = null;
}
if (this.poolEntry == null) {
final String id = Long.toString(COUNTER.getAndIncrement());
final OperatedClientConnection opconn = this.connOperator.createConnection();
this.poolEntry = new HttpPoolEntry(this.log, id, route, opconn, 0, TimeUnit.MILLISECONDS);
}
final long now = System.currentTimeMillis();
if (this.poolEntry.isExpired(now)) {
this.poolEntry.close();
this.poolEntry.getTracker().reset();
}
this.conn = new ManagedClientConnectionImpl(this, this.connOperator, this.poolEntry);
return this.conn;
}
}
示例10: layerProtocol
import org.apache.http.util.Asserts; //导入依赖的package包/类
/**
* Layers a protocol on top of an established tunnel.
*
* @param context the context for layering
* @param params the parameters for layering
*
* @throws IOException in case of a problem
*/
public void layerProtocol(final HttpContext context, final HttpParams params)
throws IOException {
//@@@ is context allowed to be null? depends on operator?
Args.notNull(params, "HTTP parameters");
Asserts.notNull(this.tracker, "Route tracker");
Asserts.check(this.tracker.isConnected(), "Connection not open");
Asserts.check(this.tracker.isTunnelled(), "Protocol layering without a tunnel not supported");
Asserts.check(!this.tracker.isLayered(), "Multiple protocol layering not supported");
// - collect the arguments
// - call the operator
// - update the tracking data
// In this order, we can be sure that only a successful
// layering on top of the connection will be tracked.
final HttpHost target = tracker.getTargetHost();
connOperator.updateSecureConnection(this.connection, target,
context, params);
this.tracker.layerProtocol(this.connection.isSecure());
}
示例11: getConnection
import org.apache.http.util.Asserts; //导入依赖的package包/类
synchronized HttpClientConnection getConnection(final HttpRoute route, final Object state) {
Asserts.check(!this.isShutdown.get(), "Connection manager has been shut down");
if (this.log.isDebugEnabled()) {
this.log.debug("Get connection for route " + route);
}
Asserts.check(!this.leased, "Connection is still allocated");
if (!LangUtils.equals(this.route, route) || !LangUtils.equals(this.state, state)) {
closeConnection();
}
this.route = route;
this.state = state;
checkExpiry();
if (this.conn == null) {
this.conn = this.connFactory.create(route, this.connConfig);
}
this.leased = true;
return this.conn;
}
示例12: connect
import org.apache.http.util.Asserts; //导入依赖的package包/类
@Override
public void connect(
final HttpClientConnection conn,
final HttpRoute route,
final int connectTimeout,
final HttpContext context) throws IOException {
Args.notNull(conn, "Connection");
Args.notNull(route, "HTTP route");
Asserts.check(conn == this.conn, "Connection not obtained from this manager");
final HttpHost host;
if (route.getProxyHost() != null) {
host = route.getProxyHost();
} else {
host = route.getTargetHost();
}
final InetSocketAddress localAddress = route.getLocalSocketAddress();
this.connectionOperator.connect(this.conn, host, localAddress,
connectTimeout, this.socketConfig, context);
}
示例13: leaseConnection
import org.apache.http.util.Asserts; //导入依赖的package包/类
protected HttpClientConnection leaseConnection(
final Future<CPoolEntry> future,
final long timeout,
final TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException {
final CPoolEntry entry;
try {
entry = future.get(timeout, tunit);
if (entry == null || future.isCancelled()) {
throw new InterruptedException();
}
Asserts.check(entry.getConnection() != null, "Pool entry with no connection");
if (this.log.isDebugEnabled()) {
this.log.debug("Connection leased: " + format(entry) + formatStats(entry.getRoute()));
}
return CPoolProxy.newProxy(entry);
} catch (final TimeoutException ex) {
throw new ConnectionPoolTimeoutException("Timeout waiting for connection from pool");
}
}
示例14: setTargetHostsFromJsonPathTest
import org.apache.http.util.Asserts; //导入依赖的package包/类
@Test
public void setTargetHostsFromJsonPathTest() {
String jsonPath = "$.sample.small-target-hosts[*].hostName";
List<String> targetHosts = thb.setTargetHostsFromJsonPath(jsonPath,
URL_JSON_PATH, SOURCE_URL);
logger.info("Get list " + targetHosts.size() + " from json path "
+ jsonPath + " from file " + URL_JSON_PATH);
Asserts.check(targetHosts.size() > 0,
"fail setTargetHostsFromJsonPathTest");
// try bad
try {
thb.setTargetHostsFromJsonPath(jsonPath,
FILEPATH_JSON_PATH + "bad", SOURCE_LOCAL);
} catch (TargetHostsLoadException e) {
logger.info("expected error. Get bad list " + " from json path "
+ jsonPath + " from file " + URL_JSON_PATH);
}
}
示例15: buildNotifyJson
import org.apache.http.util.Asserts; //导入依赖的package包/类
private String buildNotifyJson( @Nonnull final AbstractBuild build,
@Nonnull final Map<String,?> env )
{
Map<String,?> binding = new HashMap<String, Object>(){{
put( "jenkins", notNull( Jenkins.getInstance(), "Jenkins instance" ));
put( "build", notNull( build, "Build instance" ));
put( "env", notNull( env, "Build environment" ));
}};
String json = null;
String template = "<%\n\n" + JSON_FUNCTION + "\n\n%>\n\n" +
notBlank( notifyTemplate, "Notify template" );
try
{
json = notBlank( new SimpleTemplateEngine( getClass().getClassLoader()).
createTemplate( template ).
make( binding ).toString(), "Payload JSON" ).trim();
Asserts.check(( json.startsWith( "{" ) && json.endsWith( "}" )) ||
( json.startsWith( "[" ) && json.endsWith( "]" )),
"Illegal JSON content: should start and end with {} or []" );
Asserts.notNull( new JsonSlurper().parseText( json ), "Parsed JSON" );
}
catch ( Exception e )
{
throwError(( json == null ?
String.format( "Failed to parse Groovy template:%s%s%s",
LINE, template, LINE ) :
String.format( "Failed to validate JSON payload (check with http://jsonlint.com/):%s%s%s",
LINE, json, LINE )), e );
}
return json;
}