Java Code Examples for com.hazelcast.map.IMap#put()
The following examples show how to use
com.hazelcast.map.IMap#put() .
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: RandomSimulator.java From hazelcast-jet-demos with Apache License 2.0 | 6 votes |
/** * Set up an event to hang the bets off */ public default void createFutureEvent() { // Grab some horses to use as runners in races final IMap<Horse, Object> fromHC = getClient().getMap("winners"); final Set<Horse> horses = fromHC.keySet(); // Now set up some future-dated events for next Sat final LocalDate nextSat = LocalDate.now().with(TemporalAdjusters.next(DayOfWeek.SATURDAY)); LocalTime raceTime = LocalTime.of(11, 0); // 1100 start final Event e = CentralFactory.eventOf("Racing from Epsom", nextSat); final Set<Horse> runners = makeRunners(horses, 10); for (int i = 0; i < 18; i++) { final Map<Horse, Double> runnersWithOdds = makeSimulatedOdds(runners); final Race r = CentralFactory.raceOf(LocalDateTime.of(nextSat, raceTime), runnersWithOdds); e.addRace(r); raceTime = raceTime.plusMinutes(10); } final IMap<Long, Event> events = getClient().getMap("events"); events.put(e.getID(), e); }
Example 2
Source File: Lab4.java From hazelcast-jet-training with Apache License 2.0 | 6 votes |
public static void main(String[] args) { JetInstance jet = Jet.bootstrappedInstance(); // symbol -> company name // random symbols from https://www.nasdaq.com IMap<String, String> lookupTable = jet.getMap(LOOKUP_TABLE); lookupTable.put("AAPL", "Apple Inc. - Common Stock"); lookupTable.put("GOOGL", "Alphabet Inc."); lookupTable.put("MSFT", "Microsoft Corporation"); Pipeline p = buildPipeline(lookupTable); try { jet.newJob(p).join(); } finally { jet.shutdown(); } }
Example 3
Source File: Solution4.java From hazelcast-jet-training with Apache License 2.0 | 6 votes |
public static void main (String[] args) { JetInstance jet = Jet.bootstrappedInstance(); // symbol -> company name IMap<String, String> lookupTable = jet.getMap(LOOKUP_TABLE); lookupTable.put("AAPL", "Apple Inc. - Common Stock"); lookupTable.put("GOOGL", "Alphabet Inc."); lookupTable.put("MSFT", "Microsoft Corporation"); Pipeline p = buildPipeline(lookupTable); try { jet.newJob(p).join(); } finally { jet.shutdown(); } }
Example 4
Source File: TopicManager.java From mercury with Apache License 2.0 | 6 votes |
private void createTopic(String topic) { if (!topicExists(topic)) { String now = Utility.getInstance().date2str(new Date(), true); String nodes = HazelcastSetup.NAMESPACE+NODES; String realTopic = HazelcastSetup.NAMESPACE+topic; HazelcastInstance client = HazelcastSetup.getHazelcastClient(); IMap<String, byte[]> map = client.getMap(nodes); Map<String, String> metadata = new HashMap<>(); metadata.put("node", topic); metadata.put("name", Platform.getInstance().getName()); metadata.put("created", now); metadata.put("updated", now); try { map.put(topic, msgPack.pack(metadata)); // create topic if not exists client.getReliableTopic(realTopic); log.info("Topic {} created", realTopic); } catch (IOException e) { // this does not happen log.error("Unable to create topic {} - {}", topic, e.getMessage()); } } }
Example 5
Source File: ClientManager.java From openmeetings with Apache License 2.0 | 6 votes |
/** * This method will return count of users in room _after_ adding * * @param c - client to be added to the room * @return count of users in room _after_ adding */ public int addToRoom(Client c) { Room r = c.getRoom(); Long roomId = r.getId(); confLogDao.add( ConferenceLog.Type.ROOM_ENTER , c.getUserId(), "0", roomId , c.getRemoteAddress() , String.valueOf(roomId)); log.debug("Adding online room client: {}, room: {}", c.getUid(), roomId); IMap<Long, Set<String>> rooms = rooms(); rooms.lock(roomId); rooms.putIfAbsent(roomId, ConcurrentHashMap.newKeySet()); Set<String> set = rooms.get(roomId); set.add(c.getUid()); final int count = set.size(); rooms.put(roomId, set); onlineRooms.put(roomId, set); rooms.unlock(roomId); String serverId = c.getServerId(); addRoomToServer(serverId, r); update(c); return count; }
Example 6
Source File: ClientManager.java From openmeetings with Apache License 2.0 | 5 votes |
public void exitRoom(Client c, boolean update) { Long roomId = c.getRoomId(); log.debug("Removing online room client: {}, room: {}", c.getUid(), roomId); if (roomId != null) { IMap<Long, Set<String>> rooms = rooms(); rooms.lock(roomId); Set<String> clients = rooms.get(roomId); if (clients != null) { clients.remove(c.getUid()); rooms.put(roomId, clients); onlineRooms.put(roomId, clients); } rooms.unlock(roomId); if (clients == null || clients.isEmpty()) { String serverId = c.getServerId(); IMap<String, ServerInfo> servers = servers(); servers.lock(serverId); ServerInfo si = servers.get(serverId); si.remove(c.getRoom()); servers.put(serverId, si); onlineServers.put(serverId, si); servers.unlock(serverId); } kHandler.leaveRoom(c); c.setRoom(null); c.clear(); if (update) { update(c); } sendRoom(new TextRoomMessage(roomId, c, RoomMessage.Type.ROOM_EXIT, c.getUid())); confLogDao.add( ConferenceLog.Type.ROOM_LEAVE , c.getUserId(), "0", roomId , c.getRemoteAddress() , String.valueOf(roomId)); } }
Example 7
Source File: MapTransactionGetForUpdateTest.java From hazelcast-simulator with Apache License 2.0 | 5 votes |
@Prepare(global = true) public void prepare() { IMap<Integer, Long> map = targetInstance.getMap(name); for (int i = 0; i < keyCount; i++) { map.put(i, 0L); } }
Example 8
Source File: MapTransactionContextConflictTest.java From hazelcast-simulator with Apache License 2.0 | 5 votes |
@Prepare(global = true) public void prepare() { IMap<Integer, Long> map = targetInstance.getMap(name); for (int i = 0; i < keyCount; i++) { map.put(i, 0L); } }
Example 9
Source File: TestDataHelper.java From spring-data-hazelcast with Apache License 2.0 | 5 votes |
private void loadCities(IMap<String, City> cityMap) { for (int i = 0; i < TestData.newYorkCities.length; i++) { City city = new City(); city.setId(Integer.toString((int) TestData.newYorkCities[i][2])); city.setName(TestData.newYorkCities[i][0].toString()); final String[] latLng = TestData.newYorkCities[i][1].toString().split(","); city.setLocation(new Point(Double.parseDouble(latLng[0]), Double.parseDouble(latLng[1]))); cityMap.put(city.getId(), city); } }
Example 10
Source File: TestDataHelper.java From spring-data-hazelcast with Apache License 2.0 | 5 votes |
private void loadSong(IMap<String, Song> songMap) { for (int i = 0; i < TestData.bestSongs.length; i++) { Song song = new Song(); song.setId(Integer.toString((int) TestData.bestSongs[i][0])); song.setTitle(TestData.bestSongs[i][1].toString()); songMap.put(song.getId(), song); } }
Example 11
Source File: TestDataHelper.java From spring-data-hazelcast with Apache License 2.0 | 5 votes |
private void loadPerson(IMap<String, Person> personMap) { for (int i = 0; i < TestData.bestActors.length; i++) { Person person = new Person(); person.setId(Integer.toString((int) TestData.bestActors[i][0])); person.setFirstname(TestData.bestActors[i][1].toString()); person.setLastname(TestData.bestActors[i][2].toString()); personMap.put(person.getId(), person); } }
Example 12
Source File: TestDataHelper.java From spring-data-hazelcast with Apache License 2.0 | 5 votes |
private void loadMovie(IMap<String, Movie> movieMap) { for (int i = 0; i < TestData.bestPictures.length; i++) { Movie movie = new Movie(); movie.setId(Integer.toString((int) TestData.bestPictures[i][0])); movie.setTitle(TestData.bestPictures[i][1].toString()); movieMap.put(movie.getId(), movie); } }
Example 13
Source File: ClientManager.java From openmeetings with Apache License 2.0 | 5 votes |
private void addRoomToServer(String serverId, Room r) { if (!onlineServers.get(serverId).getRooms().contains(r.getId())) { log.debug("Cluster:: room {} was not found for server '{}', adding ...", r.getId(), serverId); IMap<String, ServerInfo> servers = servers(); servers.lock(serverId); ServerInfo si = servers.get(serverId); si.add(r); servers.put(serverId, si); onlineServers.put(serverId, si); servers.unlock(serverId); } }
Example 14
Source File: HazelcastCacheSample.java From micrometer with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { MeterRegistry registry = loggingMeterRegistry(); IMap<String, Integer> hazelcastCache = Hazelcast.newHazelcastInstance().getMap("hazelcast.cache"); HazelcastCacheMetrics.monitor(registry, hazelcastCache); for (int i = 0; i < 100; i++) { hazelcastCache.put("key" + i, i); Thread.sleep(1000); } }
Example 15
Source File: SampleReviews.java From hazelcast-jet-demos with Apache License 2.0 | 5 votes |
public static void populateReviewsMap(IMap<Long, String> reviewsMap) { List<String> reviews = asList( "the movie was good", "the movie was bad", "excellent movie best piece ever", "absolute disaster, worst movie ever", "had both good and bad parts, excellent casting, but camera was poor"); long key = 0; for (String review : reviews) { reviewsMap.put(key++, review); } }
Example 16
Source File: RandomSimulator.java From hazelcast-jet-demos with Apache License 2.0 | 5 votes |
/** * Sets up some random users (to place bets) and stores them in Hazlecast IMDG */ public default void createRandomUsers() { final IMap<Long, User> users = getClient().getMap("users"); final String[] firstNames = {"Dave", "Christine", "Sarah", "Sadiq", "Zoe", "Helen", "Mike", "George", "Joanne"}; final String[] lastNames = {"Baker", "Jones", "Smith", "Singh", "Shah", "Johnson", "Taylor", "Evans", "Howe"}; final Random r = new Random(); for (int i = 0; i < NUM_USERS; i++) { final User u = CentralFactory.userOf(firstNames[r.nextInt(firstNames.length)], lastNames[r.nextInt(lastNames.length)]); users.put(u.getID(), u); } }
Example 17
Source File: MyCLI.java From hazelcast-jet-demos with Apache License 2.0 | 5 votes |
@CliCommand(value = "HISTORY", help = "Recent history of changes to the 'precious' IMap") public String readHistory() { IMap<String, List<String>> commandMap = this.hazelcastInstance.getMap(Constants.IMAP_NAME_COMMAND); List<String> params = new ArrayList<>(); params.add(Constants.COMMAND_VERB_START); commandMap.put(Constants.COMMAND_NOUN_HISTORY, params); return String.format("Requested %s job '%s'", Constants.COMMAND_VERB_START, Constants.COMMAND_NOUN_HISTORY); }
Example 18
Source File: MyCLI.java From hazelcast-jet-demos with Apache License 2.0 | 5 votes |
@CliCommand(value = "KAFKA", help = "Read from Kafka into the 'precious' IMap") public String readKafka() { IMap<String, List<String>> commandMap = this.hazelcastInstance.getMap(Constants.IMAP_NAME_COMMAND); List<String> params = new ArrayList<>(); params.add(Constants.COMMAND_VERB_START); params.add(this.bootstrapServers); commandMap.put(Constants.COMMAND_NOUN_KAFKA, params); return String.format("Requested %s job '%s' with %s", Constants.COMMAND_VERB_START, Constants.COMMAND_NOUN_KAFKA, params.get(1)); }