Search in sources :

Example 1 with WinObject

use of com.xrtb.pojo.WinObject in project XRTB by benmfaul.

the class Spark method initialize.

/**
	 * Get the message handlers lashed up to handle all the accounting
	 * information.
	 */
public void initialize() throws Exception {
    // Instantiate your own logger if you
    logger = new FileLogger(INTERVAL);
    // don't want to log to files.
    /**
		 * Win Notifications HERE
		 */
    String address = getAddress(zeromq, WINCHANNEL);
    RTopic winners = new RTopic(address);
    winners.addListener(new MessageListener<WinObject>() {

        @Override
        public void onMessage(String channel, WinObject msg) {
            try {
                processWin(msg);
            } catch (Exception error) {
                error.printStackTrace();
            }
        }
    });
    System.out.println("Ok Spark is running!");
    address = getAddress(zeromq, BIDCHANNEL);
    RTopic bidresponse = new RTopic(address);
    bidresponse.addListener(new MessageListener<BidResponse>() {

        @Override
        public void onMessage(String channel, BidResponse msg) {
            try {
                processBid(msg);
            } catch (Exception error) {
                error.printStackTrace();
            }
        }
    });
    address = getAddress(zeromq, CLICKCHANNEL);
    RTopic pixelandclicks = new RTopic(address);
    pixelandclicks.addListener(new MessageListener<Object>() {

        @Override
        public void onMessage(String channel, Object msg) {
            try {
                processClickAndPixel(msg);
            } catch (Exception error) {
                error.printStackTrace();
            }
        }
    });
}
Also used : DataBaseObject(com.xrtb.db.DataBaseObject) WinObject(com.xrtb.pojo.WinObject) WinObject(com.xrtb.pojo.WinObject) RTopic(com.xrtb.jmq.RTopic) BidResponse(com.xrtb.pojo.BidResponse)

Example 2 with WinObject

use of com.xrtb.pojo.WinObject in project XRTB by benmfaul.

the class TestWinProcessing method testNegative.

@Test
public void testNegative() throws Exception {
    HttpPostGet http = new HttpPostGet();
    final CountDownLatch latch = new CountDownLatch(1);
    final CountDownLatch wlatch = new CountDownLatch(1);
    final List<Double> price = new ArrayList();
    String s = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/negative.txt")))).toString();
    com.xrtb.jmq.RTopic channel = new com.xrtb.jmq.RTopic("tcp://*:5571&bids");
    channel.subscribe("bids");
    channel.addListener(new com.xrtb.jmq.MessageListener<BidResponse>() {

        @Override
        public void onMessage(String channel, BidResponse bid) {
            price.add(bid.cost);
            System.out.println("BID COST: " + bid.cost);
            latch.countDown();
        }
    });
    com.xrtb.jmq.RTopic wchannel = new com.xrtb.jmq.RTopic("tcp://*:5572&wins");
    wchannel.subscribe("wins");
    wchannel.addListener(new com.xrtb.jmq.MessageListener<WinObject>() {

        @Override
        public void onMessage(String channel, WinObject win) {
            ;
            price.add(new Double(win.price));
            price.add(new Double(win.cost));
            wlatch.countDown();
        }
    });
    /**
			 * Send the bid request
			 */
    try {
        s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", s, 3000000, 3000000);
    } catch (Exception error) {
        fail("Can't connect to test host: " + Config.testHost);
    }
    int code = http.getResponseCode();
    assertTrue(code == 200);
    Bid bid = null;
    System.out.println(s);
    try {
        bid = new Bid(s);
    } catch (Exception error) {
        error.printStackTrace();
        fail();
    }
    assertEquals(bid.price, 1.1, .001);
    /**
			 * Send the win notification
			 */
    try {
        price.clear();
        String repl = bid.nurl.replaceAll("\\$", "");
        bid.nurl = repl.replace("{AUCTION_PRICE}", Double.toString(bid.price));
        s = http.sendPost(bid.nurl, "", 300000, 300000);
    } catch (Exception error) {
        error.printStackTrace();
        fail();
    }
    long time = 5;
    assertTrue(s.length() > 10);
    wlatch.await(time, TimeUnit.SECONDS);
    assertTrue(price.get(0) == 1.1);
    System.out.println("xxxxxx: " + price.get(1));
    assertTrue(price.get(1) == 1.1);
}
Also used : HttpPostGet(com.xrtb.common.HttpPostGet) ArrayList(java.util.ArrayList) WinObject(com.xrtb.pojo.WinObject) CountDownLatch(java.util.concurrent.CountDownLatch) BidResponse(com.xrtb.pojo.BidResponse) Bid(com.xrtb.pojo.Bid) Test(org.junit.Test)

Example 3 with WinObject

use of com.xrtb.pojo.WinObject in project XRTB by benmfaul.

the class TestSpark method transmit.

public void transmit() throws Exception {
    String crid = "111";
    WinObject obj = new WinObject();
    obj.cost = ".001";
    obj.price = ".001";
    obj.adId = "123";
    obj.cridId = crid;
    BidResponse br = new BidResponse();
    br.adid = "123";
    br.crid = crid;
    br.cost = .001;
    PixelClickConvertLog cmd = new PixelClickConvertLog();
    cmd.ad_id = "123";
    cmd.creative_id = crid;
    ZPublisher wins = new ZPublisher("tcp://*:5572", "wins");
    ZPublisher bids = new ZPublisher("tcp://*:5571", "bids");
    ZPublisher clicks = new ZPublisher("tcp://*:5573", "clicks");
    for (int j = 0; j < 1000; j++) {
        wins.add(obj);
        bids.add(br);
        cmd.type = PixelClickConvertLog.CLICK;
        clicks.add(cmd);
        cmd.type = PixelClickConvertLog.PIXEL;
        clicks.add(cmd);
    }
}
Also used : PixelClickConvertLog(com.xrtb.commands.PixelClickConvertLog) WinObject(com.xrtb.pojo.WinObject) ZPublisher(com.xrtb.bidder.ZPublisher) BidResponse(com.xrtb.pojo.BidResponse)

Example 4 with WinObject

use of com.xrtb.pojo.WinObject in project XRTB by benmfaul.

the class Record method getInstance.

public static synchronized Record getInstance(Object x) {
    long time = 0;
    long wins = 0;
    long bids = 0;
    long requests = 0;
    double bidPrice = 0;
    double winCost = 0;
    if (x instanceof Map) {
        Map r = (Map) x;
        r = (Map) r.get("ext");
        time = (long) r.get("timestamp");
        requests++;
    } else if (x instanceof BidResponse) {
        BidResponse r = (BidResponse) x;
        time = r.utc;
        bids++;
        bidPrice = r.cost;
    } else if (x instanceof WinObject) {
        WinObject r = (WinObject) x;
        time = r.utc;
        wins++;
        winCost = Double.parseDouble(r.price);
    }
    Date date = new Date(time);
    String key = format.format(date);
    Record r = records.get(key);
    if (r == null) {
        r = new Record(x);
        records.put(key, r);
    }
    r.bidPrice.add(bidPrice);
    r.winPrice.add(winCost);
    r.bids.add(bids);
    r.wins.add(wins);
    r.requests.add(requests);
    return r;
}
Also used : WinObject(com.xrtb.pojo.WinObject) BidResponse(com.xrtb.pojo.BidResponse) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date)

Aggregations

BidResponse (com.xrtb.pojo.BidResponse)4 WinObject (com.xrtb.pojo.WinObject)4 ZPublisher (com.xrtb.bidder.ZPublisher)1 PixelClickConvertLog (com.xrtb.commands.PixelClickConvertLog)1 HttpPostGet (com.xrtb.common.HttpPostGet)1 DataBaseObject (com.xrtb.db.DataBaseObject)1 RTopic (com.xrtb.jmq.RTopic)1 Bid (com.xrtb.pojo.Bid)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1