void processScanAttrib(InterpretationContext ic, Attributes attributes) { String scanAttrib = ic.subst(attributes.getValue(SCAN_ATTR)); if (!OptionHelper.isEmpty(scanAttrib) && !"false".equalsIgnoreCase(scanAttrib)) { ScheduledExecutorService scheduledExecutorService = context.getScheduledExecutorService(); URL mainURL = ConfigurationWatchListUtil.getMainWatchURL(context); if (mainURL == null) { addWarn("Due to missing top level configuration file, reconfiguration on change (configuration file scanning) cannot be done."); return; } ReconfigureOnChangeTask rocTask = new ReconfigureOnChangeTask(); rocTask.setContext(context); context.putObject(CoreConstants.RECONFIGURE_ON_CHANGE_TASK, rocTask); String scanPeriodAttrib = ic.subst(attributes.getValue(SCAN_PERIOD_ATTR)); Duration duration = getDuration(scanAttrib, scanPeriodAttrib); if (duration == null) { return; } addInfo("Will scan for changes in [" + mainURL + "] "); // Given that included files are encountered at a later phase, the complete list of files // to scan can only be determined when the configuration is loaded in full. // However, scan can be active if mainURL is set. Otherwise, when changes are detected // the top level config file cannot be accessed. addInfo("Setting ReconfigureOnChangeTask scanning period to " + duration); ScheduledFuture<?> scheduledFuture = scheduledExecutorService.scheduleAtFixedRate(rocTask, duration.getMilliseconds(), duration.getMilliseconds(), TimeUnit.MILLISECONDS); context.addScheduledFuture(scheduledFuture); } }
/** * {@inheritDoc} */ @Override protected void append(E event) { if (event == null || !isStarted()) return; try { final boolean inserted = queue.offer(event, eventDelayLimit.getMilliseconds(), TimeUnit.MILLISECONDS); if (!inserted) { addInfo("Dropping event due to timeout limit of [" + eventDelayLimit + "] milliseconds being exceeded"); } } catch (InterruptedException e) { addError("Interrupted while appending event to SocketAppender", e); } }
/** * {@inheritDoc} */ public final void run() { signalEntryInRunMethod(); try { while (!Thread.currentThread().isInterrupted()) { SocketConnector connector = createConnector(address, port, 0, reconnectionDelay.getMilliseconds()); connectorTask = activateConnector(connector); if(connectorTask == null) break; socket = waitForConnectorToReturnASocket(); if(socket == null) break; dispatchEvents(); } } catch (InterruptedException ex) { assert true; // ok... we'll exit now } addInfo("shutting down"); }
void processScanAttrib(InterpretationContext ic, Attributes attributes) { String scanAttrib = ic.subst(attributes.getValue(SCAN_ATTR)); if (!OptionHelper.isEmpty(scanAttrib) && !"false".equalsIgnoreCase(scanAttrib)) { ReconfigureOnChangeFilter rocf = new ReconfigureOnChangeFilter(); rocf.setContext(context); String scanPeriodAttrib = ic.subst(attributes.getValue(SCAN_PERIOD_ATTR)); if (!OptionHelper.isEmpty(scanPeriodAttrib)) { try { Duration duration = Duration.valueOf(scanPeriodAttrib); rocf.setRefreshPeriod(duration.getMilliseconds()); addInfo("Setting ReconfigureOnChangeFilter scanning period to " + duration); } catch (NumberFormatException nfe) { addError("Error while converting [" + scanAttrib + "] to long", nfe); } } rocf.start(); LoggerContext lc = (LoggerContext) context; addInfo("Adding ReconfigureOnChangeFilter as a turbo filter"); lc.addTurboFilter(rocf); } }
/** * Gets the maximum history in milliseconds * @return the max history in milliseconds */ public long getMaxHistoryMs() { return maxHistory != null ? maxHistory.getMilliseconds() : 0; }
@Override public void connectSuccess(long connectionStartTimeInMillis, int connectedDestinationIndex, int numDestinations) { if (connectionTTL != null) { connectionExpirationTime = connectionStartTimeInMillis + connectionTTL.getMilliseconds(); } else { connectionExpirationTime = Long.MAX_VALUE; } }
@Override public void connectSuccess(long connectionStartTimeInMillis, int connectedDestinationIndex, int numDestinations) { /* * If connected to a secondary, remember when the connection should be closed to * force attempt to reconnect to primary */ if (secondaryConnectionTTL != null && connectedDestinationIndex != PRIMARY_DESTINATION_INDEX) { secondaryConnectionExpirationTime = connectionStartTimeInMillis + secondaryConnectionTTL.getMilliseconds(); } else { secondaryConnectionExpirationTime = Long.MAX_VALUE; } nextDestinationIndex = PRIMARY_DESTINATION_INDEX; }
@Override public void start() { int errors = 0; if (discriminator == null) { addError("Missing discriminator. Aborting"); errors++; } if (!discriminator.isStarted()) { addError("Discriminator has not started successfully. Aborting"); errors++; } if (appenderFactory == null) { addError("AppenderFactory has not been set. Aborting"); errors++; } else { appenderTracker = new AppenderTracker<E>(context, appenderFactory); appenderTracker.setMaxComponents(maxAppenderCount); appenderTracker.setTimeout(timeout.getMilliseconds()); } if (errors == 0) { super.start(); } }
/** * Time period for which to wait after failing to connect to all servers, * before attempting to reconnect. * Default is {@value #DEFAULT_RECONNECTION_DELAY} milliseconds. */ public void setReconnectionDelay(Duration delay) { if (delay == null || delay.getMilliseconds() <= 0) { throw new IllegalArgumentException("reconnectionDelay must be > 0"); } this.reconnectionDelay = delay; }
public void setConnectionTTL(Duration connectionTTL) { if (connectionTTL != null && connectionTTL.getMilliseconds() <= 0) { throw new IllegalArgumentException("connectionTTL must be > 0"); } this.connectionTTL = connectionTTL; }
/** * Time period for connections to secondary destinations to be used * before attempting to reconnect to primary destination. * * When the value is null (the default), the feature is disabled: * the appender will stay on the current destination until an error occurs. * * @param secondaryConnectionTTL */ public void setSecondaryConnectionTTL(Duration secondaryConnectionTTL) { if (secondaryConnectionTTL != null && secondaryConnectionTTL.getMilliseconds() <= 0) { throw new IllegalArgumentException("secondaryConnectionTTL must be > 0"); } this.secondaryConnectionTTL = secondaryConnectionTTL; }
public void run() { if (delay.getMilliseconds() > 0) { addInfo("Sleeping for " + delay); try { Thread.sleep(delay.getMilliseconds()); } catch (InterruptedException e) { } } super.stop(); } }
public void run() { try { Thread.sleep(delay.getMilliseconds()); } catch (InterruptedException e) { } super.stop(); } }
public void performLogCleanup(SQLiteDatabase db, Duration expiry) { final long expiryMs = thisClock.currentTimeMillis() - expiry.getMilliseconds(); final String deleteExpiredLogsSQL = SQLBuilder.buildDeleteExpiredLogsSQL(dbNameResolver, expiryMs); db.execSQL(deleteExpiredLogsSQL); } };
public void run() { addInfo("Sleeping for "+delay); try { Thread.sleep(delay.getMilliseconds()); } catch (InterruptedException e) { } super.stop(); } }
public void run() { addInfo("Sleeping for "+delay); try { Thread.sleep(delay.getMilliseconds()); } catch (InterruptedException e) { } super.stop(); } }
public void run() { addInfo("Sleeping for "+delay); try { Thread.sleep(delay.getMilliseconds()); } catch (InterruptedException e) { } super.stop(); } }
@Override protected void subAppend(E event) { if (event == null || !isStarted()) return; try { final boolean inserted = deque.offer(event, eventDelayLimit.getMilliseconds(), TimeUnit.MILLISECONDS); if (!inserted) { addInfo("Dropping event due to timeout limit of [" + eventDelayLimit + "] being exceeded"); } } catch (InterruptedException e) { addError("Interrupted while appending event to SocketAppender", e); } }
/** * {@inheritDoc} */ @Override protected void append(E event) { if (event == null || !isStarted()) return; try { final boolean inserted = deque.offer(event, eventDelayLimit.getMilliseconds(), TimeUnit.MILLISECONDS); if (!inserted) { addInfo("Dropping event due to timeout limit of [" + eventDelayLimit + "] being exceeded"); } } catch (InterruptedException e) { addError("Interrupted while appending event to SocketAppender", e); } }
@Test public void testDuration() { setter.setProperty("duration", "1.4 seconds"); assertEquals(1400, house.getDuration().getMilliseconds()); }