Issue #1407 EventBus changes to support sending notifications for subscription verification
Change-Id: I8f979e44520e32fa908aa700bb0c93596a2dd820 Former-commit-id:3d900240b7
[formerly8b942c31dd
[formerly 12b51905d9b710ebc6fa54346d82cad9178b0bba]] Former-commit-id:8b942c31dd
Former-commit-id:79fa61bb8a
This commit is contained in:
parent
e0e596120c
commit
6fd82e22bc
3 changed files with 167 additions and 28 deletions
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.edex.event;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import com.google.common.eventbus.AsyncEventBus;
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
|
||||
/**
|
||||
* {@link GoogleEventBusFactory} implementation that creates an asynchronous
|
||||
* {@link EventBus}. Intentionally package-private as it should only be used
|
||||
* within this package, and not part of the public API.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Dec 11, 2012 1407 djohnson Moved in from EventBus.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author djohnson
|
||||
* @version 1.0
|
||||
*/
|
||||
class AsynchronousEventBusFactory implements GoogleEventBusFactory {
|
||||
|
||||
|
||||
private static final IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(AsynchronousEventBusFactory.class);
|
||||
|
||||
private static final int DEFAULT_THREAD_COUNT = 15;
|
||||
|
||||
private static final String EVENT_BUS_THREAD_COUNT_PROPERTY = "eventBusThreadCount";
|
||||
|
||||
static final String EVENT_BUS_NAME = "EventBus";
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public EventBus getEventBus() {
|
||||
int threadCount = 15;
|
||||
try {
|
||||
threadCount = Integer.getInteger(EVENT_BUS_THREAD_COUNT_PROPERTY,
|
||||
DEFAULT_THREAD_COUNT);
|
||||
} catch (Exception e) {
|
||||
final String logMessage = String
|
||||
.format("Unable to set thread pool size from property %s; defaulting size to %s.",
|
||||
EVENT_BUS_THREAD_COUNT_PROPERTY, threadCount);
|
||||
statusHandler.error(logMessage, e);
|
||||
}
|
||||
return new AsyncEventBus(EVENT_BUS_NAME,
|
||||
Executors.newFixedThreadPool(threadCount));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +1,7 @@
|
|||
package com.raytheon.uf.edex.event;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import com.google.common.eventbus.AsyncEventBus;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.raytheon.uf.common.event.Event;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -19,6 +15,7 @@ import com.raytheon.uf.common.status.UFStatus;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 11, 2012 1261 djohnson Add SW history, create constants for fields,
|
||||
* add unregister.
|
||||
* Dec 11, 2012 1407 djohnson Separate the creation of the Google EventBus from the wrapper class.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -26,59 +23,72 @@ import com.raytheon.uf.common.status.UFStatus;
|
|||
* @version 1.0
|
||||
*/
|
||||
public class EventBus {
|
||||
private static final IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(EventBus.class);
|
||||
|
||||
private static final EventBus instance = new EventBus();
|
||||
@VisibleForTesting
|
||||
static GoogleEventBusFactory eventBusFactory = new AsynchronousEventBusFactory();
|
||||
|
||||
private static final AsyncEventBus asyncEventBus;
|
||||
static {
|
||||
int threadCount = 15;
|
||||
try {
|
||||
threadCount = Integer.parseInt(System.getProperty(
|
||||
"eventBusThreadCount", "15"));
|
||||
} catch (Exception e) {
|
||||
statusHandler
|
||||
.error("Unable to set thread pool size from property eventBusThreadCount; defaulting size to "
|
||||
+ threadCount + ".", e);
|
||||
}
|
||||
asyncEventBus = new AsyncEventBus("EventBus",
|
||||
Executors.newFixedThreadPool(threadCount));
|
||||
/**
|
||||
* Holder class which allows safe, concurrent, and on-demand creation of the
|
||||
* EventBus. It also enforces the singleton contract.
|
||||
*/
|
||||
private static class EventBusHolder {
|
||||
private static com.google.common.eventbus.EventBus eventBus = eventBusFactory
|
||||
.getEventBus();
|
||||
|
||||
private static final EventBus instance = new EventBus(eventBus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the same instance of the data delivery event bus
|
||||
* Returns the singleton instance of the data delivery event bus
|
||||
*
|
||||
* @return
|
||||
* @return the singleton instance
|
||||
*/
|
||||
public static EventBus getInstance() {
|
||||
return instance;
|
||||
return EventBusHolder.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* The actual Google EventBus being wrapped.
|
||||
*/
|
||||
private final com.google.common.eventbus.EventBus googleEventBus;
|
||||
|
||||
/**
|
||||
* Constructor that accepts a Google EventBus.
|
||||
*
|
||||
* @param eventBus
|
||||
* the Google EventBus
|
||||
*/
|
||||
private EventBus(com.google.common.eventbus.EventBus eventBus) {
|
||||
this.googleEventBus = eventBus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an object with the event bus.
|
||||
*
|
||||
* @param subscriber
|
||||
* the subscriber to register
|
||||
*/
|
||||
public void register(Object subscriber) {
|
||||
asyncEventBus.register(subscriber);
|
||||
this.googleEventBus.register(subscriber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Publishes events for all subscribers to receive
|
||||
*
|
||||
* @param event
|
||||
* the event
|
||||
*/
|
||||
public void publish(Event event) {
|
||||
asyncEventBus.post(event);
|
||||
this.googleEventBus.post(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister an object with the event bus.
|
||||
*
|
||||
* @param instance2
|
||||
* @param subscriber
|
||||
* the object subscribed to the event buss
|
||||
*/
|
||||
public void unregister(Object subscriber) {
|
||||
asyncEventBus.unregister(subscriber);
|
||||
this.googleEventBus.unregister(subscriber);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.edex.event;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
|
||||
/**
|
||||
* Interface that defines how to get an {@link EventBus} for system use.
|
||||
* Intentionally package-private as it should only be used within this package,
|
||||
* and not part of the public API.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Dec 11, 2012 1407 djohnson Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author djohnson
|
||||
* @version 1.0
|
||||
*/
|
||||
interface GoogleEventBusFactory {
|
||||
|
||||
/**
|
||||
* Get the Google {@link EventBus} that will be wrapped with an AWIPS class.
|
||||
*
|
||||
* @return the {@link EventBus}
|
||||
*/
|
||||
EventBus getEventBus();
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue