本文整理汇总了Java中com.espertech.esper.client.context.ContextPartitionSelectorCategory类的典型用法代码示例。如果您正苦于以下问题:Java ContextPartitionSelectorCategory类的具体用法?Java ContextPartitionSelectorCategory怎么用?Java ContextPartitionSelectorCategory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContextPartitionSelectorCategory类属于com.espertech.esper.client.context包,在下文中一共展示了ContextPartitionSelectorCategory类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runAssertionContextNamedWindowQuery
import com.espertech.esper.client.context.ContextPartitionSelectorCategory; //导入依赖的package包/类
private void runAssertionContextNamedWindowQuery(EPServiceProvider epService) {
epService.getEPAdministrator().createEPL("create context PartitionedByString partition by theString from SupportBean");
epService.getEPAdministrator().createEPL("context PartitionedByString create window MyWindow#keepall as SupportBean");
epService.getEPAdministrator().createEPL("insert into MyWindow select * from SupportBean");
epService.getEPRuntime().sendEvent(new SupportBean("E1", 10));
epService.getEPRuntime().sendEvent(new SupportBean("E2", 20));
epService.getEPRuntime().sendEvent(new SupportBean("E2", 21));
// test no context
runQueryAll(epService, "select sum(intPrimitive) as c1 from MyWindow", "c1", new Object[][]{{51}}, 1);
runQueryAll(epService, "select sum(intPrimitive) as c1 from MyWindow where intPrimitive > 15", "c1", new Object[][]{{41}}, 1);
runQuery(epService, "select sum(intPrimitive) as c1 from MyWindow", "c1", new Object[][]{{41}}, new ContextPartitionSelector[]{new SupportSelectorPartitioned(Collections.singletonList(new Object[]{"E2"}))});
runQuery(epService, "select sum(intPrimitive) as c1 from MyWindow", "c1", new Object[][]{{41}}, new ContextPartitionSelector[]{new SupportSelectorById(Collections.<Integer>singleton(1))});
// test with context props
runQueryAll(epService, "context PartitionedByString select context.key1 as c0, intPrimitive as c1 from MyWindow",
"c0,c1", new Object[][]{{"E1", 10}, {"E2", 20}, {"E2", 21}}, 1);
runQueryAll(epService, "context PartitionedByString select context.key1 as c0, intPrimitive as c1 from MyWindow where intPrimitive > 15",
"c0,c1", new Object[][]{{"E2", 20}, {"E2", 21}}, 1);
// test targeted context partition
runQuery(epService, "context PartitionedByString select context.key1 as c0, intPrimitive as c1 from MyWindow where intPrimitive > 15",
"c0,c1", new Object[][]{{"E2", 20}, {"E2", 21}}, new SupportSelectorPartitioned[]{new SupportSelectorPartitioned(Collections.singletonList(new Object[]{"E2"}))});
try {
epService.getEPRuntime().executeQuery("context PartitionedByString select * from MyWindow", new ContextPartitionSelector[] {new ContextPartitionSelectorCategory() {
public Set<String> getLabels() {
return null;
}
} });
fail();
} catch (EPStatementException ex) {
assertTrue("message: " + ex.getMessage(), ex.getMessage().startsWith("Error executing statement: Invalid context partition selector, expected an implementation class of any of [ContextPartitionSelectorAll, ContextPartitionSelectorFiltered, ContextPartitionSelectorById, ContextPartitionSelectorSegmented] interfaces but received com"));
}
epService.getEPAdministrator().destroyAllStatements();
}
示例2: getSelectedContextPartitionPathIds
import com.espertech.esper.client.context.ContextPartitionSelectorCategory; //导入依赖的package包/类
public Collection<Integer> getSelectedContextPartitionPathIds(ContextPartitionSelector contextPartitionSelector) {
if (contextPartitionSelector instanceof ContextPartitionSelectorFiltered) {
ContextPartitionSelectorFiltered filter = (ContextPartitionSelectorFiltered) contextPartitionSelector;
ContextPartitionIdentifierCategory identifier = new ContextPartitionIdentifierCategory();
List<Integer> accepted = new ArrayList<Integer>();
for (Map.Entry<Integer, ContextControllerInstanceHandle> entry : handleCategories.entrySet()) {
identifier.setContextPartitionId(entry.getValue().getContextPartitionOrPathId());
identifier.setLabel(factory.getCategorySpec().getItems().get(entry.getKey()).getName());
if (filter.filter(identifier)) {
accepted.add(entry.getValue().getContextPartitionOrPathId());
}
}
return accepted;
}
if (contextPartitionSelector instanceof ContextPartitionSelectorCategory) {
ContextPartitionSelectorCategory category = (ContextPartitionSelectorCategory) contextPartitionSelector;
if (category.getLabels() == null || category.getLabels().isEmpty()) {
return Collections.emptyList();
}
List<Integer> items = new ArrayList<Integer>();
int count = 0;
for (ContextDetailCategoryItem item : factory.getCategorySpec().getItems()) {
if (category.getLabels().contains(item.getName())) {
ContextControllerInstanceHandle handle = handleCategories.get(count);
if (handle != null) {
items.add(handle.getContextPartitionOrPathId());
}
}
count++;
}
return items;
}
throw ContextControllerSelectorUtil.getInvalidSelector(new Class[] {ContextPartitionSelectorCategory.class}, contextPartitionSelector);
}
示例3: testContextNamedWindowQuery
import com.espertech.esper.client.context.ContextPartitionSelectorCategory; //导入依赖的package包/类
public void testContextNamedWindowQuery() {
epService.getEPAdministrator().createEPL("create context PartitionedByString partition by theString from SupportBean");
epService.getEPAdministrator().createEPL("context PartitionedByString create window MyWindow.win:keepall() as SupportBean");
epService.getEPAdministrator().createEPL("insert into MyWindow select * from SupportBean");
epService.getEPRuntime().sendEvent(new SupportBean("E1", 10));
epService.getEPRuntime().sendEvent(new SupportBean("E2", 20));
epService.getEPRuntime().sendEvent(new SupportBean("E2", 21));
// test no context
runQueryAll("select sum(intPrimitive) as c1 from MyWindow", "c1", new Object[][]{{51}}, 1);
runQueryAll("select sum(intPrimitive) as c1 from MyWindow where intPrimitive > 15", "c1", new Object[][]{{41}}, 1);
runQuery("select sum(intPrimitive) as c1 from MyWindow", "c1", new Object[][]{{41}}, new ContextPartitionSelector[] {new SupportSelectorPartitioned(Collections.singletonList(new Object[]{"E2"}))});
runQuery("select sum(intPrimitive) as c1 from MyWindow", "c1", new Object[][]{{41}}, new ContextPartitionSelector[] {new SupportSelectorById(Collections.<Integer>singleton(1))});
// test with context props
runQueryAll("context PartitionedByString select context.key1 as c0, intPrimitive as c1 from MyWindow",
"c0,c1", new Object[][]{{"E1", 10}, {"E2", 20}, {"E2", 21}}, 1);
runQueryAll("context PartitionedByString select context.key1 as c0, intPrimitive as c1 from MyWindow where intPrimitive > 15",
"c0,c1", new Object[][]{{"E2", 20}, {"E2", 21}}, 1);
// test targeted context partition
runQuery("context PartitionedByString select context.key1 as c0, intPrimitive as c1 from MyWindow where intPrimitive > 15",
"c0,c1", new Object[][]{{"E2", 20}, {"E2", 21}}, new SupportSelectorPartitioned[]{new SupportSelectorPartitioned(Collections.singletonList(new Object[]{"E2"}))});
try {
epService.getEPRuntime().executeQuery("context PartitionedByString select * from MyWindow", new ContextPartitionSelector[] {new ContextPartitionSelectorCategory() {
public Set<String> getLabels() {
return null;
}
}});
fail();
}
catch (EPStatementException ex) {
assertTrue("message: " + ex.getMessage(), ex.getMessage().startsWith("Error executing statement: Invalid context partition selector, expected an implementation class of any of [ContextPartitionSelectorAll, ContextPartitionSelectorFiltered, ContextPartitionSelectorById, ContextPartitionSelectorSegmented] interfaces but received com"));
}
}