@Override public IdGenerator getIdGenerator(String name) { return delegatedInstance.getIdGenerator(name); }
@Override public IdGenerator getIdGenerator(String name) { return delegatedInstance.getIdGenerator(name); }
@Override public IdGenerator getIdGenerator(String name) { return delegate.getIdGenerator(name); }
public HazelcastUniqueIdFactory(HazelcastInstance hazelcast) { idGenerator = hazelcast.getIdGenerator("job-ids"); }
/** * Generate an unique ID. * * @return the generated unique ID. */ @Override public synchronized String generateId() { if (idgenerator == null) { idgenerator = instance.getIdGenerator(GENERATOR_ID); } return String.valueOf(idgenerator.newId()); }
@Setup public void setup() { idGenerator = targetInstance.getIdGenerator(name + ":IdGenerator"); map = targetInstance.getMap(name); }
/** * A reasonable method for generating unique version ids: combining a timestamp (in seconds) with a distributed unique * Id from Hazelcast. In this way if the Hazelcast counter is restarted (for example after a cluster shutdown or * restart) then the Ids will still be unique afterwards. */ public long uniqueVersionId() { IdGenerator idGenerator = hz.getIdGenerator(CoordinationStructures.VERSION_GENERATOR); long id = idGenerator.newId(); int timeSeconds = (int) (System.currentTimeMillis() / 1000); long paddedId = id << 32; return paddedId + timeSeconds; }
/** * Generate an unique ID. * * @return the generated unique ID. */ @Override public synchronized String generateId() { if (idgenerator == null) { idgenerator = instance.getIdGenerator(GENERATOR_ID); } return String.valueOf(idgenerator.newId()); }
public static void main(String[] args) { HazelcastInstance hz = Hazelcast.newHazelcastInstance(); IdGenerator idGenerator = hz.getIdGenerator("idGenerator"); IMap map = hz.getMap("somemap-" + idGenerator.newId()); } }
@Override public IdGenerator getIdGenerator(String name) { return getHazelcastInstance().getIdGenerator(name); }
public static void main(String[] args) { HazelcastInstance hazelcast = Hazelcast.newHazelcastInstance(); IdGenerator idGenerator = hazelcast.getIdGenerator("idGenerator"); for (int i = 0; i < 10000; i++) { sleepSeconds(1); System.out.printf("Id: %s\n", idGenerator.newId()); } } }
@Override public String createTemporaryQueue() { IdGenerator idGenerator = config.getHazelcastInstance().getIdGenerator( "hzmqcontext-temporary-destination"); long tempDestId = idGenerator.newId(); String destination = Headers.DESTINATION_TEMPORARY_QUEUE_PREFIX + tempDestId; temporaryQueues.add(destination); return destination; }
public static void main(String[] args) { Config config = new ClasspathXmlConfig("hazelcast.xml"); HazelcastInstance hz = Hazelcast.newHazelcastInstance(config); IdGenerator idGenerator = hz.getIdGenerator ("idGenerator "); IMap someMap = hz.getMap("somemap-"+ idGenerator . newId ()); }
@Produces public IdGenerator produceIdGenerator(final ProviderContext context ) { final String name = retrieveSourceNameFrom( context ); final IdGenerator data = hazelcast.getIdGenerator( name ); notifyDataWasProduced( data, IdGenerator.class ); return data; }
@Override public String createTemporaryTopic() { IdGenerator idGenerator = config.getHazelcastInstance().getIdGenerator( "hzmqcontext-temporary-destination"); long tempDestId = idGenerator.newId(); String destination = Headers.DESTINATION_TEMPORARY_TOPIC_PREFIX + tempDestId; temporaryTopics.add(destination); return destination; }
@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-sample-generator"); Long id = idGenerator.newId(); topic = instance.getTopic("cellar-sample-topic"); registrationId = topic.addMessageListener(messageListener); topic.publish(new Message("id="+id)); } catch (Exception ex) { ex.printStackTrace(); } Thread.currentThread().setContextClassLoader(classLoader); }
@Setup public void setup(TestContext testContext) throws Exception { this.testContext = testContext; targetInstance = testContext.getTargetInstance(); idGenerator = targetInstance.getIdGenerator(testContext.getTestId() + ":IdGenerator"); map = targetInstance.getMap(basename + "-" + testContext.getTestId()); }
/** * Constructs the producer. * * @param destination the destination to use for send operations that don't * specify a destination * @param hazelcastMQContext the context that this producer belongs to */ public DefaultHazelcastMQProducer(String destination, DefaultHazelcastMQContext hazelcastMQContext) { this.destination = destination; this.hazelcastMQContext = hazelcastMQContext; this.config = hazelcastMQContext.getHazelcastMQInstance().getConfig(); this.idGenerator = config.getHazelcastInstance().getIdGenerator( "hazelcastmqproducer"); }
public static void main(String[] args) { HazelcastInstance instance = Hazelcast.newHazelcastInstance(); IdGenerator oldGenerator = instance.getIdGenerator(GENERATOR_NAME);