From commits-return-2240-archive-asf-public=cust-asf.ponee.io@eagle.apache.org Wed Feb 7 08:07:13 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id 494E518065B for ; Wed, 7 Feb 2018 08:07:13 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 3929F160C5B; Wed, 7 Feb 2018 07:07:13 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 12ABA160C60 for ; Wed, 7 Feb 2018 08:07:10 +0100 (CET) Received: (qmail 9076 invoked by uid 500); 7 Feb 2018 07:07:10 -0000 Mailing-List: contact commits-help@eagle.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@eagle.apache.org Delivered-To: mailing list commits@eagle.apache.org Received: (qmail 8813 invoked by uid 99); 7 Feb 2018 07:07:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Feb 2018 07:07:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 4AE12F3536; Wed, 7 Feb 2018 07:07:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jaysen@apache.org To: commits@eagle.apache.org Date: Wed, 07 Feb 2018 07:07:17 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [10/10] eagle git commit: [EAGLE-1081] Checkstyle fixes for eagle-entity-base module [EAGLE-1081] Checkstyle fixes for eagle-entity-base module Be sure to do all of the following to help us incorporate your contribution quickly and easily: - [ ] Make sure the PR title is formatted like: `[EAGLE-] Description of pull request` - [ ] Make sure tests pass via `mvn clean verify`. (Even better, enable Travis-CI on your fork and ensure the whole test matrix passes). - [ ] Replace `` in the title with the actual Jira issue number, if there is one. - [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.txt). --- Author: Colm O hEigeartaigh Closes #985 from coheigea/EAGLE-1081. Project: http://git-wip-us.apache.org/repos/asf/eagle/repo Commit: http://git-wip-us.apache.org/repos/asf/eagle/commit/6e919c2e Tree: http://git-wip-us.apache.org/repos/asf/eagle/tree/6e919c2e Diff: http://git-wip-us.apache.org/repos/asf/eagle/diff/6e919c2e Branch: refs/heads/master Commit: 6e919c2e8d20957775ed22410557a4fee83339a4 Parents: c970bb4 Author: Colm O hEigeartaigh Authored: Tue Feb 6 23:07:01 2018 -0800 Committer: Jay Sen Committed: Tue Feb 6 23:07:01 2018 -0800 ---------------------------------------------------------------------- .../eagle/log/base/taggedlog/EntityContext.java | 32 +- .../log/base/taggedlog/EntityJsonModule.java | 6 +- .../log/base/taggedlog/MapEntrySerializer.java | 7 +- .../log/base/taggedlog/NoSuchRowException.java | 18 +- .../log/base/taggedlog/RowkeyAPIEntity.java | 119 +- .../log/base/taggedlog/TaggedLogAPIEntity.java | 29 +- .../base/taggedlog/TaggedLogObjectMapper.java | 29 +- .../log/entity/AbstractHBaseLogReader.java | 401 +++---- .../eagle/log/entity/BaseEntityRepository.java | 8 +- .../log/entity/EntityCreationListener.java | 4 +- .../eagle/log/entity/EntityQualifierUtils.java | 490 ++++---- .../org/apache/eagle/log/entity/EntityUniq.java | 79 +- .../entity/GenericCreateAPIResponseEntity.java | 59 +- .../log/entity/GenericEntityBatchReader.java | 71 +- .../entity/GenericEntityScanStreamReader.java | 45 +- .../log/entity/GenericEntityStreamReader.java | 188 +-- .../log/entity/GenericEntityStreamReaderMT.java | 235 ++-- .../eagle/log/entity/GenericEntityWriter.java | 89 +- .../eagle/log/entity/GenericMetricEntity.java | 38 +- .../entity/GenericMetricEntityBatchReader.java | 61 +- ...ricMetricEntityDecompactionStreamReader.java | 143 +-- .../log/entity/GenericMetricShadowEntity.java | 14 +- .../entity/GenericServiceAPIResponseEntity.java | 55 +- ...ricServiceAPIResponseEntityDeserializer.java | 54 +- .../log/entity/HBaseInternalLogHelper.java | 440 +++---- .../eagle/log/entity/HBaseLogReader2.java | 103 +- .../apache/eagle/log/entity/HBaseLogWriter.java | 241 ++-- .../apache/eagle/log/entity/InternalLog.java | 241 ++-- .../log/entity/ListQueryAPIResponseEntity.java | 126 +- .../org/apache/eagle/log/entity/LogReader.java | 11 +- .../org/apache/eagle/log/entity/LogWriter.java | 17 +- .../eagle/log/entity/MetricMetadataEntity.java | 174 +-- .../log/entity/QualifierCreationListener.java | 12 +- .../entity/QualifierNotDefinedException.java | 16 +- .../apache/eagle/log/entity/RowkeyBuilder.java | 228 ++-- .../entity/RowkeyQueryAPIResponseEntity.java | 53 +- .../eagle/log/entity/SearchCondition.java | 254 +++-- .../apache/eagle/log/entity/StreamReader.java | 67 +- .../filter/BooleanExpressionComparator.java | 136 ++- .../log/entity/filter/HBaseFilterBuilder.java | 1074 +++++++++--------- .../entity/filter/QualifierFilterEntity.java | 162 +-- .../eagle/log/entity/filter/RowValueFilter.java | 54 +- .../entity/filter/TypedByteArrayComparator.java | 87 +- .../eagle/log/entity/index/IndexLogReader.java | 36 +- .../log/entity/index/IndexStreamReader.java | 118 +- .../index/NonClusteredIndexLogReader.java | 324 +++--- .../index/NonClusteredIndexStreamReader.java | 42 +- .../eagle/log/entity/index/RowKeyLogReader.java | 85 +- .../log/entity/index/UniqueIndexLogReader.java | 138 +-- .../entity/index/UniqueIndexStreamReader.java | 43 +- .../eagle/log/entity/meta/BooleanSerDeser.java | 55 +- .../apache/eagle/log/entity/meta/Column.java | 6 +- .../eagle/log/entity/meta/ColumnFamily.java | 6 +- .../entity/meta/DefaultJavaObjctSerDeser.java | 4 +- .../log/entity/meta/Double2DArraySerDeser.java | 38 +- .../log/entity/meta/DoubleArraySerDeser.java | 91 +- .../eagle/log/entity/meta/DoubleSerDeser.java | 38 +- .../eagle/log/entity/meta/EntityDefinition.java | 618 +++++----- .../entity/meta/EntityDefinitionManager.java | 911 ++++++++------- .../eagle/log/entity/meta/EntitySerDeser.java | 8 +- .../log/entity/meta/EntitySerDeserializer.java | 100 +- .../org/apache/eagle/log/entity/meta/Index.java | 8 +- .../eagle/log/entity/meta/IndexDefinition.java | 589 +++++----- .../apache/eagle/log/entity/meta/Indexes.java | 6 +- .../eagle/log/entity/meta/IntArraySerDeser.java | 94 +- .../eagle/log/entity/meta/IntSerDeser.java | 41 +- .../eagle/log/entity/meta/ListSerDeser.java | 186 +-- .../eagle/log/entity/meta/LongSerDeser.java | 43 +- .../eagle/log/entity/meta/MapSerDeser.java | 273 ++--- .../apache/eagle/log/entity/meta/Metric.java | 8 +- .../eagle/log/entity/meta/MetricDefinition.java | 86 +- .../eagle/log/entity/meta/NonUniqueIndex.java | 4 +- .../eagle/log/entity/meta/NonUniqueIndexes.java | 9 +- .../eagle/log/entity/meta/NullSerDeser.java | 30 +- .../apache/eagle/log/entity/meta/Partition.java | 17 +- .../apache/eagle/log/entity/meta/Prefix.java | 8 +- .../apache/eagle/log/entity/meta/Qualifier.java | 139 +-- .../apache/eagle/log/entity/meta/Service.java | 6 +- .../eagle/log/entity/meta/ServicePath.java | 5 +- .../log/entity/meta/StringArraySerDeser.java | 128 +-- .../eagle/log/entity/meta/StringSerDeser.java | 34 +- .../org/apache/eagle/log/entity/meta/Table.java | 6 +- .../org/apache/eagle/log/entity/meta/Tags.java | 4 +- .../eagle/log/entity/meta/TimeSeries.java | 6 +- .../log/entity/old/GenericByRowkeyReader.java | 90 +- .../eagle/log/entity/old/GenericDeleter.java | 144 +-- .../eagle/log/entity/old/GenericReader.java | 159 +-- .../eagle/log/entity/old/GenericWriter.java | 114 +- .../log/entity/old/HBaseLogByRowkeyReader.java | 231 ++-- .../eagle/log/entity/old/HBaseLogDeleter.java | 197 ++-- .../eagle/log/entity/old/HBaseLogReader.java | 402 +++---- .../apache/eagle/log/entity/old/LogDeleter.java | 15 +- .../eagle/log/entity/old/RowkeyHelper.java | 97 +- .../org/apache/eagle/log/entity/old/Schema.java | 11 +- .../entity/repo/DefaultEntityRepository.java | 12 +- .../eagle/log/entity/repo/EntityRepository.java | 45 +- .../entity/repo/EntityRepositoryScanner.java | 48 +- .../eagle/log/entity/test/TestEntity.java | 125 +- .../eagle/log/entity/test/TestLogAPIEntity.java | 152 +-- .../entity/test/TestTimeSeriesAPIEntity.java | 147 +-- .../eagle/log/expression/ExpressionParser.java | 314 +++-- .../log/expression/ParsiiInvalidException.java | 56 +- .../ParsiiUnknowVariableException.java | 56 +- .../TestGenericServiceAPIResponseEntity.java | 41 +- .../log/entity/TestDouble2DArraySerDeser.java | 20 +- .../eagle/log/entity/TestDoubleSerDeser.java | 71 +- .../TestGenericEntityIndexStreamReader.java | 35 +- .../log/entity/TestHBaseIntegerLogHelper.java | 62 +- .../TestHBaseWriteEntitiesPerformance.java | 31 +- .../log/entity/TestHBaseWritePerformance.java | 127 +-- .../eagle/log/entity/TestTestLogAPIEntity.java | 63 +- .../base/taggedlog/TestTaggedLogAPIEntity.java | 29 +- .../filter/TestEntityQualifierHelper.java | 303 ++--- .../entity/filter/TestExpressionComparator.java | 203 ++-- .../entity/filter/TestHBaseFilterBuilder.java | 465 ++++---- .../filter/TestTypedByteArrayComparator.java | 17 +- .../log/entity/meta/TestArraySerDeser.java | 82 +- .../meta/TestEntityDefinitionManager.java | 11 +- .../eagle/log/entity/meta/TestListSerDeser.java | 138 +-- .../eagle/log/entity/meta/TestMapSerDeser.java | 154 +-- .../repo/TestEntityRepositoryScanner.java | 12 +- .../log/expression/TestExpressionParser.java | 382 +++---- .../expression/TestExpressionPerformance.java | 153 +-- 123 files changed, 7708 insertions(+), 7267 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/eagle/blob/6e919c2e/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/EntityContext.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/EntityContext.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/EntityContext.java index 17b3fdb..14245df 100644 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/EntityContext.java +++ b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/EntityContext.java @@ -20,21 +20,21 @@ import java.util.HashMap; import java.util.Map; public class EntityContext { - private Map context; + private Map context; - public Map getContext() { - return context; - } - - public EntityContext() { - this.context = new HashMap<>(); - } - - protected EntityContext(EntityContext context) { - this.context = new HashMap<>(context.context); - } - - public EntityContext cloneEntity() { - return new EntityContext(this); - } + public Map getContext() { + return context; + } + + public EntityContext() { + this.context = new HashMap<>(); + } + + protected EntityContext(EntityContext context) { + this.context = new HashMap<>(context.context); + } + + public EntityContext cloneEntity() { + return new EntityContext(this); + } } http://git-wip-us.apache.org/repos/asf/eagle/blob/6e919c2e/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/EntityJsonModule.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/EntityJsonModule.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/EntityJsonModule.java index fb86fa6..c291528 100644 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/EntityJsonModule.java +++ b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/EntityJsonModule.java @@ -21,7 +21,7 @@ import com.fasterxml.jackson.databind.module.SimpleModule; import java.util.Map; public class EntityJsonModule extends SimpleModule { - public EntityJsonModule(){ - addSerializer(Map.Entry.class,new MapEntrySerializer()); + public EntityJsonModule() { + addSerializer(Map.Entry.class, new MapEntrySerializer()); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/eagle/blob/6e919c2e/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/MapEntrySerializer.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/MapEntrySerializer.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/MapEntrySerializer.java index 4cebbf6..8a80cf0 100644 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/MapEntrySerializer.java +++ b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/MapEntrySerializer.java @@ -29,10 +29,11 @@ public class MapEntrySerializer extends JsonSerializer { private static final String VALUE_FIELD = "value"; @Override - public void serialize(Map.Entry entry, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { + public void serialize(Map.Entry entry, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) + throws IOException, JsonProcessingException { jsonGenerator.writeStartObject(); - jsonGenerator.writeObjectField(KEY_FIELD,entry.getKey()); - jsonGenerator.writeObjectField(VALUE_FIELD,entry.getValue()); + jsonGenerator.writeObjectField(KEY_FIELD, entry.getKey()); + jsonGenerator.writeObjectField(VALUE_FIELD, entry.getValue()); jsonGenerator.writeEndObject(); } } http://git-wip-us.apache.org/repos/asf/eagle/blob/6e919c2e/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/NoSuchRowException.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/NoSuchRowException.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/NoSuchRowException.java index 3304bea..658c20a 100644 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/NoSuchRowException.java +++ b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/NoSuchRowException.java @@ -16,14 +16,14 @@ */ package org.apache.eagle.log.base.taggedlog; -public class NoSuchRowException extends RuntimeException{ - static final long serialVersionUID = -4538233994503905943L; +public class NoSuchRowException extends RuntimeException { + static final long serialVersionUID = -4538233994503905943L; - public NoSuchRowException(){ - super(); - } - - public NoSuchRowException(String s){ - super(s); - } + public NoSuchRowException() { + super(); + } + + public NoSuchRowException(String s) { + super(s); + } } http://git-wip-us.apache.org/repos/asf/eagle/blob/6e919c2e/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/RowkeyAPIEntity.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/RowkeyAPIEntity.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/RowkeyAPIEntity.java index d72c35a..3c4166c 100644 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/RowkeyAPIEntity.java +++ b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/RowkeyAPIEntity.java @@ -25,57 +25,72 @@ import javax.xml.bind.annotation.XmlType; @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(propOrder = {"success", "exception", "prefixHashCode", "timestamp", "humanTime", "tagNameHashValueHashMap", "fieldNameValueMap"}) +@XmlType(propOrder = { + "success", "exception", "prefixHashCode", "timestamp", "humanTime", + "tagNameHashValueHashMap", "fieldNameValueMap" + }) public class RowkeyAPIEntity { - boolean success; - String exception; - int prefixHashCode; - long timestamp; - String humanTime; - Map tagNameHashValueHashMap; - Map fieldNameValueMap; - - public boolean isSuccess() { - return success; - } - public void setSuccess(boolean success) { - this.success = success; - } - public String getException() { - return exception; - } - public void setException(String exception) { - this.exception = exception; - } - public String getHumanTime() { - return humanTime; - } - public void setHumanTime(String humanTime) { - this.humanTime = humanTime; - } - public int getPrefixHashCode() { - return prefixHashCode; - } - public void setPrefixHashCode(int prefixHashcode) { - this.prefixHashCode = prefixHashcode; - } - public long getTimestamp() { - return timestamp; - } - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } - public Map getTagNameHashValueHashMap() { - return tagNameHashValueHashMap; - } - public void setTagNameHashValueHashMap( - Map tagNameHashValueHashMap) { - this.tagNameHashValueHashMap = tagNameHashValueHashMap; - } - public Map getFieldNameValueMap() { - return fieldNameValueMap; - } - public void setFieldNameValueMap(Map fieldNameValueMap) { - this.fieldNameValueMap = fieldNameValueMap; - } + boolean success; + String exception; + int prefixHashCode; + long timestamp; + String humanTime; + Map tagNameHashValueHashMap; + Map fieldNameValueMap; + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public String getException() { + return exception; + } + + public void setException(String exception) { + this.exception = exception; + } + + public String getHumanTime() { + return humanTime; + } + + public void setHumanTime(String humanTime) { + this.humanTime = humanTime; + } + + public int getPrefixHashCode() { + return prefixHashCode; + } + + public void setPrefixHashCode(int prefixHashcode) { + this.prefixHashCode = prefixHashcode; + } + + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public Map getTagNameHashValueHashMap() { + return tagNameHashValueHashMap; + } + + public void setTagNameHashValueHashMap(Map tagNameHashValueHashMap) { + this.tagNameHashValueHashMap = tagNameHashValueHashMap; + } + + public Map getFieldNameValueMap() { + return fieldNameValueMap; + } + + public void setFieldNameValueMap(Map fieldNameValueMap) { + this.fieldNameValueMap = fieldNameValueMap; + } } http://git-wip-us.apache.org/repos/asf/eagle/blob/6e919c2e/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/TaggedLogAPIEntity.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/TaggedLogAPIEntity.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/TaggedLogAPIEntity.java index b396b06..8e6d314 100755 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/TaggedLogAPIEntity.java +++ b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/TaggedLogAPIEntity.java @@ -42,10 +42,8 @@ import java.util.Map; import java.util.Set; /** - * rowkey: prefix + timestamp + tagNameValues - * as of now, all tags will be persisted as a column in hbase table - * tag name is column qualifier name - * tag value is column value. + * rowkey: prefix + timestamp + tagNameValues as of now, all tags will be persisted as a column in hbase table + * tag name is column qualifier name tag value is column value. */ @JsonFilter(TaggedLogAPIEntity.PropertyBeanFilterName) public class TaggedLogAPIEntity implements PropertyChangeListener, Serializable { @@ -63,17 +61,14 @@ public class TaggedLogAPIEntity implements PropertyChangeListener, Serializable } /** - * Extra dynamic attributes. - * TODO: can we move exp, serializeAlias, serializeVerbose to a wrapper class? + * Extra dynamic attributes. TODO: can we move exp, serializeAlias, serializeVerbose to a wrapper class? */ private Map exp; private String encodedRowkey; // track what qualifiers are changed private Set modifiedProperties = new HashSet(); - protected PropertyChangeSupport pcs - = new PropertyChangeSupport(this); - + protected PropertyChangeSupport pcs = new PropertyChangeSupport(this); public Map getSerializeAlias() { return serializeAlias; @@ -135,6 +130,7 @@ public class TaggedLogAPIEntity implements PropertyChangeListener, Serializable pcs.firePropertyChange(fieldModified, null, null); } + @Override public void propertyChange(PropertyChangeEvent evt) { modifiedProperties.add(evt.getPropertyName()); } @@ -143,6 +139,7 @@ public class TaggedLogAPIEntity implements PropertyChangeListener, Serializable return this.modifiedProperties; } + @Override public String toString() { StringBuffer sb = new StringBuffer(); sb.append("prefix:"); @@ -189,22 +186,26 @@ public class TaggedLogAPIEntity implements PropertyChangeListener, Serializable }; @Override - public void serializeAsField(Object pojo, JsonGenerator jgen, SerializerProvider provider, PropertyWriter writer) throws Exception { + public void serializeAsField(Object pojo, JsonGenerator jgen, SerializerProvider provider, + PropertyWriter writer) + throws Exception { if (pojo instanceof TaggedLogAPIEntity) { - TaggedLogAPIEntity entity = (TaggedLogAPIEntity) pojo; + TaggedLogAPIEntity entity = (TaggedLogAPIEntity)pojo; Set modified = entity.modifiedQualifiers(); Set basePropertyNames = getPropertyNames(); String writerName = writer.getName(); if (modified.contains(writerName) || basePropertyNames.contains(writerName)) { if ((!entity.isSerializeVerbose() && verboseFields.contains(writerName)) - || (timestamp.equals(writerName) && !EntityDefinitionManager.isTimeSeries(entity.getClass()))) { + || (timestamp.equals(writerName) + && !EntityDefinitionManager.isTimeSeries(entity.getClass()))) { // log skip if (LOG.isDebugEnabled()) { LOG.debug("skip field"); } } else { // if serializeAlias is not null and exp is not null - if (exp.equals(writerName) && entity.getSerializeAlias() != null && entity.getExp() != null) { + if (exp.equals(writerName) && entity.getSerializeAlias() != null + && entity.getExp() != null) { Map _exp = new HashMap(); for (Map.Entry entry : entity.getExp().entrySet()) { String alias = entity.getSerializeAlias().get(entry.getKey()); @@ -248,4 +249,4 @@ public class TaggedLogAPIEntity implements PropertyChangeListener, Serializable mapper.setFilters(TaggedLogAPIEntity.getFilterProvider()); return mapper; } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/eagle/blob/6e919c2e/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/TaggedLogObjectMapper.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/TaggedLogObjectMapper.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/TaggedLogObjectMapper.java index 1df1c0d..1b712c4 100644 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/TaggedLogObjectMapper.java +++ b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/base/taggedlog/TaggedLogObjectMapper.java @@ -19,17 +19,20 @@ package org.apache.eagle.log.base.taggedlog; import java.util.Map; public interface TaggedLogObjectMapper { - /** - * when read, business logic should convert schema-less key/value into business object based on its own schema - * @param entity - * @param qualifierValues - */ - public void populateQualifierValues(TaggedLogAPIEntity entity, Map qualifierValues); - - /** - * when write, business logic should convert business object to schema-less key value - * @param entity - * @return - */ - public Map createQualifierValues(TaggedLogAPIEntity entity); + /** + * when read, business logic should convert schema-less key/value into business object based on its own + * schema + * + * @param entity + * @param qualifierValues + */ + public void populateQualifierValues(TaggedLogAPIEntity entity, Map qualifierValues); + + /** + * when write, business logic should convert business object to schema-less key value + * + * @param entity + * @return + */ + public Map createQualifierValues(TaggedLogAPIEntity entity); } http://git-wip-us.apache.org/repos/asf/eagle/blob/6e919c2e/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/AbstractHBaseLogReader.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/AbstractHBaseLogReader.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/AbstractHBaseLogReader.java index 916706f..3823d62 100755 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/AbstractHBaseLogReader.java +++ b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/AbstractHBaseLogReader.java @@ -33,208 +33,213 @@ import java.util.List; import java.util.Map; /** - * HBase Log Reader basic initialization: + * HBase Log Reader basic initialization. *
    - *
  1. Open HBase connection to target HBase table
  2. - *
  3. Generate HBase filter,start and stop row key, output qualifier and Scan
  4. - *
  5. onOpen(HTableInterface,Scan): Callback abstract method
  6. - *
  7. close: Close HBase connection
  8. + *
  9. Open HBase connection to target HBase table
  10. + *
  11. Generate HBase filter,start and stop row key, output qualifier and Scan
  12. + *
  13. onOpen(HTableInterface,Scan): Callback abstract method
  14. + *
  15. close: Close HBase connection
  16. *
* * @param Reader entity class type - * */ public abstract class AbstractHBaseLogReader implements LogReader { - private static Logger LOG = LoggerFactory.getLogger(AbstractHBaseLogReader.class); - - protected byte[][] qualifiers; - private HTableInterface tbl; - private byte[] startKey; - private byte[] stopKey; - protected Map> searchTags; - private Filter filter; - private Date startTime; - private Date endTime; - -// protected ResultScanner rs; - private boolean isOpen = false; - - /** - * TODO it's ugly that both _ed and prefix fields can hold prefix information, - * prefix field should be in precedence over _ed - */ - private String _prefix; - protected EntityDefinition _ed; - - public AbstractHBaseLogReader(EntityDefinition ed, List partitions, Date startTime, Date endTime, - Filter filter, String lastScanKey, byte[][] outputQualifiers){ - this(ed, partitions, startTime, endTime, filter, lastScanKey, outputQualifiers, null); - } - /** - * This constructor supports partition. - * - * @param ed entity definition - * @param partitions partition values, which is sorted in partition definition order. TODO: in future we need to support - * multiple values for one partition field - * @param startTime start time of the query - * @param endTime end time of the query - * @param filter filter for the hbase scan - * @param lastScanKey the key of last scan - * @param outputQualifiers the bytes of output qualifier names - * @param prefix can be populated from outside world specifically for generic metric reader - */ - public AbstractHBaseLogReader(EntityDefinition ed, List partitions, Date startTime, Date endTime, - Filter filter, String lastScanKey, byte[][] outputQualifiers, String prefix){ - this.startTime = startTime; - this.endTime = endTime; - this._ed = ed; - if (_ed.getPartitions() != null) { - if (partitions == null || _ed.getPartitions().length != partitions.size()) { - throw new IllegalArgumentException("Invalid argument. Entity " + ed.getClass().getSimpleName() + " defined " - + "partitions, but argument partitions is null or number of partition values are different!"); - } - } - /** - * decide prefix field value - */ - if(prefix == null || prefix.isEmpty()){ - this._prefix = _ed.getPrefix(); - }else{ - this._prefix = prefix; - } - this.qualifiers = outputQualifiers; - this.filter = filter; - - this.startKey = buildRowKey(this._prefix, partitions, startTime); - - - /** - * startTime should be inclusive, -128 is max value for hbase Bytes comparison, see PureJavaComparer.compareTo - * as an alternative, we can use startTime-1000 and endTime-1000 to make sure startTime is inclusive and endTime is exclusive - */ - this.startKey = ByteUtil.concat(this.startKey, new byte[] {-1, -1,-1,-1}); - if (lastScanKey == null) { - this.stopKey = buildRowKey(this._prefix, partitions, endTime); - // endTime should be exclusive - this.stopKey = ByteUtil.concat(this.stopKey, new byte[] {-1,-1,-1,-1,-1}); - } else { - // build stop key - this.stopKey = EagleBase64Wrapper.decode(lastScanKey); - // TODO to-be-fixed, probably it's an issue because contacting 1 is not - // enough for lexicographical sorting - this.stopKey = ByteUtil.concat(this.stopKey, new byte[] { 1 }); - } - } - - /** - * TODO If the required field is null for a row, then this row will not be fetched. That could be a problem for counting - * Need another version of read to strictly get the number of rows which will return all the columns for a column family - */ - @Override - public void open() throws IOException { - if (isOpen) - return; // silently return - try { - tbl = EagleConfigFactory.load().getHTable(_ed.getTable()); - } catch (RuntimeException ex) { - throw new IOException(ex); - } - - Scan s1 = new Scan(); - // reverse timestamp, startRow is stopKey, and stopRow is startKey - s1.setStartRow(stopKey); - s1.setStopRow(startKey); - s1.setFilter(filter); - // TODO the # of cached rows should be minimum of (pagesize and 100) - int cs = EagleConfigFactory.load().getHBaseClientScanCacheSize(); - s1.setCaching(cs); - // TODO not optimized for all applications - s1.setCacheBlocks(true) - ; - // scan specified columnfamily and qualifiers - if(this.qualifiers == null) { - // Filter all - s1.addFamily(_ed.getColumnFamily().getBytes()); - }else{ - for (byte[] qualifier : qualifiers) { - s1.addColumn(_ed.getColumnFamily().getBytes(), qualifier); - } - } - // TODO: Work around https://issues.apache.org/jira/browse/HBASE-2198. More graceful implementation should use SingleColumnValueExcludeFilter, - // but it's complicated in current implementation. - workaroundHBASE2198(s1, filter); - if (LOG.isDebugEnabled()) { - LOG.debug(s1.toString()); - } -// rs = tbl.getScanner(s1); - this.onOpen(tbl,s1); - isOpen = true; - } - - /** - * HBase table connection callback function - * - * @param tbl HBase table connection - * @param scan HBase scan - * @throws IOException - */ - protected abstract void onOpen(HTableInterface tbl,Scan scan) throws IOException; - - /** - *

History

- *
    - *
  • Nov 19th, 2014: Fix for out put all qualifiers
  • - *
- * @param s1 - * @param filter - */ - protected void workaroundHBASE2198(Scan s1, Filter filter) { - if (filter instanceof SingleColumnValueFilter) { - if(this.qualifiers == null){ - s1.addFamily(((SingleColumnValueFilter) filter).getFamily()); - }else { - s1.addColumn(((SingleColumnValueFilter) filter).getFamily(), ((SingleColumnValueFilter) filter).getQualifier()); - } - return; - } - if (filter instanceof FilterList) { - for (Filter f : ((FilterList)filter).getFilters()) { - workaroundHBASE2198(s1, f); - } - } - } - - /** - *

Close:

- * 1. release current table connection - * - * @throws IOException - */ - @Override - public void close() throws IOException { - if(tbl != null){ - new HTableFactory().releaseHTableInterface(tbl); - } -// if(rs != null){ -// rs.close(); -// } - } - - private static byte[] buildRowKey(String prefix, List partitions, Date t){ - final int length = (partitions == null) ? (4 + 8) : (4 + 8 + partitions.size() * 4); - final byte[] key = new byte[length]; - int offset = 0; - ByteUtil.intToBytes(prefix.hashCode(), key, offset); - offset += 4; - if (partitions != null) { - for (String partition : partitions) { - ByteUtil.intToBytes(partition.hashCode(), key, offset); - offset += 4; - } - } - // reverse timestamp - long ts = Long.MAX_VALUE - t.getTime(); - ByteUtil.longToBytes(ts, key, offset); - return key; - } + private static Logger LOG = LoggerFactory.getLogger(AbstractHBaseLogReader.class); + + protected byte[][] qualifiers; + private HTableInterface tbl; + private byte[] startKey; + private byte[] stopKey; + protected Map> searchTags; + private Filter filter; + private Date startTime; + private Date endTime; + + // protected ResultScanner rs; + private boolean isOpen = false; + + /** + * TODO it's ugly that both ed and prefix fields can hold prefix information, prefix field should be in + * precedence over ed. + */ + private String prefix; + protected EntityDefinition ed; + + public AbstractHBaseLogReader(EntityDefinition ed, List partitions, Date startTime, Date endTime, + Filter filter, String lastScanKey, byte[][] outputQualifiers) { + this(ed, partitions, startTime, endTime, filter, lastScanKey, outputQualifiers, null); + } + + /** + * This constructor supports partition. + * + * @param ed entity definition + * @param partitions partition values, which is sorted in partition definition order. TODO: in future we + * need to support multiple values for one partition field + * @param startTime start time of the query + * @param endTime end time of the query + * @param filter filter for the hbase scan + * @param lastScanKey the key of last scan + * @param outputQualifiers the bytes of output qualifier names + * @param prefix can be populated from outside world specifically for generic metric reader + */ + public AbstractHBaseLogReader(EntityDefinition ed, List partitions, Date startTime, Date endTime, + Filter filter, String lastScanKey, byte[][] outputQualifiers, + String prefix) { + this.startTime = startTime; + this.endTime = endTime; + this.ed = ed; + if (ed.getPartitions() != null) { + if (partitions == null || ed.getPartitions().length != partitions.size()) { + throw new IllegalArgumentException("Invalid argument. Entity " + ed.getClass().getSimpleName() + + " defined " + + "partitions, but argument partitions is null or number of partition values are different!"); + } + } + /** + * decide prefix field value + */ + if (prefix == null || prefix.isEmpty()) { + this.prefix = ed.getPrefix(); + } else { + this.prefix = prefix; + } + this.qualifiers = outputQualifiers; + this.filter = filter; + + this.startKey = buildRowKey(this.prefix, partitions, startTime); + + /** + * startTime should be inclusive, -128 is max value for hbase Bytes comparison, see + * PureJavaComparer.compareTo as an alternative, we can use startTime-1000 and endTime-1000 to make + * sure startTime is inclusive and endTime is exclusive + */ + this.startKey = ByteUtil.concat(this.startKey, new byte[] { -1, -1, -1, -1 }); + if (lastScanKey == null) { + this.stopKey = buildRowKey(this.prefix, partitions, endTime); + // endTime should be exclusive + this.stopKey = ByteUtil.concat(this.stopKey, new byte[] { -1, -1, -1, -1, -1 }); + } else { + // build stop key + this.stopKey = EagleBase64Wrapper.decode(lastScanKey); + // TODO to-be-fixed, probably it's an issue because contacting 1 is not + // enough for lexicographical sorting + this.stopKey = ByteUtil.concat(this.stopKey, new byte[] { 1 }); + } + } + + /** + * TODO If the required field is null for a row, then this row will not be fetched. That could be a + * problem for counting Need another version of read to strictly get the number of rows which will return + * all the columns for a column family + */ + @Override + public void open() throws IOException { + if (isOpen) { + return; // silently return + } + try { + tbl = EagleConfigFactory.load().getHTable(ed.getTable()); + } catch (RuntimeException ex) { + throw new IOException(ex); + } + + Scan s1 = new Scan(); + // reverse timestamp, startRow is stopKey, and stopRow is startKey + s1.setStartRow(stopKey); + s1.setStopRow(startKey); + s1.setFilter(filter); + // TODO the # of cached rows should be minimum of (pagesize and 100) + int cs = EagleConfigFactory.load().getHBaseClientScanCacheSize(); + s1.setCaching(cs); + // TODO not optimized for all applications + s1.setCacheBlocks(true); + // scan specified columnfamily and qualifiers + if (this.qualifiers == null) { + // Filter all + s1.addFamily(ed.getColumnFamily().getBytes()); + } else { + for (byte[] qualifier : qualifiers) { + s1.addColumn(ed.getColumnFamily().getBytes(), qualifier); + } + } + // TODO: Work around https://issues.apache.org/jira/browse/HBASE-2198. More graceful implementation + // should use SingleColumnValueExcludeFilter, + // but it's complicated in current implementation. + workaroundHBASE2198(s1, filter); + if (LOG.isDebugEnabled()) { + LOG.debug(s1.toString()); + } + // rs = tbl.getScanner(s1); + this.onOpen(tbl, s1); + isOpen = true; + } + + /** + * HBase table connection callback function. + * + * @param tbl HBase table connection + * @param scan HBase scan + * @throws IOException + */ + protected abstract void onOpen(HTableInterface tbl, Scan scan) throws IOException; + + /** + *

History

. + *
    + *
  • Nov 19th, 2014: Fix for out put all qualifiers
  • + *
+ * + * @param s1 + * @param filter + */ + protected void workaroundHBASE2198(Scan s1, Filter filter) { + if (filter instanceof SingleColumnValueFilter) { + if (this.qualifiers == null) { + s1.addFamily(((SingleColumnValueFilter)filter).getFamily()); + } else { + s1.addColumn(((SingleColumnValueFilter)filter).getFamily(), + ((SingleColumnValueFilter)filter).getQualifier()); + } + return; + } + if (filter instanceof FilterList) { + for (Filter f : ((FilterList)filter).getFilters()) { + workaroundHBASE2198(s1, f); + } + } + } + + /** + *

Close:

1. release current table connection + * + * @throws IOException + */ + @Override + public void close() throws IOException { + if (tbl != null) { + new HTableFactory().releaseHTableInterface(tbl); + } + // if(rs != null){ + // rs.close(); + // } + } + + private static byte[] buildRowKey(String prefix, List partitions, Date t) { + final int length = (partitions == null) ? (4 + 8) : (4 + 8 + partitions.size() * 4); + final byte[] key = new byte[length]; + int offset = 0; + ByteUtil.intToBytes(prefix.hashCode(), key, offset); + offset += 4; + if (partitions != null) { + for (String partition : partitions) { + ByteUtil.intToBytes(partition.hashCode(), key, offset); + offset += 4; + } + } + // reverse timestamp + long ts = Long.MAX_VALUE - t.getTime(); + ByteUtil.longToBytes(ts, key, offset); + return key; + } } http://git-wip-us.apache.org/repos/asf/eagle/blob/6e919c2e/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/BaseEntityRepository.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/BaseEntityRepository.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/BaseEntityRepository.java index 71253da..f7de525 100755 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/BaseEntityRepository.java +++ b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/BaseEntityRepository.java @@ -18,9 +18,9 @@ package org.apache.eagle.log.entity; import org.apache.eagle.log.entity.repo.EntityRepository; -public class BaseEntityRepository extends EntityRepository { +public class BaseEntityRepository extends EntityRepository { - public BaseEntityRepository() { - entitySet.add(GenericMetricEntity.class); - } + public BaseEntityRepository() { + entitySet.add(GenericMetricEntity.class); + } } http://git-wip-us.apache.org/repos/asf/eagle/blob/6e919c2e/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/EntityCreationListener.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/EntityCreationListener.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/EntityCreationListener.java index 4ad8959..37b163c 100644 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/EntityCreationListener.java +++ b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/EntityCreationListener.java @@ -19,8 +19,8 @@ package org.apache.eagle.log.entity; import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity; /** - * Interface to notify creation event of an entity + * Interface to notify creation event of an entity */ public interface EntityCreationListener { - public void entityCreated(TaggedLogAPIEntity entity) throws Exception; + public void entityCreated(TaggedLogAPIEntity entity) throws Exception; } http://git-wip-us.apache.org/repos/asf/eagle/blob/6e919c2e/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/EntityQualifierUtils.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/EntityQualifierUtils.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/EntityQualifierUtils.java index 6e5cb5c..4747760 100755 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/EntityQualifierUtils.java +++ b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/EntityQualifierUtils.java @@ -34,248 +34,274 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public class EntityQualifierUtils { - private final static Logger LOG = LoggerFactory.getLogger(EntityQualifierUtils.class); + private static final Logger LOG = LoggerFactory.getLogger(EntityQualifierUtils.class); - public static Map keyValuesToMap(List row,EntityDefinition ed){ - Map result = new HashMap(); - for(KeyValue kv:row){ - String qualifierName = new String(kv.getQualifier()); - if(!ed.isTag(qualifierName)){ - Qualifier qualifier = ed.getDisplayNameMap().get(qualifierName); - if(qualifier == null){ - qualifier = ed.getQualifierNameMap().get(qualifierName); - } - qualifierName = qualifier.getDisplayName(); - Object value = qualifier.getSerDeser().deserialize(kv.getValue()); - result.put(qualifierName,value); - }else{ - result.put(qualifierName,new String(kv.getValue())); - } - } - return result; - } + public static Map keyValuesToMap(List row, EntityDefinition ed) { + Map result = new HashMap(); + for (KeyValue kv : row) { + String qualifierName = new String(kv.getQualifier()); + if (!ed.isTag(qualifierName)) { + Qualifier qualifier = ed.getDisplayNameMap().get(qualifierName); + if (qualifier == null) { + qualifier = ed.getQualifierNameMap().get(qualifierName); + } + qualifierName = qualifier.getDisplayName(); + Object value = qualifier.getSerDeser().deserialize(kv.getValue()); + result.put(qualifierName, value); + } else { + result.put(qualifierName, new String(kv.getValue())); + } + } + return result; + } - public static Map keyValuesToDoubleMap(List row,EntityDefinition ed){ - Map result = new HashMap(); - for(KeyValue kv:row){ - String qualifierName = new String(kv.getQualifier()); - if(!ed.isTag(qualifierName)){ - Qualifier qualifier = ed.getDisplayNameMap().get(qualifierName); - if(qualifier == null){ - qualifier = ed.getQualifierNameMap().get(qualifierName); - } - qualifierName = qualifier.getDisplayName(); - Object value = qualifier.getSerDeser().deserialize(kv.getValue()); - result.put(qualifierName,convertObjToDouble(value)); - }else{ - result.put(qualifierName,Double.NaN); - } - } - return result; - } + public static Map keyValuesToDoubleMap(List row, EntityDefinition ed) { + Map result = new HashMap(); + for (KeyValue kv : row) { + String qualifierName = new String(kv.getQualifier()); + if (!ed.isTag(qualifierName)) { + Qualifier qualifier = ed.getDisplayNameMap().get(qualifierName); + if (qualifier == null) { + qualifier = ed.getQualifierNameMap().get(qualifierName); + } + qualifierName = qualifier.getDisplayName(); + Object value = qualifier.getSerDeser().deserialize(kv.getValue()); + result.put(qualifierName, convertObjToDouble(value)); + } else { + result.put(qualifierName, Double.NaN); + } + } + return result; + } - /** - * Map[Display Name,Double Value] - * - * @param map - * @param ed - * @return - */ - public static Map bytesMapToDoubleMap(Map map,EntityDefinition ed){ - Map result = new HashMap(); - for(Map.Entry entry:map.entrySet()){ - String qualifierName = entry.getKey(); - Qualifier qualifier = ed.getDisplayNameMap().get(qualifierName); - if(qualifier == null) qualifier = ed.getQualifierNameMap().get(qualifierName); - if(qualifier!=null && entry.getValue()!=null) { - qualifierName = qualifier.getDisplayName(); - Object value = qualifier.getSerDeser().deserialize(entry.getValue()); - result.put(qualifierName, convertObjToDouble(value)); - }else{ - result.put(qualifierName,null); - } - } - return result; - } + /** + * Map[Display Name,Double Value] + * + * @param map + * @param ed + * @return + */ + public static Map bytesMapToDoubleMap(Map map, EntityDefinition ed) { + Map result = new HashMap(); + for (Map.Entry entry : map.entrySet()) { + String qualifierName = entry.getKey(); + Qualifier qualifier = ed.getDisplayNameMap().get(qualifierName); + if (qualifier == null) { + qualifier = ed.getQualifierNameMap().get(qualifierName); + } + if (qualifier != null && entry.getValue() != null) { + qualifierName = qualifier.getDisplayName(); + Object value = qualifier.getSerDeser().deserialize(entry.getValue()); + result.put(qualifierName, convertObjToDouble(value)); + } else { + result.put(qualifierName, null); + } + } + return result; + } - public static byte[] toBytes(EntityDefinition ed, String qualifierName, String qualifierValueInStr){ - // Get field type from entity class - // and skip for not-found fields query expression - Object typedValue = null; - EntitySerDeser serDeser = null; - if(ed.isTag(qualifierName)){ - typedValue = qualifierValueInStr; - serDeser = EntityDefinitionManager.getSerDeser(String.class); - }else{ - try{ - Field field = ed.getEntityClass().getDeclaredField(qualifierName); - Class fieldType = field.getType(); - serDeser = EntityDefinitionManager.getSerDeser(fieldType); - if(serDeser == null){ - throw new IllegalArgumentException("Can't find EntitySerDeser for field: "+ qualifierName +"'s type: "+fieldType - +", so the field is not supported to be filtered yet"); - } - typedValue = convertStringToObject(qualifierValueInStr, fieldType); - } catch (NoSuchFieldException ex) { - // Handle the field not found exception in caller - LOG.error("Field " + qualifierName + " not found in " + ed.getEntityClass()); - throw new IllegalArgumentException("Field "+qualifierName+" not found in "+ed.getEntityClass(),ex); - } - } - return serDeser.serialize(typedValue); - } + public static byte[] toBytes(EntityDefinition ed, String qualifierName, String qualifierValueInStr) { + // Get field type from entity class + // and skip for not-found fields query expression + Object typedValue = null; + EntitySerDeser serDeser = null; + if (ed.isTag(qualifierName)) { + typedValue = qualifierValueInStr; + serDeser = EntityDefinitionManager.getSerDeser(String.class); + } else { + try { + Field field = ed.getEntityClass().getDeclaredField(qualifierName); + Class fieldType = field.getType(); + serDeser = EntityDefinitionManager.getSerDeser(fieldType); + if (serDeser == null) { + throw new IllegalArgumentException("Can't find EntitySerDeser for field: " + qualifierName + + "'s type: " + fieldType + + ", so the field is not supported to be filtered yet"); + } + typedValue = convertStringToObject(qualifierValueInStr, fieldType); + } catch (NoSuchFieldException ex) { + // Handle the field not found exception in caller + LOG.error("Field " + qualifierName + " not found in " + ed.getEntityClass()); + throw new IllegalArgumentException("Field " + qualifierName + " not found in " + + ed.getEntityClass(), ex); + } + } + return serDeser.serialize(typedValue); + } - public static Class getType(EntityDefinition ed, String qualifierName) { - Field field; - try { - field = ed.getEntityClass().getDeclaredField(qualifierName); - } catch (NoSuchFieldException e) { - if(LOG.isDebugEnabled()) LOG.debug("Field "+qualifierName+" not found in "+ed.getEntityClass()); - return null; - } - return field.getType(); - } + public static Class getType(EntityDefinition ed, String qualifierName) { + Field field; + try { + field = ed.getEntityClass().getDeclaredField(qualifierName); + } catch (NoSuchFieldException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Field " + qualifierName + " not found in " + ed.getEntityClass()); + } + return null; + } + return field.getType(); + } - /** - * Not support negative numeric value: - * - http://en.wikipedia.org/wiki/Double-precision_floating-point_format - * - * @param value - * @param type - * @return - */ - public static Object convertStringToObject(String value, Class type){ - Object obj = null; - try{ - if(String.class.equals(type)){ - obj = value; - }if(Long.class.equals(type) || long.class.equals(type)){ - obj = Long.parseLong(value); - // if((Long) obj < 0) throw new IllegalArgumentException("Don't support negative Long yet: "+obj); - }else if(Integer.class.equals(type) || int.class.equals(type)){ - obj = Integer.parseInt(value); - // if((Integer) obj < 0) throw new IllegalArgumentException("Don't support negative Integer yet: "+obj); - }else if(Double.class.equals(type) || double.class.equals(type)){ - obj = Double.parseDouble(value); - // if((Double) obj < 0) throw new IllegalArgumentException("Don't support negative Double yet: "+obj); - }else if(Float.class.equals(type) || float.class.equals(type)){ - obj = Float.parseFloat(value); - // if((Double) obj < 0) throw new IllegalArgumentException("Don't support negative Float yet: "+obj); - }else if(Boolean.class.equals(type) || boolean.class.equals(type)) { - obj = Boolean.valueOf(value); - } - if(obj != null) return obj; - }catch (NumberFormatException ex){ - throw new IllegalArgumentException("Fail to convert string: "+value +" into type of "+type,ex); - } + /** + * Not support negative numeric value: - + * http://en.wikipedia.org/wiki/Double-precision_floating-point_format + * + * @param value + * @param type + * @return + */ + public static Object convertStringToObject(String value, Class type) { + Object obj = null; + try { + if (String.class.equals(type)) { + obj = value; + } + if (Long.class.equals(type) || long.class.equals(type)) { + obj = Long.parseLong(value); + // if((Long) obj < 0) throw new IllegalArgumentException("Don't support negative Long yet: + // "+obj); + } else if (Integer.class.equals(type) || int.class.equals(type)) { + obj = Integer.parseInt(value); + // if((Integer) obj < 0) throw new IllegalArgumentException("Don't support negative Integer + // yet: "+obj); + } else if (Double.class.equals(type) || double.class.equals(type)) { + obj = Double.parseDouble(value); + // if((Double) obj < 0) throw new IllegalArgumentException("Don't support negative Double yet: + // "+obj); + } else if (Float.class.equals(type) || float.class.equals(type)) { + obj = Float.parseFloat(value); + // if((Double) obj < 0) throw new IllegalArgumentException("Don't support negative Float yet: + // "+obj); + } else if (Boolean.class.equals(type) || boolean.class.equals(type)) { + obj = Boolean.valueOf(value); + } + if (obj != null) { + return obj; + } + } catch (NumberFormatException ex) { + throw new IllegalArgumentException("Fail to convert string: " + value + " into type of " + type, + ex); + } - throw new IllegalArgumentException("Fail to convert string: "+value +" into type of "+type+", illegal type: "+type); - } + throw new IllegalArgumentException("Fail to convert string: " + value + " into type of " + type + + ", illegal type: " + type); + } - /** - * - * @param obj - * @return double value, otherwise Double.NaN - */ - public static double convertObjToDouble(Object obj){ - if(Long.class.equals(obj.getClass()) || long.class.equals(obj.getClass())){ - Long _value = (Long) obj; - return _value.doubleValue(); - }else if(Integer.class.equals(obj.getClass()) || int.class.equals(obj.getClass())){ - Integer _value = (Integer) obj; - return _value.doubleValue(); - }else if(Double.class.equals(obj.getClass()) || double.class.equals(obj.getClass())) { - return (Double) obj; - }else if(Float.class.equals(obj.getClass()) || float.class.equals(obj.getClass())) { - Float _value = (Float) obj; - return _value.doubleValue(); - }else if(Short.class.equals(obj.getClass()) || short.class.equals(obj.getClass())) { - Float _value = (Float) obj; - return _value.doubleValue(); - }else if(Byte.class.equals(obj.getClass()) || byte.class.equals(obj.getClass())) { - Byte _value = (Byte) obj; - return _value.doubleValue(); - } - LOG.warn("Failed to convert object " + obj.toString() + " in type of " + obj.getClass() + " to double"); - return Double.NaN; - } + /** + * @param obj + * @return double value, otherwise Double.NaN + */ + public static double convertObjToDouble(Object obj) { + if (Long.class.equals(obj.getClass()) || long.class.equals(obj.getClass())) { + Long _value = (Long)obj; + return _value.doubleValue(); + } else if (Integer.class.equals(obj.getClass()) || int.class.equals(obj.getClass())) { + Integer _value = (Integer)obj; + return _value.doubleValue(); + } else if (Double.class.equals(obj.getClass()) || double.class.equals(obj.getClass())) { + return (Double)obj; + } else if (Float.class.equals(obj.getClass()) || float.class.equals(obj.getClass())) { + Float _value = (Float)obj; + return _value.doubleValue(); + } else if (Short.class.equals(obj.getClass()) || short.class.equals(obj.getClass())) { + Float _value = (Float)obj; + return _value.doubleValue(); + } else if (Byte.class.equals(obj.getClass()) || byte.class.equals(obj.getClass())) { + Byte _value = (Byte)obj; + return _value.doubleValue(); + } + LOG.warn("Failed to convert object " + obj.toString() + " in type of " + obj.getClass() + + " to double"); + return Double.NaN; + } - /** - * Parse List String as Set without duplicate items - * - *

- * Support: - *
    - *
  • normal string: ("a","b") => ["a","b"]
  • - *
  • number: (1.5,"b") => [1.5,"b"]
  • - *
  • inner string comma: ("va,lue","value",",") => ["va,lue","value",","]
  • - *
  • inner escaped chars: ("va\"lue","value") => ["va\"lue","value"]
  • - *
  • some bad formats list: ("va"lue","value") => ["va\"lue","value"]
  • - *
- * - * Warning: it will not throw exception if the format is not strictly valid - * - * @param listValue in format (item1,item2,...) - * @return - */ - public static List parseList(String listValue){ - Matcher matcher = SET_PATTERN.matcher(listValue); - if(matcher.find()){ - String content = matcher.group(1); - List result = new ArrayList(); - StringBuilder str = null; - STATE state = null; - char last = 0; - for(char c: content.toCharArray()){ - if(str == null) str = new StringBuilder(); - if(c == DOUBLE_QUOTE && last != SLASH){ - // Open or Close String - if(state == STATE.STRING) - state = null; - else state = STATE.STRING; - }else if(c == COMMA && state != STATE.STRING){ - result.add(unescape(str.toString())); - str = null; - last = c; - continue; - } - last = c; - str.append(c); - } - if(str!=null) result.add(unescape(str.toString())); - return result; - }else{ - LOG.error("Invalid list value: " + listValue); - throw new IllegalArgumentException("Invalid format of list value: "+listValue+", must be in format: (item1,item2,...)"); - } - } + /** + * Parse List String as Set without duplicate items
+ *
+ * Support: + *
    + *
  • normal string: ("a","b") => ["a","b"]
  • + *
  • number: (1.5,"b") => [1.5,"b"]
  • + *
  • inner string comma: ("va,lue","value",",") => ["va,lue","value",","]
  • + *
  • inner escaped chars: ("va\"lue","value") => ["va\"lue","value"]
  • + *
  • some bad formats list: ("va"lue","value") => ["va\"lue","value"]
  • + *
+ * Warning: it will not throw exception if the format is not strictly valid + * + * @param listValue in format (item1,item2,...) + * @return + */ + public static List parseList(String listValue) { + Matcher matcher = SET_PATTERN.matcher(listValue); + if (matcher.find()) { + String content = matcher.group(1); + List result = new ArrayList(); + StringBuilder str = null; + STATE state = null; + char last = 0; + for (char c : content.toCharArray()) { + if (str == null) { + str = new StringBuilder(); + } + if (c == DOUBLE_QUOTE && last != SLASH) { + // Open or Close String + if (state == STATE.STRING) { + state = null; + } else { + state = STATE.STRING; + } + } else if (c == COMMA && state != STATE.STRING) { + result.add(unescape(str.toString())); + str = null; + last = c; + continue; + } + last = c; + str.append(c); + } + if (str != null) { + result.add(unescape(str.toString())); + } + return result; + } else { + LOG.error("Invalid list value: " + listValue); + throw new IllegalArgumentException("Invalid format of list value: " + listValue + + ", must be in format: (item1,item2,...)"); + } + } - private static String unescape(String str){ - int start=0,end = str.length(); - if(str.startsWith("\"")) start = start +1; - if(str.endsWith("\"")) end = end -1; - str = str.substring(start,end); - return StringEscapeUtils.unescapeJava(str); - } + private static String unescape(String str) { + int start = 0; + int end = str.length(); + if (str.startsWith("\"")) { + start = start + 1; + } + if (str.endsWith("\"")) { + end = end - 1; + } + str = str.substring(start, end); + return StringEscapeUtils.unescapeJava(str); + } - private final static Pattern SET_PATTERN = Pattern.compile("^\\((.*)\\)$"); - private final static char COMMA = ','; - private final static char DOUBLE_QUOTE = '"'; - private final static char SLASH = '\\'; - private static enum STATE{ STRING } + private static final Pattern SET_PATTERN = Pattern.compile("^\\((.*)\\)$"); + private static final char COMMA = ','; + private static final char DOUBLE_QUOTE = '"'; + private static final char SLASH = '\\'; + private static enum STATE { + STRING + } - -// TODO: NOT FINISHED -// private final static Map ESCAPE_REGEXP=new HashMap(){{ -// this.put("\\.","\\\\."); -// }}; -// -// public static String escapeRegExp(String value) { -// String _value = value; -// for(Map.Entry entry:ESCAPE_REGEXP.entrySet()){ -// _value = _value.replace(entry.getKey(),entry.getValue()); -// } -// return _value; -// } -} \ No newline at end of file + // TODO: NOT FINISHED + // private static final Map ESCAPE_REGEXP=new HashMap(){{ + // this.put("\\.","\\\\."); + // }}; + // + // public static String escapeRegExp(String value) { + // String _value = value; + // for(Map.Entry entry:ESCAPE_REGEXP.entrySet()){ + // _value = _value.replace(entry.getKey(),entry.getValue()); + // } + // return _value; + // } +} http://git-wip-us.apache.org/repos/asf/eagle/blob/6e919c2e/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/EntityUniq.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/EntityUniq.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/EntityUniq.java index 36e1e0b..df75e33 100755 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/EntityUniq.java +++ b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/EntityUniq.java @@ -15,7 +15,7 @@ * limitations under the License. */ /** - * + * */ package org.apache.eagle.log.entity; @@ -23,45 +23,48 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; - /** * @since Sep 12, 2014 */ public class EntityUniq { - - public Map tags; - public Long timestamp; - public long createdTime; // for cache removal; - - public EntityUniq(Map tags, long timestamp) { - this.tags = new HashMap(tags); - this.timestamp = timestamp; - this.createdTime = System.currentTimeMillis(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof EntityUniq) { - EntityUniq au = (EntityUniq) obj; - if (tags.size() != au.tags.size()) return false; - for (Entry keyValue : au.tags.entrySet()) { - boolean keyExist = tags.containsKey(keyValue.getKey()); - if ( !keyExist || !tags.get(keyValue.getKey()).equals(keyValue.getValue())) { - return false; - } - } - if (!timestamp.equals(au.timestamp)) return false; - return true; - } - return false; - } - - @Override - public int hashCode() { - int hashCode = 0; - for (String value : tags.values()) { - hashCode ^= value.hashCode(); - } - return hashCode ^= timestamp.hashCode(); - } + + public Map tags; + public Long timestamp; + public long createdTime; // for cache removal; + + public EntityUniq(Map tags, long timestamp) { + this.tags = new HashMap(tags); + this.timestamp = timestamp; + this.createdTime = System.currentTimeMillis(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof EntityUniq) { + EntityUniq au = (EntityUniq)obj; + if (tags.size() != au.tags.size()) { + return false; + } + for (Entry keyValue : au.tags.entrySet()) { + boolean keyExist = tags.containsKey(keyValue.getKey()); + if (!keyExist || !tags.get(keyValue.getKey()).equals(keyValue.getValue())) { + return false; + } + } + if (!timestamp.equals(au.timestamp)) { + return false; + } + return true; + } + return false; + } + + @Override + public int hashCode() { + int hashCode = 0; + for (String value : tags.values()) { + hashCode ^= value.hashCode(); + } + return hashCode ^= timestamp.hashCode(); + } } http://git-wip-us.apache.org/repos/asf/eagle/blob/6e919c2e/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/GenericCreateAPIResponseEntity.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/GenericCreateAPIResponseEntity.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/GenericCreateAPIResponseEntity.java index e308bc3..e97ecbb 100644 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/GenericCreateAPIResponseEntity.java +++ b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/GenericCreateAPIResponseEntity.java @@ -28,30 +28,37 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(propOrder = {"success", "exception", "encodedRowkeys"}) -@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown=true) -public class GenericCreateAPIResponseEntity{ - private boolean success; - private String exception; - private List encodedRowkeys; - - public List getEncodedRowkeys() { - return encodedRowkeys; - } - public void setEncodedRowkeys(List encodedRowkeys) { - this.encodedRowkeys = encodedRowkeys; - } - public boolean isSuccess() { - return success; - } - public void setSuccess(boolean success) { - this.success = success; - } - public String getException() { - return exception; - } - public void setException(String exception) { - this.exception = exception; - } +@XmlType(propOrder = { + "success", "exception", "encodedRowkeys" + }) +@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class GenericCreateAPIResponseEntity { + private boolean success; + private String exception; + private List encodedRowkeys; + + public List getEncodedRowkeys() { + return encodedRowkeys; + } + + public void setEncodedRowkeys(List encodedRowkeys) { + this.encodedRowkeys = encodedRowkeys; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public String getException() { + return exception; + } + + public void setException(String exception) { + this.exception = exception; + } } http://git-wip-us.apache.org/repos/asf/eagle/blob/6e919c2e/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/GenericEntityBatchReader.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/GenericEntityBatchReader.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/GenericEntityBatchReader.java index 9c42ab2..71f27c2 100755 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/GenericEntityBatchReader.java +++ b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/GenericEntityBatchReader.java @@ -23,36 +23,43 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; -public class GenericEntityBatchReader implements EntityCreationListener{ - private static final Logger LOG = LoggerFactory.getLogger(GenericEntityBatchReader.class); - - private List entities = new ArrayList(); - private StreamReader reader; - - public GenericEntityBatchReader(String serviceName, SearchCondition condition) throws InstantiationException, IllegalAccessException{ - reader = new GenericEntityStreamReader(serviceName, condition); - reader.register(this); - } - - public GenericEntityBatchReader(StreamReader reader) throws InstantiationException, IllegalAccessException{ - this.reader = reader; - reader.register(this); - } - - public long getLastTimestamp() { - return reader.getLastTimestamp(); - } - public long getFirstTimestamp(){ return reader.getFirstTimestamp();} - - @Override - public void entityCreated(TaggedLogAPIEntity entity){ - entities.add(entity); - } - - @SuppressWarnings("unchecked") - public List read() throws Exception{ - if(LOG.isDebugEnabled()) LOG.debug("Start reading as batch mode"); - reader.readAsStream(); - return (List)entities; - } +public class GenericEntityBatchReader implements EntityCreationListener { + private static final Logger LOG = LoggerFactory.getLogger(GenericEntityBatchReader.class); + + private List entities = new ArrayList(); + private StreamReader reader; + + public GenericEntityBatchReader(String serviceName, SearchCondition condition) + throws InstantiationException, IllegalAccessException { + reader = new GenericEntityStreamReader(serviceName, condition); + reader.register(this); + } + + public GenericEntityBatchReader(StreamReader reader) + throws InstantiationException, IllegalAccessException { + this.reader = reader; + reader.register(this); + } + + public long getLastTimestamp() { + return reader.getLastTimestamp(); + } + + public long getFirstTimestamp() { + return reader.getFirstTimestamp(); + } + + @Override + public void entityCreated(TaggedLogAPIEntity entity) { + entities.add(entity); + } + + @SuppressWarnings("unchecked") + public List read() throws Exception { + if (LOG.isDebugEnabled()) { + LOG.debug("Start reading as batch mode"); + } + reader.readAsStream(); + return (List)entities; + } } http://git-wip-us.apache.org/repos/asf/eagle/blob/6e919c2e/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/GenericEntityScanStreamReader.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/GenericEntityScanStreamReader.java b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/GenericEntityScanStreamReader.java index a9e03b3..6683c28 100755 --- a/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/GenericEntityScanStreamReader.java +++ b/eagle-core/eagle-query/eagle-entity-base/src/main/java/org/apache/eagle/log/entity/GenericEntityScanStreamReader.java @@ -36,7 +36,8 @@ public class GenericEntityScanStreamReader extends StreamReader { private long lastTimestamp = 0; private long firstTimestamp = 0; - public GenericEntityScanStreamReader(String serviceName, SearchCondition condition, String prefix) throws InstantiationException, IllegalAccessException{ + public GenericEntityScanStreamReader(String serviceName, SearchCondition condition, String prefix) + throws InstantiationException, IllegalAccessException { this.prefix = prefix; checkNotNull(serviceName, "serviceName"); this.entityDef = EntityDefinitionManager.getEntityByServiceName(serviceName); @@ -44,7 +45,8 @@ public class GenericEntityScanStreamReader extends StreamReader { this.condition = condition; } - public GenericEntityScanStreamReader(EntityDefinition entityDef, SearchCondition condition, String prefix) throws InstantiationException, IllegalAccessException{ + public GenericEntityScanStreamReader(EntityDefinition entityDef, SearchCondition condition, String prefix) + throws InstantiationException, IllegalAccessException { this.prefix = prefix; checkNotNull(entityDef, "entityDef"); this.entityDef = entityDef; @@ -52,12 +54,13 @@ public class GenericEntityScanStreamReader extends StreamReader { this.condition = condition; } + @Override public long getLastTimestamp() { return lastTimestamp; } - private void checkNotNull(Object o, String message){ - if(o == null){ + private void checkNotNull(Object o, String message) { + if (o == null) { throw new IllegalArgumentException(message + " should not be null"); } } @@ -71,30 +74,33 @@ public class GenericEntityScanStreamReader extends StreamReader { } @Override - public void readAsStream() throws Exception{ + public void readAsStream() throws Exception { Date start = null; Date end = null; // shortcut to avoid read when pageSize=0 - if(condition.getPageSize() <= 0){ + if (condition.getPageSize() <= 0) { return; // return nothing } // Process the time range if needed - if(entityDef.isTimeSeries()){ + if (entityDef.isTimeSeries()) { start = new Date(condition.getStartTime()); end = new Date(condition.getEndTime()); - }else{ - //start = DateTimeUtil.humanDateToDate(EntityConstants.FIXED_READ_START_HUMANTIME); - //end = DateTimeUtil.humanDateToDate(EntityConstants.FIXED_READ_END_HUMANTIME); + } else { + // start = DateTimeUtil.humanDateToDate(EntityConstants.FIXED_READ_START_HUMANTIME); + // end = DateTimeUtil.humanDateToDate(EntityConstants.FIXED_READ_END_HUMANTIME); start = new Date(EntityConstants.FIXED_READ_START_TIMESTAMP); end = new Date(EntityConstants.FIXED_READ_END_TIMESTAMP); } byte[][] outputQualifiers = null; - if(!condition.isOutputAll()) { + if (!condition.isOutputAll()) { // Generate the output qualifiers - outputQualifiers = HBaseInternalLogHelper.getOutputQualifiers(entityDef, condition.getOutputFields()); + outputQualifiers = HBaseInternalLogHelper.getOutputQualifiers(entityDef, + condition.getOutputFields()); } - HBaseLogReader2 reader = new HBaseLogReader2(entityDef, condition.getPartitionValues(), start, end, condition.getFilter(), condition.getStartRowkey(), outputQualifiers, this.prefix); - try{ + HBaseLogReader2 reader = new HBaseLogReader2(entityDef, condition.getPartitionValues(), start, end, + condition.getFilter(), condition.getStartRowkey(), + outputQualifiers, this.prefix); + try { reader.open(); InternalLog log; int count = 0; @@ -103,23 +109,24 @@ public class GenericEntityScanStreamReader extends StreamReader { if (lastTimestamp < entity.getTimestamp()) { lastTimestamp = entity.getTimestamp(); } - if(firstTimestamp > entity.getTimestamp() || firstTimestamp == 0){ + if (firstTimestamp > entity.getTimestamp() || firstTimestamp == 0) { firstTimestamp = entity.getTimestamp(); } entity.setSerializeVerbose(condition.isOutputVerbose()); entity.setSerializeAlias(condition.getOutputAlias()); - for(EntityCreationListener l : _listeners){ + for (EntityCreationListener l : listeners) { l.entityCreated(entity); } - if(++count == condition.getPageSize()) + if (++count == condition.getPageSize()) { break; + } } - }catch(IOException ioe){ + } catch (IOException ioe) { LOG.error("Fail reading log", ioe); throw ioe; - }finally{ + } finally { reader.close(); } }