Package com.trendmicro.codi

Examples of com.trendmicro.codi.ZNode


        ZooKeeperInfo.Exchange xchgMsg = builder.build();

        /**
         * Try to create and set the reference's root node
         */
        ZNode refRootNode = new ZNode(refRoot);
        for(;;) {
            try {
                if(!refRootNode.exists())
                    refRootNode.create(false, xchgMsg.toString().getBytes());
                else if(new String(refRootNode.getContent()).compareTo(xchgMsg.toString()) != 0)
                    refRootNode.setContent(xchgMsg.toString().getBytes());
                break;
            }
            catch(Exception e) {
                logger.error(e.getMessage(), e);
                Utils.justSleep(1000);
            }
        }

        /**
         * Generate the reference ephemeral node and add it
         */
        ZNode refNode = genRefNode(refRoot);
        refNode.setNodeListener(new RefListener(refNode, exchange));
        exchangeRefPath = refNode.getPath();
        synchronized(allExchangeRefs) { // To prevent concurrent list
                                        // modification
            ArrayList<ZNode> refList = allExchangeRefs.get(exchangeFullName);
            if(refList == null) {
                refList = new ArrayList<ZNode>();
View Full Code Here


    public void decExchangeRef(Exchange exchange) {
        String exchangeFullName = exchange.toString();
        String refRoot = "/exchange/" + exchangeFullName;

        ArrayList<ZNode> refList = allExchangeRefs.get(exchangeFullName);
        ZNode refNode = null;
        refNode = refList.get(0);

        String refPath = refNode.getPath();
        try {
            refNode.delete();
            logger.info("refNode " + refPath + " deleted");
        }
        catch(CODIException.NoNode e) {
            logger.info("refNode " + refPath + " disappeared, ignore it");
        }
        catch(Exception e) {
            logger.error(e.getMessage(), e);
        }
        refList.remove(0);

        try {
            if(hasReference(exchange))
                return;

            logger.info("decExchangeRef(): no reference, check exchange " + exchangeFullName);
            ZNode exNode = new ZNode(refRoot);
            ZooKeeperInfo.Exchange.Builder builder = ZooKeeperInfo.Exchange.newBuilder();
            TextFormat.merge(new String(exNode.getContent()), builder);
            String broker = builder.build().getHost();
            if(!isExchangeInUse(broker, exchange)) {
                logger.info("decExchangeRef(): no other client and pending message, remove exchange");
                exNode.delete();
            }
        }
        catch(Exception e) {
            logger.error(e.getMessage(), e);
        }
View Full Code Here

            return hostname;

        String exchangeFullName = exchange.toString();
        String exchangeNodePath = "/exchange/" + exchangeFullName;

        ZNode exchangeNode = new ZNode(exchangeNodePath);
        try {
            if(!exchangeNode.exists())
                hostname = decideExchangeHost(realname, false);
            else {
                ZooKeeperInfo.Exchange.Builder exBuilder = ZooKeeperInfo.Exchange.newBuilder();
                TextFormat.merge(new String(exchangeNode.getContent()), exBuilder);
                ZooKeeperInfo.Exchange ex = exBuilder.build();
                hostname = ex.getHost();

                ZNode brokerNode = new ZNode("/broker/" + hostname);
                if(hostname.compareTo("") == 0 || !brokerNode.exists()) {
                    hostname = decideExchangeHost(realname, true);
                    exchangeNode.setContent(ZooKeeperInfo.Exchange.newBuilder().setHost(hostname).build().toString().getBytes());
                }
                else {
                    ZooKeeperInfo.Broker.Builder brkBuilder = ZooKeeperInfo.Broker.newBuilder();
                    TextFormat.merge(new String(brokerNode.getContent()), brkBuilder);
                    if(brkBuilder.build().getStatus() != ZooKeeperInfo.Broker.Status.ONLINE) {
                        hostname = decideExchangeHost(realname, false);
                        ex = ZooKeeperInfo.Exchange.newBuilder().mergeFrom(ex).clearHost().setHost(hostname).build();
                        exchangeNode.setContent(ex.toString().getBytes());
                    }
View Full Code Here

    }

    public static List<ExchangeInfo> getAllExchanges() {
        List<ExchangeInfo> list = new ArrayList<ExchangeInfo>();
        try {
            ZNode exchangeNode = new ZNode("/exchange");
            List<String> exchanges = exchangeNode.getChildren();
            for(String name : exchanges) {
                try {
                    if(name.endsWith(".lock")) {
                        continue;
                    }

                    ZNode exchangeChildNode = new ZNode("/exchange/" + name);
                    byte[] data = exchangeChildNode.getContent();
                    ZooKeeperInfo.Exchange.Builder ex_builder = ZooKeeperInfo.Exchange.newBuilder();
                    TextFormat.merge(new String(data), ex_builder);
                    ExchangeInfo info = new ExchangeInfo();
                    info.name = name;
                    info.host = ex_builder.build().getHost();
                    info.refCount = exchangeChildNode.getChildren().size();
                    list.add(info);
                }
                catch(Exception e) {
                    e.printStackTrace();
                }
View Full Code Here

    public static String getCurrentExchangeHost(Exchange exchange) {
        String host = null;
        String exchangeFullName = exchange.toString();
        String exchangeNodePath = "/exchange/" + exchangeFullName;

        ZNode exchangeNode = new ZNode(exchangeNodePath);
        ZooKeeperInfo.Exchange.Builder exBuilder = ZooKeeperInfo.Exchange.newBuilder();
        try {
            TextFormat.merge(new String(exchangeNode.getContent()), exBuilder);
            ZooKeeperInfo.Exchange ex = exBuilder.build();
            host = ex.getHost();
        }
        catch(Exception e) {
        }
View Full Code Here

        return host;
    }

    public static FlowControlBehavior getDropPolicy(Exchange exchange) {
        String path = "/global/drop_exchange" + "/" + exchange.getName();
        ZNode dropNode = new ZNode(path);
        try {
            if(dropNode.exists()) {
                ZooKeeperInfo.DropConfig.Builder dropBuilder = ZooKeeperInfo.DropConfig.newBuilder();
                TextFormat.merge(dropNode.getContentString(), dropBuilder);
                ZooKeeperInfo.DropConfig dropConf = dropBuilder.build();
                if(dropConf.getPolicy().equals(ZooKeeperInfo.DropConfig.Policy.NEWEST))
                    return FlowControlBehavior.DROP_NEWEST;
                else
                    return FlowControlBehavior.DROP_OLDEST;
View Full Code Here

        }
    }

    public static ZooKeeperInfo.TotalLimit getTotalLimit(Exchange exchange) {
        String path = "/global/limit_exchange" + "/" + exchange.getName();
        ZNode limitNode = new ZNode(path);
        try {
            ZooKeeperInfo.TotalLimit.Builder limitBuilder = ZooKeeperInfo.TotalLimit.newBuilder();
            TextFormat.merge(limitNode.getContentString(), limitBuilder);
            return limitBuilder.build();
        }
        catch(Exception e) {
            return ZooKeeperInfo.TotalLimit.newBuilder().setCount(100000).setSizeBytes(10485760).build();
        }
View Full Code Here

    public String getCurrentExchangeHost(Exchange exchange) {
        String host = null;
        String exchangeFullName = exchange.toString();
        String exchangeNodePath = "/exchange/" + exchangeFullName;
       
        ZNode exchangeNode = new ZNode(exchangeNodePath);
        ZooKeeperInfo.Exchange.Builder exBuilder = ZooKeeperInfo.Exchange.newBuilder();
        try {
            TextFormat.merge(new String(exchangeNode.getContent()), exBuilder);
            ZooKeeperInfo.Exchange ex = exBuilder.build();
            host = ex.getHost();
        }
        catch(Exception e) {
            logger.error(e.getMessage(), e);
View Full Code Here

        return host;
    }
   
    public FlowControlBehavior getDropPolicy(Exchange exchange) {
        String path = "/global/drop_exchange" + "/" + exchange.getName();
        ZNode dropNode = new ZNode(path);
        try {
            if(dropNode.exists()) {
                ZooKeeperInfo.DropConfig.Builder dropBuilder = ZooKeeperInfo.DropConfig.newBuilder();
                TextFormat.merge(dropNode.getContentString(), dropBuilder);
                ZooKeeperInfo.DropConfig dropConf = dropBuilder.build();
                if(dropConf.getPolicy().equals(ZooKeeperInfo.DropConfig.Policy.NEWEST))
                    return FlowControlBehavior.DROP_NEWEST;
                else
                    return FlowControlBehavior.DROP_OLDEST;
View Full Code Here

        }
    }
   
    public ZooKeeperInfo.TotalLimit getTotalLimit(Exchange exchange) {
        String path = "/global/limit_exchange" + "/" + exchange.getName();
        ZNode limitNode = new ZNode(path);
        try {
            ZooKeeperInfo.TotalLimit.Builder limitBuilder = ZooKeeperInfo.TotalLimit.newBuilder();
            TextFormat.merge(limitNode.getContentString(), limitBuilder);
            return limitBuilder.build();
        }
        catch(Exception e) {
            return ZooKeeperInfo.TotalLimit.newBuilder().setCount(100000).setSizeBytes(10485760).build();
        }
View Full Code Here

TOP

Related Classes of com.trendmicro.codi.ZNode

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.