use of nl.nn.adapterframework.senders.IbisLocalSender in project iaf by ibissource.
the class DefaultIbisManager method handleAdapter.
/**
* Utility function to give commands to Adapters and Receivers
*/
public void handleAdapter(String action, String configurationName, String adapterName, String receiverName, String commandIssuedBy, boolean isAdmin) {
if (action.equalsIgnoreCase("STOPADAPTER")) {
if (adapterName.equals("*ALL*")) {
if (configurationName.equals("*ALL*")) {
log.info("Stopping all adapters on request of [" + commandIssuedBy + "]");
for (Configuration configuration : configurations) {
stopAdapters(configuration);
}
} else {
log.info("Stopping all adapters for configuration [" + configurationName + "] on request of [" + commandIssuedBy + "]");
stopAdapters(getConfiguration(configurationName));
}
} else {
for (Configuration configuration : configurations) {
if (configuration.getRegisteredAdapter(adapterName) != null) {
log.info("Stopping adapter [" + adapterName + "], on request of [" + commandIssuedBy + "]");
configuration.getRegisteredAdapter(adapterName).stopRunning();
}
}
}
} else if (action.equalsIgnoreCase("STARTADAPTER")) {
if (adapterName.equals("*ALL*")) {
if (configurationName.equals("*ALL*")) {
log.info("Starting all adapters on request of [" + commandIssuedBy + "]");
for (Configuration configuration : configurations) {
startAdapters(configuration);
}
} else {
log.info("Starting all adapters for configuration [" + configurationName + "] on request of [" + commandIssuedBy + "]");
startAdapters(getConfiguration(configurationName));
}
} else {
try {
for (Configuration configuration : configurations) {
if (configuration.getRegisteredAdapter(adapterName) != null) {
log.info("Starting adapter [" + adapterName + "] on request of [" + commandIssuedBy + "]");
configuration.getRegisteredAdapter(adapterName).startRunning();
}
}
} catch (Exception e) {
log.error("error in execution of command [" + action + "] for adapter [" + adapterName + "]", e);
// errors.add("", new ActionError("errors.generic", e.toString()));
}
}
} else if (action.equalsIgnoreCase("STOPRECEIVER")) {
for (Configuration configuration : configurations) {
if (configuration.getRegisteredAdapter(adapterName) != null) {
IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
IReceiver receiver = adapter.getReceiverByName(receiverName);
receiver.stopRunning();
log.info("receiver [" + receiverName + "] stopped by webcontrol on request of " + commandIssuedBy);
}
}
} else if (action.equalsIgnoreCase("STARTRECEIVER")) {
for (Configuration configuration : configurations) {
if (configuration.getRegisteredAdapter(adapterName) != null) {
IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
IReceiver receiver = adapter.getReceiverByName(receiverName);
receiver.startRunning();
log.info("receiver [" + receiverName + "] started by " + commandIssuedBy);
}
}
} else if (action.equalsIgnoreCase("RELOAD")) {
String msg = "Reload configuration [" + configurationName + "] on request of [" + commandIssuedBy + "]";
log.info(msg);
secLog.info(msg);
ibisContext.reload(configurationName);
} else if (action.equalsIgnoreCase("FULLRELOAD")) {
if (isAdmin) {
String msg = "Full reload on request of [" + commandIssuedBy + "]";
log.info(msg);
secLog.info(msg);
ibisContext.fullReload();
} else {
log.warn("Full reload not allowed for [" + commandIssuedBy + "]");
}
} else if (action.equalsIgnoreCase("INCTHREADS")) {
for (Configuration configuration : configurations) {
if (configuration.getRegisteredAdapter(adapterName) != null) {
IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
IReceiver receiver = adapter.getReceiverByName(receiverName);
if (receiver instanceof IThreadCountControllable) {
IThreadCountControllable tcc = (IThreadCountControllable) receiver;
if (tcc.isThreadCountControllable()) {
tcc.increaseThreadCount();
}
}
log.info("receiver [" + receiverName + "] increased threadcount on request of " + commandIssuedBy);
}
}
} else if (action.equalsIgnoreCase("DECTHREADS")) {
for (Configuration configuration : configurations) {
if (configuration.getRegisteredAdapter(adapterName) != null) {
IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
IReceiver receiver = adapter.getReceiverByName(receiverName);
if (receiver instanceof IThreadCountControllable) {
IThreadCountControllable tcc = (IThreadCountControllable) receiver;
if (tcc.isThreadCountControllable()) {
tcc.decreaseThreadCount();
}
}
log.info("receiver [" + receiverName + "] decreased threadcount on request of " + commandIssuedBy);
}
}
} else if (action.equalsIgnoreCase("SENDMESSAGE")) {
try {
// send job
IbisLocalSender localSender = new IbisLocalSender();
localSender.setJavaListener(receiverName);
localSender.setIsolated(false);
localSender.setName("AdapterJob");
localSender.configure();
localSender.open();
try {
localSender.sendMessage(null, "");
} finally {
localSender.close();
}
} catch (Exception e) {
log.error("Error while sending message (as part of scheduled job execution)", e);
}
} else if (action.equalsIgnoreCase("MOVEMESSAGE")) {
for (Configuration configuration : configurations) {
if (configuration.getRegisteredAdapter(adapterName) != null) {
IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
IReceiver receiver = adapter.getReceiverByName(receiverName);
if (receiver instanceof ReceiverBase) {
ReceiverBase rb = (ReceiverBase) receiver;
ITransactionalStorage errorStorage = rb.getErrorStorage();
if (errorStorage == null) {
log.error("action [" + action + "] is only allowed for receivers with an ErrorStorage");
} else {
if (errorStorage instanceof JdbcTransactionalStorage) {
JdbcTransactionalStorage jdbcErrorStorage = (JdbcTransactionalStorage) rb.getErrorStorage();
IListener listener = rb.getListener();
if (listener instanceof EsbJmsListener) {
EsbJmsListener esbJmsListener = (EsbJmsListener) listener;
EsbUtils.receiveMessageAndMoveToErrorStorage(esbJmsListener, jdbcErrorStorage);
} else {
log.error("action [" + action + "] is currently only allowed for EsbJmsListener, not for type [" + listener.getClass().getName() + "]");
}
} else {
log.error("action [" + action + "] is currently only allowed for JdbcTransactionalStorage, not for type [" + errorStorage.getClass().getName() + "]");
}
}
}
}
}
}
}
use of nl.nn.adapterframework.senders.IbisLocalSender in project iaf by ibissource.
the class ServiceJob method execute.
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
log.info("executing" + getLogPrefix(context));
JobDataMap dataMap = context.getJobDetail().getJobDataMap();
String serviceName = dataMap.getString(JAVALISTENER_KEY);
Message message = new Message(dataMap.getString(MESSAGE_KEY));
// send job
IbisLocalSender localSender = new IbisLocalSender();
localSender.setJavaListener(serviceName);
localSender.setIsolated(false);
localSender.setName("ServiceJob");
localSender.configure();
localSender.open();
try {
localSender.sendMessage(message, null);
} finally {
localSender.close();
}
} catch (Exception e) {
log.error("JobExecutionException while running " + getLogPrefix(context), e);
throw new JobExecutionException(e, false);
}
log.debug(getLogPrefix(context) + "completed");
}
use of nl.nn.adapterframework.senders.IbisLocalSender in project iaf by ibissource.
the class JobDef method executeSendMessageJob.
private void executeSendMessageJob(IbisManager ibisManager) {
try {
// send job
IbisLocalSender localSender = new IbisLocalSender();
localSender.setJavaListener(receiverName);
localSender.setIsolated(false);
localSender.setName("AdapterJob");
if (getInterval() == 0) {
localSender.setDependencyTimeOut(-1);
}
if (StringUtils.isNotEmpty(adapterName)) {
IAdapter iAdapter = ibisManager.getRegisteredAdapter(adapterName);
Configuration configuration = iAdapter.getConfiguration();
localSender.setConfiguration(configuration);
}
localSender.configure();
localSender.open();
try {
localSender.sendMessage(null, "");
} finally {
localSender.close();
}
} catch (Exception e) {
String msg = "Error while sending message (as part of scheduled job execution): " + e.getMessage();
getMessageKeeper().add(msg, MessageKeeperMessage.ERROR_LEVEL);
log.error(getLogPrefix() + msg, e);
}
}
Aggregations