Package com.hazelcast.core

Examples of com.hazelcast.core.HazelcastInstance


        if (ownerTenantId == MultitenantConstants.INVALID_TENANT_ID) {
            throw new IllegalStateException("Tenant ID cannot be " + ownerTenantId);
        }
        this.cacheName = cacheName;
        this.cacheManager = cacheManager;
        HazelcastInstance hazelcastInstance =
                HazelcastInstanceManager.getInstance().getHazelcastInstance();
        if (hazelcastInstance != null) {
            if (log.isDebugEnabled()) {
                log.debug("Using Hazelcast based distributed cache");
            }
            distributedCache = hazelcastInstance.getMap("$cache.$domain[" + ownerTenantDomain + "]" +
                                                        cacheManager.getName() + "#" + cacheName);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Using local cache");
            }
View Full Code Here


        tcpIpConfig = groupNwConfig.getJoin().getTcpIpConfig();

        GroupConfig groupConfig = config.getGroupConfig();
        groupConfig.setName(domain);
        config.setProperties(primaryHazelcastConfig.getProperties());
        HazelcastInstance hazelcastInstance = Hazelcast.getHazelcastInstanceByName(domain);
        if (hazelcastInstance == null) {
            hazelcastInstance = Hazelcast.newHazelcastInstance(config);
        }
        hazelcastInstance.getCluster().addMembershipListener(new GroupMembershipListener());
        localMemberUUID = hazelcastInstance.getCluster().getLocalMember().getUuid();
        Member localMember =
                MemberUtils.getLocalMember(domain, groupNwConfig.getPublicAddress(),
                                           groupMgtPort);
        log.info("Group management local member for domain [" + domain + "],sub-domain [" +
                 subDomain + "] UUID: " + localMemberUUID + ". " + localMember);
        MemberUtils.getMembersMap(hazelcastInstance, domain).put(localMemberUUID, localMember);
        members = MemberUtils.getMembersMap(hazelcastInstance, domain);
        members.addEntryListener(new MemberEntryListener(), true);
        for (Member member : members.values()) {
            connectMember(member);
        }
        groupManagementTopic = hazelcastInstance.getTopic("$" + domain + HazelcastConstants.GROUP_MGT_CMD_TOPIC);
        groupManagementTopic.addMessageListener(new GroupManagementCommandListener(configurationContext));
    }
View Full Code Here

        logger.warn("Starting server {}", opts);

        // start this first so that Hazel has to take second pickings
        DuplexTcpServerBootstrap bootstrap = startProtoServer(opts.port);

        HazelcastInstance instance = setupHazelCast(opts.hosts);
        Server us = recordServerInstance(opts, instance);

        bootstrap.getRpcServiceRegistry().registerBlockingService(
                Catcher.CatcherService.newReflectiveBlockingService(new CatcherImpl(us, instance, opts.basePath)));
        bootstrap.bind();
View Full Code Here

   * @param localOnly Indicates whether to force the cluster to be local only.
   * @return A new cluster listener.
   */
  public ClusterListener createClusterListener(boolean localOnly) {
    if (localOnly) return new NoClusterListener();
    HazelcastInstance hazelcast = getHazelcastInstance(vertx);
    if (hazelcast != null) {
      return new HazelcastClusterListener(hazelcast, vertx);
    } else {
      return new NoClusterListener();
    }
View Full Code Here

   * @param localOnly Indicates whether to force the cluster to be local only.
   * @return A cluster data store.
   */
  public ClusterData createClusterData(boolean localOnly) {
    if (localOnly) return new VertxClusterData(vertx);
    HazelcastInstance hazelcast = ClusterListenerFactory.getHazelcastInstance(vertx);
    if (hazelcast != null) {
      return new HazelcastClusterData(hazelcast);
    } else {
      return new VertxClusterData(vertx);
    }
View Full Code Here

        try {
            clientConfig = new XmlClientConfigBuilder("hazelcast-client.xml").build();
        } catch (IllegalArgumentException e) {
            clientConfig = new ClientConfig();
        }
        final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
        ClientTestApp clientTestApp = new ClientTestApp(client);
        clientTestApp.start(args);
    }
View Full Code Here

    @Override
    public void shutdown(boolean terminate) {
    }

    private IAtomicLong getBlockGenerator(String name) {
        HazelcastInstance hazelcastInstance = nodeEngine.getHazelcastInstance();
        return hazelcastInstance.getAtomicLong(ATOMIC_LONG_NAME + name);
    }
View Full Code Here

     */
    public static void main(String[] args) {

        int threadCount = 40;
        final Stats stats = new Stats();
        final HazelcastInstance hazelcast = Hazelcast.newHazelcastInstance(null);
        ExecutorService es = Executors.newFixedThreadPool(threadCount);
        for (int i = 0; i < threadCount; i++) {
            es.submit(new Runnable() {
                public void run() {
                    IMap map = hazelcast.getMap("default");
                    while (true) {
                        int keyInt = (int) (RANDOM.nextFloat() * ENTRY_COUNT);
                        int operation = ((int) (RANDOM.nextFloat() * 1000)) % 20;
                        Object key = String.valueOf(keyInt);
                        if (operation < 1) {
                            map.size();
                            stats.increment("size");
                        } else if (operation < 2) {
                            map.get(key);
                            stats.increment("get");
                        } else if (operation < 3) {
                            map.remove(key);
                            stats.increment("remove");
                        } else if (operation < 4) {
                            map.containsKey(key);
                            stats.increment("containsKey");
                        } else if (operation < 5) {
                            Object value = String.valueOf(key);
                            map.containsValue(value);
                            stats.increment("containsValue");
                        } else if (operation < 6) {
                            map.putIfAbsent(key, createValue());
                            stats.increment("putIfAbsent");
                        } else if (operation < 7) {
                            Collection col = map.values();
                            for (Object o : col) {
                                int i = 0;
                            }
                            stats.increment("values");
                        } else if (operation < 8) {
                            Collection col = map.keySet();
                            for (Object o : col) {
                                int i = 0;
                            }
                            stats.increment("keySet");
                        } else if (operation < 9) {
                            Collection col = map.entrySet();
                            for (Object o : col) {
                                int i = 0;
                            }
                            stats.increment("entrySet");
                        } else {
                            map.put(key, createValue());
                            stats.increment("put");
                        }
                    }
                }
            });
        }
        Executors.newSingleThreadExecutor().submit(new Runnable() {
            public void run() {
                while (true) {
                    try {
                        //noinspection BusyWait
                        Thread.sleep(STATS_SECONDS * 1000);
                        System.out.println("cluster size:"
                                + hazelcast.getCluster().getMembers().size());
                        Stats currentStats = stats.getAndReset();
                        System.out.println(currentStats);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
View Full Code Here

     * Creates a cluster and exercises a queue until stopped
     * @param args none
     */
    public static void main(String[] args) {
        int threadCount = 5;
        final HazelcastInstance hz1 = Hazelcast.newHazelcastInstance(null);
        final Stats stats = new Stats();
        ExecutorService es = Executors.newFixedThreadPool(threadCount);
        for (int i = 0; i < threadCount; i++) {
            es.submit(new Runnable() {
                public void run() {
                    Random random = new Random();
                    while (true) {
                        int ran = random.nextInt(100);
                        Queue<byte[]> queue = hz1.getQueue("default" + ran);
                        for (int j = 0; j < 1000; j++) {
                            queue.offer(new byte[VALUE_SIZE]);
                            stats.offers.incrementAndGet();
                        }
                        for (int j = 0; j < 1000; j++) {
                            queue.poll();
                            stats.polls.incrementAndGet();
                        }
                    }
                }
            });
        }

        Executors.newSingleThreadExecutor().submit(new Runnable() {
            @SuppressWarnings("BusyWait")
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(STATS_SECONDS * 1000);
                        System.out.println("cluster size:"
                                + hz1.getCluster().getMembers().size());
                        Stats currentStats = stats.getAndReset();
                        System.out.println(currentStats);
                        System.out.println("Operations per Second : " + currentStats.total()
                                / STATS_SECONDS);
                    } catch (Exception e) {
View Full Code Here

    @Override
    public void start(BundleContext context) throws Exception {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
        ServiceReference reference = context.getServiceReference("com.hazelcast.core.HazelcastInstance");
        HazelcastInstance instance = (HazelcastInstance) context.getService(reference);
        context.ungetService(reference);
        try {
            IdGenerator idGenerator = instance.getIdGenerator("cellar-smaple-generator");
            Long id = idGenerator.newId();
            topic = instance.getTopic("cellar-sample-topic");
            topic.addMessageListener(messageListener);
            topic.publish(new Message("id="+id));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
View Full Code Here

TOP

Related Classes of com.hazelcast.core.HazelcastInstance

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.