@Override public int selectChannel(SerializationDelegate<StreamRecord<T>> record) { K key; try { key = keySelector.getKey(record.getInstance().getValue()); } catch (Exception e) { throw new RuntimeException("Could not extract key from " + record.getInstance(), e); } return partitioner.partition(key, numberOfChannels); }
private int[] customPartition(T record, int numberOfChannels) { if (channels == null) { channels = new int[1]; extractedKeys = new Object[1]; } try { if (comparator.extractKeys(record, extractedKeys, 0) == 1) { final Object key = extractedKeys[0]; channels[0] = partitioner.partition(key, numberOfChannels); return channels; } else { throw new RuntimeException("Inconsistency in the key comparator - comparator extracted more than one field."); } } catch (Throwable t) { throw new RuntimeException("Error while calling custom partitioner.", t); } }
private int customPartition(T record, int numberOfChannels) { if (extractedKeys == null) { extractedKeys = new Object[1]; } try { if (comparator.extractKeys(record, extractedKeys, 0) == 1) { final Object key = extractedKeys[0]; return partitioner.partition(key, numberOfChannels); } else { throw new RuntimeException("Inconsistency in the key comparator - comparator extracted more than one field."); } } catch (Throwable t) { throw new RuntimeException("Error while calling custom partitioner.", t); } }
private int[] customPartition(T record, int numberOfChannels) { if (channels == null) { channels = new int[1]; extractedKeys = new Object[1]; } try { if (comparator.extractKeys(record, extractedKeys, 0) == 1) { final Object key = extractedKeys[0]; channels[0] = partitioner.partition(key, numberOfChannels); return channels; } else { throw new RuntimeException("Inconsistency in the key comparator - comparator extracted more than one field."); } } catch (Throwable t) { throw new RuntimeException("Error while calling custom partitioner.", t); } }
private int[] customPartition(T record, int numberOfChannels) { if (channels == null) { channels = new int[1]; extractedKeys = new Object[1]; } try { if (comparator.extractKeys(record, extractedKeys, 0) == 1) { final Object key = extractedKeys[0]; channels[0] = partitioner.partition(key, numberOfChannels); return channels; } else { throw new RuntimeException("Inconsistency in the key comparator - comparator extracted more than one field."); } } catch (Throwable t) { throw new RuntimeException("Error while calling custom partitioner.", t); } }
@Override public int[] selectChannels(SerializationDelegate<StreamRecord<T>> record, int numberOfOutputChannels) { K key = null; try { key = keySelector.getKey(record.getInstance().getValue()); } catch (Exception e) { throw new RuntimeException("Could not extract key from " + record.getInstance(), e); } returnArray[0] = partitioner.partition(key, numberOfOutputChannels); return returnArray; }
@Override public int[] selectChannels(SerializationDelegate<StreamRecord<T>> record, int numberOfOutputChannels) { K key = null; try { key = keySelector.getKey(record.getInstance().getValue()); } catch (Exception e) { throw new RuntimeException("Could not extract key from " + record.getInstance(), e); } returnArray[0] = partitioner.partition(key, numberOfOutputChannels); return returnArray; }
@Override public int[] selectChannels(SerializationDelegate<StreamRecord<T>> record, int numberOfOutputChannels) { K key = null; try { key = keySelector.getKey(record.getInstance().getValue()); } catch (Exception e) { throw new RuntimeException("Could not extract key from " + record.getInstance(), e); } returnArray[0] = partitioner.partition(key, numberOfOutputChannels); return returnArray; }
@Override public int[] selectChannels(SerializationDelegate<StreamRecord<Tuple2<StreamRoute, Object>>> streamRecordSerializationDelegate, int numberOfOutputChannels) { Tuple2<StreamRoute, Object> value = streamRecordSerializationDelegate.getInstance().getValue(); if (value.f0.isBroadCastPartitioning()) { // send to all channels int[] channels = new int[numberOfOutputChannels]; for (int i = 0; i < numberOfOutputChannels; ++i) { channels[i] = i; } return channels; } else if (value.f0.getPartitionKey() == -1) { // random partition returnChannels[0] = random.nextInt(numberOfOutputChannels); } else { returnChannels[0] = partitioner.partition(value.f0.getPartitionKey(), numberOfOutputChannels); } return returnChannels; } }