public static void main(String args[])throws Exception{
if(Locator.hasLocator()) {
Locator l = Locator.getLocator();
System.out.println("Name of the locator running is: "+l.asString());
}else {
LocatorLauncher locatorLauncher = new
LocatorLauncher.Builder().setMemberName("mylocator").
setPort(13334).build();
locatorLauncher.start();
ServerLauncher serverLauncher = new
ServerLauncher.Builder().setMemberName("myserver").
setServerPort(40404).
set("sta rt-locator", "localhost[13334]").build();
System.out.println(serverLauncher.getMemberName());
}
Cache myCache = new CacheFactory().create();
System.out.println("Cache created");
Region<String, String> myRegion = myCache.<String,
String>createRegionFactory(RegionShortcut.REPLICATE).create("region");
myRegion.put("1","One");
myRegion.put("2","Two");
}
执行代码时出现此错误:
Exception in thread "main" java.lang.IllegalStateException: Regions can not be created in a locator.
有人可以帮忙吗?
答案 0 :(得分:0)
您能否稍微解释一下为什么要使用LocatorLauncher
启动定位器?定位符仅用于成员发现,因此我认为这是一个有效的例外。
要开始使用,我只需使用gfsh
(从geode安装的/ bin目录中)来启动定位器,然后创建区域:
$ gfsh
gfsh> start locator
gfsh> start server
gfsh> create region --name=hello --type=REPLICATE
然后编写一个简单的客户端,以访问this wiki page中详细介绍的数据。