001package org.openimaj.picslurper.client; 002 003import java.io.ByteArrayInputStream; 004import java.io.IOException; 005import java.io.UnsupportedEncodingException; 006import java.util.HashSet; 007 008import org.openimaj.io.IOUtils; 009import org.openimaj.picslurper.output.WriteableFailedURL; 010import org.zeromq.ZMQ; 011 012/** 013 * @author Sina Samangooei (ss@ecs.soton.ac.uk) 014 * 015 */ 016public class ZMQFailClient { 017 018 019 /** 020 * @param args 021 * @throws UnsupportedEncodingException 022 */ 023 public static void main(String args[]) throws UnsupportedEncodingException { 024 // Prepare our context and subscriber 025 ZMQ.Context context = ZMQ.context(1); 026 ZMQ.Socket subscriber = context.socket(ZMQ.SUB); 027 028 subscriber.connect("tcp://152.78.64.99:5563"); 029 subscriber.subscribe("FAIL".getBytes("UTF-8")); 030 031 HashSet<String> seenHosts = new HashSet<String>(); 032 while (true) { 033 // Consume the header 034 subscriber.recv(0); 035 ByteArrayInputStream stream = new ByteArrayInputStream(subscriber.recv(0)); 036 WriteableFailedURL instance; 037 try { 038 instance = IOUtils.read(stream, WriteableFailedURL.class, "UTF-8"); 039 if(!seenHosts.contains(instance.url.getHost())) 040 { 041 System.out.println("Failed to deal with: " + instance.url.getHost() ); 042 System.out.println("Full URL: " + instance.url ); 043 System.out.println("Reason: " + instance.reason); 044 seenHosts.add(instance.url.getHost()); 045 } 046 } catch (IOException e) { 047 e.printStackTrace(); 048 } 049 } 050 } 051}