Skip to content

Instantly share code, notes, and snippets.

View nobodyiam's full-sized avatar
:electron:
Coding

Jason Song nobodyiam

:electron:
Coding
View GitHub Profile
@nobodyiam
nobodyiam / Apollo Contributor License Agreement
Last active May 15, 2021 07:39
Apollo Contributor License Agreement
# Apollo Contributor License Agreement
In order to clarify the intellectual property license granted with Contributions from any person or entity, the open source project Apollo ("Apollo") must have a Contributor License Agreement (CLA) on file that has been signed by each Contributor, indicating agreement to the license terms below. This license is for your protection as a Contributor as well as the protection of Apollo and its users; it does not change your rights to use your own Contributions for any other purpose.
You accept and agree to the following terms and conditions for Your present and future Contributions submitted to Apollo. Except for the license granted herein to Apollo and recipients of software distributed by Apollo, You reserve all right, title, and interest in and to Your Contributions.
1. Definitions. "You" (or "Your") shall mean the copyright owner or legal entity authorized by the copyright owner that is making this Agreement with Apollo. For legal entities, the entity making a Contri
Escaper pathEscapers = UrlEscapers.urlPathSegmentEscaper();
Escaper queryEscapers = UrlEscapers.urlFormParameterEscaper();
Escaper fragmentEscaper= UrlEscapers.urlFragmentEscaper();
String path1 = "somePathWithSpace ";
String path2 = "somePathWith中文AndPlus+";
String someKeyword = "someKeywordWith中文AndPlus+AndSpace ";
String someFragment = "someFragmentWithSpace ";
String url = String.format(
@nobodyiam
nobodyiam / ApolloClientNamespaceChangeListenerDemo.java
Created July 6, 2016 14:52
Apollo client change listener for namespace
Config config = ConfigService.getConfig("FX.Hermes.Producer");
config.addChangeListener(new ConfigChangeListener() {
@Override
public void onChange(ConfigChangeEvent changeEvent) {
System.out.println("Changes for namespace " + changeEvent.getNamespace());
for (String key : changeEvent.changedKeys()) {
ConfigChange change = changeEvent.getChange(key);
System.out.println(String.format(
"Found change - key: %s, oldValue: %s, newValue: %s, changeType: %s",
change.getPropertyName(), change.getOldValue(),
@nobodyiam
nobodyiam / ApolloClientGetNamespaceConfigDemo
Created July 6, 2016 14:51
Apollo client get config of namespace
Config config = ConfigService.getConfig("FX.Hermes.Producer");
Integer defaultSenderBatchSize = 200;
Integer senderBatchSize = config.getIntProperty("sender.batchsize", defaultSenderBatchSize);
@nobodyiam
nobodyiam / ApolloClientChangeListenerDemo.java
Created July 6, 2016 14:32
Apollo client change listener
Config config = ConfigService.getAppConfig();
config.addChangeListener(new ConfigChangeListener() {
@Override
public void onChange(ConfigChangeEvent changeEvent) {
for (String key : changeEvent.changedKeys()) {
ConfigChange change = changeEvent.getChange(key);
System.out.println(String.format(
"Found change - key: %s, oldValue: %s, newValue: %s, changeType: %s",
change.getPropertyName(), change.getOldValue(),
change.getNewValue(), change.getChangeType()));
@nobodyiam
nobodyiam / ApolloClientGetConfigDemo.java
Created July 6, 2016 14:25
Apollo client get config
Config config = ConfigService.getAppConfig();
Integer defaultRequestTimeout = 200;
Integer requestTimeout = config.getIntProperty("requestTimeout", defaultRequestTimeout);
@RestController
@RequestMapping("/notifications")
public class NotificationControllerSample implements MessageListener {
@Autowired
private EntityManagerUtil entityManagerUtil;
private List<String> findWatchedKeys(String applicationId, String namespace,
String dataCenter) {
List<String> watchedKeys = Lists.newArrayList();
//do more logic, may need to load from db in some cases
public class DispatcherServlet extends FrameworkServlet {
protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {
...
// Actually invoke the handler.
mv = ha.handle(processedRequest, response, mappedHandler.getHandler());
if (asyncManager.isConcurrentHandlingStarted()) {
return;
public class OpenEntityManagerInViewInterceptor extends EntityManagerFactoryAccessor implements AsyncWebRequestInterceptor {
@Override
public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException {
if (!decrementParticipateCount(request)) {
EntityManagerHolder emHolder = (EntityManagerHolder)TransactionSynchronizationManager.unbindResource(getEntityManagerFactory());
logger.debug("Closing JPA EntityManager in OpenEntityManagerInViewInterceptor");
EntityManagerFactoryUtils.closeEntityManager(emHolder.getEntityManager());
}
}
@RestController
@RequestMapping("/notifications")
public class NotificationControllerSample implements MessageListener {
private static final long TIMEOUT = 360 * 60 * 1000;//6 hours
private final Multimap<String, DeferredResult<ResponseEntity<ApolloConfigNotification>>>
deferredResults = Multimaps.synchronizedSetMultimap(HashMultimap.create());
private static final ResponseEntity<ApolloConfigNotification>
NOT_MODIFIED_RESPONSE = new ResponseEntity<>(HttpStatus.NOT_MODIFIED);
@RequestMapping(method = RequestMethod.GET)