Example usage for java.util.function Supplier get

List of usage examples for java.util.function Supplier get

Introduction

In this page you can find the example usage for java.util.function Supplier get.

Prototype

T get();

Source Link

Document

Gets a result.

Usage

From source file:org.commonjava.indy.metrics.IndyMetricsManager.java

public <T> T wrapWithStandardMetrics(final Supplier<T> method, final Supplier<String> classifier) {
    String name = classifier.get();
    if (SKIP_METRIC.equals(name)) {
        return method.get();
    }// ww w  .  ja v  a2s.co m

    String nodePrefix = config.getNodePrefix();

    String metricName = name(nodePrefix, name);

    Timer.Context timer = getTimer(name(metricName, TIMER)).time();
    logger.trace("START: {} ({})", metricName, timer);

    try {
        return method.get();
    } catch (Throwable e) {
        getMeter(name(name, EXCEPTION)).mark();

        getMeter(name(name, EXCEPTION, e.getClass().getSimpleName())).mark();

        throw e;
    } finally {
        if (timer != null) {
            timer.stop();
        }

        getMeter(name(name, METER)).mark();
        logger.trace("CALLS++ {}", metricName);
    }
}

From source file:org.commonjava.indy.pkg.npm.jaxrs.NPMContentAccessHandler.java

@Override
public Response doCreate(String packageType, String type, String name, String path, HttpServletRequest request,
        EventMetadata eventMetadata, Supplier<URI> uriBuilder,
        Consumer<Response.ResponseBuilder> builderModifier) {
    path = PathUtils.storagePath(path, eventMetadata);

    final StoreType st = StoreType.get(type);
    final StoreKey sk = new StoreKey(packageType, st, name);

    eventMetadata = eventMetadata.set(ContentManager.ENTRY_POINT_STORE, sk);

    Response response;//  ww  w.  j  av a2s .  c  om

    InputStream stream = null;
    try {
        // check the original existed package.json transfer
        final Transfer existed = contentController.get(sk, path, eventMetadata);
        Transfer httpMeta = null;
        Transfer temp = null;

        // copy the existed transfer to temp one
        if (existed != null && existed.exists()) {
            httpMeta = existed.getSiblingMeta(HttpExchangeMetadata.FILE_EXTENSION);
            temp = existed.getSibling(TEMP_EXTENSION);
            temp.copyFrom(existed, eventMetadata);
        }

        // store the transfer of new request package.json
        final Transfer tomerge = contentController.store(sk, path, request.getInputStream(), eventMetadata);

        // generate its relevant files from the new request package.json
        List<Transfer> generated = generateNPMContentsFromTransfer(tomerge, eventMetadata);

        // merged both of the transfers, original existed one and new request one,
        // then store the transfer, delete unuseful temp and meta transfers.
        if (temp != null && temp.exists()) {
            stream = new PackageMetadataMerger().merge(temp, tomerge);
            Transfer merged = contentController.store(sk, path, stream, eventMetadata);

            // for npm group, will not replace with the new http meta when re-upload,
            // delete the old http meta, will generate the new one with updated CONTENT-LENGTH when npm install
            httpMeta.delete();
            temp.delete();
        }

        final URI uri = uriBuilder.get();
        response = responseWithBuilder(Response.created(uri), builderModifier);

        // generate .http-metadata.json for hosted repo to resolve npm header requirements
        generateHttpMetadataHeaders(tomerge, generated, request, response);
    } catch (final IndyWorkflowException | IOException e) {
        logger.error(String.format("Failed to upload: %s to: %s. Reason: %s", path, name, e.getMessage()), e);

        response = formatResponse(e, builderModifier);
    } finally {
        closeQuietly(stream);
    }

    return response;
}

From source file:org.diorite.utils.concurrent.ParallelUtils.java

public static ForkJoinTask<Void> createSimpleTask(final Supplier<Boolean> runnable) {
    return new ForkJoinTask<Void>() {
        @Override/*from w  w  w.j a  v a 2s. com*/
        public Void getRawResult() {
            return null;
        }

        @Override
        protected void setRawResult(final Void value) {
        }

        @Override
        protected boolean exec() {
            return runnable.get();
        }
    };
}

From source file:org.diorite.utils.concurrent.ParallelUtils.java

public static <T> ForkJoinTask<T> createTask(final Supplier<T> runnable) {
    return new ForkJoinTask<T>() {
        private T result;

        @Override/* w  w  w  . ja  v a2 s .c om*/
        public T getRawResult() {
            return this.result;
        }

        @Override
        protected void setRawResult(final T value) {
            this.result = value;
        }

        @Override
        protected boolean exec() {
            this.result = runnable.get();
            return true;
        }
    };
}

From source file:org.eclipse.sw360.datahandler.couchdb.AttachmentConnector.java

/**
 * @todo remove this mess of constructors and use dependency injection
 *//*from ww w.  j  av a2 s .c o m*/
public AttachmentConnector(Supplier<HttpClient> httpClient, String dbName, Duration downloadTimeout)
        throws MalformedURLException {
    this(new DatabaseConnector(httpClient.get(), dbName), downloadTimeout);
}

From source file:org.gradle.tooling.internal.provider.runner.ClientForwardingProjectConfigurationOperationListener.java

private void incrementDuration(BuildOperationDescriptor buildOperation, String targetType, long applicationId,
        OperationFinishEvent finishEvent, Supplier<? extends InternalPluginIdentifier> pluginSupplier) {
    if (PROJECT_TARGET_TYPE.equals(targetType)) {
        InternalPluginIdentifier plugin = pluginSupplier.get();
        if (plugin != null) {
            results.get(buildOperation.getId()).increment(plugin, applicationId,
                    finishEvent.getEndTime() - finishEvent.getStartTime());
        }/*w w w  . j  a  v  a  2 s .c o m*/
    }
}

From source file:org.gradle.tooling.internal.provider.runner.PluginApplicationTracker.java

private void createAndTrack(BuildOperationDescriptor buildOperation, String targetType, long applicationId,
        Supplier<InternalPluginIdentifier> pluginSupplier) {
    if (PROJECT_TARGET_TYPE.equals(targetType)) {
        InternalPluginIdentifier plugin = pluginSupplier.get();
        if (plugin != null) {
            PluginApplication pluginApplication = new PluginApplication(applicationId, plugin);
            pluginApplicationRegistry.put(applicationId, pluginApplication);
            track(buildOperation, pluginApplication);
        }//from  ww w.  jav a 2s  .  c  o  m
    }
}

From source file:org.icgc.dcc.portal.resource.Resource.java

protected static void checkRequest(boolean errorCondition, String formatTemplate, Object... args) {
    if (errorCondition) {
        // We don't want exception within an exception-handling routine.
        final Supplier<String> errorMessageProvider = () -> {
            try {
                return format(formatTemplate, args);
            } catch (Exception e) {
                final String errorDetails = "message: '" + formatTemplate + "', parameters: '"
                        + COMMA_JOINER.join(args) + "'";
                log.error("Error while formatting message - " + errorDetails, e);

                return "Invalid web request - " + errorDetails;
            }/*from   www . ja v  a2 s  .c om*/
        };

        throw new BadRequestException(errorMessageProvider.get());
    }
}

From source file:org.jasig.portlet.notice.service.jdbc.AbstractJdbcNotificationService.java

public NotificationResponse fetchFromCacheOrSupplier(String username, Supplier<NotificationResponse> supplier) {

    NotificationResponse rslt;/*w w  w . j  a v a 2s  . c o m*/
    final CacheKey cacheKey = new CacheKey(getName(), username, sql);

    final Element m = cache.get(cacheKey);
    if (m != null) {
        // Cache hit
        rslt = (NotificationResponse) m.getObjectValue();
        logger.debug("Found the following response for user='{}' from cache:  {}", username, rslt);
    } else {
        // Cache miss
        rslt = supplier.get();
        cache.put(new Element(cacheKey, rslt));
        logger.debug("Notification service '{}' generated the following response" + "for user='{}':  {}",
                getName(), username, rslt);
    }

    return rslt;

}

From source file:org.jboss.pnc.coordinator.test.event.StatusUpdatesTest.java

/**
 * use Wait.forCondition//  w w  w  .  j a  v  a2 s  . c o m
 * 
 * @param sup
 * @param timeoutSeconds
 */
@Deprecated
private void waitForConditionWithTimeout(Supplier<Boolean> sup, int timeoutSeconds)
        throws InterruptedException {
    int secondsPassed = 0;
    while (!sup.get() && secondsPassed < timeoutSeconds) {
        Thread.sleep(1000);
        secondsPassed++;
    }
}