Package ru.bitel.bgbilling.kernel.event
Class EventWorker
java.lang.Object
ru.bitel.common.worker.WorkerTask<EventListenerContext>
ru.bitel.bgbilling.kernel.event.EventWorker
- All Implemented Interfaces:
java.lang.Runnable,EventListener<ru.bitel.bgbilling.kernel.event.common.Event>
- Direct Known Subclasses:
AsyncEventWorker
public abstract class EventWorker extends ru.bitel.common.worker.WorkerTask<EventListenerContext> implements EventListener<ru.bitel.bgbilling.kernel.event.common.Event>
Обрабочтик событий. Выбирает события из MessageConsumer и задает методы для обрабоотки этих событий(реализуются в потомках)
-
Nested Class Summary
Nested classes/interfaces inherited from class ru.bitel.common.worker.WorkerTask
ru.bitel.common.worker.WorkerTask.BlockingExecutionHandler -
Field Summary
Fields Modifier and Type Field Description protected longbatchWaitСколько ждать следующего задания/события, прежде чем прекратить цикл (прекратитьdoTasks()), в мс.protected ru.bitel.bgbilling.kernel.event.AbstractConsumerconsumerprotected longerrorPauseДлительность паузы после возникновения ошибки, в мс.protected intmoduleIdprotected booleanworkingFields inherited from class ru.bitel.common.worker.WorkerTask
context -
Constructor Summary
Constructors Modifier Constructor Description protectedEventWorker(int moduleId)EventWorker(EventProcessor ep, java.lang.Class<? extends ru.bitel.bgbilling.kernel.event.common.Event> clazz, int moduleId, int pluginId, java.lang.String query)EventWorker(EventProcessor ep, java.lang.String destination, int moduleId, int pluginId, java.lang.String query, boolean autoAcknowledge, java.lang.Class<?>... clazz) -
Method Summary
Modifier and Type Method Description abstract java.lang.ObjectdoTask(java.lang.Object task)Выполнение одной задачи (события).booleandoTasks()Выполнение задач (одной или нескольких, с ожиданием новых в теченииbatchWait), нужно вызывать изrunWorker().protected booleaninternalDoTask(java.lang.Object task)protected intinternalRunWorker(long timeout, boolean wait)voidnotify(ru.bitel.bgbilling.kernel.event.common.Event e, EventListenerContext ctx)protected java.lang.Objectpoll(long timeout)protected java.lang.ObjectpollFirstTask()protected voidrunImpl()protected abstract booleanrunWorker()Вызывается, когда появляются задачи.voidsetConsumer(java.lang.Class<? extends ru.bitel.bgbilling.kernel.event.common.Event> clazz, java.lang.String query)voidshutdown()Methods inherited from class ru.bitel.common.worker.WorkerTask
newBlockingFixedThreadPool, newFixedThreadPool, newFixedThreadPool, newScheduledThreadPool, run, runSync, runSync, setContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
consumer
protected ru.bitel.bgbilling.kernel.event.AbstractConsumer consumer -
batchWait
protected long batchWaitСколько ждать следующего задания/события, прежде чем прекратить цикл (прекратитьdoTasks()), в мс. -
errorPause
protected long errorPauseДлительность паузы после возникновения ошибки, в мс. -
working
protected volatile boolean working -
moduleId
protected final int moduleId
-
-
Constructor Details
-
EventWorker
protected EventWorker(int moduleId) throws ru.bitel.bgbilling.common.BGException- Throws:
ru.bitel.bgbilling.common.BGException
-
EventWorker
public EventWorker(EventProcessor ep, java.lang.Class<? extends ru.bitel.bgbilling.kernel.event.common.Event> clazz, int moduleId, int pluginId, java.lang.String query) throws ru.bitel.bgbilling.common.BGException- Throws:
ru.bitel.bgbilling.common.BGException
-
EventWorker
public EventWorker(EventProcessor ep, java.lang.String destination, int moduleId, int pluginId, java.lang.String query, boolean autoAcknowledge, java.lang.Class<?>... clazz) throws ru.bitel.bgbilling.common.BGException- Throws:
ru.bitel.bgbilling.common.BGException
-
-
Method Details
-
setConsumer
public void setConsumer(java.lang.Class<? extends ru.bitel.bgbilling.kernel.event.common.Event> clazz, java.lang.String query) throws ru.bitel.bgbilling.common.BGException- Throws:
ru.bitel.bgbilling.common.BGException
-
runImpl
protected void runImpl() throws java.lang.Exception- Specified by:
runImplin classru.bitel.common.worker.WorkerTask<EventListenerContext>- Throws:
java.lang.Exception
-
internalRunWorker
protected int internalRunWorker(long timeout, boolean wait)- Parameters:
timeout-wait-- Returns:
- -1, если произошла ошибка; 0, если ничего не было сделано, 1, если нормально выполнено одно или более заданий.
-
pollFirstTask
protected java.lang.Object pollFirstTask() -
poll
protected java.lang.Object poll(long timeout) throws ru.bitel.bgbilling.common.BGException- Throws:
ru.bitel.bgbilling.common.BGException
-
doTasks
public boolean doTasks() throws ru.bitel.bgbilling.common.BGExceptionВыполнение задач (одной или нескольких, с ожиданием новых в теченииbatchWait), нужно вызывать изrunWorker().- Returns:
- Throws:
ru.bitel.bgbilling.common.BGException
-
internalDoTask
protected boolean internalDoTask(java.lang.Object task) throws javax.jms.JMSException, javax.xml.bind.JAXBException, ru.bitel.bgbilling.common.BGException- Throws:
javax.jms.JMSExceptionjavax.xml.bind.JAXBExceptionru.bitel.bgbilling.common.BGException
-
runWorker
protected abstract boolean runWorker() throws ru.bitel.bgbilling.common.BGExceptionВызывается, когда появляются задачи. Внутри данного метода нужно вызватьdoTasks(), который выполняет последовательно появившиеся задачи. А перед и после вызоваdoTasks()можно инициализировать и освободить DAO.- Returns:
- Throws:
ru.bitel.bgbilling.common.BGException
-
notify
public void notify(ru.bitel.bgbilling.kernel.event.common.Event e, EventListenerContext ctx) throws ru.bitel.bgbilling.common.BGException- Specified by:
notifyin interfaceEventListener<ru.bitel.bgbilling.kernel.event.common.Event>- Throws:
ru.bitel.bgbilling.common.BGException
-
doTask
public abstract java.lang.Object doTask(java.lang.Object task) throws ru.bitel.bgbilling.common.BGExceptionВыполнение одной задачи (события).- Parameters:
task-- Returns:
- обычно null.
- Throws:
ru.bitel.bgbilling.common.BGException
-
shutdown
public void shutdown() throws ru.bitel.bgbilling.common.BGException- Throws:
ru.bitel.bgbilling.common.BGException
-