use of io.s4.dispatcher.partitioner.VariableKeyPartitioner in project core by s4.
the class Dispatcher method dispatchEvent.
private void dispatchEvent(String streamName, Object event, boolean variableKey, List<List<String>> compoundKeyNames) {
synchronized (this) {
rawEventCount++;
}
if (eventEmitter.getNodeCount() <= 0) {
return;
} else {
if (counts == null) {
counts = new int[eventEmitter.getNodeCount()];
}
}
try {
synchronized (this) {
eventCount++;
}
List<CompoundKeyInfo> partionInfoList = new ArrayList<CompoundKeyInfo>();
for (Partitioner partitioner : partitioners) {
List<CompoundKeyInfo> pInfoList = null;
if (!variableKey) {
pInfoList = partitioner.partition(streamName, event, eventEmitter.getNodeCount());
} else {
if (partitioner instanceof VariableKeyPartitioner) {
VariableKeyPartitioner vp = (VariableKeyPartitioner) partitioner;
pInfoList = vp.partition(streamName, compoundKeyNames, event, eventEmitter.getNodeCount());
}
}
if (pInfoList != null) {
partionInfoList.addAll(pInfoList);
}
}
Map<Integer, List<CompoundKeyInfo>> pInfoMap = new HashMap<Integer, List<CompoundKeyInfo>>();
for (CompoundKeyInfo partitionInfo : partionInfoList) {
int partitionId = partitionInfo.getPartitionId();
List<CompoundKeyInfo> listByPartitionNumber = pInfoMap.get(partitionId);
if (listByPartitionNumber == null) {
listByPartitionNumber = new ArrayList<CompoundKeyInfo>();
pInfoMap.put(partitionId, listByPartitionNumber);
}
listByPartitionNumber.add(partitionInfo);
}
for (int partitionId : pInfoMap.keySet()) {
EventWrapper eventWrapper = new EventWrapper(streamName, event, pInfoMap.get(partitionId));
counts[partitionId]++;
eventEmitter.emit(partitionId, eventWrapper);
}
} catch (Exception e) {
Logger.getLogger(loggerName).error("Exception in processEvent on thread " + Thread.currentThread().getId() + " at time " + System.currentTimeMillis(), e);
}
}
Aggregations