Skip to content

Commit 2bd2f85

Browse files
author
Vickey Singh
committed
Minor fixes
- Remove commented out code - Uncomment debug log - Use Set backed by ConcurrentHashMap instead of Synchronized Set - Correct grammatical mistakes - Add ThreadSafe annotation
1 parent d739c96 commit 2bd2f85

11 files changed

+53
-38
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55

66
<groupId>com.flipkart.databuilderframework</groupId>
7-
<version>0.5.12</version>
7+
<version>0.5.13-SNAPSHOT</version>
88
<modelVersion>4.0.0</modelVersion>
99

1010
<artifactId>databuilderframework</artifactId>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.flipkart.databuilderframework.annotations;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* Annotation to mark a class as thread safe.
10+
*/
11+
@Retention(RetentionPolicy.SOURCE)
12+
@Target(ElementType.TYPE)
13+
public @interface ThreadSafe {
14+
15+
}

src/main/java/com/flipkart/databuilderframework/engine/DataBuilderContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public DataSet getDataSet(DataBuilder builder) {
4545

4646
/**
4747
* Access the data set. Ideally a builder should only access data as declared.
48-
* Deprecated: This methpd will be removed in the near future. Do not use this in newer projects.
48+
* Deprecated: This method will be removed in the near future. Do not use this in newer projects.
4949
* @return The full data set.
5050
*/
5151
@Deprecated

src/main/java/com/flipkart/databuilderframework/engine/ExecutionGraphGenerator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public ExecutionGraph generateGraph(final DataFlow dataFlow) throws DataBuilderF
7979
List<List<DataBuilderMeta>> dependencyHierarchy
8080
= TimedExecutor.run("ExecutionGraphGenerator::buildHierarchy", () -> buildHierarchy(dependencyInfoManager, maxHeight));
8181

82-
//Return
8382
return new ExecutionGraph(dependencyHierarchy);
8483
}
8584

src/main/java/com/flipkart/databuilderframework/engine/MultiThreadedDataFlowExecutor.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.flipkart.databuilderframework.engine;
22

3+
import com.flipkart.databuilderframework.annotations.ThreadSafe;
34
import com.flipkart.databuilderframework.model.*;
45
import com.google.common.base.Preconditions;
56
import com.google.common.collect.Lists;
@@ -14,6 +15,7 @@
1415
/**
1516
* The executor for a {@link com.flipkart.databuilderframework.model.DataFlow}.
1617
*/
18+
@ThreadSafe
1719
public class MultiThreadedDataFlowExecutor extends DataFlowExecutor {
1820
private static final Logger logger = LoggerFactory.getLogger(MultiThreadedDataFlowExecutor.class.getSimpleName());
1921
private final ExecutorService executorService;
@@ -49,7 +51,7 @@ protected DataExecutionResponse run(DataBuilderContext dataBuilderContext,
4951
}
5052
List<List<DataBuilderMeta>> dependencyHierarchy = executionGraph.getDependencyHierarchy();
5153
Set<String> newlyGeneratedData = Sets.newHashSet();
52-
Set<DataBuilderMeta> processedBuilders = Collections.synchronizedSet(Sets.<DataBuilderMeta>newHashSet());
54+
Set<DataBuilderMeta> processedBuilders = ConcurrentHashMap.newKeySet();
5355
while(true) {
5456
for (List<DataBuilderMeta> levelBuilders : dependencyHierarchy) {
5557
List<Future<DataContainer>> dataFutures = Lists.newArrayList();
@@ -109,18 +111,13 @@ protected DataExecutionResponse run(DataBuilderContext dataBuilderContext,
109111
}
110112
}
111113
if(newlyGeneratedData.contains(dataFlow.getTargetData())) {
112-
//logger.debug("Finished running this instance of the flow. Exiting.");
114+
logger.debug("Finished running this instance of the flow. Exiting.");
113115
break;
114116
}
115117
if(newlyGeneratedData.isEmpty()) {
116-
//logger.debug("Nothing happened in this loop, exiting..");
118+
logger.debug("Nothing happened in this loop, exiting..");
117119
break;
118120
}
119-
// StringBuilder stringBuilder = new StringBuilder();
120-
// for(String data : newlyGeneratedData) {
121-
// stringBuilder.append(data + ", ");
122-
// }
123-
//logger.info("Newly generated: " + stringBuilder);
124121
activeDataSet.clear();
125122
activeDataSet.addAll(newlyGeneratedData);
126123
newlyGeneratedData.clear();

src/main/java/com/flipkart/databuilderframework/engine/OptimizedMultiThreadedDataFlowExecutor.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.flipkart.databuilderframework.engine;
22

3+
import com.flipkart.databuilderframework.annotations.ThreadSafe;
34
import com.flipkart.databuilderframework.model.*;
45
import com.google.common.base.Preconditions;
56
import com.google.common.collect.Lists;
@@ -15,6 +16,7 @@
1516
/**
1617
* The executor for a {@link com.flipkart.databuilderframework.model.DataFlow}.
1718
*/
19+
@ThreadSafe
1820
public class OptimizedMultiThreadedDataFlowExecutor extends DataFlowExecutor {
1921
private static final Logger logger = LoggerFactory.getLogger(OptimizedMultiThreadedDataFlowExecutor.class.getSimpleName());
2022
private final ExecutorService executorService;
@@ -50,11 +52,11 @@ protected DataExecutionResponse run(DataBuilderContext dataBuilderContext,
5052
}
5153
List<List<DataBuilderMeta>> dependencyHierarchy = executionGraph.getDependencyHierarchy();
5254
Set<String> newlyGeneratedData = Sets.newHashSet();
53-
Set<DataBuilderMeta> processedBuilders = Collections.synchronizedSet(Sets.<DataBuilderMeta>newHashSet());
55+
Set<DataBuilderMeta> processedBuilders = ConcurrentHashMap.newKeySet();
5456
while(true) {
5557
for (List<DataBuilderMeta> levelBuilders : dependencyHierarchy) {
5658
List<Future<DataContainer>> dataFutures = Lists.newArrayList();
57-
BuilderRunner singleRef = null; //refrence to builderRunner when size of levelBuilders == 1 to avoid running it behind thread
59+
BuilderRunner singleRef = null; //reference to builderRunner when size of levelBuilders == 1 to avoid running it behind thread
5860
for (DataBuilderMeta builderMeta : levelBuilders) {
5961
if (processedBuilders.contains(builderMeta)) {
6062
continue;
@@ -128,18 +130,13 @@ protected DataExecutionResponse run(DataBuilderContext dataBuilderContext,
128130
}
129131
}
130132
if(newlyGeneratedData.contains(dataFlow.getTargetData())) {
131-
//logger.debug("Finished running this instance of the flow. Exiting.");
133+
logger.debug("Finished running this instance of the flow. Exiting.");
132134
break;
133135
}
134136
if(newlyGeneratedData.isEmpty()) {
135-
//logger.debug("Nothing happened in this loop, exiting..");
137+
logger.debug("Nothing happened in this loop, exiting..");
136138
break;
137139
}
138-
// StringBuilder stringBuilder = new StringBuilder();
139-
// for(String data : newlyGeneratedData) {
140-
// stringBuilder.append(data + ", ");
141-
// }
142-
//logger.info("Newly generated: " + stringBuilder);
143140
activeDataSet.clear();
144141
activeDataSet.addAll(newlyGeneratedData);
145142
newlyGeneratedData.clear();

src/main/java/com/flipkart/databuilderframework/engine/SimpleDataFlowExecutor.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.flipkart.databuilderframework.engine;
22

3+
import com.flipkart.databuilderframework.annotations.ThreadSafe;
34
import com.flipkart.databuilderframework.model.*;
45
import com.google.common.base.Preconditions;
56
import com.google.common.collect.Maps;
@@ -16,6 +17,7 @@
1617
/**
1718
* The executor for a {@link com.flipkart.databuilderframework.model.DataFlow}.
1819
*/
20+
@ThreadSafe
1921
public class SimpleDataFlowExecutor extends DataFlowExecutor {
2022
private static final Logger logger = LoggerFactory.getLogger(SimpleDataFlowExecutor.class.getSimpleName());
2123

@@ -145,18 +147,14 @@ protected DataExecutionResponse run(DataBuilderContext dataBuilderContext,
145147
}
146148
}
147149
if(newlyGeneratedData.contains(dataFlow.getTargetData())) {
148-
//logger.debug("Finished running this instance of the flow. Exiting.");
150+
// Found the target data node
151+
logger.debug("Finished running this instance of the flow. Exiting.");
149152
break;
150153
}
151154
if(newlyGeneratedData.isEmpty()) {
152-
//logger.debug("Nothing happened in this loop, exiting..");
155+
logger.debug("Nothing happened in this loop, exiting..");
153156
break;
154157
}
155-
// StringBuilder stringBuilder = new StringBuilder();
156-
// for(String data : newlyGeneratedData) {
157-
// stringBuilder.append(data + ", ");
158-
// }
159-
//logger.info("Newly generated: " + stringBuilder);
160158
activeDataSet.clear();
161159
activeDataSet.addAll(newlyGeneratedData);
162160
newlyGeneratedData.clear();

src/main/java/com/flipkart/databuilderframework/model/Data.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
import lombok.ToString;
66

77
import javax.validation.constraints.NotNull;
8+
import java.io.Serializable;
89

910
/**
1011
* Data base class. All data classes to be considered by a DataBuilder need to inherit from this
1112
*/
1213
@JsonTypeInfo(use= JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "data")
1314
@lombok.Data
1415
@ToString
15-
public abstract class Data {
16+
public abstract class Data implements Serializable {
1617

18+
private static final long serialVersionUID = 3237890729688723887L;
1719
/**
1820
* The type-name for data. This is an app defined tag for this data.
1921
* Needs to be set by the inheriting class.

src/main/java/com/flipkart/databuilderframework/model/DataFlow.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
import com.fasterxml.jackson.annotation.JsonProperty;
55
import com.flipkart.databuilderframework.engine.DataBuilderFactory;
66
import com.google.common.collect.Maps;
7+
import com.google.common.collect.Sets;
78
import lombok.Builder;
89
import org.hibernate.validator.constraints.NotEmpty;
910

1011
import javax.validation.constraints.NotNull;
1112
import java.io.Serializable;
13+
import java.util.HashSet;
1214
import java.util.Map;
1315
import java.util.Set;
1416

@@ -105,13 +107,13 @@ public DataFlow() {
105107

106108
public DataFlow deepCopy() {
107109
return new DataFlow(name,
108-
description,
109-
targetData,
110-
resolutionSpecs,
111-
executionGraph.deepCopy(),
112-
transients,
113-
enabled,
114-
loopingEnabled,
115-
dataBuilderFactory);
110+
description,
111+
targetData,
112+
Maps.newHashMap(resolutionSpecs),
113+
executionGraph.deepCopy(),
114+
Sets.newHashSet(transients),
115+
enabled,
116+
loopingEnabled,
117+
dataBuilderFactory);
116118
}
117119
}

src/main/java/com/flipkart/databuilderframework/model/DataFlowInstance.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
import org.hibernate.validator.constraints.NotEmpty;
55

66
import javax.validation.constraints.NotNull;
7+
import java.io.Serializable;
78

89
/**
910
* A instance of the {@link com.flipkart.databuilderframework.model.DataFlow} object to be used for execution.
1011
* This class represents a running instance of the flow. It contains the flow itself as well as the
1112
* {@link com.flipkart.databuilderframework.model.DataSet} required for execution.
1213
*/
13-
public class DataFlowInstance {
14+
public class DataFlowInstance implements Serializable {
1415

16+
private static final long serialVersionUID = 7886384565411534126L;
1517
/**
1618
* The ID of the flow instance.
1719
*/

src/main/java/com/flipkart/databuilderframework/model/DataSet.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
import org.hibernate.validator.constraints.NotEmpty;
88

99
import javax.validation.constraints.NotNull;
10+
import java.io.Serializable;
1011
import java.util.Map;
1112

1213
/**
1314
* Working set for data
1415
* Contains all the data that has been provided by the system as well as those generated by the system.
1516
*/
16-
public class DataSet {
17+
public class DataSet implements Serializable {
18+
19+
private static final long serialVersionUID = -7453209452035943145L;
1720
/**
1821
* All data present for this flow execution.
1922
*/

0 commit comments

Comments
 (0)