<commit_before>/**
 * 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.web

import java.io.File
import org.apache.activemq.apollo.util._
import javax.servlet.{ServletContextListener, ServletContextEvent}
import org.apache.activemq.apollo.broker.{FileConfigStore, ConfigStore, BrokerRegistry, Broker}
import org.fusesource.hawtdispatch._

/**
 * A servlet context listener which handles starting the
 * broker instance.
 *
 * @version $Revision : 1.1 $
 */
class ApolloListener extends ServletContextListener {

  var configStore:ConfigStore = null

  def contextInitialized(sce: ServletContextEvent) = {
    try {
      if( ConfigStore() == null ) {
        configStore = createConfigStore
        ConfigStore() = configStore
        configStore.dispatchQueue {
          configStore.listBrokers.foreach { id=>
            configStore.getBroker(id, true).foreach{ config=>

              println("Config store contained broker: "+config.id);
              // Only start the broker up if it's enabled..
              if( config.enabled ) {

                println("starting broker: "+config.id);
                val broker = new Broker()
                broker.config = config
                BrokerRegistry.add(config.id, broker)
                broker.start()
              }
            }
          }
        }
      }
    } catch {
      case e:Exception =>
        e.printStackTrace
    }
  }

  def contextDestroyed(sce: ServletContextEvent) = {
    val tracker = new LoggingTracker("webapp shutdown")
    if( configStore!=null ) {
      configStore.dispatchQueue {
        configStore.listBrokers.foreach { id=>
          val broker = BrokerRegistry.remove(id);
          if( broker!=null ) {
            tracker.stop(broker)
          }
        }
      }
      tracker.stop(configStore)
      tracker.await
      configStore = null
    }
  }

  def createConfigStore():ConfigStore = {
    val store = new FileConfigStore
    store.file = new File("activemq.xml")
    LoggingTracker("config store startup") { tracker=>
      store.start(tracker.task())
    }
    store
  }


}<commit_msg>use a apollo.xml for the config file name.<commit_after>/**
 * 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.web

import java.io.File
import org.apache.activemq.apollo.util._
import javax.servlet.{ServletContextListener, ServletContextEvent}
import org.apache.activemq.apollo.broker.{FileConfigStore, ConfigStore, BrokerRegistry, Broker}
import org.fusesource.hawtdispatch._

/**
 * A servlet context listener which handles starting the
 * broker instance.
 *
 * @version $Revision : 1.1 $
 */
class ApolloListener extends ServletContextListener {

  var configStore:ConfigStore = null

  def contextInitialized(sce: ServletContextEvent) = {
    try {
      if( ConfigStore() == null ) {
        configStore = createConfigStore
        ConfigStore() = configStore
        configStore.dispatchQueue {
          configStore.listBrokers.foreach { id=>
            configStore.getBroker(id, true).foreach{ config=>

              println("Config store contained broker: "+config.id);
              // Only start the broker up if it's enabled..
              if( config.enabled ) {

                println("starting broker: "+config.id);
                val broker = new Broker()
                broker.config = config
                BrokerRegistry.add(config.id, broker)
                broker.start()
              }
            }
          }
        }
      }
    } catch {
      case e:Exception =>
        e.printStackTrace
    }
  }

  def contextDestroyed(sce: ServletContextEvent) = {
    val tracker = new LoggingTracker("webapp shutdown")
    if( configStore!=null ) {
      configStore.dispatchQueue {
        configStore.listBrokers.foreach { id=>
          val broker = BrokerRegistry.remove(id);
          if( broker!=null ) {
            tracker.stop(broker)
          }
        }
      }
      tracker.stop(configStore)
      tracker.await
      configStore = null
    }
  }

  def createConfigStore():ConfigStore = {
    val store = new FileConfigStore
    store.file = new File("apollo.xml")
    LoggingTracker("config store startup") { tracker=>
      store.start(tracker.task())
    }
    store
  }


}
{'fraction_non_alphanumeric': 0.08818952100985647, 'fraction_numerical': 0.0020750475531730937, 'mean_word_length': 2.5747836835599505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '834136', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1505, 'n_words': 477}