Package com.google.common.collect

Examples of com.google.common.collect.MapMaker


        } catch (Exception e) {
            throw new ManagerException(e);
        }

        GenericMapMaker mapMaker = null;
        mapMaker = new MapMaker().expireAfterAccess(5, TimeUnit.MINUTES)
            .softValues()
            .evictionListener(new MapEvictionListener<Long, MBeanServerConnection>() {

                public void onEviction(Long nid, MBeanServerConnection mbeanServer) {
                    // do nothing
View Full Code Here


    public CanalController(){
        this(System.getProperties());
    }

    public CanalController(final Properties properties){
        managerClients = new MapMaker().makeComputingMap(new Function<String, CanalConfigClient>() {

            public CanalConfigClient apply(String managerAddress) {
                return getManagerClient(managerAddress);
            }
        });

        // 初始化全局参数设置
        globalInstanceConfig = initGlobalConfig(properties);
        instanceConfigs = new MapMaker().makeMap();
        // 初始化instance config
        initInstanceConfig(properties);

        // 准备canal server
        cid = Long.valueOf(getProperty(properties, CanalConstants.CANAL_ID));
        ip = getProperty(properties, CanalConstants.CANAL_IP);
        if (StringUtils.isEmpty(ip)) {
            ip = AddressUtils.getHostIp();
        }
        port = Integer.valueOf(getProperty(properties, CanalConstants.CANAL_PORT));
        final String zkServers = getProperty(properties, CanalConstants.CANAL_ZKSERVERS);
        if (StringUtils.isNotEmpty(zkServers)) {
            zkclientx = ZkClientx.getZkClient(zkServers);
            // 初始化系统目录
            zkclientx.createPersistent(ZookeeperPathUtils.DESTINATION_ROOT_NODE, true);
            zkclientx.createPersistent(ZookeeperPathUtils.CANAL_CLUSTER_ROOT_NODE, true);
        }
        boolean stopInstanceAsPossible = BooleanUtils.toBoolean(getProperty(properties,
                                                                            CanalConstants.CANAL_STOPINSTANCEASPOSSIBLE));

        final ServerRunningData serverData = new ServerRunningData(cid, ip + ":" + port);
        ServerRunningMonitors.setServerData(serverData);
        ServerRunningMonitors.setRunningMonitors(new MapMaker().makeComputingMap(new Function<String, ServerRunningMonitor>() {

            public ServerRunningMonitor apply(final String destination) {
                ServerRunningMonitor runningMonitor = new ServerRunningMonitor(serverData);
                runningMonitor.setDestination(destination);
                runningMonitor.setListener(new ServerRunningListener() {

                    public void processActiveEnter() {
                        try {
                            MDC.put(CanalConstants.MDC_DESTINATION, String.valueOf(destination));
                            embededCanalServer.start(destination);
                        } finally {
                            MDC.remove(CanalConstants.MDC_DESTINATION);
                        }
                    }

                    public void processActiveExit() {
                        try {
                            MDC.put(CanalConstants.MDC_DESTINATION, String.valueOf(destination));
                            embededCanalServer.stop(destination);
                        } finally {
                            MDC.remove(CanalConstants.MDC_DESTINATION);
                        }
                    }

                    public void processStart() {
                        try {
                            if (zkclientx != null) {
                                final String path = ZookeeperPathUtils.getDestinationClusterNode(destination, ip + ":"
                                                                                                              + port);
                                initCid(path);
                                zkclientx.subscribeStateChanges(new IZkStateListener() {

                                    public void handleStateChanged(KeeperState state) throws Exception {

                                    }

                                    public void handleNewSession() throws Exception {
                                        initCid(path);
                                    }
                                });
                            }
                        } finally {
                            MDC.remove(CanalConstants.MDC_DESTINATION);
                        }
                    }

                    public void processStop() {
                        try {
                            MDC.put(CanalConstants.MDC_DESTINATION, String.valueOf(destination));
                            if (zkclientx != null) {
                                final String path = ZookeeperPathUtils.getDestinationClusterNode(destination, ip + ":"
                                                                                                              + port);
                                releaseCid(path);
                            }
                        } finally {
                            MDC.remove(CanalConstants.MDC_DESTINATION);
                        }
                    }

                });
                if (zkclientx != null) {
                    runningMonitor.setZkClient(zkclientx);
                }
                return runningMonitor;
            }
        }));

        embededCanalServer = new CanalServerWithEmbeded();
        embededCanalServer.setCanalInstanceGenerator(instanceGenerator);// 设置自定义的instanceGenerator
        canalServer = new CanalServerWithNetty(embededCanalServer);
        canalServer.setIp(ip);
        canalServer.setPort(port);
        canalServer.setStopInstanceAsPossible(stopInstanceAsPossible);

        // 初始化monitor机制
        autoScan = BooleanUtils.toBoolean(getProperty(properties, CanalConstants.CANAL_AUTO_SCAN));
        if (autoScan) {
            defaultAction = new InstanceAction() {

                public void start(String destination) {
                    InstanceConfig config = instanceConfigs.get(destination);
                    if (config == null) {
                        config = new InstanceConfig(globalInstanceConfig);
                        instanceConfigs.put(destination, config);
                    }

                    if (!config.getLazy() && !embededCanalServer.isStart(destination)) {
                        // HA机制启动
                        ServerRunningMonitor runningMonitor = ServerRunningMonitors.getRunningMonitor(destination);
                        if (!runningMonitor.isStart()) {
                            runningMonitor.start();
                        }
                    }
                }

                public void stop(String destination) {
                    // 此处的stop,代表强制退出,非HA机制,所以需要退出HA的monitor和配置信息
                    InstanceConfig config = instanceConfigs.remove(destination);
                    if (config != null) {
                        embededCanalServer.stop(destination);
                        ServerRunningMonitor runningMonitor = ServerRunningMonitors.getRunningMonitor(destination);
                        if (runningMonitor.isStart()) {
                            runningMonitor.stop();
                        }
                    }
                }

                public void reload(String destination) {
                    // 目前任何配置变化,直接重启,简单处理
                    stop(destination);
                    start(destination);
                }
            };

            instanceConfigMonitors = new MapMaker().makeComputingMap(new Function<InstanceMode, InstanceConfigMonitor>() {

                public InstanceConfigMonitor apply(InstanceMode mode) {
                    int scanInterval = Integer.valueOf(getProperty(properties, CanalConstants.CANAL_AUTO_SCAN_INTERVAL));

                    if (mode.isSpring()) {
View Full Code Here

    // 第一层tableId,第二层schema.table,解决tableId重复,对应多张表
    private Map<String, TableMeta> tableMetaCache;

    public TableMetaCache(MysqlConnection con){
        this.connection = con;
        tableMetaCache = new MapMaker().makeComputingMap(new Function<String, TableMeta>() {

            public TableMeta apply(String name) {
                try {
                    return getTableMeta0(name);
                } catch (IOException e) {
View Full Code Here

        invalidationListeners = new LinkedHashSet<IInvalidationListener>();

        swcManager = new SWCManager(this);
        mxmlDataManager = new MXMLDataManager();

        projects = new MapMaker().weakKeys().makeMap();
        pathToFileSpecMap = new HashMap<String, IFileSpecification>();
        pathToCompilationUnitMapping = new StringToCompilationUnitMap();
        includeFilesToIncludingCompilationUnitMapping = new StringToCompilationUnitMap();

        packageNamespaceDefinitionCache = new PackageNamespaceDefinitionCache();
View Full Code Here

  private ApplicationDataMapDb buildApplicationDataTemplate(ApplicationDb application, String personId, String count) {
    ApplicationDataMapDb applicationDataMap = new ApplicationDataMapDb();
    applicationDataMap.setApplication(application);
    applicationDataMap.setPersonId(personId);
    Map<String, String> values = new MapMaker().makeMap();
    if (null != count) {
      values.put("count", count);
    }
    applicationDataMap.setValues(values);
    return applicationDataMap;
View Full Code Here

      mediaItem2.setUrl("http://www.archive.org/download/testmp3testfile/mpthreetest.mp3");
      mediaItems.add(mediaItem1);
      mediaItems.add(mediaItem2);
      activity.setMediaItems(mediaItems);
      activity.setPostedTime(1111111111L);
      Map<String, String> templateParams = new MapMaker().makeMap();
      templateParams.put("small", "true");
      templateParams.put("otherContent", "and got wet");
      activity.setTemplateParams(templateParams);
      activity.setTitle("My trip");
      activity.setTitleId("1");
      activity.setUpdated(new Date());
      activity.setUrl("http://www.example.org/canonical/activities/1");

    } else if ("2".equals(id)) {
      activity.setBody("Went skiing");
      activity.setBodyId("2");
      activity.setExternalId("http://www.example.org/123457");
      List<MediaItem> mediaItems = new ArrayList<MediaItem>();
      activity.setMediaItems(mediaItems);
      activity.setPostedTime(1111111112L);
      Map<String, String> templateParams = new MapMaker().makeMap();
      templateParams.put("small", "true");
      templateParams.put("otherContent", "and went fast");
      activity.setTemplateParams(templateParams);
      activity.setTitle("My next trip");
      activity.setTitleId("2");
View Full Code Here

  }

  @Test
  public void updateJohnDoeApplicationDataSettingCountTo5() throws Exception {
    // Do update
    Map<String, String> values = new MapMaker().makeMap();
    values.put("count", "5");
    this.appDataServiceDb.updatePersonData(new UserId(Type.userId, "john.doe"), new GroupId(GroupId.Type.self, "@self"), DEFAULT_APPLICATION_ID, SpiTestUtil.asSet("count"), values, SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN);

    // Verify that update succeeded
    Future<DataCollection> results = this.appDataServiceDb.getPersonData(SpiTestUtil.buildUserIds("john.doe"), new GroupId(GroupId.Type.self, "@self"), DEFAULT_APPLICATION_ID, null, SpiTestUtil.DEFAULT_TEST_SECURITY_TOKEN);
View Full Code Here

    public CacheService<K, V> newCacheService()
    {
        if ( map == null )
        {
            map = new MapMaker().concurrencyLevel( concurrencyLevel ).initialCapacity( initialCapacity ).makeMap();
        }
        if ( memoryManager == null )
        {
            memoryManager = new MemoryManagerServiceImpl<V>();
        }
View Full Code Here

    private void pumpWithOneAllocation( int ops, byte[] payload )
    {

        ConcurrentMap<String, ByteBuffer> test =
            new MapMaker().concurrencyLevel( 4 ).maximumSize( ops ).expireAfterWrite( 10, TimeUnit.MINUTES ).makeMap();

        logger.info( Ram.inMb( ops * payload.length ) + " in " + ops + " slices to store" );

        ByteBuffer bulk = ByteBuffer.allocateDirect( ops * payload.length );

View Full Code Here

    }

    private void pump( int ops )
    {
        ConcurrentMap<String, ByteBuffer> test =
            new MapMaker().concurrencyLevel( 4 ).maximumSize( ops ).expireAfterWrite( 10, TimeUnit.MINUTES ).makeMap();

        logger.info( Ram.inMb( ops * payload.length ) + " to store" );

        double started = System.currentTimeMillis();

View Full Code Here

TOP

Related Classes of com.google.common.collect.MapMaker

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