class MqResource implements IMqResource {

	protected <T> T post(Object request, String path, int tryCount, Class<T> class1, boolean isImportant) {
		T response = null;
		int count = 0;
		Exception last = null;
		String url = null;
		while (response == null && count < tryCount) {
			String host = getHost(isImportant);
			url = host + path;
			try {
				response = httpClient.post(url, request, class1);
				last = null;
			} catch (IOException e) {
				if (!(url.indexOf(MqConstanst.CONSUMERPRE + "/heartbeat") != -1
						|| url.indexOf(MqConstanst.CONSUMERPRE + "/getMetaGroup") != -1)) {
					logger.error("访问" + url + "异常,access_error", e);
				}
				addErrorCat(e, request, count, tryCount);
				last = e;
			} catch (BrokerException e) {
				last = e;
				addErrorCat(e, request, count, tryCount);
			} catch (Exception e) {
				last = e;
				addErrorCat(e, request, count, tryCount);
			} finally {
				if (response != null) {
					if (isImportant) {
						failUrlG1.put(host, System.currentTimeMillis() - 10 * 1000);
					} else {
						failUrlG2.put(host, System.currentTimeMillis() - 10 * 1000);
					}
					if (response instanceof PublishMessageResponse) {
						PublishMessageResponse response2 = ((PublishMessageResponse) response);
						if (response2.getSleepTime() > 0) {
							response = null;
							logger.info(response2.getMsg());
							Util.sleep(response2.getSleepTime());
							// 这个不算重试，只是降速
							count--;
						}
					} else {
						BaseResponse baseResponse = (BaseResponse) response;
						if (!baseResponse.isSuc() && baseResponse.getCode() == MqConstanst.NO) {
							response = null;
							Util.sleep(1000);
						} else {
							if (!baseResponse.isSuc()) {
								logger.error(baseResponse.getMsg());
							}
						}
					}
				} else {
					// response 等于null 说明接口调用失败了。此时需要将url 放入失败接口中。
					if (isImportant) {
						failUrlG1.put(host, System.currentTimeMillis());
					} else {
						failUrlG2.put(host, System.currentTimeMillis());
					}
					Util.sleep(500);
				}
			}
			count++;
		}
		if (last != null) {			
			throw new RuntimeException(last);
		}
		return response;
	}

	public  MqResource(String url, long connectionTimeOut, long readTimeOut);
	public  MqResource(IHttpClient httpClient, String url);

}