[ https://issues.apache.org/jira/browse/GOBBLIN-807?focusedWorklogId=268937&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-268937 ]
ASF GitHub Bot logged work on GOBBLIN-807: ------------------------------------------ Author: ASF GitHub Bot Created on: 27/Jun/19 23:07 Start Date: 27/Jun/19 23:07 Worklog Time Spent: 10m Work Description: vikrambohra commented on pull request #2678: [GOBBLIN-807] TimingEvent is now closeable, extends GobblinEventBuilder URL: https://github.com/apache/incubator-gobblin/pull/2678#discussion_r298402704 ########## File path: gobblin-metrics-libs/gobblin-metrics-base/src/main/java/org/apache/gobblin/metrics/event/CountEventBuilder.java ########## @@ -0,0 +1,95 @@ +/* + * 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 org.apache.gobblin.metrics.event; + +import java.util.Map; + +import org.apache.commons.lang.StringUtils; + +import lombok.Getter; +import lombok.Setter; + +import org.apache.gobblin.metrics.GobblinTrackingEvent; + +/** + * The builder builds builds a specific {@link GobblinTrackingEvent} whose metadata has + * {@value GobblinEventBuilder#EVENT_TYPE} to be {@value #COUNT_EVENT_TYPE} + * + * <p> + * Note: A {@link CountEventBuilder} instance is not reusable + */ +public class CountEventBuilder extends GobblinEventBuilder { + + public static final String COUNT_EVENT_TYPE = "CountEvent"; + public static final String COUNT_KEY = "count"; + @Setter + @Getter + private int count; + + public CountEventBuilder(String name, int count) { + this(name, NAMESPACE, count); + } + + public CountEventBuilder(String name, String namespace, int count) { + super(name, namespace); + this.metadata.put(EVENT_TYPE, COUNT_EVENT_TYPE); + this.count = count; + } + + /** + * + * @return {@link GobblinTrackingEvent} + */ + @Override + public GobblinTrackingEvent build() { + this.metadata.put(COUNT_KEY, Integer.toString(count)); + return super.build(); + } + + /** + * Check if the given {@link GobblinTrackingEvent} is a {@link CountEventBuilder} + */ + public static boolean isCountEvent(GobblinTrackingEvent event) { + String eventType = (event.getMetadata() == null) ? "" : event.getMetadata().get(EVENT_TYPE); + return StringUtils.isNotEmpty(eventType) && eventType.equals(COUNT_EVENT_TYPE); + } + /** + * Create a {@link CountEventBuilder} from a {@link GobblinTrackingEvent}. An inverse function + * to {@link CountEventBuilder#build()} + */ + public static CountEventBuilder fromEvent(GobblinTrackingEvent event) { + if(!isCountEvent(event)) { + return null; + } + + Map<String, String> metadata = event.getMetadata(); + int count = Integer.parseInt(metadata.get(COUNT_KEY)); Review comment: done ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 268937) Time Spent: 4h 10m (was: 4h) > TimingEvent to extend GobblinEventBuilder > ------------------------------------------ > > Key: GOBBLIN-807 > URL: https://issues.apache.org/jira/browse/GOBBLIN-807 > Project: Apache Gobblin > Issue Type: Improvement > Reporter: Vikram Bohra > Priority: Minor > Time Spent: 4h 10m > Remaining Estimate: 0h > > GobblinEventBuilder and its subclasses should be used to build > GobblinTrackingEvents and EventSubmitter should solely be responsible for > submitting events. Depreacate older roles and methods > appropriately.TimingEvent should extend the GobblinEventBuilder while > maintaining older methods for backward compatability. -- This message was sent by Atlassian JIRA (v7.6.3#76005)