Java Code Examples for com.hazelcast.core.Hazelcast#getMap()

The following examples show how to use com.hazelcast.core.Hazelcast#getMap() . 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: NodeSelector.java    From JPPF with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize this node selector and distribute the trades among the nodes.
 * @param trades the list of trades to distribute among the nodes.
 * @param nodeIdList the list of node ids.
 */
public NodeSelector(final List<Trade> trades, final List<String> nodeIdList) {
  System.out.println("populating the trades");
  this.nodeIdList = nodeIdList;
  final int nbNodes = nodeIdList.size();
  final Trade[] tradeArray = trades.toArray(new Trade[0]);
  //for (int i=0; i<tradeArray.length; i++) tradeToNodeMap.put(tradeArray[i].getId(), nodeIdList.get(i % nbNodes));
  final ExecutorService executor = Executors.newFixedThreadPool(nbNodes);
  final List<Future<?>> futures = new ArrayList<>();
  for (int i=0; i<nbNodes; i++) {
    final String nodeId = nodeIdList.get(i);
    final Map<String, Trade> hazelcastMap = Hazelcast.getMap(ModelConstants.TRADE_MAP_PREFIX + nodeId);
    nodeToHazelcastMap.put(nodeId, hazelcastMap);
    futures.add(executor.submit(new PopulateTradesTask(tradeArray, i, nbNodes, hazelcastMap)));
  }
  for (final Future<?> f: futures) {
    try {
      f.get();
    } catch(final Exception e) {
      e.printStackTrace();
    }
  }
  executor.shutdownNow();
  System.out.println("end of populating the trades");
}
 
Example 2
Source File: DataDependencyStartup.java    From JPPF with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void run() {
  //-Dhazelcast.wait.seconds.before.join=1
  System.setProperty("hazelcast.wait.seconds.before.join", "1");
  System.out.println("Initializing distributed maps");
  dataMap = Hazelcast.getMap(ModelConstants.MARKET_DATA_MAP_NAME);
  tradeMap = Hazelcast.getMap(ModelConstants.TRADE_MAP_PREFIX + node.getUuid());
  System.out.println("Data initialization complete");
}
 
Example 3
Source File: MarketDataHandler.java    From JPPF with Apache License 2.0 5 votes vote down vote up
/**
 * Perform the nodes' initializations.
 * @param marketDataList the initial market data to send to each node.
 * @throws Exception if any error is raised.
 */
public void populateMarketData(final List<MarketData> marketDataList) throws Exception {
  System.out.println("populating the market data");
  dataMap = Hazelcast.getMap(ModelConstants.MARKET_DATA_MAP_NAME);
  dataMap.clear();
  //for (MarketData data: marketDataList) dataMap.put(data.getId(), data);
  populateInParallel(marketDataList);
  System.out.println("end of populating the market data");
}
 
Example 4
Source File: HazelcastSymmetric.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void init() {

        //Specific map time to live
        MapConfig myMapConfig = new MapConfig();
        myMapConfig.setName("cachetest");
        myMapConfig.setTimeToLiveSeconds(10);

        //Package config
        Config myConfig = new Config();
        myConfig.addMapConfig(myMapConfig);

        //Symmetric Encryption
        SymmetricEncryptionConfig symmetricEncryptionConfig = new SymmetricEncryptionConfig();
        symmetricEncryptionConfig.setAlgorithm("DESede");
        symmetricEncryptionConfig.setSalt("saltysalt");
        symmetricEncryptionConfig.setPassword("lamepassword");
        symmetricEncryptionConfig.setIterationCount(1337);

        //Weak Network config..
        NetworkConfig networkConfig = new NetworkConfig();
        networkConfig.setSymmetricEncryptionConfig(symmetricEncryptionConfig);

        myConfig.setNetworkConfig(networkConfig);

        Hazelcast.init(myConfig);

        cacheMap = Hazelcast.getMap("cachetest");
    }