xiatian 5 年之前
父节点
当前提交
8d4a64ce21

+ 0 - 78
src/main/java/cn/com/qmth/multithread/ComputeConsumer.java

@@ -1,78 +0,0 @@
-package cn.com.qmth.multithread;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.http.HttpEntity;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
-import org.apache.log4j.Logger;
-
-public class ComputeConsumer extends Consumer<Kv> {
-
-    private static final Logger logger = Logger.getLogger(ComputeConsumer.class);
-
-    private CloseableHttpClient client = HttpClients.createDefault();
-
-    private final static String url1 = "https://checkapi.aliyun.com/check/checkdomain?";
-
-    private final static String param = "&command=&token=Y9506071268d5ca43e4e356f0fb6b6023&ua=&currency=&site=&bid=&_csrf_token=&callback=jsonp_1575251283490_63951";
-
-    private List<Kv> cret = new ArrayList<Kv>();
-
-    private List<Kv> cunret = new ArrayList<Kv>();
-
-    @Override
-    public void consume(Kv et) {
-        logger.info("***************************计算开始");
-        String dmain = et.getKey() + ".com";
-        String ret = getData(url1 + "domain=" + dmain + param);
-        char c = ret.charAt(ret.indexOf("\"avail\":") + 8);
-        if (c == '1') {
-            cret.add(et);
-        } else {
-            cunret.add(et);
-        }
-        logger.info("***************************计算结束");
-    }
-
-    private String getData(String url) {
-        HttpGet get = new HttpGet(url);
-        try {
-            CloseableHttpResponse response = client.execute(get);
-            int statusCode = response.getStatusLine().getStatusCode();
-            HttpEntity entity = response.getEntity();
-            String data = EntityUtils.toString(entity, "UTF-8");
-            if (statusCode == 200) {
-                return data;
-            }else {
-                logger.error("***************************计算结束出错:-->"+data+"-->"+url);
-                return "";
-            }
-        } catch (Exception e) {
-            logger.error("***************************计算结束出错:"+e.getMessage());
-        }
-        return "";
-    }
-
-    @Override
-    public void disposeOnEnd(File re, File unre) {
-        try {
-            for (Kv o : cret) {
-                FileUtils.write(re, o.getKey() + " : " + o.getValue() + "\n", "utf-8", true);
-            }
-            for (Kv o : cunret) {
-                FileUtils.write(unre, o.getKey() + " : " + o.getValue() + "\n", "utf-8", true);
-            }
-        } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-    }
-}

+ 0 - 72
src/main/java/cn/com/qmth/multithread/ComputeProducer.java

@@ -1,72 +0,0 @@
-package cn.com.qmth.multithread;
-
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.log4j.Logger;
-
-public class ComputeProducer extends Producer {
-    
-    private static final Logger logger = Logger.getLogger(ComputeProducer.class);
-    
-    private final static Pattern p = Pattern.compile("^[^a-z]*([a-z]*)(.*)$");
-
-    @Override
-    protected void produce(Map<String, Object> param) throws Exception {
-        logger.info("***************************任务生产开始");
-        List<Kv> list = parse();
-        if (list != null && list.size() > 0) {
-            for (Kv et : list) {
-                // 生产数据
-                offer(et);
-            }
-        }
-        logger.info("***************************任务生产结束");
-    }
-
-    private List<Kv> parse() throws IOException {
-        List<Kv> ret = new ArrayList<Kv>();
-        List<String> list = readFile();
-        for (String s : list) {
-            Matcher m = p.matcher(s);
-            if (m.find()) {
-                String k = m.group(1);
-                String v = m.group(2);
-                if (k!=null&&v!=null) {
-                    Kv o = new Kv(k, v);
-                    ret.add(o);
-                }
-            }
-        }
-        return ret;
-    }
-
-    private List<String> readFile() throws IOException {
-        int start=14000;
-        int c=4000;
-        int index=1;
-        List<String> list = new ArrayList<String>();
-        FileInputStream fis = new FileInputStream("d:\\cc.txt");
-        InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
-        BufferedReader br = new BufferedReader(isr);
-        String line = "";
-        while ((line = br.readLine()) != null) {
-            if(start<=index&&index<start+c) {
-                list.add(line.toLowerCase());
-            }
-            index++;
-        }
-        
-        br.close();
-        isr.close();
-        fis.close();
-        return list;
-    }
-}