use of org.codehaus.jackson.type.TypeReference in project samza by apache.
the class TestCoordinatorStreamSystemProducer method testCoordinatorStreamSystemProducer.
@Test
public void testCoordinatorStreamSystemProducer() {
String source = "source";
SystemStream systemStream = new SystemStream("system", "stream");
MockCoordinatorSystemProducer systemProducer = new MockCoordinatorSystemProducer(source);
MockSystemAdmin systemAdmin = new MockSystemAdmin();
CoordinatorStreamSystemProducer producer = new CoordinatorStreamSystemProducer(systemStream, systemProducer, systemAdmin);
SetConfig setConfig1 = new SetConfig(source, "job.name", "my-job-name");
SetConfig setConfig2 = new SetConfig(source, "job.id", "1234");
Delete delete = new Delete(source, "job.name", SetConfig.TYPE);
assertFalse(systemProducer.isRegistered());
producer.register(source);
assertTrue(systemProducer.isRegistered());
assertFalse(systemProducer.isStarted());
producer.start();
assertTrue(systemProducer.isStarted());
producer.send(setConfig1);
producer.send(setConfig2);
producer.send(delete);
assertFalse(systemProducer.isStopped());
producer.stop();
assertTrue(systemProducer.isStopped());
List<OutgoingMessageEnvelope> envelopes = systemProducer.getEnvelopes();
OutgoingMessageEnvelope envelope0 = envelopes.get(0);
OutgoingMessageEnvelope envelope1 = envelopes.get(1);
OutgoingMessageEnvelope envelope2 = envelopes.get(2);
TypeReference<Object[]> keyRef = new TypeReference<Object[]>() {
};
TypeReference<Map<String, Object>> msgRef = new TypeReference<Map<String, Object>>() {
};
assertEquals(3, envelopes.size());
assertEquals(new CoordinatorStreamMessage(setConfig1), new CoordinatorStreamMessage(deserialize((byte[]) envelope0.getKey(), keyRef), deserialize((byte[]) envelope0.getMessage(), msgRef)));
assertEquals(new CoordinatorStreamMessage(setConfig2), new CoordinatorStreamMessage(deserialize((byte[]) envelope1.getKey(), keyRef), deserialize((byte[]) envelope1.getMessage(), msgRef)));
assertEquals(new CoordinatorStreamMessage(delete), new CoordinatorStreamMessage(deserialize((byte[]) envelope2.getKey(), keyRef), deserialize((byte[]) envelope2.getMessage(), msgRef)));
}
use of org.codehaus.jackson.type.TypeReference in project eiger by wlloyd.
the class SSTableImport method importSorted.
public static int importSorted(String jsonFile, ColumnFamily columnFamily, String ssTablePath, IPartitioner<?> partitioner) throws IOException {
// already imported keys count
int importedKeys = 0;
long start = System.currentTimeMillis();
JsonParser parser = getParser(jsonFile);
if (keyCountToImport == null) {
keyCountToImport = 0;
System.out.println("Counting keys to import, please wait... (NOTE: to skip this use -n <num_keys>)");
// START_OBJECT
parser.nextToken();
while (parser.nextToken() != null) {
parser.nextToken();
parser.skipChildren();
if (parser.getCurrentName() == null)
continue;
keyCountToImport++;
}
}
System.out.printf("Importing %s keys...%n", keyCountToImport);
// renewing parser
parser = getParser(jsonFile);
SSTableWriter writer = new SSTableWriter(ssTablePath, keyCountToImport);
int lineNumber = 1;
DecoratedKey prevStoredKey = null;
while (parser.nextToken() != null) {
String key = parser.getCurrentName();
if (key != null) {
String tokenName = parser.nextToken().name();
if (tokenName.equals("START_ARRAY")) {
if (columnFamily.getType() == ColumnFamilyType.Super) {
throw new RuntimeException("Can't write Standard columns to the Super Column Family.");
}
List<?> columns = parser.readValueAs(new TypeReference<List<?>>() {
});
addToStandardCF(columns, columnFamily);
} else if (tokenName.equals("START_OBJECT")) {
if (columnFamily.getType() == ColumnFamilyType.Standard) {
throw new RuntimeException("Can't write Super columns to the Standard Column Family.");
}
Map<?, ?> columns = parser.readValueAs(new TypeReference<Map<?, ?>>() {
});
addToSuperCF(columns, columnFamily);
} else {
throw new UnsupportedOperationException("Only Array or Hash allowed as row content.");
}
DecoratedKey currentKey = partitioner.decorateKey(hexToBytes(key));
if (prevStoredKey != null && prevStoredKey.compareTo(currentKey) != -1) {
System.err.printf("Line %d: Key %s is greater than previous, collection is not sorted properly. Aborting import. You might need to delete SSTables manually.%n", lineNumber, key);
return -1;
}
// saving decorated key
writer.append(currentKey, columnFamily);
columnFamily.clear();
prevStoredKey = currentKey;
importedKeys++;
lineNumber++;
long current = System.currentTimeMillis();
if (// 5 secs.
current - start >= 5000) {
System.out.printf("Currently imported %d keys.%n", importedKeys);
start = current;
}
if (keyCountToImport == importedKeys)
break;
}
}
writer.closeAndOpenReader();
return importedKeys;
}
use of org.codehaus.jackson.type.TypeReference in project Trello-Android by chrisHoekstra.
the class TrelloService method getCardsByBoardList.
public ArrayList<CardVO> getCardsByBoardList(String boardListId) {
ArrayList<CardVO> result = null;
ArrayList<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("key", PUBLIC_KEY));
params.add(new BasicNameValuePair("token", mToken));
params.add(new BasicNameValuePair("filter", "open"));
params.add(new BasicNameValuePair("badges", "true"));
params.add(new BasicNameValuePair("labels", "true"));
params.add(new BasicNameValuePair("members", "true"));
HttpGet httpGet = new HttpGet(TRELLO_API_URL + "lists/" + boardListId + "/cards?" + URLEncodedUtils.format(params, "UTF-8"));
HttpClient httpClient = getHttpClient();
try {
httpGet.setHeader("Accept", "application/json, text/javascript, */*; q=0.01");
httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT_STRING);
HttpResponse response = httpClient.execute(httpGet, mContext);
if (response != null) {
result = mObjectMapper.readValue(mJsonFactory.createJsonParser(new InputStreamReader(response.getEntity().getContent(), "UTF-8")), new TypeReference<ArrayList<CardVO>>() {
});
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
use of org.codehaus.jackson.type.TypeReference in project Trello-Android by chrisHoekstra.
the class TrelloService method getAllBoards.
public ArrayList<BoardVO> getAllBoards() {
ArrayList<BoardVO> result = null;
ArrayList<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("key", PUBLIC_KEY));
params.add(new BasicNameValuePair("token", mToken));
HttpGet httpGet = new HttpGet(TRELLO_API_URL + "members/" + "me/" + "boards/" + "all?" + URLEncodedUtils.format(params, "UTF-8"));
HttpClient httpClient = getHttpClient();
try {
httpGet.setHeader("Accept", "application/json, text/javascript, */*; q=0.01");
httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT_STRING);
HttpResponse response = httpClient.execute(httpGet, mContext);
if (response != null) {
result = mObjectMapper.readValue(mJsonFactory.createJsonParser(new InputStreamReader(response.getEntity().getContent(), "UTF-8")), new TypeReference<ArrayList<BoardVO>>() {
});
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
use of org.codehaus.jackson.type.TypeReference in project Trello-Android by chrisHoekstra.
the class TrelloService method getListsByBoard.
public ArrayList<BoardListVO> getListsByBoard(String boardId) {
ArrayList<BoardListVO> result = null;
ArrayList<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("key", PUBLIC_KEY));
params.add(new BasicNameValuePair("token", mToken));
params.add(new BasicNameValuePair("cards", "none"));
HttpGet httpGet = new HttpGet(TRELLO_API_URL + "boards/" + boardId + "/lists?" + URLEncodedUtils.format(params, "UTF-8"));
HttpClient httpClient = getHttpClient();
try {
httpGet.setHeader("Accept", "application/json, text/javascript, */*; q=0.01");
httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT_STRING);
HttpResponse response = httpClient.execute(httpGet, mContext);
if (response != null) {
result = mObjectMapper.readValue(mJsonFactory.createJsonParser(new InputStreamReader(response.getEntity().getContent(), "UTF-8")), new TypeReference<ArrayList<BoardListVO>>() {
});
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
Aggregations