use of nl.nn.adapterframework.core.IReceiver 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.core.IReceiver in project iaf by ibissource.
the class JobDef method recoverAdapters.
private void recoverAdapters(IbisManager ibisManager) {
int countAdapter = 0;
int countAdapterStateStarted = 0;
int countReceiver = 0;
int countReceiverStateStarted = 0;
for (IAdapter iAdapter : ibisManager.getRegisteredAdapters()) {
countAdapter++;
if (iAdapter instanceof Adapter) {
Adapter adapter = (Adapter) iAdapter;
RunStateEnum adapterRunState = adapter.getRunState();
if (adapterRunState.equals(RunStateEnum.ERROR)) {
log.debug("trying to recover adapter [" + adapter.getName() + "]");
try {
adapter.setRecover(true);
adapter.configure();
} catch (ConfigurationException e) {
// do nothing
log.warn("error during recovering adapter [" + adapter.getName() + "]: " + e.getMessage());
} finally {
adapter.setRecover(false);
}
if (adapter.configurationSucceeded()) {
adapter.stopRunning();
int count = 10;
while (count-- >= 0 && !adapter.getRunState().equals(RunStateEnum.STOPPED)) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// do nothing
}
}
}
// check for start is in method startRunning in Adapter self
if (adapter.isAutoStart()) {
adapter.startRunning();
}
log.debug("finished recovering adapter [" + adapter.getName() + "]");
}
String message = "adapter [" + adapter.getName() + "] has state [" + adapterRunState + "]";
adapterRunState = adapter.getRunState();
if (adapterRunState.equals(RunStateEnum.STARTED)) {
countAdapterStateStarted++;
heartbeatLog.info(message);
} else if (adapterRunState.equals(RunStateEnum.ERROR)) {
heartbeatLog.error(message);
} else {
heartbeatLog.warn(message);
}
for (Iterator receiverIt = adapter.getReceiverIterator(); receiverIt.hasNext(); ) {
countReceiver++;
IReceiver iReceiver = (IReceiver) receiverIt.next();
if (iReceiver instanceof ReceiverBase) {
ReceiverBase receiver = (ReceiverBase) iReceiver;
RunStateEnum receiverRunState = receiver.getRunState();
if (!adapterRunState.equals(RunStateEnum.ERROR) && receiverRunState.equals(RunStateEnum.ERROR)) {
log.debug("trying to recover receiver [" + receiver.getName() + "] of adapter [" + adapter.getName() + "]");
try {
if (receiver != null) {
receiver.setRecover(true);
}
adapter.configureReceiver(receiver);
} finally {
if (receiver != null) {
receiver.setRecover(false);
}
}
if (receiver != null) {
if (receiver.configurationSucceeded()) {
receiver.stopRunning();
int count = 10;
while (count-- >= 0 && !receiver.getRunState().equals(RunStateEnum.STOPPED)) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
log.debug("Interrupted waiting for receiver to stop", e);
}
}
}
// check for start is in method startRunning in
// ReceiverBase self
receiver.startRunning();
log.debug("finished recovering receiver [" + receiver.getName() + "] of adapter [" + adapter.getName() + "]");
}
}
receiverRunState = receiver.getRunState();
message = "receiver [" + receiver.getName() + "] of adapter [" + adapter.getName() + "] has state [" + receiverRunState + "]";
if (receiverRunState.equals(RunStateEnum.STARTED)) {
countReceiverStateStarted++;
heartbeatLog.info(message);
} else if (receiverRunState.equals(RunStateEnum.ERROR)) {
heartbeatLog.error(message);
} else {
heartbeatLog.warn(message);
}
} else {
log.warn("will not try to recover receiver [" + iReceiver.getName() + "] of adapter [" + adapter.getName() + "], is not of type Receiver but [" + iAdapter.getClass().getName() + "]");
}
}
} else {
log.warn("will not try to recover adapter [" + iAdapter.getName() + "], is not of type Adapter but [" + iAdapter.getClass().getName() + "]");
}
}
heartbeatLog.info("[" + countAdapterStateStarted + "/" + countAdapter + "] adapters and [" + countReceiverStateStarted + "/" + countReceiver + "] receivers have state [" + RunStateEnum.STARTED + "]");
}
use of nl.nn.adapterframework.core.IReceiver in project iaf by ibissource.
the class EsbJmsListenerChecker method doCheck.
public static void doCheck(IbisManager ibisManager, PlatformTransactionManager txManager, String logPrefix) {
long idleTimeout = AppConstants.getInstance().getInt("check.esbJmsListeners.idleTimeout", 300) * 1000;
for (Configuration configuration : ibisManager.getConfigurations()) {
String msg;
List<String> jmsRealmNames = new ArrayList<String>();
for (IAdapter adapter : configuration.getRegisteredAdapters()) {
if (adapter instanceof Adapter) {
for (Iterator receiverIt = adapter.getReceiverIterator(); receiverIt.hasNext(); ) {
IReceiver receiver = (IReceiver) receiverIt.next();
if (receiver instanceof ReceiverBase) {
ReceiverBase rb = (ReceiverBase) receiver;
if (rb.getRunState().equals(RunStateEnum.STARTED)) {
// if (true) {
long lastMessageDate = rb.getLastMessageDate();
if (lastMessageDate == 0 || System.currentTimeMillis() - lastMessageDate > idleTimeout) {
IListener listener = rb.getListener();
if (listener instanceof EsbJmsListener) {
EsbJmsListener esbJmsListener = (EsbJmsListener) listener;
if (esbJmsListener.getMessageProtocol().equals("FF")) {
Object managedConnectionFactory = null;
try {
managedConnectionFactory = esbJmsListener.getManagedConnectionFactory();
if (managedConnectionFactory == null) {
msg = logPrefix + "could not get managed connection factory";
warn(adapter, msg);
} else {
String contextFactoryClassname = getContextFactoryClassname(managedConnectionFactory);
String providerURL = getProviderURL(managedConnectionFactory);
String authDataAlias = getAuthDataAlias(managedConnectionFactory);
String username = null;
String password = null;
msg = logPrefix + "found esbJmsListener [" + esbJmsListener.getName() + "] with managedConnectionFactoryClassname [" + managedConnectionFactory.getClass().getName() + "] having contextFactoryClassname [" + contextFactoryClassname + "] providerURL [" + providerURL + "] authDataAlias [" + authDataAlias + "]";
if (authDataAlias != null) {
CredentialFactory cf = new CredentialFactory(authDataAlias, null, null);
username = cf.getUsername();
password = cf.getPassword();
}
if (contextFactoryClassname != null && contextFactoryClassname.equals("com.tibco.tibjms.naming.TibjmsInitialContextFactory")) {
log.debug(msg + ", checking...");
long age = getTibcoQueueFirstMessageAge(providerURL, authDataAlias, username, password, esbJmsListener.getPhysicalDestinationShortName(), esbJmsListener.getMessageSelector());
if (age > idleTimeout) {
msg = logPrefix + "most probably esbJmsListener [" + esbJmsListener.getName() + "] has lost connection with queue [" + esbJmsListener.getPhysicalDestinationShortName() + "]";
warn(adapter, msg);
}
} else {
log.debug(msg + ", ignoring...");
}
}
} catch (Throwable t) {
msg = logPrefix + "exception on checking queue [" + esbJmsListener.getPhysicalDestinationShortName() + "]";
warn(adapter, msg, t);
}
}
}
}
}
}
}
}
}
}
}
use of nl.nn.adapterframework.core.IReceiver in project iaf by ibissource.
the class RestListenerUtils method doRestartShowConfigurationStatus.
private static boolean doRestartShowConfigurationStatus(ServletContext servletContext) {
String attributeKey = AppConstants.getInstance().getProperty(ConfigurationServlet.KEY_CONTEXT);
IbisContext ibisContext = (IbisContext) servletContext.getAttribute(attributeKey);
IAdapter adapter = null;
IReceiver receiver = null;
if (ibisContext != null) {
IbisManager ibisManager = ibisContext.getIbisManager();
if (ibisManager != null) {
Configuration configuration = ibisManager.getConfiguration(SHOW_CONFIG_STATUS_CONFIGURATION);
if (configuration != null) {
adapter = configuration.getRegisteredAdapter(SHOW_CONFIG_STATUS_ADAPTER);
if (adapter instanceof Adapter) {
receiver = ((Adapter) adapter).getReceiverByNameAndListener(SHOW_CONFIG_STATUS_RECEIVER, RestListener.class);
}
}
}
}
if (adapter == null) {
log.info("could not restart ShowConfigurationStatus, adapter [" + SHOW_CONFIG_STATUS_ADAPTER + "] not found");
return false;
}
if (receiver == null) {
log.info("could not restart ShowConfigurationStatus, receiver [" + SHOW_CONFIG_STATUS_RECEIVER + "] not found");
return false;
}
RunStateEnum adapterStatus = adapter.getRunState();
RunStateEnum receiverStatus = receiver.getRunState();
if (RunStateEnum.STARTED.equals(adapterStatus) && RunStateEnum.STARTED.equals(receiverStatus)) {
log.info("ShowConfigurationStatus is already running, will restart it");
ibisContext.getIbisManager().handleAdapter("stopadapter", SHOW_CONFIG_STATUS_CONFIGURATION, SHOW_CONFIG_STATUS_ADAPTER, SHOW_CONFIG_STATUS_RECEIVER, "system", true);
}
if (RunStateEnum.STOPPED.equals(adapterStatus)) {
log.info("starting adapter of ShowConfigurationStatus");
ibisContext.getIbisManager().handleAdapter("startadapter", SHOW_CONFIG_STATUS_CONFIGURATION, SHOW_CONFIG_STATUS_ADAPTER, SHOW_CONFIG_STATUS_RECEIVER, "system", true);
return true;
} else {
if (RunStateEnum.STARTED.equals(adapterStatus) && RunStateEnum.STOPPED.equals(receiverStatus)) {
log.info("starting receiver of ShowConfigurationStatus");
ibisContext.getIbisManager().handleAdapter("startreceiver", SHOW_CONFIG_STATUS_CONFIGURATION, SHOW_CONFIG_STATUS_ADAPTER, SHOW_CONFIG_STATUS_RECEIVER, "system", true);
return true;
}
}
log.info("could not restart ShowConfigurationStatus with adapter status [" + adapterStatus + "] and receiver status [" + receiverStatus + "]");
return false;
}
use of nl.nn.adapterframework.core.IReceiver in project iaf by ibissource.
the class DefaultIbisManager method unload.
private void unload(Configuration configuration) {
configuration.setUnloadInProgressOrDone(true);
while (configuration.getStartAdapterThreads().size() > 0) {
log.debug("Waiting for start threads to end: " + configuration.getStartAdapterThreads());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
log.warn("Interrupted waiting for start threads to end", e);
}
}
stopAdapters(configuration);
while (configuration.getStopAdapterThreads().size() > 0) {
log.debug("Waiting for stop threads to end: " + configuration.getStopAdapterThreads());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
log.warn("Interrupted waiting for stop threads to end", e);
}
}
// destroy all jmsContainers
for (int i = 0; i < configuration.getRegisteredAdapters().size(); i++) {
IAdapter adapter = configuration.getRegisteredAdapter(i);
Iterator recIt = adapter.getReceiverIterator();
if (recIt.hasNext()) {
while (recIt.hasNext()) {
IReceiver receiver = (IReceiver) recIt.next();
if (receiver instanceof ReceiverBase) {
ReceiverBase rb = (ReceiverBase) receiver;
IListener listener = rb.getListener();
if (listener instanceof PushingJmsListener) {
PushingJmsListener pjl = (PushingJmsListener) listener;
pjl.destroy();
}
}
}
}
}
while (configuration.getRegisteredAdapters().size() > 0) {
IAdapter adapter = configuration.getRegisteredAdapter(0);
AdapterService adapterService = configuration.getAdapterService();
adapterService.unRegisterAdapter(adapter);
}
configurations.remove(configuration);
}
Aggregations