You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apex.apache.org by chandnisingh <gi...@git.apache.org> on 2016/02/22 23:30:27 UTC

[GitHub] incubator-apex-malhar pull request: MLHR-1897 #comment added manag...

Github user chandnisingh commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/145#discussion_r53704929
  
    --- Diff: library/src/main/java/com/datatorrent/lib/state/managed/TimeBucketAssigner.java ---
    @@ -0,0 +1,223 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package com.datatorrent.lib.state.managed;
    +
    +import java.util.Calendar;
    +import java.util.Set;
    +
    +import javax.validation.constraints.NotNull;
    +
    +import org.joda.time.Duration;
    +
    +import com.esotericsoftware.kryo.serializers.FieldSerializer;
    +import com.esotericsoftware.kryo.serializers.JavaSerializer;
    +import com.google.common.collect.Sets;
    +
    +import com.datatorrent.api.Component;
    +import com.datatorrent.api.Context;
    +import com.datatorrent.lib.appdata.query.WindowBoundedService;
    +
    +/**
    + * Keeps track of time buckets.<br/>
    + *
    + * The data of a bucket is further divided into time-buckets. This component controls the length of time buckets,
    + * which time-bucket an event falls into and sliding the time boundaries.
    + * <p/>
    + *
    + * The configuration {@link #expireBefore} and {@link #bucketSpan}  are used to calculate number of time-buckets.
    + * For eg. if <code>expireBefore = 1 hour</code> and <code>bucketSpan = 30 minutes</code>, then <code>
    + *   numBuckets = 60 minutes/ 30 minutes = 2 </code>.
    + * <p/>
    + *
    + * The time boundaries- start and end, periodically move by span of a single time-bucket. Any event with time < start
    + * is expired. These boundaries slide between application window by another thread and not the operator thread.
    + */
    +public class TimeBucketAssigner implements Component<Context.OperatorContext>
    +{
    +  @NotNull
    +  @FieldSerializer.Bind(JavaSerializer.class)
    +  private Duration expireBefore = Duration.standardDays(2);
    +
    +  @FieldSerializer.Bind(JavaSerializer.class)
    +  private Duration bucketSpan;
    +
    +  private long bucketSpanMillis;
    +
    +  private long fixedStartTime;
    +  private long startTime;
    +  private long endTime;
    +  private int numBuckets;
    +
    +  private boolean initialized;
    +
    +  private transient WindowBoundedService windowBoundedService;
    +
    +  @NotNull
    +  private final transient Set<Listener> listeners = Sets.newHashSet();
    --- End diff --
    
    From @amberarrow 
    Do we need a set here, i.e. do we expect more than one listener ? With a set, several questions come up:
    1. We should document the fact that the listener should ensure that set membership works correctly by implementing hashCode()/equals().
    2. The purgeTimeBucketsBefore() method should not take a long time since it is run with a lock held in the expiry task.
    3. Do we need an unregister() method to remove a listener ?
    
    All these go away if we limit it to just 1 listener.
    ---------------
     
    Made the change


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---