text:
/*
 * (C) 2007-2012 Alibaba Group Holding Limited.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * Authors:
 *   wuhua <wq163@163.com> , boyan <killme2008@gmail.com>
 */
package com.taobao.metamorphosis.client.consumer;

import java.lang.management.ManagementFactory;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.I0Itec.zkclient.IZkChildListener;
import org.I0Itec.zkclient.IZkStateListener;
import org.I0Itec.zkclient.ZkClient;
import org.I0Itec.zkclient.exception.ZkNoNodeException;
import org.I0Itec.zkclient.exception.ZkNodeExistsException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.zookeeper.KeeperException.NoNodeException;
import org.apache.zookeeper.Watcher.Event.KeeperState;

import com.taobao.gecko.core.util.StringUtils;
import com.taobao.gecko.service.exception.NotifyRemotingException;
import com.taobao.metamorphosis.client.RemotingClientWrapper;
import com.taobao.metamorphosis.client.ZkClientChangedListener;
import com.taobao.metamorphosis.client.consumer.storage.OffsetStorage;
import com.taobao.metamorphosis.cluster.Broker;
import com.taobao.metamorphosis.cluster.Cluster;
import com.taobao.metamorphosis.cluster.Partition;
import com.taobao.metamorphosis.exception.MetaClientException;
import com.taobao.metamorphosis.network.RemotingUtils;
import com.taobao.metamorphosis.utils.MetaZookeeper;
import com.taobao.metamorphosis.utils.MetaZookeeper.ZKGroupDirs;
import com.taobao.metamorphosis.utils.MetaZookeeper.ZKGroupTopicDirs;
import com.taobao.metamorphosis.utils.ThreadUtils;
import com.taobao.metamorphosis.utils.ZkUtils;
import com.taobao.metamorphosis.utils.ZkUtils.ZKConfig;

/**
 * ConsumerÓëZookeeper½»»¥
 *
 * @author boyan
 * @Date 2011-4-26
 * @author wuhua
 * @Date 2011-6-26
 */
public class ConsumerZooKeeper implements ZkClientChangedListener {
    protected ZkClient zkClient;
    protected final ConcurrentHashMap<FetchManager, FutureTask<ZKLoadRebalanceListener>> consumerLoadBalanceListeners =
            new ConcurrentHashMap<FetchManager, FutureTask<ZKLoadRebalanceListener>>();
    private final RemotingClientWrapper remotingClient;
    private final ZKConfig zkConfig;
    protected final MetaZookeeper metaZookeeper;

    public ConsumerZooKeeper(final MetaZookeeper metaZookeeper, final RemotingClientWrapper remotingClient,
            final ZkClient zkClient, final ZKConfig zkConfig) {
        super();
        this.metaZookeeper = metaZookeeper;
        this.zkClient = zkClient;
        this.remotingClient = remotingClient;
        this.zkConfig = zkConfig;
    }

    public void commitOffsets(final FetchManager fetchManager) {
        final ZKLoadRebalanceListener listener = this.getBrokerConnectionListener(fetchManager);
        if (listener != null) {
            listener.commitOffsets();
        }
    }

    public ZKLoadRebalanceListener getBrokerConnectionListener(final FetchManager fetchManager) {
        final FutureTask<ZKLoadRebalanceListener> task = this.consumerLoadBalanceListeners.get(fetchManager);
        if (task != null) {
            try {
                return task.get();
            }
            catch (final ExecutionException e) {
                throw ThreadUtils.launderThrowable(e.getCause());
            }
            catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
        return null;
    }

    /**
     * È¡Ïû×¢²áconsumer
     *
     * @param fetchManager
     */
    public void unRegisterConsumer(final FetchManager fetchManager) {
        try {
            final FutureTask<ZKLoadRebalanceListener> futureTask =
                    this.consumerLoadBalanceListeners.remove(fetchManager);
            if (futureTask != null) {
                final ZKLoadRebalanceListener listener = futureTask.get();
                if (listener != null) {
                    listener.stop();
                    // Ìá½»offsets
                    listener.commitOffsets();
                    this.zkClient.unsubscribeStateChanges(new ZKSessionExpireListenner(listener));
                    final ZKGroupDirs dirs = this.metaZookeeper.new ZKGroupDirs(listener.consumerConfig.getGroup());
                    this.zkClient.unsubscribeChildChanges(dirs.consumerRegistryDir, listener);
                    log.info("unsubscribeChildChanges:" + dirs.consumerRegistryDir);
                    // ÒƳý¼àÊÓ¶©ÔÄtopicµÄ·ÖÇø±ä»¯
                    for (final String topic : listener.topicSubcriberRegistry.keySet()) {
                        final String partitionPath = this.metaZookeeper.brokerTopicsSubPath + "/" + topic;
                        this.zkClient.unsubscribeChildChanges(partitionPath, listener);
                        log.info("unsubscribeChildChanges:" + partitionPath);
                    }
                    // ɾ³ýownership
                    listener.releaseAllPartitionOwnership();
                    // ɾ³ýÁÙʱ½Úµã
                    ZkUtils.deletePath(this.zkClient, listener.dirs.consumerRegistryDir + "/"
                            + listener.consumerIdString);

                }
            }
        }
        catch (final InterruptedException e) {
            Thread.currentThread().interrupt();
            log.error("Interrupted when unRegisterConsumer", e);
        }
        catch (final Exception e) {
            log.error("Error in unRegisterConsumer,maybe error when registerConsumer", e);
        }
    }

    /**
     * ×¢²á¶©ÔÄÕß
     *
     * @throws Exception
     */
    public void registerConsumer(final ConsumerConfig consumerConfig, final FetchManager fetchManager,
            final ConcurrentHashMap<String/* topic */, SubscriberInfo> topicSubcriberRegistry,
            final OffsetStorage offsetStorage, final LoadBalanceStrategy loadBalanceStrategy) throws Exception {

        final FutureTask<ZKLoadRebalanceListener> task =
                new FutureTask<ZKLoadRebalanceListener>(new Callable<ZKLoadRebalanceListener>() {

                    @Override
                    public ZKLoadRebalanceListener call() throws Exception {
                        final ZKGroupDirs dirs =
                                ConsumerZooKeeper.this.metaZookeeper.new ZKGroupDirs(consumerConfig.getGroup());
                        final String consumerUUID = ConsumerZooKeeper.this.getConsumerUUID(consumerConfig);
                        final String consumerUUIDString = consumerConfig.getGroup() + "_" + consumerUUID;
                        final ZKLoadRebalanceListener loadBalanceListener =
                                new ZKLoadRebalanceListener(fetchManager, dirs, consumerUUIDString, consumerConfig,
                                    offsetStorage, topicSubcriberRegistry, loadBalanceStrategy);
                        loadBalanceListener.start();
                        return ConsumerZooKeeper.this.registerConsumerInternal(loadBalanceListener);
                    }

                });
        final FutureTask<ZKLoadRebalanceListener> existsTask =
                this.consumerLoadBalanceListeners.putIfAbsent(fetchManager, task);
        if (existsTask == null) {
            task.run();
        }
        else {
            throw new MetaClientException("Consumer has been already registed");
        }

    }

    protected ZKLoadRebalanceListener registerConsumerInternal(final ZKLoadRebalanceListener loadBalanceListener)
            throws UnknownHostException, InterruptedException, Exception {
        final ZKGroupDirs dirs = this.metaZookeeper.new ZKGroupDirs(loadBalanceListener.consumerConfig.getGroup());

        final String topicString = this.getTopicsString(loadBalanceListener.topicSubcriberRegistry);

        if (this.zkClient == null) {
            // Ö±Á¬Ä£Ê½
            loadBalanceListener.fetchManager.stopFetchRunner();
            loadBalanceListener.fetchManager.resetFetchState();
            // zkClientΪnull£¬Ê¹ÓÃÅäÖÃÏî²¢·¢ÆðfetchÇëÇó
            for (final String topic : loadBalanceListener.topicSubcriberRegistry.keySet()) {
                final SubscriberInfo subInfo = loadBalanceListener.topicSubcriberRegistry.get(topic);
                ConcurrentHashMap<Partition, TopicPartitionRegInfo> topicPartRegInfoMap =
                        loadBalanceListener.topicRegistry.get(topic);
                if (topicPartRegInfoMap == null) {
                    topicPartRegInfoMap = new ConcurrentHashMap<Partition, TopicPartitionRegInfo>();
                    loadBalanceListener.topicRegistry.put(topic, topicPartRegInfoMap);
                }
                final Partition partition = new Partition(loadBalanceListener.consumerConfig.getPartition());
                long offset = loadBalanceListener.consumerConfig.getOffset();
                if (loadBalanceListener.consumerConfig.isAlwaysConsumeFromMaxOffset()) {
                    offset = Long.MAX_VALUE;
                }
                final TopicPartitionRegInfo regInfo = new TopicPartitionRegInfo(topic, partition, offset);
                topicPartRegInfoMap.put(partition, regInfo);
                loadBalanceListener.fetchManager.addFetchRequest(new FetchRequest(new Broker(0,
                    loadBalanceListener.consumerConfig.getServerUrl()), 0L, regInfo, subInfo.getMaxSize()));
            }
            loadBalanceListener.fetchManager.startFetchRunner();
        }
        else {
            for (int i = 0; i < MAX_N_RETRIES; i++) {
                // ×¢²áconsumer id
                ZkUtils.makeSurePersistentPathExists(this.zkClient, dirs.consumerRegistryDir);
                ZkUtils.createEphemeralPathExpectConflict(this.zkClient, dirs.consumerRegistryDir + "/"
                        + loadBalanceListener.consumerIdString, topicString);
                // ¼àÊÓͬһ¸ö·Ö×éµÄconsumerÁбíÊÇ·ñÓб仯
                this.zkClient.subscribeChildChanges(dirs.consumerRegistryDir, loadBalanceListener);

                // ¼àÊÓ¶©ÔÄtopicµÄ·ÖÇøÊÇ·ñÓб仯
                for (final String topic : loadBalanceListener.topicSubcriberRegistry.keySet()) {
                    final String partitionPath = this.metaZookeeper.brokerTopicsSubPath + "/" + topic;
                    ZkUtils.makeSurePersistentPathExists(this.zkClient, partitionPath);
                    this.zkClient.subscribeChildChanges(partitionPath, loadBalanceListener);
                }

                // ¼àÊÓzk client״̬£¬ÔÚÁ¬½ÓÖØÁ¬µÄʱºòÖØÐÂ×¢²á
                this.zkClient.subscribeStateChanges(new ZKSessionExpireListenner(loadBalanceListener));

                // µÚÒ»´Î£¬ÐèÒªÃ÷È·´¥·¢balance
                if (loadBalanceListener.syncedRebalance()) {
                    break;
                }
            }
        }
        return loadBalanceListener;
    }

    private String getTopicsString(final ConcurrentHashMap<String/* topic */, SubscriberInfo> topicSubcriberRegistry) {
        final StringBuilder topicSb = new StringBuilder();
        boolean wasFirst = true;
        for (final String topic : topicSubcriberRegistry.keySet()) {
            if (wasFirst) {
                wasFirst = false;
                topicSb.append(topic);
            }
            else {
                topicSb.append(",").append(topic);
            }
        }
        return topicSb.toString();
    }

    protected String getConsumerUUID(final ConsumerConfig consumerConfig) throws Exception {
        String consumerUUID = null;
        if (consumerConfig.getConsumerId() != null) {
            consumerUUID = consumerConfig.getConsumerId();
        }
        else {
          consumerUUID =
            RemotingUtils.getLocalHost() + "-" + this.getPid() + "-" + UUID.randomUUID();
        }
        return consumerUUID;
    }

    private String getPid() {
        final String name = ManagementFactory.getRuntimeMXBean().getName();
        if (name.contains("@")) {
            return name.split("@")[0];
        }
        return name;
    }

    @Override
    public void onZkClientChanged(final ZkClient newClient) {
        this.zkClient = newClient;
        // ÖØÐÂ×¢²áconsumer
        for (final FutureTask<ZKLoadRebalanceListener> task : this.consumerLoadBalanceListeners.values()) {
            try {
                final ZKLoadRebalanceListener listener = task.get();
                // ÒªÇå¿ÕÒÑÓеÄ×¢²áÐÅÏ¢£¬·ÀÖ¹ÔÚ×¢²áconsumerʧ°ÜµÄʱºò»¹Ìá½»offset£¬µ¼Ö¸²¸Ç¸üеÄoffset
                listener.topicRegistry.clear();
                log.info("re-register consumer to zk,group=" + listener.consumerConfig.getGroup());
                this.registerConsumerInternal(listener);
            }
            catch (final Exception e) {
                log.error("reRegister consumer failed", e);
            }
        }

    }

    class ZKSessionExpireListenner implements IZkStateListener {
        private final String consumerIdString;
        private final ZKLoadRebalanceListener loadBalancerListener;

        public ZKSessionExpireListenner(final ZKLoadRebalanceListener loadBalancerListener) {
            super();
            this.consumerIdString = loadBalancerListener.consumerIdString;
            this.loadBalancerListener = loadBalancerListener;
        }

        @Override
        public void handleNewSession() throws Exception {
            /**
             * When we get a SessionExpired event, we lost all ephemeral nodes
             * and zkclient has reestablished a connection for us. We need to
             * release the ownership of the current consumer and re-register
             * this consumer in the consumer registry and trigger a rebalance.
             */
            ;
            log.info("ZK expired; release old broker parition ownership; re-register consumer " + this.consumerIdString);
            this.loadBalancerListener.resetState();
            ConsumerZooKeeper.this.registerConsumerInternal(this.loadBalancerListener);
        }

        @Override
        public void handleStateChanged(final KeeperState state) throws Exception {
            // do nothing, since zkclient will do reconnect for us.

        }

        @Override
        public boolean equals(final Object obj) {
            if (!(obj instanceof ZKSessionExpireListenner)) {
                return false;
            }
            final ZKSessionExpireListenner other = (ZKSessionExpireListenner) obj;
            return this.loadBalancerListener.equals(other.loadBalancerListener);
        }

        @Override
        public int hashCode() {
            return this.loadBalancerListener.hashCode();
        }

    }

    static final int MAX_N_RETRIES = 7;

    static final Log log = LogFactory.getLog(ConsumerZooKeeper.class);

    /**
     * Consumer load balance listener for zookeeper. This is a internal class
     * for consumer,you should not use it directly in your code.
     *
     * @author dennis<killme2008@gmail.com>
     *
     */
    public class ZKLoadRebalanceListener implements IZkChildListener, Runnable {
        private final ZKGroupDirs dirs;

        private final String group;

        protected final String consumerIdString;

        private final LoadBalanceStrategy loadBalanceStrategy;

        Map<String, List<String>> oldConsumersPerTopicMap = new HashMap<String, List<String>>();

        Map<String, List<String>> oldPartitionsPerTopicMap = new HashMap<String, List<String>>();

        private final Lock rebalanceLock = new ReentrantLock();

        /**
         * ¶©ÔĵÄtopic¶ÔÓ¦µÄbroker,offsetµÈÐÅÏ¢
         */
        final ConcurrentHashMap<String/* topic */, ConcurrentHashMap<Partition, TopicPartitionRegInfo>> topicRegistry =
                new ConcurrentHashMap<String, ConcurrentHashMap<Partition, TopicPartitionRegInfo>>();

        /**
         * ¶©ÔÄÐÅÏ¢£¬Èç×î´ó´«Êä´óС£¬ÏûÏ¢¼àÌýÆ÷µÈ
         */
        private final ConcurrentHashMap<String/* topic */, SubscriberInfo> topicSubcriberRegistry;

        private final ConsumerConfig consumerConfig;

        private final OffsetStorage offsetStorage;

        private final FetchManager fetchManager;

        private final Thread rebalanceThread;

        private volatile boolean stopped = false;

        Set<Broker> oldBrokerSet = new HashSet<Broker>();
        private Cluster oldCluster = new Cluster();

        public ZKLoadRebalanceListener(final FetchManager fetchManager, final ZKGroupDirs dirs,
                final String consumerIdString, final ConsumerConfig consumerConfig, final OffsetStorage offsetStorage,
                final ConcurrentHashMap<String/* topic */, SubscriberInfo> topicSubcriberRegistry,
                final LoadBalanceStrategy loadBalanceStrategy) {
            super();
            this.fetchManager = fetchManager;
            this.dirs = dirs;
            this.consumerIdString = consumerIdString;
            this.group = consumerConfig.getGroup();
            this.consumerConfig = consumerConfig;
            this.offsetStorage = offsetStorage;
            this.topicSubcriberRegistry = topicSubcriberRegistry;
            this.loadBalanceStrategy = loadBalanceStrategy;
            this.rebalanceThread = new Thread(this);
        }

        public void start() {
            this.rebalanceThread.start();
        }

        public void stop() {
            this.stopped = true;
            this.rebalanceThread.interrupt();
            try {
                this.rebalanceThread.join(500);
            }
            catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }

        /**
         * ¸üÐÂoffsetµ½zk
         */
        private void commitOffsets() {
            this.offsetStorage.commitOffset(this.consumerConfig.getGroup(), this.getTopicPartitionRegInfos());
        }

        private TopicPartitionRegInfo initTopicPartitionRegInfo(final String topic, final String group,
                final Partition partition, final long offset) {
            this.offsetStorage.initOffset(topic, group, partition, offset);
            return new TopicPartitionRegInfo(topic, partition, offset);
        }

        /**
         * Returns current topic-partitions info.
         *
         * @since 1.4.4
         * @return
         */
        public Map<String/* topic */, Set<Partition>> getTopicPartitions() {
            Map<String, Set<Partition>> rt = new HashMap<String, Set<Partition>>();
            for (Map.Entry<String, ConcurrentHashMap<Partition, TopicPartitionRegInfo>> entry : this.topicRegistry
                    .entrySet()) {
                rt.put(entry.getKey(), entry.getValue().keySet());
            }
            return rt;
        }

        List<TopicPartitionRegInfo> getTopicPartitionRegInfos() {
            final List<TopicPartitionRegInfo> rt = new ArrayList<TopicPartitionRegInfo>();
            for (final ConcurrentHashMap<Partition, TopicPartitionRegInfo> subMap : this.topicRegistry.values()) {
                final Collection<TopicPartitionRegInfo> values = subMap.values();
                if (values != null) {
                    rt.addAll(values);
                }
            }
            return rt;
        }

        /**
         * ¼ÓÔØoffsetÐÅÏ¢
         *
         * @param topic
         * @param partition
         * @return
         */
        private TopicPartitionRegInfo loadTopicPartitionRegInfo(final String topic, final Partition partition) {
            return this.offsetStorage.load(topic, this.consumerConfig.getGroup(), partition);
        }

        private final BlockingQueue<Byte> rebalanceEvents = new ArrayBlockingQueue<Byte>(10);

        private final Byte REBALANCE_EVT = (byte) 1;

        @Override
        public void handleChildChange(final String parentPath, final List<String> currentChilds) throws Exception {
            this.rebalanceEvents.put(this.REBALANCE_EVT);
        }

        @Override
        public void run() {
            while (!this.stopped) {
                try {
                    Byte evt = this.rebalanceEvents.take();
                    if (evt != null) {
                        this.dropDuplicatedEvents();
                        this.syncedRebalance();
                    }
                }
                catch (InterruptedException e) {
                    // continue;
                }
                catch (Throwable e) {
                    log.error("Rebalance failed.", e);
                }
            }

        }

        private void dropDuplicatedEvents() {
            Byte evt = null;
            int count = 0;
            while ((evt = this.rebalanceEvents.poll()) != null) {
                // poll out duplicated events.
                count++;
            }
            if (count > 0) {
                log.info("Drop " + count + " duplicated rebalance events");
            }
        }

        boolean syncedRebalance() throws InterruptedException, Exception {
            this.rebalanceLock.lock();
            try {
                for (int i = 0; i < MAX_N_RETRIES; i++) {
                    log.info("begin rebalancing consumer " + this.consumerIdString + " try #" + i);
                    boolean done;
                    try {
                        done = this.rebalance();
                    }
                    catch (InterruptedException e) {
                        throw e;
                    }
                    catch (final Throwable e) {
                        // ·¢ÉúÁËÔ¤ÁÏÖ®ÍâµÄÒì³£,¶¼ÖØÊÔÒ»ÏÂ,
                        // ÓпÉÄÜÊǶà¸ö»úÆ÷consumerÔÚͬʱrebalanceÔì³ÉµÄ¶ÁÈ¡zkÊý¾Ý²»Ò»ÖÂ,-- wuhua
                        log.warn("unexpected exception occured while try rebalancing", e);
                        done = false;
                    }
                    log.warn("end rebalancing consumer " + this.consumerIdString + " try #" + i);

                    if (done) {
                        log.warn("rebalance success.");
                        return true;
                    }
                    else {
                        log.warn("rebalance failed,try #" + i);
                    }

                    // release all partitions, reset state and retry
                    this.releaseAllPartitionOwnership();
                    this.resetState();
                    // µÈ´ýzkÊý¾Ýͬ²½
                    Thread.sleep(ConsumerZooKeeper.this.zkConfig.zkSyncTimeMs);
                }
                log.error("rebalance failed,finally");
                return false;
            }
            finally {
                this.rebalanceLock.unlock();
            }
        }

        private void resetState() {
            this.topicRegistry.clear();
            this.oldConsumersPerTopicMap.clear();
            this.oldPartitionsPerTopicMap.clear();
        }

        /**
         * ¸üÐÂfetchÏß³Ì
         *
         * @param cluster
         */
        protected void updateFetchRunner(final Cluster cluster) throws Exception {
            this.fetchManager.resetFetchState();
            final Set<Broker> newBrokers = new HashSet<Broker>();
            for (final Map.Entry<String/* topic */, ConcurrentHashMap<Partition, TopicPartitionRegInfo>> entry : this.topicRegistry
                    .entrySet()) {
                final String topic = entry.getKey();
                for (final Map.Entry<Partition, TopicPartitionRegInfo> partEntry : entry.getValue().entrySet()) {
                    final Partition partition = partEntry.getKey();
                    final TopicPartitionRegInfo info = partEntry.getValue();
                    // Ëæ»úÈ¡master»òslaveµÄÒ»¸ö¶Á,wuhua
                    final Broker broker = cluster.getBrokerRandom(partition.getBrokerId());
                    if (broker != null) {
                        newBrokers.add(broker);
                        final SubscriberInfo subscriberInfo = this.topicSubcriberRegistry.get(topic);
                        // Ìí¼ÓfetchÇëÇó
                        this.fetchManager.addFetchRequest(new FetchRequest(broker, 0L, info, subscriberInfo
                            .getMaxSize()));
                    }
                    else {
                        log.error("Could not find broker for broker id " + partition.getBrokerId()
                            + ", it should not happen.");
                    }
                }
            }

            for (Broker newOne : newBrokers) {
                int times = 0;
                NotifyRemotingException ne = null;
                while (times++ < 3) {
                    ConsumerZooKeeper.this.remotingClient.connectWithRef(newOne.getZKString(), this);
                    try {
                        ConsumerZooKeeper.this.remotingClient.awaitReadyInterrupt(newOne.getZKString(), 4000);
                        log.warn("Connected to " + newOne.getZKString());
                        break;
                    }
                    catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                        throw new IllegalStateException("Remoting client is interrupted", e);
                    }
                    catch (NotifyRemotingException e) {
                        times++;
                        ne = e;
                        continue;
                    }
                }
                if (ne != null) {
                    // Throw it to do rebalancing.
                    throw ne;
                }
            }
            // ÖØÐÂÆô¶¯fetchÏß³Ì
            log.warn("Starting fetch runners");
            this.oldBrokerSet = newBrokers;
            this.fetchManager.startFetchRunner();
        }

        boolean rebalance() throws InterruptedException, Exception {

            final Map<String/* topic */, String/* consumerId */> myConsumerPerTopicMap =
                    this.getConsumerPerTopic(this.consumerIdString);
            final Cluster cluster = ConsumerZooKeeper.this.metaZookeeper.getCluster();
            Map<String/* topic */, List<String>/* consumer list */> consumersPerTopicMap = null;
            try {
                consumersPerTopicMap = this.getConsumersPerTopic(this.group);
            }
            catch (final NoNodeException e) {
                // ¶à¸öconsumerͬʱÔÚ¸ºÔؾùºâʱ,¿ÉÄܻᵽ´ïÕâÀï -- wuhua
                log.warn("maybe other consumer is rebalancing now," + e.getMessage());
                return false;
            }
            catch (final ZkNoNodeException e) {
                // ¶à¸öconsumerͬʱÔÚ¸ºÔؾùºâʱ,¿ÉÄܻᵽ´ïÕâÀï -- wuhua
                log.warn("maybe other consumer is rebalancing now," + e.getMessage());
                return false;
            }

            final Map<String, List<String>> partitionsPerTopicMap =
                    this.getPartitionStringsForTopics(myConsumerPerTopicMap);

            final Map<String/* topic */, String/* consumer id */> relevantTopicConsumerIdMap =
                    this.getRelevantTopicMap(myConsumerPerTopicMap, partitionsPerTopicMap,
                        this.oldPartitionsPerTopicMap, consumersPerTopicMap, this.oldConsumersPerTopicMap);
            // ûÓбä¸ü£¬ÎÞÐèƽºâ
            if (relevantTopicConsumerIdMap.size() <= 0) {
                // ´¦ÀíÖ÷±¸Çé¿ö,topic·ÖÇøºÍÏû·ÑÕßûÓб仯,µ«Ö÷±¸µÄÆäÖÐһ̨¹ÒÁË,
                // µ¼ÖÂpartitionsPerTopicMap¿ÉÄÜÊÇûÓб仯µÄ,
                // ËùÒÔÒª¼ì²é¼¯ÈºµÄ±ä»¯²¢ÖØÐÂÁ¬½Ó
                if (this.checkClusterChange(cluster)) {
                    log.warn("Stopping fetch runners,maybe master or slave changed");
                    this.fetchManager.stopFetchRunner();
                    // closed all connections to old brokers.
                    this.closeOldBrokersConnections();
                    this.commitOffsets();
                    this.updateFetchRunner(cluster);
                    this.oldCluster = cluster;
                }
                else {
                    log.warn("Consumer " + this.consumerIdString + " with " + consumersPerTopicMap
                        + " doesn't need to be rebalanced.");
                }
                return true;
            }
            log.warn("Stopping fetch runners");
            this.fetchManager.stopFetchRunner();
            // closed all connections to old brokers.
            this.closeOldBrokersConnections();
            log.warn("Comitting all offsets");
            this.commitOffsets();

            for (final Map.Entry<String, String> entry : relevantTopicConsumerIdMap.entrySet()) {
                final String topic = entry.getKey();
                final String consumerId = entry.getValue();

                final ZKGroupTopicDirs topicDirs =
                        ConsumerZooKeeper.this.metaZookeeper.new ZKGroupTopicDirs(topic, this.group);
                // µ±Ç°¸ÃtopicµÄ¶©ÔÄÕß
                final List<String> curConsumers = consumersPerTopicMap.get(topic);
                // µ±Ç°¸ÃtopicµÄ·ÖÇø
                final List<String> curPartitions = partitionsPerTopicMap.get(topic);

                if (curConsumers == null) {
                    log.warn("Releasing partition ownerships for topic:" + topic);
                    this.releasePartitionOwnership(topic);
                    this.topicRegistry.remove(topic);
                    log.warn("There are no consumers subscribe topic " + topic);
                    continue;
                }
                if (curPartitions == null) {
                    log.warn("Releasing partition ownerships for topic:" + topic);
                    this.releasePartitionOwnership(topic);
                    this.topicRegistry.remove(topic);
                    log.warn("There are no partitions under topic " + topic);
                    continue;
                }

                // ¸ù¾Ý¸ºÔؾùºâ²ßÂÔ»ñÈ¡Õâ¸öconsumer¶ÔÓ¦µÄpartitionÁбí
                final List<String> newParts =
                        this.loadBalanceStrategy.getPartitions(topic, consumerId, curConsumers, curPartitions);

                // ²é¿´µ±Ç°Õâ¸ötopicµÄ·ÖÇøÁÐ±í£¬²é¿´ÊÇ·ñÓбä¸ü
                ConcurrentHashMap<Partition, TopicPartitionRegInfo> partRegInfos = this.topicRegistry.get(topic);
                if (partRegInfos == null) {
                    partRegInfos = new ConcurrentHashMap<Partition, TopicPartitionRegInfo>();
                    this.topicRegistry.put(topic, new ConcurrentHashMap<Partition, TopicPartitionRegInfo>());
                }
                final Set<Partition> currentParts = partRegInfos.keySet();

                for (final Partition partition : currentParts) {
                    // еķÖÇøÁбíÖв»´æÔڵķÖÇø£¬ÐèÒªÊÍ·ÅownerShip£¬Ò²¾ÍÊÇÀϵÄÓУ¬ÐµÄûÓÐ
                    if (!newParts.contains(partition.toString())) {
                        log.warn("Releasing partition ownerships for partition:" + partition);
                        this.releasePartitionOwnership(topic, partition);
                        partRegInfos.remove(partition);
                    }
                }

                for (final String partition : newParts) {
                    // µ±Ç°Ã»ÓеķÖÇø£¬¹ÒÔØÉÏÈ¥£¬Ò²¾ÍÊÇеÄÓУ¬ÀϵÄûÓÐ
                    if (!currentParts.contains(new Partition(partition))) {
                        log.warn(consumerId + " attempting to claim partition " + partition);
                        // ×¢²á·ÖÇøowner¹Øϵ
                        if (!this.ownPartition(topicDirs, partition, topic, consumerId)) {
                            log.warn("Claim partition " + partition + " failed,retry...");
                            return false;
                        }
                    }
                }

            }
            this.updateFetchRunner(cluster);
            this.oldPartitionsPerTopicMap = partitionsPerTopicMap;
            this.oldConsumersPerTopicMap = consumersPerTopicMap;
            this.oldCluster = cluster;

            return true;
        }

        private void closeOldBrokersConnections() throws NotifyRemotingException {
            for (Broker old : this.oldBrokerSet) {
                ConsumerZooKeeper.this.remotingClient.closeWithRef(old.getZKString(), this, false);
                log.warn("Closed " + old.getZKString());
            }
        }

        protected boolean checkClusterChange(final Cluster cluster) {
            return !this.oldCluster.equals(cluster);
        }

        protected Map<String, List<String>> getPartitionStringsForTopics(final Map<String, String> myConsumerPerTopicMap) {
            return ConsumerZooKeeper.this.metaZookeeper.getPartitionStringsForSubTopics(myConsumerPerTopicMap.keySet());
        }

        /**
         * Ìí¼Ó·ÖÇøµÄowner¹Øϵ
         *
         * @param topicDirs
         * @param partition
         * @param topic
         * @param consumerThreadId
         * @return
         */
        protected boolean ownPartition(final ZKGroupTopicDirs topicDirs, final String partition, final String topic,
                final String consumerThreadId) throws Exception {
            final String partitionOwnerPath = topicDirs.consumerOwnerDir + "/" + partition;
            try {
                ZkUtils.createEphemeralPathExpectConflict(ConsumerZooKeeper.this.zkClient, partitionOwnerPath,
                    consumerThreadId);
            }
            catch (final ZkNodeExistsException e) {
                // ԭ'µÄ¹ØϵӦ¸ÃÒѾÉ¾³ý£¬ËùÒÔÉÔºòÔÙÖØÊÔ
                log.info("waiting for the partition ownership to be deleted: " + partition);
                return false;

            }
            catch (final Exception e) {
                throw e;
            }
            this.addPartitionTopicInfo(topicDirs, partition, topic, consumerThreadId);
            return true;
        }

        // »ñÈ¡offsetÐÅÏ¢²¢±£´æµ½±¾µØ
        protected void addPartitionTopicInfo(final ZKGroupTopicDirs topicDirs, final String partitionString,
                final String topic, final String consumerThreadId) {
            final Partition partition = new Partition(partitionString);
            final ConcurrentHashMap<Partition, TopicPartitionRegInfo> partitionTopicInfo =
                    this.topicRegistry.get(topic);
            TopicPartitionRegInfo existsTopicPartitionRegInfo = this.loadTopicPartitionRegInfo(topic, partition);
            if (existsTopicPartitionRegInfo == null) {
                // ³õ'»¯µÄʱºòĬÈÏʹÓÃ0,TODO ¿ÉÄܲÉÓÃÆäËû
                existsTopicPartitionRegInfo =
                        this.initTopicPartitionRegInfo(topic, consumerThreadId, partition,
                            this.consumerConfig.getOffset());// Long.MAX_VALUE
            }
            // If alwaysConsumeFromMaxOffset is set to be true,we always set
            // offset to be Long.MAX_VALUE
            if (this.consumerConfig.isAlwaysConsumeFromMaxOffset()) {
                existsTopicPartitionRegInfo.getOffset().set(Long.MAX_VALUE);
            }
            partitionTopicInfo.put(partition, existsTopicPartitionRegInfo);
        }

        /**
         * ÊÍ·Å·ÖÇøËùÓÐȨ
         */
        private void releaseAllPartitionOwnership() {
            for (final Map.Entry<String, ConcurrentHashMap<Partition, TopicPartitionRegInfo>> entry : this.topicRegistry
                    .entrySet()) {
                final String topic = entry.getKey();
                final ZKGroupTopicDirs topicDirs =
                        ConsumerZooKeeper.this.metaZookeeper.new ZKGroupTopicDirs(topic, this.consumerConfig.getGroup());
                for (final Partition partition : entry.getValue().keySet()) {
                    final String znode = topicDirs.consumerOwnerDir + "/" + partition;
                    this.deleteOwnership(znode);
                }
            }
        }

        /**
         * ÊÍ·ÅÖ¸¶¨·ÖÇøµÄownership
         *
         * @param topic
         * @param partition
         */
        private void releasePartitionOwnership(final String topic, final Partition partition) {
            final ZKGroupTopicDirs topicDirs =
                    ConsumerZooKeeper.this.metaZookeeper.new ZKGroupTopicDirs(topic, this.consumerConfig.getGroup());
            final String znode = topicDirs.consumerOwnerDir + "/" + partition;
            this.deleteOwnership(znode);
        }

        private void deleteOwnership(final String znode) {
            try {
                ZkUtils.deletePath(ConsumerZooKeeper.this.zkClient, znode);
            }
            catch (final Throwable t) {
                log.error("exception during releasePartitionOwnership", t);
            }
            if (log.isDebugEnabled()) {
                log.debug("Consumer " + this.consumerIdString + " releasing " + znode);
            }
        }

        /**
         * ÊÍ·ÅÖ¸¶¨topic¹ØÁª·ÖÇøµÄownership
         *
         * @param topic
         * @param partition
         */
        private void releasePartitionOwnership(final String topic) {
            final ZKGroupTopicDirs topicDirs =
                    ConsumerZooKeeper.this.metaZookeeper.new ZKGroupTopicDirs(topic, this.consumerConfig.getGroup());
            final ConcurrentHashMap<Partition, TopicPartitionRegInfo> partInfos = this.topicRegistry.get(topic);
            if (partInfos != null) {
                for (final Partition partition : partInfos.keySet()) {
                    final String znode = topicDirs.consumerOwnerDir + "/" + partition;
                    this.deleteOwnership(znode);
                }
            }
        }

        /**
         * ·µ»ØÓбä¸üµÄtopic¸úconsumer¼¯ºÏ
         *
         * @param myConsumerPerTopicMap
         * @param newPartMap
         * @param oldPartMap
         * @param newConsumerMap
         * @param oldConsumerMap
         * @return
         */
        private Map<String, String> getRelevantTopicMap(final Map<String, String> myConsumerPerTopicMap,
            final Map<String, List<String>> newPartMap, final Map<String, List<String>> oldPartMap,
            final Map<String, List<String>> newConsumerMap, final Map<String, List<String>> oldConsumerMap) {
            final Map<String, String> relevantTopicThreadIdsMap = new HashMap<String, String>();
            for (final Map.Entry<String, String> entry : myConsumerPerTopicMap.entrySet()) {
                final String topic = entry.getKey();
                final String consumerId = entry.getValue();
                // ÅжϷÖÇø±ä¸ü»òÕ߶©ÔÄÕßÁбíÊÇ·ñ±ä¸ü
                if (!this.listEquals(oldPartMap.get(topic), newPartMap.get(topic))
                        || !this.listEquals(oldConsumerMap.get(topic), newConsumerMap.get(topic))) {
                    relevantTopicThreadIdsMap.put(topic, consumerId);
                }
            }
            return relevantTopicThreadIdsMap;
        }

        private boolean listEquals(final List<String> list1, final List<String> list2) {
            if (list1 == null && list2 != null) {
                return false;
            }
            if (list1 != null && list2 == null) {
                return false;
            }
            if (list1 == null && list2 == null) {
                return true;
            }
            return list1.equals(list2);
        }

        /**
         * »ñȡij¸ö·Ö×鶩ÔĵÄtopicµ½¶©ÔÄÕßÖ®¼äµÄÓ³Éämap
         *
         * @param group
         * @return
         * @throws Exception
         * @throws NoNodeException
         *             ¶à¸öconsumerͬʱÔÚ¸ºÔؾùºâʱ,¿ÉÄÜ»áÅ׳öNoNodeException
         */
        protected Map<String, List<String>> getConsumersPerTopic(final String group) throws Exception, NoNodeException {
            final List<String> consumers =
                    ZkUtils.getChildren(ConsumerZooKeeper.this.zkClient, this.dirs.consumerRegistryDir);
            if (consumers == null) {
                return Collections.emptyMap();
            }
            final Map<String, List<String>> consumersPerTopicMap = new HashMap<String, List<String>>();
            for (final String consumer : consumers) {
                final List<String> topics = this.getTopics(consumer);// ¶à¸öconsumerͬʱÔÚ¸ºÔؾùºâʱ,ÕâÀï¿ÉÄÜ»áÅ׳öNoNodeException£¬--wuhua
                for (final String topic : topics) {
                    if (consumersPerTopicMap.get(topic) == null) {
                        final List<String> list = new ArrayList<String>();
                        list.add(consumer);
                        consumersPerTopicMap.put(topic, list);
                    }
                    else {
                        consumersPerTopicMap.get(topic).add(consumer);
                    }
                }

            }
            // ¶©ÔÄÕßÅÅÐò
            for (final Map.Entry<String, List<String>> entry : consumersPerTopicMap.entrySet()) {
                Collections.sort(entry.getValue());
            }
            return consumersPerTopicMap;
        }

        public Map<String, String> getConsumerPerTopic(final String consumerId) throws Exception {
            final List<String> topics = this.getTopics(consumerId);
            final Map<String/* topic */, String/* consumerId */> rt = new HashMap<String, String>();
            for (final String topic : topics) {
                rt.put(topic, consumerId);
            }
            return rt;
        }

        /**
         * ¸ù¾ÝconsumerId»ñÈ¡¶©ÔĵÄtopicÁбí
         *
         * @param consumerId
         * @return
         * @throws Exception
         */
        protected List<String> getTopics(final String consumerId) throws Exception {
            final String topicsString =
                    ZkUtils.readData(ConsumerZooKeeper.this.zkClient, this.dirs.consumerRegistryDir + "/" + consumerId);
            if (StringUtils.isBlank(topicsString)) {
                return Collections.emptyList();
            }
            final String[] topics = topicsString.split(",");
            final List<String> rt = new ArrayList<String>(topics.length);
            for (final String topic : topics) {
                rt.add(topic);
            }
            return rt;
        }
    }
}


text:
<?php
namespace App\Model\Entity;

use Cake\ORM\Entity;

/**
 * CustomerCreditCard Entity.
 */
class CustomerCreditCard extends Entity
{

}

redpajama_set_name: RedPajamaGithub


text:
#include <irtkImage.h>

#include <irtkFileToImage.h>

#include <irtkHistogram.h>

#include <irtkTransformation.h>

// Default filenames
char *output_name = NULL, *prefix_name = NULL, *suffix_name = NULL, *textfile = NULL;

#define MAX_IMAGES 10000
#define EPSILON    0.001

void usage()
{
	cerr << "Usage: atlas [output] <input1..inputN> <options>" << endl;
	cerr << "" << endl;
	cerr << "Make an atlas from a given set of input images. All input images must have the" << endl;
	cerr << "same voxel lattice. Names of input images can be given on the command line or" << endl;
	cerr << "in a file (see below)." << endl;
	cerr << "" << endl;
	cerr << "If they are named on the command line, images are given equal weighting." << endl;
	cerr << "Different weights can be given if a file with names is provided." << endl;
	cerr << "" << endl;
	cerr << "where <options> is one or more of the following:" << endl;
	cerr << "<-imagenames file>      File containing image names and values to use for weighting." << endl;
	cerr << "                        The format should be one line for each image with" << endl;
	cerr << "                          \"image_name value\"" << endl;
	cerr << "                        on each line. If a mean and sigma value are specified" << endl;
	cerr << "                        with the \'-gaussian\' flag (see below), then the values" << endl;
	cerr << "                        are converted to weights using the corresponding Gaussian" << endl;
	cerr << "                        function. Otherwise, the values in the file are used" << endl;
	cerr << "                        directly as weights." << endl;
	cerr << "<-prefix directory>     Directory in which to find the images." << endl;
	cerr << "<-gaussian mean sigma>  Use Gaussian with mean and sigma for kernel-based smoothing\n";
	cerr << "<-epsilon value>        Epsilon value for ignoring image in kernel-based smoothing " << endl;
	cerr << "                          (default = " << EPSILON << ")" << endl;
	cerr << "<-scaling value>        Scaling value for final atlas (default = 1)\n";
	cerr << "<-norm>                 Normalise intensities before atlas construction " << endl;
	cerr << "<-maxnumber value>      Maxium number of images taken " << endl;
	cerr << "                          (default = off)\n";
	exit(1);
}

template<typename VoxelType> void normalise(irtkGenericImage<VoxelType> *input, irtkGenericImage<double> *output)
{
	int j;
	double mean, std;
	VoxelType *ptr1;
	double *ptr2;

	// Set up input histogram
	cout << "Setting up input histogram...";
	cout.flush();
	VoxelType min, max;
	input->GetMinMax(&min, &max);
	irtkHistogram histogram(max - min + 1);
	histogram.PutMin(min - 0.5);
	histogram.PutMax(max + 0.5);

	ptr1 = input->GetPointerToVoxels();
	for (j = 0; j < input->GetNumberOfVoxels(); j++) {
		histogram.AddSample(*ptr1);
		ptr1++;
	}

	mean = histogram.Mean();
	std = histogram.StandardDeviation();
	cout << "done" << endl;
	cout << "Stats: Mean = " << mean << " SD = " << std << endl;

	ptr1 = input->GetPointerToVoxels();
	ptr2 = output->GetPointerToVoxels();
	for (j = 0; j < input->GetNumberOfVoxels(); j++) {
		*ptr2 = (*ptr1 - mean) / std;
		ptr1++;
		ptr2++;
	}
}

void finalize_atlas(irtkGenericImage<double> *output, double scale, irtkGenericImage<double> *weight)
{
	int i;
	double *ptr2,*ptr3;

	cout << "Constructing average atlas...";
	cout.flush();
	ptr2 = output->GetPointerToVoxels();
	ptr3 = weight->GetPointerToVoxels();
	for (i = 0; i < output->GetNumberOfVoxels(); i++) {
		if(*ptr3 > 0){
			*ptr2 = scale * *ptr2 / *ptr3;
		}else{
			*ptr2 = -1;
		}
		ptr2++;
		ptr3++;
	}
	cout << " done\n";
}

template<typename VoxelType> void add_atlas(irtkGenericImage<VoxelType> *input, irtkGenericImage<double> *output, int norm, double inputweight, irtkGenericImage<double> *weight)
{
	int i;
	double *ptr1, *ptr2, *ptr3;

	cout << inputweight ;
	cout << " Adding input to atlas...";
	cout.flush();

	irtkGenericImage<double> tmp = *input;
	if (norm == true) normalise(input, &tmp);
	tmp *= inputweight;

	if (!(input->GetImageAttributes() == output->GetImageAttributes())
		||!(input->GetImageAttributes() == weight->GetImageAttributes())){
			cerr << "Mismatch of image attributes:" << endl;
			input->GetImageAttributes().Print();
			output->GetImageAttributes().Print();
			weight->GetImageAttributes().Print();
			exit(1);
	}

	ptr1 = tmp.GetPointerToVoxels();
	ptr2 = output->GetPointerToVoxels();
	ptr3 = weight->GetPointerToVoxels();

	for (i = 0; i < input->GetNumberOfVoxels(); i++) {
		if(*ptr1 >= 0){
			*ptr2 += *ptr1;
			*ptr3 += inputweight;
		}

		ptr1++;
		ptr2++;
		ptr3++;
	}

	cout << "done\n";
}

int main(int argc, char **argv)
{
	irtkImage                *input = NULL;
	irtkGenericImage<double> *output = NULL;
	irtkGenericImage<double> *weight = NULL;
	double scale, mean, sigma, epsilon;
	int padding, norm, i, no, ok, image_type, useGaussianWeights, maxiumimage = 10000;

	// Check command line
	if (argc < 4) {
		usage();
	}

	// Parse parameters
	output_name = argv[1];
	argc--;
	argv++;

	// Default: scaling factor
	scale = 1;

	// Default: Use weights directly. Alternatively, convert using Gaussian formula.
	useGaussianWeights = false;

	// Default values for kernel smoothing
	mean = 0;
	sigma = 1;

	// Default: No intensity  normalisation
	norm = false;

	// Default: Epsilon
	epsilon = EPSILON;

	// Default padding
	padding = MIN_GREY;

	// Parse input file names and values
	char **input_name = new char *[MAX_IMAGES];
	double *input_value = new double[MAX_IMAGES];
	double *input_weight = new double[MAX_IMAGES];

	// Parse any remaining paramters
	no = 0;

	while ((argc > 1) && (argv[1][0] != '-')) {
		input_name[no] = argv[1];
		input_weight[no] = 1;
		no++;
		argc--;
		argv++;
	}

	while (argc > 1) {
		ok = false;
		if ((ok == false) && (strcmp(argv[1], "-scaling") == 0)) {
			argc--;
			argv++;
			scale = atof(argv[1]);
			argc--;
			argv++;
			ok = true;
		}
		if ((ok == false) && (strcmp(argv[1], "-gaussian") == 0)) {
			argc--;
			argv++;
			useGaussianWeights = true;
			mean = atof(argv[1]);
			argc--;
			argv++;
			sigma = atof(argv[1]);
			argc--;
			argv++;
			ok = true;
		}
		if ((ok == false) && (strcmp(argv[1], "-norm") == 0)) {
			argc--;
			argv++;
			norm = true;
			ok = true;
		}
		if ((ok == false) && (strcmp(argv[1], "-imagenames") == 0)) {
			argc--;
			argv++;
			textfile = argv[1];
			argc--;
			argv++;
			ok = true;
		}
		if ((ok == false) && (strcmp(argv[1], "-maxnumber") == 0)) {
			argc--;
			argv++;
			maxiumimage = atoi(argv[1]);
			argc--;
			argv++;
			ok = true;
		}
		if ((ok == false) && (strcmp(argv[1], "-padding") == 0)) {
			argc--;
			argv++;
			padding = atoi(argv[1]);
			argc--;
			argv++;
			ok = true;
		}
		if ((ok == false) && (strcmp(argv[1], "-prefix") == 0)) {
			argc--;
			argv++;
			prefix_name = argv[1];
			argc--;
			argv++;
			ok = true;
		}
		if ((ok == false) && (strcmp(argv[1], "-suffix") == 0)) {
			argc--;
			argv++;
			suffix_name = argv[1];
			argc--;
			argv++;
			ok = true;
		}
		if ((ok == false) && (strcmp(argv[1], "-epsilon") == 0)) {
			argc--;
			argv++;
			epsilon = atof(argv[1]);
			argc--;
			argv++;
			ok = true;
		}
		if (ok == false) {
			cerr << "Unknown argument: " << argv[1] << endl << endl;
			usage();
		}
	}

	if (textfile != NULL) {
		ifstream in(textfile);
		if (in.is_open()) {
			while (!in.eof()) {
				input_name[no] = new char[256];
				in >> input_name[no] >> input_value[no];
				if (strlen(input_name[no]) > 0) {

					if (useGaussianWeights == true) {
						// Convert input value to weight based on Gaussian centred at above specified mean.
						input_weight[no] = 1.0 / sqrt(2.0) / sigma * exp(-pow((mean - input_value[no]) / sigma, 2.0) / 2);
					} else {
						// Use input value directly as a weight.
						input_weight[no] = input_value[no];
					}

					if (input_weight[no] > epsilon) {
						no++;
					}
				}
			}
			in.close();
		} else {
			cout << "atlas: Unable to open file " << textfile << endl;
			exit(1);
		}
	}

	if(no > maxiumimage){
		no = maxiumimage;
	}

	// Read and add one input image after the other
	for (i = 0; i < no; i++) {
		char buffer[255];

		// Read input
		if (prefix_name != NULL) {
			sprintf(buffer, "%s%s", prefix_name, input_name[i]);
		} else {
			sprintf(buffer, "%s", input_name[i]);
		}
		input_name[i] = strdup(buffer);
		if (suffix_name != NULL) {
			sprintf(buffer, "%s%s", input_name[i], suffix_name);
		} else {
			sprintf(buffer, "%s", input_name[i]);
		}
		input_name[i] = strdup(buffer);

		// Check what voxel type the first input image has: This voxel type will be used for all calculations
		if (i == 0) {
			irtkFileToImage *reader = irtkFileToImage::New(input_name[i]);
			image_type = reader->GetDataType();
		}

		switch (image_type) {
		case IRTK_VOXEL_UNSIGNED_CHAR: {
			cout << "Reading input image " << input_name[i] << "... ";
			cout.flush();
			input = new irtkGenericImage<unsigned char>(input_name[i]);
			cout << "done" << endl;

			if (i == 0) {
				output = new irtkGenericImage<double>(input->GetImageAttributes());
				weight = new irtkGenericImage<double>(input->GetImageAttributes());
			}

			add_atlas(dynamic_cast<irtkGenericImage<unsigned char> *>(input), output, norm, input_weight[i], weight);

			delete input;

			break;
									   }
		case IRTK_VOXEL_CHAR: {
			cout << "Reading input image " << input_name[i] << "... ";
			cout.flush();
			input = new irtkGenericImage<char>(input_name[i]);
			cout << "done" << endl;

			if (i == 0) {
				output = new irtkGenericImage<double>(input->GetImageAttributes());
				weight = new irtkGenericImage<double>(input->GetImageAttributes());
			}

			add_atlas(dynamic_cast<irtkGenericImage<char> *>(input), output, norm, input_weight[i], weight);

			delete input;

			break;
							  }
		case IRTK_VOXEL_UNSIGNED_SHORT: {
			cout << "Reading input image " << input_name[i] << "... ";
			cout.flush();
			input = new irtkGenericImage<unsigned short>(input_name[i]);
			cout << "done" << endl;

			if (i == 0) {
				output = new irtkGenericImage<double>(input->GetImageAttributes());
				weight = new irtkGenericImage<double>(input->GetImageAttributes());
			}

			add_atlas(dynamic_cast<irtkGenericImage<unsigned short> *>(input), output, norm, input_weight[i], weight);

			delete input;

			break;
										}
		case IRTK_VOXEL_SHORT: {
			cout << "Reading input image " << input_name[i] << "... ";
			cout.flush();
			input = new irtkGenericImage<short>(input_name[i]);
			cout << "done" << endl;

			if (i == 0) {
				output = new irtkGenericImage<double>(input->GetImageAttributes());
				weight = new irtkGenericImage<double>(input->GetImageAttributes());
			}

			add_atlas(dynamic_cast<irtkGenericImage<short> *>(input), output, norm, input_weight[i], weight);

			delete input;

			break;
							   }
		case IRTK_VOXEL_FLOAT: {
			cout << "Reading input image " << input_name[i] << "... ";
			cout.flush();
			input = new irtkGenericImage<float>(input_name[i]);
			cout << "done" << endl;

			if (i == 0) {
				output = new irtkGenericImage<double>(input->GetImageAttributes());
				weight = new irtkGenericImage<double>(input->GetImageAttributes());
			}

			add_atlas(dynamic_cast<irtkGenericImage<float> *>(input), output, norm, input_weight[i], weight);

			delete input;

			break;
							   }
		case IRTK_VOXEL_DOUBLE: {
			cout << "Reading input image " << input_name[i] << "... ";
			cout.flush();
			input = new irtkGenericImage<double>(input_name[i]);
			cout << "done" << endl;

			if (i == 0) {
				output = new irtkGenericImage<double>(input->GetImageAttributes());
				weight = new irtkGenericImage<double>(input->GetImageAttributes());
			}

			add_atlas(dynamic_cast<irtkGenericImage<double> *>(input), output, norm, input_weight[i], weight);

			delete input;

			break;
								}
		default:
			cerr << "Voxel type not supported" << endl;
			exit(1);
		}
	}

	// Finalize atlas
	finalize_atlas(output, scale, weight);

	// Write atlas
	cout << "Writing atlas to " << output_name << " ... ";
	cout.flush();
	output->Write(output_name);
	cout << "done\n";
}


text:
CKEDITOR.plugins.setLang( 'stylescombo', 'bn', {
	label: 'স্টাইল',
	panelTitle: 'Formatting Styles', // MISSING
	panelTitle1: 'Block Styles', // MISSING
	panelTitle2: 'Inline Styles', // MISSING
	panelTitle3: 'Object Styles' // MISSING
} );


text:
    //
//  main.m
//  Demo3
//
//  Created by hanya on 16/3/31.
//  Copyright © 2016年 hanya. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}


text:
namespace Gallio.Icarus.Models
{
    public enum SortOrder
    {
        Ascending,
        Descending
    }
}


text:
<?php

namespace WebFamily\MainBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class WebFamilyMainBundle extends Bundle
{
}


text:
const basePage = require(__srcdir + '/pages/basePage.js');
const { By } = require('selenium-webdriver');

const heading = '.splash-page--heading';
const influxLogo = '[data-testid=logo--influxdb-cloud]';
const versionInfo = '.version-info p';
const creditsLink = '.splash-page--credits a';
const nameInput = 'input[name=username]'; //TODO - see if data-testid can be updated - currently 'input-field' for both name and password inputds
const passwordInput = 'input[name=password]'; //TODO - see if data-testid can be updated
const signinButton = '[data-testid=button]';

const urlCtx = 'signin';

class signinPage extends basePage{

    constructor(driver){
        super(driver);
        this.urlCtx = urlCtx;
    }

    async getHeading(){
        return await this.driver.findElement(By.css(heading));
    }

    async getVersionInfo(){
        return await this.driver.findElement(By.css(versionInfo));
    }

    async getCreditsLink(){
        return await this.driver.findElement(By.css(creditsLink));
    }

    async getNameInput(){
        return await this.driver.findElement(By.css(nameInput));
    }

    async getPasswordInput(){
        return await this.driver.findElement(By.css(passwordInput));
    }

    async getSigninButton(){
        return await this.driver.findElement(By.css(signinButton));
    }

    async getInfluxLogo(){
        return await this.driver.findElement(By.css(influxLogo));
    }

}

module.exports = signinPage;


text:
! { dg-do compile }
! This file must be compiled BEFORE binding_label_tests_10_main.f03, which it
! should be because dejagnu will sort the files.
module binding_label_tests_10
  use iso_c_binding
  implicit none
  integer(c_int), bind(c,name="c_one") :: one
end module binding_label_tests_10

! Do not use dg-final to cleanup-modules


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">

  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title>README</title>

Map data (c) OpenStreetMap contributors, https://www.openstreetmap.org
Extracts created by BBBike, http://extract.bbbike.org
 by Geofabrik, http://geofabrik.de

Please read the OSM wiki how to use shape files.

  https://wiki.openstreetmap.org/wiki/Shapefiles

This shape file was created on: Thu Oct 27 12:44:31 UTC 2016
GPS rectangle coordinates (lng,lat):
Script URL:
Name of area:

We appreciate any feedback, suggestions and a donation! You can support us via
PayPal, Flattr or bank wire transfer: http://www.BBBike.org/community.html

thanks, Wolfram Schneider

--
Your Cycle Route Planner: http://www.BBBike.org
BBBike Map Compare: http://bbbike.org/mc


text:
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Google.Apis.Appengine.v1.Data;
using GoogleCloudExtension.Utils;

namespace GoogleCloudExtension.CloudExplorerSources.Gae
{
    /// <summary>
    /// This class represents a GAE instance in the Properties Window.
    /// </summary>
    internal class InstanceItem : PropertyWindowItemBase
    {
        private readonly Instance _instance;

        public InstanceItem(Instance instance) : base(className: Resources.CloudExplorerGaeInstanceCategory, componentName: instance.Id)
        {
            _instance = instance;
        }

        [LocalizedCategory(nameof(Resources.CloudExplorerGaeInstanceCategory))]
        public string Name => _instance.Name;

        [LocalizedCategory(nameof(Resources.CloudExplorerGaeInstanceCategory))]
        public string Id => _instance.Id;

        [LocalizedCategory(nameof(Resources.CloudExplorerGaeInstanceCategory))]
        public string Availability => _instance.Availability;

        [LocalizedCategory(nameof(Resources.CloudExplorerGaeInstanceCategory))]
        public int? Requests => _instance.Requests;

        [LocalizedCategory(nameof(Resources.CloudExplorerGaeInstanceCategory))]
        public int? Errors => _instance.Errors;

        [LocalizedCategory(nameof(Resources.CloudExplorerGaeInstanceCategory))]
        public float? QPS => _instance.Qps;

        [LocalizedDisplayName(nameof(Resources.CloudExplorerGaeInstanceStartTimeDisplayName))]
        [LocalizedCategory(nameof(Resources.CloudExplorerGaeInstanceCategory))]
        public string StartTime => _instance.StartTime;

        [LocalizedDisplayName(nameof(Resources.CloudExplorerGaeInstanceAppEngineReleaseDisplayName))]
        [LocalizedCategory(nameof(Resources.CloudExplorerGaeInstanceCategory))]
        public string AppEngineRelease => _instance.AppEngineRelease;

        [LocalizedDisplayName(nameof(Resources.CloudExplorerGaeInstanceMemoryUsageDisplayName))]
        [LocalizedCategory(nameof(Resources.CloudExplorerGaeInstanceCategory))]
        public long? MemoryUsage => _instance.MemoryUsage;

        [LocalizedDisplayName(nameof(Resources.CloudExplorerGaeInstanceAverageLatencyDisplayName))]
        [LocalizedCategory(nameof(Resources.CloudExplorerGaeInstanceCategory))]
        public int? AverageLatency => _instance.AverageLatency;

        [LocalizedDisplayName(nameof(Resources.CloudExplorerGaeInstanceVirtualMachineNameDisplayName))]
        [LocalizedCategory(nameof(Resources.CloudExplorerGaeInstanceVirtualMachineCategory))]
        public string VmName => _instance.VmName;

        [LocalizedDisplayName(nameof(Resources.CloudExplorerGaeInstanceVirtualMachineZoneDisplayName))]
        [LocalizedCategory(nameof(Resources.CloudExplorerGaeInstanceVirtualMachineCategory))]
        public string VmZone => _instance.VmZoneName;

        [LocalizedDisplayName(nameof(Resources.CloudExplorerGaeInstanceVirtualMachineIdDisplayName))]
        [LocalizedCategory(nameof(Resources.CloudExplorerGaeInstanceVirtualMachineCategory))]
        public string VmId => _instance.VmId;

        [LocalizedDisplayName(nameof(Resources.CloudExplorerGaeInstanceVirtualMachineStatusDisplayName))]
        [LocalizedCategory(nameof(Resources.CloudExplorerGaeInstanceVirtualMachineCategory))]
        public string VmStatus => _instance.VmStatus;

        public override string ToString() => _instance.VmName;
    }
}


text:
package com.infinitechaos.vpcviewer.web.rest.dto;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.amazonaws.services.ec2.model.Subnet;
import com.amazonaws.services.ec2.model.Tag;
import com.fasterxml.jackson.annotation.JsonCreator;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
public class SubnetDTO {
    private String name;
    private String subnetId;
    private String vpcId;
    private String state;
    private String availabilityZone;
    private String cidrBlock;
    private List<TagDTO> tags = new ArrayList<>();

    public SubnetDTO(final Subnet subnet) {
        this.subnetId = subnet.getSubnetId();
        this.vpcId = subnet.getVpcId();
        this.state = subnet.getState();
        this.availabilityZone = subnet.getAvailabilityZone();
        this.cidrBlock = subnet.getCidrBlock();

        this.tags.addAll(
            subnet.getTags()
                .stream()
                .map(TagDTO::new)
                .collect(Collectors.toList()));

        this.name = subnet.getTags()
            .stream()
            .filter(t -> t.getKey().equals("Name"))
            .findFirst()
            .map(Tag::getValue)
            .orElse("n/a");
    }

    @JsonCreator
    public SubnetDTO() {

    }
}


text:
<!DOCTYPE html>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>在树莓派的archlinux中安装lxde – PeerStudio</title>
    <link rel="dns-prefetch" href="//maxcdn.bootstrapcdn.com">
    <link rel="dns-prefetch" href="//cdnjs.cloudflare.com">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="Peer的博客">
    <meta name="robots" content="all">
    <meta name="author" content="Peer Xu">

    <meta name="keywords" content="">
    <link rel="canonical" href="https://blog.e3rp4y.me/2013/01/03/rpi-install-lxde-on-archlinux/">
    <link rel="alternate" type="application/rss+xml" title="RSS Feed for PeerStudio" href="/feed.xml" />

    <link rel="stylesheet" href="/css/pixyll.css?201901291801" type="text/css">

    <link href='//fonts.googleapis.com/css?family=Merriweather:900,900italic,300,300italic' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Lato:900,300' rel='stylesheet' type='text/css'>

    <meta property="og:locale" content="en_US">
    <meta property="og:type" content="article">
    <meta property="og:title" content="在树莓派的archlinux中安装lxde">
    <meta property="og:description" content="Peer的博客">
    <meta property="og:url" content="https://blog.e3rp4y.me/2013/01/03/rpi-install-lxde-on-archlinux/">
    <meta property="og:site_name" content="PeerStudio">

    <meta name="twitter:card" content="summary" />

        <meta name="twitter:site" content="@PeerXu" />
        <meta name="twitter:creator" content="@PeerXu" />

    <meta name="twitter:title" content="在树莓派的archlinux中安装lxde" />
    <meta name="twitter:description" content="Peer的博客" />
    <meta name="twitter:url" content="https://blog.e3rp4y.me/2013/01/03/rpi-install-lxde-on-archlinux/" />

    <link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png">
    <link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png">
    <link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144x144.png">
    <link rel="apple-touch-icon" sizes="60x60" href="/apple-touch-icon-60x60.png">
    <link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-120x120.png">
    <link rel="apple-touch-icon" sizes="76x76" href="/apple-touch-icon-76x76.png">
    <link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon-152x152.png">
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon-180x180.png">
    <link rel="icon" type="image/png" href="/favicon-192x192.png" sizes="192x192">
    <link rel="icon" type="image/png" href="/favicon-160x160.png" sizes="160x160">
    <link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
    <link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
    <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">

      PeerStudio

        About PeerStudio

        Say Hello

在树莓派的archlinux中安装lxde

  Jan 3, 2013

    1 minute read

  p. archlinux是一个很好的linux发行版, 比raspbian好多了. 况且archlinux的yaourt工具实在是太强大了.

p. 好了,废话不多说了, 直接上代码:

bc. # pacman -Syu
# pacman -S xf86-video-fbdev lxde xorg-xinit dbus
# cat << EOF > ~/.xinitrc
exec startlxde
EOF
# startx

p. 经过漫长的等待之后就可以启动这个 _丑陋的_ 桌面了.

  Please enable JavaScript to view the comments powered by Disqus.

      Theme crafted with <3 by John Otander (@4lpine).

      </> available on GitHub.


text:
<?xml version="1.0"?>

<!--
 Copyright 2003 Sun Microsystems, Inc. All rights reserved.
 SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
-->

<!DOCTYPE faces-config PUBLIC
  "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
  "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">

<faces-config>

  <application>
    <view-handler>
      com.sun.facelets.FaceletViewHandler
    </view-handler>
  </application>

  <navigation-rule>
    <navigation-case>
      <from-outcome>newGame</from-outcome>
      <to-view-id>/guess.jsf</to-view-id>
      <redirect/>
    </navigation-case>
    <navigation-case>
      <from-outcome>win</from-outcome>
      <to-view-id>/win.jsf</to-view-id>
      <redirect/>
    </navigation-case>
    <navigation-case>
      <from-outcome>lose</from-outcome>
      <to-view-id>/lose.jsf</to-view-id>
      <redirect/>
    </navigation-case>
  </navigation-rule>

  <managed-bean>
    <managed-bean-name>visit</managed-bean-name>
    <managed-bean-class>hangman1.Visit</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
  </managed-bean>

  <managed-bean>
    <managed-bean-name>guessesLeftImages</managed-bean-name>
    <managed-bean-class>java.util.ArrayList</managed-bean-class>
    <managed-bean-scope>application</managed-bean-scope>
    <list-entries>
      <value>images/Chalkboard_1x7.png</value>
      <value>images/Chalkboard_1x8.png</value>
      <value>images/Chalkboard_2x7.png</value>
      <value>images/Chalkboard_2x8.png</value>
      <value>images/Chalkboard_3x7.png</value>
      <value>images/Chalkboard_3x8.png</value>
    </list-entries>
  </managed-bean>

  <managed-bean>
    <managed-bean-name>scaffoldImages</managed-bean-name>
    <managed-bean-class>java.util.ArrayList</managed-bean-class>
    <managed-bean-scope>application</managed-bean-scope>
    <list-entries>
      <value>images/scaffold-5.png</value>
      <value>images/scaffold-4.png</value>
      <value>images/scaffold-3.png</value>
      <value>images/scaffold-2.png</value>
      <value>images/scaffold-1.png</value>
      <value>images/scaffold.png</value>
    </list-entries>
  </managed-bean>

  <managed-bean>
    <managed-bean-name>letterImages</managed-bean-name>
    <managed-bean-class>java.util.TreeMap</managed-bean-class>
    <managed-bean-scope>application</managed-bean-scope>
    <map-entries>
      <map-entry>
        <key>#</key>
        <value>images/letter-spacer.png</value>
      </map-entry>
      <map-entry>
        <key>_</key>
        <value>images/Chalkboard_5x3.png</value>
      </map-entry>
      <map-entry>
        <key>a</key>
        <value>images/Chalkboard_1x1.png</value>
      </map-entry>
      <map-entry>
        <key>b</key>
        <value>images/Chalkboard_1x2.png</value>
      </map-entry>
      <map-entry>
        <key>c</key>
        <value>images/Chalkboard_1x3.png</value>
      </map-entry>
      <map-entry>
        <key>d</key>
        <value>images/Chalkboard_1x4.png</value>
      </map-entry>
      <map-entry>
        <key>e</key>
        <value>images/Chalkboard_1x5.png</value>
      </map-entry>
      <map-entry>
        <key>f</key>
        <value>images/Chalkboard_1x6.png</value>
      </map-entry>
      <map-entry>
        <key>g</key>
        <value>images/Chalkboard_2x1.png</value>
      </map-entry>
      <map-entry>
        <key>h</key>
        <value>images/Chalkboard_2x2.png</value>
      </map-entry>
      <map-entry>
        <key>i</key>
        <value>images/Chalkboard_2x3.png</value>
      </map-entry>
      <map-entry>
        <key>j</key>
        <value>images/Chalkboard_2x4.png</value>
      </map-entry>
      <map-entry>
        <key>k</key>
        <value>images/Chalkboard_2x5.png</value>
      </map-entry>
      <map-entry>
        <key>l</key>
        <value>images/Chalkboard_2x6.png</value>
      </map-entry>
      <map-entry>
        <key>m</key>
        <value>images/Chalkboard_3x1.png</value>
      </map-entry>
      <map-entry>
        <key>n</key>
        <value>images/Chalkboard_3x2.png</value>
      </map-entry>
      <map-entry>
        <key>o</key>
        <value>images/Chalkboard_3x3.png</value>
      </map-entry>
      <map-entry>
        <key>p</key>
        <value>images/Chalkboard_3x4.png</value>
      </map-entry>
      <map-entry>
        <key>q</key>
        <value>images/Chalkboard_3x5.png</value>
      </map-entry>
      <map-entry>
        <key>r</key>
        <value>images/Chalkboard_3x6.png</value>
      </map-entry>
      <map-entry>
        <key>s</key>
        <value>images/Chalkboard_4x1.png</value>
      </map-entry>
      <map-entry>
        <key>t</key>
        <value>images/Chalkboard_4x2.png</value>
      </map-entry>
      <map-entry>
        <key>u</key>
        <value>images/Chalkboard_4x3.png</value>
      </map-entry>
      <map-entry>
        <key>v</key>
        <value>images/Chalkboard_4x4.png</value>
      </map-entry>
      <map-entry>
        <key>w</key>
        <value>images/Chalkboard_4x5.png</value>
      </map-entry>
      <map-entry>
        <key>x</key>
        <value>images/Chalkboard_4x6.png</value>
      </map-entry>
      <map-entry>
        <key>y</key>
        <value>images/Chalkboard_5x1.png</value>
      </map-entry>
      <map-entry>
        <key>z</key>
        <value>images/Chalkboard_5x2.png</value>
      </map-entry>
    </map-entries>
  </managed-bean>

</faces-config>


text:
<?php

namespace PhpOffice\Common;

/**
 * XML Reader wrapper
 *
 * @since   0.2.1
 */
class XMLReader
{
    /**
     * DOMDocument object
     *
     * @var \DOMDocument
     */
    private $dom = null;

    /**
     * DOMXpath object
     *
     * @var \DOMXpath
     */
    private $xpath = null;

    /**
     * Get DOMDocument from ZipArchive
     *
     * @param string $zipFile
     * @param string $xmlFile
     * @return \DOMDocument|false
     * @throws \Exception
     */
    public function getDomFromZip($zipFile, $xmlFile)
    {
        if (file_exists($zipFile) === false) {
            throw new \Exception('Cannot find archive file.');
        }

        $zip = new \ZipArchive();
        $zip->open($zipFile);
        $content = $zip->getFromName($xmlFile);
        $zip->close();

        if ($content === false) {
            return false;
        } else {
            return $this->getDomFromString($content);
        }
    }

    /**
     * Get DOMDocument from content string
     *
     * @param string $content
     * @return \DOMDocument
     */
    public function getDomFromString($content)
    {
        $this->dom = new \DOMDocument();
        $this->dom->loadXML($content);

        return $this->dom;
    }

    /**
     * Get elements
     *
     * @param string $path
     * @param \DOMElement $contextNode
     * @return \DOMNodeList
     */
    public function getElements($path, \DOMElement $contextNode = null)
    {
        if ($this->dom === null) {
            return array();
        }
        if ($this->xpath === null) {
            $this->xpath = new \DOMXpath($this->dom);
        }

        if (is_null($contextNode)) {
            return $this->xpath->query($path);
        } else {
            return $this->xpath->query($path, $contextNode);
        }
    }

    /**
     * Get element
     *
     * @param string $path
     * @param \DOMElement $contextNode
     * @return \DOMElement|null
     */
    public function getElement($path, \DOMElement $contextNode = null)
    {
        $elements = $this->getElements($path, $contextNode);
        if ($elements->length > 0) {
            return $elements->item(0);
        } else {
            return null;
        }
    }

    /**
     * Get element attribute
     *
     * @param string $attribute
     * @param \DOMElement $contextNode
     * @param string $path
     * @return string|null
     */
    public function getAttribute($attribute, \DOMElement $contextNode = null, $path = null)
    {
        $return = null;
        if ($path !== null) {
            $elements = $this->getElements($path, $contextNode);
            if ($elements->length > 0) {
                /** @var \DOMElement $node Type hint */
                $node = $elements->item(0);
                $return = $node->getAttribute($attribute);
            }
        } else {
            if ($contextNode !== null) {
                $return = $contextNode->getAttribute($attribute);
            }
        }

        return ($return == '') ? null : $return;
    }

    /**
     * Get element value
     *
     * @param string $path
     * @param \DOMElement $contextNode
     * @return string|null
     */
    public function getValue($path, \DOMElement $contextNode = null)
    {
        $elements = $this->getElements($path, $contextNode);
        if ($elements->length > 0) {
            return $elements->item(0)->nodeValue;
        } else {
            return null;
        }
    }

    /**
     * Count elements
     *
     * @param string $path
     * @param \DOMElement $contextNode
     * @return integer
     */
    public function countElements($path, \DOMElement $contextNode = null)
    {
        $elements = $this->getElements($path, $contextNode);

        return $elements->length;
    }

    /**
     * Element exists
     *
     * @param string $path
     * @param \DOMElement $contextNode
     * @return boolean
     */
    public function elementExists($path, \DOMElement $contextNode = null)
    {
        return $this->getElements($path, $contextNode)->length > 0;
    }
}


text:
X-Google-Original-From: Wanpeng Li <wanpengli@tencent.com>

```c

Dedicated instances are currently disturbed by unnecessary jitter due
to the emulated lapic timers fire on the same pCPUs which vCPUs resident.
There is no hardware virtual timer on Intel for guest like ARM. Both
programming timer in guest and the emulated timer fires incur vmexits.
This patchset tries to avoid vmexit which is incurred by the emulated
timer fires in dedicated instance scenario.

When nohz_full is enabled in dedicated instances scenario, the unpinned
timer will be moved to the nearest busy housekeepers after commit 444969223c8
("sched/nohz: Fix affine unpinned timers mess"). However, KVM always makes
lapic timer pinned to the pCPU which vCPU residents, the reason is explained
by commit 61abdbe0 (kvm: x86: make lapic hrtimer pinned). Actually, these
emulated timers can be offload to the housekeeping cpus since APICv
is really common in recent years. The guest timer interrupt is injected by
posted-interrupt which is delivered by housekeeping cpu once the emulated
timer fires.

This patchset introduces a new kvm module parameter, it is false by default.
The host admin can enable it after fine tuned, e.g. dedicated instances
scenario w/ nohz_full cover the pCPUs which vCPUs resident, several pCPUs
surplus for housekeeping, disable mwait/hlt/pause vmexits to occupy the
pCPUs, fortunately preemption timer is disabled after mwait is exposed
to guest which makes emulated timer offload can be possible.
3%~5% redis performance benefit can be observed on Skylake server.

Wanpeng Li (3):
  KVM: LAPIC: Make lapic timer unpinned when timer is injected by posted-interrupt
  KVM: LAPIC: lapic timer is injected by posted interrupt
  KVM: LAPIC: Ignore timer migration when lapic timer is injected by
    posted-interrupt

 arch/x86/include/asm/kvm_host.h |  1 +
 arch/x86/kvm/lapic.c            | 45 +++++++++++++++++++++++++++++++++++------
 arch/x86/kvm/svm.c              |  5 +++++
 arch/x86/kvm/vmx/vmx.c          |  9 +++++++++
 4 files changed, 54 insertions(+), 6 deletions(-)
```


text:
<!DOCTYPE html>

    <meta charset="utf-8" />
	<meta property="wb:webmaster" content="09651739c4ca0bf6" />
    <title><{$setting.SiteTitle}></title>
    <meta name="keywords" content="<{$setting.SiteKeyWords}>" />
    <meta name="description" content="<{$setting.SiteDescription}>" />
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<{include file="common/sources.html"}>

              <img src="<{$mod_path}>images/load.gif" alt='loader' />

                <{foreach from=$baner item=b_l}>
                <div class="pattern" style="background-image: url(<{$b_l.imaadd}>);">

                <{/foreach}>

					<{foreach from=$baner item=b_l}>

<img src="<{$mod_path}>images/baner_logo.png">

					<{/foreach}>

			Are You Ready?

	<{include file="common/head.html"}>

目的地DESTINATION

                	<{foreach from=$aim item=a_l}>
                    <li class="item<{$a_l.OrderNum}>"><a target="_blank" href="<{$a_l.imalink}>"><img src="<{$a_l.imaadd}>" alt="<{$a_l.advtName}>">

                    <{/foreach}>

主题游THEME TRAVEL

                        <{foreach from=$zhuti item=z_l}>
                        <a target="_blank" href="<{$z_l.imalink}>"><img src="<{$z_l.imaadd}>" alt="<{$z_l.advtName}>">
                        <{/foreach}>

我们的理念OUR IDEA

                	<{foreach from=$linian item=l_l}>

<a target="_blank" href="<{$l_l.imalink}>"><img src="<{$l_l.imaadd}>" alt="<{$l_l.advtName}>">

                    <{/foreach}>

    	<{foreach from=$adv_baner item=a_b_n}>
        <a title="<{$a_b_n.advtName}>" href="<{$a_b_n.imalink}>" style="background:url(<{$a_b_n.imaadd}>) center no-repeat;">
        <{/foreach}>

范儿游资讯NEWS INFORMATION

                    <{foreach from=$news_top item=n_t_l}>

                            <img src="<{$n_t_l.NImg}>" class="post-img" alt="">

                            <a href="/youjiview/<{$n_t_l.ID}>.html">
<{$n_t_l.Newstitle}>

                                    <{$n_t_l.Ndescription}>

<a href="/youjiview/<{$n_t_l.ID}>.html"><{$n_t_l.addtime}>

<a href="/youjiview/<{$n_t_l.ID}>.html"><{$n_t_l.Author}>

<a href="/youjiview/<{$n_t_l.ID}>.html"><{$n_t_l.visit}>

                    <{/foreach}>

更多资讯 >>

                    <{foreach from=$news_vedio item=n_v_l}>

                            <img src="<{$n_v_l.NImg}>" class="post-img" alt="">

                            <a href="/youjiview/<{$n_v_l.ID}>.html">
<{$n_v_l.Newstitle}>

                    <{/foreach}>

更多视频 >>

    <{include file="common/foot.html"}>


text:
"""\
Coverage: code coverage testing for Python

Coverage.py is a Python module that measures code coverage during test execution.
It uses the code analysis tools and tracing hooks provided in the Python standard
library to determine which lines are executable, and which have been executed.
"""

classifiers = """\
Development Status :: 5 - Production/Stable
Environment :: Console
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Operating System :: OS Independent
Programming Language :: Python
Topic :: Software Development :: Quality Assurance
Topic :: Software Development :: Testing
"""

version = '2.85'

from setuptools import setup, find_packages

doclines = __doc__.split("\n")

setup(
    name = 'coverage',
    version = version,
    py_modules = ['coverage'],
    entry_points={
        'console_scripts': [
            'coverage = coverage:main',
        ]
    },
    zip_safe = True,    # __file__ appears in the source, but doesn't break zippy-ness.

    author = 'Ned Batchelder',
    author_email = 'ned@nedbatchelder.com',
    description = doclines[0],
    long_description = "\n".join(doclines[2:]),
    keywords = 'code coverage testing',
    license = 'BSD',
    classifiers = filter(None, classifiers.split("\n")),
    url = 'http://nedbatchelder.com/code/modules/coverage.html',
    download_url = 'http://nedbatchelder.com/code/modules/coverage-%s.tar.gz' % version,
)


text:
package org.apereo.cas.pm;

import org.apereo.cas.adaptors.ldap.LdapIntegrationTestsOperations;
import org.apereo.cas.audit.spi.config.CasCoreAuditConfiguration;
import org.apereo.cas.authentication.credential.UsernamePasswordCredential;
import org.apereo.cas.config.CasCoreUtilConfiguration;
import org.apereo.cas.config.LdapPasswordManagementConfiguration;
import org.apereo.cas.pm.config.PasswordManagementConfiguration;
import org.apereo.cas.util.junit.EnabledIfPortOpen;

import com.unboundid.ldap.sdk.LDAPConnection;
import lombok.SneakyThrows;
import lombok.val;
import org.apereo.inspektr.common.web.ClientInfo;
import org.apereo.inspektr.common.web.ClientInfoHolder;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.ldaptive.BindConnectionInitializer;
import org.ldaptive.Credential;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.annotation.DirtiesContext;

import static org.junit.jupiter.api.Assertions.*;

/**
 * This is {@link LdapPasswordManagementServiceTests}.
 *
 * @author Misagh Moayyed
 * @since 5.3.0
 */
@Tag("Ldap")
@SpringBootTest(classes = {
    RefreshAutoConfiguration.class,
    LdapPasswordManagementConfiguration.class,
    PasswordManagementConfiguration.class,
    CasCoreAuditConfiguration.class,
    CasCoreUtilConfiguration.class
}, properties = {
    "cas.authn.pm.reset.sms.attributeName=telephoneNumber",
    "cas.authn.pm.ldap[0].ldapUrl=ldap://localhost:10389",
    "cas.authn.pm.ldap[0].bindDn=cn=Directory Manager",
    "cas.authn.pm.ldap[0].bindCredential=password",
    "cas.authn.pm.ldap[0].baseDn=ou=people,dc=example,dc=org",
    "cas.authn.pm.ldap[0].searchFilter=cn={user}",
    "cas.authn.pm.ldap[0].type=GENERIC",
    "cas.authn.pm.ldap[0].securityQuestionsAttributes.registeredAddress=roomNumber",
    "cas.authn.pm.ldap[0].securityQuestionsAttributes.postalCode=teletexTerminalIdentifier"
})
@DirtiesContext
@EnabledIfPortOpen(port = 10389)
public class LdapPasswordManagementServiceTests {
    private static final int LDAP_PORT = 10389;

    @Autowired
    @Qualifier("passwordChangeService")
    private PasswordManagementService passwordChangeService;

    @BeforeAll
    @SneakyThrows
    public static void bootstrap() {
        ClientInfoHolder.setClientInfo(new ClientInfo(new MockHttpServletRequest()));
        val localhost = new LDAPConnection("localhost", LDAP_PORT,
            "cn=Directory Manager", "password");
        LdapIntegrationTestsOperations.populateEntries(localhost,
            new ClassPathResource("ldif/ldap-pm.ldif").getInputStream(),
            "ou=people,dc=example,dc=org",
            new BindConnectionInitializer("cn=Directory Manager", new Credential("password")));
    }

    @Test
    public void verifyTokenCreationAndParsing() {
        val token = passwordChangeService.createToken("casuser");
        assertNotNull(token);
        val result = passwordChangeService.parseToken(token);
        assertEquals("casuser", result);
    }

    @Test
    public void verifyPasswordChangedFails() {
        val credential = new UsernamePasswordCredential("caspm", "123456");
        val bean = new PasswordChangeRequest();
        bean.setConfirmedPassword("Mellon");
        bean.setPassword("Mellon");
        bean.setUsername(credential.getUsername());
        assertFalse(passwordChangeService.change(credential, bean));
    }

    @Test
    public void verifyFindEmail() {
        val email = passwordChangeService.findEmail("caspm");
        assertEquals("caspm@example.org", email);
    }

    @Test
    public void verifyFindPhone() {
        val ph = passwordChangeService.findPhone("caspm");
        assertEquals("1234567890", ph);
    }

    @Test
    public void verifyFindSecurityQuestions() {
        val questions = passwordChangeService.getSecurityQuestions("caspm");
        assertEquals(2, questions.size());
        assertTrue(questions.containsKey("RegisteredAddressQuestion"));
        assertEquals("666", questions.get("RegisteredAddressQuestion"));
        assertTrue(questions.containsKey("PostalCodeQuestion"));
        assertEquals("1776", questions.get("PostalCodeQuestion"));
    }
}


text:
<?php

namespace Ingenerator\Pigeonhole;

/**
 * Holder for flash messages that should be displayed to the user on the next full page render
 *
 * @package Ingenerator\Pigeonhole
 */
class Pigeonhole
{

	/**
	 * @var \Session
	 */
	protected $session;

	/**
	 * @var string key to use for storing message collection in the session
	 */
	protected $session_key = 'pigeonhole';

	/**
	 * Create an instance
	 *
	 * @param \Session $session the session instance
	 */
	public function __construct(\Session $session)
    {
        $this->session = $session;
    }

	/**
	 * Add a message for display to the user
	 *
	 * @param Message $message message to display
	 */
	public function add(Message $message)
    {
        $messages = $this->peek();
	    $messages[] = $message;
	    $this->session->set($this->session_key, $messages);
    }

	/**
	 * Whether there are any messages pending for this session
	 *
	 * @return bool
	 */
	public function has_messages()
    {
		return (\count($this->peek()) > 0);
    }

	/**
	 * Retrieve the list of outstanding messages without clearing it
	 *
	 * @return Message[]
	 */
	public function peek()
    {
        return $this->session->get($this->session_key, array());
    }

	/**
	 * Retrieve the list of outstanding messages for display and clear them from the container
	 *
	 * @return Message[]
	 */
	public function clear()
    {
		return $this->session->get_once($this->session_key, array());
    }
}


text:
namespace tudat
{

namespace propagators
{

template class NBodyCowellStateDerivative< double, double >;

#if( BUILD_EXTENDED_PRECISION_PROPAGATION_TOOLS )
template class NBodyCowellStateDerivative< long double, double >;
template class NBodyCowellStateDerivative< double, Time >;
template class NBodyCowellStateDerivative< long double, Time >;
#endif

} // namespace propagators

} // namespace tudat