com.freedomotic.bus.BusBroker Maven / Gradle / Ivy
/**
*
* Copyright (c) 2009-2014 Freedomotic team http://freedomotic.com
*
* This file is part of Freedomotic
*
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2, or (at your option) any later version.
*
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* Freedomotic; see the file COPYING. If not, see
* .
*/
package com.freedomotic.bus;
import com.freedomotic.util.Info;
import java.util.logging.Logger;
import org.apache.activemq.broker.BrokerService;
/**
* Bus broker implementation holder.
*
* It is life cycle managed, see {@link LifeCycle}
*
* @author Freedomotic Team
*
*/
class BusBroker extends LifeCycle {
private static final Logger LOG = Logger.getLogger(BusBroker.class.getName());
private BrokerService broker; // the broker itself.
private void configureBroker() throws Exception {
// websocket connector for javascript apps
broker.addConnector(Info.MESSAGING.BROKER_STOMP);
// websocket connector for javascript apps
broker.addConnector(Info.MESSAGING.BROKER_WEBSOCKET);
// broker setup
broker.setPersistent(false); // do not save messages on disk
broker.setUseJmx(false);
}
/**
* {@inheritDoc}
*
* @throws java.lang.Exception
*/
@Override
protected void start() throws Exception {
LOG.info("Creating new messaging broker");
this.broker = new BrokerService();
LOG.info("Configuring messaging broker");
configureBroker();
LOG.info("Starting messaging broker");
broker.start();
}
/**
* {@inheritDoc}
*
* @throws java.lang.Exception
*/
@Override
protected void stop() throws Exception {
LOG.info("Stopping messaging broker");
broker.stop();
}
}