Skip to content

Commit fe2f05f

Browse files
author
huaiyuan.why
committed
add timeline v2
1 parent 22a2723 commit fe2f05f

File tree

66 files changed

+8125
-250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+8125
-250
lines changed

pom.xml

Lines changed: 229 additions & 233 deletions
Large diffs are not rendered by default.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.alicloud.openservices.tablestore.timeline;
2+
3+
4+
import com.alicloud.openservices.tablestore.timeline.model.TimelineEntry;
5+
import com.alicloud.openservices.tablestore.timeline.model.TimelineIdentifier;
6+
import com.alicloud.openservices.tablestore.timeline.model.TimelineMessage;
7+
8+
public interface TimelineCallback {
9+
/**
10+
* Function to invoke when succeed.
11+
* @param identifier The identifier of timeline.
12+
* @param message The message which is updated or stored asynchronously.
13+
* @param timelineEntry The timeline entry.
14+
*/
15+
void onCompleted(final TimelineIdentifier identifier, final TimelineMessage message, final TimelineEntry timelineEntry);
16+
17+
/**
18+
* Function to invoke when failed.
19+
* @param identifier The identifier of timeline.
20+
* @param message The message which is updated or stored asynchronously.
21+
* @param ex The exception when failed.
22+
*/
23+
void onFailed(final TimelineIdentifier identifier, final TimelineMessage message, final Exception ex);
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.alicloud.openservices.tablestore.timeline;
2+
3+
public class TimelineException extends RuntimeException {
4+
public TimelineException() {
5+
super();
6+
}
7+
8+
public TimelineException(String message) {
9+
super(message);
10+
}
11+
12+
public TimelineException(Throwable cause) {
13+
super(cause);
14+
}
15+
16+
public TimelineException(String message, Throwable cause) {
17+
super(message, cause);
18+
}
19+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.alicloud.openservices.tablestore.timeline;
2+
3+
import com.alicloud.openservices.tablestore.model.search.SearchQuery;
4+
import com.alicloud.openservices.tablestore.timeline.model.TimelineIdentifier;
5+
import com.alicloud.openservices.tablestore.timeline.model.TimelineMeta;
6+
import com.alicloud.openservices.tablestore.timeline.query.SearchParameter;
7+
import com.alicloud.openservices.tablestore.timeline.query.SearchResult;
8+
9+
/**
10+
* The store service of timeline meta.
11+
*/
12+
public interface TimelineMetaStore {
13+
/**
14+
* Get timeline meta by identifier.
15+
* Return null if this timeline meta is not exist.
16+
*
17+
* @param identifier The identifier of timeline meta.
18+
*
19+
* @return TimelineMeta
20+
*/
21+
TimelineMeta read(TimelineIdentifier identifier);
22+
23+
/**
24+
* Search timeline meta by search parameter.
25+
* Search will throw TimelineException when index info not set in TimelineSchema.
26+
*
27+
* @param searchParameter The parameter of search, which will convert to SearchQuery.
28+
*
29+
* @return SearchResult<TimelineMeta>
30+
*/
31+
SearchResult<TimelineMeta> search(SearchParameter searchParameter);
32+
33+
/**
34+
* Search timeline meta by search parameter.
35+
* Search will throw TimelineException when index info not set in TimelineSchema.
36+
*
37+
* @param searchQuery The searchQuery of search, which is self-defined query condition.
38+
*
39+
* @return SearchResult<TimelineMeta>
40+
*/
41+
SearchResult<TimelineMeta> search(SearchQuery searchQuery);
42+
43+
/**
44+
* Insert a new timeline meta with properties.
45+
*
46+
* @param meta The meta of timeline.
47+
*
48+
* @return TimelineMeta
49+
*/
50+
TimelineMeta insert(TimelineMeta meta);
51+
52+
/**
53+
* Update existed timeline meta with new properties.
54+
* It will insert a new meta if the timeline meta not exist.
55+
*
56+
* @param meta the meta of timeline.
57+
*
58+
* @return TimelineMeta
59+
*/
60+
TimelineMeta update(TimelineMeta meta);
61+
62+
/**
63+
* Delete existed timeline meta by identifier.
64+
* It won't throw exception, when the timeline meta with this identifier not exist.
65+
*
66+
* @param identifier The identifier of the timeline to be delete.
67+
*/
68+
void delete(TimelineIdentifier identifier);
69+
70+
/**
71+
* Create the table of meta store;
72+
* And create the SearchIndex of timeline meta if necessary.
73+
*/
74+
void prepareTables();
75+
76+
/**
77+
* Drop the table of meta store.
78+
* And Drop the SearchIndex of timeline meta if exist.
79+
**/
80+
void dropAllTables();
81+
82+
/**
83+
* Close store service.
84+
*/
85+
void close();
86+
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package com.alicloud.openservices.tablestore.timeline;
2+
3+
import com.alicloud.openservices.tablestore.timeline.model.TimelineEntry;
4+
import com.alicloud.openservices.tablestore.timeline.model.TimelineIdentifier;
5+
import com.alicloud.openservices.tablestore.timeline.model.TimelineMessage;
6+
import com.alicloud.openservices.tablestore.timeline.query.ScanParameter;
7+
8+
import java.util.Iterator;
9+
import java.util.concurrent.Future;
10+
11+
/**
12+
* The queue of single timeline distinguished by identifier.
13+
*/
14+
public interface TimelineQueue {
15+
16+
/**
17+
* The specified identifier of single timeline queue.
18+
*
19+
* @return Identifier
20+
*/
21+
TimelineIdentifier getIdentifier();
22+
23+
/**
24+
* Store message into specified timeline queue with auto-generated sequence id.
25+
*
26+
* @param message The content of the message to store.
27+
*
28+
* @return TimelineEntry
29+
*/
30+
TimelineEntry store(TimelineMessage message);
31+
32+
/**
33+
* Store message to specified timeline queue whose sequence id is set manually.
34+
*
35+
* @param sequenceId The sequence id of the timeline, which should be unique and incremental.
36+
* @param message The content of the message to store.
37+
*
38+
* @return TimelineEntry
39+
*/
40+
TimelineEntry store(long sequenceId, TimelineMessage message);
41+
42+
/**
43+
* Store message asynchronously with auto-generated sequence id.
44+
*
45+
* @param message The content of the message to store.
46+
* @param callback The timeline callback, which deal with response.
47+
*
48+
* @return Future<TimelineEntry>
49+
*/
50+
Future<TimelineEntry> storeAsync(TimelineMessage message, TimelineCallback callback);
51+
52+
/**
53+
* Store message asynchronously with manually set sequence id.
54+
*
55+
* @param sequenceId The sequence id of the timeline, which should be unique and incremental.
56+
* @param message The content of the message to store.
57+
* @param callback The timeline callback, which deal with response.
58+
*
59+
* @return Future<TimelineEntry>
60+
*/
61+
Future<TimelineEntry> storeAsync(long sequenceId, TimelineMessage message, TimelineCallback callback);
62+
63+
/**
64+
* Batch store message to specified timeline queue with auto-generated sequence id.
65+
*
66+
* @param message The content of the message to store.
67+
*
68+
* @return Future<TimelineEntry>
69+
*/
70+
Future<TimelineEntry> batchStore(TimelineMessage message);
71+
72+
/**
73+
* Batch store message asynchronously with manually set sequence id.
74+
*
75+
* @param sequenceId The sequence id of the timeline, which should be unique and incremental.
76+
* @param message The content of the message to store.
77+
*
78+
* @return Future<TimelineEntry>
79+
*/
80+
Future<TimelineEntry> batchStore(long sequenceId, TimelineMessage message);
81+
82+
/**
83+
* Store message asynchronously with autogenerated sequence id by writer.
84+
*
85+
* @param message The content of the message to store.
86+
* @param callback Timeline callback, which deal with single message response.
87+
*
88+
* @return Future<TimelineEntry>
89+
*/
90+
Future<TimelineEntry> batchStore(TimelineMessage message, TimelineCallback callback);
91+
92+
/**
93+
* Store message asynchronously with manually set sequence id by writer.
94+
*
95+
* @param sequenceId The sequence id of the timeline, which should be unique and incremental.
96+
* @param message The content of the message to store.
97+
* @param callback Timeline callback, which deal with single message response.
98+
*
99+
* @return Future<TimelineEntry>
100+
*/
101+
Future<TimelineEntry> batchStore(long sequenceId, TimelineMessage message, TimelineCallback callback);
102+
103+
/**
104+
* Update message with new content by sequence id.
105+
*
106+
* @param sequenceId The sequence id of the timeline to update.
107+
* @param message New content of the message to update.
108+
*
109+
* @return TimelineEntry
110+
*/
111+
TimelineEntry update(long sequenceId, TimelineMessage message);
112+
/**
113+
* Update message asynchronously with new content by sequence id.
114+
*
115+
* @param sequenceId The sequence id of the timeline to update.
116+
* @param message New content of the message to update.
117+
* @param callback Timeline callback to deal with response.
118+
*
119+
* @return Future<TimelineEntry>
120+
*/
121+
Future<TimelineEntry> updateAsync(long sequenceId, TimelineMessage message, TimelineCallback callback);
122+
123+
/**
124+
* Get timeline entry by sequence id.
125+
* Return null if this timeline entry is not exist.
126+
*
127+
* @param sequenceId The sequence id of the timeline to get.
128+
*
129+
* @return TimelineEntry
130+
*/
131+
TimelineEntry get(long sequenceId);
132+
133+
/**
134+
* Delete timeline entry by specified sequence id.
135+
*
136+
* @param sequenceId The sequence id of the timeline to delete.
137+
*/
138+
void delete(long sequenceId);
139+
140+
/**
141+
* Scan a specified range of timeline entries by scan parameter.
142+
*
143+
* @param parameter The parameter of scan range.
144+
*
145+
* @return Iterator<TimelineEntry>
146+
*/
147+
Iterator<TimelineEntry> scan(ScanParameter parameter);
148+
149+
/**
150+
* Get the latest sequence id of specified identifier.
151+
* Return 0 if not exist.
152+
*
153+
* @return long
154+
*/
155+
long getLatestSequenceId();
156+
157+
/**
158+
* Get the latest timeline entry of specified identifier.
159+
* Return null if not exist.
160+
*
161+
* @return TimelineEntry
162+
*/
163+
TimelineEntry getLatestTimelineEntry();
164+
165+
/**
166+
* Flush all the messages in buffer, wait until finish writing.
167+
*/
168+
void flush();
169+
170+
void close();
171+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.alicloud.openservices.tablestore.timeline;
2+
3+
import com.alicloud.openservices.tablestore.model.search.SearchQuery;
4+
import com.alicloud.openservices.tablestore.timeline.model.TimelineEntry;
5+
import com.alicloud.openservices.tablestore.timeline.model.TimelineIdentifier;
6+
import com.alicloud.openservices.tablestore.timeline.query.SearchParameter;
7+
import com.alicloud.openservices.tablestore.timeline.query.SearchResult;
8+
9+
/**
10+
* The store service of timeline.
11+
*/
12+
public interface TimelineStore {
13+
14+
/**
15+
* Create and get the timeline queue with specified identifier.
16+
*
17+
* @param identifier The identifier of timeline.
18+
*
19+
* @return TimelineQueue
20+
*/
21+
TimelineQueue createTimelineQueue(TimelineIdentifier identifier);
22+
23+
/**
24+
* Search timeline entries by search parameter.
25+
* Search will throw TimelineException when index info not set in TimelineSchema.
26+
*
27+
* @param searchParameter The parameter of search, which will convert to SearchQuery.
28+
*
29+
* @return SearchResult<TimelineEntry>
30+
*/
31+
SearchResult<TimelineEntry> search(SearchParameter searchParameter);
32+
33+
/**
34+
* Search TimelineEntry by search parameter.
35+
* Search will throw TimelineException when index info not set in TimelineSchema.
36+
*
37+
* @param searchQuery The SearchQuery of search, which is self-defined query condition.
38+
*
39+
* @return SearchResult<TimelineEntry>
40+
*/
41+
SearchResult<TimelineEntry> search(SearchQuery searchQuery);
42+
43+
/**
44+
* Create the table of timeline.
45+
* And create the SearchIndex of timeline if necessary.
46+
*/
47+
void prepareTables();
48+
49+
/**
50+
* Drop the table of timeline.
51+
* And drop the SearchIndex of timeline if exist.
52+
**/
53+
void dropAllTables();
54+
55+
/**
56+
* Flush all the messages in buffer, wait until finish writing.
57+
*/
58+
void flush();
59+
60+
/**
61+
* Close the writer and thread pool.
62+
*/
63+
void close();
64+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.alicloud.openservices.tablestore.timeline;
2+
3+
import com.alicloud.openservices.tablestore.timeline.model.TimelineMetaSchema;
4+
import com.alicloud.openservices.tablestore.timeline.model.TimelineSchema;
5+
6+
/**
7+
* The factory which provides the service of timeline meta and timeline.
8+
*/
9+
public interface TimelineStoreFactory {
10+
11+
/**
12+
* Create timeline store service with timeline schema.
13+
*
14+
* @param timelineSchema The schema of timeline, include table name, primary key, index schema and etc.
15+
*
16+
* @return TimelineStore
17+
*/
18+
TimelineStore createTimelineStore(TimelineSchema timelineSchema);
19+
20+
/**
21+
* Create timeline meta store service with meta schema.
22+
*
23+
* @param metaSchema The schema of timeline meta, include table name, primary key, index schema and etc.
24+
*
25+
* @return TimelineMetaStore
26+
*/
27+
TimelineMetaStore createMetaStore(TimelineMetaSchema metaSchema);
28+
}

0 commit comments

Comments
 (0)