我正在尝试使用Java中的couchdb(连续)更改API,并发现在耗尽当前更改列表后,流似乎已关闭,而不是永远保持打开它应该如此.
我正在使用的代码如下.我希望永远不会退出while循环,但只要当前现有的更改完成流式传输就会立即执行.我对couchdb和Java都比较新,所以可能会遗漏一些明显的东西.任何人都可以告诉我如何正确地写这个吗?
URL url = new URL("[path to database here]/_changes?feed=continuous";);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestMethod("GET");
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while((line = reader.readLine()) != null){
// do something with the line here
}
// Should never get here under normal circumstances
reader.close();
Run Code Online (Sandbox Code Playgroud) 我有一个我目前使用的映射 MapFrom一切都按预期工作。
我试图MapFrom用 a替换ResolveUsing,我发现我的解析函数根本没有被调用。就好像代码不存在一样(在构造函数中尝试带有断点的类表单时,它没有被命中)。
// This works as expected
CreateMap<Contact, ContactListViewModel>()
.ForMember(dest => dest.FirstName, map =>
map.MapFrom(s => s.RelationshipTypeId == Relationship.SELF ? s.Person.FirstName : s.FirstName))
// This doesnt. Resolver never invoked
CreateMap<Contact, ContactListViewModel>()
.ForMember(dest => dest.FirstName, opt => opt.ResolveUsing<CustomResolver>());
// Example resolver
public class CustomResolver : IValueResolver<object, object, string>
{
public CustomResolver()
{
// never called
}
public string Resolve(object source, object destination, string member, ResolutionContext context)
{
return ... // never invoked
}
} …Run Code Online (Sandbox Code Playgroud)