Exemplo n.º 1
0
  private void configureVariantStream() {

    ConfigurationVariantStream variantStream = new ConfigurationVariantStream();
    variantStream.setTypeVariance(
        ConfigurationVariantStream.TypeVariance
            .ANY); // allow any type of event to be inserted into the stream

    // add variant stream
    provider
        .getEPAdministrator()
        .getConfiguration()
        .addVariantStream("MyVariantStream", variantStream);

    // keep the last few events from the variant stream
    EPStatement stmt =
        provider.getEPAdministrator().createEPL("select * from MyVariantStream.win:time(1 min)");

    // insert MyEvent events into the variant stream
    provider.getEPAdministrator().createEPL("insert into MyVariantStream select * from MyEvent");

    // Add a second event type
    Map<String, Object> typeDefinition = new HashMap<String, Object>();
    typeDefinition.put("propertyOther", String.class);
    provider.getEPAdministrator().getConfiguration().addEventType("MyOtherEvent", typeDefinition);

    // insert MyOtherEvent events into the variant stream
    provider
        .getEPAdministrator()
        .createEPL("insert into MyVariantStream select * from MyOtherEvent");

    // send some events
    Map<String, Object> eventData = new HashMap<String, Object>();
    eventData.put("propertyOne", "value");
    eventData.put("propertyTwo", 10);
    provider.getEPRuntime().sendEvent(eventData, "MyEvent");

    eventData = new HashMap<String, Object>();
    eventData.put("propertyOther", "test");
    provider.getEPRuntime().sendEvent(eventData, "MyOtherEvent");

    // print results
    System.out.println("\nConfigure Variant Stream:");
    Iterator<EventBean> iterator = stmt.iterator();
    EventBean first = iterator.next();
    System.out.println(
        "Received (1):"
            + " propertyOne="
            + first.get("propertyOne")
            + " propertyOther="
            + first.get("propertyOther"));

    EventBean second = iterator.next();
    System.out.println(
        "Received (2):"
            + " propertyOne="
            + second.get("propertyOne")
            + " propertyOther="
            + second.get("propertyOther"));
  }
Exemplo n.º 2
0
  public void testAnyTypeStaggered() {
    // test insert into staggered with map
    ConfigurationVariantStream configVariantStream = new ConfigurationVariantStream();
    configVariantStream.setTypeVariance(ConfigurationVariantStream.TypeVariance.ANY);
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addVariantStream("VarStream", configVariantStream);
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("SupportBean", SupportBean.class);
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("SupportMarketDataBean", SupportMarketDataBean.class);

    epService
        .getEPAdministrator()
        .createEPL("insert into MyStream select theString, intPrimitive from SupportBean");
    epService
        .getEPAdministrator()
        .createEPL("insert into VarStream select theString as abc from MyStream");
    epService
        .getEPAdministrator()
        .createEPL("@Name('Target') select * from VarStream.win:keepall()");

    epService.getEPRuntime().sendEvent(new SupportBean("E1", 1));

    EventBean[] arr =
        EPAssertionUtil.iteratorToArray(
            epService.getEPAdministrator().getStatement("Target").iterator());
    EPAssertionUtil.assertPropsPerRow(arr, new String[] {"abc"}, new Object[][] {{"E1"}});

    epService
        .getEPAdministrator()
        .createEPL("insert into MyStream2 select feed from SupportMarketDataBean");
    epService
        .getEPAdministrator()
        .createEPL("insert into VarStream select feed as abc from MyStream2");

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("IBM", 1, 1L, "E2"));

    arr =
        EPAssertionUtil.iteratorToArray(
            epService.getEPAdministrator().getStatement("Target").iterator());
    EPAssertionUtil.assertPropsPerRow(arr, new String[] {"abc"}, new Object[][] {{"E1"}, {"E2"}});
  }
Exemplo n.º 3
0
  public void setUp() {
    Configuration config = SupportConfigFactory.getConfiguration();
    ConfigurationVariantStream variant = new ConfigurationVariantStream();
    variant.setTypeVariance(ConfigurationVariantStream.TypeVariance.ANY);
    config.addVariantStream("MyVariantStream", variant);
    assertTrue(config.isVariantStreamExists("MyVariantStream"));

    epService = EPServiceProviderManager.getDefaultProvider(config);
    epService.initialize();
    listener = new SupportUpdateListener();

    // assert type metadata
    EventTypeSPI type =
        (EventTypeSPI)
            ((EPServiceProviderSPI) epService)
                .getValueAddEventService()
                .getValueAddProcessor("MyVariantStream")
                .getValueAddEventType();
    assertEquals(null, type.getMetadata().getOptionalApplicationType());
    assertEquals(null, type.getMetadata().getOptionalSecondaryNames());
    assertEquals("MyVariantStream", type.getMetadata().getPrimaryName());
    assertEquals("MyVariantStream", type.getMetadata().getPublicName());
    assertEquals("MyVariantStream", type.getName());
    assertEquals(EventTypeMetadata.TypeClass.VARIANT, type.getMetadata().getTypeClass());
    assertEquals(true, type.getMetadata().isApplicationConfigured());
    assertEquals(true, type.getMetadata().isApplicationPreConfigured());
    assertEquals(true, type.getMetadata().isApplicationPreConfiguredStatic());

    EventType[] valueAddTypes =
        ((EPServiceProviderSPI) epService).getValueAddEventService().getValueAddedTypes();
    assertEquals(1, valueAddTypes.length);
    assertSame(type, valueAddTypes[0]);

    assertEquals(0, type.getPropertyNames().length);
    assertEquals(0, type.getPropertyDescriptors().length);
  }