我正在尝试使用https://dzone.com/articles/getting-started-with-apache-ignitenet-part-3-cache
中给出的ScanQuery示例我创建了具有Person类的Ignite服务器,如下所示:
class Program
{
static void Main(string[] args)
{
var cfg = new IgniteConfiguration
{
// Register custom class for Ignite serialization
BinaryConfiguration = new BinaryConfiguration(typeof(Person))
};
cfg.BinaryConfiguration.NameMapper = new BinaryBasicNameMapper() { IsSimpleName = true };
IIgnite ignite = Ignition.Start(cfg);
ICache<int, Person> cache = ignite.GetOrCreateCache<int, Person>("persons");
for (int i = 0; i < 10; i++)
{
Console.WriteLine("Inserting " + i + "th Person");
cache.Put(i, new Person() { Name = "Person " + i, Age = (i + 1) * 10 });
}
Console.WriteLine("***** Ignite Server Started and Ready *****");
Console.ReadLine();
}
}
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public override string ToString()
{
return $"Person [Name={Name}, Age={Age}]";
}
}
和如下所示的胖客户端
class Program
{
static void Main(string[] args)
{
var cfg = new IgniteConfiguration
{
// Register custom class for Ignite serialization
BinaryConfiguration = new BinaryConfiguration(typeof(Person), typeof(PersonFilter))
};
cfg.ClientMode = true;
cfg.BinaryConfiguration.NameMapper = new BinaryBasicNameMapper() { IsSimpleName = true };
IIgnite ignite = Ignition.Start(cfg);
ICache<int, Person> cache = ignite.GetOrCreateCache<int, Person>("persons");
//ScanQuery with Filter
var scanQuery = new ScanQuery<int, Person>(new PersonFilter());
IQueryCursor<ICacheEntry<int, Person>> queryCursor = cache.Query(scanQuery);
foreach (ICacheEntry<int, Person> cacheEntry in queryCursor)
Console.WriteLine(cacheEntry);
Console.ReadLine();
}
}
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public override string ToString()
{
return $"Person [Name={Name}, Age={Age}]";
}
}
public class PersonFilter : ICacheEntryFilter<int, Person>
{
public bool Invoke(ICacheEntry<int, Person> entry)
{
return entry.Key % 2 == 0;
}
}
当我同时运行它们时,胖客户端将引发错误:
JavaException:类org.apache.ignite.IgniteCheckedException:无法注入资源[method = setIgniteInstance,target = org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilterImpl @ 15b7b1c,rsrc = IgniteKernal [longJVMPauseDetector = …
但是,如果我也在IgniteServer项目中复制PersonFilter并将其添加到BinaryConfiguration类型,则此错误消失。
它应该如何工作?我认为客户端可以在运行时创建自己的过滤器,然后对服务器运行它们。那不是真的吗如果服务器是用JAVA编写的,客户端是.NET的,它将如何工作?
答案 0 :(得分:0)
是的,ScanQuery
要求在服务器端提供过滤器实现。
如果服务器是用JAVA编写的,而客户端是.NET的,它将如何工作
这是行不通的,因为Ignite需要在服务器端执行.NET筛选器,而纯Java服务器节点无法做到这一点。