Skip to content

Commit dfbb754

Browse files
kaideng
0 parents  commit dfbb754

16 files changed

+2764
-0
lines changed

pom.xml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>datapump</groupId>
8+
<artifactId>datapump</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<dependencies>
11+
12+
<dependency>
13+
<groupId>com.lmax</groupId>
14+
<artifactId>disruptor</artifactId>
15+
<version>3.3.6</version>
16+
</dependency>
17+
18+
19+
<dependency>
20+
<groupId>com.google.guava</groupId>
21+
<artifactId>guava</artifactId>
22+
<version>14.0-rc2</version>
23+
</dependency>
24+
25+
26+
<dependency>
27+
<groupId>org.apache.thrift</groupId>
28+
<artifactId>libthrift</artifactId>
29+
<version>0.10.0</version>
30+
</dependency>
31+
32+
33+
</dependencies>
34+
35+
36+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.datapump;
2+
3+
import com.lmax.disruptor.EventHandler;
4+
5+
/**
6+
* Created by kaideng on 17-6-17.
7+
*/
8+
public class AbstractConsumer implements EventHandler<Event>{
9+
10+
11+
12+
13+
14+
public void onEvent(Event event, long l, boolean b) throws Exception {
15+
16+
}
17+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.datapump;
2+
3+
/**
4+
* Created by kaideng on 17-6-18.
5+
*/
6+
public class Bootstrap {
7+
8+
public static void main(String[] args)
9+
{
10+
11+
12+
13+
}
14+
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.datapump;
2+
3+
/**
4+
* Created by kaideng on 17-6-17.
5+
*/
6+
public interface Configurable {
7+
8+
public void configure(Context context);
9+
10+
}
+223
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
package com.datapump;
2+
3+
import java.util.Collections;
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
7+
import com.google.common.base.Preconditions;
8+
import com.google.common.collect.ImmutableMap;
9+
import com.google.common.collect.Maps;
10+
11+
/**
12+
* Created by kaideng on 17-6-17.
13+
*/
14+
public class Context {
15+
16+
private Map<String, String> parameters;
17+
18+
public Context() {
19+
parameters = Collections.synchronizedMap(new HashMap<String, String>());
20+
}
21+
22+
public Context(Map<String, String> paramters) {
23+
this();
24+
this.putAll(paramters);
25+
}
26+
27+
/**
28+
* Gets a copy of the backing map structure.
29+
* @return immutable copy of backing map structure
30+
*/
31+
public ImmutableMap<String, String> getParameters() {
32+
synchronized (parameters) {
33+
return ImmutableMap.copyOf(parameters);
34+
}
35+
}
36+
/**
37+
* Removes all of the mappings from this map.
38+
*/
39+
public void clear() {
40+
parameters.clear();
41+
}
42+
43+
/**
44+
* Get properties which start with a prefix. When a property is returned,
45+
* the prefix is removed the from name. For example, if this method is
46+
* called with a parameter &quot;hdfs.&quot; and the context contains:
47+
* <code>
48+
* { hdfs.key = value, otherKey = otherValue }
49+
* </code>
50+
* this method will return a map containing:
51+
* <code>
52+
* { key = value}
53+
* </code>
54+
*
55+
* <b>Note:</b> The <tt>prefix</tt> must end with a period character. If not
56+
* this method will raise an IllegalArgumentException.
57+
*
58+
* @param prefix key prefix to find and remove from keys in resulting map
59+
* @return map with keys which matched prefix with prefix removed from
60+
* keys in resulting map. If no keys are matched, the returned map is
61+
* empty
62+
* @throws IllegalArguemntException if the given prefix does not end with
63+
* a period character.
64+
*/
65+
public ImmutableMap<String, String> getSubProperties(String prefix) {
66+
Preconditions.checkArgument(prefix.endsWith("."),
67+
"The given prefix does not end with a period (" + prefix + ")");
68+
Map<String, String> result = Maps.newHashMap();
69+
synchronized (parameters) {
70+
for (String key : parameters.keySet()) {
71+
if (key.startsWith(prefix)) {
72+
String name = key.substring(prefix.length());
73+
result.put(name, parameters.get(key));
74+
}
75+
}
76+
}
77+
return ImmutableMap.copyOf(result);
78+
}
79+
/**
80+
* Associates all of the given map's keys and values in the Context.
81+
*/
82+
public void putAll(Map<String, String> map) {
83+
parameters.putAll(map);
84+
}
85+
/**
86+
* Associates the specified value with the specified key in this context.
87+
* If the context previously contained a mapping for the key, the old value
88+
* is replaced by the specified value.
89+
* @param key key with which the specified value is to be associated
90+
* @param value to be associated with the specified key
91+
*/
92+
public void put(String key, String value) {
93+
parameters.put(key, value);
94+
}
95+
96+
/**
97+
* Returns true if this Context contains a mapping for key.
98+
* Otherwise, returns false.
99+
*/
100+
public boolean containsKey(String key) {
101+
return parameters.containsKey(key);
102+
}
103+
104+
/**
105+
* Gets value mapped to key, returning defaultValue if unmapped.
106+
* @param key to be found
107+
* @param defaultValue returned if key is unmapped
108+
* @return value associated with key
109+
*/
110+
public Boolean getBoolean(String key, Boolean defaultValue) {
111+
String value = get(key);
112+
if (value != null) {
113+
return Boolean.parseBoolean(value.trim());
114+
}
115+
return defaultValue;
116+
}
117+
/**
118+
* Gets value mapped to key, returning null if unmapped.
119+
* <p>
120+
* Note that this method returns an object as opposed to a
121+
* primitive. The configuration key requested may not be mapped
122+
* to a value and by returning the primitive object wrapper we can
123+
* return null. If the key does not exist the return value of
124+
* this method is assigned directly to a primitive, a
125+
* {@link NullPointerException} will be thrown.
126+
* </p>
127+
* @param key to be found
128+
* @return value associated with key or null if unmapped
129+
*/
130+
public Boolean getBoolean(String key) {
131+
return getBoolean(key, null);
132+
}
133+
/**
134+
* Gets value mapped to key, returning defaultValue if unmapped.
135+
* @param key to be found
136+
* @param defaultValue returned if key is unmapped
137+
* @return value associated with key
138+
*/
139+
public Integer getInteger(String key, Integer defaultValue) {
140+
String value = get(key);
141+
if (value != null) {
142+
return Integer.parseInt(value.trim());
143+
}
144+
return defaultValue;
145+
}
146+
/**
147+
* Gets value mapped to key, returning null if unmapped.
148+
* <p>
149+
* Note that this method returns an object as opposed to a
150+
* primitive. The configuration key requested may not be mapped
151+
* to a value and by returning the primitive object wrapper we can
152+
* return null. If the key does not exist the return value of
153+
* this method is assigned directly to a primitive, a
154+
* {@link NullPointerException} will be thrown.
155+
* </p>
156+
* @param key to be found
157+
* @return value associated with key or null if unmapped
158+
*/
159+
public Integer getInteger(String key) {
160+
return getInteger(key, null);
161+
}
162+
/**
163+
* Gets value mapped to key, returning defaultValue if unmapped.
164+
* @param key to be found
165+
* @param defaultValue returned if key is unmapped
166+
* @return value associated with key
167+
*/
168+
public Long getLong(String key, Long defaultValue) {
169+
String value = get(key);
170+
if (value != null) {
171+
return Long.parseLong(value.trim());
172+
}
173+
return defaultValue;
174+
}
175+
/**
176+
* Gets value mapped to key, returning null if unmapped.
177+
* <p>
178+
* Note that this method returns an object as opposed to a
179+
* primitive. The configuration key requested may not be mapped
180+
* to a value and by returning the primitive object wrapper we can
181+
* return null. If the key does not exist the return value of
182+
* this method is assigned directly to a primitive, a
183+
* {@link NullPointerException} will be thrown.
184+
* </p>
185+
* @param key to be found
186+
* @return value associated with key or null if unmapped
187+
*/
188+
public Long getLong(String key) {
189+
return getLong(key, null);
190+
}
191+
/**
192+
* Gets value mapped to key, returning defaultValue if unmapped.
193+
* @param key to be found
194+
* @param defaultValue returned if key is unmapped
195+
* @return value associated with key
196+
*/
197+
public String getString(String key, String defaultValue) {
198+
return get(key, defaultValue);
199+
}
200+
/**
201+
* Gets value mapped to key, returning null if unmapped.
202+
* @param key to be found
203+
* @return value associated with key or null if unmapped
204+
*/
205+
public String getString(String key) {
206+
return get(key);
207+
}
208+
private String get(String key, String defaultValue) {
209+
String result = parameters.get(key);
210+
if (result != null) {
211+
return result;
212+
}
213+
return defaultValue;
214+
}
215+
private String get(String key) {
216+
return get(key, null);
217+
}
218+
@Override
219+
public String toString() {
220+
return "{ parameters:" + parameters + " }";
221+
}
222+
}
223+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.datapump;
2+
3+
4+
import com.lmax.disruptor.EventHandler;
5+
6+
/**
7+
* Created by kaideng on 17-6-17.
8+
*/
9+
public class EmptyConsumer extends AbstractConsumer {
10+
11+
private int seq;
12+
13+
public EmptyConsumer(){}
14+
15+
16+
public EmptyConsumer(int seq)
17+
{
18+
this.seq=seq;
19+
}
20+
21+
22+
public void onEvent(Event event, long l, boolean b) throws Exception {
23+
System.err.println("consumer : "+event.getValue())d;
24+
}
25+
}

src/main/java/com/datapump/Event.java

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.datapump;
2+
3+
/**
4+
* Created by kaideng on 17-6-17.
5+
*/
6+
public class Event {
7+
8+
9+
private String value ;
10+
11+
public String getValue() {
12+
return value;
13+
}
14+
15+
public void setValue(String value) {
16+
this.value = value;
17+
}
18+
}

0 commit comments

Comments
 (0)