当前位置: 首页>>代码示例>>Java>>正文


Java Asserts.check方法代码示例

本文整理汇总了Java中org.apache.http.util.Asserts.check方法的典型用法代码示例。如果您正苦于以下问题:Java Asserts.check方法的具体用法?Java Asserts.check怎么用?Java Asserts.check使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.util.Asserts的用法示例。


在下文中一共展示了Asserts.check方法的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;
        }

    };
}
 
开发者ID:zxfrdas,项目名称:ZTLib,代码行数:26,代码来源:AbstractConnPool.java

示例2: 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;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:19,代码来源:BasicHttpClientConnectionManager.java

示例3: 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);
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:19,代码来源:BasicHttpClientConnectionManager.java

示例4: 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);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:20,代码来源:BasicHttpClientConnectionManager.java

示例5: 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();
	}
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:22,代码来源:SyncMain.java

示例6: 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));
		}
	}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:25,代码来源:ClientFolder.java

示例7: 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());

}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:32,代码来源:AbstractPoolEntry.java

示例8: 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);
    }

}
 
开发者ID:eBay,项目名称:parallec,代码行数:21,代码来源:TargetHostsBuilderTest.java

示例9: 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;
}
 
开发者ID:evgeny-goldin,项目名称:jenkins-notify-plugin,代码行数:37,代码来源:NotifyRecorder.java

示例10: 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");
    }
}
 
开发者ID:SxdsF,项目名称:Visit,代码行数:20,代码来源:PoolingHttpClientConnectionManager.java

示例11: sendNotifyRequest

import org.apache.http.util.Asserts; //导入方法依赖的package包/类
private void sendNotifyRequest( @Nonnull String url, @Nonnull String json )
    throws IOException
{
    try
    {
        HttpPost request = new HttpPost( notBlank( url, "Notify URL" ));
        request.setEntity( new StringEntity( notBlank( json, "Notify JSON" ),
                                             ContentType.create( "application/json", Consts.UTF_8 )));
        HttpResponse response   = HTTP_CLIENT.execute( request );
        int          statusCode = response.getStatusLine().getStatusCode();

        Asserts.check( statusCode == 200, String.format( "status code is %s, expected 200", statusCode ));
        EntityUtils.consumeQuietly( notNull( response.getEntity(), "Response entity" ));
        request.releaseConnection();
    }
    catch ( Exception e )
    {
        throwError( String.format( "Failed to publish notify request to '%s', payload JSON was:%s%s%s",
                                   notifyUrl, LINE, json, LINE ), e );
    }
}
 
开发者ID:evgeny-goldin,项目名称:jenkins-notify-plugin,代码行数:22,代码来源:NotifyRecorder.java

示例12: 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;
}
 
开发者ID:zxfrdas,项目名称:ZTLib,代码行数:19,代码来源:BasicHttpClientConnectionManager.java

示例13: index

import org.apache.http.util.Asserts; //导入方法依赖的package包/类
@Override
public void index(Document ... docs) {
    Asserts.notNull(docs,"Document to index should not be null.");
    Asserts.check(docs.length > 0, "Should be at least one document to index.");
    for(Document doc: docs) {
        indexSingleDocument(doc);
    }
}
 
开发者ID:RBMHTechnology,项目名称:vind,代码行数:9,代码来源:SolrSearchServer.java

示例14: free

import org.apache.http.util.Asserts; //导入方法依赖的package包/类
public void free(final E entry, final boolean reusable) {
    Args.notNull(entry, "Pool entry");
    final boolean found = this.leased.remove(entry);
    Asserts.check(found, "Entry %s has not been leased from this pool", entry);
    if (reusable) {
        this.available.addFirst(entry);
    }
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:9,代码来源:RouteSpecificPool.java

示例15: isSecure

import org.apache.http.util.Asserts; //导入方法依赖的package包/类
/**
 * Checks whether a socket connection is secure.
 * This factory creates plain socket connections
 * which are not considered secure.
 *
 * @param sock      the connected socket
 *
 * @return  {@code false}
 *
 * @throws IllegalArgumentException if the argument is invalid
 */
@Override
public final boolean isSecure(final Socket sock)
    throws IllegalArgumentException {

    Args.notNull(sock, "Socket");
    // This check is performed last since it calls a method implemented
    // by the argument object. getClass() is final in java.lang.Object.
    Asserts.check(!sock.isClosed(), "Socket is closed");
    return false;

}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:MultihomePlainSocketFactory.java


注:本文中的org.apache.http.util.Asserts.check方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。