• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Constants类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.taobao.diamond.common.Constants的典型用法代码示例。如果您正苦于以下问题:Java Constants类的具体用法?Java Constants怎么用?Java Constants使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Constants类属于com.taobao.diamond.common包,在下文中一共展示了Constants类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getSnapshotConfiginfomation

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
private String getSnapshotConfiginfomation(String dataId, String group) {
    if (group == null) {
        group = Constants.DEFAULT_GROUP;
    }
    try {
        CacheData cacheData = getCacheData(dataId, group);
        String config = this.snapshotConfigInfoProcessor.getConfigInfomation(dataId, group);
        if (config != null && cacheData != null) {
            cacheData.incrementFetchCountAndGet();
        }
        return config;
    }
    catch (Exception e) {
        log.error("获取snapshot出错, dataId=" + dataId + ",group=" + group, e);
        return null;
    }
}
 
开发者ID:lysu,项目名称:diamond,代码行数:18,代码来源:DefaultDiamondSubscriber.java


示例2: getNotModified

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
/**
 * 回馈的结果为RP_NO_CHANGE,则整个流程为:<br>
 * 1.检查缓存中的MD5码与返回的MD5码是否一致,如果不一致,则删除缓存行。重新再次查询。<br>
 * 2.如果MD5码一致,则直接返回NULL<br>
 */
private String getNotModified(String dataId, CacheData cacheData, HttpMethod httpMethod) {
    Header md5Header = httpMethod.getResponseHeader(Constants.CONTENT_MD5);
    if (null == md5Header) {
        throw new RuntimeException("RP_NO_CHANGE返回的结果中没有MD5码");
    }
    String md5 = md5Header.getValue();
    if (!cacheData.getMd5().equals(md5)) {
        String lastMd5 = cacheData.getMd5();
        cacheData.setMd5(Constants.NULL);
        cacheData.setLastModifiedHeader(Constants.NULL);
        throw new RuntimeException("MD5码校验对比出错,DataID为:[" + dataId + "]上次MD5为:[" + lastMd5 + "]本次MD5为:[" + md5
                + "]");
    }

    cacheData.setMd5(md5);
    changeSpacingInterval(httpMethod);
    if (log.isInfoEnabled()) {
        log.info("DataId: " + dataId + ", 对应的configInfo没有变化");
    }
    return null;
}
 
开发者ID:lysu,项目名称:diamond,代码行数:27,代码来源:DefaultDiamondSubscriber.java


示例3: configureHttpMethod

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
private void configureHttpMethod(boolean skipContentCache, CacheData cacheData, long onceTimeOut,
        HttpMethod httpMethod) {
    if (skipContentCache && null != cacheData) {
        if (null != cacheData.getLastModifiedHeader() && Constants.NULL != cacheData.getLastModifiedHeader()) {
            httpMethod.addRequestHeader(Constants.IF_MODIFIED_SINCE, cacheData.getLastModifiedHeader());
        }
        if (null != cacheData.getMd5() && Constants.NULL != cacheData.getMd5()) {
            httpMethod.addRequestHeader(Constants.CONTENT_MD5, cacheData.getMd5());
        }
    }

    httpMethod.addRequestHeader(Constants.ACCEPT_ENCODING, "gzip,deflate");

    // 设置HttpMethod的参数
    HttpMethodParams params = new HttpMethodParams();
    params.setSoTimeout((int) onceTimeOut);
    // ///////////////////////
    httpMethod.setParams(params);
    httpClient.getHostConfiguration().setHost(diamondConfigure.getDomainNameList().get(this.domainNamePos.get()),
        diamondConfigure.getPort());
}
 
开发者ID:lysu,项目名称:diamond,代码行数:22,代码来源:DefaultDiamondSubscriber.java


示例4: removeDataId

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
public synchronized void removeDataId(String dataId, String group) {
    if (null == group) {
        group = Constants.DEFAULT_GROUP;
    }
    ConcurrentHashMap<String, CacheData> cacheDatas = this.cache.get(dataId);
    if (null == cacheDatas) {
        return;
    }
    cacheDatas.remove(group);

    log.warn("删除了DataID[" + dataId + "]中的Group: " + group);

    if (cacheDatas.size() == 0) {
        this.cache.remove(dataId);
        log.warn("删除了DataID[" + dataId + "]");
    }
}
 
开发者ID:lysu,项目名称:diamond,代码行数:18,代码来源:DefaultDiamondSubscriber.java


示例5: getFileContent

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
public static String getFileContent(String path) throws IOException {
    File tFile = new File(path);
    if (!tFile.isFile()) {
        throw new RuntimeException("不是文件");
    }
    RandomAccessFile file = new RandomAccessFile(tFile, "r");
    long fileSize = file.length();
    byte[] bytes = new byte[(int) fileSize];
    long readLength = 0L;
    while (readLength < fileSize) {
        int onceLength = file.read(bytes, (int) readLength, (int) (fileSize - readLength));
        if (onceLength > 0) {
            readLength += onceLength;
        }
        else {
            break;
        }
    }
    try {
        file.close();
    }
    catch (Exception e) {

    }
    return new String(bytes, Constants.ENCODE);
}
 
开发者ID:lysu,项目名称:diamond,代码行数:27,代码来源:FileUtils.java


示例6: hash

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
/**
 * 对字符串进行md5
 * 
 * @param str
 * @return md5 byte[16]
 */
public byte[] hash(String str) {
    opLock.lock();
    try {
        byte[] bt = mHasher.digest(str.getBytes(Constants.ENCODE));
        if (null == bt || bt.length != 16) {
            throw new IllegalArgumentException("md5 need");
        }
        return bt;
    }
    catch (UnsupportedEncodingException e) {
        throw new RuntimeException("unsupported utf-8 encoding", e);
    }
    finally {
        opLock.unlock();
    }
}
 
开发者ID:lysu,项目名称:diamond,代码行数:23,代码来源:MD5.java


示例7: getNullableData

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
@Override
public String getNullableData(long timeout, String strategy) {
    String data = null;
    try {
        data = env.getConfig(dataId, null, Constants.GETCONFIG_LOCAL_SERVER_SNAPSHOT, timeout);
    } catch (IOException e) {
        // 不抛异常,只记录一下
        logger.error(e);
    }

    if (data != null) {
        mbean.setAttribute(dataId, data);
    } else {
        mbean.setAttribute(dataId, "");
    }

    return data;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:19,代码来源:DiamondConfigDataHandler.java


示例8: getData

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
@Override
public String getData(long timeout, String strategy) {
    String data = null;
    try {
        data = env.getConfig(dataId, null, Constants.GETCONFIG_LOCAL_SERVER_SNAPSHOT, timeout);
    } catch (IOException e) {
        throw new RuntimeException("get diamond data error!dataId:" + dataId, e);
    }

    if (data != null) {
        mbean.setAttribute(dataId, data);
    } else {
        mbean.setAttribute(dataId, "");
    }

    return data;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:18,代码来源:DiamondConfigDataHandler.java


示例9: getNullableData

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
public String getNullableData(long timeout, String strategy) {
    String data = null;
    try {
        data = env.getConfig(dataId, null, Constants.GETCONFIG_LOCAL_SNAPSHOT_SERVER, timeout);
    } catch (IOException e) {
        // 不抛异常,只记录一下
        logger.error(e);
    }

    if (data != null) {
        mbean.setAttribute(dataId, data);
    } else {
        mbean.setAttribute(dataId, "");
    }

    return data;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:18,代码来源:DiamondConfigDataHandler.java


示例10: getData

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
public String getData(long timeout, String strategy) {
    String data = null;
    try {
        data = env.getConfig(dataId, null, Constants.GETCONFIG_LOCAL_SNAPSHOT_SERVER, timeout);
    } catch (IOException e) {
        throw new RuntimeException("get diamond data error!dataId:" + dataId, e);
    }

    if (data != null) {
        mbean.setAttribute(dataId, data);
    } else {
        mbean.setAttribute(dataId, "");
    }

    return data;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:17,代码来源:DiamondConfigDataHandler.java


示例11: DefaultDiamondManager

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
private DefaultDiamondManager(Builder builder) {
	this.dataId = builder.dataId;
	this.group = builder.group;

	diamondSubscriber = DiamondClientFactory
			.getSingletonDiamondSubscriber(Constants.DEFAULT_DIAMOND_CLUSTER);

	if (null != builder.diamondConfigure) {
		this.diamondSubscriber
				.setDiamondConfigure(builder.diamondConfigure);
	}
	this.managerListeners.addAll(builder.managerListenerList);
	((DefaultSubscriberListener) diamondSubscriber.getSubscriberListener())
			.addManagerListeners(this.dataId, this.group, this.instanceId,
					this.managerListeners);
	diamondSubscriber.addDataId(this.dataId, this.group);
	diamondSubscriber.start();
}
 
开发者ID:weijiahao001,项目名称:tb_diamond,代码行数:19,代码来源:DefaultDiamondManager.java


示例12: getSnapshotConfiginfomation

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
private String getSnapshotConfiginfomation(String dataId, String group) {
	if (group == null) {
		group = Constants.DEFAULT_GROUP;
	}
	try {
		CacheData cacheData = getCacheData(dataId, group);
		String config = this.snapshotConfigInfoProcessor
				.getConfigInfomation(dataId, group);
		if (config != null && cacheData != null) {
			cacheData.incrementFetchCountAndGet();
		}
		return config;
	} catch (Exception e) {
		log.error("��ȡsnapshot���� dataId=" + dataId + ",group=" + group, e);
		return null;
	}
}
 
开发者ID:weijiahao001,项目名称:tb_diamond,代码行数:18,代码来源:DefaultDiamondSubscriber.java


示例13: getNotModified

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
/**
 * �����Ľ��ΪRP_NO_CHANGE������������Ϊ��<br>
 * 1.��黺���е�MD5���뷵�ص�MD5���Ƿ�һ�£������һ�£���ɾ�������С������ٴβ�ѯ��<br>
 * 2.���MD5��һ�£���ֱ�ӷ���NULL<br>
 */
private String getNotModified(String dataId, CacheData cacheData,
		HttpMethod httpMethod) {
	Header md5Header = httpMethod.getResponseHeader(Constants.CONTENT_MD5);
	if (null == md5Header) {
		throw new RuntimeException("RP_NO_CHANGE���صĽ����û��MD5��");
	}
	String md5 = md5Header.getValue();
	if (!cacheData.getMd5().equals(md5)) {
		String lastMd5 = cacheData.getMd5();
		cacheData.setMd5(Constants.NULL);
		cacheData.setLastModifiedHeader(Constants.NULL);
		throw new RuntimeException("MD5��У��Աȳ���,DataIDΪ:[" + dataId
				+ "]�ϴ�MD5Ϊ:[" + lastMd5 + "]����MD5Ϊ:[" + md5 + "]");
	}

	cacheData.setMd5(md5);
	changeSpacingInterval(httpMethod);
	if (log.isInfoEnabled()) {
		log.info("DataId: " + dataId + ", ��Ӧ��configInfoû�б仯");
	}
	return null;
}
 
开发者ID:weijiahao001,项目名称:tb_diamond,代码行数:28,代码来源:DefaultDiamondSubscriber.java


示例14: configureAckHttpMethod

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
private void configureAckHttpMethod(HttpMethod httpMethod, long onceTimeOut) {
	// ����appName�Ϳͻ��˰汾
	if (null != this.appName) {
		httpMethod.addRequestHeader(Constants.APPNAME, this.appName);
	}
	httpMethod.addRequestHeader(Constants.CLIENT_VERSION_HEADER,
			Constants.CLIENT_VERSION);

	// ����HttpMethod�IJ���
	HttpMethodParams params = new HttpMethodParams();
	params.setSoTimeout((int) onceTimeOut);

	httpMethod.setParams(params);
	httpClient.getHostConfiguration().setHost(
			diamondConfigure.getDomainNameList().get(
					this.domainNamePos.get()), diamondConfigure.getPort());
}
 
开发者ID:weijiahao001,项目名称:tb_diamond,代码行数:18,代码来源:DefaultDiamondSubscriber.java


示例15: removeDataId

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
public synchronized void removeDataId(String dataId, String group) {
	if (null == group) {
		group = Constants.DEFAULT_GROUP;
	}
	ConcurrentHashMap<String, CacheData> cacheDatas = this.cache
			.get(dataId);
	if (null == cacheDatas) {
		return;
	}
	cacheDatas.remove(group);

	log.warn("ɾ����DataID[" + dataId + "]�е�Group: " + group);

	if (cacheDatas.size() == 0) {
		this.cache.remove(dataId);
		log.warn("ɾ����DataID[" + dataId + "]");
	}
}
 
开发者ID:weijiahao001,项目名称:tb_diamond,代码行数:19,代码来源:DefaultDiamondSubscriber.java


示例16: doGet

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/html;charset=GBK");
    resp.setHeader(Constants.CONTENT_MD5, md5);
    String lastModifiedFromClient = req.getHeader(Constants.IF_MODIFIED_SINCE);
    if (lastModifiedFromClient != null && lastModifiedFromClient.equals(String.valueOf(lastModified))) {
        resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return;
    }
    if (this.configInfo == null) {
        resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    resp.setHeader(Constants.LAST_MODIFIED, String.valueOf(lastModified));

    PrintWriter writer = resp.getWriter();
    writer.write(configInfo);
    writer.flush();
    // super.doGet(req, resp);
}
 
开发者ID:weijiahao001,项目名称:tb_diamond,代码行数:21,代码来源:MockConfigServlet.java


示例17: doPost

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    probeModify = req.getParameter(Constants.PROBE_MODIFY_REQUEST);
    final List<ConfigKey> configKeyList = getProbeConfigKeyList(probeModify);

    StringBuilder resultBuilder = new StringBuilder();
    StringBuilder newResultBuilder = new StringBuilder();

    for (ConfigKey key : configKeyList) {
        resultBuilder.append(key.getDataId()).append(":").append(key.getGroup()).append(";");
        newResultBuilder.append(key.getDataId()).append(WORD_SEPARATOR).append(key.getGroup())
            .append(LINE_SEPARATOR);

    }
    resp.addHeader(Constants.PROBE_MODIFY_RESPONSE, resultBuilder.toString());
    resp.addHeader(Constants.PROBE_MODIFY_RESPONSE_NEW, newResultBuilder.toString());
    // super.doPost(req, resp);
}
 
开发者ID:weijiahao001,项目名称:tb_diamond,代码行数:19,代码来源:MockConfigServlet.java


示例18: getFileContent

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
public static String getFileContent(String path) throws IOException {
    File tFile = new File(path);
    if (!tFile.isFile()) {
        throw new RuntimeException("�����ļ�");
    }
    RandomAccessFile file = new RandomAccessFile(tFile, "r");
    long fileSize = file.length();
    byte[] bytes = new byte[(int) fileSize];
    long readLength = 0L;
    while (readLength < fileSize) {
        int onceLength = file.read(bytes, (int) readLength, (int) (fileSize - readLength));
        if (onceLength > 0) {
            readLength += onceLength;
        }
        else {
            break;
        }
    }
    try {
        file.close();
    }
    catch (Exception e) {

    }
    return new String(bytes, Constants.ENCODE);
}
 
开发者ID:weijiahao001,项目名称:tb_diamond,代码行数:27,代码来源:FileUtils.java


示例19: hash

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
/**
 * ���ַ�������md5
 * 
 * @param str
 * @return md5 byte[16]
 */
public byte[] hash(String str) {
    opLock.lock();
    try {
        byte[] bt = mHasher.digest(str.getBytes(Constants.ENCODE));
        if (null == bt || bt.length != 16) {
            throw new IllegalArgumentException("md5 need");
        }
        return bt;
    }
    catch (UnsupportedEncodingException e) {
        throw new RuntimeException("unsupported utf-8 encoding", e);
    }
    finally {
        opLock.unlock();
    }
}
 
开发者ID:weijiahao001,项目名称:tb_diamond,代码行数:23,代码来源:MD5.java


示例20: testIsModified

import com.taobao.diamond.common.Constants; //导入依赖的package包/类
@Test
public void testIsModified() throws Exception {
    String dataId = "diskServiceTest-dataId";
    String group = "iskServiceTest-group";
    String content = "hello world\n";
    ConfigInfo info = new ConfigInfo(dataId, group, content);
    EasyMock.expect(servletContext.getRealPath("/" + Constants.BASE_DIR))
        .andReturn(path + "/" + Constants.BASE_DIR).anyTimes();
    EasyMock.expect(servletContext.getRealPath("/" + Constants.BASE_DIR + "/" + group)).andReturn(
        path + "/" + Constants.BASE_DIR + "/" + group).anyTimes();
    String dataPath = path + "/" + Constants.BASE_DIR + "/" + group + "/" + dataId;
    EasyMock.expect(servletContext.getRealPath("/" + Constants.BASE_DIR + "/" + group + "/" + dataId)).andReturn(
        dataPath).anyTimes();
    mocksControl.replay();

    assertFalse(this.diskService.isModified(dataId, group));
    this.diskService.saveToDisk(info);
    assertFalse(this.diskService.isModified(dataId, group));
    this.diskService.removeConfigInfo(info);

}
 
开发者ID:weijiahao001,项目名称:tb_diamond,代码行数:22,代码来源:DiskServiceUnitTest.java



注:本文中的com.taobao.diamond.common.Constants类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Configurable类代码示例发布时间:2022-05-22
下一篇:
Java TShortCollection类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap