
org.hawkular.btm.server.jms.ProcessorMDB Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2015-2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed 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.hawkular.btm.server.jms;
import java.util.List;
import org.hawkular.btm.api.services.Publisher;
import org.hawkular.btm.server.api.task.Handler;
import org.hawkular.btm.server.api.task.ProcessingUnit;
import org.hawkular.btm.server.api.task.Processor;
/**
* @author gbrown
*/
public abstract class ProcessorMDB extends RetryCapableMDB {
private Processor processor;
private Publisher publisher;
/**
* @return the processor
*/
public Processor getProcessor() {
return processor;
}
/**
* @param processor the processor to set
*/
public void setProcessor(Processor processor) {
this.processor = processor;
}
/**
* @return the publisher
*/
public Publisher getPublisher() {
return publisher;
}
/**
* @param publisher the publisher to set
*/
public void setPublisher(Publisher publisher) {
this.publisher = publisher;
}
/**
* {@inheritDoc}
*/
@Override
protected void process(String tenantId, List items, int retryCount) throws Exception {
ProcessingUnit pu =
new ProcessingUnit();
pu.setProcessor(getProcessor());
pu.setRetryCount(retryCount);
pu.setResultHandler(new Handler() {
@Override
public void handle(String tenantId, List items) throws Exception {
getPublisher().publish(tenantId, items, getPublisher().getInitialRetryCount(),
getProcessor().getDeliveryDelay(items));
}
});
pu.setRetryHandler(new Handler() {
@Override
public void handle(String tenantId, List items) throws Exception {
getRetryPublisher().publish(tenantId, items, pu.getRetryCount() - 1,
getProcessor().getRetryDelay(items));
}
});
pu.handle(tenantId, items);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy