/** * @return The cached builder. */ public SB acquire() { // If cached instance is already used, then we don't optimize. // Simply return a new StringBuilder in such case. if (used) return new SB(); used = true; return builder; }
/** * Converts byte array to hex string. * * @param arr Array of bytes. * @return Hex string. */ public static String byteArray2HexString(byte[] arr) { SB sb = new SB(arr.length << 1); for (byte b : arr) sb.a(Integer.toHexString(MASK & b >>> 4)).a(Integer.toHexString(MASK & b)); return sb.toString().toUpperCase(); }
/** * Creates file name for address. * * @param addr Node address. * @return Name. */ private String name(InetSocketAddress addr) { assert addr != null; SB sb = new SB(); sb.a(addr.getAddress().getHostAddress()) .a(DELIM) .a(addr.getPort()); return sb.toString(); }
/** * Returns new file name for the given key. Since fine name is based on the key, * the key must be unique. This method converts string key into hexadecimal-based * string to avoid conflicts of special characters in file names. * * @param key Unique checkpoint key. * @return Unique checkpoint file name. */ private String getUniqueFileName(CharSequence key) { assert key != null; SB sb = new SB(); // To be overly safe we'll limit file name size // to 128 characters (124 characters name + 4 character extension). // We also limit file name to upper case only to avoid surprising // behavior between Windows and Unix file systems. for (int i = 0; i < key.length() && i < 124; i++) sb.a(CODES.charAt(key.charAt(i) % CODES_LEN)); return sb.a(".gcp").toString(); }
/** * * @param err Whether to print to {@code System.err}. * @param objs Objects to log in quiet mode. */ public static void quiet(boolean err, Object... objs) { assert objs != null; String time = SHORT_DATE_FMT.format(new java.util.Date()); SB sb = new SB(); for (Object obj : objs) sb.a('[').a(time).a("] ").a(obj.toString()).a(NL); PrintStream ps = err ? System.err : System.out; ps.print(compact(sb.toString())); }
/** * Short node representation. * * @param ns Grid nodes. * @return Short string representing the node. */ public static String toShortString(Collection<? extends GridNode> ns) { SB sb = new SB("Grid nodes [cnt=" + ns.size()); for (GridNode n : ns) sb.a(", ").a(toShortString(n)); return sb.a(']').toString(); }
/** {@inheritDoc} */ @Override public String toString() { SB b = new SB("["); for (int i = 0; i < idx; i++) { if (i != 0) b.a(','); b.a(arr[i]); } b.a(']'); return S.toString(GridLongList.class, this, "arr", b); }
/** * @return String representation of structure. */ String print() { long root = root(); if (root == 0) return "Empty tree"; ArrayList<SB> s = new ArrayList<SB>(height(root) + 1); print(root, s, 0, 0); SB res = new SB(); for (SB sb : s) res.a(sb).a('\n'); return '\n' + res.toString(); }
/** * Constructs JMX object name with given properties. * Map with ordered {@code groups} used for proper object name construction. * * @param gridName Grid name. * @param grp Name of the group. * @param name Name of mbean. * @return JMX object name. * @throws MalformedObjectNameException Thrown in case of any errors. */ public static ObjectName makeMBeanName(@Nullable String gridName, @Nullable String grp, String name) throws MalformedObjectNameException { SB sb = new SB(JMX_DOMAIN + ':'); appendJvmId(sb); if (gridName != null && !gridName.isEmpty()) sb.a("grid=").a(gridName).a(','); if (grp != null) sb.a("group=").a(grp).a(','); sb.a("name=").a(name); return new ObjectName(sb.toString()); }
/** * */ private void ackCacheConfiguration() { GridCacheConfiguration[] cacheCfgs = cfg.getCacheConfiguration(); if (cacheCfgs == null || cacheCfgs.length == 0) U.warn(log, "Cache is not configured - in-memory data grid is off."); else { SB sb = new SB(); for (GridCacheConfiguration c : cacheCfgs) { String name = c.getName(); if (name == null) name = "<default>"; sb.a("'").a(name).a("', "); } String names = sb.toString(); U.log(log, "Configured caches [" + names.substring(0, names.length() - 2) + ']'); } }
/** * Constructs JMX object name with given properties. * Map with ordered {@code groups} used for proper object name construction. * * @param gridName Grid name. * @param cacheName Name of the cache. * @param name Name of mbean. * @return JMX object name. * @throws MalformedObjectNameException Thrown in case of any errors. */ public static ObjectName makeCacheMBeanName(@Nullable String gridName, @Nullable String cacheName, String name) throws MalformedObjectNameException { SB sb = new SB(JMX_DOMAIN + ':'); appendJvmId(sb); if (gridName != null && !gridName.isEmpty()) sb.a("grid=").a(gridName).a(','); cacheName = maskName(cacheName); sb.a("group=").a(cacheName).a(','); sb.a("name=").a(name); return new ObjectName(sb.toString()); }
/** * @param flags Flags. * @return String builder containing all flags. */ static String toString(short flags) { SB sb = new SB(); for (Mask m : MASKS) { if (m.ordinal() != 0) sb.a('|'); sb.a(m.name().toLowerCase()).a('=').a(m.bit(flags)); } return sb.toString(); } }
/** * Pretty-formatting for minutes. * * @param mins Minutes to format. * @return Formatted presentation of minutes. */ public static String formatMins(long mins) { assert mins >= 0; if (mins == 0) return "< 1 min"; SB sb = new SB(); long dd = mins / 1440; // 1440 mins = 60 mins * 24 hours if (dd > 0) sb.a(dd).a(dd == 1 ? " day " : " days "); mins %= 1440; long hh = mins / 60; if (hh > 0) sb.a(hh).a(hh == 1 ? " hour " : " hours "); mins %= 60; if (mins > 0) sb.a(mins).a(mins == 1 ? " min " : " mins "); return sb.toString().trim(); }
/** * Pretty-formatting for minutes. * * @param mins Minutes to format. * @return Formatted presentation of minutes. */ public static String formatMins(long mins) { assert mins >= 0; if (mins == 0) return "< 1 min"; SB sb = new SB(); long dd = mins / 1440; // 1440 mins = 60 mins * 24 hours if (dd > 0) sb.a(dd).a(dd == 1 ? " day " : " days "); mins %= 1440; long hh = mins / 60; if (hh > 0) sb.a(hh).a(hh == 1 ? " hour " : " hours "); mins %= 60; if (mins > 0) sb.a(mins).a(mins == 1 ? " min " : " mins "); return sb.toString().trim(); }
/** {@inheritDoc} */ @Override public Object readObjectOverride() throws ClassNotFoundException, IOException { curObj = null; curFields = null; byte ref = in.readByte(); switch (ref) { case NULL: return null; case HANDLE: return handles.lookup(readInt()); case OBJECT: GridOptimizedClassDescriptor desc = GridOptimizedClassResolver.readClass(this, clsLdr); curCls = desc.describedClass(); return desc.read(this); default: SB msg = new SB("Unexpected error occurred during unmarshalling"); if (curCls != null) msg.a(" of an instance of the class: ").a(curCls.getName()); msg.a(". Check that all nodes are running the same version of GridGain and that all nodes have " + "GridOptimizedMarshaller configured with identical optimized classes lists, if any " + "(see setClassNames and setClassNamesPath methods). If your serialized classes implement " + "java.io.Externalizable interface, verify that serialization logic is correct."); throw new IOException(msg.toString()); } }
/** {@inheritDoc} */ @Override public String toString() { SB sb = new SB((indexType.isUnique() ? "Unique index '" : "Index '") + getName() + "' ["); boolean first = true; for (IndexColumn col : getIndexColumns()) { if (first) first = false; else sb.a(", "); sb.a(col.getSQL()); } sb.a(" ]"); return sb.toString(); }
/** {@inheritDoc} */ @Override public String readLine() throws IOException { SB sb = new SB(); int b; while ((b = read()) >= 0) { char c = (char)b; switch (c) { case '\n': return sb.toString(); case '\r': b = read(); if (b < 0 || b == '\n') return sb.toString(); else sb.a((char)b); break; default: sb.a(c); } } return sb.toString(); }
/** * Builds ggstart.sh attributes to set up SSH username and password and log directory for started node. * * @param username SSH user name. * @param host Host. * @return {@code ggstart.sh} script arguments. */ private String buildRemoteLogArguments(String username, String host) { assert username != null; assert host != null; SB sb = new SB(); sb.a(" -J-D").a(GG_SSH_HOST).a("=\"").a(host).a("\""). a(" -J-D").a(GG_SSH_USER_NAME).a("=\"").a(username).a("\""); return sb.toString(); }
/** {@inheritDoc} */ @Override public String toString() { SB sb = new SB("Row@"); sb.a(Integer.toHexString(System.identityHashCode(this))); Value v = super.getValue(KEY_COL); sb.a("[ key: ").a(v == null ? "nil" : v.getString()); v = WeakValue.unwrap(super.getValue(VAL_COL)); sb.a(", val: ").a(v == null ? "nil" : v.getString()); sb.a(" ][ "); if (v != null) { for (int i = 2, cnt = getColumnCount(); i < cnt; i++) { v = getValue(i); if (i != 2) sb.a(", "); sb.a(v == null ? "nil" : v.getString()); } } sb.a(" ]"); return sb.toString(); }
/** {@inheritDoc} */ @Override public String toString() { SB res = new SB(); res.a(ts).a(DELIM_FIELD).a(threadId).a(DELIM_FIELD).a(pid).a(DELIM_FIELD).a(type).a(DELIM_FIELD) .a(string(path)).a(DELIM_FIELD).a(string(mode)).a(DELIM_FIELD).a(string(streamId)).a(DELIM_FIELD) .a(string(bufSize)).a(DELIM_FIELD).a(string(dataLen)).a(DELIM_FIELD).a(string(append)).a(DELIM_FIELD) .a(string(overwrite)).a(DELIM_FIELD).a(string(replication)).a(DELIM_FIELD).a(string(blockSize)) .a(DELIM_FIELD).a(string(pos)).a(DELIM_FIELD).a(string(readLen)).a(DELIM_FIELD).a(string(skipCnt)) .a(DELIM_FIELD).a(string(readLimit)).a(DELIM_FIELD).a(string(userTime)).a(DELIM_FIELD) .a(string(sysTime)).a(DELIM_FIELD).a(string(total)).a(DELIM_FIELD).a(string(destPath)).a(DELIM_FIELD) .a(string(recursive)).a(DELIM_FIELD).a(string(list)); return res.toString(); } }