當前位置: 首頁>>代碼示例>>Java>>正文


Java IMap.addEntryListener方法代碼示例

本文整理匯總了Java中com.hazelcast.core.IMap.addEntryListener方法的典型用法代碼示例。如果您正苦於以下問題:Java IMap.addEntryListener方法的具體用法?Java IMap.addEntryListener怎麽用?Java IMap.addEntryListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.hazelcast.core.IMap的用法示例。


在下文中一共展示了IMap.addEntryListener方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import com.hazelcast.core.IMap; //導入方法依賴的package包/類
public static void main(String[] args) {
	HazelcastInstance ins = Hazelcast.newHazelcastInstance();
	IMap<Integer, String> map = ins.getMap("");
	map.addEntryListener(new ListenerExample(), true);//添加自定義監聽器
	map.put(1, "Grand Theft Auto");
	map.put(1, "Final Fantasy");
	map.put(2, "World Of Warcraft");
	
	HazelcastInstance insex = Hazelcast.newHazelcastInstance();
	IMap<Integer, String> mapex = insex.getMap("");
	
	System.out.println(mapex.get(1));
	System.out.println(mapex.get(2));
	mapex.remove(1);
	mapex.remove(2);
	System.exit(0);
}
 
開發者ID:chkui,項目名稱:hazelcast-demo,代碼行數:18,代碼來源:ListenerDemo.java

示例2: initBean

import com.hazelcast.core.IMap; //導入方法依賴的package包/類
private void initBean(RefreshableConfiguration refreshableConfiguration) {
    IMap<String, String> configMap = hazelcastInstance.getMap(TENANT_CONFIGURATION_MAP);

    configMap.forEach((key, value) -> {
        if (refreshableConfiguration.isListeningConfiguration(key)) {

            log.info(
                "Process config init event: [key = {}, size = {}, newHash = {}] in bean: [{}]",
                key,
                StringUtils.length(value),
                getValueHash(value),
                getBeanName(refreshableConfiguration));

            refreshableConfiguration.onInit(key, value);
        }
    });

    log.info("refreshable configuration bean [{}] initialized by configMap with {} entries",
             getBeanName(refreshableConfiguration), configMap.size());

    final boolean includeValue = true;
    configMap.addEntryListener((EntryAddedListener<String, String>) e -> {
        onEntryChange(refreshableConfiguration, e, configMap);
    }, includeValue);
    configMap.addEntryListener((EntryRemovedListener<String, String>) e -> {
        onEntryChange(refreshableConfiguration, e, configMap);
    }, includeValue);
    configMap.addEntryListener((EntryUpdatedListener<String, String>) e -> {
        onEntryChange(refreshableConfiguration, e, configMap);
    }, includeValue);
}
 
開發者ID:xm-online,項目名稱:xm-commons,代碼行數:32,代碼來源:InitRefreshableConfigurationBeanPostProcessor.java

示例3: listen

import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@PostConstruct
public void listen() {
    if (hazelcastInstance != null) {
        IMap map = hazelcastInstance.getMap(HazelcastDestinationDiscoveryDelegate.DESTINATION_DISCOVERY_REQUEST);
        map.addEntryListener(this, true);
        if (LOG.isDebugEnabled())
            LOG.debug("Now listening on: " + HazelcastDestinationDiscoveryDelegate.DESTINATION_DISCOVERY_REQUEST);
    } else {
        throw new IllegalStateException("Could not create hazelcast instance to listen through");
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:12,代碼來源:HazelcastDestinationDiscoveryRequestListener.java

示例4: DistributedConfigManager

import com.hazelcast.core.IMap; //導入方法依賴的package包/類
public DistributedConfigManager(String key, RateLimitingSettings initial, IMap<String, RateLimitingSettings> map,
		ConfigWatcher<RateLimitingSettings> watcher, String configPersistencePath) {
	this.configMap = map;
	this.configKey = key;
	this.externalWatcher = watcher;
	this.configPersistencePath = configPersistencePath;

	JMXConfig jmxConf = initial.getJmxConfig();
	if (jmxConf != null) {
		MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

		accessor = new ConfigurationAccessor(new ConfigWatcher<RateLimitingSettings>() {
			@Override
			public void configChanged(RateLimitingSettings settings) {
				externalWatcher.configChanged(settings);

				logger.info("Configuration changed with MBean, persisting to map");
				try {
					configMap.put(configKey, settings);
				} catch (Exception e) {
					logger.error("Error putting", e);
				}

				persistConfigurationMap();
			}

			@Override
			public RateLimitingSettings refreshConfig() {
				RateLimitingSettings newSettings = externalWatcher.refreshConfig();
				logger.info("Configuration refreshed, persisting to map");
				try {
					configMap.put(configKey, newSettings);
				} catch (Exception e) {
					logger.error("Error putting", e);
				}
				return newSettings;
			}
		}, initial);

		try {
			ObjectName name = new ObjectName(jmxConf.getConfigDomainPrefix() + "." + key + ":name=" + JmxName);
			logger.info("Registering configuration bean with name=" + name.toString());
			mbs.registerMBean(accessor, name);
		} catch (Exception e) {
			logger.error("Error registering configuration MBean with key='" + key
					+ "'. Will proceed without dynamic configuration.", e);
		}
	} else {
		logger.warn("No JMX settings present, configuration will not be externally managed");
	}

	configMap.put(key, initial);
	map.addEntryListener(new EntryWatcher(new ConfigWatcher<RateLimitingSettings>() {
		@Override
		public void configChanged(RateLimitingSettings settings) {
			logger.info("Configuration updated in map; propagating");
			accessor.updateConfiguration(settings);
			externalWatcher.configChanged(settings);
			persistConfigurationMap();
		}

		@Override
		public RateLimitingSettings refreshConfig() {
			return externalWatcher.refreshConfig();
		}
	}), key, true);
}
 
開發者ID:akharchuk,項目名稱:rate-limiting,代碼行數:68,代碼來源:DistributedConfigManager.java

示例5: HazelcastMapConsumer

import com.hazelcast.core.IMap; //導入方法依賴的package包/類
public HazelcastMapConsumer(HazelcastInstance hazelcastInstance, Endpoint endpoint, Processor processor, String cacheName) {
    super(hazelcastInstance, endpoint, processor, cacheName);

    IMap<Object, Object> cache = hazelcastInstance.getMap(cacheName);
    cache.addEntryListener(new CamelMapListener(this, cacheName), true);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:7,代碼來源:HazelcastMapConsumer.java


注:本文中的com.hazelcast.core.IMap.addEntryListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。