use of nl.nn.adapterframework.util.RunStateEnum in project iaf by ibissource.
the class ReceiverBase method startRunning.
public void startRunning() {
try {
// may only be executed when the adapter is started.
if (adapter != null) {
RunStateEnum adapterRunState = adapter.getRunState();
if (!adapterRunState.equals(RunStateEnum.STARTED)) {
log.warn(getLogPrefix() + "on adapter [" + adapter.getName() + "] was tried to start, but the adapter is in state [" + adapterRunState + "]. Ignoring command.");
adapter.getMessageKeeper().add("ignored start command on [" + getName() + "]; adapter is in state [" + adapterRunState + "]");
return;
}
}
// See also Adapter.startRunning()
if (!configurationSucceeded) {
log.error("configuration of receiver [" + getName() + "] did not succeed, therefore starting the receiver is not possible");
warn("configuration did not succeed. Starting the receiver [" + getName() + "] is not possible");
runState.setRunState(RunStateEnum.ERROR);
return;
}
if (adapter.getConfiguration().isUnloadInProgressOrDone()) {
log.error("configuration of receiver [" + getName() + "] unload in progress or done, therefore starting the receiver is not possible");
warn("configuration unload in progress or done. Starting the receiver [" + getName() + "] is not possible");
return;
}
synchronized (runState) {
RunStateEnum currentRunState = getRunState();
if (!currentRunState.equals(RunStateEnum.STOPPED)) {
String msg = getLogPrefix() + "currently in state [" + currentRunState + "], ignoring start() command";
warn(msg);
return;
}
runState.setRunState(RunStateEnum.STARTING);
}
String msg = (getLogPrefix() + "starts listening");
log.info(msg);
if (adapter != null) {
adapter.getMessageKeeper().add(msg);
}
openAllResources();
runState.setRunState(RunStateEnum.STARTED);
} catch (Throwable t) {
error(getLogPrefix() + "error occured while starting", t);
runState.setRunState(RunStateEnum.ERROR);
}
}
use of nl.nn.adapterframework.util.RunStateEnum 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.util.RunStateEnum in project iaf by ibissource.
the class IbisTester method testStartAdapters.
public boolean testStartAdapters() {
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.INFO);
// remove AppConstants because it can be present from another JUnit test
AppConstants.removeInstance();
appConstants = AppConstants.getInstance();
webAppPath = getWebContentDirectory();
String projectBaseDir = Misc.getProjectBaseDir();
appConstants.put("project.basedir", projectBaseDir);
debug("***set property with name [project.basedir] and value [" + projectBaseDir + "]***");
appConstants.put("create.dbscript.location", "create_database_h2.sql");
// appConstants.put("validators.disabled", "true");
// appConstants.put("xmlValidator.lazyInit", "true");
// appConstants.put("xmlValidator.maxInitialised", "200");
ibisContext = new IbisContext();
long configLoadStartTime = System.currentTimeMillis();
ibisContext.init();
long configLoadEndTime = System.currentTimeMillis();
debug("***configuration loaded in [" + (configLoadEndTime - configLoadStartTime) + "] msec***");
int adaptersStarted = 0;
int adaptersCount = 0;
List<IAdapter> registeredAdapters = ibisContext.getIbisManager().getRegisteredAdapters();
for (IAdapter adapter : registeredAdapters) {
adaptersCount++;
RunStateEnum runState = adapter.getRunState();
if (!(RunStateEnum.STARTED).equals(runState)) {
debug("adapter [" + adapter.getName() + "] has state [" + runState + "], will retry...");
int count = 30;
while (count-- > 0 && !(RunStateEnum.STARTED).equals(runState)) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
runState = adapter.getRunState();
if (!(RunStateEnum.STARTED).equals(runState)) {
debug("adapter [" + adapter.getName() + "] has state [" + runState + "], retries left [" + count + "]");
} else {
debug("adapter [" + adapter.getName() + "] has state [" + runState + "]");
}
}
} else {
debug("adapter [" + adapter.getName() + "] has state [" + runState + "]");
}
if ((RunStateEnum.STARTED).equals(runState)) {
adaptersStarted++;
} else {
error("adapter [" + adapter.getName() + "] has state [" + runState + "]");
}
}
String msg = "adapters started [" + adaptersStarted + "] from [" + adaptersCount + "]";
if (adaptersCount == adaptersStarted) {
debug(msg);
return true;
} else {
error(msg);
return false;
}
}
use of nl.nn.adapterframework.util.RunStateEnum 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.util.RunStateEnum in project iaf by ibissource.
the class ShowConfigurationStatus method mapAdapterReceivers.
private ArrayList<Object> mapAdapterReceivers(Adapter adapter, boolean showPendingMsgCount) {
ArrayList<Object> receivers = new ArrayList<Object>();
Iterator<?> recIt = adapter.getReceiverIterator();
if (recIt.hasNext()) {
while (recIt.hasNext()) {
IReceiver receiver = (IReceiver) recIt.next();
Map<String, Object> receiverInfo = new HashMap<String, Object>();
RunStateEnum receiverRunState = receiver.getRunState();
receiverInfo.put("started", receiverRunState.equals(RunStateEnum.STARTED));
receiverInfo.put("state", receiverRunState.toString().toLowerCase().replace("*", ""));
receiverInfo.put("name", receiver.getName());
receiverInfo.put("class", ClassUtils.nameOf(receiver));
Map<String, Object> messages = new HashMap<String, Object>(3);
messages.put("received", receiver.getMessagesReceived());
messages.put("retried", receiver.getMessagesRetried());
messages.put("rejected", receiver.getMessagesRejected());
receiverInfo.put("messages", messages);
ISender sender = null;
if (receiver instanceof ReceiverBase) {
ReceiverBase rb = (ReceiverBase) receiver;
IListener listener = rb.getListener();
receiverInfo.put("listenerClass", ClassUtils.nameOf(listener));
if (listener instanceof HasPhysicalDestination) {
String pd = ((HasPhysicalDestination) rb.getListener()).getPhysicalDestinationName();
receiverInfo.put("listenerDestination", pd);
}
if (listener instanceof HasSender) {
sender = ((HasSender) listener).getSender();
}
// receiverInfo.put("hasInprocessStorage", ""+(rb.getInProcessStorage()!=null));
ITransactionalStorage ts;
ts = rb.getErrorStorage();
receiverInfo.put("hasErrorStorage", (ts != null));
if (ts != null) {
try {
if (showCountErrorStore) {
receiverInfo.put("errorStorageCount", ts.getMessageCount());
} else {
receiverInfo.put("errorStorageCount", "?");
}
} catch (Exception e) {
log.warn(e);
receiverInfo.put("errorStorageCount", "error");
}
}
ts = rb.getMessageLog();
receiverInfo.put("hasMessageLog", (ts != null));
if (ts != null) {
try {
if (showCountMessageLog) {
receiverInfo.put("messageLogCount", ts.getMessageCount());
} else {
receiverInfo.put("messageLogCount", "?");
}
} catch (Exception e) {
log.warn(e);
receiverInfo.put("messageLogCount", "error");
}
}
boolean isRestListener = (listener instanceof RestListener);
receiverInfo.put("isRestListener", isRestListener);
if (isRestListener) {
RestListener rl = (RestListener) listener;
receiverInfo.put("restUriPattern", rl.getRestUriPattern());
receiverInfo.put("isView", (rl.isView() == null ? false : rl.isView()));
}
if ((listener instanceof JmsListenerBase) && showPendingMsgCount) {
JmsListenerBase jlb = (JmsListenerBase) listener;
JmsMessageBrowser jmsBrowser;
if (StringUtils.isEmpty(jlb.getMessageSelector())) {
jmsBrowser = new JmsMessageBrowser();
} else {
jmsBrowser = new JmsMessageBrowser(jlb.getMessageSelector());
}
jmsBrowser.setName("MessageBrowser_" + jlb.getName());
jmsBrowser.setJmsRealm(jlb.getJmsRealName());
jmsBrowser.setDestinationName(jlb.getDestinationName());
jmsBrowser.setDestinationType(jlb.getDestinationType());
String numMsgs;
try {
int messageCount = jmsBrowser.getMessageCount();
numMsgs = String.valueOf(messageCount);
} catch (Throwable t) {
log.warn(t);
numMsgs = "?";
}
receiverInfo.put("pendingMessagesCount", numMsgs);
}
boolean isEsbJmsFFListener = false;
if (listener instanceof EsbJmsListener) {
EsbJmsListener ejl = (EsbJmsListener) listener;
if (ejl.getMessageProtocol().equalsIgnoreCase("FF")) {
isEsbJmsFFListener = true;
}
if (showPendingMsgCount) {
String esbNumMsgs = EsbUtils.getQueueMessageCount(ejl);
if (esbNumMsgs == null) {
esbNumMsgs = "?";
}
receiverInfo.put("esbPendingMessagesCount", esbNumMsgs);
}
}
receiverInfo.put("isEsbJmsFFListener", isEsbJmsFFListener);
}
if (receiver instanceof HasSender) {
ISender rsender = ((HasSender) receiver).getSender();
if (rsender != null) {
// this sender has preference, but avoid overwriting listeners sender with null
sender = rsender;
}
}
if (sender != null) {
receiverInfo.put("senderName", sender.getName());
receiverInfo.put("senderClass", ClassUtils.nameOf(sender));
if (sender instanceof HasPhysicalDestination) {
String pd = ((HasPhysicalDestination) sender).getPhysicalDestinationName();
receiverInfo.put("senderDestination", pd);
}
}
if (receiver instanceof IThreadCountControllable) {
IThreadCountControllable tcc = (IThreadCountControllable) receiver;
if (tcc.isThreadCountReadable()) {
receiverInfo.put("threadCount", tcc.getCurrentThreadCount());
receiverInfo.put("maxThreadCount", tcc.getMaxThreadCount());
}
if (tcc.isThreadCountControllable()) {
receiverInfo.put("threadCountControllable", "true");
}
}
receivers.add(receiverInfo);
}
}
return receivers;
}
Aggregations