Package io.s4.comm.zk

Examples of io.s4.comm.zk.ZkQueue


            logger.info("Comm layer mode is set to static");
            processMonitor = new StaticProcessMonitor(zkaddress,
                                                      clusterName,
                                                      ClusterType.S4);
        } else {
            processMonitor = new ZkProcessMonitor(zkaddress,
                                                  clusterName,
                                                  ClusterType.S4,
                                                  callbackHandler);
        }
        return processMonitor;
View Full Code Here


import org.apache.zookeeper.KeeperException;

public class ZkQueueTest {
    public static void main(String args[]) {
        ZkQueue q = new ZkQueue(args[0], "/app1");

        System.out.println("Input: " + args[0]);
        int i;
        Integer max = new Integer(args[1]);

        if (args[2].equals("p")) {
            System.out.println("Producer");
            for (i = 0; i < max; i++)
                try {
                    q.produce(new Integer(10 + i));
                } catch (KeeperException e) {

                } catch (InterruptedException e) {

                }
        } else {
            System.out.println("Consumer");

            for (i = 0; i < max || true; i++) {
                try {
                    Integer r = (Integer) q.consume();
                    System.out.println("Item: " + r);
                } catch (KeeperException e) {
                    e.printStackTrace();
                    i--;
                } catch (InterruptedException e) {
View Full Code Here

        taskSetup.cleanUp();
        taskSetup.setUpTasks("1.0.0.0", new String[] { "task0", "task1" });
        Object obj;
        System.out.println(processName + " Going to Wait for a task");
        HashMap<String, String> map = new HashMap<String, String>();
        ZkTaskManager taskManager = new ZkTaskManager(address,
                                                      "/taskmanagerTest",
                                                      ClusterType.S4);
        obj = taskManager.acquireTask(map);
        System.out.println(processName + "taking up task: " + obj);
        File f = new File("c:/" + obj + ".file");
        f.delete();
        while (true) {
            if (f.exists()) {
View Full Code Here

        zkTaskSetup.cleanUp();
        zkTaskSetup.setUpTasks("1.0.0.", new String[] { "task0", "task1" });
        Object obj;
        System.out.println(processName + " Going to Wait for a task");
        HashMap<String, String> map = new HashMap<String, String>();
        ZkTaskManager taskManager = new ZkTaskManager(address,
                                                      "/taskmanagerTest",
                                                      ClusterType.S4);
        obj = taskManager.acquireTask(map);
        System.out.println(processName + "taking up task: " + obj);
        File f = new File("c:/" + obj + ".file");
        f.delete();
        while (true) {
            if (f.exists()) {
View Full Code Here

            taskManager = new StaticTaskManager(zkaddress,
                                                clusterName,
                                                clusterType,
                                                callbackHandler);
        } else {
            taskManager = new ZkTaskManager(zkaddress,
                                            clusterName,
                                            clusterType,
                                            callbackHandler);
        }
View Full Code Here

        };
        // setup
        ZooKeeper zk = new ZooKeeper(address, 30000, watcher);
        String root = "/tasksetup_app_test";
        ZkTaskSetup zkSetup = new ZkTaskSetup(address, root, ClusterType.S4);
        Map<String, String> task1 = new HashMap<String, String>();
        task1.put("name", "task-1");

        Map<String, String> task2 = new HashMap<String, String>();
        task2.put("name", "task-2");
        String tasksListRoot = root + "/tasks";
        zkSetup.cleanUp();
        Stat exists = zk.exists(tasksListRoot, false);
        myassert(exists == null);
        Object[] data = new Object[] { task1, task2 };
        zkSetup.setUpTasks(data);

        // verify that tasks are created
        exists = zk.exists(tasksListRoot, false);
        myassert(exists != null);
        List<String> children = zk.getChildren(tasksListRoot, false);
        myassert(children.size() == data.length);
        boolean[] matched = new boolean[data.length];
        for (String child : children) {
            System.out.println(child);
            String childPath = tasksListRoot + "/" + child;
            Stat sTemp = zk.exists(childPath, false);
            byte[] tempData = zk.getData(tasksListRoot + "/" + child,
                                         false,
                                         sTemp);
            Map<String, Object> map = (Map<String, Object>) JSONUtil.getMapFromJson(new String(tempData));
            // check if it matches any of the data
            for (int i = 0; i < data.length; i++) {
                Map<String, Object> newData = (Map<String, Object>) data[i];
                if (!matched[i] && CommUtil.compareMaps(newData, map)) {
                    matched[i] = true;
                    break;
                }
            }
        }
        for (int i = 0; i < matched.length; i++) {
            myassert(matched[i]);
        }

        // try running again and make verify new node is not created
        Stat oldStat = zk.exists(tasksListRoot, false);
        System.out.println("oldStat=" + oldStat);
        zkSetup.setUpTasks(data);
        Stat newStat = zk.exists(tasksListRoot, false);
        System.out.println("newstat=" + newStat);
        myassert(oldStat.getMtime() == newStat.getMtime());

        // make change to task config and try running again and verify new
        // config is uploaded
        oldStat = zk.exists(tasksListRoot, false);
        System.out.println("oldStat=" + oldStat.getVersion());
        ((Map<String, String>) data[data.length - 1]).put("name", "changedname");
        zkSetup.setUpTasks(data);
        newStat = zk.exists(tasksListRoot, false);
        System.out.println("newstat=" + newStat.getVersion());
        System.out.println();
        myassert(oldStat.getMtime() != newStat.getMtime());

        // ensure version change is working
        zkSetup.setUpTasks("1.0.0.0", data);
    }
View Full Code Here

        System.out.println("Here");
        // "effortfell.greatamerica.corp.yahoo.com:2181"
        String address = args[0];
        address = "localhost:2181";
        String processName = args[1];
        ZkTaskSetup taskSetup = new ZkTaskSetup(address,
                                                      "/taskmanagerTest",
                                                      ClusterType.S4);
        taskSetup.cleanUp();
        taskSetup.setUpTasks("1.0.0.0", new String[] { "task0", "task1" });
        Object obj;
        System.out.println(processName + " Going to Wait for a task");
        HashMap<String, String> map = new HashMap<String, String>();
        ZkTaskManager taskManager = new ZkTaskManager(address,
                                                      "/taskmanagerTest",
View Full Code Here

        System.out.println("Hereh");
        // "effortfell.greatamerica.corp.yahoo.com:2181"
        String address = args[0];
        address = "localhost:2181";
        String processName = args[1];
        ZkTaskSetup zkTaskSetup = new ZkTaskSetup(address,
                                                        "/taskmanagerTest",
                                                        ClusterType.S4);
        zkTaskSetup.cleanUp();
        zkTaskSetup.setUpTasks("1.0.0.", new String[] { "task0", "task1" });
        Object obj;
        System.out.println(processName + " Going to Wait for a task");
        HashMap<String, String> map = new HashMap<String, String>();
        ZkTaskManager taskManager = new ZkTaskManager(address,
                                                      "/taskmanagerTest",
View Full Code Here

        }
    }

    private static void processCluster(boolean clean, String zkAddress, Cluster cluster, String version) {
        List<Map<String,String>> clusterInfo = ConfigUtils.readConfig(cluster, cluster.getName(), cluster.getType(), false);
        ZkTaskSetup zkSetup = new ZkTaskSetup(zkAddress, cluster.getName(), cluster.getType());
        if (clean) {
            zkSetup.cleanUp();
        }
       
        zkSetup.setUpTasks(version, clusterInfo.toArray());
    }
View Full Code Here

        List<EventRecord> plainCompoundKeyList = null;
        if ((plainCompoundKeyList = get(Dispatcher.PARTITION_INFO_KEY,
                                        EMPTY_LIST)) != EMPTY_LIST) {
            for (EventRecord plainCompoundKeyInfo : plainCompoundKeyList) {
                CompoundKeyInfo compoundKeyInfo = new CompoundKeyInfo();
                compoundKeyInfo.setCompoundValue(plainCompoundKeyInfo.get("compoundValue",
                                                                          (String) null));
                compoundKeyInfo.setCompoundKey(plainCompoundKeyInfo.get("compoundKey",
                                                                        (String) null));
                compoundKeys.add(compoundKeyInfo);
                for (EventRecord plainKeyInfo : plainCompoundKeyInfo.get("keyInfoList",
                                                                         EMPTY_LIST)) {
                    KeyInfo keyInfo = new KeyInfo();
                    for (EventRecord plainKeyPathElement : plainKeyInfo.get("keyPathElementList",
                                                                            EMPTY_LIST)) {
                        String keyName = plainKeyPathElement.get("keyName",
                                                                 (String) null);
                        Integer index = plainKeyPathElement.get("index",
                                                                (Integer) null);

                        if (keyName != null) {
                            keyInfo.addElementToPath(keyName);
                        } else if (index != null) {
                            keyInfo.addElementToPath(index);
                        }
                    }
                    compoundKeyInfo.addKeyInfo(keyInfo);
                }
            }
        }
        if (debug) {
            for (CompoundKeyInfo compoundKeyInfo : compoundKeys) {
                System.out.println("CompoundKey: "
                        + compoundKeyInfo.getCompoundValue());
                for (KeyInfo keyInfo : compoundKeyInfo.getKeyInfoList()) {
                    String keyPath = "";
                    for (KeyPathElement keyPathElement : keyInfo.getKeyPath()) {
                        if (keyPathElement instanceof KeyPathElementIndex) {
                            keyPath += "["
                                    + ((KeyPathElementIndex) keyPathElement).getIndex()
View Full Code Here

TOP

Related Classes of io.s4.comm.zk.ZkQueue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.