forked from openmessaging/openconnect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize ConnectRecord api openmessaging#47
- Loading branch information
1 parent
ed258b0
commit 5de17b2
Showing
3 changed files
with
269 additions
and
37 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
connector/src/main/java/io/openmessaging/connector/api/component/task/sink/SinkRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package io.openmessaging.connector.api.component.task.sink; | ||
|
||
import io.openmessaging.KeyValue; | ||
import io.openmessaging.connector.api.data.ConnectRecord; | ||
import io.openmessaging.connector.api.data.Schema; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* sink connect record | ||
*/ | ||
public class SinkRecord extends ConnectRecord<SinkRecord> { | ||
|
||
private final String brokerName; | ||
private final long queueOffset; | ||
|
||
public SinkRecord(String brokerName, long queueOffset,String topic, Integer queueId, Schema schema, Object data) { | ||
this(brokerName, queueOffset, topic, queueId, null, schema, data ,null ); | ||
} | ||
|
||
public SinkRecord(String brokerName, long queueOffset,String topic, Integer queueId, Schema schema, Object data, KeyValue extensions) { | ||
this(brokerName, queueOffset, topic, queueId, null, schema, data ,extensions ); | ||
} | ||
|
||
public SinkRecord(String brokerName, long queueOffset,String topic, Integer queueId, Long timestamp, Schema schema, Object data) { | ||
this(brokerName, queueOffset, topic, queueId, timestamp, schema, data ,null ); | ||
} | ||
|
||
public SinkRecord(String brokerName, long queueOffset, String topic, Integer queueId, Long timestamp, Schema schema, Object data, KeyValue extensions) { | ||
super(topic, queueId, timestamp, schema, data, extensions); | ||
this.brokerName = brokerName; | ||
this.queueOffset = queueOffset; | ||
} | ||
|
||
public String brokerName(){ | ||
return brokerName; | ||
} | ||
|
||
public long queueOffset(){ | ||
return queueOffset; | ||
} | ||
|
||
/** | ||
* new record | ||
* | ||
* @param topic | ||
* @param queueId | ||
* @param schema | ||
* @param data | ||
* @param timestamp | ||
* @return | ||
*/ | ||
@Override | ||
public SinkRecord newRecord(String topic, Integer queueId, Schema schema, Object data, Long timestamp) { | ||
return newRecord(topic,queueId,schema,data,timestamp, null); | ||
} | ||
|
||
/** | ||
* new record | ||
* | ||
* @param topic | ||
* @param queueId | ||
* @param schema | ||
* @param data | ||
* @param timestamp | ||
* @param extensions | ||
* @return | ||
*/ | ||
@Override | ||
public SinkRecord newRecord(String topic, Integer queueId, Schema schema, Object data, Long timestamp, KeyValue extensions) { | ||
return new SinkRecord(brokerName(), queueOffset(), topic, queueId, timestamp, schema, data, extensions); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof SinkRecord)) return false; | ||
if (!super.equals(o)) return false; | ||
SinkRecord that = (SinkRecord) o; | ||
return queueOffset == that.queueOffset && Objects.equals(brokerName, that.brokerName); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(super.hashCode(), brokerName, queueOffset); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SinkRecord{" + | ||
"brokerName='" + brokerName + '\'' + | ||
", queueOffset=" + queueOffset + | ||
"} " + super.toString(); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...ctor/src/main/java/io/openmessaging/connector/api/component/task/source/SourceRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package io.openmessaging.connector.api.component.task.source; | ||
|
||
import io.openmessaging.KeyValue; | ||
import io.openmessaging.connector.api.data.ConnectRecord; | ||
import io.openmessaging.connector.api.data.RecordOffset; | ||
import io.openmessaging.connector.api.data.RecordPartition; | ||
import io.openmessaging.connector.api.data.RecordPosition; | ||
import io.openmessaging.connector.api.data.Schema; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* source connect record | ||
*/ | ||
public class SourceRecord extends ConnectRecord<SourceRecord> { | ||
|
||
private final RecordPosition position; | ||
|
||
public SourceRecord(RecordPartition recordPartition, RecordOffset recordOffset, String topic, Schema schema, Object data) { | ||
this(recordPartition, recordOffset, topic, null , null,schema , data, null); | ||
} | ||
|
||
public SourceRecord(RecordPartition recordPartition, RecordOffset recordOffset, String topic, Schema schema, Object data, KeyValue extensions) { | ||
this(recordPartition, recordOffset, topic, null , null,schema , data, extensions); | ||
} | ||
|
||
public SourceRecord(RecordPartition recordPartition, RecordOffset recordOffset,String topic, Integer queueId, Schema schema, Object data) { | ||
this(recordPartition, recordOffset, topic, queueId, null, schema , data, null); | ||
} | ||
|
||
public SourceRecord(RecordPartition recordPartition, RecordOffset recordOffset,String topic, Integer queueId, Schema schema, Object data, KeyValue extensions) { | ||
this(recordPartition, recordOffset, topic, queueId, null, schema , data, extensions); | ||
} | ||
|
||
public SourceRecord(RecordPartition recordPartition, RecordOffset recordOffset,String topic, Integer queueId, Long timestamp, Schema schema, Object data) { | ||
this(recordPartition, recordOffset, topic, queueId, timestamp, schema , data, null); | ||
} | ||
|
||
public SourceRecord(RecordPartition recordPartition, RecordOffset recordOffset, String topic, Integer queueId, Long timestamp, Schema schema, Object data, KeyValue extensions) { | ||
super(topic, queueId, timestamp, schema, data, extensions); | ||
this.position = new RecordPosition(recordPartition, recordOffset); | ||
} | ||
|
||
public RecordPosition position() { | ||
return position; | ||
} | ||
|
||
/** | ||
* new record | ||
* | ||
* @param topic | ||
* @param queueId | ||
* @param schema | ||
* @param data | ||
* @param timestamp | ||
* @return | ||
*/ | ||
@Override | ||
public SourceRecord newRecord(String topic, Integer queueId, Schema schema, Object data, Long timestamp) { | ||
return newRecord(topic, queueId, schema , data, timestamp, null ); | ||
} | ||
|
||
/** | ||
* new record | ||
* | ||
* @param topic | ||
* @param queueId | ||
* @param schema | ||
* @param data | ||
* @param timestamp | ||
* @param extensions | ||
* @return | ||
*/ | ||
@Override | ||
public SourceRecord newRecord(String topic, Integer queueId, Schema schema, Object data, Long timestamp, KeyValue extensions) { | ||
return new SourceRecord(position().getPartition(), position().getOffset(), topic, queueId, timestamp, schema, data, extensions); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof SourceRecord)) return false; | ||
if (!super.equals(o)) return false; | ||
SourceRecord that = (SourceRecord) o; | ||
return Objects.equals(position, that.position); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(super.hashCode(), position); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SourceRecord{" + | ||
"position=" + position + | ||
"} " + super.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters