public void run() { while (true) { TransactionContext context = hazelcast.newTransactionContext(); context.beginTransaction(); Set<Integer> setAllInvolvedPMs = new HashSet<Integer>(9); try { Order order = qOrders.take(); countOrdersProcessed.incrementAndGet(); List<Integer> lsAccounts = order.lsAccounts; int accountQuantity = order.quantity / lsAccounts.size(); // for (Integer account : lsAccounts) { // String key = account + "," + order.instrumentId; // updatePosition(key, order, account, accountQuantity); // } String key = order.portfolioManagerId + "," + order.instrumentId; updatePosition(key, order, order.portfolioManagerId, order.quantity); context.commitTransaction(); // setAllInvolvedPMs.addAll(lsAccounts); setAllInvolvedPMs.add(order.portfolioManagerId); for (Integer involvedPM : setAllInvolvedPMs) { mapNewOrders.put(involvedPM, order.instrumentId); } } catch (Throwable t) { t.printStackTrace(); context.rollbackTransaction(); } } }
public void start(String[] args) throws Exception { if (lineReader == null) { lineReader = new DefaultLineReader(); } running = true; while (running) { print("hazelcast[" + namespace + "] > "); try { final String command = lineReader.readLine(); handleCommand(command); } catch (Throwable e) { e.printStackTrace(); } } }
private Object executeTaskAndGet(final DistributedTask task) { try { factory.getExecutorService().execute(task); try { return task.get(3, TimeUnit.SECONDS); } catch (Throwable e) { logger.log(Level.FINEST, e.getMessage(), e); return null; } } catch (Throwable e) { if (running.get() && factory.node.isActive()) { logger.log(Level.WARNING, e.getMessage(), e); } return null; } }