当前位置: 首页>>代码示例>>Java>>正文


Java ClasspathXmlConfig类代码示例

本文整理汇总了Java中com.hazelcast.config.ClasspathXmlConfig的典型用法代码示例。如果您正苦于以下问题:Java ClasspathXmlConfig类的具体用法?Java ClasspathXmlConfig怎么用?Java ClasspathXmlConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClasspathXmlConfig类属于com.hazelcast.config包,在下文中一共展示了ClasspathXmlConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: perform

import com.hazelcast.config.ClasspathXmlConfig; //导入依赖的package包/类
/**
 * Establishes Hazelcast cluster and once required number of clients connect, execute multiple document insertion.
 */
@Override
public void perform(DefaultProperties properties) throws IOException {
	Config config = new ClasspathXmlConfig("hazelcast/hazelcast-master.xml");
	String address = properties.getProperty(ClusterConstants.CLUSTER_MASTER_PROP);
	config.getNetworkConfig().setPublicAddress(address);

	HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
	try {
		InsertProperties insProperties = new InsertProperties(properties);
		init(hz, properties, insProperties);
		InetSocketAddress establishedAddress = hz.getCluster().getLocalMember().getSocketAddress();
		LOGGER.info("Cluster established at {}", establishedAddress);
		executeSend(properties, insProperties);
		LOGGER.info("Sending on master node finished");
		waitForAllClientShutdown(hz.getClientService());
	} catch (InterruptedException ex) {
		LOGGER.error("Thread interrupted: ", ex);
	} finally {
		hz.shutdown();
	}
}
 
开发者ID:kucera-jan-cz,项目名称:esBench,代码行数:25,代码来源:MasterNodeInsertAction.java

示例2: createGrids

import com.hazelcast.config.ClasspathXmlConfig; //导入依赖的package包/类
@BeforeClass
    public static void createGrids() {
		/* Suppress Hazelcast log output to standard error which does not appear to be suppressible via Agent Server's
		 * log4j.xml. */
//        ConsoleOutputSuppressor.suppressStandardError();
        final Config standardConfig1 = new ClasspathXmlConfig("hazelcast1.xml"),
                standardConfig2 = new ClasspathXmlConfig("hazelcast2.xml");

        standardConfig1.setProperty("hazelcast.operation.call.timeout.millis", "3000");
        standardConfig2.setProperty("hazelcast.operation.call.timeout.millis", "3000");
        grid1 = Hazelcast.newHazelcastInstance(standardConfig1);
        grid2 = Hazelcast.newHazelcastInstance(standardConfig2);

        dataStructureFactory1 = HazelcastDataStructureFactory.getInstance(grid1);
        dataStructureFactory2 = HazelcastDataStructureFactory.getInstance(grid2);

        lockService1 = new DistributedLockUtils().new PublicDistributedLockService(dataStructureFactory1);
        lockService2 = new DistributedLockUtils().new PublicDistributedLockService(dataStructureFactory2);
    }
 
开发者ID:ThoughtWire,项目名称:hazelcast-locks,代码行数:20,代码来源:HazelcastReentrantReadWriteLockTest.java

示例3: testNativeClient

import com.hazelcast.config.ClasspathXmlConfig; //导入依赖的package包/类
@Test
public void testNativeClient() throws Exception {
    HazelcastInstance main = Hazelcast.newHazelcastInstance(new ClasspathXmlConfig("hazelcast-custom.xml"));
    Properties props = getDefaultProperties();
    props.setProperty(CacheEnvironment.USE_NATIVE_CLIENT, "true");
    props.setProperty(CacheEnvironment.NATIVE_CLIENT_GROUP, "dev-custom");
    props.setProperty(CacheEnvironment.NATIVE_CLIENT_PASSWORD, "dev-pass");
    props.setProperty(CacheEnvironment.NATIVE_CLIENT_ADDRESS, "localhost");
    SessionFactory sf = createSessionFactory(props);
    HazelcastInstance hz = HazelcastAccessor.getHazelcastInstance(sf);
    assertTrue(hz instanceof HazelcastClient);
    assertEquals(1, main.getCluster().getMembers().size());
    HazelcastClient client = (HazelcastClient) hz;
    ClientConfig clientConfig = client.getClientConfig();
    assertEquals("dev-custom", clientConfig.getGroupConfig().getName());
    assertEquals("dev-pass", clientConfig.getGroupConfig().getPassword());
    Hazelcast.newHazelcastInstance(new ClasspathXmlConfig("hazelcast-custom.xml"));
    assertEquals(2, hz.getCluster().getMembers().size());
    main.getLifecycleService().shutdown();
    Thread.sleep(1000 * 2); // let client to reconnect
    assertEquals(1, hz.getCluster().getMembers().size());
    sf.close();
    Hazelcast.shutdownAll();
}
 
开发者ID:mdogan,项目名称:hazelcast-archive,代码行数:25,代码来源:CustomPropertiesTest.java

示例4: configureCluster

import com.hazelcast.config.ClasspathXmlConfig; //导入依赖的package包/类
private void configureCluster(IConfig config) throws FileNotFoundException {
    LOG.info("Configuring embedded Hazelcast instance");
    String interceptHandlerClassname = config.getProperty(BrokerConstants.INTERCEPT_HANDLER_PROPERTY_NAME);
    if (interceptHandlerClassname == null || !HZ_INTERCEPT_HANDLER.equals(interceptHandlerClassname)) {
        LOG.info("There are no Hazelcast intercept handlers. The server won't start a Hazelcast instance.");
        return;
    }
    String hzConfigPath = config.getProperty(BrokerConstants.HAZELCAST_CONFIGURATION);
    if (hzConfigPath != null) {
        boolean isHzConfigOnClasspath = this.getClass().getClassLoader().getResource(hzConfigPath) != null;
        Config hzconfig = isHzConfigOnClasspath
                ? new ClasspathXmlConfig(hzConfigPath)
                : new FileSystemXmlConfig(hzConfigPath);
        LOG.info("Starting Hazelcast instance. ConfigurationFile={}", hzconfig);
        hazelcastInstance = Hazelcast.newHazelcastInstance(hzconfig);
    } else {
        LOG.info("Starting Hazelcast instance with default configuration");
        hazelcastInstance = Hazelcast.newHazelcastInstance();
    }
    listenOnHazelCastMsg();
}
 
开发者ID:andsel,项目名称:moquette,代码行数:22,代码来源:Server.java

示例5: withHazelcast

import com.hazelcast.config.ClasspathXmlConfig; //导入依赖的package包/类
protected void withHazelcast(int numInstances, Consumer<HazelcastInstance> f) {
    int initialPort = 5701;
    List<HazelcastInstance> instances =
            IntStream
                    .rangeClosed(1, numInstances)
                    .mapToObj(i -> {
                        ClasspathXmlConfig config = new ClasspathXmlConfig("hazelcast.xml");
                        config.setInstanceName("MyHazelcastInstance-" + (initialPort + i - 1));
                        return Hazelcast.newHazelcastInstance(config);
                    })
                    .collect(Collectors.toList());

    try {
        f.accept(instances.get(0));
    } finally {
        instances
                .stream()
                .forEach(h -> h.getLifecycleService().shutdown());
        Hazelcast.shutdownAll();
    }
}
 
开发者ID:kazuhira-r,项目名称:hazelcast-examples,代码行数:22,代码来源:HazelcastTestSupport.java

示例6: getHazelcast

import com.hazelcast.config.ClasspathXmlConfig; //导入依赖的package包/类
public synchronized HazelcastInstance getHazelcast() {
	if (hazelcast == null) {
		Config config = new ClasspathXmlConfig("org/j2server/j2cache/cache/hazelcast/hazelcast-cache-config.xml");
           config.setInstanceName("j2cache");
           hazelcast = Hazelcast.newHazelcastInstance(config);
	}
	
	return hazelcast;
}
 
开发者ID:mini188,项目名称:j2cache,代码行数:10,代码来源:HazelcastLocal.java

示例7: main

import com.hazelcast.config.ClasspathXmlConfig; //导入依赖的package包/类
public static void main(String[] args) throws FileNotFoundException {
	//加载配置
	Config config = new ClasspathXmlConfig("org/palm/hazelcast/map/store/mapStoreConfig.xml");
	//创建Hazelcast实力
	HazelcastInstance ins = Hazelcast.newHazelcastInstance(config);
	//获取Map
	Map<Integer, String> map = ins.getMap("demo");
	println(map.get(1));//输出第一条数据
	
	map.put(11, "Moonbrook");//添加一条数据
	println(map.get(11));//输出第一条数据
	
	map.remove(11);//移除添加的数据
	println(map.get(11));//输出被移除的数据
}
 
开发者ID:chkui,项目名称:hazelcast-demo,代码行数:16,代码来源:MapStoreExampleMain.java

示例8: main

import com.hazelcast.config.ClasspathXmlConfig; //导入依赖的package包/类
public static void main(String[] args) {
	// 从classpath加载配置文件
	Config config = new ClasspathXmlConfig("xmlconfig/simple-config.xml");
	// 获取网络配置
	NetworkConfig netConfig = config.getNetworkConfig();
	// 获取用户定义的map配置
	MapConfig mapConfigXml = config.getMapConfig("demo.config");
	// 获取系统默认的map配置
	MapConfig mapConfigDefault = config.getMapConfig("default");
	// 输出集群监听的起始端口号
	System.out.println("Current port:" + netConfig.getPort());
	// 输出监听端口的累加号
	System.out.println("Current port count:" + netConfig.getPortCount());
	// 输出自定义map的备份副本个数
	System.out.println("Config map backup count:" + mapConfigXml.getBackupCount());
	// 输出默认map的备份副本个数
	System.out.println("Default map backup count:" + mapConfigDefault.getBackupCount());

	// 测试创建Hazelcast实例并读写测试数据
	HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
	HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);

	Map<Integer, String> defaultMap1 = instance1.getMap("defaultMap");
	defaultMap1.put(1, "testMap");
	Map<Integer, String> configMap1 = instance1.getMap("configMap");
	configMap1.put(1, "configMap");

	Map<Integer, String> testMap2 = instance2.getMap("defaultMap");
	System.out.println("Default map value:" + testMap2.get(1));
	Map<Integer, String> configMap2 = instance2.getMap("configMap");
	System.out.println("Config map value:" + configMap2.get(1));
}
 
开发者ID:chkui,项目名称:hazelcast-demo,代码行数:33,代码来源:HazelcastConfigSimple.java

示例9: embeddedHazelcast

import com.hazelcast.config.ClasspathXmlConfig; //导入依赖的package包/类
@Bean
public HazelcastInstance embeddedHazelcast() {
	Config hazelcastConfig = new ClasspathXmlConfig(
			"org/springframework/session/hazelcast/config/annotation/web/http/hazelcast-custom-map-name.xml");
	NetworkConfig netConfig = new NetworkConfig();
	netConfig.setPort(SocketUtils.findAvailableTcpPort());
	hazelcastConfig.setNetworkConfig(netConfig);
	return Hazelcast.newHazelcastInstance(hazelcastConfig);
}
 
开发者ID:spring-projects,项目名称:spring-session,代码行数:10,代码来源:HazelcastHttpSessionConfigurationXmlTests.java

示例10: testLiteMember

import com.hazelcast.config.ClasspathXmlConfig; //导入依赖的package包/类
@Test
public void testLiteMember() throws Exception {
    HazelcastInstance main = Hazelcast.newHazelcastInstance(new ClasspathXmlConfig("hazelcast-custom.xml"));
    Properties props = getDefaultProperties();
    props.setProperty(CacheEnvironment.USE_LITE_MEMBER, "true");
    SessionFactory sf = createSessionFactory(props);
    HazelcastInstance hz = HazelcastAccessor.getHazelcastInstance(sf);
    assertTrue(hz.getCluster().getLocalMember().isLiteMember());
    assertEquals(2, main.getCluster().getMembers().size());
    sf.close();
    main.getLifecycleService().shutdown();
}
 
开发者ID:mdogan,项目名称:hazelcast-archive,代码行数:13,代码来源:CustomPropertiesTest.java

示例11: testXmlPartitionGroupConfig

import com.hazelcast.config.ClasspathXmlConfig; //导入依赖的package包/类
@Test
public void testXmlPartitionGroupConfig() {
    Config config = new ClasspathXmlConfig("hazelcast-fullconfig.xml");
    PartitionGroupConfig partitionGroupConfig = config.getPartitionGroupConfig();
    Assert.assertFalse(partitionGroupConfig.isEnabled());
    Assert.assertEquals(MemberGroupType.CUSTOM, partitionGroupConfig.getGroupType());
    Assert.assertEquals(2, partitionGroupConfig.getMemberGroupConfigs().size());
}
 
开发者ID:mdogan,项目名称:hazelcast-archive,代码行数:9,代码来源:PartitionStateGeneratorTest.java

示例12: doMain

import com.hazelcast.config.ClasspathXmlConfig; //导入依赖的package包/类
public void doMain(final String[] args) throws UnknownHostException, SocketException {
    final Enumeration e = NetworkInterface.getNetworkInterfaces();
    while (e.hasMoreElements()) {
        final Enumeration ee = ((NetworkInterface) e.nextElement()).getInetAddresses();
        while (ee.hasMoreElements()) {
            final InetAddress inetAddress = (InetAddress) ee.nextElement();
            if (inetAddress.isLinkLocalAddress()) {
                continue;
            }
            if (inetAddress.isLoopbackAddress()) {
                continue;
            }
            m_inetAddress = inetAddress;
        }
    }
    if (args.length > 0) {
        final HazelcastInstance hazelcastInstance = HazelcastClient.newHazelcastClient();
        try {
            final String hostAddress = m_inetAddress == null ? "0.0.0.0" : m_inetAddress.getHostAddress();
            hazelcastInstance.<String>getTopic(args[0]).publish(hostAddress);
        } finally {
            hazelcastInstance.shutdown();
        }
    } else if (args.length == 0) {
        final Config config = new ClasspathXmlConfig("hazelcast.xml");
        m_hazelcastInstance = Hazelcast.newHazelcastInstance(config);
        m_hazelcastInstance.<String>getTopic("stop").addMessageListener(this);
        m_hazelcastInstance.<String>getTopic("shutdown").addMessageListener(new MessageListener<String>() {
            @Override
            public void onMessage(final Message<String> message) {
                m_hazelcastInstance.shutdown();
            }
        });
    }
}
 
开发者ID:mraad,项目名称:HZSpatial,代码行数:36,代码来源:HZServer.java

示例13: withHazelcast

import com.hazelcast.config.ClasspathXmlConfig; //导入依赖的package包/类
protected void withHazelcast(int numInstances, Consumer<HazelcastInstance> f) {
    List<HazelcastInstance> hazelcastInstances =
            IntStream
                    .rangeClosed(1, numInstances)
                    .mapToObj(i -> Hazelcast.newHazelcastInstance(new ClasspathXmlConfig("hazelcast.xml")))
                    .collect(Collectors.toList());

    try {
        f.accept(hazelcastInstances.get(0));
    } finally {
        hazelcastInstances.forEach(h -> h.getLifecycleService().shutdown());
        Hazelcast.shutdownAll();
    }
}
 
开发者ID:kazuhira-r,项目名称:hazelcast-examples,代码行数:15,代码来源:HazelcastReliableTopicTest.java

示例14: withHazelcast

import com.hazelcast.config.ClasspathXmlConfig; //导入依赖的package包/类
protected void withHazelcast(String configFilePath, int numInstances, Consumer<HazelcastInstance> consumer) {
    List<HazelcastInstance> hazelcastInstances = IntStream
            .rangeClosed(1, numInstances)
            .mapToObj(i -> {
                ClasspathXmlConfig config = new ClasspathXmlConfig(configFilePath);
                return Hazelcast.newHazelcastInstance(config);
            })
            .collect(Collectors.toList());

    hazelcastInstances.forEach(h -> h.getLifecycleService().shutdown());
}
 
开发者ID:kazuhira-r,项目名称:hazelcast-examples,代码行数:12,代码来源:LiteMemberTest.java

示例15: withHazelcast

import com.hazelcast.config.ClasspathXmlConfig; //导入依赖的package包/类
protected void withHazelcast(int numInstances, Consumer<HazelcastInstance> consumer) {
    List<HazelcastInstance> hazelcastInstances =
            IntStream
                    .rangeClosed(1, numInstances)
                    .mapToObj(i -> Hazelcast.newHazelcastInstance(new ClasspathXmlConfig("hazelcast.xml")))
                    .collect(Collectors.toList());

    try {
        consumer.accept(hazelcastInstances.get(0));
    } finally {
        hazelcastInstances.forEach(h -> h.getLifecycleService().shutdown());
        Hazelcast.shutdownAll();
    }
}
 
开发者ID:kazuhira-r,项目名称:hazelcast-examples,代码行数:15,代码来源:HazelcastRingbufferTest.java


注:本文中的com.hazelcast.config.ClasspathXmlConfig类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。