protected Logger createLogger() { return Loggers.getLogger(this); }
@Override public Time deserialize(final JsonParser parser, final DeserializationContext context) throws IOException { return Time.seconds(parser.readValueAs(Long.class)); } }
@Override @Transitions(from = STOPPED, to = DELETED) public void delete() throws Exception { MultipleFailures failures = new MultipleFailures(); for (Facet facet : facets.reverse()) { try { log.debug("Deleting facet: {}", facet); facet.delete(); } catch (Throwable t) { log.error("Failed to delete facet: {}", facet, t); failures.add(t); } } failures.maybePropagate("Failed to delete facets"); }
@Override public void customize(final HttpClientPlan plan) { checkNotNull(plan); plan.setUserAgentBase(userAgentGenerator.generate()); plan.getClient().setKeepAliveStrategy(new NexusConnectionKeepAliveStrategy(keepAliveDuration.toMillis())); plan.getClient().setRetryHandler(new StandardHttpRequestRetryHandler(2, false)); plan.getConnection().setBufferSize(bufferSize.toBytesI()); plan.getRequest().setConnectionRequestTimeout(connectionRequestTimeout.toMillisI()); plan.getRequest().setCookieSpec(CookieSpecs.IGNORE_COOKIES); plan.getRequest().setExpectContinueEnabled(false); int requestTimeoutMillis = requestTimeout.toMillisI(); plan.getSocket().setSoTimeout(requestTimeoutMillis); plan.getRequest().setConnectTimeout(requestTimeoutMillis); plan.getRequest().setSocketTimeout(requestTimeoutMillis); } }
public BlockingHttpClient(final CloseableHttpClient delegate, final Config config, final RemoteConnectionStatusObserver statusObserver, final boolean repositoryOnline, final AutoBlockConfiguration autoBlockConfiguration) { super(delegate); checkNotNull(config); this.statusObserver = checkNotNull(statusObserver); this.autoBlockConfiguration = checkNotNull(autoBlockConfiguration); blocked = config.blocked != null ? config.blocked : false; autoBlock = config.autoBlock != null ? config.autoBlock : false; if (repositoryOnline) { updateStatus(blocked ? BLOCKED : READY); } else { updateStatus(OFFLINE); } // TODO shall we use config.getConnectionConfig().getTimeout() * 2 as in NX2? autoBlockSequence = new FibonacciNumberSequence(Time.seconds(40).toMillis()); }
@Inject public BrowseNodeEntityAdapter(final ComponentEntityAdapter componentEntityAdapter, final AssetEntityAdapter assetEntityAdapter, final BrowseNodeConfiguration configuration) { super(DB_CLASS); this.assetEntityAdapter = checkNotNull(assetEntityAdapter); this.componentEntityAdapter = checkNotNull(componentEntityAdapter); this.timeoutMillis = configuration.getQueryTimeout().toMillisI(); }
private void monitorBackupResults(final List<Callable<Void>> jobs, final MultipleFailures failures) throws InterruptedException { ExecutorService executorService = makeExecutorService(); List<Future<Void>> futures = executorService.invokeAll(jobs); executorService.shutdown(); for (Future<Void> future : futures) { try { future.get(); } catch (ExecutionException e) { if (e.getCause() != null) { failures.add(e.getCause()); // when cause is present, unwrapping to reduce log noise } else { failures.add(e); } } } }
public void apply(final Mutator mutator) { checkState(initialized, "not initialized"); checkNotNull(mutator); Lock lock = Locks.write(readWriteLock); try { mutator.apply(model, configurationManager); } finally { lock.unlock(); } eventManager.post(new SecurityContributionChangedEvent()); } }
/** * Check if current state is given state. */ @VisibleForTesting boolean is(final State state) { Lock lock = Locks.read(readWriteLock); try { return current == state; } finally { lock.unlock(); } }
@Override public void serialize(final Time value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException { jgen.writeNumber(value.toSecondsI()); } }
@Inject public WebResourceServlet(final WebResourceService webResources, final XFrameOptions xframeOptions, @Named("${nexus.webresources.maxAge:-30days}") final Time maxAge) { this.webResources = checkNotNull(webResources); this.maxAgeSeconds = checkNotNull(maxAge.toSeconds()); this.xframeOptions = checkNotNull(xframeOptions); log.info("Max-age: {} ({} seconds)", maxAge, maxAgeSeconds); }
@Override @Transitions(from = NEW, to = INITIALISED) public void init(final Configuration configuration) throws Exception { this.configuration = checkNotNull(configuration); this.name = configuration.getRepositoryName(); MultipleFailures failures = new MultipleFailures(); for (Facet facet : facets) { try { log.debug("Initializing facet: {}", facet); facet.init(); } catch (Throwable t) { log.error("Failed to initialize facet: {}", facet, t); failures.add(t); } } failures.maybePropagate("Failed to initialize facets"); }
@VisibleForTesting protected boolean isTokenExpired(final long now, final Entry<UserAuthToken, Long> entry) { long diff = now - entry.getValue(); return diff > expireAfter.toMillis(); }
@VisibleForTesting public AuthTicketCache() { this(Time.seconds(2)); }
@Override public final void start() throws Exception { Lock lock = Locks.write(readWriteLock); ensure(State.NEW, State.STOPPED); try { logTransition("Starting"); doStart(); current = State.STARTED; logTransition("Started"); } catch (Throwable failure) { doFailed("start", failure); } finally { lock.unlock(); } }
public Slf4jLogChute() { this.logger = Loggers.getLogger(VelocityEngine.class); this.redirectVelocityInfoToDebug = true; }
@Override public SecurityConfiguration getContribution() { checkState(initialized, "not initialized"); Lock lock = Locks.read(readWriteLock); try { return model; } finally { lock.unlock(); } }
public static Pause pause(Time time) { return new Pause(time.toMillis()); }
@Override public final void stop() throws Exception { Lock lock = Locks.write(readWriteLock); ensure(State.STARTED); try { logTransition("Stopping"); doStop(); current = State.STOPPED; logTransition("Stopped"); } catch (Throwable failure) { doFailed("stop", failure); } finally { lock.unlock(); } }