001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.transport.jms;
019:
020: import java.io.File;
021:
022: import org.apache.activemq.broker.BrokerService;
023: import org.apache.activemq.store.memory.MemoryPersistenceAdapter;
024:
025: class JMSBrokerSetup {
026: JMSEmbeddedBroker jmsBrokerThread;
027: String jmsBrokerUrl = "tcp://localhost:61616";
028: String activeMQStorageDir;
029:
030: public JMSBrokerSetup(String url) {
031: jmsBrokerUrl = url;
032: }
033:
034: public void start() throws Exception {
035: jmsBrokerThread = new JMSEmbeddedBroker(jmsBrokerUrl);
036: jmsBrokerThread.startBroker();
037: }
038:
039: public void stop() throws Exception {
040: synchronized (this ) {
041: jmsBrokerThread.shutdownBroker = true;
042: }
043: if (jmsBrokerThread != null) {
044: jmsBrokerThread.join();
045: }
046:
047: jmsBrokerThread = null;
048: }
049:
050: class JMSEmbeddedBroker extends Thread {
051: boolean shutdownBroker;
052: final String brokerUrl;
053: Exception exception;
054:
055: public JMSEmbeddedBroker(String url) {
056: brokerUrl = url;
057: }
058:
059: public void startBroker() throws Exception {
060: synchronized (this ) {
061: super .start();
062: try {
063: wait();
064: if (exception != null) {
065: throw exception;
066: }
067: } catch (InterruptedException ex) {
068: ex.printStackTrace();
069: }
070: }
071: }
072:
073: public void run() {
074: try {
075: //ContainerWapper container;
076: BrokerService broker = new BrokerService();
077: synchronized (this ) {
078: broker
079: .setPersistenceAdapter(new MemoryPersistenceAdapter());
080: broker.setTmpDataDirectory(new File("./target"));
081: broker.addConnector(brokerUrl);
082: broker.start();
083: Thread.sleep(200);
084: notifyAll();
085: }
086: synchronized (this ) {
087: while (!shutdownBroker) {
088: wait(1000);
089: }
090: }
091: broker.stop();
092: broker = null;
093: } catch (Exception e) {
094: exception = e;
095: e.printStackTrace();
096: }
097: }
098:
099: }
100:
101: /*class ContainerWapper extends BrokerContainerImpl {
102:
103: public void shutdown() {
104: super.containerShutdown();
105: }
106: }*/
107: }
|