Author: ldywicki Date: Wed Dec 14 22:38:44 2011 New Revision: 1214515 URL: http://svn.apache.org/viewvc?rev=1214515&view=rev Log: Added demo for events producer/consumer to let preview topics in webconsole
Signed-off-by: Lukasz Dywicki <l...@code-house.org> Added: karaf/webconsole/trunk/examples/events/ karaf/webconsole/trunk/examples/events/consumer/ karaf/webconsole/trunk/examples/events/consumer/pom.xml - copied, changed from r1214513, karaf/webconsole/trunk/examples/pom.xml karaf/webconsole/trunk/examples/events/consumer/src/ karaf/webconsole/trunk/examples/events/consumer/src/main/ karaf/webconsole/trunk/examples/events/consumer/src/main/java/ karaf/webconsole/trunk/examples/events/consumer/src/main/java/org/ karaf/webconsole/trunk/examples/events/consumer/src/main/java/org/apache/ karaf/webconsole/trunk/examples/events/consumer/src/main/java/org/apache/karaf/ karaf/webconsole/trunk/examples/events/consumer/src/main/java/org/apache/karaf/webconsole/ karaf/webconsole/trunk/examples/events/consumer/src/main/java/org/apache/karaf/webconsole/examples/ karaf/webconsole/trunk/examples/events/consumer/src/main/java/org/apache/karaf/webconsole/examples/events/ karaf/webconsole/trunk/examples/events/consumer/src/main/java/org/apache/karaf/webconsole/examples/events/consumer/ karaf/webconsole/trunk/examples/events/consumer/src/main/java/org/apache/karaf/webconsole/examples/events/consumer/DemoConsumer.java karaf/webconsole/trunk/examples/events/consumer/src/main/resources/ karaf/webconsole/trunk/examples/events/consumer/src/main/resources/OSGI-INF/ karaf/webconsole/trunk/examples/events/consumer/src/main/resources/OSGI-INF/blueprint/ karaf/webconsole/trunk/examples/events/consumer/src/main/resources/OSGI-INF/blueprint/event-consumer.xml karaf/webconsole/trunk/examples/events/pom.xml - copied, changed from r1214513, karaf/webconsole/trunk/examples/pom.xml karaf/webconsole/trunk/examples/events/provider/ karaf/webconsole/trunk/examples/events/provider/pom.xml karaf/webconsole/trunk/examples/events/provider/src/ karaf/webconsole/trunk/examples/events/provider/src/main/ karaf/webconsole/trunk/examples/events/provider/src/main/java/ karaf/webconsole/trunk/examples/events/provider/src/main/java/org/ karaf/webconsole/trunk/examples/events/provider/src/main/java/org/apache/ karaf/webconsole/trunk/examples/events/provider/src/main/java/org/apache/karaf/ karaf/webconsole/trunk/examples/events/provider/src/main/java/org/apache/karaf/webconsole/ karaf/webconsole/trunk/examples/events/provider/src/main/java/org/apache/karaf/webconsole/examples/ karaf/webconsole/trunk/examples/events/provider/src/main/java/org/apache/karaf/webconsole/examples/events/ karaf/webconsole/trunk/examples/events/provider/src/main/java/org/apache/karaf/webconsole/examples/events/provider/ karaf/webconsole/trunk/examples/events/provider/src/main/java/org/apache/karaf/webconsole/examples/events/provider/DemoProducer.java karaf/webconsole/trunk/examples/events/provider/src/main/resources/ karaf/webconsole/trunk/examples/events/provider/src/main/resources/OSGI-INF/ karaf/webconsole/trunk/examples/events/provider/src/main/resources/OSGI-INF/blueprint/ karaf/webconsole/trunk/examples/events/provider/src/main/resources/OSGI-INF/blueprint/event-provider.xml - copied, changed from r1214513, karaf/webconsole/trunk/examples/pom.xml Modified: karaf/webconsole/trunk/examples/pom.xml Copied: karaf/webconsole/trunk/examples/events/consumer/pom.xml (from r1214513, karaf/webconsole/trunk/examples/pom.xml) URL: http://svn.apache.org/viewvc/karaf/webconsole/trunk/examples/events/consumer/pom.xml?p2=karaf/webconsole/trunk/examples/events/consumer/pom.xml&p1=karaf/webconsole/trunk/examples/pom.xml&r1=1214513&r2=1214515&rev=1214515&view=diff ============================================================================== --- karaf/webconsole/trunk/examples/pom.xml (original) +++ karaf/webconsole/trunk/examples/events/consumer/pom.xml Wed Dec 14 22:38:44 2011 @@ -20,18 +20,39 @@ <modelVersion>4.0.0</modelVersion> <parent> - <groupId>org.apache.karaf</groupId> - <artifactId>webconsole</artifactId> + <groupId>org.apache.karaf.webconsole.examples</groupId> + <artifactId>events</artifactId> <version>0.3.0-SNAPSHOT</version> </parent> - <groupId>org.apache.karaf.webconsole</groupId> - <artifactId>examples</artifactId> - <name>Apache Karaf :: WebConsole :: Examples</name> - <packaging>pom</packaging> + <groupId>org.apache.karaf.webconsole.examples.events</groupId> + <artifactId>consumer</artifactId> + <name>Apache Karaf :: WebConsole :: Examples :: Events :: Consumer</name> + <packaging>bundle</packaging> - <modules> - <module>branding</module> - </modules> + <dependencies> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <version>2.3.5</version> + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> + <Import-Package> + * + </Import-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> </project> Added: karaf/webconsole/trunk/examples/events/consumer/src/main/java/org/apache/karaf/webconsole/examples/events/consumer/DemoConsumer.java URL: http://svn.apache.org/viewvc/karaf/webconsole/trunk/examples/events/consumer/src/main/java/org/apache/karaf/webconsole/examples/events/consumer/DemoConsumer.java?rev=1214515&view=auto ============================================================================== --- karaf/webconsole/trunk/examples/events/consumer/src/main/java/org/apache/karaf/webconsole/examples/events/consumer/DemoConsumer.java (added) +++ karaf/webconsole/trunk/examples/events/consumer/src/main/java/org/apache/karaf/webconsole/examples/events/consumer/DemoConsumer.java Wed Dec 14 22:38:44 2011 @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.karaf.webconsole.examples.events.consumer; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.osgi.service.event.Event; +import org.osgi.service.event.EventHandler; + +/** + * Example brand provider which modify console look and feel. + */ +public class DemoConsumer implements EventHandler { + + private Logger logger = Logger.getLogger(DemoConsumer.class.getName()); + + public void handleEvent(Event event) { + logger.log(Level.FINE, "Received event " + event); + } + +} \ No newline at end of file Added: karaf/webconsole/trunk/examples/events/consumer/src/main/resources/OSGI-INF/blueprint/event-consumer.xml URL: http://svn.apache.org/viewvc/karaf/webconsole/trunk/examples/events/consumer/src/main/resources/OSGI-INF/blueprint/event-consumer.xml?rev=1214515&view=auto ============================================================================== --- karaf/webconsole/trunk/examples/events/consumer/src/main/resources/OSGI-INF/blueprint/event-consumer.xml (added) +++ karaf/webconsole/trunk/examples/events/consumer/src/main/resources/OSGI-INF/blueprint/event-consumer.xml Wed Dec 14 22:38:44 2011 @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> + + <service ref="eventHandler" interface="org.osgi.service.event.EventHandler"> + <service-properties> + <entry key="event.topics" value="org/apache/karaf/webconsole/examples" /> + </service-properties> + </service> + + <service ref="eventHandler" interface="org.osgi.service.event.EventHandler"> + <service-properties> + <entry key="event.topics"> + <array value-type="java.lang.String"> + <value>org/apache/karaf/webconsole/examples/first</value> + <value>org/apache/karaf/webconsole/examples/second</value> + </array> + </entry> + </service-properties> + </service> + + <bean id="eventHandler" class="org.apache.karaf.webconsole.examples.events.consumer.DemoConsumer" /> + +</blueprint> Copied: karaf/webconsole/trunk/examples/events/pom.xml (from r1214513, karaf/webconsole/trunk/examples/pom.xml) URL: http://svn.apache.org/viewvc/karaf/webconsole/trunk/examples/events/pom.xml?p2=karaf/webconsole/trunk/examples/events/pom.xml&p1=karaf/webconsole/trunk/examples/pom.xml&r1=1214513&r2=1214515&rev=1214515&view=diff ============================================================================== --- karaf/webconsole/trunk/examples/pom.xml (original) +++ karaf/webconsole/trunk/examples/events/pom.xml Wed Dec 14 22:38:44 2011 @@ -20,18 +20,19 @@ <modelVersion>4.0.0</modelVersion> <parent> - <groupId>org.apache.karaf</groupId> - <artifactId>webconsole</artifactId> + <groupId>org.apache.karaf.webconsole</groupId> + <artifactId>examples</artifactId> <version>0.3.0-SNAPSHOT</version> </parent> - <groupId>org.apache.karaf.webconsole</groupId> - <artifactId>examples</artifactId> - <name>Apache Karaf :: WebConsole :: Examples</name> + <groupId>org.apache.karaf.webconsole.examples</groupId> + <artifactId>events</artifactId> + <name>Apache Karaf :: WebConsole :: Examples :: Events</name> <packaging>pom</packaging> <modules> - <module>branding</module> + <module>consumer</module> + <module>provider</module> </modules> </project> Added: karaf/webconsole/trunk/examples/events/provider/pom.xml URL: http://svn.apache.org/viewvc/karaf/webconsole/trunk/examples/events/provider/pom.xml?rev=1214515&view=auto ============================================================================== --- karaf/webconsole/trunk/examples/events/provider/pom.xml (added) +++ karaf/webconsole/trunk/examples/events/provider/pom.xml Wed Dec 14 22:38:44 2011 @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.karaf.webconsole.examples</groupId> + <artifactId>events</artifactId> + <version>0.3.0-SNAPSHOT</version> + </parent> + + <groupId>org.apache.karaf.webconsole.examples.events</groupId> + <artifactId>provider</artifactId> + <name>Apache Karaf :: WebConsole :: Examples :: Events :: Provider</name> + <packaging>bundle</packaging> + + <dependencies> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <version>2.3.5</version> + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> + <Import-Package> + * + </Import-Package> + <Private-Package>org.apache.karaf.webconsole.examples.events.provider</Private-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> +</project> Added: karaf/webconsole/trunk/examples/events/provider/src/main/java/org/apache/karaf/webconsole/examples/events/provider/DemoProducer.java URL: http://svn.apache.org/viewvc/karaf/webconsole/trunk/examples/events/provider/src/main/java/org/apache/karaf/webconsole/examples/events/provider/DemoProducer.java?rev=1214515&view=auto ============================================================================== --- karaf/webconsole/trunk/examples/events/provider/src/main/java/org/apache/karaf/webconsole/examples/events/provider/DemoProducer.java (added) +++ karaf/webconsole/trunk/examples/events/provider/src/main/java/org/apache/karaf/webconsole/examples/events/provider/DemoProducer.java Wed Dec 14 22:38:44 2011 @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.karaf.webconsole.examples.events.provider; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.osgi.service.event.Event; +import org.osgi.service.event.EventAdmin; + +/** + * Example brand provider which modify console look and feel. + */ +public class DemoProducer { + + private EventAdmin eventAdmin; + private List<String> topics; + private AtomicBoolean run = new AtomicBoolean(true); + + public DemoProducer(EventAdmin eventAdmin) { + this.eventAdmin = eventAdmin; + } + + public void setTopics(List<String> topics) { + this.topics = topics; + } + + public void start() { + new Thread(new Runnable() { + public void run() { + int counter = 0; + int topicCount = 0; + + while (run.get()) { + if (++topicCount >= topics.size()) { + topicCount = 0; + } + Map properties = new HashMap(); + properties.put("topicCounter", topicCount); + properties.put("counter", ++counter); + eventAdmin.postEvent(new Event(topics.get(topicCount), properties)); + + try { + Thread.sleep(TimeUnit.SECONDS.toMillis(10)); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + }).start(); + } + + public void stop() { + run.set(false); + } + +} \ No newline at end of file Copied: karaf/webconsole/trunk/examples/events/provider/src/main/resources/OSGI-INF/blueprint/event-provider.xml (from r1214513, karaf/webconsole/trunk/examples/pom.xml) URL: http://svn.apache.org/viewvc/karaf/webconsole/trunk/examples/events/provider/src/main/resources/OSGI-INF/blueprint/event-provider.xml?p2=karaf/webconsole/trunk/examples/events/provider/src/main/resources/OSGI-INF/blueprint/event-provider.xml&p1=karaf/webconsole/trunk/examples/pom.xml&r1=1214513&r2=1214515&rev=1214515&view=diff ============================================================================== --- karaf/webconsole/trunk/examples/pom.xml (original) +++ karaf/webconsole/trunk/examples/events/provider/src/main/resources/OSGI-INF/blueprint/event-provider.xml Wed Dec 14 22:38:44 2011 @@ -15,23 +15,20 @@ See the License for the specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> - <parent> - <groupId>org.apache.karaf</groupId> - <artifactId>webconsole</artifactId> - <version>0.3.0-SNAPSHOT</version> - </parent> + <reference id="eventAdmin" interface="org.osgi.service.event.EventAdmin" /> - <groupId>org.apache.karaf.webconsole</groupId> - <artifactId>examples</artifactId> - <name>Apache Karaf :: WebConsole :: Examples</name> - <packaging>pom</packaging> + <bean class="org.apache.karaf.webconsole.examples.events.provider.DemoProducer" + init-method="start" destroy-method="stop"> + <argument ref="eventAdmin" /> + <property name="topics"> + <list> + <value>org/apache/karaf/webconsole/examples</value> + <value>org/apache/karaf/webconsole/examples/first</value> + <value>org/apache/karaf/webconsole/examples/second</value> + </list> + </property> + </bean> - <modules> - <module>branding</module> - </modules> - -</project> +</blueprint> Modified: karaf/webconsole/trunk/examples/pom.xml URL: http://svn.apache.org/viewvc/karaf/webconsole/trunk/examples/pom.xml?rev=1214515&r1=1214514&r2=1214515&view=diff ============================================================================== --- karaf/webconsole/trunk/examples/pom.xml (original) +++ karaf/webconsole/trunk/examples/pom.xml Wed Dec 14 22:38:44 2011 @@ -32,6 +32,7 @@ <modules> <module>branding</module> + <module>events</module> </modules> </project>