Example usage for java.util NavigableMap get

List of usage examples for java.util NavigableMap get

Introduction

In this page you can find the example usage for java.util NavigableMap get.

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:org.trafodion.dtm.HBaseTmZK.java

/**
 * @param node//from www.  j av  a 2  s.co m
 * @param recovTable
 * @throws IOException
 */
public void postAllRegionEntries(HTable recovTable) throws IOException {
    LOG.info("HBaseTmZK:postAllRegionEntries: recovTable: " + recovTable);
    NavigableMap<HRegionInfo, ServerName> regionMap = recovTable.getRegionLocations();
    Iterator<Map.Entry<HRegionInfo, ServerName>> it = regionMap.entrySet().iterator();
    while (it.hasNext()) { // iterate entries.
        NavigableMap.Entry<HRegionInfo, ServerName> pairs = it.next();
        HRegionInfo region = pairs.getKey();
        LOG.info("postAllRegionEntries: region: " + region.getRegionNameAsString());
        ServerName serverValue = regionMap.get(region);
        String hostAndPort = new String(serverValue.getHostAndPort());
        StringTokenizer tok = new StringTokenizer(hostAndPort, ":");
        String hostName = new String(tok.nextElement().toString());
        int portNumber = Integer.parseInt(tok.nextElement().toString());
        byte[] lv_byte_region_info = region.toByteArray();
        try {
            LOG.info("Calling createRecoveryzNode for encoded region: " + region.getEncodedName());
            createRecoveryzNode(hostName, portNumber, region.getEncodedName(), lv_byte_region_info);
        } catch (Exception e2) {
            LOG.error("postAllRegionEntries exception in createRecoveryzNode "
                    + region.getTable().getNameAsString() + " exception: " + e2);
        }
    } // while
}

From source file:org.trafodion.dtm.TmAuditTlog.java

public void getTransactionState(TransactionState ts) throws IOException {
    if (LOG.isTraceEnabled())
        LOG.trace("getTransactionState start; transid: " + ts.getTransactionId());

    // This request might be for a transaction not originating on this node, so we need to open
    // the appropriate Tlog
    HTableInterface unknownTransactionTable;
    long lvTransid = ts.getTransactionId();
    int lv_ownerNid = (int) (lvTransid >> 32);
    int lv_lockIndex = (int) (lvTransid & tLogHashKey);
    String lv_tLogName = new String(
            "TRAFODION._DTM_.TLOG" + String.valueOf(lv_ownerNid) + "_LOG_" + Integer.toHexString(lv_lockIndex));
    HConnection unknownTableConnection = HConnectionManager.createConnection(this.config);
    unknownTransactionTable = unknownTableConnection.getTable(TableName.valueOf(lv_tLogName));

    try {/*w ww.ja v  a2  s. c o m*/
        String transidString = new String(String.valueOf(lvTransid));
        Get g;
        long key = (((lvTransid & tLogHashKey) << tLogHashShiftFactor) + (lvTransid & 0xFFFFFFFF));
        if (LOG.isTraceEnabled())
            LOG.trace("key: " + key + ", hexkey: " + Long.toHexString(key) + ", transid: " + lvTransid);
        g = new Get(Bytes.toBytes(key));
        TransState lvTxState = TransState.STATE_NOTX;
        String stateString = "";
        String transidToken = "";
        try {
            Result r = unknownTransactionTable.get(g);
            if (r == null) {
                if (LOG.isTraceEnabled())
                    LOG.trace("getTransactionState: tLog result is null: " + transidString);
            }
            if (r.isEmpty()) {
                if (LOG.isTraceEnabled())
                    LOG.trace("getTransactionState: tLog empty result: " + transidString);
            }
            byte[] value = r.getValue(TLOG_FAMILY, ASN_STATE);
            if (value == null) {
                ts.setStatus(TransState.STATE_NOTX);
                if (LOG.isTraceEnabled())
                    LOG.trace("getTransactionState: tLog value is null: " + transidString);
                return;
            }
            if (value.length == 0) {
                ts.setStatus(TransState.STATE_NOTX);
                if (LOG.isTraceEnabled())
                    LOG.trace("getTransactionState: tLog transaction not found: " + transidString);
                return;
            }
            ts.clearParticipatingRegions();
            String recordString = new String(Bytes.toString(value));
            StringTokenizer st = new StringTokenizer(recordString, ",");
            if (st.hasMoreElements()) {
                String asnToken = st.nextElement().toString();
                transidToken = st.nextElement().toString();
                stateString = st.nextElement().toString();
                if (LOG.isTraceEnabled())
                    LOG.trace("getTransactionState: transaction: " + transidToken + " stateString is: "
                            + stateString);
            }
            if (stateString.compareTo("COMMITTED") == 0) {
                lvTxState = TransState.STATE_COMMITTED;
            } else if (stateString.compareTo("ABORTED") == 0) {
                lvTxState = TransState.STATE_ABORTED;
            } else if (stateString.compareTo("ACTIVE") == 0) {
                lvTxState = TransState.STATE_ACTIVE;
            } else if (stateString.compareTo("PREPARED") == 0) {
                lvTxState = TransState.STATE_PREPARED;
            } else if (stateString.compareTo("NOTX") == 0) {
                lvTxState = TransState.STATE_NOTX;
            } else if (stateString.compareTo("FORGOTTEN") == 0) {
                // Need to get the previous state record so we know how to drive the regions
                String keyS = new String(r.getRow());
                Get get = new Get(r.getRow());
                get.setMaxVersions(versions); // will return last n versions of row
                Result lvResult = unknownTransactionTable.get(get);
                // byte[] b = lvResult.getValue(TLOG_FAMILY, ASN_STATE);  // returns current version of value
                List<Cell> list = lvResult.getColumnCells(TLOG_FAMILY, ASN_STATE); // returns all versions of this column
                for (Cell element : list) {
                    String stringValue = new String(CellUtil.cloneValue(element));
                    st = new StringTokenizer(stringValue, ",");
                    if (st.hasMoreElements()) {
                        if (LOG.isTraceEnabled())
                            LOG.trace("Performing secondary search on (" + transidToken + ")");
                        String asnToken = st.nextElement().toString();
                        transidToken = st.nextElement().toString();
                        String stateToken = st.nextElement().toString();
                        if ((stateToken.compareTo("COMMITTED") == 0)
                                || (stateToken.compareTo("ABORTED") == 0)) {
                            String rowKey = new String(r.getRow());
                            if (LOG.isTraceEnabled())
                                LOG.trace("Secondary search found record for (" + transidToken
                                        + ") with state: " + stateToken);
                            lvTxState = (stateToken.compareTo("COMMITTED") == 0) ? TransState.STATE_COMMITTED
                                    : TransState.STATE_ABORTED;
                            break;
                        } else {
                            if (LOG.isTraceEnabled())
                                LOG.trace("Secondary search skipping entry for (" + transidToken
                                        + ") with state: " + stateToken);
                        }
                    }
                }
            } else if (stateString.compareTo("ABORTING") == 0) {
                lvTxState = TransState.STATE_ABORTING;
            } else if (stateString.compareTo("COMMITTING") == 0) {
                lvTxState = TransState.STATE_COMMITTING;
            } else if (stateString.compareTo("PREPARING") == 0) {
                lvTxState = TransState.STATE_PREPARING;
            } else if (stateString.compareTo("FORGETTING") == 0) {
                lvTxState = TransState.STATE_FORGETTING;
            } else if (stateString.compareTo("FORGETTING_HEUR") == 0) {
                lvTxState = TransState.STATE_FORGETTING_HEUR;
            } else if (stateString.compareTo("BEGINNING") == 0) {
                lvTxState = TransState.STATE_BEGINNING;
            } else if (stateString.compareTo("HUNGCOMMITTED") == 0) {
                lvTxState = TransState.STATE_HUNGCOMMITTED;
            } else if (stateString.compareTo("HUNGABORTED") == 0) {
                lvTxState = TransState.STATE_HUNGABORTED;
            } else if (stateString.compareTo("IDLE") == 0) {
                lvTxState = TransState.STATE_IDLE;
            } else if (stateString.compareTo("FORGOTTEN_HEUR") == 0) {
                lvTxState = TransState.STATE_FORGOTTEN_HEUR;
            } else if (stateString.compareTo("ABORTING_PART2") == 0) {
                lvTxState = TransState.STATE_ABORTING_PART2;
            } else if (stateString.compareTo("TERMINATING") == 0) {
                lvTxState = TransState.STATE_TERMINATING;
            } else {
                lvTxState = TransState.STATE_BAD;
            }

            // get past the filler
            st.nextElement();

            // Load the TransactionState object up with regions
            while (st.hasMoreElements()) {
                String tableNameToken = st.nextToken();
                HTable table = new HTable(config, tableNameToken);
                NavigableMap<HRegionInfo, ServerName> regions = table.getRegionLocations();
                Iterator<Map.Entry<HRegionInfo, ServerName>> it = regions.entrySet().iterator();
                while (it.hasNext()) { // iterate entries.
                    NavigableMap.Entry<HRegionInfo, ServerName> pairs = it.next();
                    HRegionInfo regionKey = pairs.getKey();
                    if (LOG.isTraceEnabled())
                        LOG.trace("getTransactionState: transaction: " + transidToken + " adding region: "
                                + regionKey.getRegionNameAsString());
                    ServerName serverValue = regions.get(regionKey);
                    String hostAndPort = new String(serverValue.getHostAndPort());
                    StringTokenizer tok = new StringTokenizer(hostAndPort, ":");
                    String hostName = new String(tok.nextElement().toString());
                    int portNumber = Integer.parseInt(tok.nextElement().toString());
                    TransactionRegionLocation loc = new TransactionRegionLocation(regionKey, serverValue);
                    ts.addRegion(loc);
                }
            }
            ts.setStatus(lvTxState);

            if (LOG.isTraceEnabled())
                LOG.trace("getTransactionState: returning transid: " + ts.getTransactionId() + " state: "
                        + lvTxState);
        } catch (Exception e) {
            LOG.error("getTransactionState Exception " + Arrays.toString(e.getStackTrace()));
            throw e;
        }
    } catch (Exception e2) {
        LOG.error("getTransactionState Exception2 " + e2);
        e2.printStackTrace();
    }
    if (LOG.isTraceEnabled())
        LOG.trace("getTransactionState end transid: " + ts.getTransactionId());
    return;
}

From source file:org.wisdom.raml.visitor.RamlControllerVisitor.java

/**
 * Navigate through the Controller routes, and create {@link org.raml.model.Resource} from them.
 * If the <code>parent</code> is not null, then the created route will be added has children of the parent, otherwise
 * a new Resource is created and will be added directly to the <code>raml</code> model.
 *
 * @param routes The @{link ControllerRoute}
 * @param parent The parent {@link Resource}
 * @param raml   The {@link Raml} model/*from  ww w  .  j  a  v a  2 s  .c om*/
 */
private void navigateTheRoutes(NavigableMap<String, Collection<ControllerRouteModel<Raml>>> routes,
        Resource parent, Raml raml) {
    //nothing to see here
    if (routes == null || routes.isEmpty()) {
        return;
    }

    String headUri = routes.firstKey();
    LOGGER.debug("Routes " + routes.toString());
    LOGGER.debug("Parent " + parent);
    Collection<ControllerRouteModel<Raml>> siblings = routes.get(headUri);
    String relativeUri;

    Resource res = new Resource();
    if (parent != null) {
        res.setParentResource(parent);
        res.setParentUri(parent.getUri());
        //Get the relative part of the url
        relativeUri = normalizeActionPath(parent, headUri);
        res.setRelativeUri(relativeUri);
        parent.getResources().put(res.getRelativeUri(), res);
    } else {
        // We don't have a parent, check whether we should create one.
        if (headUri.endsWith("/")) {
            // We have to create a 'fake' parent when we have such kind of url: /foo/
            // We create a parent /foo and a sub-resource /, this is because /foo and /foo/ are different
            // Create a parent - this parent doest not have any action attached.
            String parentUri = normalizeParentPath(headUri);

            // However we do have a tricky case here, if parentURi == "/", we are the parent.
            if (!parentUri.equals("/")) {
                parent = new Resource();
                parent.setParentUri("");
                parent.setRelativeUri(parentUri);
                raml.getResources().put(parentUri, parent);

                // Now manage the current resource, it's uri is necessarily /
                relativeUri = "/";
                res.setParentUri(parent.getUri());
                res.setRelativeUri(relativeUri);
                parent.getResources().put(relativeUri, res);
            } else {
                // We are the root.
                res.setParentUri("");
                relativeUri = normalizeParentPath(headUri);
                res.setRelativeUri(relativeUri);
                raml.getResources().put(res.getRelativeUri(), res);
            }
        } else {
            // No parent
            res.setParentUri("");
            relativeUri = normalizeParentPath(headUri);
            res.setRelativeUri(relativeUri);
            raml.getResources().put(res.getRelativeUri(), res);
        }
    }

    //Add the action from the brother routes
    for (ControllerRouteModel<Raml> bro : siblings) {
        addActionFromRouteElem(bro, res);
    }

    //visit the children route
    NavigableMap<String, Collection<ControllerRouteModel<Raml>>> child = routes.tailMap(headUri, false);

    //no more route element
    if (child.isEmpty()) {
        return;
    }

    final String next = child.firstKey();
    final Resource maybeParent = findParent(next, raml);
    navigateTheRoutes(child, maybeParent, raml);
}

From source file:sadl.modellearner.rtiplus.SimplePDRTALearner.java

/**
 * Calculates the maximum allowed size for an empty interval part when only few {@link TimedTail}s use this interval. The allowed size depends on the
 * parameter for the minimum amount of {@link TimedTail}s and the distance between the occupied slots.
 * /* w w  w .jav  a 2s  .com*/
 * @param minData
 *            The minimum amount of {@link TimedTail}s
 * @return The maximum allowed size for an empty interval part
 */
private int getToleranceFewSlots(Interval in, int minData) {

    final NavigableMap<Integer, Collection<TimedTail>> tails = in.getTails().asMap();
    final int slots = tails.size();
    assert (slots > 0 && slots <= 2);
    if (slots == 1) {
        final int size = tails.firstEntry().getValue().size();
        if (size < (minData / 2.0)) {
            return (int) Math.ceil((in.getEnd() - in.getBegin() + 1) * 0.05);
        } else {
            return 0;
        }
    } else {
        final Integer t1Int = tails.firstKey();
        final int s1 = tails.get(t1Int).size();
        final Integer t2Int = tails.lastKey();
        final int s2 = tails.get(t2Int).size();
        final int t1 = t1Int.intValue();
        final int t2 = t2Int.intValue();
        final double perc = (double) (t2 - t1 - 1) / (double) (in.getEnd() - in.getBegin() - 1);
        if (s1 >= minData && s2 >= minData && perc >= 0.2) {
            return (int) Math.ceil((in.getEnd() - in.getBegin() + 1) * 0.05);
        } else if ((s1 >= minData || s2 >= minData) && perc >= 0.2) {
            return (int) Math.ceil((in.getEnd() - in.getBegin() + 1) * 0.075);
        } else {
            return (int) Math.ceil((t2 - t1 - 1) / 2.0);
        }
    }
}