com.datatorrent.api.StreamCodec Java Examples

The following examples show how to use com.datatorrent.api.StreamCodec. 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: StreamingContainer.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
private HashMap.SimpleEntry<String, ComponentContextPair<Stream, StreamContext>> deployBufferServerPublisher(
    String connIdentifier, StreamCodec<?> streamCodec, long finishedWindowId, int queueCapacity,
    OperatorDeployInfo.OutputDeployInfo nodi)
    throws UnknownHostException
{
  String sinkIdentifier = "tcp://".concat(nodi.bufferServerHost).concat(":").concat(String.valueOf(nodi.bufferServerPort)).concat("/").concat(connIdentifier);

  StreamContext bssc = new StreamContext(nodi.declaredStreamId);
  bssc.setPortId(nodi.portName);
  bssc.setSourceId(connIdentifier);
  bssc.setSinkId(sinkIdentifier);
  bssc.setFinishedWindowId(finishedWindowId);
  bssc.put(StreamContext.CODEC, streamCodec);
  bssc.put(StreamContext.EVENT_LOOP, eventloop);
  bssc.setBufferServerAddress(InetSocketAddress.createUnresolved(nodi.bufferServerHost, nodi.bufferServerPort));
  bssc.put(StreamContext.BUFFER_SERVER_TOKEN, nodi.bufferServerToken);
  InetAddress inetAddress = bssc.getBufferServerAddress().getAddress();
  if (inetAddress != null && NetUtils.isLocalAddress(inetAddress)) {
    bssc.setBufferServerAddress(new InetSocketAddress(InetAddress.getByName(null), nodi.bufferServerPort));
  }

  Stream publisher = fastPublisherSubscriber ? new FastPublisher(connIdentifier, queueCapacity * 256) : new BufferServerPublisher(connIdentifier, queueCapacity);
  return new HashMap.SimpleEntry<>(sinkIdentifier, new ComponentContextPair<>(publisher, bssc));
}
 
Example #2
Source File: StreamCodecWrapperForPersistance.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
public boolean shouldCaptureEvent(T o)
{
  for (Entry<InputPortMeta, Collection<PartitionKeys>> entry : inputPortToPartitionMap.entrySet()) {
    StreamCodec<Object> codec = codecsToMerge.get(entry.getKey());
    Collection<PartitionKeys> partitionKeysList = entry.getValue();

    for (PartitionKeys keys : partitionKeysList) {
      if ( keys.partitions != null && keys.partitions.contains(keys.mask & codec.getPartition(o))) {
        // Then at least one of the partitions is getting this event
        // So send the event to persist operator
        return true;
      }
    }
  }

  return false;
}
 
Example #3
Source File: PartitionAwareSink.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param serde
 * @param partitions
 * @param mask
 * @param output
 */
public PartitionAwareSink(StreamCodec<T> serde, Set<Integer> partitions, int mask, Sink<T> output)
{
  this.serde = serde;
  this.partitions = partitions;
  this.output = output;
  this.mask = mask;
}
 
Example #4
Source File: StreamCodecTest.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
private void checkPresentStreamCodecInfo(Map<Integer, StreamCodec<?>> streamCodecs, String id,
    Integer streamCodecIdentifier, StreamCodec<?> streamCodecInfo)
{
  StreamCodec<?> opStreamCodecInfo = streamCodecs.get(streamCodecIdentifier);
  Assert.assertNotNull("stream codec info null " + id, opStreamCodecInfo);
  Assert.assertEquals("stream codec not same " + id, opStreamCodecInfo, streamCodecInfo);
}
 
Example #5
Source File: StreamCodecTest.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
private void checkPresentStreamCodec(LogicalPlan.OperatorMeta operatorMeta, Operator.InputPort<?> inputPort,
    Map<Integer, StreamCodec<?>> streamCodecs,
    String id, PhysicalPlan plan)
{
  StreamCodec<?> streamCodec = operatorMeta.getMeta(inputPort).getStreamCodec();
  Assert.assertTrue("stream codec identifier not present" + id, isStrCodecPresent(streamCodec, plan));
  Integer streamCodecIdentifier = plan.getStreamCodecIdentifier(streamCodec);
  checkPresentStreamCodecInfo(streamCodecs, id, streamCodecIdentifier, streamCodec);
}
 
Example #6
Source File: POJOInnerJoinOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the streamcodec for the streams
 * @param isStream1data Specifies whether the codec needs for stream1 or stream2.
 * @return the object of JoinStreamCodec
 */
private StreamCodec<Object> getInnerJoinStreamCodec(boolean isStream1data)
{
  if (isStream1data) {
    return new JoinStreamCodec(getLeftKeyExpression());
  }
  return new JoinStreamCodec(getRightKeyExpression());
}
 
Example #7
Source File: PhysicalPlan.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
public Integer getStreamCodecIdentifier(StreamCodec<?> streamCodecInfo)
{
  Integer id;
  synchronized (streamCodecIdentifiers) {
    id = streamCodecIdentifiers.get(streamCodecInfo);
    if (id == null) {
      id = strCodecIdSequence.incrementAndGet();
      streamCodecIdentifiers.put(streamCodecInfo, id);
    }
  }
  return id;
}
 
Example #8
Source File: LogicalPlan.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
private void addStreamCodec(InputPortMeta sinkToPersistPortMeta, InputPort<?> port)
{
  StreamCodec<Object> inputStreamCodec = (StreamCodec<Object>)sinkToPersistPortMeta.getStreamCodec();
  if (inputStreamCodec != null) {
    Map<InputPortMeta, StreamCodec<Object>> codecs = new HashMap<>();
    codecs.put(sinkToPersistPortMeta, inputStreamCodec);
    InputPortMeta persistOperatorPortMeta = assertGetPortMeta(port);
    StreamCodec<Object> specifiedCodecForPersistOperator = (StreamCodec<Object>)persistOperatorPortMeta.getStreamCodec();
    StreamCodecWrapperForPersistance<Object> codec = new StreamCodecWrapperForPersistance<>(codecs, specifiedCodecForPersistOperator);
    persistOperatorPortMeta.setStreamCodec(codec);
  }
}
 
Example #9
Source File: LogicalPlan.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
void setStreamCodec(StreamCodec<?> streamCodec)
{
  if (streamCodec != null) {
    StreamCodec<?> oldStreamCodec = attributes.put(STREAM_CODEC, streamCodec);
    if (oldStreamCodec != null && oldStreamCodec != streamCodec) { // once input port codec is set, it is not expected that it will be changed.
      LOG.warn("Operator {} input port {} stream codec was changed from {} to {}", getOperatorMeta().getName(), getPortName(), oldStreamCodec, streamCodec);
    }
  }
}
 
Example #10
Source File: ValidationToFile.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public StreamCodec<byte[]> getStreamCodec()
{
  if (ValidationToFile.this.streamCodec == null) {
    return super.getStreamCodec();
  } else {
    return streamCodec;
  }
}
 
Example #11
Source File: StreamCodecWrapperForPersistance.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
public StreamCodec<Object> getSpecifiedStreamCodec()
{
  if (specifiedStreamCodec == null) {
    specifiedStreamCodec = new DefaultKryoStreamCodec();
  }
  return specifiedStreamCodec;
}
 
Example #12
Source File: AbstractBaseNOperatorMap.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public StreamCodec<Map<K, V>> getStreamCodec()
{
  StreamCodec<Map<K, V>> streamCodec = AbstractBaseNOperatorMap.this.getStreamCodec();
  if (streamCodec == null) {
    return super.getStreamCodec();
  } else {
    return streamCodec;
  }
}
 
Example #13
Source File: BufferServerPublisher.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void setup(StreamContext context)
{
  StreamCodec<?> codec = context.get(StreamContext.CODEC);
  if (codec == null) {
    statefulSerde = ((StatefulStreamCodec<Object>)StreamContext.CODEC.defaultValue).newInstance();
  } else if (codec instanceof StatefulStreamCodec) {
    statefulSerde = ((StatefulStreamCodec<Object>)codec).newInstance();
  } else {
    serde = (StreamCodec<Object>)codec;
  }
}
 
Example #14
Source File: BufferServerSubscriber.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
public SweepableReservoir acquireReservoirForPersistStream(String id, int capacity, StreamCodec<?> streamCodec)
{
  BufferReservoir r = reservoirMap.get(id);
  if (r == null) {
    reservoirMap.put(id, r = new BufferReservoirForPersistStream(capacity, (StreamCodecWrapperForPersistance<Object>)streamCodec));
    BufferReservoir[] newReservoirs = new BufferReservoir[reservoirs.length + 1];
    newReservoirs[reservoirs.length] = r;
    for (int i = reservoirs.length; i-- > 0;) {
      newReservoirs[i] = reservoirs[i];
    }
    reservoirs = newReservoirs;
  }

  return r;
}
 
Example #15
Source File: BufferServerSubscriber.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void setup(StreamContext context)
{
  StreamCodec<?> codec = context.get(StreamContext.CODEC);
  if (codec == null) {
    statefulSerde = ((StatefulStreamCodec<Object>)StreamContext.CODEC.defaultValue).newInstance();
  } else if (codec instanceof StatefulStreamCodec) {
    statefulSerde = ((StatefulStreamCodec<Object>)codec).newInstance();
  } else {
    serde = (StreamCodec<Object>)codec;
  }
  baseSeconds = context.getFinishedWindowId() & 0xffffffff00000000L;
}
 
Example #16
Source File: MaxKeyVal.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
/**
 * Set StreamCodec used for partitioning.
 */
@Override
public StreamCodec<KeyValPair<K, V>> getStreamCodec()
{
  return getKeyValPairStreamCodec();
}
 
Example #17
Source File: MinKeyVal.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
/**
 * Set StreamCodec used for partitioning.
 */
@Override
public StreamCodec<KeyValPair<K, V>> getStreamCodec()
{
  return getKeyValPairStreamCodec();
}
 
Example #18
Source File: BaseKeyValueOperator.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
/**
 * A codec to enable partitioning to be done by key
 */
public StreamCodec<KeyValPair<K, V>> getKeyValPairStreamCodec()
{
  return new DefaultPartitionCodec<K, V>();
}
 
Example #19
Source File: RangeKeyVal.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
public StreamCodec<KeyValPair<K, V>> getStreamCodec()
{
  return getKeyValPairStreamCodec();
}
 
Example #20
Source File: SumKeyVal.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
/**
 * Stream codec used for partitioning.
 */
@Override
public StreamCodec<KeyValPair<K, V>> getStreamCodec()
{
  return getKeyValPairStreamCodec();
}
 
Example #21
Source File: LogstreamTopN.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
protected StreamCodec<Map<String, DimensionObject<String>>> getStreamCodec()
{
  return new LogstreamTopNStreamCodec();
}
 
Example #22
Source File: MarginKeyVal.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
/**
 * Set StreamCodec used for partitioning.
 */
@Override
public StreamCodec<KeyValPair<K, V>> getStreamCodec()
{
  return getKeyValPairStreamCodec();
}
 
Example #23
Source File: MarginKeyVal.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
/**
 * Set StreamCodec used for partitioning.
 */
@Override
public StreamCodec<KeyValPair<K, V>> getStreamCodec()
{
  return getKeyValPairStreamCodec();
}
 
Example #24
Source File: ManagedTimeStateMultiValue.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public StreamCodec getStreamCodec()
{
  return streamCodec;
}
 
Example #25
Source File: ManagedTimeStateMultiValue.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public void setStreamCodec(StreamCodec streamCodec)
{
  this.streamCodec = streamCodec;
}
 
Example #26
Source File: POJOInnerJoinOperator.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
public StreamCodec<Object> getStreamCodec()
{
  return getInnerJoinStreamCodec(true);
}
 
Example #27
Source File: POJOInnerJoinOperator.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
public StreamCodec<Object> getStreamCodec()
{
  return getInnerJoinStreamCodec(false);
}
 
Example #28
Source File: BoundedDedupOperator.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
public StreamCodec<Object> getStreamCodec()
{
  return streamCodec;
}
 
Example #29
Source File: BoundedDedupOperator.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
protected StreamCodec<Object> getDeduperStreamCodec()
{
  return new DeduperStreamCodec(keyExpression);
}
 
Example #30
Source File: TimeBasedDedupOperator.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
public StreamCodec<Object> getStreamCodec()
{
  return streamCodec;
}