Search in sources :

Example 1 with StopBidder

use of com.xrtb.commands.StopBidder in project XRTB by benmfaul.

the class Commands method stopBidder.

/**
  * Send a stop bidder command
  */
public void stopBidder() {
    System.out.print("Which bidder to stop:");
    String to = scan.nextLine();
    StopBidder cmd = new StopBidder(to);
    cmd.from = uuid;
    commands.add(cmd);
}
Also used : StopBidder(com.xrtb.commands.StopBidder)

Example 2 with StopBidder

use of com.xrtb.commands.StopBidder in project XRTB by benmfaul.

the class WebCampaign method doExecute.

/**
	 * Used to stop, start, nobbideason and change log level of a bidder
	 * instance.
	 * 
	 * @param m
	 *            Map. The command parameters.
	 * @return Sting. The JSON encoded return of the command.
	 * @throws Exception
	 *             on cache/aerospike or JSON errors.
	 */
public String doExecute(Map m) throws Exception {
    String action = (String) m.get("action");
    String who = (String) m.get("who");
    String username = (String) m.get("username");
    switch(action) {
        case "start":
            StartBidder start = new StartBidder();
            start.from = username;
            start.to = who;
            Controller.getInstance().startBidder(start);
            break;
        case "stop":
            StopBidder stop = new StopBidder();
            stop.from = username;
            stop.to = who;
            Controller.getInstance().stopBidder(stop);
            break;
        case "loglevel":
            LogLevel level = new LogLevel();
            level.from = username;
            level.to = who;
            String valu = (String) m.get("level");
            level.target = valu;
            Controller.getInstance().setLogLevel(level);
            break;
        case "nobidreason":
            NobidReason nbr = new NobidReason();
            nbr.from = username;
            nbr.to = who;
            valu = (String) m.get("level");
            nbr.target = valu;
            Controller.getInstance().setNoBidReason(nbr);
            break;
        case "reload":
            break;
        default:
            break;
    }
    Map x = new HashMap();
    x.put("message", "Command sent");
    return getString(x);
}
Also used : StopBidder(com.xrtb.commands.StopBidder) HashMap(java.util.HashMap) StartBidder(com.xrtb.commands.StartBidder) HashMap(java.util.HashMap) Map(java.util.Map) LogLevel(com.xrtb.commands.LogLevel) NobidReason(com.xrtb.commands.NobidReason)

Example 3 with StopBidder

use of com.xrtb.commands.StopBidder in project XRTB by benmfaul.

the class DeadmanSwitch method run.

@Override
public void run() {
    while (true) {
        try {
            if (canRun() == false) {
                if (sentStop == false) {
                    try {
                        if (!testmode) {
                            Controller.getInstance().sendLog(1, "DeadmanSwitch", ("Switch error: " + key + ", does not exist, no bidding allowed!"));
                            StopBidder cmd = new StopBidder();
                            cmd.from = Configuration.getInstance().instanceName;
                            Controller.getInstance().stopBidder(cmd);
                        } else {
                            System.out.println("Deadman Switch is thrown");
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                sentStop = true;
            } else {
                if (sentStop) {
                    sentStop = false;
                    if (RTBServer.stopped) {
                        RTBServer.stopped = false;
                        StartBidder cmd = new StartBidder();
                        cmd.from = Configuration.getInstance().instanceName;
                        try {
                            Controller.getInstance().startBidder(cmd);
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }
            }
            Thread.sleep(60000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : StopBidder(com.xrtb.commands.StopBidder) StartBidder(com.xrtb.commands.StartBidder)

Example 4 with StopBidder

use of com.xrtb.commands.StopBidder in project XRTB by benmfaul.

the class TestZZZRedis method stopStartBidder.

/**
	 * Test starting and stopping the rtb bidder engine.
	 * 
	 * @throws Exception
	 *             on Redis errors.
	 */
@Test
public void stopStartBidder() throws Exception {
    StopBidder e = new StopBidder();
    e.id = "STOPBIDDER-ID";
    rcv = null;
    latch = new CountDownLatch(1);
    commands.add(e);
    latch.await(5, TimeUnit.SECONDS);
    System.out.println("------------>" + rcv);
    assertTrue(rcv.msg.equals("stopped"));
    // Now make a bid
    HttpPostGet http = new HttpPostGet();
    String s = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexage.txt")))).toString();
    long time = 0;
    String str = null;
    try {
        str = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", s);
    } catch (Exception error) {
        fail("Network error");
    }
    assertNull(str);
    assertTrue(http.getResponseCode() == 204);
    StartBidder ee = new StartBidder();
    ee.id = "STARTBIDDER-ID";
    latch = new CountDownLatch(1);
    commands.add(ee);
    latch.await(5, TimeUnit.SECONDS);
    time = System.currentTimeMillis();
    test = rcv.msg;
    assertTrue(test.equals("running"));
}
Also used : StopBidder(com.xrtb.commands.StopBidder) HttpPostGet(com.xrtb.common.HttpPostGet) CountDownLatch(java.util.concurrent.CountDownLatch) StartBidder(com.xrtb.commands.StartBidder) Test(org.junit.Test)

Aggregations

StopBidder (com.xrtb.commands.StopBidder)4 StartBidder (com.xrtb.commands.StartBidder)3 LogLevel (com.xrtb.commands.LogLevel)1 NobidReason (com.xrtb.commands.NobidReason)1 HttpPostGet (com.xrtb.common.HttpPostGet)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1