Skip to content

Instantly share code, notes, and snippets.

View fastnsilver's full-sized avatar

Chris Phillipson fastnsilver

View GitHub Profile
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.redis.RedisProperties;
import org.springframework.boot.autoconfigure.redis.RedisProperties.Sentinel;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@fastnsilver
fastnsilver / JettyConfig.java
Last active August 19, 2019 03:18
Spring Boot Jetty9 enhanced config
import org.eclipse.jetty.server.LowResourceMonitor;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@fastnsilver
fastnsilver / AdditionalSystemPublicMetrics.java
Last active August 29, 2015 14:18
Another way to export metrics via statsd, graphite, and/or cloudwatch
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.Collection;
import java.util.LinkedHashSet;
import org.springframework.boot.actuate.endpoint.PublicMetrics;
import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.core.Ordered;
import com.sun.management.OperatingSystemMXBean;
@fastnsilver
fastnsilver / JettyConfig.java
Last active March 14, 2016 17:03
A possible way to bring together AWS CloudWatch and ServoMetrics observers in a Jetty Container
@Configuration
public class JettyConfig {
@Autowired
private MetricRegistry metricRegistry;
public Server jettyServer(int maxThreads, int minThreads, int idleTimeout) {
QueuedThreadPool threadPool = new InstrumentedQueuedThreadPool(metricRegistry);
threadPool.setMaxThreads(maxThreads);
threadPool.setMinThreads(minThreads);
@fastnsilver
fastnsilver / CloudWatchMetricCollector.java
Last active December 15, 2023 15:52
How to configure AWS CloudWatch metrics w/ Spring Boot
// Modeled after {@link org.springframework.cloud.netflix.servo.ServoMetricCollector}
// employed explicitly for publication of AWS CloudWatch metrics
public class CloudWatchMetricCollector {
private final Logger log = LoggerFactory.getLogger(getClass());
@Value("${spring.aws.cloudwatch.metrics.polling.timeUnit:SECONDS}")
private String timeUnit;
@Value("${spring.aws.cloudwatch.metrics.polling.interval:5}")
@fastnsilver
fastnsilver / gist:4af20978e8994ea1463e
Created March 12, 2015 04:19
Obtain Self Signed Cert
private static SSLContext obtainTrustSelfSignedSSL() {
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1)
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.BasicErrorController;
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
import org.springframework.dao.DataIntegrityViolationException;
@fastnsilver
fastnsilver / EventBusListenerMethod.java
Created August 26, 2014 16:48
Possible solution to issues 53 and 70 for Vaadin4Spring
/*
* Copyright 2014 The original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@fastnsilver
fastnsilver / SpringViewProvider.java
Created August 26, 2014 14:43
VaadinView and SpringViewProvider enhanced to discriminate version and name
/*
* Copyright 2014 The original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@fastnsilver
fastnsilver / ValidatableFieldUpdater
Created June 1, 2012 05:29
Updates field contents of a AbstractValidatableColumn
import java.util.Set;
import javax.validation.ConstraintViolation;
import org.spp.im.mui.gwt.client.module.common.widget.grid.ValidatableInputCell.ValidationData;
import org.spp.im.mui.gwt.shared.i18n.UiMessages;
import com.google.gwt.cell.client.FieldUpdater;
import com.google.gwt.user.cellview.client.AbstractHasData;
import com.google.gwt.view.client.ProvidesKey;