org.osgi.service.event.EventAdmin Java Examples

The following examples show how to use org.osgi.service.event.EventAdmin. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SendUserAdminEventJob.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void run()
{
  EventAdmin ea = (EventAdmin) eventAdminTracker.getService();
  if (null!=ea) {
    ea.postEvent( getEvent() );
  }

  for (Enumeration en = listeners.elements(); en.hasMoreElements();) {
    ServiceReference sr = (ServiceReference) en.nextElement();
    UserAdminListener ual = (UserAdminListener) bc.getService(sr);
    if (ual != null) {
      try {
        ual.roleChanged(event);
      } catch (Throwable t) {
        Activator.log.error("[UserAdmin] Error while sending roleChanged event to"+sr,
                  t);
      }
    }
    bc.ungetService(sr);
  }
}
 
Example #2
Source File: ChannelImpl.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
public ChannelImpl ( final String storageId, final EventAdmin eventAdmin, final StorageManager manager, final ChannelProviderImpl provider, final Map<MetaKey, String> configuration )
{
    this.storageId = storageId;
    this.manager = manager;
    this.provider = provider;

    this.storageKey = new MetaKey ( "channel", storageId );

    String dir = configuration.get ( KEY_APM_DIR_OVERRIDE );
    if ( dir == null )
    {
        dir = storageId;
    }

    this.handle = manager.registerModel ( 10_000, this.storageKey, new ChannelModelProvider ( storageId, dir ) );
}
 
Example #3
Source File: Scenario14TestSuite.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public EventPublisher(BundleContext context,String topic,String name,int id){
  /* call super class */
  super(name + ":" + id);
  /* assign bundleContext */
  bundleContext = context;
  /* assign the topic to publish */
  topicToPublish = topic;
  /* assign the publisherID */
  publisherId = id;

  /* Claims the reference of the EventAdmin Service */
  serviceReference = bundleContext
    .getServiceReference(EventAdmin.class.getName());


  /* get the service  */
  eventAdmin = (EventAdmin) bundleContext
    .getService(serviceReference);


}
 
Example #4
Source File: OSGiEventPublisher.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private void postAsOSGiEvent(final EventAdmin eventAdmin, final Event event) throws IllegalStateException {
    try {
        AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
            @Override
            public Void run() throws Exception {
                Dictionary<String, Object> properties = new Hashtable<String, Object>(3);
                properties.put("type", event.getType());
                properties.put("payload", event.getPayload());
                properties.put("topic", event.getTopic());
                if (event.getSource() != null) {
                    properties.put("source", event.getSource());
                }
                eventAdmin.postEvent(new org.osgi.service.event.Event("smarthome", properties));
                return null;
            }
        });
    } catch (PrivilegedActionException pae) {
        Exception e = pae.getException();
        throw new IllegalStateException("Cannot post the event via the event bus. Error message: " + e.getMessage(),
                e);
    }
}
 
Example #5
Source File: FileAppenderTest.java    From karaf-decanter with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
    // install decanter
    System.out.println(executeCommand("feature:repo-add decanter " + System.getProperty("decanter.version")));
    System.out.println(executeCommand("feature:install decanter-appender-file", new RolePrincipal("admin")));

    // send event
    EventAdmin eventAdmin = getOsgiService(EventAdmin.class);
    HashMap<String, String> data = new HashMap<>();
    data.put("foo", "bar");
    Event event = new Event("decanter/collect/test", data);
    eventAdmin.sendEvent(event);

    // read file
    File file = new File(System.getProperty("karaf.data"), "decanter");
    StringBuilder builder = new StringBuilder();
    try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
        builder.append(reader.readLine()).append("\n");
    }

    Assert.assertTrue(builder.toString().contains("foo=bar"));
}
 
Example #6
Source File: OSGiEventPublisher.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
private void postAsOSGiEvent(final EventAdmin eventAdmin, final Event event) throws IllegalStateException {
    try {
        AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
            @Override
            public Void run() throws Exception {
                Dictionary<String, Object> properties = new Hashtable<>(3);
                properties.put("type", event.getType());
                properties.put("payload", event.getPayload());
                properties.put("topic", event.getTopic());
                if (event.getSource() != null) {
                    properties.put("source", event.getSource());
                }
                eventAdmin.postEvent(new org.osgi.service.event.Event("smarthome", properties));
                return null;
            }
        });
    } catch (PrivilegedActionException pae) {
        Exception e = pae.getException();
        throw new IllegalStateException("Cannot post the event via the event bus. Error message: " + e.getMessage(),
                e);
    }
}
 
Example #7
Source File: LogAppenderTest.java    From karaf-decanter with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
    // install decanter
    System.out.println(executeCommand("feature:repo-add decanter " + System.getProperty("decanter.version")));
    System.out.println(executeCommand("feature:install decanter-appender-log", new RolePrincipal("admin")));

    // send event synchronously for test
    EventAdmin eventAdmin = getOsgiService(EventAdmin.class);
    HashMap<String, String> data = new HashMap<>();
    data.put("foo", "bar");
    Event event = new Event("decanter/collect/test", data);
    eventAdmin.sendEvent(event);

    // get log
    String log = executeCommand("log:display");

    Assert.assertTrue(log.contains("foo=bar"));
    Assert.assertTrue(log.contains("decanter/collect/test"));
}
 
Example #8
Source File: FuntionalTestSuite.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void runTest() throws Throwable {
  /* Claims the reference of the EventAdmin Service */
  serviceReference = bundleContext
    .getServiceReference(EventAdmin.class.getName());

  /* assert that a reference is aquired */
  assertNotNull(getName()
                + " Should be able to get reference to EventAdmin service",
                serviceReference);
  /* check the service reference */
  if (serviceReference == null) {
    /* set fail */
    fail(getName() + " service reference should not be null");
  }

  /* get the service  */
  eventAdmin = (EventAdmin) bundleContext
    .getService(serviceReference);

  /* assert that service is available */
  assertNotNull(getName() +" Should be able to get instance to "
                +"EventAdmin object",
                eventAdmin);

  /* check if null */
  if (eventAdmin == null) {
    /* set a fail */
    fail(getName() + " event admin should not be null");
  }


  publish();


}
 
Example #9
Source File: OSGiEventDistributorTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
@Test
public void notifyExecution() throws Exception {
  String processDefinitionId = "123";
  String currActivityId = "Act1234";
  String processInstanceId = "Inst1234";
  String executionId = "Exe4711";
  String transitionId = "Trans1";
  DelegateExecution execution = mock(DelegateExecution.class);
  when(execution.getCurrentActivityId()).thenReturn(currActivityId);
  when(execution.getCurrentTransitionId()).thenReturn(transitionId);
  when(execution.getProcessDefinitionId()).thenReturn(processDefinitionId);
  when(execution.getProcessInstanceId()).thenReturn(processInstanceId);
  when(execution.getId()).thenReturn(executionId);
  when(execution.getEventName()).thenReturn(ExecutionListener.EVENTNAME_START);
  EventAdmin eventAdminMock = mock(EventAdmin.class);
  ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
  OSGiEventDistributor distributor = new OSGiEventDistributor(eventAdminMock);
  distributor.notify(execution);

  verify(eventAdminMock).postEvent(eventCaptor.capture());
  Event event = eventCaptor.getValue();
  assertThat(event.getTopic(), is(Topics.EXECUTION_EVENT_TOPIC));
  assertThat((String) event.getProperty(BusinessProcessEventProperties.ACTIVITY_ID), is(currActivityId));
  assertThat((String) event.getProperty(BusinessProcessEventProperties.EXECUTION_ID), is(executionId));
  assertThat((String) event.getProperty(BusinessProcessEventProperties.PROCESS_DEFINITION), is(processDefinitionId));
  assertThat((String) event.getProperty(BusinessProcessEventProperties.PROCESS_INSTANCE_ID), is(processInstanceId));
  assertThat((String) event.getProperty(BusinessProcessEventProperties.TASK_DEFINITION_KEY), is(nullValue()));
  assertThat((String) event.getProperty(BusinessProcessEventProperties.TASK_ID), is(nullValue()));
  String timestamp = (String) event.getProperty(BusinessProcessEventProperties.TIMESTAMP);
  assertThat(new Date(Long.parseLong(timestamp)), is(beforeOrEqual(new Date())));
  assertThat((String) event.getProperty(BusinessProcessEventProperties.TRANSITION_ID), is(transitionId));
  assertThat((String) event.getProperty(BusinessProcessEventProperties.TYPE), is(ExecutionListener.EVENTNAME_START));
}
 
Example #10
Source File: MongodbAppenderTest.java    From karaf-decanter with Apache License 2.0 5 votes vote down vote up
/**
 * Require a running MongoDB instance.
 */
@Test
public void test() throws Exception {
    System.out.println("Download and start MongoDB with:");
    System.out.println("\tbin/mongod");
    System.out.println("Create a database in MongoDB with:");
    System.out.println("\tbin/mongo");
    System.out.println("\t> use decanter");
    System.out.println("");
    System.out.println("Installing Decanter");
    System.out.println(executeCommand("feature:repo-add decanter " + System.getProperty("decanter.version")));
    System.out.println(executeCommand("feature:install decanter-common", new RolePrincipal("admin")));
    System.out.println(executeCommand("feature:install decanter-appender-mongodb", new RolePrincipal("admin")));

    System.out.println("Sending Decanter event");
    EventAdmin eventAdmin = getOsgiService(EventAdmin.class);
    HashMap<String, Object> data = new HashMap<>();
    data.put("foo", "bar");
    Event event = new Event("decanter/collect/test", data);
    eventAdmin.sendEvent(event);

    System.out.println("Check data in MongoDB with:");
    System.out.println("\tmongo");
    System.out.println("\t> use decanter");
    System.out.println("\t> db.decanter.find()");

    System.out.println("*********************************");
    System.out.println("* Latest Tested Version: 4.2.1  *");
    System.out.println("*********************************");
}
 
Example #11
Source File: UserAdminImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
UserAdminImpl() {
    revert(); // Read saved roles
    if (roles == null) {
      zap(); // Create "empty" roles table
    }
    listeners = new Vector();

    eventAdminTracker
      = new ServiceTracker(Activator.bc, EventAdmin.class.getName(), null );
    eventQueue = new EventQueue();
}
 
Example #12
Source File: OSGiEventPublisher.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void post(final Event event) throws IllegalArgumentException, IllegalStateException {
    EventAdmin eventAdmin = this.osgiEventAdmin;
    assertValidArgument(event);
    assertValidState(eventAdmin);
    postAsOSGiEvent(eventAdmin, event);
}
 
Example #13
Source File: OSGiEventDistributorTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
@Test
public void notifyTask() {
  String processDefinitionId = "123";
  String currActivityId = "Act1234";
  String processInstanceId = "Inst1234";
  String executionId = "Exe4711";
  String taskId = "Task42";
  String taskDefinitionKey = "TaskDef";
  String transitionId = "Trans1";
  DelegateTask task = mock(DelegateTask.class);
  when(task.getProcessDefinitionId()).thenReturn(processDefinitionId);
  when(task.getProcessInstanceId()).thenReturn(processInstanceId);
  when(task.getExecutionId()).thenReturn(executionId);
  when(task.getId()).thenReturn(taskId);
  when(task.getTaskDefinitionKey()).thenReturn(taskDefinitionKey);
  when(task.getEventName()).thenReturn(TaskListener.EVENTNAME_CREATE);
  DelegateExecution execution = mock(DelegateExecution.class);
  when(execution.getCurrentActivityId()).thenReturn(currActivityId);
  when(execution.getCurrentTransitionId()).thenReturn(transitionId);
  when(task.getExecution()).thenReturn(execution);
  EventAdmin eventAdminMock = mock(EventAdmin.class);
  ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
  OSGiEventDistributor distributor = new OSGiEventDistributor(eventAdminMock);
  distributor.notify(task);

  verify(eventAdminMock).postEvent(eventCaptor.capture());
  Event event = eventCaptor.getValue();
  assertThat(event.getTopic(), is(Topics.TASK_EVENT_TOPIC));
  assertThat((String) event.getProperty(BusinessProcessEventProperties.ACTIVITY_ID), is(currActivityId));
  assertThat((String) event.getProperty(BusinessProcessEventProperties.EXECUTION_ID), is(executionId));
  assertThat((String) event.getProperty(BusinessProcessEventProperties.PROCESS_DEFINITION), is(processDefinitionId));
  assertThat((String) event.getProperty(BusinessProcessEventProperties.PROCESS_INSTANCE_ID), is(processInstanceId));
  assertThat((String) event.getProperty(BusinessProcessEventProperties.TASK_DEFINITION_KEY), is(taskDefinitionKey));
  assertThat((String) event.getProperty(BusinessProcessEventProperties.TASK_ID), is(taskId));
  String timestamp = (String) event.getProperty(BusinessProcessEventProperties.TIMESTAMP);
  assertThat(new Date(Long.parseLong(timestamp)), is(beforeOrEqual(new Date())));
  assertThat((String) event.getProperty(BusinessProcessEventProperties.TRANSITION_ID), is(transitionId));
  assertThat((String) event.getProperty(BusinessProcessEventProperties.TYPE), is(TaskListener.EVENTNAME_CREATE));
}
 
Example #14
Source File: EventAdminActivator.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 
 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
 */
public void start(BundleContext context) throws Exception {
	EventAdminActivator.context = context;
	eventAdmin = new EventAdminImpl();
	context.addBundleListener(eventAdmin);
	context.addServiceListener(eventAdmin);
	context.addFrameworkListener(eventAdmin);
	context.registerService(EventAdmin.class.getName(), eventAdmin, null);
}
 
Example #15
Source File: Scenario6TestSuite.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public EventPublisher(BundleContext context, String name, int id,
                      String topic) {
  /* assign bundleContext */
  bundleContext = context;
  /* assign topic */
  topicToSend = topic;

  /* Claims the reference of the EventAdmin Service */
  serviceReference = bundleContext
    .getServiceReference(EventAdmin.class.getName());

  /* get the service */
  eventAdmin = (EventAdmin) bundleContext
    .getService(serviceReference);
}
 
Example #16
Source File: EventDistributorHandlerTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
@Test
public void invokeWithoutEventAdmin() throws Throwable {
  BundleContext bundleContext = createBundleContext();
  registerEventBridgeActivator(bundleContext);
  @SuppressWarnings("unchecked")
  ServiceReference<EventAdmin> refMock = mock(ServiceReference.class);
  when(bundleContext.getServiceReference(eq(EventAdmin.class))).thenReturn(refMock);
  when(bundleContext.getService(eq(refMock))).thenReturn(null);

  Object invoke = new EventDistributorHandler(bundleContext).invoke(new Object(), OSGiEventDistributor.class.getMethod("notify", DelegateExecution.class),
      null);
  assertThat(invoke, is(nullValue()));
}
 
Example #17
Source File: ChannelInstance.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public ChannelInstance ( final String channelId, final String providerId, final Map<MetaKey, String> configuration, final ChannelProviderTracker providerTracker, final ChannelAspectProcessor aspectProcessor, final EventAdmin eventAdmin, final StorageManager storage, final ProcessorFactoryTracker processorFactoryTracker, final ConfiguredTriggerFactoryTracker triggerFactory )
{
    this.channelId = channelId;
    this.providerId = providerId;
    this.configuration = configuration;

    this.providerTracker = providerTracker;

    this.aspectProcessor = aspectProcessor;
    this.eventAdmin = eventAdmin;
    this.storage = storage;
    this.processorFactoryTracker = processorFactoryTracker;

    final ReadWriteLock lock = new ReentrantReadWriteLock ( false );
    this.readLock = lock.readLock ();
    this.writeLock = lock.writeLock ();

    final MetaKey channelKey = new MetaKey ( "channelInstance", channelId );
    this.handle = this.storage.registerModel ( 15_000, channelKey, new ChannelInstanceModelProvider ( channelId ) );

    try
    {
        addFeature ( this.triggered = new TriggeredChannelFeature ( channelId, storage, channelKey, processorFactoryTracker, triggerFactory, makePredefinedTriggers () ) );

        this.providerTracker.addListener ( this.providerId, this );
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to create channel instance: " + channelId, e );
        this.handle.unregister ();
        throw e;
    }
}
 
Example #18
Source File: EventDistributorHandlerTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
private EventAdmin registerEventAdmin(BundleContext bundleContext) {
  @SuppressWarnings("unchecked")
  ServiceReference<EventAdmin> refMock = mock(ServiceReference.class);
  when(bundleContext.getServiceReference(eq(EventAdmin.class))).thenReturn(refMock);
  EventAdmin eventAdmin = mock(EventAdmin.class);
  when(bundleContext.getService(eq(refMock))).thenReturn(eventAdmin);
  return eventAdmin;
}
 
Example #19
Source File: EventDistributorHandlerTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
@Test
public void invokeWithoutEventAdminRef() throws Throwable {
  BundleContext bundleContext = createBundleContext();
  registerEventBridgeActivator(bundleContext);
  when(bundleContext.getServiceReference(eq(EventAdmin.class))).thenReturn(null);

  Object invoke = new EventDistributorHandler(bundleContext).invoke(new Object(), OSGiEventDistributor.class.getMethod("notify", DelegateExecution.class),
      null);
  assertThat(invoke, is(nullValue()));
}
 
Example #20
Source File: EventDistributorHandler.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
  if (isObjectMethod(method)) {
    return handleObjectMethod(proxy, method, args);
  }
  if (isEventBridgeActivatorPresent(systemBundle.getBundleContext())) {
    EventAdmin eventAdmin = findEventAdmin(systemBundle.getBundleContext());
    if (eventAdmin != null) {
      OSGiEventDistributor distributor = new OSGiEventDistributor(eventAdmin);
      return method.invoke(distributor, args);
    }
  }
  return null;
}
 
Example #21
Source File: OSGiEventPublisher.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void post(final Event event) throws IllegalArgumentException, IllegalStateException {
    EventAdmin eventAdmin = this.osgiEventAdmin;
    assertValidArgument(event);
    assertValidState(eventAdmin);
    postAsOSGiEvent(eventAdmin, event);
}
 
Example #22
Source File: ElasticsearchAppenderTest.java    From karaf-decanter with Apache License 2.0 5 votes vote down vote up
/**
 * Require a running Elasticsearch instance.
 */
@Test
public void test() throws Exception {
    System.out.println("Please first download and start Elasticsearch instance with:");
    System.out.println("\tbin/elasticsearch");

    // install decanter
    System.out.println(executeCommand("feature:repo-add decanter " + System.getProperty("decanter.version")));
    System.out.println(executeCommand("feature:install decanter-appender-elasticsearch", new RolePrincipal("admin")));

    // send event
    EventAdmin eventAdmin = getOsgiService(EventAdmin.class);
    HashMap<String, String> data = new HashMap<>();
    data.put("foo", "bar");
    Event event = new Event("decanter/collect/test", data);
    eventAdmin.sendEvent(event);

    // check in Cassandra
    System.out.println("Please check in karaf index in Elasticsearch with:");
    System.out.println("\t curl http://localhost:9200/_cat/indices");
    System.out.println("\t curl http://localhost:9200/karaf-yyyy.mm.dd");
    System.out.println("");


    System.out.println("********************************");
    System.out.println("* Latest Tested Version: 7.5.0 *");
    System.out.println("********************************");
}
 
Example #23
Source File: KafkaAppenderTest.java    From karaf-decanter with Apache License 2.0 5 votes vote down vote up
/**
 * Require running Kafka broker.
 */
@Test
public void test() throws Exception {
    System.out.println("Please, first download and start Kafka:");
    System.out.println("\tbin/zookeeper-server-start.sh ../config/zookeeper.properties");
    System.out.println("\tbin/kafka-server-start.sh ../config/server.properties");
    System.out.println("Create decanter topic:");
    System.out.println("\tbin/kafka-topics.sh --create --partitions 1 --replication-factor 1 --zookeeper localhost:2181 --topic decanter");

    // install decanter
    addFeaturesRepository("mvn:org.apache.karaf.decanter/apache-karaf-decanter/" + System.getProperty("decanter.version") + "/xml/features");
    installAndAssertFeature("decanter-common");
    installAndAssertFeature("decanter-appender-kafka");

    // send event
    EventAdmin eventAdmin = getOsgiService(EventAdmin.class);
    HashMap<String, String> data = new HashMap<>();
    data.put("foo", "bar");
    Event event = new Event("decanter/collect/test", data);
    eventAdmin.sendEvent(event);

    System.out.println("Check message in Kafka using:");
    System.out.println("\tbin/kafka-console-consumer.sh ");

    System.out.println("*********************************");
    System.out.println("* Latest Tested Version: 2.1.0  *");
    System.out.println("*********************************");
}
 
Example #24
Source File: JmsAppenderTest.java    From karaf-decanter with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    // install jms
    System.out.println(executeCommand("feature:install jms", new RolePrincipal("admin")));
    System.out.println(executeCommand("feature:install pax-jms-activemq", new RolePrincipal("admin")));

    // create connection factory
    System.out.println(executeCommand("jms:create decanter"));

    Thread.sleep(2000);

    System.out.println(executeCommand("jms:connectionfactories"));
    System.out.println(executeCommand("jms:info jms/decanter"));

    // install decanter
    System.out.println(executeCommand("feature:repo-add decanter " + System.getProperty("decanter.version")));
    System.out.println(executeCommand("feature:install decanter-appender-jms", new RolePrincipal("admin")));

    // send event
    EventAdmin eventAdmin = getOsgiService(EventAdmin.class);
    HashMap<String, String> data = new HashMap<>();
    data.put("foo", "bar");
    Event event = new Event("decanter/collect/test", data);
    eventAdmin.sendEvent(event);

    // browse
    String browse = executeCommand("jms:browse jms/decanter decanter");

    System.out.println(browse);

    Assert.assertTrue(browse.contains("\"foo\":\"bar\""));
}
 
Example #25
Source File: WebsocketAppenderTest.java    From karaf-decanter with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    // install decanter
    System.out.println(executeCommand("feature:repo-add decanter " + System.getProperty("decanter.version")));
    System.out.println(executeCommand("feature:install decanter-appender-websocket-servlet", new RolePrincipal("admin")));

    String httpList = executeCommand("http:list");
    while (!httpList.contains("Deployed")) {
        Thread.sleep(500);
        httpList = executeCommand("http:list");
    }
    System.out.println(httpList);

    // websocket
    WebSocketClient client = new WebSocketClient();
    DecanterSocket decanterSocket = new DecanterSocket();
    client.start();
    URI uri = new URI("ws://localhost:" + getHttpPort() + "/decanter-websocket");
    ClientUpgradeRequest request = new ClientUpgradeRequest();
    client.connect(decanterSocket, uri, request).get();

    // sending event
    EventAdmin eventAdmin = getOsgiService(EventAdmin.class);
    HashMap<String, String> data = new HashMap<>();
    data.put("foo", "bar");
    Event event = new Event("decanter/collect/test", data);
    eventAdmin.sendEvent(event);

    decanterSocket.awaitClose(20, TimeUnit.SECONDS);

    Assert.assertEquals(1, decanterSocket.messages.size());

    Assert.assertTrue(decanterSocket.messages.get(0).contains("\"foo\":\"bar\""));
    Assert.assertTrue(decanterSocket.messages.get(0).contains("\"event_topics\":\"decanter/collect/test\""));

    client.stop();
}
 
Example #26
Source File: InfluxdbAppenderTest.java    From karaf-decanter with Apache License 2.0 5 votes vote down vote up
/**
 * Require a running InfluxDB instance.
 */
@Test
public void test() throws Exception {
    System.out.println("Please first download and start InfluxDB instance with:");
    System.out.println("\tusr/bin/influxd");
    System.out.println("Create the database and default replication policy:");
    System.out.println("\tusr/bin/influx");
    System.out.println("\t> create database decanter");
    System.out.println("\t> use decanter");
    System.out.println("\t> create retention policy \"defaultPolicy\" on \"decanter\" duration 1d replication 1 default");

    // install decanter
    System.out.println(executeCommand("feature:repo-add decanter " + System.getProperty("decanter.version")));
    System.out.println(executeCommand("feature:install decanter-appender-influxdb", new RolePrincipal("admin")));

    // send event
    EventAdmin eventAdmin = getOsgiService(EventAdmin.class);
    HashMap<String, String> data = new HashMap<>();
    data.put("foo", "bar");
    Event event = new Event("decanter/collect/test", data);
    eventAdmin.sendEvent(event);

    // check in InfluxDB
    System.out.println("Please check InfluxDB content with:");
    System.out.println("\tusr/bin/influx");
    System.out.println("\t> select * from decanter");


    System.out.println("**********************************");
    System.out.println("* Latest Tested Version: 1.7.9-1 *");
    System.out.println("**********************************");
}
 
Example #27
Source File: CassandraAppenderTest.java    From karaf-decanter with Apache License 2.0 5 votes vote down vote up
/**
 * Require a running Cassandra instance.
 */
@Test
public void test() throws Exception {
    System.out.println("Please, first download and run Cassandra");
    System.out.println("\t* Start cassandra with bin/cassandra -f");
    System.out.println("\t* Connect using bin/cqlsh and do:");
    System.out.println("\t    cqlsh> CREATE KEYSPACE IF NOT EXISTS decanter WITH REPLICATION = { 'class': 'SimpleStrategy', 'replication_factor': 1 };");
    System.out.println("");

    // install decanter
    System.out.println(executeCommand("feature:repo-add decanter " + System.getProperty("decanter.version")));
    System.out.println(executeCommand("feature:install decanter-appender-cassandra", new RolePrincipal("admin")));

    // send event
    EventAdmin eventAdmin = getOsgiService(EventAdmin.class);
    HashMap<String, String> data = new HashMap<>();
    data.put("foo", "bar");
    Event event = new Event("decanter/collect/test", data);
    eventAdmin.sendEvent(event);

    // check in Cassandra
    System.out.println("Please check in decanter table in Cassandra with bin/cqlsh:");
    System.out.println("\t cqlsh> SELECT * FROM decanter.decanter");
    System.out.println("");

    System.out.println("*********************************");
    System.out.println("* Latest Tested Version: 3.11.5 *");
    System.out.println("*********************************");
}
 
Example #28
Source File: JdbcAppenderTest.java    From karaf-decanter with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    // install database
    System.out.println(executeCommand("feature:install jdbc", new RolePrincipal("admin")));
    System.out.println(executeCommand("feature:install pax-jdbc-derby", new RolePrincipal("admin")));

    System.out.println(executeCommand("jdbc:ds-list"));

    // install decanter
    System.out.println(executeCommand("feature:repo-add decanter " + System.getProperty("decanter.version")));
    System.out.println(executeCommand("feature:install decanter-appender-jdbc", new RolePrincipal("admin")));

    // send event
    EventAdmin eventAdmin = getOsgiService(EventAdmin.class);
    HashMap<String, String> data = new HashMap<>();
    data.put("foo", "bar");
    Event event = new Event("decanter/collect/test", data);
    eventAdmin.sendEvent(event);

    // check database content
    DataSource dataSource = getOsgiService(DataSource.class);
    try (Connection connection = dataSource.getConnection()) {
        try (Statement statement = connection.createStatement()) {
            try (ResultSet resultSet = statement.executeQuery("select * from decanter")) {
                resultSet.next();
                String json = resultSet.getString(2);
                Assert.assertTrue(json.contains("\"foo\":\"bar\""));
                Assert.assertTrue(json.contains("\"event_topics\":\"decanter/collect/test\""));
            }
        }
    }
}
 
Example #29
Source File: EventDistributorHandler.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
private EventAdmin findEventAdmin(BundleContext ctx) {
  ServiceReference<EventAdmin> ref = ctx.getServiceReference(EventAdmin.class);
  EventAdmin eventAdmin = null;
  if (ref != null) {
    eventAdmin = ctx.getService(ref);
  }
  return eventAdmin;
}
 
Example #30
Source File: VltRepositoryFactoryWrapper.java    From aem-ide-tooling-4-intellij with Apache License 2.0 4 votes vote down vote up
public VltRepositoryFactoryWrapper() {
    EventAdmin eventAdmin = ServiceManager.getService(EventAdmin.class);
    bindEventAdmin(eventAdmin);
}