Examples of ZLock


Examples of com.trendmicro.codi.lock.ZLock

                return;
            }

            myConsole.logResponse("starting `%s' ... ", broker_ip);
            String lockPath = "/locks/brk_" + broker_ip;
            ZLock brokerLock = new ZLock(lockPath);
            ZNode brokerNode = new ZNode("/broker/" + broker_ip);
            try{

                brokerLock.acquire(LockType.WRITE_LOCK);
                ZooKeeperInfo.Broker.Builder brkBuilder = ZooKeeperInfo.Broker.newBuilder();
                TextFormat.merge(new String(brokerNode.getContent()), brkBuilder);
                brkBuilder.clearStatus().setStatus(ZooKeeperInfo.Broker.Status.ONLINE);
                brokerNode.setContent(brkBuilder.build().toString().getBytes());
                myConsole.logResponseNL("success");
            }
            catch(Exception e){
                myConsole.logResponseNL("failed");
                myConsole.logResponseNL(e.toString());
            }
            finally {
                try {
                    brokerLock.release();
                    if(brokerLock.getChildren().isEmpty())
                        brokerLock.delete();
                }
                catch(CODIException e) {
                }
            }
        }
View Full Code Here

Examples of com.trendmicro.codi.lock.ZLock

                }
            }

            myConsole.logResponse("stopping `%s' ...%n", broker_ip);
            String lockPath = "/locks/brk_" + broker_ip;
            ZLock brokerLock = new ZLock(lockPath);
            ZNode brokerNode = new ZNode("/broker/" + broker_ip);
            try {
                brokerLock.acquire(LockType.WRITE_LOCK);
                ZooKeeperInfo.Broker.Builder brkBuilder = ZooKeeperInfo.Broker.newBuilder();
                TextFormat.merge(new String(brokerNode.getContent()), brkBuilder);
                brkBuilder.clearStatus().setStatus(ZooKeeperInfo.Broker.Status.OFFLINE);
                brokerNode.setContent(brkBuilder.build().toString().getBytes());

                if(availBrkCnt > 1) {
                    BrokerSpy brokerSpy = new BrokerSpy(broker_ip);
                    ArrayList<Exchange> exchangeList = brokerSpy.getAllExchangeMetadata();

                    ArrayList<MigrateThread> migrateList = new ArrayList<MigrateThread>();
                    for(Exchange exg : exchangeList) {
                        migrateList.add(new MigrateThread(exg));
                    }

                    while(migrateList.size() > 0) {
                        Iterator<MigrateThread> iter = migrateList.iterator();
                        ArrayList<MigrateThread> runningList = new ArrayList<MigrateThread>();
                        for(int i = 0; i < 8; i++) {
                            if(iter.hasNext()) {
                                MigrateThread th = iter.next();
                                th.start();
                                runningList.add(th);
                            }
                        }

                        ArrayList<MigrateThread> pendingList = (ArrayList<MigrateThread>)migrateList.clone();
                        for(MigrateThread th : runningList)
                            pendingList.remove(th);

                        for(;;) {
                            Utils.justSleep(2000);
                            boolean allReady = true;
                            for(MigrateThread th : runningList)
                                allReady &= th.isReady();
                            if(!allReady)
                                continue;

                            boolean hasAlive = false;
                            if(pendingList.size() > 0) {
                                System.out.print("pending to be migrated: ");
                                for(MigrateThread th : pendingList)
                                    System.out.print(th.getExchange() + ", ");
                                myConsole.logResponseNL("");
                            }
                            for(MigrateThread th : runningList) {
                                hasAlive |= th.isAlive();
                                if(th.isAlive()){
                                    if(th.getPendingCnt()>0)
                                        myConsole.logResponseNL("[%s] %d messages left", th.getExchange(), th.getPendingCnt());
                                }
                            }
                            if(!hasAlive)
                                break;
                        }

                        for(MigrateThread th : runningList) {
                            myConsole.logResponseNL("[" + th.getExchange() + "] Migration completed! " + th.getMigrateCount() + " messages forwarded");
                            th.join();
                            migrateList.remove(th);
                        }
                    }
                }
                myConsole.logResponse("stopping `%s' ... success%n", broker_ip);
            }
            catch(Exception e) {
                myConsole.logResponse("stopping `%s' ... failed%n", broker_ip);
                myConsole.logResponseNL(e.toString());
            }
            finally{
                try {
                    brokerLock.release();
                    if(brokerLock.getChildren().isEmpty())
                        brokerLock.delete();
                }
                catch(CODIException e) {
                }
            }
        }
View Full Code Here

Examples of com.trendmicro.codi.lock.ZLock

    }
   
    private synchronized boolean checkOnlineStatus() {
        if(statusChanged) {
            String lockPath = tmeRoot + "/locks/brk_" + host;
            ZLock lock = new ZLock(lockPath);
            try {
                logger.info("Waiting for broker lock...");
                lock.acquire(LockType.WRITE_LOCK);
                logger.info("Get broker lock.");
                ZooKeeperInfo.Broker.Status newStatus = getNewStatus();
                if((newStatus == ZooKeeperInfo.Broker.Status.ONLINE) != isOnline) {
                    switch(newStatus) {
                    case OFFLINE:
                        stop();
                        break;
                    case ONLINE:
                        start();
                        break;
                    default:
                        break;
                    }
                }
            }
            catch(Exception e) {
                logger.error(e.getMessage(), e);
            }
            finally {
                try {
                    lock.release();
                    if(lock.getChildren().isEmpty())
                        lock.delete();
                }
                catch(CODIException e) {
                }
            }
           
View Full Code Here

Examples of com.trendmicro.codi.lock.ZLock

            myConsole.logResponseNL("Warning: Can't get authorization information, running under unprotected mode!\n");

        zksm.setDefaultPerms(Id.ANYONE, EnumSet.allOf(Perms.class));

        String lockPath = "/global/tme-console.lock";
        consoleLock = new ZLock(lockPath);

        if(consoleLock.tryAcquire(LockType.WRITE_LOCK, 3000) == false)
            throw new Exception("Cannot get administration lock! Another instance of tme-console might be running, exiting.");
       
        return true;
View Full Code Here

Examples of com.trendmicro.codi.lock.ZLock

            logger.info("client already opened, skip");
            return;
        }
       
        String lockPath = "/exchange/" + exchange.toString() + ".lock";
        ZLock lock = new ZLock(lockPath);
        brokerDetermined = determined;
        try {
            if(brokerDetermined) {
                exchange.setBroker(sessionConfig.getConnection().getHostName());
                logger.info(String.format("exchange %s uses determined broker %s", exchange.getName(), exchange.getBroker()));
                connection = Daemon.getConnection(sessionConfig.getConnection());
            }
            else {
                logger.info("getting exchange lock: " + lockPath);
                lock.acquire(LockType.WRITE_LOCK);
                logger.info("exchange lock: " + lockPath + " acquired");

                exchange.setBroker(ExchangeFarm.getInstance().queryExchangeHost(exchange));
                if(exchange.getBroker() == null)
                    throw new MistException(String.format("can not request broker from MFR for `%s:%s'", isQueue() ? "queue": "topic", getChannelName()));
                logger.info(String.format("request exchange %s, select broker: %s", exchange.getName(), exchange.getBroker()));
                connection = Daemon.getConnection(exchange.getBroker());
            }
           
            if(isResume)
                oldConnection.decreaseReference();
           
            javax.jms.Connection jms_conn = connection.getJMSConnection();
            jms_session = jms_conn.createSession(false, javax.jms.Session.CLIENT_ACKNOWLEDGE);
           
            if(isQueue())
                destination = jms_session.createQueue(exchange.getName());
            else
                destination = jms_session.createTopic(exchange.getName());

            if(isConsumer()) {
                consumer = jms_session.createConsumer(destination);
            }
            else {
                producer = jms_session.createProducer(destination);
                if(getConfig().getChannel().getPersistent())
                    producer.setDeliveryMode(DeliveryMode.PERSISTENT);
                else
                    producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
            }
            logger.info(String.format("attached to %s", getInfo()));

            if(!brokerDetermined) {
                if(!isResume && !isMigrate) {
                    String exchangeRefPath = ExchangeFarm.getInstance().incExchangeRef(exchange);
                    logger.info("exchangeRefPath added: " + exchangeRefPath);
                }
            }
            try {
                BrokerSpy.setExchangeFlowControl(exchange, ExchangeFarm.getDropPolicy(exchange));
            }
            catch(Exception e) {
                logger.error(e.getMessage(), e);
            }
            ZooKeeperInfo.TotalLimit limit = ExchangeFarm.getTotalLimit(exchange);
            try {
                BrokerSpy.setExchangeTotalLimit(exchange, limit.getSizeBytes(), limit.getCount());
            }
            catch(Exception e) {
                logger.error(e.getMessage(), e);
            }
            opened = true;
        }
        catch(JMSException e) {
            logger.error("fail to create session level objects: " + e.getMessage(), e);
            throw new MistException(e.getMessage());
        }
        catch(CODIException e) {
            logger.error(e.getMessage(), e);
            throw new MistException(e.getMessage());
        }
        catch(InterruptedException e) {
            logger.error(e.getMessage(), e);
            throw new MistException(e.getMessage());
        }
        finally {
            if(!brokerDetermined) {
                try {
                    lock.release();
                }
                catch(CODIException e) {
                }
                logger.info("lock released: " + lockPath);
            }
View Full Code Here

Examples of com.trendmicro.codi.lock.ZLock

            }
            opened = false;
        }
       
        String lockPath = "/exchange/" + exchange.toString() + ".lock";
        ZLock lock = new ZLock(lockPath);
        try {
            logger.info("closing jms client");
            if(isConsumer())
                consumer.close();
            else
                producer.close();

            logger.info("closing client: jms_session");
            jms_session.close();
            logger.info(String.format("detached from %s", getInfo()));
            if(!isPause)
                connection.decreaseReference();

            if(!brokerDetermined) {
                logger.info("getting lock: " + lockPath);
                lock.acquire(LockType.WRITE_LOCK);
                logger.info("lock acquired: " + lockPath);
                if(!isPause && !isMigrate)
                    ExchangeFarm.getInstance().decExchangeRef(exchange);
            }
        }
        catch(JMSException e) {
            logger.error("fail to close session level objects: " + e.getMessage(), e);
        }
        catch(CODIException e) {
            logger.error(e.getMessage(), e);
        }
        catch(InterruptedException e) {
            logger.error(e.getMessage(), e);
        }
        finally {
            if(!brokerDetermined) {
                try {
                    lock.release();
                }
                catch(CODIException e) {
                }
                logger.info("lock released: " + lockPath);
            }
View Full Code Here

Examples of com.trendmicro.codi.lock.ZLock

         * The function to recreate the reference node
         */
        public void renewRef() {
            ArrayList<ZNode> refList = allExchangeRefs.get(exchange.toString());
            String lockPath = "/exchange/" + exchange.toString() + ".lock";
            ZLock lock = new ZLock(lockPath);
            try {
                /**
                 * Get the exchange's lock first
                 */
                logger.info("getting exchange lock: " + lockPath);
                lock.acquire(LockType.WRITE_LOCK);
                logger.info("exchange lock: " + lockPath + " acquired");

                /**
                 * If the node does not exist in the refList, it means that it
                 * is discarded by decExchangeRef(), so it can be ignored
                 */
                if(!refList.contains(origNode)) {
                    logger.info("ref Node " + origNode.getPath() + " removed, ignore");
                    return;
                }

                /**
                 * Remove the old node and create a new one
                 */
                refList.remove(origNode);
                String newRefPath = incExchangeRef(exchange);
                logger.info("new ref node created: " + newRefPath);
            }
            catch(Exception e) {
                logger.error(e.getMessage(), e);
            }
            finally {
                try {
                    lock.release();
                }
                catch(Exception e) {
                }
                logger.info("lock released: " + lockPath);
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.