This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.orm.jpa.EntityManagerFactoryAccessor; | |
import org.springframework.orm.jpa.EntityManagerFactoryUtils; | |
import org.springframework.orm.jpa.EntityManagerHolder; | |
import org.springframework.stereotype.Component; | |
import org.springframework.transaction.support.TransactionSynchronizationManager; | |
@Component | |
public class EntityManagerUtil extends EntityManagerFactoryAccessor { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Config config = ConfigService.getAppConfig(); | |
Integer defaultRequestTimeout = 200; | |
Integer requestTimeout = config.getIntProperty("requestTimeout", defaultRequestTimeout); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Config config = ConfigService.getConfig("FX.Hermes.Producer"); | |
Integer defaultSenderBatchSize = 200; | |
Integer senderBatchSize = config.getIntProperty("sender.batchsize", defaultSenderBatchSize); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
OlderNewer