/** * @param create if true, instantiate the data array and fill it with random data. */ public SessionTag(boolean create) { super(); if (create) { _data = SimpleByteCache.acquire(BYTE_LENGTH); RandomSource.getInstance().nextBytes(_data); _cachedHashCode = SipHash.hashCode(_data); } }
/** * Return a msg with the date stamp of the last duplicate * @since 0.9.3 */ private String dupMessage(int dupCount, LogRecord lastRecord, boolean reverse) { String arrows = reverse ? (SystemVersion.isAndroid() ? "vvv" : "↓↓↓") : "^^^"; return LogRecordFormatter.getWhen(_manager, lastRecord) + ' ' + arrows + ' ' + _t(dupCount, "1 similar message omitted", "{0} similar messages omitted") + ' ' + arrows + LogRecordFormatter.NL; }
private void rereadConfig() { long now = Clock.getInstance().now(); if (now - _lastReadConfig > CONFIG_READ_INTERVAL) { _manager.rereadConfig(); _lastReadConfig = now; } }
/** I2P this is all static so have the UPnPManager call this */ public static void initialize(I2PAppContext ctx) { // don't keep static ref on android, just skip it if (SystemVersion.isAndroid()) return; _log = ctx.logManager().getLog(Debug.class); // org.cybergarage.util.Debug=DEBUG at startup enabled = _log.shouldLog(Log.DEBUG); }
/** * Use if it includes a link. * Does not escape '<' and '>' before queueing * @since 0.9.14.1 */ public void addMessageNoEscape(String message) { _messages.addMessageNoEscape(message); if (_log.shouldLog(Log.INFO)) _log.info("MSG: " + message); }
/** translate @since 0.7.14 */ private static String getPriority(LogRecord rec, I2PAppContext ctx) { int len; if (Translate.getLanguage(ctx).equals("de")) len = 8; // KRITISCH else len = MAX_PRIORITY_LENGTH; return toString(Translate.getString(Log.toLevelString(rec.getPriority()), ctx, BUNDLE_NAME), len); }
private ByteCache(int maxCachedEntries, int entrySize) { super(new ByteArrayFactory(entrySize), maxCachedEntries); _entrySize = entrySize; int stagger = SystemVersion.isAndroid() ? 0 : (entrySize % 777); SimpleTimer2.getInstance().addPeriodicEvent(new Cleanup(), CLEANUP_FREQUENCY + stagger); I2PAppContext.getGlobalContext().statManager().createRateStat("byteCache.memory." + entrySize, "Memory usage (B)", "Router", new long[] { 10*60*1000 }); }
/** * gettext * @since 0.9.3 */ private String _t(int a, String b, String c) { return Translate.getString(a, b, c, _manager.getContext(), BUNDLE_NAME); }
protected void writeRecord(LogRecord rec, String formatted) { writeRecord(rec.getPriority(), formatted); }
private static String getThread(LogRecord logRecord) { return toString(logRecord.getThreadName(), MAX_THREAD_LENGTH); }
/** * Sets file to mode 600 if the file is created */ @Override public boolean createNewFile() throws IOException { boolean rv = super.createNewFile(); if (rv) setPerms(); return rv; }
@Override public void run() { super.run(); synchronized(this) { // Task may have rescheduled itself without actually running. // If we schedule again, it will be stuck in a scheduling loop. // This happens after a backwards clock shift. if (_state == TimedEventState.IDLE) schedule(_timeoutMs); } } }
public void setDefaultLimit(String lim) { _defaultLimit = Log.getLevel(lim); updateLimits(); }
private SimpleByteCache(int maxCachedEntries, int entrySize) { _available = new TryCache<byte[]>(new ByteArrayFactory(entrySize), maxCachedEntries); _entrySize = entrySize; }
/** * Connect to a HTTP proxy. * Proxy address must be in _proxyHost and _proxyPort. * Side effects: Sets _proxy, _proxyIn, _proxyOut, * and other globals via readHeaders() * * @param port what the proxy should connect to, probably 4444 * @since 0.9.33 */ private void internalHttpProxyConnect(String host, int port) throws IOException { // connect to the proxy _proxy = InternalSocket.getSocket(_proxyHost, _proxyPort); httpProxyConnect(_proxy, host, port); }
/** * 32 bytes from the byte array cache. * Does NOT zero. */ protected byte[] acquireTmp() { byte rv[] = SimpleByteCache.acquire(Hash.HASH_LENGTH); return rv; }
protected void initializeClock() { // overridden in RouterContext synchronized (_lock14) { if (_clock == null) _clock = new Clock(this); _clockInitialized = true; } }