Java 类com.hazelcast.config.GroupConfig 实例源码

项目:hazelcast-archive    文件:ManagementCenterService.java   
public TimedMemberState getTimedMemberState() {
    if (latestThisMemberState == null) {
        updateLocalState();
    }
    GroupConfig groupConfig = factory.getConfig().getGroupConfig();
    TimedMemberState timedMemberState = new TimedMemberState();
    timedMemberState.setMaster(factory.node.isMaster());


    if (timedMemberState.getMaster()) {
        timedMemberState.setMemberList(new ArrayList<String>());
        for (Address addr : addresses) {
            timedMemberState.getMemberList().add(addr.getHost() + ":" + addr.getPort());
        }
    }
    timedMemberState.setMemberState(latestThisMemberState);
    timedMemberState.setClusterName(groupConfig.getName());
    timedMemberState.setInstanceNames(getLongInstanceNames());
    return timedMemberState;
}
项目:hazelcast-archive    文件:TestClientApp.java   
private void connect(String[] args) {
    String ip = "localhost";
    String groupName = "dev";
    String pass = "dev-pass";
    if (args.length > 0) {
        ip = args[0];
    }
    if (args.length > 2) {
        groupName = args[1];
        pass = args[2];
    }
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setGroupConfig(new GroupConfig(groupName, pass));
    System.out.println("Connecting to " + ip);
    String[] ips = null;
    if (ip.indexOf(':') == -1) {
        ips = new String[]{ip + ":5701", ip + ":5702", ip + ":5703"};
    } else {
        ips = new String[]{ip};
    }
    clientConfig.addAddress(ips);
    this.hz = HazelcastClient.newHazelcastClient(clientConfig);
    System.out.println(hz.getCluster().getMembers());
}
项目:hazelcast-archive    文件:DynamicClusterTest.java   
@Test
public void testAuthenticate
        () {
    String grName = "dev";
    String grPass = "pass";
    Config conf = new Config();
    conf.setProperty(GroupProperties.PROP_WAIT_SECONDS_BEFORE_JOIN, "1");
    GroupConfig gc = new GroupConfig();
    gc.setName(grName);
    gc.setPassword(grPass);
    conf.setGroupConfig(gc);
    HazelcastInstance h = Hazelcast.newHazelcastInstance(conf);
    client = newHazelcastClient(grName, grPass, h);
    Map map = client.getMap("aasd");
    client.shutdown();
    h.shutdown();
}
项目:hazelcast-archive    文件:DynamicClusterTest.java   
@Test
public void testAuthenticateWithEmptyPass
        () {
    String grName = "dev";
    String grPass = "";
    Config conf = new Config();
    GroupConfig gc = new GroupConfig();
    gc.setName(grName);
    gc.setPassword(grPass);
    conf.setGroupConfig(gc);
    HazelcastInstance h = Hazelcast.newHazelcastInstance(conf);
    client = newHazelcastClient(grName, "", h);
    Map map = client.getMap("aasd");
    client.shutdown();
    h.shutdown();
}
项目:hazelcast-archive    文件:DynamicClusterTest.java   
@Test(expected = RuntimeException.class)
public void testAuthenticateWrongPass
        () {
    String grName = "dev";
    String grPass = "pass";
    Config conf = new Config();
    GroupConfig gc = new GroupConfig();
    gc.setName(grName);
    gc.setPassword(grPass);
    conf.setGroupConfig(gc);
    HazelcastInstance h = Hazelcast.newHazelcastInstance(conf);
    client = newHazelcastClient(grName, "wrong-pass", h);
    Map map = client.getMap("aasd");
    client.shutdown();
    h.shutdown();
}
项目:hazelcast-archive    文件:DynamicClusterTest.java   
@Test
public void twoClientsAndTransaction() {
    Config config1 = new XmlConfigBuilder().build();
    config1.setProperty(GroupProperties.PROP_WAIT_SECONDS_BEFORE_JOIN, "1");
    Config config2 = new XmlConfigBuilder().build();
    config2.setProperty(GroupProperties.PROP_WAIT_SECONDS_BEFORE_JOIN, "1");
    GroupConfig gConfig1 = new GroupConfig("g1", "pg1");
    GroupConfig gConfig2 = new GroupConfig("g2", "pg2");
    config1.setGroupConfig(gConfig1);
    config2.setGroupConfig(gConfig2);
    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config1);
    HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config2);
    HazelcastInstance client1 = TestUtility.newHazelcastClient(h1);
    HazelcastInstance client2 = TestUtility.newHazelcastClient(h2);
    Transaction t1 = client1.getTransaction();
    Transaction t2 = client2.getTransaction();
    t1.begin();
    client1.getMap("map").put(1, 4);
    t1.commit();
    client1.shutdown();
    client2.shutdown();
    h1.shutdown();
    h2.shutdown();
}
项目:health-and-care-developer-network    文件:ManagementCenterService.java   
public byte[] changeWebServerUrlOverCluster(String groupName, String groupPass, String newUrl) {
    try {
        GroupConfig groupConfig = factory.getConfig().getGroupConfig();
        if (!(groupConfig.getName().equals(groupName) && groupConfig.getPassword().equals(groupPass)))
            return HttpCommand.RES_403;
        ManagementCenterConfigCallable callable = new ManagementCenterConfigCallable(newUrl);
        callable.setHazelcastInstance(factory);
        Set<Member> members = factory.getCluster().getMembers();
        MultiTask<Void> task = new MultiTask<Void>(callable, members);
        ExecutorService executorService = factory.getExecutorService();
        executorService.execute(task);
    } catch (Throwable throwable) {
        logger.log(Level.WARNING, "New web server url cannot be assigned.", throwable);
        return HttpCommand.RES_500;
    }
    return HttpCommand.RES_204;
}
项目:health-and-care-developer-network    文件:ManagementCenterService.java   
private TimedMemberState getTimedMemberState() {
    if (running.get()) {
        final MemberStateImpl memberState = new MemberStateImpl();
        createMemberState(memberState);
        GroupConfig groupConfig = factory.getConfig().getGroupConfig();
        TimedMemberState timedMemberState = new TimedMemberState();
        timedMemberState.setMaster(factory.node.isMaster());
        if (timedMemberState.getMaster()) {
            timedMemberState.setMemberList(new ArrayList<String>());
            Set<Member> memberSet = factory.getCluster().getMembers();
            for (Member member : memberSet) {
                MemberImpl memberImpl = (MemberImpl) member;
                Address address = memberImpl.getAddress();
                timedMemberState.getMemberList().add(address.getHost() + ":" + address.getPort());
            }
        }

        timedMemberState.setExecutorList(getExecutorNames());
        timedMemberState.setMemberState(memberState);
        timedMemberState.setClusterName(groupConfig.getName());
        timedMemberState.setInstanceNames(getLongInstanceNames());
        return timedMemberState;
    }
    return null;
}
项目:health-and-care-developer-network    文件:TestClientApp.java   
private void connect(String[] args) {
    String ip = "localhost";
    String groupName = "dev";
    String pass = "dev-pass";
    if (args.length > 0) {
        ip = args[0];
    }
    if (args.length > 2) {
        groupName = args[1];
        pass = args[2];
    }
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setGroupConfig(new GroupConfig(groupName, pass));
    System.out.println("Connecting to " + ip);
    String[] ips = null;
    if (ip.indexOf(':') == -1) {
        ips = new String[]{ip + ":5701", ip + ":5702", ip + ":5703"};
    } else {
        ips = new String[]{ip};
    }
    clientConfig.addAddress(ips);
    this.hz = HazelcastClient.newHazelcastClient(clientConfig);
    System.out.println(hz.getCluster().getMembers());
}
项目:health-and-care-developer-network    文件:DynamicClusterTest.java   
@Test
public void testAuthenticate
        () {
    String grName = "dev";
    String grPass = "pass";
    Config conf = new Config();
    conf.setProperty(GroupProperties.PROP_WAIT_SECONDS_BEFORE_JOIN, "1");
    GroupConfig gc = new GroupConfig();
    gc.setName(grName);
    gc.setPassword(grPass);
    conf.setGroupConfig(gc);
    HazelcastInstance h = Hazelcast.newHazelcastInstance(conf);
    client = newHazelcastClient(grName, grPass, h);
    Map map = client.getMap("aasd");
    client.shutdown();
    h.shutdown();
}
项目:health-and-care-developer-network    文件:DynamicClusterTest.java   
@Test
public void testAuthenticateWithEmptyPass
        () {
    String grName = "dev";
    String grPass = "";
    Config conf = new Config();
    GroupConfig gc = new GroupConfig();
    gc.setName(grName);
    gc.setPassword(grPass);
    conf.setGroupConfig(gc);
    HazelcastInstance h = Hazelcast.newHazelcastInstance(conf);
    client = newHazelcastClient(grName, "", h);
    Map map = client.getMap("aasd");
    client.shutdown();
    h.shutdown();
}
项目:health-and-care-developer-network    文件:DynamicClusterTest.java   
@Test(expected = RuntimeException.class)
public void testAuthenticateWrongPass
        () {
    String grName = "dev";
    String grPass = "pass";
    Config conf = new Config();
    GroupConfig gc = new GroupConfig();
    gc.setName(grName);
    gc.setPassword(grPass);
    conf.setGroupConfig(gc);
    HazelcastInstance h = Hazelcast.newHazelcastInstance(conf);
    client = newHazelcastClient(grName, "wrong-pass", h);
    Map map = client.getMap("aasd");
    client.shutdown();
    h.shutdown();
}
项目:health-and-care-developer-network    文件:DynamicClusterTest.java   
@Test
public void twoClientsAndTransaction() {
    Config config1 = new XmlConfigBuilder().build();
    config1.setProperty(GroupProperties.PROP_WAIT_SECONDS_BEFORE_JOIN, "1");
    Config config2 = new XmlConfigBuilder().build();
    config2.setProperty(GroupProperties.PROP_WAIT_SECONDS_BEFORE_JOIN, "1");
    GroupConfig gConfig1 = new GroupConfig("g1", "pg1");
    GroupConfig gConfig2 = new GroupConfig("g2", "pg2");
    config1.setGroupConfig(gConfig1);
    config2.setGroupConfig(gConfig2);
    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config1);
    HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config2);
    HazelcastInstance client1 = TestUtility.newHazelcastClient(h1);
    HazelcastInstance client2 = TestUtility.newHazelcastClient(h2);
    Transaction t1 = client1.getTransaction();
    Transaction t2 = client2.getTransaction();
    t1.begin();
    client1.getMap("map").put(1, 4);
    t1.commit();
    client1.shutdown();
    client2.shutdown();
    h1.shutdown();
    h2.shutdown();
}
项目:dpCms    文件:HazelcastSessionDao.java   
public HazelcastSessionDao() {
    log.info("Initializing Hazelcast Shiro session persistence..");

    // configure Hazelcast instance
    final Config cfg = new Config();
    cfg.setInstanceName(hcInstanceName);
    // group configuration
    cfg.setGroupConfig(new GroupConfig(HC_GROUP_NAME, HC_GROUP_PASSWORD));
    // network configuration initialization
    final NetworkConfig netCfg = new NetworkConfig();
    netCfg.setPortAutoIncrement(true);
    netCfg.setPort(HC_PORT);
    // multicast
    final MulticastConfig mcCfg = new MulticastConfig();
    mcCfg.setEnabled(false);
    mcCfg.setMulticastGroup(HC_MULTICAST_GROUP);
    mcCfg.setMulticastPort(HC_MULTICAST_PORT);
    // tcp
    final TcpIpConfig tcpCfg = new TcpIpConfig();
    tcpCfg.addMember("127.0.0.1");
    tcpCfg.setEnabled(false);
    // network join configuration
    final JoinConfig joinCfg = new JoinConfig();
    joinCfg.setMulticastConfig(mcCfg);
    joinCfg.setTcpIpConfig(tcpCfg);
    netCfg.setJoin(joinCfg);
    // ssl
    netCfg.setSSLConfig(new SSLConfig().setEnabled(false));

    // get map
    map = Hazelcast.newHazelcastInstance(cfg).getMap(HC_MAP);
    log.info("Hazelcast Shiro session persistence initialized.");
}
项目:docker-hazelcast-mapstore-cassandra    文件:HazelcastWorker.java   
private ClientConfig getConfig() {
  final ClientConfig clientConfig = new ClientConfig();
  clientConfig.setGroupConfig(new GroupConfig(Constants.HC_GROUP_NAME,
      Constants.HC_GROUP_PASSWORD));
  clientConfig.setClassLoader(getClass().getClassLoader());

  return clientConfig;
}
项目:hazelcast-jet    文件:SerializableClientConfig.java   
SerializableClientConfig(ClientConfig clientConfig) {
    GroupConfig groupConfig = clientConfig.getGroupConfig();
    List<String> addresses = clientConfig.getNetworkConfig().getAddresses();
    this.groupName = groupConfig.getName();
    this.groupPass = groupConfig.getPassword();
    this.addresses = addresses;
}
项目:hazelcast-mapstore-postgres-cassandra    文件:HazelcastWorker.java   
private ClientConfig getConfig() {
  final ClientConfig clientConfig = new ClientConfig();
  clientConfig.setGroupConfig(new GroupConfig(Constants.HC_GROUP_NAME,
      Constants.HC_GROUP_PASSWORD));
  clientConfig.setClassLoader(getClass().getClassLoader());

  return clientConfig;
}
项目:spring-boot-shiro-orientdb    文件:HazelcastSessionDao.java   
public HazelcastSessionDao() {
    log.info("Initializing Hazelcast Shiro session persistence..");

    // configure Hazelcast instance
    final Config cfg = new Config();
    cfg.setInstanceName(hcInstanceName);
    // group configuration
    cfg.setGroupConfig(new GroupConfig(HC_GROUP_NAME, HC_GROUP_PASSWORD));
    // network configuration initialization
    final NetworkConfig netCfg = new NetworkConfig();
    netCfg.setPortAutoIncrement(true);
    netCfg.setPort(HC_PORT);
    // multicast
    final MulticastConfig mcCfg = new MulticastConfig();
    mcCfg.setEnabled(false);
    mcCfg.setMulticastGroup(HC_MULTICAST_GROUP);
    mcCfg.setMulticastPort(HC_MULTICAST_PORT);
    // tcp
    final TcpIpConfig tcpCfg = new TcpIpConfig();
    tcpCfg.addMember("127.0.0.1");
    tcpCfg.setEnabled(false);
    // network join configuration
    final JoinConfig joinCfg = new JoinConfig();
    joinCfg.setMulticastConfig(mcCfg);
    joinCfg.setTcpIpConfig(tcpCfg);
    netCfg.setJoin(joinCfg);
    // ssl
    netCfg.setSSLConfig(new SSLConfig().setEnabled(false));

    // get map
    map = Hazelcast.newHazelcastInstance(cfg).getMap(HC_MAP);
    log.info("Hazelcast Shiro session persistence initialized.");
}
项目:fabric8-cxf-shiro    文件:HazelcastSessionDao.java   
public HazelcastSessionDao() {
  log.info("Initializating Hazelcast Shiro session persistence..");

  // configure Hazelcast instance
  hcInstanceName = UUID.randomUUID().toString();
  Config cfg = new Config();
  cfg.setInstanceName(hcInstanceName);
  // group configuration
  cfg.setGroupConfig(new GroupConfig(HC_GROUP_NAME, HC_GROUP_PASSWORD));

  // network configuration initialization
  NetworkConfig netCfg = new NetworkConfig();
  netCfg.setPortAutoIncrement(true);
  netCfg.setPort(HC_PORT);
  // multicast
  MulticastConfig mcCfg = new MulticastConfig();
  mcCfg.setEnabled(true);
  mcCfg.setMulticastGroup(HC_MULTICAST_GROUP);
  mcCfg.setMulticastPort(HC_MULTICAST_PORT);
  // tcp
  TcpIpConfig tcpCfg = new TcpIpConfig();
  tcpCfg.setEnabled(false);
  // network join configuration
  JoinConfig joinCfg = new JoinConfig();
  joinCfg.setMulticastConfig(mcCfg);
  joinCfg.setTcpIpConfig(tcpCfg);
  netCfg.setJoin(joinCfg);
  // ssl
  netCfg.setSSLConfig(new SSLConfig().setEnabled(false));

  // get map
  map = Hazelcast.newHazelcastInstance(cfg).getMap(HC_MAP);

  log.info("Hazelcast Shiro session persistence initialized.");
}
项目:hazelcast-archive    文件:HazelcastClientLoader.java   
public HazelcastInstance loadInstance() throws CacheException {
    if (props == null) {
        throw new NullPointerException("Hibernate environment properties is null!");
    }
    if (client != null && client.getLifecycleService().isRunning()) {
        logger.log(Level.WARNING, "Current HazelcastClient is already active! Shutting it down...");
        unloadInstance();
    }
    String address = PropertiesHelper.getString(CacheEnvironment.NATIVE_CLIENT_ADDRESS, props, null);
    if (address == null) {
        String[] hosts = PropertiesHelper.toStringArray(CacheEnvironment.NATIVE_CLIENT_HOSTS, ",", props);
        if (hosts != null && hosts.length > 0) {
            address = hosts[0];
            logger.log(Level.WARNING, "Hibernate property '" + CacheEnvironment.NATIVE_CLIENT_HOSTS + "' " +
                    "is deprecated, use '" + CacheEnvironment.NATIVE_CLIENT_ADDRESS + "' instead!");
        }
    }
    String group = PropertiesHelper.getString(CacheEnvironment.NATIVE_CLIENT_GROUP, props, null);
    String pass = PropertiesHelper.getString(CacheEnvironment.NATIVE_CLIENT_PASSWORD, props, null);
    if (address == null || group == null || pass == null) {
        throw new CacheException("Configuration properties " + CacheEnvironment.NATIVE_CLIENT_ADDRESS + ", "
                + CacheEnvironment.NATIVE_CLIENT_GROUP + " and " + CacheEnvironment.NATIVE_CLIENT_PASSWORD
                + " are mandatory to use native client!");
    }
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setGroupConfig(new GroupConfig(group, pass)).addAddress(address);
    clientConfig.setUpdateAutomatic(true);
    return (client = HazelcastClient.newHazelcastClient(clientConfig));
}
项目:hazelcast-archive    文件:HazelcastClientBeanDefinitionParser.java   
public SpringXmlBuilder(ParserContext parserContext) {
    this.parserContext = parserContext;
    this.builder = BeanDefinitionBuilder.rootBeanDefinition(HazelcastClient.class);
    this.builder.setFactoryMethod("newHazelcastClient");
    this.builder.setDestroyMethodName("shutdown");
    this.members = new ManagedList();
    this.configBuilder = createBeanBuilder(ClientConfig.class, "client-config");
    this.groupConfigBuilder = createBeanBuilder(GroupConfig.class, "client-group-config");
    configBuilder.addPropertyValue("groupConfig", groupConfigBuilder.getBeanDefinition());
}
项目:hazelcast-archive    文件:ManagementCenterService.java   
public void run() {
    if (host == null) {
        logger.log(Level.WARNING, "Web server url is null!");
        return;
    }
    try {
        Random rand = new Random();
        Address address = ((MemberImpl) factory.node.getClusterImpl().getLocalMember()).getAddress();
        GroupConfig groupConfig = factory.getConfig().getGroupConfig();
        while (running) {
            try {
                URL url = new URL(host + "getTask.do?member=" + address.getHost() + ":" + address.getPort() + "&cluster=" + groupConfig.getName());
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setRequestProperty("Connection", "keep-alive");
                InputStream inputStream = connection.getInputStream();
                DataInputStream input = new DataInputStream(inputStream);

                int taskId = input.readInt();
                if (taskId > 0) {
                    int requestType = input.readInt();
                    ConsoleRequest request = consoleRequests[requestType];
                    request.readData(input);
                    sendResponse(taskId, request);
                }
            } catch (Exception e) {
                logger.log(Level.FINEST, e.getMessage(), e);
            }
            Thread.sleep(700 + rand.nextInt(300));
        }
    } catch (Throwable throwable) {
        logger.log(Level.FINEST, "Web Management Center will be closed due to exception.", throwable);
    }
}
项目:hazelcast-archive    文件:SocketInterceptorTest.java   
@Test(expected = RuntimeException.class, timeout = 120000)
public void testFailingClientSocketInterceptor() {
    Config config = new Config();
    SocketInterceptorConfig sic = new SocketInterceptorConfig();
    MySocketInterceptor mySocketInterceptor = new MySocketInterceptor(true);
    sic.setImplementation(mySocketInterceptor);
    config.getNetworkConfig().setSocketInterceptorConfig(sic);
    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config);
    HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config);
    int count = 1000;
    for (int i = 0; i < count; i++) {
        h1.getMap("default").put(i, "value" + i);
        h2.getMap("default").put(i, "value" + i);
    }
    assertEquals(2, h2.getCluster().getMembers().size());
    assertTrue(mySocketInterceptor.getAcceptCallCount() >= 1);
    assertTrue(mySocketInterceptor.getConnectCallCount() >= 1);
    assertEquals(2, mySocketInterceptor.getInitCallCount());
    assertEquals(0, mySocketInterceptor.getAcceptFailureCount());
    assertEquals(0, mySocketInterceptor.getConnectFailureCount());
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setGroupConfig(new GroupConfig("dev", "dev-pass")).addAddress("localhost");
    MySocketInterceptor myClientSocketInterceptor = new MySocketInterceptor(false);
    clientConfig.setSocketInterceptor(myClientSocketInterceptor);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    for (int i = 0; i < count; i++) {
        client.getMap("default").put(i, "value" + i);
    }
    assertTrue(mySocketInterceptor.getAcceptCallCount() >= 2);
    assertTrue(mySocketInterceptor.getConnectCallCount() >= 1);
    assertEquals(1, myClientSocketInterceptor.getConnectCallCount());
    assertEquals(0, myClientSocketInterceptor.getAcceptCallCount());
    assertEquals(1, mySocketInterceptor.getAcceptFailureCount());
    assertEquals(0, myClientSocketInterceptor.getAcceptFailureCount());
    assertEquals(1, myClientSocketInterceptor.getConnectFailureCount());
}
项目:hazelcast-archive    文件:TestUtility.java   
public static ClientConfig toClientConfig(ClientProperties properties) {
    String groupName = properties.getProperty(ClientProperties.ClientPropertyName.GROUP_NAME);
    String groupPassword = properties.getProperty(ClientProperties.ClientPropertyName.GROUP_PASSWORD);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setGroupConfig(new GroupConfig(groupName, groupPassword));
    clientConfig.setConnectionTimeout(properties.getInteger(ClientProperties.ClientPropertyName.CONNECTION_TIMEOUT));
    clientConfig.setInitialConnectionAttemptLimit(properties.getInteger(ClientProperties.ClientPropertyName.INIT_CONNECTION_ATTEMPTS_LIMIT));
    clientConfig.setReconnectionAttemptLimit(properties.getInteger(ClientProperties.ClientPropertyName.RECONNECTION_ATTEMPTS_LIMIT));
    clientConfig.setReConnectionTimeOut(properties.getInteger(ClientProperties.ClientPropertyName.RECONNECTION_TIMEOUT));
    return clientConfig;
}
项目:hazelcast-archive    文件:HazelcastClientClusterTest.java   
@Test(expected = IllegalStateException.class, timeout = 50000L)
public void testNoClusterOnStart() throws Exception {
    final ClientProperties clientProperties =
            ClientProperties.createBaseClientProperties(GroupConfig.DEFAULT_GROUP_NAME, GroupConfig.DEFAULT_GROUP_PASSWORD);
    clientProperties.setPropertyValue(ClientPropertyName.INIT_CONNECTION_ATTEMPTS_LIMIT, "2");
    clientProperties.setPropertyValue(ClientPropertyName.RECONNECTION_TIMEOUT, "500");
    TestUtility.newHazelcastClient(clientProperties, "localhost:5701");
}
项目:hazelcast-archive    文件:HazelcastClientClusterTest.java   
@Test(expected = NoMemberAvailableException.class, timeout = 50000L)
public void testNoClusterAfterStart() throws Exception {
    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(new Config());
    final ClientProperties clientProperties =
            ClientProperties.createBaseClientProperties(GroupConfig.DEFAULT_GROUP_NAME, GroupConfig.DEFAULT_GROUP_PASSWORD);
    clientProperties.setPropertyValue(ClientPropertyName.INIT_CONNECTION_ATTEMPTS_LIMIT, "2");
    clientProperties.setPropertyValue(ClientPropertyName.RECONNECTION_TIMEOUT, "100");
    HazelcastClient client = newHazelcastClient(clientProperties, h1);
    final IMap<Object, Object> map = client.getMap("default");
    map.put("smth", "nothing");
    h1.getLifecycleService().shutdown();
    map.put("smth", "nothing");
}
项目:hazelcast-archive    文件:HazelcastClientClusterTest.java   
@Test(expected = NoMemberAvailableException.class)
public void testNoClusterAfterStartIssue328() throws Exception {
    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(new Config());
    final ClientProperties clientProperties =
            ClientProperties.createBaseClientProperties(GroupConfig.DEFAULT_GROUP_NAME, GroupConfig.DEFAULT_GROUP_PASSWORD);
    clientProperties.setPropertyValue(ClientPropertyName.INIT_CONNECTION_ATTEMPTS_LIMIT, "2");
    clientProperties.setPropertyValue(ClientPropertyName.RECONNECTION_TIMEOUT, "500");
    HazelcastClient client = newHazelcastClient(clientProperties, h1);
    final IMap<Object, Object> map = client.getMap("default");
    h1.getLifecycleService().shutdown();
    map.put("smth", "nothing");
}
项目:tesora-dve-pub    文件:HazelcastCoordinationServices.java   
private void startHazelcastServices(List<String> registeredServers) throws PEException {
    Config cfg = new Config();

    cfg.setInstanceName(HAZELCAST_INSTANCE_NAME);
    cfg.setProperty("hazelcast.logging.type", "log4j");

    GroupConfig group = cfg.getGroupConfig();
    group.setName(HAZELCAST_GROUP_NAME);
    group.setPassword(HAZELCAST_GROUP_PASSWORD);

    NetworkConfig network = cfg.getNetworkConfig();
    network.setPortAutoIncrement(false);
    network.setPublicAddress(ourClusterAddress.getAddress().getHostAddress());
    network.setPort(ourClusterAddress.getPort());
    Join join = network.getJoin();
    join.getMulticastConfig().setEnabled(false);

    for (String serverAddress : registeredServers) {
        join.getTcpIpConfig().addMember(serverAddress);
        logger.debug("Added member " + serverAddress);
    }
    join.getTcpIpConfig().setEnabled(true);

    MapConfig mc = new MapConfig(GLOBAL_SESS_VAR_MAP_NAME);
    mc.setStorageType(StorageType.HEAP);
    mc.setTimeToLiveSeconds(0);
    mc.setMaxIdleSeconds(0);
    MaxSizeConfig msc = new MaxSizeConfig();
    msc.setSize(0);
    msc.setMaxSizePolicy(MaxSizeConfig.POLICY_CLUSTER_WIDE_MAP_SIZE);
    mc.setMaxSizeConfig(msc);

    cfg.addMapConfig(mc);

    ourHazelcastInstance = Hazelcast.newHazelcastInstance(cfg);
}
项目:health-and-care-developer-network    文件:HazelcastClientBeanDefinitionParser.java   
public SpringXmlBuilder(ParserContext parserContext) {
    this.parserContext = parserContext;
    this.builder = BeanDefinitionBuilder.rootBeanDefinition(HazelcastClient.class);
    this.builder.setFactoryMethod("newHazelcastClient");
    this.builder.setDestroyMethodName("shutdown");
    this.members = new ManagedList();
    this.configBuilder = BeanDefinitionBuilder.rootBeanDefinition(ClientConfig.class);
    this.groupConfigBuilder = BeanDefinitionBuilder.rootBeanDefinition(GroupConfig.class);
    configBuilder.addPropertyValue("groupConfig", groupConfigBuilder.getBeanDefinition());
}
项目:health-and-care-developer-network    文件:ManagementCenterService.java   
public void run() {
    if (webServerUrl == null) {
        logger.log(Level.WARNING, "Web server url is null!");
        return;
    }
    try {
        Random rand = new Random();
        Address address = ((MemberImpl) factory.node.getClusterImpl().getLocalMember()).getAddress();
        GroupConfig groupConfig = factory.getConfig().getGroupConfig();
        while (running.get()) {
            try {
                URL url = new URL(webServerUrl + "getTask.do?member=" + address.getHost() + ":" + address.getPort() + "&cluster=" + groupConfig.getName());
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setRequestProperty("Connection", "keep-alive");
                InputStream inputStream = connection.getInputStream();
                DataInputStream input = new DataInputStream(inputStream);
                final int taskId = input.readInt();
                if (taskId > 0) {
                    final int requestType = input.readInt();
                    if (requestType < consoleRequests.length) {
                        final ConsoleRequest request = consoleRequests[requestType];
                        if (request != null) {
                            request.readData(input);
                            sendResponse(taskId, request);
                        }
                    }
                }
            } catch (Exception e) {
                logger.log(Level.FINEST, e.getMessage(), e);
            }
            Thread.sleep(700 + rand.nextInt(300));
        }
    } catch (Throwable throwable) {
        if (throwable instanceof OutOfMemoryError) {
            OutOfMemoryErrorDispatcher.onOutOfMemory((OutOfMemoryError) throwable);
        }
        logger.log(Level.FINEST, "Problem on management center while polling task.", throwable);
    }
}
项目:health-and-care-developer-network    文件:SocketInterceptorTest.java   
@Test(expected = RuntimeException.class, timeout = 120000)
public void testFailingClientSocketInterceptor() {
    Config config = new Config();
    SocketInterceptorConfig sic = new SocketInterceptorConfig();
    MySocketInterceptor mySocketInterceptor = new MySocketInterceptor(true);
    sic.setImplementation(mySocketInterceptor).setEnabled(true);
    config.getNetworkConfig().setSocketInterceptorConfig(sic);
    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config);
    HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config);
    int count = 1000;
    for (int i = 0; i < count; i++) {
        h1.getMap("default").put(i, "value" + i);
        h2.getMap("default").put(i, "value" + i);
    }
    assertEquals(2, h2.getCluster().getMembers().size());
    assertTrue(mySocketInterceptor.getAcceptCallCount() >= 1);
    assertTrue(mySocketInterceptor.getConnectCallCount() >= 1);
    assertEquals(2, mySocketInterceptor.getInitCallCount());
    assertEquals(0, mySocketInterceptor.getAcceptFailureCount());
    assertEquals(0, mySocketInterceptor.getConnectFailureCount());
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setGroupConfig(new GroupConfig("dev", "dev-pass")).addAddress("localhost");
    MySocketInterceptor myClientSocketInterceptor = new MySocketInterceptor(false);
    clientConfig.setSocketInterceptor(myClientSocketInterceptor);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    for (int i = 0; i < count; i++) {
        client.getMap("default").put(i, "value" + i);
    }
    assertTrue(mySocketInterceptor.getAcceptCallCount() >= 2);
    assertTrue(mySocketInterceptor.getConnectCallCount() >= 1);
    assertEquals(1, myClientSocketInterceptor.getConnectCallCount());
    assertEquals(0, myClientSocketInterceptor.getAcceptCallCount());
    assertEquals(1, mySocketInterceptor.getAcceptFailureCount());
    assertEquals(0, myClientSocketInterceptor.getAcceptFailureCount());
    assertEquals(1, myClientSocketInterceptor.getConnectFailureCount());
}
项目:health-and-care-developer-network    文件:TestUtility.java   
public static ClientConfig toClientConfig(ClientProperties properties) {
    String groupName = properties.getProperty(ClientProperties.ClientPropertyName.GROUP_NAME);
    String groupPassword = properties.getProperty(ClientProperties.ClientPropertyName.GROUP_PASSWORD);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setGroupConfig(new GroupConfig(groupName, groupPassword));
    clientConfig.setConnectionTimeout(properties.getInteger(ClientProperties.ClientPropertyName.CONNECTION_TIMEOUT));
    clientConfig.setInitialConnectionAttemptLimit(properties.getInteger(ClientProperties.ClientPropertyName.INIT_CONNECTION_ATTEMPTS_LIMIT));
    clientConfig.setReconnectionAttemptLimit(properties.getInteger(ClientProperties.ClientPropertyName.RECONNECTION_ATTEMPTS_LIMIT));
    clientConfig.setReConnectionTimeOut(properties.getInteger(ClientProperties.ClientPropertyName.RECONNECTION_TIMEOUT));
    return clientConfig;
}
项目:health-and-care-developer-network    文件:HazelcastClientClusterTest.java   
@Test(expected = IllegalStateException.class, timeout = 50000L)
public void testNoClusterOnStart() throws Exception {
    final ClientProperties clientProperties =
            ClientProperties.createBaseClientProperties(GroupConfig.DEFAULT_GROUP_NAME, GroupConfig.DEFAULT_GROUP_PASSWORD);
    clientProperties.setPropertyValue(ClientPropertyName.INIT_CONNECTION_ATTEMPTS_LIMIT, "2");
    clientProperties.setPropertyValue(ClientPropertyName.RECONNECTION_TIMEOUT, "500");
    TestUtility.newHazelcastClient(clientProperties, "localhost:5701");
}
项目:health-and-care-developer-network    文件:HazelcastClientClusterTest.java   
@Test(expected = NoMemberAvailableException.class, timeout = 50000L)
public void testNoClusterAfterStart() throws Exception {
    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(new Config());
    final ClientProperties clientProperties =
            ClientProperties.createBaseClientProperties(GroupConfig.DEFAULT_GROUP_NAME, GroupConfig.DEFAULT_GROUP_PASSWORD);
    clientProperties.setPropertyValue(ClientPropertyName.INIT_CONNECTION_ATTEMPTS_LIMIT, "2");
    clientProperties.setPropertyValue(ClientPropertyName.RECONNECTION_TIMEOUT, "100");
    HazelcastClient client = newHazelcastClient(clientProperties, h1);
    final IMap<Object, Object> map = client.getMap("default");
    map.put("smth", "nothing");
    h1.getLifecycleService().shutdown();
    map.put("smth", "nothing");
}
项目:health-and-care-developer-network    文件:HazelcastClientClusterTest.java   
@Test(expected = NoMemberAvailableException.class)
public void testNoClusterAfterStartIssue328() throws Exception {
    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(new Config());
    final ClientProperties clientProperties =
            ClientProperties.createBaseClientProperties(GroupConfig.DEFAULT_GROUP_NAME, GroupConfig.DEFAULT_GROUP_PASSWORD);
    clientProperties.setPropertyValue(ClientPropertyName.INIT_CONNECTION_ATTEMPTS_LIMIT, "2");
    clientProperties.setPropertyValue(ClientPropertyName.RECONNECTION_TIMEOUT, "500");
    HazelcastClient client = newHazelcastClient(clientProperties, h1);
    final IMap<Object, Object> map = client.getMap("default");
    h1.getLifecycleService().shutdown();
    map.put("smth", "nothing");
}
项目:eet.osslite.cz    文件:HazelcastConfiguration.java   
private void setGroup(GroupConfig group) {
    group.setName("eetlite");
    group.setPassword("eetlite-pass");
}
项目:docker-hazelcast-mapstore-cassandra    文件:InstanceStart.java   
public static void main(String[] args) throws InterruptedException {
  final Config cfg = new Config();
  cfg.setInstanceName(UUID.randomUUID().toString());

  final Properties props = new Properties();
  props.put("hazelcast.rest.enabled", false);
  props.put("hazelcast.logging.type", "slf4j");
  props.put("hazelcast.connect.all.wait.seconds", 45);
  props.put("hazelcast.operation.call.timeout.millis", 30000);

  // group configuration
  cfg.setGroupConfig(new GroupConfig(args[0],
      args[1]));
  // network configuration initialization
  final NetworkConfig netCfg = new NetworkConfig();
  netCfg.setPortAutoIncrement(true);
  netCfg.setPort(5701);
  // multicast
  final MulticastConfig mcCfg = new MulticastConfig();
  mcCfg.setEnabled(false);
  // tcp
  final TcpIpConfig tcpCfg = new TcpIpConfig();
  tcpCfg.addMember("127.0.0.1");
  tcpCfg.setEnabled(true);
  // network join configuration
  final JoinConfig joinCfg = new JoinConfig();
  joinCfg.setMulticastConfig(mcCfg);
  joinCfg.setTcpIpConfig(tcpCfg);
  netCfg.setJoin(joinCfg);
  // ssl
  netCfg.setSSLConfig(new SSLConfig().setEnabled(false));

  // creating cassandra client
  final CassandraClient dao = new CassandraClient();
  dao.initialize(args[2]);

  final HazelcastMapStore mapStore = new HazelcastMapStore(User.class);
  mapStore.setDao(dao);


  // Adding mapstore
  final MapConfig mapCfg = cfg.getMapConfig("cassandra-map-store");

  final MapStoreConfig mapStoreCfg = new MapStoreConfig();
  mapStoreCfg.setImplementation(mapStore);
  mapStoreCfg.setWriteDelaySeconds(1);
  // to load all map at same time
  mapStoreCfg.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
  mapCfg.setMapStoreConfig(mapStoreCfg);
  cfg.addMapConfig(mapCfg);


  HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);

  // TERM signal processing
  Runtime.getRuntime().addShutdownHook(new Thread(() -> {
    Hazelcast.shutdownAll();
  }));
}
项目:runrightfast-vertx    文件:TypesafeHazelcastConfig.java   
private GroupConfig groupConfig(final com.typesafe.config.Config config) {
    return new GroupConfig(config.getString("name"), config.getString("password"));
}
项目:hazelcast-mapstore-postgres-cassandra    文件:MyHazelcastInstance.java   
public Config getConfig() {

    final Config cfg = new Config();
    cfg.setInstanceName(instanceName);

    final Properties props = new Properties();
    props.put("hazelcast.rest.enabled", false);
    props.put("hazelcast.logging.type", "slf4j");
    props.put("hazelcast.connect.all.wait.seconds", 45);
    props.put("hazelcast.operation.call.timeout.millis", 30000);

    // group configuration
    cfg.setGroupConfig(new GroupConfig(Constants.HC_GROUP_NAME,
        Constants.HC_GROUP_PASSWORD));
    // network configuration initialization
    final NetworkConfig netCfg = new NetworkConfig();
    netCfg.setPortAutoIncrement(true);
    netCfg.setPort(Constants.HC_PORT);
    // multicast
    final MulticastConfig mcCfg = new MulticastConfig();
    mcCfg.setEnabled(false);
    // tcp
    final TcpIpConfig tcpCfg = new TcpIpConfig();
    tcpCfg.addMember("127.0.0.1");
    tcpCfg.setEnabled(true);
    // network join configuration
    final JoinConfig joinCfg = new JoinConfig();
    joinCfg.setMulticastConfig(mcCfg);
    joinCfg.setTcpIpConfig(tcpCfg);
    netCfg.setJoin(joinCfg);
    // ssl
    netCfg.setSSLConfig(new SSLConfig().setEnabled(false));

    // Adding mapstore
    final MapConfig mapCfg = cfg.getMapConfig(storeType);

    final MapStoreConfig mapStoreCfg = new MapStoreConfig();
    mapStoreCfg.setImplementation(store);
    mapStoreCfg.setWriteDelaySeconds(1);
    // to load all map at same time
    mapStoreCfg.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
    mapCfg.setMapStoreConfig(mapStoreCfg);
    cfg.addMapConfig(mapCfg);
    return cfg;
  }
项目:hazelcast-archive    文件:DummyCredentialsFactory.java   
public void configure(GroupConfig groupConfig, Properties properties) {
}