Search in sources :

Example 11 with TypeReference

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)));
}
Also used : Delete(org.apache.samza.coordinator.stream.messages.Delete) SystemStream(org.apache.samza.system.SystemStream) CoordinatorStreamMessage(org.apache.samza.coordinator.stream.messages.CoordinatorStreamMessage) SetConfig(org.apache.samza.coordinator.stream.messages.SetConfig) TypeReference(org.codehaus.jackson.type.TypeReference) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope) Map(java.util.Map) Test(org.junit.Test)

Example 12 with TypeReference

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;
}
Also used : SSTableWriter(org.apache.cassandra.io.sstable.SSTableWriter) List(java.util.List) TypeReference(org.codehaus.jackson.type.TypeReference) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) JsonParser(org.codehaus.jackson.JsonParser)

Example 13 with TypeReference

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpGet(org.apache.http.client.methods.HttpGet) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) ArrayList(java.util.ArrayList) CardVO(com.chrishoekstra.trello.vo.CardVO) HttpResponse(org.apache.http.HttpResponse) TypeReference(org.codehaus.jackson.type.TypeReference) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Example 14 with TypeReference

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpGet(org.apache.http.client.methods.HttpGet) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) TypeReference(org.codehaus.jackson.type.TypeReference) IOException(java.io.IOException) BoardVO(com.chrishoekstra.trello.vo.BoardVO) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Example 15 with TypeReference

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;
}
Also used : BoardListVO(com.chrishoekstra.trello.vo.BoardListVO) InputStreamReader(java.io.InputStreamReader) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpGet(org.apache.http.client.methods.HttpGet) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) TypeReference(org.codehaus.jackson.type.TypeReference) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Aggregations

TypeReference (org.codehaus.jackson.type.TypeReference)28 IOException (java.io.IOException)16 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)10 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)10 JsonParseException (org.codehaus.jackson.JsonParseException)9 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 InputStreamReader (java.io.InputStreamReader)4 HashMap (java.util.HashMap)4 HttpResponse (org.apache.http.HttpResponse)4 ClientProtocolException (org.apache.http.client.ClientProtocolException)4 HttpClient (org.apache.http.client.HttpClient)4 HttpGet (org.apache.http.client.methods.HttpGet)3 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)3 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)3 File (java.io.File)2 List (java.util.List)2 Test (org.junit.Test)2 Activate (aQute.bnd.annotation.component.Activate)1 BlogSearchJson (cn.eoe.app.entity.BlogSearchJson)1