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


Java UtilAll.crc32方法代码示例

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


在下文中一共展示了UtilAll.crc32方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fetchClassFromRemoteHost

import com.alibaba.rocketmq.common.UtilAll; //导入方法依赖的package包/类
private void fetchClassFromRemoteHost() {
    Iterator<Entry<String, FilterClassInfo>> it = this.filterClassTable.entrySet().iterator();
    while (it.hasNext()) {
        try {
            Entry<String, FilterClassInfo> next = it.next();
            FilterClassInfo filterClassInfo = next.getValue();
            String[] topicAndGroup = next.getKey().split("@");
            String responseStr =
                    this.filterClassFetchMethod.fetch(topicAndGroup[0], topicAndGroup[1],
                        filterClassInfo.getClassName());
            byte[] filterSourceBinary = responseStr.getBytes("UTF-8");
            int classCRC = UtilAll.crc32(responseStr.getBytes("UTF-8"));
            if (classCRC != filterClassInfo.getClassCRC()) {
                String javaSource = new String(filterSourceBinary, MixAll.DEFAULT_CHARSET);
                Class<?> newClass =
                        DynaCode.compileAndLoadClass(filterClassInfo.getClassName(), javaSource);
                Object newInstance = newClass.newInstance();
                filterClassInfo.setMessageFilter((MessageFilter) newInstance);
                filterClassInfo.setClassCRC(classCRC);

                log.info("fetch Remote class File OK, {} {}", next.getKey(),
                    filterClassInfo.getClassName());
            }
        }
        catch (Exception e) {
            log.error("fetchClassFromRemoteHost Exception", e);
        }
    }
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:30,代码来源:FilterClassManager.java

示例2: main

import com.alibaba.rocketmq.common.UtilAll; //导入方法依赖的package包/类
public static void main(String[] args) throws InstantiationException, IllegalAccessException, IOException {
    String name = MessageFilterImpl.class.getName().replace(".", "/") + ".class";
    System.out.println(name);

    InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(name);
    int ava = is.available();
    byte[] content = new byte[ava];

    int crc32 = UtilAll.crc32(content);
    System.out.println("crc=" + crc32);

    System.out.println("ava = " + ava);
    int len = is.read(content);

    // 打开一个随机访问文件流,按读写方式
    RandomAccessFile randomFile = new RandomAccessFile("/Users/vive/c.txt", "rw");
    randomFile.seek(0);
    randomFile.write(content, 0, len);
    randomFile.close();
    System.out.println(len);

    MyClassLoader my = new MyClassLoader();
    Class<?> newClass = my.createNewClass(null, content, 0, content.length);
    Object newInstance = newClass.newInstance();
    System.out.println(newInstance);

    MessageFilter filter = (MessageFilter) newInstance;
    filter.doFilter(null);
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:30,代码来源:Test.java

示例3: fetchClassFromRemoteHost

import com.alibaba.rocketmq.common.UtilAll; //导入方法依赖的package包/类
private void fetchClassFromRemoteHost() {
    Iterator<Entry<String, FilterClassInfo>> it = this.filterClassTable.entrySet().iterator();
    while (it.hasNext()) {
        try {
            Entry<String, FilterClassInfo> next = it.next();
            FilterClassInfo filterClassInfo = next.getValue();

            String url = this.filtersrvController.getFiltersrvConfig().getFilterClassRepertoryUrl();
            url += "/";
            url += filterClassInfo.getClassName();
            url += ".java";

            HttpResult result = HttpTinyClient.httpGet(url, null, null, "UTF-8", 5000);
            if (200 == result.code) {
                String responseStr = result.content;
                byte[] filterSourceBinary = responseStr.getBytes("UTF-8");
                int classCRC = UtilAll.crc32(responseStr.getBytes("UTF-8"));
                if (classCRC != filterClassInfo.getClassCRC()) {
                    String javaSource = new String(filterSourceBinary, MixAll.DEFAULT_CHARSET);
                    Class<?> newClass =
                            DynaCode.compileAndLoadClass(filterClassInfo.getClassName(), javaSource);
                    Object newInstance = newClass.newInstance();
                    filterClassInfo.setMessageFilter((MessageFilter) newInstance);
                    filterClassInfo.setClassCRC(classCRC);

                    log.info("fetch Remote class File OK, {} {} {}", next.getKey(),
                        filterClassInfo.getClassName(), url);
                }
            }
        }
        catch (Exception e) {
            log.error("fetchClassFromRemoteHost Exception", e);
        }
    }
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:36,代码来源:FilterClassManager.java

示例4: uploadFilterClassToAllFilterServer

import com.alibaba.rocketmq.common.UtilAll; //导入方法依赖的package包/类
private void uploadFilterClassToAllFilterServer(final String consumerGroup, final String fullClassName, final String topic,
        final String filterClassSource) throws UnsupportedEncodingException {
    byte[] classBody = null;
    int classCRC = 0;
    try {
        classBody = filterClassSource.getBytes(MixAll.DEFAULT_CHARSET);
        classCRC = UtilAll.crc32(classBody);
    }
    catch (Exception e1) {
        log.warn("uploadFilterClassToAllFilterServer Exception, ClassName: {} {}", //
            fullClassName,//
            RemotingHelper.exceptionSimpleDesc(e1));
    }

    TopicRouteData topicRouteData = this.topicRouteTable.get(topic);
    if (topicRouteData != null //
            && topicRouteData.getFilterServerTable() != null && !topicRouteData.getFilterServerTable().isEmpty()) {
        Iterator<Entry<String, List<String>>> it = topicRouteData.getFilterServerTable().entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, List<String>> next = it.next();
            List<String> value = next.getValue();
            for (final String fsAddr : value) {
                try {
                    this.mQClientAPIImpl.registerMessageFilterClass(fsAddr, consumerGroup, topic, fullClassName, classCRC, classBody,
                        5000);

                    log.info("register message class filter to {} OK, ConsumerGroup: {} Topic: {} ClassName: {}", fsAddr,
                        consumerGroup, topic, fullClassName);

                }
                catch (Exception e) {
                    log.error("uploadFilterClassToAllFilterServer Exception", e);
                }
            }
        }
    }
    else {
        log.warn("register message class filter failed, because no filter server, ConsumerGroup: {} Topic: {} ClassName: {}",
            consumerGroup, topic, fullClassName);
    }
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:42,代码来源:MQClientInstance.java

示例5: uploadFilterClassToAllFilterServer

import com.alibaba.rocketmq.common.UtilAll; //导入方法依赖的package包/类
/**
 * 上传filter类源码到所有的filterServer
 *
 * @param consumerGroup     消费者所在组
 * @param fullClassName     filter类全名
 * @param topic             需要被过滤的Topic
 * @param filterClassSource filter类源码
 * @throws UnsupportedEncodingException
 */
private void uploadFilterClassToAllFilterServer(final String consumerGroup, final String fullClassName, final String topic,
                                                final String filterClassSource) throws UnsupportedEncodingException {
    /**
     * 类文件转为byte,计算CRC32校验码
     */
    byte[] classBody = null;
    int classCRC = 0;
    try {
        classBody = filterClassSource.getBytes(MixAll.DEFAULT_CHARSET);
        classCRC = UtilAll.crc32(classBody);
    } catch (Exception e1) {
        log.warn("uploadFilterClassToAllFilterServer Exception, ClassName: {} {}", //
                fullClassName,//
                RemotingHelper.exceptionSimpleDesc(e1));
    }

    /**
     * 根据Topic查找该Topic对应的filterServer信息,如果找到则不上传
     */
    TopicRouteData topicRouteData = this.topicRouteTable.get(topic);
    if (topicRouteData != null //
            && topicRouteData.getFilterServerTable() != null && !topicRouteData.getFilterServerTable().isEmpty()) {

        /**
         * 遍历flterserver,向该Topic对应的所有filterServer上传源码
         */
        Iterator<Entry<String, List<String>>> it = topicRouteData.getFilterServerTable().entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, List<String>> next = it.next();
            List<String> value = next.getValue();
            for (final String fsAddr : value) {
                try {
                    this.mQClientAPIImpl.registerMessageFilterClass(fsAddr, consumerGroup, topic, fullClassName, classCRC, classBody,
                            5000);

                    log.info("register message class filter to {} OK, ConsumerGroup: {} Topic: {} ClassName: {}", fsAddr,
                            consumerGroup, topic, fullClassName);

                } catch (Exception e) {
                    log.error("uploadFilterClassToAllFilterServer Exception", e);
                }
            }
        }
    } else {
        log.warn("register message class filter failed, because no filter server, ConsumerGroup: {} Topic: {} ClassName: {}",
                consumerGroup, topic, fullClassName);
    }
}
 
开发者ID:medusar,项目名称:rocketmq-commet,代码行数:58,代码来源:MQClientInstance.java

示例6: uploadFilterClassToAllFilterServer

import com.alibaba.rocketmq.common.UtilAll; //导入方法依赖的package包/类
private void uploadFilterClassToAllFilterServer(final String consumerGroup, final String className,
        final String topic) throws UnsupportedEncodingException {
    URL classFile = FilterAPI.classFile(className);
    byte[] classBody = null;
    int classCRC = 0;
    try {
        String fileContent = MixAll.file2String(classFile);
        classBody = fileContent.getBytes(MixAll.DEFAULT_CHARSET);
        classCRC = UtilAll.crc32(classBody);
    }
    catch (Exception e1) {
        log.warn("uploadFilterClassToAllFilterServer Exception, ClassFile: {} ClassName: {} {}", //
            classFile,//
            className,//
            RemotingHelper.exceptionSimpleDesc(e1));
    }

    TopicRouteData topicRouteData = this.topicRouteTable.get(topic);
    if (topicRouteData != null //
            && topicRouteData.getFilterServerTable() != null
            && !topicRouteData.getFilterServerTable().isEmpty()) {
        Iterator<Entry<String, List<String>>> it =
                topicRouteData.getFilterServerTable().entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, List<String>> next = it.next();
            List<String> value = next.getValue();
            for (final String fsAddr : value) {
                try {
                    this.mQClientAPIImpl.registerMessageFilterClass(fsAddr, consumerGroup, topic,
                        className, classCRC, classBody, 5000);

                    log.info(
                        "register message class filter to {} OK, ConsumerGroup: {} Topic: {} ClassName: {} ClassFile: {}",
                        fsAddr, consumerGroup, topic, className, classFile);

                }
                catch (Exception e) {
                    log.error("uploadFilterClassToAllFilterServer Exception", e);
                }
            }
        }
    }
    else {
        log.warn(
            "register message class filter failed, because no filter server, ConsumerGroup: {} Topic: {} ClassName: {}",
            consumerGroup, topic, className);
    }
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:49,代码来源:MQClientInstance.java


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