Example usage for java.lang Long toHexString

List of usage examples for java.lang Long toHexString

Introduction

In this page you can find the example usage for java.lang Long toHexString.

Prototype

public static String toHexString(long i) 

Source Link

Document

Returns a string representation of the long argument as an unsigned integer in base 16.

Usage

From source file:org.apache.hadoop.hbase.regionserver.HRegionServer.java

protected void handleReportForDutyResponse(final RegionServerStartupResponse c) throws IOException {
    try {//from  ww w.  j  a v a  2  s  . com
        for (NameStringPair e : c.getMapEntriesList()) {
            String key = e.getName();
            // The hostname the master sees us as.
            if (key.equals(HConstants.KEY_FOR_HOSTNAME_SEEN_BY_MASTER)) {
                String hostnameFromMasterPOV = e.getValue();
                this.serverName = ServerName.valueOf(hostnameFromMasterPOV, rpcServices.isa.getPort(),
                        this.startcode);
                if (!hostnameFromMasterPOV.equals(rpcServices.isa.getHostName())) {
                    LOG.info("Master passed us a different hostname to use; was="
                            + rpcServices.isa.getHostName() + ", but now=" + hostnameFromMasterPOV);
                }
                continue;
            }
            String value = e.getValue();
            if (LOG.isDebugEnabled()) {
                LOG.info("Config from master: " + key + "=" + value);
            }
            this.conf.set(key, value);
        }

        // hack! Maps DFSClient => RegionServer for logs.  HDFS made this
        // config param for task trackers, but we can piggyback off of it.
        if (this.conf.get("mapreduce.task.attempt.id") == null) {
            this.conf.set("mapreduce.task.attempt.id", "hb_rs_" + this.serverName.toString());
        }

        // Save it in a file, this will allow to see if we crash
        ZNodeClearer.writeMyEphemeralNodeOnDisk(getMyEphemeralNodePath());

        this.hlog = setupWALAndReplication();
        // Init in here rather than in constructor after thread name has been set
        this.metricsRegionServer = new MetricsRegionServer(new MetricsRegionServerWrapperImpl(this));

        startServiceThreads();
        startHeapMemoryManager();
        LOG.info("Serving as " + this.serverName + ", RpcServer on " + rpcServices.isa + ", sessionid=0x"
                + Long.toHexString(this.zooKeeper.getRecoverableZooKeeper().getSessionId()));
        synchronized (online) {
            online.set(true);
            online.notifyAll();
        }
    } catch (Throwable e) {
        stop("Failed initialization");
        throw convertThrowableToIOE(cleanup(e, "Failed init"), "Region server startup failed");
    } finally {
        sleeper.skipSleepCycle();
    }
}

From source file:org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils.java

public boolean checkFileCRCCode(File targetFile, File sourceFile) throws Exception {
    // Cyclic Redundancy Check(CRC)
    if (!targetFile.exists() || !sourceFile.exists()) {
        return true;
    }//from   w  w w.  j a  va  2 s .  com
    FileInputStream tagetFilestream = new FileInputStream(targetFile);
    CRC32 targertCrc32 = new CRC32();
    for (CheckedInputStream checkedinputstream = new CheckedInputStream(tagetFilestream,
            targertCrc32); checkedinputstream.read() != -1;) {
        //
    }
    FileInputStream sourceFilestream = new FileInputStream(sourceFile);
    CRC32 sourceCrc32 = new CRC32();
    for (CheckedInputStream checkedinputstream = new CheckedInputStream(sourceFilestream,
            sourceCrc32); checkedinputstream.read() != -1;) {
        //
    }
    tagetFilestream.close();
    sourceFilestream.close();
    return Long.toHexString(targertCrc32.getValue()).equals(Long.toHexString(sourceCrc32.getValue()));

}

From source file:org.apache.pulsar.client.impl.ConsumerImpl.java

private boolean verifyChecksum(ByteBuf headersAndPayload, MessageIdData messageId) {

    if (hasChecksum(headersAndPayload)) {
        int checksum = readChecksum(headersAndPayload);
        int computedChecksum = computeChecksum(headersAndPayload);
        if (checksum != computedChecksum) {
            log.error(/*from  w  ww .j a v a 2 s . co m*/
                    "[{}][{}] Checksum mismatch for message at {}:{}. Received checksum: 0x{}, Computed checksum: 0x{}",
                    topic, subscription, messageId.getLedgerId(), messageId.getEntryId(),
                    Long.toHexString(checksum), Integer.toHexString(computedChecksum));
            return false;
        }
    }

    return true;
}

From source file:com.moez.QKSMS.mmssms.Transaction.java

private static Uri insert(Context context, String[] to, MMSPart[] parts, String subject) {
    try {//  ww  w . j av  a 2  s . c o  m
        Uri destUri = Uri.parse("content://mms");

        Set<String> recipients = new HashSet<>();
        recipients.addAll(Arrays.asList(to));
        long thread_id = Utils.getOrCreateThreadId(context, recipients);

        // Create a dummy sms
        ContentValues dummyValues = new ContentValues();
        dummyValues.put("thread_id", thread_id);
        dummyValues.put("body", " ");
        Uri dummySms = context.getContentResolver().insert(Uri.parse("content://sms/sent"), dummyValues);

        // Create a new message entry
        long now = System.currentTimeMillis();
        ContentValues mmsValues = new ContentValues();
        mmsValues.put("thread_id", thread_id);
        mmsValues.put("date", now / 1000L);
        mmsValues.put("msg_box", 4);
        //mmsValues.put("m_id", System.currentTimeMillis());
        mmsValues.put("read", true);
        mmsValues.put("sub", subject != null ? subject : "");
        mmsValues.put("sub_cs", 106);
        mmsValues.put("ct_t", "application/vnd.wap.multipart.related");

        long imageBytes = 0;

        for (MMSPart part : parts) {
            imageBytes += part.Data.length;
        }

        mmsValues.put("exp", imageBytes);

        mmsValues.put("m_cls", "personal");
        mmsValues.put("m_type", 128); // 132 (RETRIEVE CONF) 130 (NOTIF IND) 128 (SEND REQ)
        mmsValues.put("v", 19);
        mmsValues.put("pri", 129);
        mmsValues.put("tr_id", "T" + Long.toHexString(now));
        mmsValues.put("resp_st", 128);

        // Insert message
        Uri res = context.getContentResolver().insert(destUri, mmsValues);
        String messageId = res.getLastPathSegment().trim();

        // Create part
        for (MMSPart part : parts) {
            if (part.MimeType.startsWith("image")) {
                createPartImage(context, messageId, part.Data, part.MimeType);
            } else if (part.MimeType.startsWith("text")) {
                createPartText(context, messageId, new String(part.Data, "UTF-8"));
            }
        }

        // Create addresses
        for (String addr : to) {
            createAddr(context, messageId, addr);
        }

        //res = Uri.parse(destUri + "/" + messageId);

        // Delete dummy sms
        context.getContentResolver().delete(dummySms, null, null);

        return res;
    } catch (Exception e) {
        if (LOCAL_LOGV)
            Log.v(TAG, "still an error saving... :(");
        Log.e(TAG, "exception thrown", e);
    }

    return null;
}

From source file:com.peterbochs.instrument.InstrumentPanel.java

@Override
public void chartMouseClicked(ChartMouseEvent event) {
    try {/*from  w w w .  j av a 2  s.  com*/
        // System.out.println(event.getTrigger().getX());
        JFreeChart chart = event.getChart();
        XYPlot xyplot = chart.getXYPlot();
        MyXYBlockRenderer renderer = (MyXYBlockRenderer) xyplot.getRenderer();

        XYZDataset dataset = (XYZDataset) xyplot.getDataset();
        XYItemEntity entity = (XYItemEntity) event.getEntity();
        int series = entity.getSeriesIndex();
        int item = entity.getItem();

        int i = event.getTrigger().getX();
        int j = event.getTrigger().getY();
        Point2D point2d = jMemoryChartPanel.translateScreenToJava2D(new Point(i, j));
        ChartRenderingInfo chartrenderinginfo = jMemoryChartPanel.getChartRenderingInfo();
        Rectangle2D rectangle2d = chartrenderinginfo.getPlotInfo().getDataArea();
        double x = xyplot.getDomainAxis().java2DToValue(point2d.getX(), rectangle2d,
                xyplot.getDomainAxisEdge());
        double y = xyplot.getRangeAxis().java2DToValue(point2d.getY(), rectangle2d, xyplot.getRangeAxisEdge());
        int realX = (int) Math.round(x);
        int realY = (int) Math.round(y);
        renderer.setSelectedXY(realX, realY);
        long blockSize = CommonLib.convertFilesize((String) jBlockSizeComboBox.getSelectedItem());
        long columnCount = Data.getColumnCount(
                CommonLib.convertFilesize((String) jFromComboBox.getSelectedItem()),
                CommonLib.convertFilesize((String) jToComboBox.getSelectedItem()), blockSize);
        Long address = ((realY * columnCount) + realX) * blockSize;

        updateHotestTable(address, blockSize);

        this.jAddressLabel.setText("Address=0x" + Long.toHexString(address));
        this.jRWCountLabel.setText("R/W count=" + (int) dataset.getZValue(series, item));
    } catch (Exception ex) {

    }
}

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  w w.j  a v  a 2 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:com.cyberway.issue.crawler.framework.CrawlController.java

protected String getBdbLogFileName(final long index) {
    String lastBdbLogFileHex = Long.toHexString(index);
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < (8 - lastBdbLogFileHex.length()); i++) {
        buffer.append('0');
    }/*from w  w w. j a  va 2s  .com*/
    buffer.append(lastBdbLogFileHex);
    buffer.append(".jdb");
    return buffer.toString();
}

From source file:org.apache.hadoop.hbase.client.ConnectionImplementation.java

private void closeZooKeeperWatcher() {
    synchronized (masterAndZKLock) {
        if (keepAliveZookeeper != null) {
            LOG.info("Closing zookeeper sessionid=0x"
                    + Long.toHexString(keepAliveZookeeper.getRecoverableZooKeeper().getSessionId()));
            keepAliveZookeeper.internalClose();
            keepAliveZookeeper = null;/*w w  w  .  j a  v a2  s. com*/
        }
        keepAliveZookeeperUserCount.set(0);
    }
}

From source file:org.oscm.subscriptionservice.bean.SubscriptionServiceBean.java

/**
 * Gets the URL to access the subscription.
 * /*from   www  .j a  v a2  s.co m*/
 * @param subscription
 *            the subscription for which we want to know the URL
 * @return the URL to access the subscription
 */
String getSubscriptionUrl(Subscription subscription) {
    StringBuilder url = new StringBuilder();
    String baseUrl = cfgService.getBaseURL();
    String technicalProductBaseUrl = subscription.getProduct().getTechnicalProduct().getBaseURL();

    if (ADMValidator.isHttpsScheme(technicalProductBaseUrl)) {
        baseUrl = cfgService
                .getConfigurationSetting(ConfigurationKey.BASE_URL_HTTPS, Configuration.GLOBAL_CONTEXT)
                .getValue();
    }

    url.append(baseUrl);
    if (url.length() == 0 || url.charAt(url.length() - 1) != '/') {
        url.append('/');
    }
    url.append("opt/");
    url.append(Long.toHexString(subscription.getKey()));
    url.append('/');
    return url.toString();
}

From source file:com.servoy.j2db.util.Utils.java

public static String longToHexString(long n, int digits) {
    StringBuilder buffer = new StringBuilder(Long.toHexString(n));
    if (buffer.length() > digits)
        return buffer.substring(buffer.length() - digits);
    while (buffer.length() < digits)
        buffer.insert(0, '0');
    return buffer.toString();
}