Beispiel #1
0
 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();
     }
   }
 }
 @Test
 public void testNetworkConfig() {
   NetworkConfig networkConfig = config.getNetworkConfig();
   assertNotNull(networkConfig);
   assertEquals(5700, networkConfig.getPort());
   assertFalse(networkConfig.isPortAutoIncrement());
   final Collection<String> allowedPorts = networkConfig.getOutboundPortDefinitions();
   assertEquals(2, allowedPorts.size());
   Iterator portIter = allowedPorts.iterator();
   assertEquals("35000-35100", portIter.next());
   assertEquals("36000,36100", portIter.next());
   assertFalse(networkConfig.getJoin().getMulticastConfig().isEnabled());
   assertEquals(networkConfig.getJoin().getMulticastConfig().getMulticastTimeoutSeconds(), 8);
   assertEquals(networkConfig.getJoin().getMulticastConfig().getMulticastTimeToLive(), 16);
   assertFalse(networkConfig.getInterfaces().isEnabled());
   assertEquals(1, networkConfig.getInterfaces().getInterfaces().size());
   assertEquals("10.10.1.*", networkConfig.getInterfaces().getInterfaces().iterator().next());
   TcpIpConfig tcp = networkConfig.getJoin().getTcpIpConfig();
   assertNotNull(tcp);
   assertTrue(tcp.isEnabled());
   assertTrue(networkConfig.getSymmetricEncryptionConfig().isEnabled());
   final List<String> members = tcp.getMembers();
   assertEquals(members.toString(), 2, members.size());
   assertEquals("127.0.0.1:5700", members.get(0));
   assertEquals("127.0.0.1:5701", members.get(1));
   assertEquals("127.0.0.1:5700", tcp.getRequiredMember());
   AwsConfig aws = networkConfig.getJoin().getAwsConfig();
   assertFalse(aws.isEnabled());
   assertEquals("sample-access-key", aws.getAccessKey());
   assertEquals("sample-secret-key", aws.getSecretKey());
   assertEquals("sample-region", aws.getRegion());
   assertEquals("sample-group", aws.getSecurityGroupName());
   assertEquals("sample-tag-key", aws.getTagKey());
   assertEquals("sample-tag-value", aws.getTagValue());
 }
 @Test
 public void testConfigListeners() {
   assertNotNull(membershipListener);
   List<ListenerConfig> list = config.getListenerConfigs();
   assertEquals(2, list.size());
   for (ListenerConfig lc : list) {
     if (lc.getClassName() != null) {
       assertNull(lc.getImplementation());
       assertEquals(DummyMembershipListener.class.getName(), lc.getClassName());
     } else {
       assertNotNull(lc.getImplementation());
       assertEquals(membershipListener, lc.getImplementation());
     }
   }
 }
Beispiel #4
0
 public QueryResult queryOnPartition(String mapName, Predicate predicate, int partitionId) {
   final QueryResult result = new QueryResult();
   List<QueryEntry> list = new LinkedList<QueryEntry>();
   PartitionContainer container = getPartitionContainer(partitionId);
   RecordStore recordStore = container.getRecordStore(mapName);
   Map<Data, Record> records = recordStore.getReadonlyRecordMap();
   SerializationService serializationService = nodeEngine.getSerializationService();
   final PagingPredicate pagingPredicate =
       predicate instanceof PagingPredicate ? (PagingPredicate) predicate : null;
   Comparator<Map.Entry> wrapperComparator = SortingUtil.newComparator(pagingPredicate);
   for (Record record : records.values()) {
     Data key = record.getKey();
     Object value = record.getValue();
     if (value == null) {
       continue;
     }
     QueryEntry queryEntry = new QueryEntry(serializationService, key, key, value);
     if (predicate.apply(queryEntry)) {
       if (pagingPredicate != null) {
         Map.Entry anchor = pagingPredicate.getAnchor();
         if (anchor != null
             && SortingUtil.compare(
                     pagingPredicate.getComparator(),
                     pagingPredicate.getIterationType(),
                     anchor,
                     queryEntry)
                 >= 0) {
           continue;
         }
       }
       list.add(queryEntry);
     }
   }
   if (pagingPredicate != null) {
     Collections.sort(list, wrapperComparator);
     if (list.size() > pagingPredicate.getPageSize()) {
       list = list.subList(0, pagingPredicate.getPageSize());
     }
   }
   for (QueryEntry entry : list) {
     result.add(
         new QueryResultEntryImpl(entry.getKeyData(), entry.getKeyData(), entry.getValueData()));
   }
   return result;
 }
 List<Edge> detectDeadlock() {
   Collection<Map<String, MapLockState>> collection =
       (Collection<Map<String, MapLockState>>) callOnAllMembers(new LockInformationCallable());
   List<Vertex> graph = new ArrayList<Vertex>();
   for (Map<String, MapLockState> mapLockStateMap : collection) {
     for (MapLockState map : mapLockStateMap.values()) {
       for (Object key : map.getLockOwners().keySet()) {
         Vertex owner = new Vertex(map.getLockOwners().get(key));
         Vertex requester = new Vertex(map.getLockRequested().get(key));
         int index = graph.indexOf(owner);
         if (index >= 0) {
           owner = graph.get(index);
         } else {
           graph.add(owner);
         }
         index = graph.indexOf(requester);
         if (index >= 0) {
           requester = graph.get(index);
         } else {
           graph.add(requester);
         }
         Edge edge = new Edge();
         edge.from = requester;
         edge.to = owner;
         edge.key = key;
         edge.mapName = map.getMapName();
         edge.globalLock = map.isGlobalLock();
         owner.addIncoming(edge);
         requester.addOutgoing(edge);
       }
     }
   }
   List<Edge> list = new ArrayList<Edge>();
   if (graph != null && graph.size() > 0) {
     try {
       graph.get(0).visit(list);
     } catch (RuntimeException e) {
     }
   }
   return list;
 }