Java Code Examples for com.hazelcast.core.HazelcastInstance#getQueue()

The following examples show how to use com.hazelcast.core.HazelcastInstance#getQueue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HazelcastScheduler.java    From greycat with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    Config cfg = new Config();
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
    Map<Integer, String> mapCustomers = instance.getMap("customers");
    mapCustomers.put(1, "Joe");
    mapCustomers.put(2, "Ali");
    mapCustomers.put(3, "Avi");

    System.out.println("Customer with key 1: "+ mapCustomers.get(1));
    System.out.println("Map Size:" + mapCustomers.size());

    Queue<String> queueCustomers = instance.getQueue("customers");
    queueCustomers.offer("Tom");
    queueCustomers.offer("Mary");
    queueCustomers.offer("Jane");
    System.out.println("First customer: " + queueCustomers.poll());
    System.out.println("Second customer: "+ queueCustomers.peek());
    System.out.println("Queue size: " + queueCustomers.size());
}
 
Example 2
Source File: HazelcastGetStartClient.java    From hazelcast-demo with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	ClientConfig clientConfig = new ClientConfig();
	HazelcastInstance instance = HazelcastClient.newHazelcastClient(clientConfig);
	Map<Integer, String> clusterMap = instance.getMap("MyMap");
	Queue<String> clusterQueue = instance.getQueue("MyQueue");
	
	System.out.println("Map Value:" + clusterMap.get(1));
	System.out.println("Queue Size :" + clusterQueue.size());
	System.out.println("Queue Value 1:" + clusterQueue.poll());
	System.out.println("Queue Value 2:" + clusterQueue.poll());
	System.out.println("Queue Size :" + clusterQueue.size());
}
 
Example 3
Source File: HazelcastGetStartServerSlave.java    From hazelcast-demo with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	//创建一个 hazelcastInstance实例
	HazelcastInstance instance = Hazelcast.newHazelcastInstance();
	Map<Integer, String> clusterMap = instance.getMap("MyMap");
	Queue<String> clusterQueue = instance.getQueue("MyQueue");
	
	System.out.println("Map Value:" + clusterMap.get(1));
	System.out.println("Queue Size :" + clusterQueue.size());
	System.out.println("Queue Value 1:" + clusterQueue.poll());
	System.out.println("Queue Value 2:" + clusterQueue.poll());
	System.out.println("Queue Size :" + clusterQueue.size());
}
 
Example 4
Source File: HazelcastGetStartServerMaster.java    From hazelcast-demo with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	// 创建一个 hazelcastInstance实例
	HazelcastInstance instance = Hazelcast.newHazelcastInstance();
	// 创建集群Map
	Map<Integer, String> clusterMap = instance.getMap("MyMap");
	clusterMap.put(1, "Hello hazelcast map!");

	// 创建集群Queue
	Queue<String> clusterQueue = instance.getQueue("MyQueue");
	clusterQueue.offer("Hello hazelcast!");
	clusterQueue.offer("Hello hazelcast queue!");
}
 
Example 5
Source File: AtomicExample.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void consume(HazelcastInstance hazelcastInstance) {
   IQueue<String> cola = hazelcastInstance.getQueue("cola");
   while (true){
      try {
         System.out.println("Taken from queue: "+cola.take());
      } catch (InterruptedException e) {
         e.printStackTrace();
      }
   }
   
}
 
Example 6
Source File: AtomicExample.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void produce(HazelcastInstance hazelcastInstance) {
   IQueue<String> cola = hazelcastInstance.getQueue("cola");
   
   int count=0;
   while (true){
      try {
         cola.offer(Integer.toString(count++));
         Thread.sleep(1000);
         System.out.println("Added to queue. It has now "+cola.size());
      } catch (InterruptedException e) {
         e.printStackTrace();
      }
   }
}