Package org.json_voltpatches

Examples of org.json_voltpatches.JSONArray


        /*
         * Create an array containing an ad for every node including this one
         * even though the connection has already been made
         */
        JSONArray jsArray = new JSONArray();
        JSONObject hostObj = new JSONObject();
        hostObj.put("hostId", getHostId());
        hostObj.put("address",
                m_config.internalInterface.isEmpty() ?
                        socket.socket().getLocalAddress().getHostAddress() : m_config.internalInterface);
        hostObj.put("port", m_config.internalPort);
        jsArray.put(hostObj);
        for (Map.Entry<Integer, ForeignHost>  entry : m_foreignHosts.entrySet()) {
            if (entry.getValue() == null) continue;
            int hsId = entry.getKey();
            ForeignHost fh = entry.getValue();
            hostObj = new JSONObject();
            hostObj.put("hostId", hsId);
            hostObj.put("address", fh.m_listeningAddress.getAddress().getHostAddress());
            hostObj.put("port", fh.m_listeningAddress.getPort());
            jsArray.put(hostObj);
        }
        jsObj.put("hosts", jsArray);
        byte messageBytes[] = jsObj.toString(4).getBytes("UTF-8");
        ByteBuffer message = ByteBuffer.allocate(4 + messageBytes.length);
        message.putInt(messageBytes.length);
View Full Code Here


            /*
             * Loop over all the hosts and create a connection (except for the first entry, that is the leader)
             * and publish the host id that was generated. This finishes creating the mesh
             */
            JSONArray otherHosts = jsonObj.getJSONArray("hosts");
            int hostIds[] = new int[otherHosts.length()];
            SocketChannel hostSockets[] = new SocketChannel[hostIds.length];
            InetSocketAddress listeningAddresses[] = new InetSocketAddress[hostIds.length];

            for (int ii = 0; ii < otherHosts.length(); ii++) {
                JSONObject host = otherHosts.getJSONObject(ii);
                String address = host.getString("address");
                int port = host.getInt("port");
                final int hostId = host.getInt("hostId");

                LOG.info("Leader provided address " + address + ":" + port);
View Full Code Here

    }

    public static Response responseFromJSON(String jsonStr) throws JSONException, IOException {
        Response response = new Response();
        JSONObject jsonObj = new JSONObject(jsonStr);
        JSONArray resultsJson = jsonObj.getJSONArray("results");
        response.results = new VoltTable[resultsJson.length()];
        for (int i = 0; i < response.results.length; i++) {
            JSONObject tableJson = resultsJson.getJSONObject(i);
            response.results[i] =  VoltTable.fromJSONObject(tableJson);
        }
        if (jsonObj.isNull("status") == false) {
            response.status = (byte) jsonObj.getInt("status");
        }
View Full Code Here

                if (f.canRead()) {
                    try {
                        Set<String> tableNames = new HashSet<String>();
                        JSONObject digest = SnapshotUtil.CRCCheck(f, SNAP_LOG);
                        if (digest == null) continue;
                        JSONArray tables = digest.getJSONArray("tables");
                        for (int ii = 0; ii < tables.length(); ii++) {
                            tableNames.add(tables.getString(ii));
                        }
                        final StringWriter sw = new StringWriter();
                        int ii = 0;
                        for (String name : tableNames) {
                            sw.append(name);
View Full Code Here

        AdHocPlannedStatement plannedStatement = plannedStatements.get(i);
        String aggplan = new String(plannedStatement.core.aggregatorFragment, Constants.UTF8ENCODING);
        PlanNodeTree pnt = new PlanNodeTree();
        try {
            JSONObject jobj = new JSONObject( aggplan );
            JSONArray jarray =  jobj.getJSONArray(PlanNodeTree.Members.PLAN_NODES.name());
            pnt.loadFromJSONArray(jarray, db);

            if( plannedStatement.core.collectorFragment != null ) {
                //multi-partition query plan
                String collplan = new String(plannedStatement.core.collectorFragment, Constants.UTF8ENCODING);
View Full Code Here

    private ImmutableList<Stream> parseStreams(JSONObject jsData)
    {
        ImmutableList.Builder<Stream> builder = ImmutableList.builder();

        try {
            JSONArray streamArray = jsData.getJSONArray("streams");

            for (int i = 0; i < streamArray.length(); i++) {
                JSONObject streamObj = streamArray.getJSONObject(i);

                Integer newPartition = null;
                if (!streamObj.isNull("newPartition")) {
                    newPartition = Integer.parseInt(streamObj.getString("newPartition"));
                }
View Full Code Here

                @SuppressWarnings("unchecked")
                Iterator<String> it = sp.keys();
                while (it.hasNext()) {
                    String key = it.next();
                    long sourceHSId = Long.valueOf(key);
                    JSONArray destJSONArray = sp.getJSONArray(key);
                    for (int i = 0; i < destJSONArray.length(); i++) {
                        long destHSId = destJSONArray.getLong(i);
                        streamPairs.put(sourceHSId, destHSId);
                    }
                }
            } catch (JSONException e) {
                SNAP_LOG.warn("Failed to parse stream pair information", e);
View Full Code Here

     * @throws JSONException on JSON-related error.
     * @throws IOException if thrown by our JSON library.
     */
    public static VoltTable fromJSONObject(JSONObject json) throws JSONException, IOException {
        // extract the schema and creat an empty table
        JSONArray jsonCols = json.getJSONArray(JSON_SCHEMA_KEY);
        ColumnInfo[] columns = new ColumnInfo[jsonCols.length()];
        for (int i = 0; i < jsonCols.length(); i++) {
            JSONObject jsonCol = jsonCols.getJSONObject(i);
            String name = jsonCol.getString(JSON_NAME_KEY);
            VoltType type = VoltType.get((byte) jsonCol.getInt(JSON_TYPE_KEY));
            columns[i] = new ColumnInfo(name, type);
        }
        VoltTable t = new VoltTable(columns);

        // set the status byte
        byte status = (byte) json.getInt(JSON_STATUS_KEY);
        t.setStatusCode(status);

        // load the row data
        JSONArray data = json.getJSONArray(JSON_DATA_KEY);
        for (int i = 0; i < data.length(); i++) {
            JSONArray jsonRow = data.getJSONArray(i);
            assert(jsonRow.length() == jsonCols.length());
            Object[] row = new Object[jsonRow.length()];
            for (int j = 0; j < jsonRow.length(); j++) {
                row[j] = jsonRow.get(j);
                if (row[j] == JSONObject.NULL)
                    row[j] = null;
                VoltType type = columns[j].type;

                // convert strings to numbers
View Full Code Here

    {
        final List<Table> tables = SnapshotUtil.getTablesToSave(catalogDatabase);
        final Set<Integer> tableIdsToInclude = new HashSet<Integer>();

        if (jsData != null) {
            JSONArray tableIds = jsData.optJSONArray("tableIds");
            if (tableIds != null) {
                for (int i = 0; i < tableIds.length(); i++) {
                    try {
                        tableIdsToInclude.add(tableIds.getInt(i));
                    } catch (JSONException e) {
                        SNAP_LOG.warn("Unable to parse tables to include for stream snapshot", e);
                    }
                }
            }
View Full Code Here

     * If this cluster has per partition transactions ids carried over from
     * previous instances, retrieve them from ZK and pass them to snapshot save so that it can
     * include them in the snapshot
     */
    private JSONArray retrievePerPartitionTransactionIds() {
        JSONArray retval = new JSONArray();
        try {
            ByteBuffer values = ByteBuffer.wrap(m_zk.getData(VoltZK.perPartitionTxnIds, false, null));
            int numKeys = values.getInt();
            for (int ii = 0; ii < numKeys; ii++) {
                retval.put(values.getLong());
            }
        } catch (KeeperException.NoNodeException e) {/*doesn't have to exist*/}
        catch (Exception e) {
            VoltDB.crashLocalVoltDB("Failed to retrieve per partition transaction ids for snapshot", false, e);
        }
View Full Code Here

TOP

Related Classes of org.json_voltpatches.JSONArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.