Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 15214 invoked from network); 30 Jan 2011 04:08:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 30 Jan 2011 04:08:05 -0000 Received: (qmail 69083 invoked by uid 500); 30 Jan 2011 04:08:05 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 69024 invoked by uid 500); 30 Jan 2011 04:08:03 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 69017 invoked by uid 99); 30 Jan 2011 04:08:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 30 Jan 2011 04:08:03 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 30 Jan 2011 04:07:56 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4607D23888DD; Sun, 30 Jan 2011 04:07:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1065181 - in /activemq/activemq-apollo/trunk: ./ apollo-bdb/ apollo-broker/ apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/ apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/osgi/ apollo-broker/src/main/scala/o... Date: Sun, 30 Jan 2011 04:07:32 -0000 To: commits@activemq.apache.org From: chirino@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110130040733.4607D23888DD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: chirino Date: Sun Jan 30 04:07:31 2011 New Revision: 1065181 URL: http://svn.apache.org/viewvc?rev=1065181&view=rev Log: big class finder refactor so we can work better inside OSGi. Added: activemq/activemq-apollo/trunk/apollo-karaf/ activemq/activemq-apollo/trunk/apollo-karaf/pom.xml - copied, changed from r1065180, activemq/activemq-apollo/trunk/apollo-bdb/pom.xml activemq/activemq-apollo/trunk/apollo-karaf/src/ activemq/activemq-apollo/trunk/apollo-karaf/src/main/ activemq/activemq-apollo/trunk/apollo-karaf/src/main/resources/ activemq/activemq-apollo/trunk/apollo-karaf/src/main/resources/OSGI-INF/ activemq/activemq-apollo/trunk/apollo-karaf/src/main/resources/OSGI-INF/blueprint/ activemq/activemq-apollo/trunk/apollo-karaf/src/main/resources/OSGI-INF/blueprint/broker.xml activemq/activemq-apollo/trunk/apollo-karaf/src/main/resources/features.xml - copied, changed from r1065180, activemq/activemq-apollo/trunk/apollo-karaf-feature/src/main/resources/features.xml activemq/activemq-apollo/trunk/apollo-karaf/src/main/scala/ activemq/activemq-apollo/trunk/apollo-karaf/src/main/scala/org/ activemq/activemq-apollo/trunk/apollo-karaf/src/main/scala/org/apache/ activemq/activemq-apollo/trunk/apollo-karaf/src/main/scala/org/apache/activemq/ activemq/activemq-apollo/trunk/apollo-karaf/src/main/scala/org/apache/activemq/apollo/ activemq/activemq-apollo/trunk/apollo-karaf/src/main/scala/org/apache/activemq/apollo/karaf/ activemq/activemq-apollo/trunk/apollo-karaf/src/main/scala/org/apache/activemq/apollo/karaf/BrokerService.scala activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ClassFinderActivator.scala Removed: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/osgi/Activator.scala activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/JavaClassFinder.java Modified: activemq/activemq-apollo/trunk/apollo-bdb/pom.xml activemq/activemq-apollo/trunk/apollo-broker/pom.xml activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/QueueBinding.scala activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/protocol/MultiProtocol.scala activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/protocol/ProtocolFactory.scala activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/store/StoreFactory.scala activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServer.scala activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServerFactory.scala activemq/activemq-apollo/trunk/apollo-cassandra/pom.xml activemq/activemq-apollo/trunk/apollo-cli/pom.xml activemq/activemq-apollo/trunk/apollo-dto/pom.xml activemq/activemq-apollo/trunk/apollo-hawtdb/pom.xml activemq/activemq-apollo/trunk/apollo-jdbm2/pom.xml activemq/activemq-apollo/trunk/apollo-karaf-feature/src/main/resources/features.xml activemq/activemq-apollo/trunk/apollo-stomp/pom.xml activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/perf/StompBrokerPerfTest.scala activemq/activemq-apollo/trunk/apollo-tcp/pom.xml activemq/activemq-apollo/trunk/apollo-transport/pom.xml activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/DiscoveryAgentFactory.java activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/ProtocolCodecFactory.java activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/TransportFactory.java activemq/activemq-apollo/trunk/apollo-util/pom.xml activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ClassFinder.scala activemq/activemq-apollo/trunk/pom.xml Modified: activemq/activemq-apollo/trunk/apollo-bdb/pom.xml URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-bdb/pom.xml?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-bdb/pom.xml (original) +++ activemq/activemq-apollo/trunk/apollo-bdb/pom.xml Sun Jan 30 04:07:31 2011 @@ -34,6 +34,10 @@ ${project.artifactId} + + org.apache.activemq.apollo.util.ClassFinderExportingActivator + + Modified: activemq/activemq-apollo/trunk/apollo-broker/pom.xml URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/pom.xml?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-broker/pom.xml (original) +++ activemq/activemq-apollo/trunk/apollo-broker/pom.xml Sun Jan 30 04:07:31 2011 @@ -35,7 +35,7 @@ ${project.artifactId} - + org.apache.activemq.apollo.util.ClassFinderExportingActivator @@ -154,16 +154,6 @@ - - org.apache.felix - maven-bundle-plugin - - - org.apache.activemq.apollo.broker.osgi.ApolloActivator - - - - maven-jar-plugin @@ -178,7 +168,7 @@ org.fusesource.hawtbuf - hawtbuf-proto + hawtbuf-protoc ${hawtbuf-version} alt Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala (original) +++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala Sun Jan 30 04:07:31 2011 @@ -46,19 +46,13 @@ object BrokerFactory { def createBroker(brokerURI:String):Broker } - def discover = { - val finder = new ClassFinder[Provider]("META-INF/services/org.apache.activemq.apollo/broker-factory.index") - finder.new_instances - } - - var providers = discover - + val providers = new ClassFinder[Provider]("META-INF/services/org.apache.activemq.apollo/broker-factory.index",classOf[Provider]) def createBroker(uri:String):Broker = { if( uri == null ) { return null } - providers.foreach { provider=> + providers.singletons.foreach { provider=> val broker = provider.createBroker(uri) if( broker!=null ) { return broker; Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/QueueBinding.scala URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/QueueBinding.scala?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/QueueBinding.scala (original) +++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/QueueBinding.scala Sun Jan 30 04:07:31 2011 @@ -37,15 +37,10 @@ object QueueBinding { def create(binding_dto:DestinationDTO):QueueBinding } - def discover = { - val finder = new ClassFinder[Provider]("META-INF/services/org.apache.activemq.apollo/binding-factory.index") - finder.new_instances - } - - var providers = discover + val providers = new ClassFinder[Provider]("META-INF/services/org.apache.activemq.apollo/binding-factory.index",classOf[Provider]) def create(binding_kind:AsciiBuffer, binding_data:Buffer):QueueBinding = { - providers.foreach { provider=> + providers.singletons.foreach { provider=> val rc = provider.create(binding_kind, binding_data) if( rc!=null ) { return rc @@ -54,7 +49,7 @@ object QueueBinding { throw new IllegalArgumentException("Invalid binding type: "+binding_kind); } def create(binding_dto:DestinationDTO):QueueBinding = { - providers.foreach { provider=> + providers.singletons.foreach { provider=> val rc = provider.create(binding_dto) if( rc!=null ) { return rc Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/protocol/MultiProtocol.scala URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/protocol/MultiProtocol.scala?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/protocol/MultiProtocol.scala (original) +++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/protocol/MultiProtocol.scala Sun Jan 30 04:07:31 2011 @@ -35,7 +35,7 @@ import org.fusesource.hawtdispatch._ */ class MultiProtocolFactory extends ProtocolFactory.Provider { - def all_protocols: Array[Protocol] = ((ProtocolFactory.providers.map(_.create())).filter(_.isIdentifiable)).toArray + def all_protocols: Array[Protocol] = ((ProtocolFactory.provider.singletons.map(_.create())).filter(_.isIdentifiable)).toArray def create() = { new MultiProtocol(()=>all_protocols) Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/protocol/ProtocolFactory.scala URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/protocol/ProtocolFactory.scala?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/protocol/ProtocolFactory.scala (original) +++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/protocol/ProtocolFactory.scala Sun Jan 30 04:07:31 2011 @@ -37,15 +37,10 @@ object ProtocolFactory { def create(config:String):Protocol } - def discover = { - val finder = new ClassFinder[Provider]("META-INF/services/org.apache.activemq.apollo/protocol-factory.index") - finder.new_instances - } - - var providers = discover + val provider = new ClassFinder[Provider]("META-INF/services/org.apache.activemq.apollo/protocol-factory.index",classOf[Provider]) def get(name:String):Option[Protocol] = { - providers.foreach { provider=> + provider.singletons.foreach { provider=> val rc = provider.create(name) if( rc!=null ) { return Some(rc) Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/store/StoreFactory.scala URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/store/StoreFactory.scala?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/store/StoreFactory.scala (original) +++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/store/StoreFactory.scala Sun Jan 30 04:07:31 2011 @@ -33,18 +33,13 @@ object StoreFactory { def validate(config: StoreDTO, reporter:Reporter):ReporterLevel } - def discover = { - val finder = new ClassFinder[Provider]("META-INF/services/org.apache.activemq.apollo/store-factory.index") - finder.new_instances - } - - var providers = discover + val providers = new ClassFinder[Provider]("META-INF/services/org.apache.activemq.apollo/store-factory.index", classOf[Provider]) def create(config:StoreDTO):Store = { if( config == null ) { return null } - providers.foreach { provider=> + providers.singletons.foreach { provider=> val rc = provider.create(config) if( rc!=null ) { return rc @@ -58,7 +53,7 @@ object StoreFactory { if( config == null ) { return INFO } else { - providers.foreach { provider=> + providers.singletons.foreach { provider=> val rc = provider.validate(config, reporter) if( rc!=null ) { return rc Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServer.scala URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServer.scala?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServer.scala (original) +++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServer.scala Sun Jan 30 04:07:31 2011 @@ -40,6 +40,9 @@ trait WebServer extends Service object JettyWebServerFactory extends WebServerFactory.Provider { + // So that the factory class does not load, if we can not load jetty. + private val LOAD_JETTY = classOf[LoginService] + def create(broker:Broker): WebServer = new JettyWebServer(broker) def validate(config: WebAdminDTO, reporter: Reporter): ReporterLevel.ReporterLevel = { @@ -54,7 +57,6 @@ object JettyWebServerFactory extends Web object JettyWebServer extends Log { - val LOAD_JETTY = classOf[LoginService] val webapp = { import FileSupport._ Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServerFactory.scala URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServerFactory.scala?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServerFactory.scala (original) +++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServerFactory.scala Sun Jan 30 04:07:31 2011 @@ -35,18 +35,13 @@ object WebServerFactory { def validate(config: WebAdminDTO, reporter:Reporter):ReporterLevel } - def discover = { - val finder = new ClassFinder[Provider]("META-INF/services/org.apache.activemq.apollo/web-server-factory.index") - finder.new_instances - } - - var providers = discover + val providers = new ClassFinder[Provider]("META-INF/services/org.apache.activemq.apollo/web-server-factory.index",classOf[Provider]) def create(broker:Broker):WebServer = { if( broker == null ) { return null } - providers.foreach { provider=> + providers.singletons.foreach { provider=> val rc = provider.create(broker) if( rc!=null ) { return rc @@ -60,7 +55,7 @@ object WebServerFactory { if( config == null ) { return INFO } else { - providers.foreach { provider=> + providers.singletons.foreach { provider=> val rc = provider.validate(config, reporter) if( rc!=null ) { return rc Modified: activemq/activemq-apollo/trunk/apollo-cassandra/pom.xml URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-cassandra/pom.xml?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-cassandra/pom.xml (original) +++ activemq/activemq-apollo/trunk/apollo-cassandra/pom.xml Sun Jan 30 04:07:31 2011 @@ -34,6 +34,10 @@ ${project.artifactId} + + org.apache.activemq.apollo.util.ClassFinderExportingActivator + + shorrockin Maven 2 Repository Modified: activemq/activemq-apollo/trunk/apollo-cli/pom.xml URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-cli/pom.xml?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-cli/pom.xml (original) +++ activemq/activemq-apollo/trunk/apollo-cli/pom.xml Sun Jan 30 04:07:31 2011 @@ -31,6 +31,10 @@ ${project.artifactId} + + org.apache.activemq.apollo.util.ClassFinderExportingActivator + + @@ -108,18 +112,7 @@ 1.0-SNAPSHOT test - - org.apache.activemq - apollo-hawtdb - 1.0-SNAPSHOT - test - - - - - - - + org.apache.activemq apollo-bdb Modified: activemq/activemq-apollo/trunk/apollo-dto/pom.xml URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/pom.xml?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-dto/pom.xml (original) +++ activemq/activemq-apollo/trunk/apollo-dto/pom.xml Sun Jan 30 04:07:31 2011 @@ -34,20 +34,12 @@ ${project.artifactId} - + org.apache.activemq.apollo.util.ClassFinderExportingActivator - + - - stax - stax-api - ${stax-api-version} - - - stax - stax - ${stax-version} - + + org.codehaus.jackson jackson-core-asl Modified: activemq/activemq-apollo/trunk/apollo-hawtdb/pom.xml URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-hawtdb/pom.xml?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-hawtdb/pom.xml (original) +++ activemq/activemq-apollo/trunk/apollo-hawtdb/pom.xml Sun Jan 30 04:07:31 2011 @@ -34,6 +34,10 @@ ${project.artifactId} + + org.apache.activemq.apollo.util.ClassFinderExportingActivator + + @@ -127,7 +131,7 @@ org.fusesource.hawtbuf - hawtbuf-proto + hawtbuf-protoc ${hawtbuf-version} alt Modified: activemq/activemq-apollo/trunk/apollo-jdbm2/pom.xml URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-jdbm2/pom.xml?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-jdbm2/pom.xml (original) +++ activemq/activemq-apollo/trunk/apollo-jdbm2/pom.xml Sun Jan 30 04:07:31 2011 @@ -33,6 +33,9 @@ bundle ${project.artifactId} + + org.apache.activemq.apollo.util.ClassFinderExportingActivator + Modified: activemq/activemq-apollo/trunk/apollo-karaf-feature/src/main/resources/features.xml URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-karaf-feature/src/main/resources/features.xml?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-karaf-feature/src/main/resources/features.xml (original) +++ activemq/activemq-apollo/trunk/apollo-karaf-feature/src/main/resources/features.xml Sun Jan 30 04:07:31 2011 @@ -17,60 +17,49 @@ limitations under the License. --> - - - - apollo-jdbm - apollo-stomp - - - + mvn:org.apache.activemq/apollo-broker/${pom.version} - mvn:org.apache.activemq/apollo-cli/${pom.version} + mvn:org.apache.activemq/apollo-dto/${pom.version} mvn:org.apache.activemq/apollo-selector/${pom.version} mvn:org.apache.activemq/apollo-transport/${pom.version} mvn:org.apache.activemq/apollo-util/${pom.version} + mvn:org.apache.activemq/apollo-karaf/${pom.version} wrap:mvn:org.scala-lang/scala-library/${scala-version} mvn:org.fusesource.hawtbuf/hawtbuf/${hawtbuf-version} - wrap:mvn:org.fusesource.hawtbuf/hawtbuf-proto/${hawtbuf-version} - wrap:mvn:org.fusesource.hawtdispatch/hawtdispatch/${hawtdispatch-version} - wrap:mvn:org.fusesource.hawtdispatch/hawtdispatch-scala/${hawtdispatch-version} + mvn:org.fusesource.hawtbuf/hawtbuf-proto/${hawtbuf-version} + mvn:org.fusesource.hawtdispatch/hawtdispatch/${hawtdispatch-version} + mvn:org.fusesource.hawtdispatch/hawtdispatch-scala/${hawtdispatch-version} mvn:org.codehaus.jackson/jackson-core-asl/${jackson-version} mvn:org.codehaus.jackson/jackson-mapper-asl/${jackson-version} + mvn:org.apache.activemq/activemq-jaas/${activemq-version} + wrap:mvn:org.jasypt/jasypt/${jasypt-version} - wrap:mvn:org.apache.activemq/activemq-jaas/${activemq-version} wrap:mvn:org.yaml/snakeyaml/${snakeyaml-version} + + + mvn:org.apache.activemq/apollo-tcp/${pom.version} + mvn:org.apache.activemq/apollo-stomp/${pom.version} + - + - apollo-broker - wrap:mvn:org.apache.activemq/apollo-jdbm2/${pom.version} + mvn:org.apache.activemq/apollo-jdbm2/${pom.version} + mvn:org.fusesource.jdbm/jdbm/${jdbm-version} + - apollo-broker - wrap:mvn:org.apache.activemq/apollo-bdb/${pom.version} - - - - - apollo-broker - mvn:org.apache.activemq/apollo-tcp/${pom.version} - - - - - apollo-tcp - mvn:org.apache.activemq/apollo-stomp/${pom.version} + apollo + mvn:org.apache.activemq/apollo-bdb/${pom.version} + wrap:mvn:com.sleepycat/je/${bdb-version} - - apollo-broker + apollo mvn:org.apache.activemq/apollo-web/${pom.version}/slim mvn:org.apache.activemq/apollo-web/${pom.version}/war/slim Copied: activemq/activemq-apollo/trunk/apollo-karaf/pom.xml (from r1065180, activemq/activemq-apollo/trunk/apollo-bdb/pom.xml) URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-karaf/pom.xml?p2=activemq/activemq-apollo/trunk/apollo-karaf/pom.xml&p1=activemq/activemq-apollo/trunk/apollo-bdb/pom.xml&r1=1065180&r2=1065181&rev=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-bdb/pom.xml (original) +++ activemq/activemq-apollo/trunk/apollo-karaf/pom.xml Sun Jan 30 04:07:31 2011 @@ -15,57 +15,42 @@ See the License for the specific language governing permissions and limitations under the License. --> - - + 4.0.0 - org.apache.activemq apollo-scala 1.0-SNAPSHOT ../apollo-scala - + org.apache.activemq - apollo-bdb + apollo-karaf 1.0-SNAPSHOT bundle - + ${project.artifactId} + Karaf Integration - - - - org.apache.activemq - apollo-broker - 1.0-SNAPSHOT - - - - com.sleepycat - je - ${bdb-version} - + + + + - - org.apache.activemq - apollo-web - 1.0-SNAPSHOT - jar - slim - true + org.osgi + org.osgi.core + ${osgi-version} + provided - javax.servlet - servlet-api - ${servlet-api-version} + org.osgi + org.osgi.compendium + ${osgi-version} provided - org.scala-lang scala-library @@ -79,61 +64,31 @@ compile true - - - - org.scalatest - scalatest - ${scalatest-version} - test - + org.apache.activemq - apollo-broker + apollo-stomp 1.0-SNAPSHOT - test-jar - test org.apache.activemq - apollo-util + apollo-jdbm2 1.0-SNAPSHOT - test-jar - test - junit - junit - test - ${junit-version} + org.eclipse.jetty.aggregate + jetty-all-server + ${jetty-version} - org.slf4j - slf4j-log4j12 - ${slf4j-version} - test + org.apache.activemq + apollo-web + 1.0-SNAPSHOT + jar + slim - + - - - - - org.fusesource.scalate - maven-scalate-plugin - ${scalate-version} - - - - precompile - - - - - - - - Added: activemq/activemq-apollo/trunk/apollo-karaf/src/main/resources/OSGI-INF/blueprint/broker.xml URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-karaf/src/main/resources/OSGI-INF/blueprint/broker.xml?rev=1065181&view=auto ============================================================================== --- activemq/activemq-apollo/trunk/apollo-karaf/src/main/resources/OSGI-INF/blueprint/broker.xml (added) +++ activemq/activemq-apollo/trunk/apollo-karaf/src/main/resources/OSGI-INF/blueprint/broker.xml Sun Jan 30 04:07:31 2011 @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file Copied: activemq/activemq-apollo/trunk/apollo-karaf/src/main/resources/features.xml (from r1065180, activemq/activemq-apollo/trunk/apollo-karaf-feature/src/main/resources/features.xml) URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-karaf/src/main/resources/features.xml?p2=activemq/activemq-apollo/trunk/apollo-karaf/src/main/resources/features.xml&p1=activemq/activemq-apollo/trunk/apollo-karaf-feature/src/main/resources/features.xml&r1=1065180&r2=1065181&rev=1065181&view=diff ============================================================================== (empty) Added: activemq/activemq-apollo/trunk/apollo-karaf/src/main/scala/org/apache/activemq/apollo/karaf/BrokerService.scala URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-karaf/src/main/scala/org/apache/activemq/apollo/karaf/BrokerService.scala?rev=1065181&view=auto ============================================================================== --- activemq/activemq-apollo/trunk/apollo-karaf/src/main/scala/org/apache/activemq/apollo/karaf/BrokerService.scala (added) +++ activemq/activemq-apollo/trunk/apollo-karaf/src/main/scala/org/apache/activemq/apollo/karaf/BrokerService.scala Sun Jan 30 04:07:31 2011 @@ -0,0 +1,170 @@ +/** + * 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.activemq.apollo.karaf + +import org.osgi.framework._ +import java.net.URL +import org.apache.activemq.apollo.broker.{Broker, ConfigStore, FileConfigStore} +import org.fusesource.hawtdispatch._ +import org.apache.activemq.apollo.util.FileSupport._ +import java.lang.{Class, String} +import scala.reflect.BeanProperty +import org.apache.activemq.apollo.dto.{XmlCodec, BrokerDTO} +import java.io.{FileInputStream, File} +import org.osgi.service.cm.ConfigurationAdmin +import java.util.{Properties, Enumeration} +import org.apache.activemq.apollo.broker.security.EncryptionSupport +import collection.JavaConversions._ +import org.apache.activemq.apollo.util.{ServiceControl, Log, LoggingReporter} + +class BrokerService extends Log { + + @BeanProperty + var context: BundleContext = _ + + @BeanProperty + var basedir: File = _ + + @BeanProperty + var config:BrokerDTO = _ + + @BeanProperty + var configAdmin:ConfigurationAdmin = _ + + var broker:Broker = _ + + def start(): Unit = this.synchronized { + try { + + // this makes jaxb happy + Thread.currentThread().setContextClassLoader(JaxbClassLoader(context)) + + // in case the config gets injected. + if( config == null ) { + + // val base = system_dir("apollo.base") + val apollo_xml = basedir / "etc" / "apollo.xml" + + if (!apollo_xml.exists) { + error("Apollo configuration file'%s' does not exist.".format(apollo_xml)); + return; + } + + // Load the configs and start the brokers up. + info("Loading configuration file '%s'.", apollo_xml); + + val props = new Properties() + props.putAll(System.getProperties) + props.put("apollo.base", basedir.getCanonicalPath) + val cmProps = configAdmin.getConfiguration("org.apache.activemq.apollo").getProperties + if( cmProps!=null ) { + cmProps.keySet.foreach { key => + props.put(key.asInstanceOf[String], cmProps.get(key).asInstanceOf[String]) + } + } + config = XmlCodec.unmarshalBrokerDTO(new FileInputStream(apollo_xml), props) + } + + debug("Starting broker"); + broker = new Broker() + broker.configure(config, LoggingReporter(this)) + broker.tmp = basedir / "tmp" + broker.tmp.mkdirs + broker.start(^{ + info("Apollo started"); + }) + + } catch { + case e: Throwable => + error(e) + } + } + + def stop(): Unit = this.synchronized { + if( broker!=null ) { + ServiceControl.stop(broker, "Apollo shutdown") + info("Apollo stopped"); + } + } + +} + +// We need to setup a context class loader because apollo allows +// optional/plugin modules to dynamically add to the JAXB context. +case class JaxbClassLoader(context: BundleContext) extends ClassLoader(classOf[JaxbClassLoader].getClassLoader) { + + def wait_for_start(bundle:Bundle):Option[Bundle] = { + var i=0 + while(true) { + i+=1 + bundle.getState match { + case Bundle.UNINSTALLED=> return None + case Bundle.RESOLVED=> return Some(bundle) + case Bundle.ACTIVE=> return Some(bundle) + case _ => + Thread.sleep(100) + if( (i%50)==0 ) { + println("Waiting on bundle: "+bundle.getSymbolicName); + } + } + } + None + } + + val bundles = context.getBundles.flatMap { bundle => + if (bundle.getEntry("META-INF/services/org.apache.activemq.apollo/xml-packages.index")!=null ) { + wait_for_start(bundle) + } else { + None + } + } + + override def findClass(name: String): Class[_] = { + // try to find the class in one of the bundles. + bundles.foreach{ bundle:Bundle => + try { + return bundle.loadClass(name) + } catch { + case e:ClassNotFoundException => // ignore. + } + } + super.findClass(name) + } + + override def findResource(name: String): URL = { + bundles.foreach{ bundle => + val rc = bundle.getResource(name) + if( rc!=null ) { + return rc + } + } + null + } + + override def findResources(name: String): Enumeration[URL] = { + val list = new java.util.Vector[URL] + bundles.foreach{ bundle => + val rc = bundle.getResources(name) + if( rc!=null ) { + rc.foreach{ x=> + list.add( x.asInstanceOf[URL] ) + } + } + } + list.elements + } +} \ No newline at end of file Modified: activemq/activemq-apollo/trunk/apollo-stomp/pom.xml URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/pom.xml?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-stomp/pom.xml (original) +++ activemq/activemq-apollo/trunk/apollo-stomp/pom.xml Sun Jan 30 04:07:31 2011 @@ -33,6 +33,9 @@ bundle ${project.artifactId} + + org.apache.activemq.apollo.util.ClassFinderExportingActivator + @@ -84,18 +87,6 @@ test - - - - - - - - org.apache.activemq - apollo-hawtdb - 1.0-SNAPSHOT - test - org.apache.activemq apollo-bdb Modified: activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/perf/StompBrokerPerfTest.scala URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/perf/StompBrokerPerfTest.scala?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/perf/StompBrokerPerfTest.scala (original) +++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/perf/StompBrokerPerfTest.scala Sun Jan 30 04:07:31 2011 @@ -20,20 +20,11 @@ import _root_.org.apache.activemq.apollo import java.io.File import org.apache.activemq.apollo.dto.BrokerDTO import org.apache.activemq.apollo.broker.store.bdb.dto.BDBStoreDTO -import org.apache.activemq.apollo.broker.store.hawtdb.dto.HawtDBStoreDTO class BasicNonPersistentTest extends BasicScenarios with StompScenario { override def description = "Using the STOMP protocol over TCP" } -class BasicHawtDBTest extends BasicScenarios with PersistentScenario with HawtDBScenario with StompScenario { - override def description = "Using the STOMP protocol over TCP persistent to the HawtDB store" -} - -class DeepQueueHawtDBTest extends BasicScenarios with LargeInitialDB with HawtDBScenario with StompScenario { - override def description = "Using the STOMP protocol over TCP persisting to the HawtDB store that contains 1M messages in a queue." -} - class BasicBDBTest extends BasicScenarios with PersistentScenario with BDBScenario with StompScenario { override def description = "Using the STOMP protocol over TCP persistent to the BerkleyDB store" } @@ -50,17 +41,6 @@ trait StompScenario extends BrokerPerfSu override def getRemoteProtocolName() = "stomp" } -trait HawtDBScenario extends PersistentScenario { - override def createBrokerConfig(name: String, bindURI: String, connectUri: String): BrokerDTO = { - val rc = super.createBrokerConfig(name, bindURI, connectUri) - val store = new HawtDBStoreDTO - storeDirectory = new File(new File(test_data_dir, getClass.getName), name) - store.directory = storeDirectory - rc.virtual_hosts.get(0).store = store - rc - } -} - trait BDBScenario extends PersistentScenario { override def createBrokerConfig(name: String, bindURI: String, connectUri: String): BrokerDTO = { val rc = super.createBrokerConfig(name, bindURI, connectUri) Modified: activemq/activemq-apollo/trunk/apollo-tcp/pom.xml URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-tcp/pom.xml?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-tcp/pom.xml (original) +++ activemq/activemq-apollo/trunk/apollo-tcp/pom.xml Sun Jan 30 04:07:31 2011 @@ -32,6 +32,9 @@ bundle ${project.artifactId} + + org.apache.activemq.apollo.util.ClassFinderExportingActivator + Modified: activemq/activemq-apollo/trunk/apollo-transport/pom.xml URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-transport/pom.xml?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-transport/pom.xml (original) +++ activemq/activemq-apollo/trunk/apollo-transport/pom.xml Sun Jan 30 04:07:31 2011 @@ -34,7 +34,7 @@ ${project.artifactId} - + org.apache.activemq.apollo.util.ClassFinderExportingActivator Modified: activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/DiscoveryAgentFactory.java URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/DiscoveryAgentFactory.java?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/DiscoveryAgentFactory.java (original) +++ activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/DiscoveryAgentFactory.java Sun Jan 30 04:07:31 2011 @@ -16,7 +16,7 @@ */ package org.apache.activemq.apollo.transport; -import org.apache.activemq.apollo.util.JavaClassFinder; +import org.apache.activemq.apollo.util.ClassFinder; import java.util.List; @@ -26,18 +26,13 @@ public class DiscoveryAgentFactory { public DiscoveryAgent create(String uri) throws Exception; } - static public List providers; - - static { - JavaClassFinder finder = new JavaClassFinder("META-INF/services/org.apache.activemq.apollo/discovery-agent-factory.index"); - providers = finder.new_instances(); - } + public static final ClassFinder providers = new ClassFinder("META-INF/services/org.apache.activemq.apollo/discovery-agent-factory.index", Provider.class); /** * Creates a DiscoveryAgent */ public static DiscoveryAgent create(String uri) throws Exception { - for( Provider provider : providers) { + for( Provider provider : providers.jsingletons()) { DiscoveryAgent rc = provider.create(uri); if( rc!=null ) { return rc; Modified: activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/ProtocolCodecFactory.java URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/ProtocolCodecFactory.java?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/ProtocolCodecFactory.java (original) +++ activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/ProtocolCodecFactory.java Sun Jan 30 04:07:31 2011 @@ -16,7 +16,7 @@ */ package org.apache.activemq.apollo.transport; -import org.apache.activemq.apollo.util.JavaClassFinder; +import org.apache.activemq.apollo.util.ClassFinder; import org.fusesource.hawtbuf.Buffer; import java.util.HashMap; @@ -57,20 +57,17 @@ public class ProtocolCodecFactory { } - static public HashMap providers = new HashMap(); - - static { - JavaClassFinder finder = new JavaClassFinder("META-INF/services/org.apache.activemq.apollo/protocol-codec-factory.index"); - for( Provider provider: finder.new_instances() ) { - providers.put(provider.protocol(), provider); - } - } - + public static final ClassFinder providers = new ClassFinder("META-INF/services/org.apache.activemq.apollo/protocol-codec-factory.index", Provider.class); /** * Gets the provider. */ public static ProtocolCodecFactory.Provider get(String name) { - return providers.get(name); + for( Provider provider: providers.jsingletons() ) { + if( name.equals(provider.protocol()) ) { + return provider; + } + } + return null; } Modified: activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/TransportFactory.java URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/TransportFactory.java?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/TransportFactory.java (original) +++ activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/TransportFactory.java Sun Jan 30 04:07:31 2011 @@ -16,7 +16,7 @@ */ package org.apache.activemq.apollo.transport; -import org.apache.activemq.apollo.util.JavaClassFinder; +import org.apache.activemq.apollo.util.ClassFinder; import java.util.List; @@ -31,18 +31,13 @@ public class TransportFactory { public Transport connect(String location) throws Exception; } - static public List providers; - - static { - JavaClassFinder finder = new JavaClassFinder("META-INF/services/org.apache.activemq.apollo/transport-factory.index"); - providers = finder.new_instances(); - } + public static final ClassFinder providers = new ClassFinder("META-INF/services/org.apache.activemq.apollo/transport-factory.index", Provider.class); /** * Creates a client transport. */ public static Transport connect(String location) throws Exception { - for( Provider provider : providers) { + for( Provider provider : providers.jsingletons()) { Transport rc = provider.connect(location); if( rc!=null ) { return rc; @@ -55,7 +50,7 @@ public class TransportFactory { * Creates a transport server. */ public static TransportServer bind(String location) throws Exception { - for( Provider spi : providers) { + for( Provider spi : providers.jsingletons()) { TransportServer rc = spi.bind(location); if( rc!=null ) { return rc; Modified: activemq/activemq-apollo/trunk/apollo-util/pom.xml URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-util/pom.xml?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-util/pom.xml (original) +++ activemq/activemq-apollo/trunk/apollo-util/pom.xml Sun Jan 30 04:07:31 2011 @@ -35,7 +35,7 @@ ${project.artifactId} - + org.apache.activemq.apollo.util.ClassFinderImportingActivator @@ -87,7 +87,14 @@ 3.1.0 true - + + + org.osgi + org.osgi.core + 4.2.0 + provided + + commons-cli commons-cli Modified: activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ClassFinder.scala URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ClassFinder.scala?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ClassFinder.scala (original) +++ activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ClassFinder.scala Sun Jan 30 04:07:31 2011 @@ -19,97 +19,65 @@ package org.apache.activemq.apollo.util import java.io.InputStream import java.util.Properties import scala.collection.mutable.ListBuffer -import java.net.URL +import collection.JavaConversions._ object ClassFinder extends Log { trait Loader { - def getResources(path:String):java.util.Enumeration[URL] - def loadClass(name:String):Class[_] + def discover[T](path:String, clazz: Class[T])( callback: List[T]=>Unit ) } - case class ClassLoaderLoader(cl:ClassLoader) extends Loader { - def getResources(path:String) = cl.getResources(path) - def loadClass(name:String) = cl.loadClass(name) - } - - def standalone_loader():Array[Loader] = { - Array(ClassLoaderLoader(Thread.currentThread.getContextClassLoader)) - } - - var default_loaders = ()=>standalone_loader -} - -import ClassFinder._ - - -/** - *

- * Used to discover classes using the META-INF discovery trick. - *

- * - * @author Hiram Chirino - */ -class ClassFinder[T](val path:String, val loaders: ()=>Array[Loader]) { - - def this(path:String) = this(path, default_loaders) -// def this(path:String, loaders:Array[ClassLoader]) = this(path, ()=>{loaders.map(ClassLoaderLoader _) }) - - def findArray(): Array[Class[T]] = find.toArray - - def find(): List[Class[T]] = { - var classes = List[Class[T]]() - loaders().foreach { loader=> - - val resources = loader.getResources(path) - var classNames: List[String] = Nil - while(resources.hasMoreElements) { - val url = resources.nextElement; - val p = loadProperties(url.openStream) - val enum = p.keys - while (enum.hasMoreElements) { - classNames = classNames ::: enum.nextElement.asInstanceOf[String] :: Nil + case class ClassLoaderLoader(loaders: Seq[ClassLoader]) extends Loader { + def discover[T](path: String, clazz: Class[T])(callback: (List[T]) => Unit) = { + val classes = ListBuffer[Class[_]]() + loaders.foreach { loader=> + val resources = loader.getResources(path) + val classNames = ListBuffer[String]() + while(resources.hasMoreElements) { + val p = loadProperties(resources.nextElement.openStream) + p.keys.foreach { next => + classNames += next.asInstanceOf[String] + } + } + classNames.distinct.foreach { name=> + try { + classes += loader.loadClass(name) + } catch { + case e:Throwable => + debug(e, "Could not load class %s", name) + } } } - classNames = classNames.distinct + val singltons = classes.flatMap(x=> instantiate(clazz, x) ).distinct + callback( singltons.toList ) + } + } - classes :::= classNames.flatMap { name=> + def instantiate[T](target:Class[T], clazz:Class[_]) = { + try { + Some(target.cast(clazz.newInstance)) + } catch { + case e: Throwable => + // It may be a scala object.. check for a module class try { - Some(loader.loadClass(name).asInstanceOf[Class[T]]) + val moduleField = clazz.getClassLoader.loadClass(clazz.getName + "$").getDeclaredField("MODULE$") + Some(moduleField.get(null).asInstanceOf[T]) } catch { - case e:Throwable => - debug(e, "Could not load class %s", name) + case e2: Throwable => + debug(e, "Could create an instance of the class") None } - } } - - return classes.distinct } - def new_instances() = { - val t = ListBuffer[T]() - find.foreach {clazz => - try { - t += clazz.newInstance.asInstanceOf[T] - } catch { - case e: Throwable => - // It may be a scala object.. check for a module class - try { - val moduleField = clazz.getClassLoader.loadClass(clazz.getName + "$").getDeclaredField("MODULE$") - val instance = moduleField.get(null).asInstanceOf[T] - t += instance - } catch { - case e2: Throwable => - debug(e, "Could not load the class") - } - } - } - t.toList + def standalone_loader() = { + ClassLoaderLoader(Array(Thread.currentThread.getContextClassLoader)) } - private def loadProperties(is:InputStream):Properties = { + var default_loader:Loader = standalone_loader + + def loadProperties(is:InputStream):Properties = { if( is==null ) { return null; } @@ -128,4 +96,35 @@ class ClassFinder[T](val path:String, va } } } +} + + + +/** + *

+ * Used to discover classes using the META-INF discovery trick. + *

+ * + * @author Hiram Chirino + */ +class ClassFinder[T](val path:String, val clazz: Class[T]) { + + import ClassFinder._ + + @volatile + var singletons = List[T]() + var on_change = ()=>{} + + var loader:Loader=default_loader + + loader.discover(path, clazz) { x=> + singletons = x + on_change() + } + + def jsingletons = { + import collection.JavaConversions._ + asJavaList(singletons) + } + } \ No newline at end of file Added: activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ClassFinderActivator.scala URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ClassFinderActivator.scala?rev=1065181&view=auto ============================================================================== --- activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ClassFinderActivator.scala (added) +++ activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ClassFinderActivator.scala Sun Jan 30 04:07:31 2011 @@ -0,0 +1,173 @@ +/** + * 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.activemq.apollo.util + +import org.osgi.framework._ +import java.lang.String +import java.lang.ref._ +import java.lang.ref.WeakReference +import collection.JavaConversions._ +import scala.collection.mutable.ListBuffer +import java.util.Properties + +/** + * An OSGi bundle activator for Apollo which tracks Apollo extension + * modules. + */ +object ClassFinderImportingActivator extends Log with ClassFinder.Loader { + + private var bundleContext: BundleContext = null + + case class DiscoverRequest[T](path: String, clazz: Class[T], callback: (List[T]) => Unit) + + // + // Used the track the GC's of the DiscoverRequests + // + val queue = new ReferenceQueue[DiscoverRequest[_]]() + + // + // A service listener which un-registers when the DiscoverRequest gets GCed. + // + class DiscoverServiceListener[T](request:DiscoverRequest[T]) extends WeakReference[DiscoverRequest[T]](request, queue) with org.osgi.framework.ServiceListener { + val path = request.path + var classes = Set[T]() + + def serviceChanged(event: ServiceEvent): Unit = this.synchronized { + val request = get + if( request==null ) { + dain_queue + return; + } + + val found = cast(request, event.getServiceReference).getOrElse(return) + + val original_size = classes.size + if( event.getType == ServiceEvent.UNREGISTERING ) { + classes -= found + } else { + classes += found + } + + // if the set changed, then notify the callback. + if( original_size!= classes.size) { + request.callback(classes.toList) + } + } + + this.synchronized { + bundleContext.addServiceListener(this, filter) + classes = Option(bundleContext.getServiceReferences(null, filter)).getOrElse(Array()).flatMap { ref => + cast(request, ref) + }.toSet + request.callback(classes.toList) + } + + + def filter: String = "(finder_resource=" + path + ")" + + def cast(request:DiscoverRequest[T], ref:ServiceReference):Option[T] = { + try { + Some(request.clazz.cast(bundleContext.getService(ref))) + } catch { + case _ => None + } + } + + } + + + def dain_queue:Unit = { + var rc = queue.poll + while( rc!=null ) { + val dsl: DiscoverServiceListener[_] = rc.asInstanceOf[DiscoverServiceListener[_]] + bundleContext.removeServiceListener(dsl) + rc = queue.poll + } + } + + + def discover[T](path: String, clazz: Class[T])(callback: (List[T]) => Unit) = { + dain_queue + new DiscoverServiceListener(DiscoverRequest(path, clazz, callback)) + } + + // Change the default loaders used by the ClassFinder so + // that it can find classes using osgi + ClassFinder.default_loader = ClassFinderImportingActivator + +} + +class ClassFinderImportingActivator extends BundleActivator { + + import ClassFinderImportingActivator._ + + def start(bc: BundleContext): Unit = this.synchronized{ + debug("activating") + bundleContext = bc + debug("activated") + } + + def stop(bc: BundleContext): Unit = this.synchronized{ + debug("deactivating") + + bundleContext = null + debug("deactivated") + } + +} +object ClassFinderExportingActivator extends Log + +class ClassFinderExportingActivator extends BundleActivator { + + import ClassFinderExportingActivator._ + + var service_path_base = "META-INF/services/org.apache.activemq.apollo/" + + def start(bc: BundleContext): Unit = this.synchronized{ + val bundle = bc.getBundle + val paths = bundle.getEntryPaths(service_path_base) + + if( paths!=null ){ + paths.foreach { case path:String => + if(!path.endsWith("/xml-packages.index")) { + val url = bundle.getEntry(path) + val classNames = ListBuffer[String]() + val p = ClassFinder.loadProperties(url.openStream) + p.keys.foreach { next=> + classNames += next.asInstanceOf[String] + } + + classNames.distinct.foreach { name=> + try { + ClassFinder.instantiate(classOf[Object], bundle.loadClass(name)).foreach { service => + val p = new Properties + p.put("finder_resource", path) + bc.registerService(service.getClass.getName, service, p) + } + } catch { + case e:Throwable => + debug(e, "Could not load class %s", name) + } + } + } + } + } + } + + def stop(bc: BundleContext): Unit = this.synchronized{ + } +} \ No newline at end of file Modified: activemq/activemq-apollo/trunk/pom.xml URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/pom.xml?rev=1065181&r1=1065180&r2=1065181&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/pom.xml (original) +++ activemq/activemq-apollo/trunk/pom.xml Sun Jan 30 04:07:31 2011 @@ -96,10 +96,10 @@ 3.4 1.0.0 - 1.1 - 1.3 + 1.2-SNAPSHOT + 1.4-SNAPSHOT - 2.0.0 + 2.0.1-SNAPSHOT 4.1.6 1.6 @@ -112,9 +112,6 @@ 1.5-ea03 1.7 - 2.1.99-SNAPSHOT - 2.1.0 - 2.15.0 2.4.3 @@ -126,6 +123,10 @@ 1.3-SNAPSHOT 1.6-SNAPSHOT + + 4.2.0 + 2.1.2 + 2.1.0 2.3.0-SNAPSHOT {local-packages} ${project.groupId}.${project.artifactId} @@ -133,8 +134,8 @@ ${apollo.osgi.export.pkg};version=${project.version};-noimport:=true !* - org.apache.activemq.apollo-broker - + + @@ -175,6 +176,7 @@ apollo-cli apollo-website apollo-distro + apollo-karaf @@ -395,6 +397,7 @@ ${apollo.osgi.host} ${project.artifactId} ${apollo.osgi.name} + ${apollo.osgi.activator} ${apollo.osgi.export} ${apollo.osgi.import} ${apollo.osgi.private}